@@ -206,7 +206,7 @@ function parseScript(
206
206
*/
207
207
export function parseScriptSetupElements (
208
208
scriptSetupElement : VElement ,
209
- scriptElement : VElement ,
209
+ scriptElements : VElement [ ] ,
210
210
sfcCode : string ,
211
211
linesAndColumns : LinesAndColumns ,
212
212
originalParserOptions : ParserOptions ,
@@ -216,7 +216,7 @@ export function parseScriptSetupElements(
216
216
)
217
217
const scriptSetupModuleCodeBlocks = getScriptSetupModuleCodeBlocks (
218
218
scriptSetupElement ,
219
- scriptElement ,
219
+ scriptElements ,
220
220
sfcCode ,
221
221
linesAndColumns ,
222
222
parserOptions ,
@@ -283,7 +283,7 @@ export function parseScriptSetupElements(
283
283
284
284
// Adjust AST and tokens
285
285
if ( result . ast . tokens != null ) {
286
- for ( const node of [ scriptSetupElement , scriptElement ] ) {
286
+ for ( const node of [ scriptSetupElement , ... scriptElements ] ) {
287
287
const startTag = node . startTag
288
288
const endTag = node . endTag
289
289
@@ -314,7 +314,7 @@ export function parseScriptSetupElements(
314
314
result . ast . loc . start =
315
315
locationCalculator . getLocFromIndex ( programStartOffset )
316
316
if ( result . ast . start != null ) {
317
- result . ast . start = [ scriptSetupElement , scriptElement ] . reduce (
317
+ result . ast . start = [ scriptSetupElement , ... scriptElements ] . reduce (
318
318
( start , node ) => {
319
319
const textNode = node . children [ 0 ]
320
320
return Math . min (
@@ -335,7 +335,7 @@ export function parseScriptSetupElements(
335
335
result . ast . range [ 1 ] = programEndOffset
336
336
result . ast . loc . end = locationCalculator . getLocFromIndex ( programEndOffset )
337
337
if ( result . ast . end != null ) {
338
- result . ast . end = [ scriptSetupElement , scriptElement ] . reduce (
338
+ result . ast . end = [ scriptSetupElement , ... scriptElements ] . reduce (
339
339
( end , node ) => {
340
340
const textNode = node . children [ 0 ]
341
341
return Math . max (
@@ -447,7 +447,7 @@ export function parseScriptSetupElements(
447
447
*/
448
448
function getScriptSetupModuleCodeBlocks (
449
449
scriptSetupElement : VElement ,
450
- scriptElement : VElement ,
450
+ scriptElements : VElement [ ] ,
451
451
sfcCode : string ,
452
452
linesAndColumns : LinesAndColumns ,
453
453
parserOptions : ParserOptions ,
@@ -459,24 +459,30 @@ function getScriptSetupModuleCodeBlocks(
459
459
parserOptions ,
460
460
)
461
461
462
- const textNode = scriptElement . children [ 0 ]
463
- if ( textNode == null || textNode . type !== "VText" ) {
464
- return scriptSetupCodeBlocks
462
+ const codeBlocks = new CodeBlocks ( )
463
+
464
+ for ( const scriptElement of scriptElements ) {
465
+ const textNode = scriptElement . children [ 0 ]
466
+ if ( textNode == null || textNode . type !== "VText" ) {
467
+ continue
468
+ }
469
+
470
+ const [ scriptStartOffset , scriptEndOffset ] = textNode . range
471
+
472
+ codeBlocks . append (
473
+ sfcCode . slice ( scriptStartOffset , scriptEndOffset ) ,
474
+ scriptStartOffset ,
475
+ )
465
476
}
466
477
467
- const [ scriptStartOffset , scriptEndOffset ] = textNode . range
468
- const codeBlocks = new CodeBlocks ( )
469
- codeBlocks . append (
470
- sfcCode . slice ( scriptStartOffset , scriptEndOffset ) ,
471
- scriptStartOffset ,
472
- )
473
478
if ( scriptSetupCodeBlocks == null ) {
474
479
return { codeBlocks }
475
480
}
476
481
477
482
codeBlocks . appendSplitPunctuators ( ";" )
478
483
const scriptSetupOffset = codeBlocks . length
479
484
codeBlocks . appendCodeBlocks ( scriptSetupCodeBlocks . codeBlocks )
485
+
480
486
return {
481
487
codeBlocks,
482
488
scriptSetupBlockRange : [
0 commit comments