From 9ef34247320b99bf0126d34116223077adb4da51 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:42:06 +0100 Subject: [PATCH] fix: support class exports (#9465) --- .changeset/thirty-flowers-sit.md | 5 +++++ packages/svelte/src/compiler/phases/2-analyze/index.js | 10 ++++++++-- .../svelte/src/compiler/phases/2-analyze/validation.js | 9 --------- 3 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 .changeset/thirty-flowers-sit.md diff --git a/.changeset/thirty-flowers-sit.md b/.changeset/thirty-flowers-sit.md new file mode 100644 index 0000000000..a3d0927788 --- /dev/null +++ b/.changeset/thirty-flowers-sit.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: support class exports diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index cfb6194c77..7a769a2256 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -577,7 +577,10 @@ const legacy_scope_tweaker = { return next(); } - if (node.declaration.type === 'FunctionDeclaration') { + if ( + node.declaration.type === 'FunctionDeclaration' || + node.declaration.type === 'ClassDeclaration' + ) { state.analysis.exports.push({ name: /** @type {import('estree').Identifier} */ (node.declaration.id).name, alias: null @@ -681,7 +684,10 @@ const runes_scope_tweaker = { return next(); } - if (node.declaration.type === 'FunctionDeclaration') { + if ( + node.declaration.type === 'FunctionDeclaration' || + node.declaration.type === 'ClassDeclaration' + ) { state.analysis.exports.push({ name: /** @type {import('estree').Identifier} */ (node.declaration.id).name, alias: null diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index 7d421cd07e..d1688a1d68 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -453,15 +453,6 @@ export const validation_legacy = merge(validation, a11y_validators, { // TODO check if it's a store subscription that's called? How likely is it that someone uses a store that contains a function? error(node.init, 'invalid-rune-usage', callee.name); }, - ExportNamedDeclaration(node) { - if ( - node.declaration && - node.declaration.type !== 'VariableDeclaration' && - node.declaration.type !== 'FunctionDeclaration' - ) { - error(node, 'TODO', 'whatever this is'); - } - }, AssignmentExpression(node, { state, path }) { const parent = path.at(-1); if (parent && parent.type === 'ConstTag') return;