@@ -40,6 +40,7 @@ import {
40
40
} from '../svelte2tsx/nodes/handleScopeAndResolveForSlot' ;
41
41
import { EventHandler } from '../svelte2tsx/nodes/event-handler' ;
42
42
import { ComponentEvents } from '../svelte2tsx/nodes/ComponentEvents' ;
43
+ import { analyze } from 'periscopic' ;
43
44
44
45
export interface TemplateProcessResult {
45
46
/**
@@ -53,7 +54,7 @@ export interface TemplateProcessResult {
53
54
scriptTag : BaseNode ;
54
55
moduleScriptTag : BaseNode ;
55
56
/** Start/end positions of snippets that should be moved to the instance script or possibly even module script */
56
- rootSnippets : Array < [ number , number ] > ;
57
+ rootSnippets : Array < [ start : number , end : number , globals : Map < string , any > ] > ;
57
58
/** To be added later as a comment on the default class export */
58
59
componentDocumentation : ComponentDocumentation ;
59
60
events : ComponentEvents ;
@@ -92,7 +93,7 @@ export function convertHtmlxToJsx(
92
93
93
94
stripDoctype ( str ) ;
94
95
95
- const rootSnippets : Array < [ number , number ] > = [ ] ;
96
+ const rootSnippets : Array < [ number , number , Map < string , any > ] > = [ ] ;
96
97
let element : Element | InlineComponent | undefined ;
97
98
98
99
const pendingSnippetHoistCheck = new Set < BaseNode > ( ) ;
@@ -249,7 +250,21 @@ export function convertHtmlxToJsx(
249
250
) ;
250
251
if ( parent === ast ) {
251
252
// root snippet -> move to instance script or possibly even module script
252
- rootSnippets . push ( [ node . start , node . end ] ) ;
253
+ const result = analyze ( {
254
+ type : 'FunctionDeclaration' ,
255
+ start : - 1 ,
256
+ end : - 1 ,
257
+ id : node . expression ,
258
+ params : node . parameters ?? [ ] ,
259
+ body : {
260
+ type : 'BlockStatement' ,
261
+ start : - 1 ,
262
+ end : - 1 ,
263
+ body : node . children as any [ ] // wrong AST, but periscopic doesn't care
264
+ }
265
+ } ) ;
266
+
267
+ rootSnippets . push ( [ node . start , node . end , result . globals ] ) ;
253
268
} else {
254
269
pendingSnippetHoistCheck . add ( parent ) ;
255
270
}
0 commit comments