Skip to content

Commit

Permalink
fix: ensure correct types for media bindings (#2284)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dummdidumm authored Feb 7, 2024
1 parent a72a2ad commit 3d61533
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,36 @@ import { Element } from './Element';
import { InlineComponent } from './InlineComponent';
import { surroundWithIgnoreComments } from '../../utils/ignore';

/**
* List of binding names that are transformed to sth like `binding = variable`.
*/
const oneWayBindingAttributes: Set<string> = new Set([
'clientWidth',
'clientHeight',
'offsetWidth',
'offsetHeight',
'duration',
'buffered',
'seekable',
'seeking',
'played',
'ended',
'readyState',
'naturalWidth',
'naturalHeight'
]);

/**
* List of binding names that are transformed to sth like `binding = variable as GeneratedCode`.
*/
const oneWayBindingAttributesNotOnElement: Map<string, string> = new Map([
['contentRect', 'DOMRectReadOnly'],
['contentBoxSize', 'ResizeObserverSize[]'],
['borderBoxSize', 'ResizeObserverSize[]'],
['devicePixelContentBoxSize', 'ResizeObserverSize[]']
['devicePixelContentBoxSize', 'ResizeObserverSize[]'],
// available on the element, but with a different type
['buffered', "import('svelte/elements').SvelteMediaTimeRange[]"],
['played', "import('svelte/elements').SvelteMediaTimeRange[]"],
['seekable', "import('svelte/elements').SvelteMediaTimeRange[]"]
]);

/**
* List of all binding names that are transformed to sth like `binding = variable`.
* This applies to readonly bindings and the this binding.
*/
export const assignmentBindings = new Set([...oneWayBindingAttributes.keys(), 'this']);

const supportsBindThis = [
'InlineComponent',
'Element',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3d61533

Please sign in to comment.