From 37049b4171ee3e5cf9bd1ee05fdb609cc6d47503 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 31 Oct 2024 11:38:13 -0400 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20migrate=20`Component`=20to=20?= =?UTF-8?q?`ComponentExports`=20in=20=E2=80=A6"=20(#14?= =?UTF-8?q?070)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4715dfaad2562bd9074d3ff79fd775aeee4dc0a0. --- .changeset/new-parrots-pay.md | 5 --- packages/svelte/src/compiler/migrate/index.js | 37 +++---------------- .../samples/component-type/input.svelte | 18 --------- .../samples/component-type/output.svelte | 22 ----------- 4 files changed, 5 insertions(+), 77 deletions(-) delete mode 100644 .changeset/new-parrots-pay.md delete mode 100644 packages/svelte/tests/migrate/samples/component-type/input.svelte delete mode 100644 packages/svelte/tests/migrate/samples/component-type/output.svelte diff --git a/.changeset/new-parrots-pay.md b/.changeset/new-parrots-pay.md deleted file mode 100644 index 3dbcc9580a..0000000000 --- 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 3e47bf8167..ee5abc8853 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 7184f9f4d1..0000000000 --- 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 ab774e56ad..0000000000 --- a/packages/svelte/tests/migrate/samples/component-type/output.svelte +++ /dev/null @@ -1,22 +0,0 @@ - - - \ No newline at end of file