@@ -73,15 +73,26 @@ export function analyzeTypeScriptInSvelte(
7373
7474 analyzeRuneVariables ( result , ctx , context . svelteParseContext ) ;
7575
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+ }
8390
84- analyzeRenderScopes ( code , ctx ) ;
91+ applyTransforms ( scriptTransformers , ctx ) ;
92+
93+ analyzeRenderScopes ( code , ctx , ( ) =>
94+ applyTransforms ( templateTransformers , ctx ) ,
95+ ) ;
8596
8697 // 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`.
8798 // see: https://github.com/sveltejs/svelte-eslint-parser/issues/557
@@ -625,10 +636,12 @@ function* analyzeDollarDerivedScopes(
625636function analyzeRenderScopes (
626637 code : { script : string ; render : string ; rootScope : string } ,
627638 ctx : VirtualTypeScriptContext ,
639+ analyzeInTemplate : ( ) => void ,
628640) {
629641 ctx . appendOriginal ( code . script . length ) ;
630642 const renderFunctionName = ctx . generateUniqueId ( "render" ) ;
631643 ctx . appendVirtualScript ( `export function ${ renderFunctionName } (){` ) ;
644+ analyzeInTemplate ( ) ;
632645 ctx . appendOriginal ( code . script . length + code . render . length ) ;
633646 ctx . appendVirtualScript ( `}` ) ;
634647 ctx . restoreContext . addRestoreStatementProcess ( ( node , result ) => {
0 commit comments