Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ export function processInstanceScriptContent(
}
};

const handleExportFunctionOrClass = (node: ts.ClassDeclaration | ts.FunctionDeclaration) => {
const exportModifier = findExportKeyword(node);
if (!exportModifier) {
return;
}

removeExport(exportModifier.getStart(), exportModifier.end);
addGetter(node.name);

// Can't export default here
if (node.name) {
exportedNames.addExport(node.name);
}
};

const handleStore = (ident: ts.Node, parent: ts.Node) => {
// handle assign to
// eslint-disable-next-line max-len
Expand Down Expand Up @@ -323,8 +338,8 @@ export function processInstanceScriptContent(
const isLet = node.declarationList.flags === ts.NodeFlags.Let;
const isConst = node.declarationList.flags === ts.NodeFlags.Const;

handleExportedVariableDeclarationList(node.declarationList);
if (isLet) {
handleExportedVariableDeclarationList(node.declarationList);
propTypeAssertToUserDefined(node.declarationList);
} else if (isConst) {
node.declarationList.forEachChild((n) => {
Expand All @@ -338,24 +353,14 @@ export function processInstanceScriptContent(
}

if (ts.isFunctionDeclaration(node)) {
if (node.modifiers) {
const exportModifier = findExportKeyword(node);
if (exportModifier) {
removeExport(exportModifier.getStart(), exportModifier.end);
addGetter(node.name);
}
}
handleExportFunctionOrClass(node);

pushScope();
onLeaveCallbacks.push(() => popScope());
}

if (ts.isClassDeclaration(node)) {
const exportModifier = findExportKeyword(node);
if (exportModifier) {
removeExport(exportModifier.getStart(), exportModifier.end);
addGetter(node.name);
}
handleExportFunctionOrClass(node);
}

if (ts.isBlock(node)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Foo {};
;
() => (<></>);
return { props: {}, slots: {}, getters: {Foo: Foo}, events: {} }}
return { props: {Foo: Foo}, slots: {}, getters: {Foo: Foo}, events: {} }}

export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) {
get Foo() { return render().getters.Foo }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const SOME = 1, CONSTANT = 2;
;
() => (<></>);
return { props: {}, slots: {}, getters: {name: name, SOME: SOME, CONSTANT: CONSTANT}, events: {} }}
return { props: {name: name , SOME: SOME , CONSTANT: CONSTANT} as {name?: string, SOME?: typeof SOME, CONSTANT?: typeof CONSTANT}, slots: {}, getters: {name: name, SOME: SOME, CONSTANT: CONSTANT}, events: {} }}

export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) {
get name() { return render().getters.name }
Expand Down