Skip to content

Commit

Permalink
Revert "feat: migrate Component to `ComponentExports<typeof Compone…
Browse files Browse the repository at this point in the history
…nt>` in …" (#14070)

This reverts commit 4715dfa.
  • Loading branch information
Rich-Harris authored Oct 31, 2024
1 parent 2784fb1 commit 37049b4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 77 deletions.
5 changes: 0 additions & 5 deletions .changeset/new-parrots-pay.md

This file was deleted.

37 changes: 5 additions & 32 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
@@ -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' */
Expand Down Expand Up @@ -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;
Expand All @@ -418,12 +416,11 @@ export function migrate(source, { filename, use_ts } = {}) {
* derived_components: Map<string, string>;
* derived_labeled_statements: Set<LabeledStatement>;
* has_svelte_self: boolean;
* migrate_prop_component_type?: boolean;
* uses_ts: boolean;
* }} State
*/

/** @type {Visitors<ASTNode, State>} */
/** @type {Visitors<SvelteNode, State>} */
const instance_script = {
_(node, { state, next }) {
// @ts-expect-error
Expand All @@ -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<typeof ${state.str.original.substring(node.start, node.end)}>`
);
}
}
},
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;
Expand Down Expand Up @@ -525,8 +503,6 @@ const instance_script = {
return;
}

next();

let nr_of_props = 0;

for (const declarator of node.declarations) {
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
18 changes: 0 additions & 18 deletions packages/svelte/tests/migrate/samples/component-type/input.svelte

This file was deleted.

22 changes: 0 additions & 22 deletions packages/svelte/tests/migrate/samples/component-type/output.svelte

This file was deleted.

0 comments on commit 37049b4

Please sign in to comment.