diff --git a/.changeset/new-parrots-pay.md b/.changeset/new-parrots-pay.md deleted file mode 100644 index 3dbcc9580ae8..000000000000 --- a/.changeset/new-parrots-pay.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'svelte': patch ---- - -fix: migrate `Component` to `ComponentExports` in TS diff --git a/packages/svelte/src/compiler/migrate/index.js b/packages/svelte/src/compiler/migrate/index.js index 3e47bf816714..ee5abc8853c8 100644 --- a/packages/svelte/src/compiler/migrate/index.js +++ b/packages/svelte/src/compiler/migrate/index.js @@ -1,5 +1,5 @@ /** @import { VariableDeclarator, Node, Identifier, AssignmentExpression, LabeledStatement, ExpressionStatement } from 'estree' */ -/** @import { Visitors, Context } from 'zimmerframe' */ +/** @import { Visitors } from 'zimmerframe' */ /** @import { ComponentAnalysis } from '../phases/types.js' */ /** @import { Scope, ScopeRoot } from '../phases/scope.js' */ /** @import { AST, Binding, SvelteNode, ValidatedCompileOptions } from '#compiler' */ @@ -398,8 +398,6 @@ export function migrate(source, { filename, use_ts } = {}) { } } -/** @typedef {SvelteNode | { type: "TSTypeReference", typeName: Identifier, start: number, end: number }} ASTNode */ - /** * @typedef {{ * scope: Scope; @@ -418,12 +416,11 @@ export function migrate(source, { filename, use_ts } = {}) { * derived_components: Map; * derived_labeled_statements: Set; * has_svelte_self: boolean; - * migrate_prop_component_type?: boolean; * uses_ts: boolean; * }} State */ -/** @type {Visitors} */ +/** @type {Visitors} */ const instance_script = { _(node, { state, next }) { // @ts-expect-error @@ -440,27 +437,8 @@ const instance_script = { } next(); }, - TSTypeReference(node, { state, path }) { - if (state.analysis.runes) return; - if (node.typeName.type === 'Identifier') { - const binding = state.scope.get(node.typeName.name); - if ( - binding && - binding.declaration_kind === 'import' && - binding.initial?.type === 'ImportDeclaration' && - binding.initial.source.value?.toString().endsWith('.svelte') - ) { - state.str.overwrite( - node.start, - node.end, - `import('svelte').ComponentExports` - ); - } - } - }, - Identifier(node, { state, path, next }) { + Identifier(node, { state, path }) { handle_identifier(node, state, path); - next(); }, ImportDeclaration(node, { state }) { state.props_insertion_point = node.end ?? state.props_insertion_point; @@ -525,8 +503,6 @@ const instance_script = { return; } - next(); - let nr_of_props = 0; for (const declarator of node.declarations) { @@ -1433,7 +1409,7 @@ function migrate_slot_usage(node, path, state) { /** * @param {VariableDeclarator} declarator * @param {State} state - * @param {ASTNode[]} path + * @param {SvelteNode[]} path */ function extract_type_and_comment(declarator, state, path) { const str = state.str; @@ -1456,10 +1432,7 @@ function extract_type_and_comment(declarator, state, path) { while (str.original[start] === ' ') { start++; } - return { - type: str.snip(start, declarator.id.typeAnnotation.end).toString(), - comment - }; + return { type: str.original.substring(start, declarator.id.typeAnnotation.end), comment }; } let cleaned_comment_arr = comment diff --git a/packages/svelte/tests/migrate/samples/component-type/input.svelte b/packages/svelte/tests/migrate/samples/component-type/input.svelte deleted file mode 100644 index 7184f9f4d1b5..000000000000 --- a/packages/svelte/tests/migrate/samples/component-type/input.svelte +++ /dev/null @@ -1,18 +0,0 @@ - - - \ No newline at end of file diff --git a/packages/svelte/tests/migrate/samples/component-type/output.svelte b/packages/svelte/tests/migrate/samples/component-type/output.svelte deleted file mode 100644 index ab774e56ad63..000000000000 --- a/packages/svelte/tests/migrate/samples/component-type/output.svelte +++ /dev/null @@ -1,22 +0,0 @@ - - - \ No newline at end of file