From 90c995391be8090d23eb5460d006b2fdf9d83f5c Mon Sep 17 00:00:00 2001 From: "Kim, Jang-hwan" Date: Thu, 9 Jan 2025 05:00:31 +0900 Subject: [PATCH 1/2] fix: Update prettier-options-schema.json (#2658) sync with `options.ts` in sveltejs/prettier-plugin-svelte fixes #2657 --- .../prettier-options-schema.json | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/packages/svelte-vscode/prettier-options-schema.json b/packages/svelte-vscode/prettier-options-schema.json index 9df51ad56..5d3877d07 100644 --- a/packages/svelte-vscode/prettier-options-schema.json +++ b/packages/svelte-vscode/prettier-options-schema.json @@ -9,36 +9,31 @@ "description": "Sort order for , scripts, markup, and styles.", "default": "options-scripts-markup-styles", "enum": [ - "options-scripts-markup-styles", - "options-scripts-styles-markup", - "options-markup-scripts-styles", - "options-markup-styles-scripts", - "options-styles-scripts-markup", - "options-styles-markup-scripts", - "scripts-options-markup-styles", - "scripts-options-styles-markup", - "scripts-markup-options-styles", - "scripts-markup-styles-options", - "scripts-styles-options-markup", - "scripts-styles-markup-options", "markup-options-scripts-styles", "markup-options-styles-scripts", "markup-scripts-options-styles", "markup-scripts-styles-options", "markup-styles-options-scripts", "markup-styles-scripts-options", - "styles-options-scripts-markup", - "styles-options-markup-scripts", - "styles-scripts-options-markup", - "styles-scripts-markup-options", + "options-markup-scripts-styles", + "options-markup-styles-scripts", + "options-scripts-markup-styles", + "options-scripts-styles-markup", + "options-styles-markup-scripts", + "options-styles-scripts-markup", + "scripts-markup-options-styles", + "scripts-markup-styles-options", + "scripts-options-markup-styles", + "scripts-options-styles-markup", + "scripts-styles-markup-options", + "scripts-styles-options-markup", "styles-markup-options-scripts", "styles-markup-scripts-options", - "scripts-markup-styles", - "scripts-styles-markup", - "markup-styles-scripts", - "markup-scripts-styles", - "styles-markup-scripts", - "styles-scripts-markup" + "styles-options-markup-scripts", + "styles-options-scripts-markup", + "styles-scripts-markup-options", + "styles-scripts-options-markup", + "none", ] }, "svelteStrictMode": { From 2f46701d89c5e8b4493ec8a64326c1a01c1d18ca Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:25:59 +0100 Subject: [PATCH 2/2] fix: don't hoist types referencing stores or destructured variables (#2661) #2659 #2660 --- .../prettier-options-schema.json | 2 +- .../svelte2tsx/nodes/HoistableInterfaces.ts | 28 +++++++++++++++++-- .../expectedv2.ts | 11 ++++++++ .../input.svelte | 4 +++ .../expectedv2.ts | 14 ++++++++++ .../input.svelte | 7 +++++ 6 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-6.v5/expectedv2.ts create mode 100644 packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-6.v5/input.svelte create mode 100644 packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-7.v5/expectedv2.ts create mode 100644 packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-7.v5/input.svelte diff --git a/packages/svelte-vscode/prettier-options-schema.json b/packages/svelte-vscode/prettier-options-schema.json index 5d3877d07..382633ee4 100644 --- a/packages/svelte-vscode/prettier-options-schema.json +++ b/packages/svelte-vscode/prettier-options-schema.json @@ -33,7 +33,7 @@ "styles-options-scripts-markup", "styles-scripts-markup-options", "styles-scripts-options-markup", - "none", + "none" ] }, "svelteStrictMode": { diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/HoistableInterfaces.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/HoistableInterfaces.ts index bca4a25ce..8fd726ff6 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/HoistableInterfaces.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/HoistableInterfaces.ts @@ -179,6 +179,19 @@ export class HoistableInterfaces { node.declarationList.declarations.forEach((declaration) => { if (ts.isIdentifier(declaration.name)) { this.disallowed_values.add(declaration.name.text); + } else { + const walk = (node: ts.Node) => { + if ( + ts.isIdentifier(node) && + ts.isBindingElement(node.parent) && + node.parent.name === node + ) { + this.disallowed_values.add(node.text); + } + ts.forEachChild(node, walk); + }; + + walk(declaration.name); } }); } @@ -256,7 +269,7 @@ export class HoistableInterfaces { } for (const dep of deps.value_deps) { - if (this.disallowed_values.has(dep)) { + if (!this.isAllowedReference(dep)) { this.disallowed_types.add(interface_name); can_hoist = false; break; @@ -275,7 +288,7 @@ export class HoistableInterfaces { ...this.props_interface.type_deps, ...this.props_interface.value_deps ].every((dep) => { - return !this.disallowed_types.has(dep) && !this.disallowed_values.has(dep); + return !this.disallowed_types.has(dep) && this.isAllowedReference(dep); }); if (can_hoist) { @@ -333,7 +346,16 @@ export class HoistableInterfaces { } isAllowedReference(reference: string) { - return !this.disallowed_values.has(reference); + return !( + this.disallowed_values.has(reference) || + reference === '$$props' || + reference === '$$restProps' || + reference === '$$slots' || + // could be a $store reference + (reference[0] === '$' && + reference[1] !== '$' && + this.disallowed_values.has(reference.slice(1))) + ); } /** diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-6.v5/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-6.v5/expectedv2.ts new file mode 100644 index 000000000..23dd09fb8 --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-6.v5/expectedv2.ts @@ -0,0 +1,11 @@ +/// +;function render() { + + let store = null/*Ωignore_startΩ*/;let $store = __sveltets_2_store_get(store);/*Ωignore_endΩ*/;;type $$ComponentProps = { someProp: typeof $store }; + let { someProp }:/*Ωignore_startΩ*/$$ComponentProps/*Ωignore_endΩ*/ = $props(); +; +async () => {}; +return { props: {} as any as $$ComponentProps, exports: {}, bindings: __sveltets_$$bindings(''), slots: {}, events: {} }} +const Input__SvelteComponent_ = __sveltets_2_fn_component(render()); +type Input__SvelteComponent_ = ReturnType; +export default Input__SvelteComponent_; \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-6.v5/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-6.v5/input.svelte new file mode 100644 index 000000000..452f0d22c --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-6.v5/input.svelte @@ -0,0 +1,4 @@ + diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-7.v5/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-7.v5/expectedv2.ts new file mode 100644 index 000000000..c5bbee061 --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-7.v5/expectedv2.ts @@ -0,0 +1,14 @@ +/// +;function render() { + + let { destructured } = {}; + type Props = { + prop: typeof destructured; + }; + let { prop }: Props = $props(); +; +async () => {}; +return { props: {} as any as Props, exports: {}, bindings: __sveltets_$$bindings(''), slots: {}, events: {} }} +const Input__SvelteComponent_ = __sveltets_2_fn_component(render()); +type Input__SvelteComponent_ = ReturnType; +export default Input__SvelteComponent_; \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-7.v5/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-7.v5/input.svelte new file mode 100644 index 000000000..1e219d3e8 --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-runes-hoistable-props-false-7.v5/input.svelte @@ -0,0 +1,7 @@ + \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy