@@ -23,17 +23,19 @@ const DEFINE_MODEL = 'defineModel'
23
23
* Pre-transpile script setup block to remove type syntax and replace it with runtime declarations.
24
24
* This function only performs minimal error checking, it means that it will preserve all errors that can be triggered at runtime
25
25
*/
26
- export async function preTranspileScriptSetup ( sfc : SFCDescriptor & { scriptSetup : SFCScriptBlock } , id : string ) : Promise < SFCScriptBlock > {
27
- const context = await prepareContext ( sfc , id )
26
+ export async function preTranspileScriptSetup ( sfc : SFCDescriptor , id : string ) : Promise < SFCScriptBlock > {
27
+ if ( ! sfc . scriptSetup ) {
28
+ throw new Error ( 'No script setup block found' )
29
+ }
30
+ const context = await prepareContext ( sfc as SFCDescriptor & { scriptSetup : SFCScriptBlock } , id )
28
31
const resultBuilder = new context . utils . MagicString ( sfc . scriptSetup . content )
29
32
30
33
for ( const node of context . ctx . ast ) {
31
34
if ( node . type === 'ExpressionStatement' ) {
32
- const processedTypeSyntax
33
- = processDefineProps ( node . expression , context )
34
- || processDefineEmits ( node . expression , context )
35
- || processWithDefaults ( node . expression , context )
36
- || processDefineModel ( node . expression , context )
35
+ const processedTypeSyntax = processDefineProps ( node . expression , context )
36
+ || processDefineEmits ( node . expression , context )
37
+ || processWithDefaults ( node . expression , context )
38
+ || processDefineModel ( node . expression , context )
37
39
38
40
if ( processedTypeSyntax !== undefined ) {
39
41
resultBuilder . overwrite ( node . start ! , node . end ! , processedTypeSyntax )
0 commit comments