@@ -73,15 +73,26 @@ export function analyzeTypeScriptInSvelte(
73
73
74
74
analyzeRuneVariables ( result , ctx , context . svelteParseContext ) ;
75
75
76
- applyTransforms (
77
- [
78
- ...analyzeReactiveScopes ( result ) ,
79
- ...analyzeDollarDerivedScopes ( result , context . svelteParseContext ) ,
80
- ] ,
81
- ctx ,
82
- ) ;
76
+ const scriptTransformers : TransformInfo [ ] = [
77
+ ...analyzeReactiveScopes ( result ) ,
78
+ ] ;
79
+ const templateTransformers : TransformInfo [ ] = [ ] ;
80
+ for ( const transform of analyzeDollarDerivedScopes (
81
+ result ,
82
+ context . svelteParseContext ,
83
+ ) ) {
84
+ if ( transform . node . range [ 0 ] < code . script . length ) {
85
+ scriptTransformers . push ( transform ) ;
86
+ } else {
87
+ templateTransformers . push ( transform ) ;
88
+ }
89
+ }
83
90
84
- analyzeRenderScopes ( code , ctx ) ;
91
+ applyTransforms ( scriptTransformers , ctx ) ;
92
+
93
+ analyzeRenderScopes ( code , ctx , ( ) =>
94
+ applyTransforms ( templateTransformers , ctx ) ,
95
+ ) ;
85
96
86
97
// When performing type checking on TypeScript code that is not a module, the error `Cannot redeclare block-scoped variable 'xxx'`. occurs. To fix this, add an `export`.
87
98
// see: https://github.com/sveltejs/svelte-eslint-parser/issues/557
@@ -625,10 +636,12 @@ function* analyzeDollarDerivedScopes(
625
636
function analyzeRenderScopes (
626
637
code : { script : string ; render : string ; rootScope : string } ,
627
638
ctx : VirtualTypeScriptContext ,
639
+ analyzeInTemplate : ( ) => void ,
628
640
) {
629
641
ctx . appendOriginal ( code . script . length ) ;
630
642
const renderFunctionName = ctx . generateUniqueId ( "render" ) ;
631
643
ctx . appendVirtualScript ( `export function ${ renderFunctionName } (){` ) ;
644
+ analyzeInTemplate ( ) ;
632
645
ctx . appendOriginal ( code . script . length + code . render . length ) ;
633
646
ctx . appendVirtualScript ( `}` ) ;
634
647
ctx . restoreContext . addRestoreStatementProcess ( ( node , result ) => {
0 commit comments