Skip to content

Commit

Permalink
fix: consider <svelte:options runes /> to determine ExportedNames
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Oct 9, 2024
1 parent 267ca97 commit bcd9079
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
23 changes: 19 additions & 4 deletions packages/svelte2tsx/src/svelte2tsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type TemplateProcessResult = {
events: ComponentEvents;
resolvedStores: string[];
usesAccessors: boolean;
isRunes: boolean;
};

function processSvelteTemplate(
Expand All @@ -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();

Expand Down Expand Up @@ -92,6 +94,9 @@ function processSvelteTemplate(
usesAccessors = true;
}
break;
case 'runes':
isRunes = true;
break;
}
}
};
Expand Down Expand Up @@ -303,7 +308,8 @@ function processSvelteTemplate(
uses$$slots,
componentDocumentation,
resolvedStores,
usesAccessors
usesAccessors,
isRunes
};
}

Expand Down Expand Up @@ -342,7 +348,8 @@ export function svelte2tsx(
events,
componentDocumentation,
resolvedStores,
usesAccessors
usesAccessors,
isRunes
} = processSvelteTemplate(str, options.parse || parse, {
...options,
svelte5Plus
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -808,6 +809,6 @@ export class ExportedNames {
}

usesRunes() {
return this.hasRunesGlobals || this.hasPropsRune();
return this.hasRunesGlobals || this.hasPropsRune() || this.isRunes;
}
}
12 changes: 10 additions & 2 deletions packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down

0 comments on commit bcd9079

Please sign in to comment.