1- import { parse , SFCScriptCompileOptions } from '../src'
1+ import { parse , SFCScriptCompileOptions , compileScript } from '../src'
22import { parse as babelParse } from '@babel/parser'
33import { babelParserDefautPlugins } from '@vue/shared'
44
55function compile ( src : string , options ?: SFCScriptCompileOptions ) {
6- return parse ( src , options ) . descriptor . scriptTransformed !
6+ const { descriptor } = parse ( src )
7+ return compileScript ( descriptor , options )
78}
89
910function assertCode ( code : string ) {
@@ -370,24 +371,23 @@ describe('SFC compile <script setup>', () => {
370371
371372 describe ( 'errors' , ( ) => {
372373 test ( '<script> and <script setup> must have same lang' , ( ) => {
373- expect (
374- parse ( `<script>foo()</script><script setup lang="ts">bar()</script>` )
375- . errors [ 0 ] . message
376- ) . toMatch ( `<script> and <script setup> must have the same language type` )
374+ expect ( ( ) =>
375+ compile ( `<script>foo()</script><script setup lang="ts">bar()</script>` )
376+ ) . toThrow ( `<script> and <script setup> must have the same language type` )
377377 } )
378378
379379 test ( 'export local as default' , ( ) => {
380- expect (
381- parse ( `<script setup>
380+ expect ( ( ) =>
381+ compile ( `<script setup>
382382 const bar = 1
383383 export { bar as default }
384- </script>` ) . errors [ 0 ] . message
385- ) . toMatch ( `Cannot export locally defined variable as default` )
384+ </script>` )
385+ ) . toThrow ( `Cannot export locally defined variable as default` )
386386 } )
387387
388388 test ( 'export default referencing local var' , ( ) => {
389- expect (
390- parse ( `<script setup>
389+ expect ( ( ) =>
390+ compile ( `<script setup>
391391 const bar = 1
392392 export default {
393393 props: {
@@ -396,19 +396,19 @@ describe('SFC compile <script setup>', () => {
396396 }
397397 }
398398 }
399- </script>` ) . errors [ 0 ] . message
400- ) . toMatch ( `cannot reference locally declared variables` )
399+ </script>` )
400+ ) . toThrow ( `cannot reference locally declared variables` )
401401 } )
402402
403403 test ( 'export default referencing exports' , ( ) => {
404- expect (
405- parse ( `<script setup>
404+ expect ( ( ) =>
405+ compile ( `<script setup>
406406 export const bar = 1
407407 export default {
408408 props: bar
409409 }
410- </script>` ) . errors [ 0 ] . message
411- ) . toMatch ( `cannot reference locally declared variables` )
410+ </script>` )
411+ ) . toThrow ( `cannot reference locally declared variables` )
412412 } )
413413
414414 test ( 'should allow export default referencing scope var' , ( ) => {
@@ -458,62 +458,62 @@ describe('SFC compile <script setup>', () => {
458458 } )
459459
460460 test ( 'error on duplicated default export' , ( ) => {
461- expect (
462- parse ( `
461+ expect ( ( ) =>
462+ compile ( `
463463 <script>
464464 export default {}
465465 </script>
466466 <script setup>
467467 export default {}
468468 </script>
469- ` ) . errors [ 0 ] . message
470- ) . toMatch ( `Default export is already declared` )
469+ ` )
470+ ) . toThrow ( `Default export is already declared` )
471471
472- expect (
473- parse ( `
472+ expect ( ( ) =>
473+ compile ( `
474474 <script>
475475 export default {}
476476 </script>
477477 <script setup>
478478 const x = {}
479479 export { x as default }
480480 </script>
481- ` ) . errors [ 0 ] . message
482- ) . toMatch ( `Default export is already declared` )
481+ ` )
482+ ) . toThrow ( `Default export is already declared` )
483483
484- expect (
485- parse ( `
484+ expect ( ( ) =>
485+ compile ( `
486486 <script>
487487 export default {}
488488 </script>
489489 <script setup>
490490 export { x as default } from './y'
491491 </script>
492- ` ) . errors [ 0 ] . message
493- ) . toMatch ( `Default export is already declared` )
492+ ` )
493+ ) . toThrow ( `Default export is already declared` )
494494
495- expect (
496- parse ( `
495+ expect ( ( ) =>
496+ compile ( `
497497 <script>
498498 export { x as default } from './y'
499499 </script>
500500 <script setup>
501501 export default {}
502502 </script>
503- ` ) . errors [ 0 ] . message
504- ) . toMatch ( `Default export is already declared` )
503+ ` )
504+ ) . toThrow ( `Default export is already declared` )
505505
506- expect (
507- parse ( `
506+ expect ( ( ) =>
507+ compile ( `
508508 <script>
509509 const x = {}
510510 export { x as default }
511511 </script>
512512 <script setup>
513513 export default {}
514514 </script>
515- ` ) . errors [ 0 ] . message
516- ) . toMatch ( `Default export is already declared` )
515+ ` )
516+ ) . toThrow ( `Default export is already declared` )
517517 } )
518518 } )
519519} )
0 commit comments