@@ -137,46 +137,48 @@ export function TranscribeTypeDraftSync(source: string)
137
137
138
138
export async function TranscribeSvelteDraftAsync ( source : string )
139
139
{
140
+ //
140
141
const code = await readFile ( source , "utf8" ) ;
141
- const transcriber = new SvelteTranscriber ( code ) ;
142
- config . dsls . forEach ( dsl => transcriber . AddDSL ( dsl . name , dsl . dsl ) ) ;
143
- const { import_section, script_section, template_section } = transcriber . TranscribeToSections ( ) ;
142
+ const { import_section, script_section, template_section, module_context } = Transcribe ( code ) ;
144
143
145
144
//
146
145
const style = source . replace ( ".svelte.tsx" , ".css" ) ;
147
146
const style_section = await pathExists ( style ) ? await readFile ( style , "utf8" ) : "" ;
148
147
149
148
//
150
- const component = [
151
- "<script>" ,
152
- import_section ,
153
- "\n" ,
154
- script_section ,
155
- "</script>" ,
156
- "\n" ,
157
- template_section ,
158
- "\n" ,
159
- "<style>" ,
160
- style_section ,
161
- "</style>"
162
- ] . join ( "\n" ) ;
163
-
149
+ const component = AssembleComponent ( import_section , script_section , template_section , style_section , module_context ) ;
164
150
return component ;
165
151
}
166
152
167
153
export function TranscribeSvelteDraftSync ( source : string )
168
154
{
155
+ //
169
156
const code = readFileSync ( source , "utf8" ) ;
170
- const transcriber = new SvelteTranscriber ( code ) ;
171
- config . dsls . forEach ( dsl => transcriber . AddDSL ( dsl . name , dsl . dsl ) ) ;
172
- const { import_section, script_section, template_section } = transcriber . TranscribeToSections ( ) ;
157
+ const { import_section, script_section, template_section, module_context } = Transcribe ( code ) ;
173
158
174
159
//
175
160
const style = source . replace ( ".svelte.tsx" , ".css" ) ;
176
161
const style_section = existsSync ( style ) ? readFileSync ( style , "utf8" ) : "" ;
177
162
178
163
//
164
+ const component = AssembleComponent ( import_section , script_section , template_section , style_section , module_context ) ;
165
+ return component ;
166
+ }
167
+
168
+ function Transcribe ( code : string )
169
+ {
170
+ const transcriber = new SvelteTranscriber ( code ) ;
171
+ config . dsls . forEach ( dsl => transcriber . AddDSL ( dsl . name , dsl . dsl ) ) ;
172
+ const module_context = transcriber . ExtractModuleContext ( ) ;
173
+ const { import_section, script_section, template_section } = transcriber . TranscribeToSections ( ) ;
174
+ return { import_section, script_section, template_section, module_context }
175
+ }
176
+
177
+ function AssembleComponent ( import_section : string , script_section : string , template_section : string , style_section : string , module_context : string )
178
+ {
179
+ const module_context_section = module_context ? `<script context="module">\n${ module_context } \n</script>` : "" ;
179
180
const component = [
181
+ module_context_section ,
180
182
"<script>" ,
181
183
import_section ,
182
184
"\n" ,
0 commit comments