From bcd907990fd9f99a0c7cbb67fc6b6c62793d0c3d Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Wed, 9 Oct 2024 18:09:31 +0200 Subject: [PATCH] fix: consider `` to determine `ExportedNames` --- packages/svelte2tsx/src/svelte2tsx/index.ts | 23 +++++++++++++++---- .../src/svelte2tsx/nodes/ExportedNames.ts | 5 ++-- .../processInstanceScriptContent.ts | 12 ++++++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/packages/svelte2tsx/src/svelte2tsx/index.ts b/packages/svelte2tsx/src/svelte2tsx/index.ts index 91e0d6b5a..87e6779c4 100644 --- a/packages/svelte2tsx/src/svelte2tsx/index.ts +++ b/packages/svelte2tsx/src/svelte2tsx/index.ts @@ -44,6 +44,7 @@ type TemplateProcessResult = { events: ComponentEvents; resolvedStores: string[]; usesAccessors: boolean; + isRunes: boolean; }; function processSvelteTemplate( @@ -64,6 +65,7 @@ function processSvelteTemplate( let uses$$restProps = false; let uses$$slots = false; let usesAccessors = !!options.accessors; + let isRunes = false; const componentDocumentation = new ComponentDocumentation(); @@ -92,6 +94,9 @@ function processSvelteTemplate( usesAccessors = true; } break; + case 'runes': + isRunes = true; + break; } } }; @@ -303,7 +308,8 @@ function processSvelteTemplate( uses$$slots, componentDocumentation, resolvedStores, - usesAccessors + usesAccessors, + isRunes }; } @@ -342,7 +348,8 @@ export function svelte2tsx( events, componentDocumentation, resolvedStores, - usesAccessors + usesAccessors, + isRunes } = processSvelteTemplate(str, options.parse || parse, { ...options, svelte5Plus @@ -370,7 +377,14 @@ export function svelte2tsx( : instanceScriptTarget; const implicitStoreValues = new ImplicitStoreValues(resolvedStores, renderFunctionStart); //move the instance script and process the content - let exportedNames = new ExportedNames(str, 0, basename, options?.isTsFile, svelte5Plus); + let exportedNames = new ExportedNames( + str, + 0, + basename, + options?.isTsFile, + svelte5Plus, + isRunes + ); let generics = new Generics(str, 0, { attributes: [] } as any); let uses$$SlotsInterface = false; if (scriptTag) { @@ -387,7 +401,8 @@ export function svelte2tsx( /**hasModuleScripts */ !!moduleScriptTag, options?.isTsFile, basename, - svelte5Plus + svelte5Plus, + isRunes ); uses$$props = uses$$props || res.uses$$props; uses$$restProps = uses$$restProps || res.uses$$restProps; diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts index 91ec37aba..8184da952 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts @@ -55,7 +55,8 @@ export class ExportedNames { private astOffset: number, private basename: string, private isTsFile: boolean, - private isSvelte5Plus: boolean + private isSvelte5Plus: boolean, + private isRunes: boolean ) {} handleVariableStatement(node: ts.VariableStatement, parent: ts.Node): void { @@ -808,6 +809,6 @@ export class ExportedNames { } usesRunes() { - return this.hasRunesGlobals || this.hasPropsRune(); + return this.hasRunesGlobals || this.hasPropsRune() || this.isRunes; } } diff --git a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts index e226c2b1b..044aeb83a 100644 --- a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts +++ b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts @@ -42,7 +42,8 @@ export function processInstanceScriptContent( hasModuleScript: boolean, isTSFile: boolean, basename: string, - isSvelte5Plus: boolean + isSvelte5Plus: boolean, + isRunes: boolean ): InstanceScriptProcessResult { const htmlx = str.original; const scriptContent = htmlx.substring(script.content.start, script.content.end); @@ -54,7 +55,14 @@ export function processInstanceScriptContent( ts.ScriptKind.TS ); const astOffset = script.content.start; - const exportedNames = new ExportedNames(str, astOffset, basename, isTSFile, isSvelte5Plus); + const exportedNames = new ExportedNames( + str, + astOffset, + basename, + isTSFile, + isSvelte5Plus, + isRunes + ); const generics = new Generics(str, astOffset, script); const interfacesAndTypes = new InterfacesAndTypes();