@@ -30,7 +30,6 @@ import {
3030 CallExpression ,
3131 RestElement ,
3232 TSInterfaceBody ,
33- AwaitExpression ,
3433 Program ,
3534 ObjectMethod ,
3635 LVal ,
@@ -187,7 +186,6 @@ export function compileScript(
187186 | undefined
188187 let emitsTypeDeclRaw : Node | undefined
189188 let emitIdentifier : string | undefined
190- let hasAwait = false
191189 let hasInlinedSsrRenderFn = false
192190 // props/emits declared via types
193191 const typeDeclaredProps : Record < string , PropTypeData > = { }
@@ -471,56 +469,6 @@ export function compileScript(
471469 } )
472470 }
473471
474- /**
475- * await foo()
476- * -->
477- * ;(
478- * ([__temp,__restore] = withAsyncContext(() => foo())),
479- * await __temp,
480- * __restore()
481- * )
482- *
483- * const a = await foo()
484- * -->
485- * const a = (
486- * ([__temp, __restore] = withAsyncContext(() => foo())),
487- * __temp = await __temp,
488- * __restore(),
489- * __temp
490- * )
491- */
492- function processAwait (
493- node : AwaitExpression ,
494- needSemi : boolean ,
495- isStatement : boolean
496- ) {
497- const argumentStart =
498- node . argument . extra && node . argument . extra . parenthesized
499- ? ( node . argument . extra . parenStart as number )
500- : node . argument . start !
501-
502- const argumentStr = source . slice (
503- argumentStart + startOffset ,
504- node . argument . end ! + startOffset
505- )
506-
507- const containsNestedAwait = / \b a w a i t \b / . test ( argumentStr )
508-
509- s . overwrite (
510- node . start ! + startOffset ,
511- argumentStart + startOffset ,
512- `${ needSemi ? `;` : `` } (\n ([__temp,__restore] = ${ helper (
513- `withAsyncContext`
514- ) } (${ containsNestedAwait ? `async ` : `` } () => `
515- )
516- s . appendLeft (
517- node . end ! + startOffset ,
518- `)),\n ${ isStatement ? `` : `__temp = ` } await __temp,\n __restore()${
519- isStatement ? `` : `,\n __temp`
520- } \n)`
521- )
522- }
523-
524472 /**
525473 * check defaults. If the default object is an object literal with only
526474 * static properties, we can directly generate more optimized default
@@ -984,23 +932,9 @@ export function compileScript(
984932 scope . push ( child . body )
985933 }
986934 if ( child . type === 'AwaitExpression' ) {
987- hasAwait = true
988- // if the await expression is an expression statement and
989- // - is in the root scope
990- // - or is not the first statement in a nested block scope
991- // then it needs a semicolon before the generated code.
992- const currentScope = scope [ scope . length - 1 ]
993- const needsSemi = currentScope . some ( ( n , i ) => {
994- return (
995- ( scope . length === 1 || i > 0 ) &&
996- n . type === 'ExpressionStatement' &&
997- n . start === child . start
998- )
999- } )
1000- processAwait (
1001- child ,
1002- needsSemi ,
1003- parent . type === 'ExpressionStatement'
935+ error (
936+ `Vue 2 does not support top level await in <script setup>.` ,
937+ child
1004938 )
1005939 }
1006940 } ,
@@ -1177,11 +1111,6 @@ export function compileScript(
11771111 ) } (__props, ${ JSON . stringify ( Object . keys ( propsDestructuredBindings ) ) } )\n`
11781112 )
11791113 }
1180- // inject temp variables for async context preservation
1181- if ( hasAwait ) {
1182- const any = isTS ? `: any` : ``
1183- s . prependLeft ( startOffset , `\nlet __temp${ any } , __restore${ any } \n` )
1184- }
11851114
11861115 const destructureElements = hasDefineExposeCall ? [ `expose` ] : [ ]
11871116 if ( emitIdentifier ) {
@@ -1268,9 +1197,7 @@ export function compileScript(
12681197 startOffset ,
12691198 `\nexport default /*#__PURE__*/${ helper (
12701199 `defineComponent`
1271- ) } ({${ def } ${ runtimeOptions } \n ${
1272- hasAwait ? `async ` : ``
1273- } setup(${ args } ) {\n`
1200+ ) } ({${ def } ${ runtimeOptions } \n setup(${ args } ) {\n`
12741201 )
12751202 s . appendRight ( endOffset , `})` )
12761203 } else {
@@ -1280,14 +1207,13 @@ export function compileScript(
12801207 s . prependLeft (
12811208 startOffset ,
12821209 `\nexport default /*#__PURE__*/Object.assign(${ DEFAULT_VAR } , {${ runtimeOptions } \n ` +
1283- `${ hasAwait ? `async ` : `` } setup(${ args } ) {\n`
1210+ `setup(${ args } ) {\n`
12841211 )
12851212 s . appendRight ( endOffset , `})` )
12861213 } else {
12871214 s . prependLeft (
12881215 startOffset ,
1289- `\nexport default {${ runtimeOptions } \n ` +
1290- `${ hasAwait ? `async ` : `` } setup(${ args } ) {\n`
1216+ `\nexport default {${ runtimeOptions } \n setup(${ args } ) {\n`
12911217 )
12921218 s . appendRight ( endOffset , `}` )
12931219 }
0 commit comments