Skip to content

Commit b755136

Browse files
committed
simplify
1 parent b3e8d70 commit b755136

File tree

1 file changed

+9
-22
lines changed
  • packages/svelte/src/compiler/migrate

1 file changed

+9
-22
lines changed

packages/svelte/src/compiler/migrate/index.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ export function migrate(source, { filename } = {}) {
306306
}
307307
}
308308

309+
/** @typedef {SvelteNode | { type: "TSTypeReference", typeName: Identifier, start: number, end: number }} ASTNode */
310+
309311
/**
310312
* @typedef {{
311313
* scope: Scope;
@@ -327,7 +329,7 @@ export function migrate(source, { filename } = {}) {
327329
* }} State
328330
*/
329331

330-
/** @type {Visitors<SvelteNode | { type: "TSTypeReference", typeName: Identifier, start: number, end: number }, State>} */
332+
/** @type {Visitors<ASTNode, State>} */
331333
const instance_script = {
332334
_(node, { state, next }) {
333335
// @ts-expect-error
@@ -345,16 +347,6 @@ const instance_script = {
345347
next();
346348
},
347349
TSTypeReference(node, { state, path }) {
348-
// we don't want to overwrite in case it's an exported prop because
349-
// we already take care of that in extract_type_and_comment
350-
if (
351-
path[1] &&
352-
path[1].type === 'ExportNamedDeclaration' &&
353-
path[1].declaration?.type === 'VariableDeclaration' &&
354-
path[1].declaration?.kind === 'let' &&
355-
!state.migrate_prop_component_type
356-
)
357-
return;
358350
if (state.analysis.runes) return;
359351
if (node.typeName.type === 'Identifier') {
360352
const binding = state.scope.get(node.typeName.name);
@@ -400,12 +392,13 @@ const instance_script = {
400392
state.str.remove(/** @type {number} */ (node.start), /** @type {number} */ (node.end));
401393
}
402394
},
403-
VariableDeclaration(node, context) {
404-
const { state, path, visit, next } = context;
395+
VariableDeclaration(node, { state, path, visit, next }) {
405396
if (state.scope !== state.analysis.instance.scope) {
406397
return;
407398
}
408399

400+
next();
401+
409402
let nr_of_props = 0;
410403

411404
for (const declarator of node.declarations) {
@@ -496,7 +489,7 @@ const instance_script = {
496489
: '',
497490
optional: !!declarator.init,
498491
bindable: binding.updated,
499-
...extract_type_and_comment(declarator, state.str, context)
492+
...extract_type_and_comment(declarator, state.str, path)
500493
});
501494
}
502495

@@ -684,7 +677,6 @@ const instance_script = {
684677
while (state.str.original[end] !== '\n') end++;
685678
state.str.update(start, end, '');
686679
}
687-
next();
688680
},
689681
BreakStatement(node, { state, path }) {
690682
if (path[1].type !== 'LabeledStatement') return;
@@ -1176,10 +1168,9 @@ function migrate_slot_usage(node, path, state) {
11761168
/**
11771169
* @param {VariableDeclarator} declarator
11781170
* @param {MagicString} str
1179-
* @param {Context<SvelteNode | { type: "TSTypeReference", typeName: Identifier, start: number, end: number }, State>} context
1171+
* @param {ASTNode[]} path
11801172
*/
1181-
function extract_type_and_comment(declarator, str, context) {
1182-
const path = context.path;
1173+
function extract_type_and_comment(declarator, str, path) {
11831174
const parent = path.at(-1);
11841175

11851176
// Try to find jsdoc above the declaration
@@ -1199,10 +1190,6 @@ function extract_type_and_comment(declarator, str, context) {
11991190
while (str.original[start] === ' ') {
12001191
start++;
12011192
}
1202-
context.visit(declarator.id.typeAnnotation, {
1203-
...context.state,
1204-
migrate_prop_component_type: true
1205-
});
12061193
return {
12071194
type: str.snip(start, declarator.id.typeAnnotation.end).toString(),
12081195
comment

0 commit comments

Comments
 (0)