@@ -43,10 +43,10 @@ export function analyzeTypeScriptInSvelte(
43
43
code : { script : string ; rootScope : string ; render : string } ,
44
44
attrs : Record < string , string | undefined > ,
45
45
parserOptions : NormalizedParserOptions ,
46
- context : AnalyzeTypeScriptContext ,
46
+ context : AnalyzeTypeScriptContext
47
47
) : VirtualTypeScriptContext {
48
48
const ctx = new VirtualTypeScriptContext (
49
- code . script + code . render + code . rootScope ,
49
+ code . script + code . render + code . rootScope
50
50
) ;
51
51
ctx . appendOriginal ( / ^ \s * / u. exec ( code . script ) ! [ 0 ] . length ) ;
52
52
@@ -57,7 +57,7 @@ export function analyzeTypeScriptInSvelte(
57
57
...parserOptions ,
58
58
// Without typings
59
59
project : null ,
60
- } ,
60
+ }
61
61
) as unknown as TSESParseForESLintResult ;
62
62
63
63
ctx . _beforeResult = result ;
@@ -68,7 +68,7 @@ export function analyzeTypeScriptInSvelte(
68
68
result ,
69
69
ctx ,
70
70
context . svelteParseContext ,
71
- context . slots ,
71
+ context . slots
72
72
) ;
73
73
74
74
analyzeRuneVariables ( result , ctx , context . svelteParseContext ) ;
@@ -78,7 +78,7 @@ export function analyzeTypeScriptInSvelte(
78
78
...analyzeReactiveScopes ( result ) ,
79
79
...analyzeDollarDerivedScopes ( result , context . svelteParseContext ) ,
80
80
] ,
81
- ctx ,
81
+ ctx
82
82
) ;
83
83
84
84
analyzeRenderScopes ( code , ctx ) ;
@@ -102,7 +102,7 @@ export function analyzeTypeScript(
102
102
code : string ,
103
103
attrs : Record < string , string | undefined > ,
104
104
parserOptions : NormalizedParserOptions ,
105
- svelteParseContext : SvelteParseContext ,
105
+ svelteParseContext : SvelteParseContext
106
106
) : VirtualTypeScriptContext {
107
107
const ctx = new VirtualTypeScriptContext ( code ) ;
108
108
ctx . appendOriginal ( / ^ \s * / u. exec ( code ) ! [ 0 ] . length ) ;
@@ -119,7 +119,7 @@ export function analyzeTypeScript(
119
119
120
120
applyTransforms (
121
121
[ ...analyzeDollarDerivedScopes ( result , svelteParseContext ) ] ,
122
- ctx ,
122
+ ctx
123
123
) ;
124
124
125
125
ctx . appendOriginalToEnd ( ) ;
@@ -146,7 +146,7 @@ function hasExportDeclaration(ast: TSESParseForESLintResult["ast"]): boolean {
146
146
function analyzeStoreReferenceNames (
147
147
result : TSESParseForESLintResult ,
148
148
svelteParseContext : SvelteParseContext ,
149
- ctx : VirtualTypeScriptContext ,
149
+ ctx : VirtualTypeScriptContext
150
150
) {
151
151
const globals = getGlobalsForSvelte ( svelteParseContext ) ;
152
152
const scopeManager = result . scopeManager ;
@@ -175,7 +175,7 @@ function analyzeStoreReferenceNames(
175
175
? F extends (value: infer V, ...args: any) => any
176
176
? V
177
177
: never
178
- : T;` ,
178
+ : T;`
179
179
) ;
180
180
ctx . restoreContext . addRestoreStatementProcess ( ( node , result ) => {
181
181
if (
@@ -199,7 +199,7 @@ function analyzeStoreReferenceNames(
199
199
for ( const nm of maybeStoreRefNames ) {
200
200
const realName = nm . slice ( 1 ) ;
201
201
ctx . appendVirtualScript (
202
- `declare let ${ nm } : ${ storeValueTypeName } <typeof ${ realName } >;` ,
202
+ `declare let ${ nm } : ${ storeValueTypeName } <typeof ${ realName } >;`
203
203
) ;
204
204
ctx . restoreContext . addRestoreStatementProcess ( ( node , result ) => {
205
205
if (
@@ -236,14 +236,14 @@ function analyzeDollarDollarVariables(
236
236
result : TSESParseForESLintResult ,
237
237
ctx : VirtualTypeScriptContext ,
238
238
svelteParseContext : SvelteParseContext ,
239
- slots : Set < SvelteHTMLElement > ,
239
+ slots : Set < SvelteHTMLElement >
240
240
) {
241
241
const globals = getGlobalsForSvelte ( svelteParseContext ) ;
242
242
const scopeManager = result . scopeManager ;
243
243
for ( const globalName of globals ) {
244
244
if (
245
245
! scopeManager . globalScope ! . through . some (
246
- ( reference ) => reference . identifier . name === globalName ,
246
+ ( reference ) => reference . identifier . name === globalName
247
247
)
248
248
) {
249
249
continue ;
@@ -260,7 +260,7 @@ function analyzeDollarDollarVariables(
260
260
for ( const slot of slots ) {
261
261
const nameAttr = slot . startTag . attributes . find (
262
262
( attr ) : attr is SvelteAttribute =>
263
- attr . type === "SvelteAttribute" && attr . key . name === "name" ,
263
+ attr . type === "SvelteAttribute" && attr . key . name === "name"
264
264
) ;
265
265
if ( ! nameAttr || nameAttr . value . length === 0 ) {
266
266
nameTypes . add ( '"default"' ) ;
@@ -281,17 +281,17 @@ function analyzeDollarDollarVariables(
281
281
. map ( ( value ) =>
282
282
value . type === "SvelteLiteral"
283
283
? value . value . replace ( / ( [ $ ` ] ) / gu, "\\$1" )
284
- : "${string}" ,
284
+ : "${string}"
285
285
)
286
- . join ( "" ) } \``,
286
+ . join ( "" ) } \``
287
287
) ;
288
288
}
289
289
290
290
appendDeclareVirtualScript (
291
291
globalName ,
292
292
`Record<${
293
293
nameTypes . size > 0 ? [ ...nameTypes ] . join ( " | " ) : "any"
294
- } , boolean>`,
294
+ } , boolean>`
295
295
) ;
296
296
break ;
297
297
}
@@ -375,7 +375,7 @@ function appendDummyExport(ctx: VirtualTypeScriptContext) {
375
375
function analyzeRuneVariables (
376
376
result : TSESParseForESLintResult ,
377
377
ctx : VirtualTypeScriptContext ,
378
- svelteParseContext : SvelteParseContext ,
378
+ svelteParseContext : SvelteParseContext
379
379
) {
380
380
// No processing is needed if the user is determined not to be in Runes mode.
381
381
if ( svelteParseContext . runes === false ) {
@@ -385,13 +385,13 @@ function analyzeRuneVariables(
385
385
for ( const globalName of globalsForRunes ) {
386
386
if (
387
387
! scopeManager . globalScope ! . through . some (
388
- ( reference ) => reference . identifier . name === globalName ,
388
+ ( reference ) => reference . identifier . name === globalName
389
389
)
390
390
) {
391
391
continue ;
392
392
}
393
393
switch ( globalName ) {
394
- // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16 /packages/svelte/types/index.d.ts#L2299
394
+ // See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d /packages/svelte/types/index.d.ts#L2679
395
395
case "$state" : {
396
396
appendDeclareFunctionVirtualScripts ( globalName , [
397
397
"<T>(initial: T): T" ,
@@ -407,7 +407,7 @@ function analyzeRuneVariables(
407
407
408
408
break ;
409
409
}
410
- // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16 /packages/svelte/types/index.d.ts#L2453
410
+ // See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d /packages/svelte/types/index.d.ts#L2833
411
411
case "$derived" : {
412
412
appendDeclareFunctionVirtualScripts ( globalName , [
413
413
"<T>(expression: T): T" ,
@@ -417,7 +417,7 @@ function analyzeRuneVariables(
417
417
] ) ;
418
418
break ;
419
419
}
420
- // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16 /packages/svelte/types/index.d.ts#L2513
420
+ // See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d /packages/svelte/types/index.d.ts#L2893
421
421
case "$effect" : {
422
422
appendDeclareFunctionVirtualScripts ( globalName , [
423
423
"(fn: () => void | (() => void)): void" ,
@@ -429,27 +429,33 @@ function analyzeRuneVariables(
429
429
] ) ;
430
430
break ;
431
431
}
432
- // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16 /packages/svelte/types/index.d.ts#L2615
432
+ // See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d /packages/svelte/types/index.d.ts#L2997
433
433
case "$props" : {
434
434
// Use type parameters to avoid `@typescript-eslint/no-unsafe-assignment` errors.
435
435
appendDeclareFunctionVirtualScripts ( globalName , [ "<T>(): T" ] ) ;
436
+ appendDeclareNamespaceVirtualScripts ( globalName , [
437
+ "export function id(): string;" ,
438
+ ] ) ;
436
439
break ;
437
440
}
438
- // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16 /packages/svelte/types/index.d.ts#L2626
441
+ // See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d /packages/svelte/types/index.d.ts#L3038
439
442
case "$bindable" : {
440
443
appendDeclareFunctionVirtualScripts ( globalName , [
441
444
"<T>(fallback?: T): T" ,
442
445
] ) ;
443
446
break ;
444
447
}
445
- // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16 /packages/svelte/types/index.d.ts#L2646
448
+ // See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d /packages/svelte/types/index.d.ts#L3081
446
449
case "$inspect" : {
447
450
appendDeclareFunctionVirtualScripts ( globalName , [
448
451
`<T extends any[]>(...values: T): { with: (fn: (type: 'init' | 'update', ...values: T) => void) => void }` ,
449
452
] ) ;
453
+ appendDeclareNamespaceVirtualScripts ( globalName , [
454
+ "export function trace(name?: string): void;" ,
455
+ ] ) ;
450
456
break ;
451
457
}
452
- // See https://github.com/sveltejs/svelte/blob/41b5cd6f5daae3970a9927e062f42b6b62440d16 /packages/svelte/types/index.d.ts#L2669
458
+ // See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d /packages/svelte/types/index.d.ts#L3144
453
459
case "$host" : {
454
460
appendDeclareFunctionVirtualScripts ( globalName , [
455
461
`<El extends HTMLElement = HTMLElement>(): El` ,
@@ -494,7 +500,7 @@ function analyzeRuneVariables(
494
500
495
501
function appendDeclareNamespaceVirtualScripts (
496
502
name : string ,
497
- scripts : string [ ] ,
503
+ scripts : string [ ]
498
504
) {
499
505
for ( const script of scripts ) {
500
506
ctx . appendVirtualScript ( `declare namespace ${ name } { ${ script } }` ) ;
@@ -529,11 +535,11 @@ function analyzeRuneVariables(
529
535
* Transform source code to provide the correct type information in the `$:` statements.
530
536
*/
531
537
function * analyzeReactiveScopes (
532
- result : TSESParseForESLintResult ,
538
+ result : TSESParseForESLintResult
533
539
) : Iterable < TransformInfo > {
534
540
const scopeManager = result . scopeManager ;
535
541
const throughIds = scopeManager . globalScope ! . through . map (
536
- ( reference ) => reference . identifier ,
542
+ ( reference ) => reference . identifier
537
543
) ;
538
544
for ( const statement of result . ast . body ) {
539
545
if ( statement . type === "LabeledStatement" && statement . label . name === "$" ) {
@@ -550,8 +556,7 @@ function* analyzeReactiveScopes(
550
556
const left = statement . body . expression . left ;
551
557
if (
552
558
throughIds . some (
553
- ( id ) =>
554
- left . range [ 0 ] <= id . range [ 0 ] && id . range [ 1 ] <= left . range [ 1 ] ,
559
+ ( id ) => left . range [ 0 ] <= id . range [ 0 ] && id . range [ 1 ] <= left . range [ 1 ]
555
560
)
556
561
) {
557
562
const node = statement ;
@@ -564,7 +569,7 @@ function* analyzeReactiveScopes(
564
569
left ,
565
570
expression ,
566
571
result . ast . tokens ,
567
- ctx ,
572
+ ctx
568
573
) ,
569
574
} ;
570
575
continue ;
@@ -584,13 +589,13 @@ function* analyzeReactiveScopes(
584
589
*/
585
590
function * analyzeDollarDerivedScopes (
586
591
result : TSESParseForESLintResult ,
587
- svelteParseContext : SvelteParseContext ,
592
+ svelteParseContext : SvelteParseContext
588
593
) : Iterable < TransformInfo > {
589
594
// No processing is needed if the user is determined not to be in Runes mode.
590
595
if ( svelteParseContext . runes === false ) return ;
591
596
const scopeManager = result . scopeManager ;
592
597
const derivedReferences = scopeManager . globalScope ! . through . filter (
593
- ( reference ) => reference . identifier . name === "$derived" ,
598
+ ( reference ) => reference . identifier . name === "$derived"
594
599
) ;
595
600
if ( ! derivedReferences . length ) {
596
601
return ;
@@ -618,7 +623,7 @@ function* analyzeDollarDerivedScopes(
618
623
*/
619
624
function analyzeRenderScopes (
620
625
code : { script : string ; render : string ; rootScope : string } ,
621
- ctx : VirtualTypeScriptContext ,
626
+ ctx : VirtualTypeScriptContext
622
627
) {
623
628
ctx . appendOriginal ( code . script . length ) ;
624
629
const renderFunctionName = ctx . generateUniqueId ( "render" ) ;
@@ -637,7 +642,7 @@ function analyzeRenderScopes(
637
642
program . body . splice (
638
643
program . body . indexOf ( node ) ,
639
644
1 ,
640
- ...node . declaration . body . body ,
645
+ ...node . declaration . body . body
641
646
) ;
642
647
for ( const body of node . declaration . body . body ) {
643
648
body . parent = program ;
@@ -655,7 +660,7 @@ function analyzeRenderScopes(
655
660
*/
656
661
function applyTransforms (
657
662
transforms : TransformInfo [ ] ,
658
- ctx : VirtualTypeScriptContext ,
663
+ ctx : VirtualTypeScriptContext
659
664
) {
660
665
transforms . sort ( ( a , b ) => a . node . range [ 0 ] - b . node . range [ 0 ] ) ;
661
666
@@ -677,7 +682,7 @@ function transformForDeclareReactiveVar(
677
682
id : TSESTree . Identifier | TSESTree . ArrayPattern | TSESTree . ObjectPattern ,
678
683
expression : TSESTree . AssignmentExpression ,
679
684
tokens : TSESTree . Token [ ] ,
680
- ctx : VirtualTypeScriptContext ,
685
+ ctx : VirtualTypeScriptContext
681
686
) : void {
682
687
// e.g.
683
688
// From:
@@ -721,7 +726,7 @@ function transformForDeclareReactiveVar(
721
726
let expressionCloseParen : TSESTree . Token | null = null ;
722
727
const startIndex = sortedLastIndex (
723
728
tokens ,
724
- ( target ) => target . range [ 0 ] - statement . range [ 0 ] ,
729
+ ( target ) => target . range [ 0 ] - statement . range [ 0 ]
725
730
) ;
726
731
for ( let index = startIndex ; index < tokens . length ; index ++ ) {
727
732
const token = tokens [ index ] ;
@@ -761,7 +766,7 @@ function transformForDeclareReactiveVar(
761
766
ctx . appendVirtualScript ( "let " ) ;
762
767
ctx . appendOriginal ( eq ? eq . range [ 1 ] : expression . right . range [ 0 ] ) ;
763
768
ctx . appendVirtualScript (
764
- `${ functionId } ();\nfunction ${ functionId } (){let ${ tmpVarId } ;return (${ tmpVarId } = ` ,
769
+ `${ functionId } ();\nfunction ${ functionId } (){let ${ tmpVarId } ;return (${ tmpVarId } = `
765
770
) ;
766
771
ctx . appendOriginal ( expression . right . range [ 1 ] ) ;
767
772
ctx . appendVirtualScript ( `)` ) ;
@@ -867,7 +872,7 @@ function transformForDeclareReactiveVar(
867
872
addElementsToSortedArray (
868
873
program . tokens ,
869
874
[ ...openParens , ...closeParens ] ,
870
- ( a , b ) => a . range [ 0 ] - b . range [ 0 ] ,
875
+ ( a , b ) => a . range [ 0 ] - b . range [ 0 ]
871
876
) ;
872
877
873
878
const scopeManager = result . scopeManager as ScopeManager ;
@@ -896,7 +901,7 @@ function transformForDeclareReactiveVar(
896
901
*/
897
902
function transformForReactiveStatement (
898
903
statement : TSESTree . LabeledStatement ,
899
- ctx : VirtualTypeScriptContext ,
904
+ ctx : VirtualTypeScriptContext
900
905
) {
901
906
const functionId = ctx . generateUniqueId ( "reactiveStatementScopeFunction" ) ;
902
907
const originalBody = statement . body ;
@@ -933,13 +938,13 @@ function transformForReactiveStatement(
933
938
*/
934
939
function transformForDollarDerived (
935
940
derivedCall : TSESTree . CallExpression ,
936
- ctx : VirtualTypeScriptContext ,
941
+ ctx : VirtualTypeScriptContext
937
942
) {
938
943
const functionId = ctx . generateUniqueId ( "$derivedArgument" ) ;
939
944
const expression = derivedCall . arguments [ 0 ] ;
940
945
ctx . appendOriginal ( expression . range [ 0 ] ) ;
941
946
ctx . appendVirtualScript (
942
- `(()=>{return ${ functionId } ();function ${ functionId } (){return ` ,
947
+ `(()=>{return ${ functionId } ();function ${ functionId } (){return `
943
948
) ;
944
949
ctx . appendOriginal ( expression . range [ 1 ] ) ;
945
950
ctx . appendVirtualScript ( `}})()` ) ;
@@ -988,7 +993,7 @@ function transformForDollarDerived(
988
993
removeFunctionScope ( arg . callee . body . body [ 1 ] , scopeManager ) ;
989
994
removeIdentifierReference (
990
995
arg . callee . body . body [ 0 ] . argument . callee ,
991
- scopeManager . acquire ( arg . callee ) ! ,
996
+ scopeManager . acquire ( arg . callee ) !
992
997
) ;
993
998
removeFunctionScope ( arg . callee , scopeManager ) ;
994
999
return true ;
@@ -1002,7 +1007,7 @@ function removeFunctionScope(
1002
1007
| TSESTree . FunctionDeclaration
1003
1008
| TSESTree . FunctionExpression
1004
1009
| TSESTree . ArrowFunctionExpression ,
1005
- scopeManager : ScopeManager ,
1010
+ scopeManager : ScopeManager
1006
1011
) {
1007
1012
const scope = scopeManager . acquire ( node ) ! ;
1008
1013
const upper = scope . upper ! ;
@@ -1024,12 +1029,12 @@ function removeFunctionScope(
1024
1029
addElementsToSortedArray (
1025
1030
upperVariable . identifiers ,
1026
1031
variable . identifiers ,
1027
- ( a , b ) => a . range ! [ 0 ] - b . range ! [ 0 ] ,
1032
+ ( a , b ) => a . range ! [ 0 ] - b . range ! [ 0 ]
1028
1033
) ;
1029
1034
addElementsToSortedArray (
1030
1035
upperVariable . defs ,
1031
1036
variable . defs ,
1032
- ( a , b ) => a . node . range ! [ 0 ] - b . node . range ! [ 0 ] ,
1037
+ ( a , b ) => a . node . range ! [ 0 ] - b . node . range ! [ 0 ]
1033
1038
) ;
1034
1039
addAllReferences ( upperVariable . references , variable . references ) ;
1035
1040
} else {
0 commit comments