@@ -38,10 +38,10 @@ export function analyzeTypeScriptInSvelte(
38
38
code : { script : string ; rootScope : string ; render : string } ,
39
39
attrs : Record < string , string | undefined > ,
40
40
parserOptions : NormalizedParserOptions ,
41
- context : AnalyzeTypeScriptContext ,
41
+ context : AnalyzeTypeScriptContext
42
42
) : VirtualTypeScriptContext {
43
43
const ctx = new VirtualTypeScriptContext (
44
- code . script + code . render + code . rootScope ,
44
+ code . script + code . render + code . rootScope
45
45
) ;
46
46
ctx . appendOriginal ( / ^ \s * / u. exec ( code . script ) ! [ 0 ] . length ) ;
47
47
@@ -52,7 +52,7 @@ export function analyzeTypeScriptInSvelte(
52
52
...parserOptions ,
53
53
// Without typings
54
54
project : null ,
55
- } ,
55
+ }
56
56
) as unknown as TSESParseForESLintResult ;
57
57
58
58
ctx . _beforeResult = result ;
@@ -65,7 +65,7 @@ export function analyzeTypeScriptInSvelte(
65
65
66
66
applyTransforms (
67
67
[ ...analyzeReactiveScopes ( result ) , ...analyzeDollarDerivedScopes ( result ) ] ,
68
- ctx ,
68
+ ctx
69
69
) ;
70
70
71
71
analyzeRenderScopes ( code , ctx ) ;
@@ -82,7 +82,7 @@ export function analyzeTypeScriptInSvelte(
82
82
export function analyzeTypeScript (
83
83
code : string ,
84
84
attrs : Record < string , string | undefined > ,
85
- parserOptions : NormalizedParserOptions ,
85
+ parserOptions : NormalizedParserOptions
86
86
) : VirtualTypeScriptContext {
87
87
const ctx = new VirtualTypeScriptContext ( code ) ;
88
88
ctx . appendOriginal ( / ^ \s * / u. exec ( code ) ! [ 0 ] . length ) ;
@@ -110,7 +110,7 @@ export function analyzeTypeScript(
110
110
*/
111
111
function analyzeStoreReferenceNames (
112
112
result : TSESParseForESLintResult ,
113
- ctx : VirtualTypeScriptContext ,
113
+ ctx : VirtualTypeScriptContext
114
114
) {
115
115
const scopeManager = result . scopeManager ;
116
116
const programScope = getProgramScope ( scopeManager as ScopeManager ) ;
@@ -138,7 +138,7 @@ function analyzeStoreReferenceNames(
138
138
? F extends (value: infer V, ...args: any) => any
139
139
? V
140
140
: never
141
- : T;` ,
141
+ : T;`
142
142
) ;
143
143
ctx . restoreContext . addRestoreStatementProcess ( ( node , result ) => {
144
144
if (
@@ -162,7 +162,7 @@ function analyzeStoreReferenceNames(
162
162
for ( const nm of maybeStoreRefNames ) {
163
163
const realName = nm . slice ( 1 ) ;
164
164
ctx . appendVirtualScript (
165
- `declare let ${ nm } : ${ storeValueTypeName } <typeof ${ realName } >;` ,
165
+ `declare let ${ nm } : ${ storeValueTypeName } <typeof ${ realName } >;`
166
166
) ;
167
167
ctx . restoreContext . addRestoreStatementProcess ( ( node , result ) => {
168
168
if (
@@ -198,13 +198,13 @@ function analyzeStoreReferenceNames(
198
198
function analyzeDollarDollarVariables (
199
199
result : TSESParseForESLintResult ,
200
200
ctx : VirtualTypeScriptContext ,
201
- slots : Set < SvelteHTMLElement > ,
201
+ slots : Set < SvelteHTMLElement >
202
202
) {
203
203
const scopeManager = result . scopeManager ;
204
204
for ( const globalName of globals ) {
205
205
if (
206
206
! scopeManager . globalScope ! . through . some (
207
- ( reference ) => reference . identifier . name === globalName ,
207
+ ( reference ) => reference . identifier . name === globalName
208
208
)
209
209
) {
210
210
continue ;
@@ -221,7 +221,7 @@ function analyzeDollarDollarVariables(
221
221
for ( const slot of slots ) {
222
222
const nameAttr = slot . startTag . attributes . find (
223
223
( attr ) : attr is SvelteAttribute =>
224
- attr . type === "SvelteAttribute" && attr . key . name === "name" ,
224
+ attr . type === "SvelteAttribute" && attr . key . name === "name"
225
225
) ;
226
226
if ( ! nameAttr || nameAttr . value . length === 0 ) {
227
227
nameTypes . add ( '"default"' ) ;
@@ -242,17 +242,17 @@ function analyzeDollarDollarVariables(
242
242
. map ( ( value ) =>
243
243
value . type === "SvelteLiteral"
244
244
? value . value . replace ( / ( [ $ ` ] ) / gu, "\\$1" )
245
- : "${string}" ,
245
+ : "${string}"
246
246
)
247
- . join ( "" ) } \``,
247
+ . join ( "" ) } \``
248
248
) ;
249
249
}
250
250
251
251
appendDeclareVirtualScript (
252
252
globalName ,
253
253
`Record<${
254
254
nameTypes . size > 0 ? [ ...nameTypes ] . join ( " | " ) : "any"
255
- } , boolean>`,
255
+ } , boolean>`
256
256
) ;
257
257
break ;
258
258
}
@@ -306,13 +306,13 @@ function analyzeDollarDollarVariables(
306
306
*/
307
307
function analyzeRuneVariables (
308
308
result : TSESParseForESLintResult ,
309
- ctx : VirtualTypeScriptContext ,
309
+ ctx : VirtualTypeScriptContext
310
310
) {
311
311
const scopeManager = result . scopeManager ;
312
312
for ( const globalName of globalsForRunes ) {
313
313
if (
314
314
! scopeManager . globalScope ! . through . some (
315
- ( reference ) => reference . identifier . name === globalName ,
315
+ ( reference ) => reference . identifier . name === globalName
316
316
)
317
317
) {
318
318
continue ;
@@ -354,7 +354,7 @@ function analyzeRuneVariables(
354
354
}
355
355
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2655
356
356
case "$props" : {
357
- appendDeclareFunctionVirtualScripts ( globalName , [ "<T> (): T " ] ) ;
357
+ appendDeclareFunctionVirtualScripts ( globalName , [ "(): any " ] ) ;
358
358
break ;
359
359
}
360
360
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2666
@@ -407,7 +407,7 @@ function analyzeRuneVariables(
407
407
408
408
function appendDeclareNamespaceVirtualScripts (
409
409
name : string ,
410
- scripts : string [ ] ,
410
+ scripts : string [ ]
411
411
) {
412
412
for ( const script of scripts ) {
413
413
ctx . appendVirtualScript ( `declare namespace ${ name } { ${ script } }` ) ;
@@ -442,11 +442,11 @@ function analyzeRuneVariables(
442
442
* Transform source code to provide the correct type information in the `$:` statements.
443
443
*/
444
444
function * analyzeReactiveScopes (
445
- result : TSESParseForESLintResult ,
445
+ result : TSESParseForESLintResult
446
446
) : Iterable < TransformInfo > {
447
447
const scopeManager = result . scopeManager ;
448
448
const throughIds = scopeManager . globalScope ! . through . map (
449
- ( reference ) => reference . identifier ,
449
+ ( reference ) => reference . identifier
450
450
) ;
451
451
for ( const statement of result . ast . body ) {
452
452
if ( statement . type === "LabeledStatement" && statement . label . name === "$" ) {
@@ -463,8 +463,7 @@ function* analyzeReactiveScopes(
463
463
const left = statement . body . expression . left ;
464
464
if (
465
465
throughIds . some (
466
- ( id ) =>
467
- left . range [ 0 ] <= id . range [ 0 ] && id . range [ 1 ] <= left . range [ 1 ] ,
466
+ ( id ) => left . range [ 0 ] <= id . range [ 0 ] && id . range [ 1 ] <= left . range [ 1 ]
468
467
)
469
468
) {
470
469
const node = statement ;
@@ -477,7 +476,7 @@ function* analyzeReactiveScopes(
477
476
left ,
478
477
expression ,
479
478
result . ast . tokens ! ,
480
- ctx ,
479
+ ctx
481
480
) ,
482
481
} ;
483
482
continue ;
@@ -496,11 +495,11 @@ function* analyzeReactiveScopes(
496
495
* Transform source code to provide the correct type information in the `$derived(...)` expression.
497
496
*/
498
497
function * analyzeDollarDerivedScopes (
499
- result : TSESParseForESLintResult ,
498
+ result : TSESParseForESLintResult
500
499
) : Iterable < TransformInfo > {
501
500
const scopeManager = result . scopeManager ;
502
501
const derivedReferences = scopeManager . globalScope ! . through . filter (
503
- ( reference ) => reference . identifier . name === "$derived" ,
502
+ ( reference ) => reference . identifier . name === "$derived"
504
503
) ;
505
504
if ( ! derivedReferences . length ) {
506
505
return ;
@@ -528,7 +527,7 @@ function* analyzeDollarDerivedScopes(
528
527
*/
529
528
function analyzeRenderScopes (
530
529
code : { script : string ; render : string ; rootScope : string } ,
531
- ctx : VirtualTypeScriptContext ,
530
+ ctx : VirtualTypeScriptContext
532
531
) {
533
532
ctx . appendOriginal ( code . script . length ) ;
534
533
const renderFunctionName = ctx . generateUniqueId ( "render" ) ;
@@ -560,7 +559,7 @@ function analyzeRenderScopes(
560
559
*/
561
560
function applyTransforms (
562
561
transforms : TransformInfo [ ] ,
563
- ctx : VirtualTypeScriptContext ,
562
+ ctx : VirtualTypeScriptContext
564
563
) {
565
564
transforms . sort ( ( a , b ) => a . node . range [ 0 ] - b . node . range [ 0 ] ) ;
566
565
@@ -582,7 +581,7 @@ function transformForDeclareReactiveVar(
582
581
id : TSESTree . Identifier | TSESTree . ArrayPattern | TSESTree . ObjectPattern ,
583
582
expression : TSESTree . AssignmentExpression ,
584
583
tokens : TSESTree . Token [ ] ,
585
- ctx : VirtualTypeScriptContext ,
584
+ ctx : VirtualTypeScriptContext
586
585
) : void {
587
586
// e.g.
588
587
// From:
@@ -626,7 +625,7 @@ function transformForDeclareReactiveVar(
626
625
let expressionCloseParen : TSESTree . Token | null = null ;
627
626
const startIndex = sortedLastIndex (
628
627
tokens ,
629
- ( target ) => target . range [ 0 ] - statement . range [ 0 ] ,
628
+ ( target ) => target . range [ 0 ] - statement . range [ 0 ]
630
629
) ;
631
630
for ( let index = startIndex ; index < tokens . length ; index ++ ) {
632
631
const token = tokens [ index ] ;
@@ -666,7 +665,7 @@ function transformForDeclareReactiveVar(
666
665
ctx . appendVirtualScript ( "let " ) ;
667
666
ctx . appendOriginal ( eq ? eq . range [ 1 ] : expression . right . range [ 0 ] ) ;
668
667
ctx . appendVirtualScript (
669
- `${ functionId } ();\nfunction ${ functionId } (){let ${ tmpVarId } ;return (${ tmpVarId } = ` ,
668
+ `${ functionId } ();\nfunction ${ functionId } (){let ${ tmpVarId } ;return (${ tmpVarId } = `
670
669
) ;
671
670
ctx . appendOriginal ( expression . right . range [ 1 ] ) ;
672
671
ctx . appendVirtualScript ( `)` ) ;
@@ -772,7 +771,7 @@ function transformForDeclareReactiveVar(
772
771
addElementsToSortedArray (
773
772
program . tokens ! ,
774
773
[ ...openParens , ...closeParens ] ,
775
- ( a , b ) => a . range [ 0 ] - b . range [ 0 ] ,
774
+ ( a , b ) => a . range [ 0 ] - b . range [ 0 ]
776
775
) ;
777
776
778
777
const scopeManager = result . scopeManager as ScopeManager ;
@@ -801,7 +800,7 @@ function transformForDeclareReactiveVar(
801
800
*/
802
801
function transformForReactiveStatement (
803
802
statement : TSESTree . LabeledStatement ,
804
- ctx : VirtualTypeScriptContext ,
803
+ ctx : VirtualTypeScriptContext
805
804
) {
806
805
const functionId = ctx . generateUniqueId ( "reactiveStatementScopeFunction" ) ;
807
806
const originalBody = statement . body ;
@@ -834,13 +833,13 @@ function transformForReactiveStatement(
834
833
*/
835
834
function transformForDollarDerived (
836
835
derivedCall : TSESTree . CallExpression ,
837
- ctx : VirtualTypeScriptContext ,
836
+ ctx : VirtualTypeScriptContext
838
837
) {
839
838
const functionId = ctx . generateUniqueId ( "$derivedArgument" ) ;
840
839
const expression = derivedCall . arguments [ 0 ] ;
841
840
ctx . appendOriginal ( expression . range [ 0 ] ) ;
842
841
ctx . appendVirtualScript (
843
- `(()=>{return ${ functionId } ();function ${ functionId } (){return ` ,
842
+ `(()=>{return ${ functionId } ();function ${ functionId } (){return `
844
843
) ;
845
844
ctx . appendOriginal ( expression . range [ 1 ] ) ;
846
845
ctx . appendVirtualScript ( `}})()` ) ;
@@ -889,7 +888,7 @@ function transformForDollarDerived(
889
888
removeFunctionScope ( arg . callee . body . body [ 1 ] , scopeManager ) ;
890
889
removeIdentifierReference (
891
890
arg . callee . body . body [ 0 ] . argument . callee ,
892
- scopeManager . acquire ( arg . callee ) ! ,
891
+ scopeManager . acquire ( arg . callee ) !
893
892
) ;
894
893
removeFunctionScope ( arg . callee , scopeManager ) ;
895
894
return true ;
@@ -903,7 +902,7 @@ function removeFunctionScope(
903
902
| TSESTree . FunctionDeclaration
904
903
| TSESTree . FunctionExpression
905
904
| TSESTree . ArrowFunctionExpression ,
906
- scopeManager : ScopeManager ,
905
+ scopeManager : ScopeManager
907
906
) {
908
907
const scope = scopeManager . acquire ( node ) ! ;
909
908
const upper = scope . upper ! ;
@@ -925,12 +924,12 @@ function removeFunctionScope(
925
924
addElementsToSortedArray (
926
925
upperVariable . identifiers ,
927
926
variable . identifiers ,
928
- ( a , b ) => a . range ! [ 0 ] - b . range ! [ 0 ] ,
927
+ ( a , b ) => a . range ! [ 0 ] - b . range ! [ 0 ]
929
928
) ;
930
929
addElementsToSortedArray (
931
930
upperVariable . defs ,
932
931
variable . defs ,
933
- ( a , b ) => a . node . range ! [ 0 ] - b . node . range ! [ 0 ] ,
932
+ ( a , b ) => a . node . range ! [ 0 ] - b . node . range ! [ 0 ]
934
933
) ;
935
934
addAllReferences ( upperVariable . references , variable . references ) ;
936
935
} else {
0 commit comments