@@ -306,6 +306,8 @@ export function migrate(source, { filename } = {}) {
306
306
}
307
307
}
308
308
309
+ /** @typedef {SvelteNode | { type: "TSTypeReference", typeName: Identifier, start: number, end: number } } ASTNode */
310
+
309
311
/**
310
312
* @typedef {{
311
313
* scope: Scope;
@@ -327,7 +329,7 @@ export function migrate(source, { filename } = {}) {
327
329
* }} State
328
330
*/
329
331
330
- /** @type {Visitors<SvelteNode | { type: "TSTypeReference", typeName: Identifier, start: number, end: number } , State> } */
332
+ /** @type {Visitors<ASTNode , State> } */
331
333
const instance_script = {
332
334
_ ( node , { state, next } ) {
333
335
// @ts -expect-error
@@ -345,16 +347,6 @@ const instance_script = {
345
347
next ( ) ;
346
348
} ,
347
349
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 ;
358
350
if ( state . analysis . runes ) return ;
359
351
if ( node . typeName . type === 'Identifier' ) {
360
352
const binding = state . scope . get ( node . typeName . name ) ;
@@ -400,12 +392,13 @@ const instance_script = {
400
392
state . str . remove ( /** @type {number } */ ( node . start ) , /** @type {number } */ ( node . end ) ) ;
401
393
}
402
394
} ,
403
- VariableDeclaration ( node , context ) {
404
- const { state, path, visit, next } = context ;
395
+ VariableDeclaration ( node , { state, path, visit, next } ) {
405
396
if ( state . scope !== state . analysis . instance . scope ) {
406
397
return ;
407
398
}
408
399
400
+ next ( ) ;
401
+
409
402
let nr_of_props = 0 ;
410
403
411
404
for ( const declarator of node . declarations ) {
@@ -496,7 +489,7 @@ const instance_script = {
496
489
: '' ,
497
490
optional : ! ! declarator . init ,
498
491
bindable : binding . updated ,
499
- ...extract_type_and_comment ( declarator , state . str , context )
492
+ ...extract_type_and_comment ( declarator , state . str , path )
500
493
} ) ;
501
494
}
502
495
@@ -684,7 +677,6 @@ const instance_script = {
684
677
while ( state . str . original [ end ] !== '\n' ) end ++ ;
685
678
state . str . update ( start , end , '' ) ;
686
679
}
687
- next ( ) ;
688
680
} ,
689
681
BreakStatement ( node , { state, path } ) {
690
682
if ( path [ 1 ] . type !== 'LabeledStatement' ) return ;
@@ -1176,10 +1168,9 @@ function migrate_slot_usage(node, path, state) {
1176
1168
/**
1177
1169
* @param {VariableDeclarator } declarator
1178
1170
* @param {MagicString } str
1179
- * @param {Context<SvelteNode | { type: "TSTypeReference", typeName: Identifier, start: number, end: number }, State> } context
1171
+ * @param {ASTNode[] } path
1180
1172
*/
1181
- function extract_type_and_comment ( declarator , str , context ) {
1182
- const path = context . path ;
1173
+ function extract_type_and_comment ( declarator , str , path ) {
1183
1174
const parent = path . at ( - 1 ) ;
1184
1175
1185
1176
// Try to find jsdoc above the declaration
@@ -1199,10 +1190,6 @@ function extract_type_and_comment(declarator, str, context) {
1199
1190
while ( str . original [ start ] === ' ' ) {
1200
1191
start ++ ;
1201
1192
}
1202
- context . visit ( declarator . id . typeAnnotation , {
1203
- ...context . state ,
1204
- migrate_prop_component_type : true
1205
- } ) ;
1206
1193
return {
1207
1194
type : str . snip ( start , declarator . id . typeAnnotation . end ) . toString ( ) ,
1208
1195
comment
0 commit comments