Skip to content

Commit

Permalink
fix: revert additional two-way-binding checks (#2508)
Browse files Browse the repository at this point in the history
This reverts commit 8c080cf.

This reverts #2477. Sadly, the idea didn't work out, as shown by two opened bug reports:

- #2506: A type union can be narrowed on the input, but not on the way back out
- #2494: A generic nested within a bound value is not properly resolved and not falling back to `any` (in #2477 we thought of the generic case, but only for when the generic is the whole value type, not when it's nested)

For these reasons I don't see a way to properly implement #1392 at the moment.
  • Loading branch information
dummdidumm authored Sep 19, 2024
1 parent e74f1d7 commit 81019d9
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,8 @@ export class RenameProviderImpl implements RenameProvider {
const mappedLocations = await Promise.all(
renameLocations.map(async (loc) => {
const snapshot = await snapshots.retrieve(loc.fileName);
const text = snapshot.getFullText();
const end = loc.textSpan.start + loc.textSpan.length;

if (
!(snapshot instanceof SvelteDocumentSnapshot) ||
(!isTextSpanInGeneratedCode(text, loc.textSpan) &&
// prevent generated code for bindings from being renamed
// (it's not inside a generate comment because diagnostics should show up)
text.slice(end + 3, end + 27) !== '__sveltets_binding_value')
) {
if (!isTextSpanInGeneratedCode(snapshot.getFullText(), loc.textSpan)) {
return {
...loc,
range: this.mapRangeToOriginal(snapshot, loc.textSpan),
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 6 additions & 6 deletions packages/svelte2tsx/repl/index.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import MyComponent from './ComponentB.svelte'
let value: Date
$: console.log('value:', value)
<script>
export let value;
</script>

<MyComponent bind:value />

{#if value}
<input bind:value on:change />
{/if}
6 changes: 0 additions & 6 deletions packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ export function handleBinding(
if (isSvelte5Plus && element instanceof InlineComponent) {
// To check if property is actually bindable
element.appendToStartEnd([`${element.name}.$$bindings = '${attr.name}';`]);
// To check if the binding is also assigned to the variable (only works when there's no assertion, we can't transform that)
if (!isTypescriptNode(attr.expression)) {
element.appendToStartEnd([
`${expressionStr} = __sveltets_binding_value(${element.originalName}, '${attr.name}');`
]);
}
}

if (element instanceof Element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class InlineComponent {
private startTagEnd: number;
private isSelfclosing: boolean;
public child?: any;
public originalName = this.node.name;

// Add const $$xxx = ... only if the variable name is actually used
// in order to prevent "$$xxx is defined but never used" TS hints
Expand Down
13 changes: 0 additions & 13 deletions packages/svelte2tsx/svelte-shims-v4.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,3 @@ declare function __sveltets_2_isomorphic_component<
declare function __sveltets_2_isomorphic_component_slots<
Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
>(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<__sveltets_2_PropsWithChildren<Props, Slots>, Events, Slots, Exports, Bindings>;

type __sveltets_NonUndefined<T> = T extends undefined ? never : T;

declare function __sveltets_binding_value<
// @ts-ignore this is only used for Svelte 5, which knows about the Component type
Comp extends typeof import('svelte').Component<any>,
Key extends string
>(comp: Comp, key: Key): Key extends keyof import('svelte').ComponentProps<Comp> ?
// bail on unknown because it hints at a generic type which we can't properly resolve here
// remove undefined because optional properties have it, and would result in false positives
unknown extends import('svelte').ComponentProps<Comp>[Key] ? any : __sveltets_NonUndefined<import('svelte').ComponentProps<Comp>[Key]> : any;
// Overload to ensure typings that only use old SvelteComponent class or something invalid are gracefully handled
declare function __sveltets_binding_value(comp: any, key: string): any

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

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

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

0 comments on commit 81019d9

Please sign in to comment.