Skip to content

Commit 3d61533

Browse files
authored
fix: ensure correct types for media bindings (#2284)
buffered/played/seekable exist on the DOM element but their types are different to the ones Svelte uses for its bindings - adjust them accordingly. #2272
1 parent a72a2ad commit 3d61533

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Binding.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,36 @@ import { Element } from './Element';
1010
import { InlineComponent } from './InlineComponent';
1111
import { surroundWithIgnoreComments } from '../../utils/ignore';
1212

13+
/**
14+
* List of binding names that are transformed to sth like `binding = variable`.
15+
*/
1316
const oneWayBindingAttributes: Set<string> = new Set([
1417
'clientWidth',
1518
'clientHeight',
1619
'offsetWidth',
1720
'offsetHeight',
1821
'duration',
19-
'buffered',
20-
'seekable',
2122
'seeking',
22-
'played',
2323
'ended',
2424
'readyState',
2525
'naturalWidth',
2626
'naturalHeight'
2727
]);
2828

29+
/**
30+
* List of binding names that are transformed to sth like `binding = variable as GeneratedCode`.
31+
*/
2932
const oneWayBindingAttributesNotOnElement: Map<string, string> = new Map([
3033
['contentRect', 'DOMRectReadOnly'],
3134
['contentBoxSize', 'ResizeObserverSize[]'],
3235
['borderBoxSize', 'ResizeObserverSize[]'],
33-
['devicePixelContentBoxSize', 'ResizeObserverSize[]']
36+
['devicePixelContentBoxSize', 'ResizeObserverSize[]'],
37+
// available on the element, but with a different type
38+
['buffered', "import('svelte/elements').SvelteMediaTimeRange[]"],
39+
['played', "import('svelte/elements').SvelteMediaTimeRange[]"],
40+
['seekable', "import('svelte/elements').SvelteMediaTimeRange[]"]
3441
]);
3542

36-
/**
37-
* List of all binding names that are transformed to sth like `binding = variable`.
38-
* This applies to readonly bindings and the this binding.
39-
*/
40-
export const assignmentBindings = new Set([...oneWayBindingAttributes.keys(), 'this']);
41-
4243
const supportsBindThis = [
4344
'InlineComponent',
4445
'Element',

packages/svelte2tsx/test/htmlx2jsx/samples/binding-oneway/expectedv2.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)