Skip to content

Commit 09dd498

Browse files
authored
(fix) add back export const, function and class (#649)
#647
1 parent d412d37 commit 09dd498

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ export function processInstanceScriptContent(
122122
}
123123
};
124124

125+
const handleExportFunctionOrClass = (node: ts.ClassDeclaration | ts.FunctionDeclaration) => {
126+
const exportModifier = findExportKeyword(node);
127+
if (!exportModifier) {
128+
return;
129+
}
130+
131+
removeExport(exportModifier.getStart(), exportModifier.end);
132+
addGetter(node.name);
133+
134+
// Can't export default here
135+
if (node.name) {
136+
exportedNames.addExport(node.name);
137+
}
138+
};
139+
125140
const handleStore = (ident: ts.Node, parent: ts.Node) => {
126141
// handle assign to
127142
// eslint-disable-next-line max-len
@@ -323,8 +338,8 @@ export function processInstanceScriptContent(
323338
const isLet = node.declarationList.flags === ts.NodeFlags.Let;
324339
const isConst = node.declarationList.flags === ts.NodeFlags.Const;
325340

341+
handleExportedVariableDeclarationList(node.declarationList);
326342
if (isLet) {
327-
handleExportedVariableDeclarationList(node.declarationList);
328343
propTypeAssertToUserDefined(node.declarationList);
329344
} else if (isConst) {
330345
node.declarationList.forEachChild((n) => {
@@ -338,24 +353,14 @@ export function processInstanceScriptContent(
338353
}
339354

340355
if (ts.isFunctionDeclaration(node)) {
341-
if (node.modifiers) {
342-
const exportModifier = findExportKeyword(node);
343-
if (exportModifier) {
344-
removeExport(exportModifier.getStart(), exportModifier.end);
345-
addGetter(node.name);
346-
}
347-
}
356+
handleExportFunctionOrClass(node);
348357

349358
pushScope();
350359
onLeaveCallbacks.push(() => popScope());
351360
}
352361

353362
if (ts.isClassDeclaration(node)) {
354-
const exportModifier = findExportKeyword(node);
355-
if (exportModifier) {
356-
removeExport(exportModifier.getStart(), exportModifier.end);
357-
addGetter(node.name);
358-
}
363+
handleExportFunctionOrClass(node);
359364
}
360365

361366
if (ts.isBlock(node)) {

packages/svelte2tsx/test/svelte2tsx/samples/export-class/expected.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class Foo {};
55
;
66
() => (<></>);
7-
return { props: {}, slots: {}, getters: {Foo: Foo}, events: {} }}
7+
return { props: {Foo: Foo}, slots: {}, getters: {Foo: Foo}, events: {} }}
88

99
export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) {
1010
get Foo() { return render().getters.Foo }

packages/svelte2tsx/test/svelte2tsx/samples/ts-export-const/expected.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const SOME = 1, CONSTANT = 2;
66
;
77
() => (<></>);
8-
return { props: {}, slots: {}, getters: {name: name, SOME: SOME, CONSTANT: CONSTANT}, events: {} }}
8+
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: {} }}
99

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

0 commit comments

Comments
 (0)