diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts index 3645ccb92da..3a066178632 100644 --- a/packages/compiler-sfc/__tests__/compileScript.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts @@ -1101,22 +1101,22 @@ const emit = defineEmits(['a', 'b']) assertAwaitDetection( `await (await foo)`, `;(([__temp,__restore]=_withAsyncContext(` + - `()=>(((([__temp,__restore]=_withAsyncContext(` + + `async ()=>(((([__temp,__restore]=_withAsyncContext(` + `()=>(foo))),__temp=await __temp,__restore(),__temp))))` + `),__temp=await __temp,__restore())` ) assertAwaitDetection( `await ((await foo))`, `;(([__temp,__restore]=_withAsyncContext(` + - `()=>((((([__temp,__restore]=_withAsyncContext(` + + `async ()=>((((([__temp,__restore]=_withAsyncContext(` + `()=>(foo))),__temp=await __temp,__restore(),__temp)))))` + `),__temp=await __temp,__restore())` ) assertAwaitDetection( `await (await (await foo))`, `;(([__temp,__restore]=_withAsyncContext(` + - `()=>(((([__temp,__restore]=_withAsyncContext(` + - `()=>(((([__temp,__restore]=_withAsyncContext(` + + `async ()=>(((([__temp,__restore]=_withAsyncContext(` + + `async ()=>(((([__temp,__restore]=_withAsyncContext(` + `()=>(foo))),__temp=await __temp,__restore(),__temp))))` + `),__temp=await __temp,__restore(),__temp))))` + `),__temp=await __temp,__restore())` diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 4a46dfbc63c..7fb02cea464 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -520,7 +520,7 @@ export function compileScript( end + startOffset, `${isStatement ? `;` : ``}(([__temp,__restore]=${helper( `withAsyncContext` - )}(()=>(` + )}(${node.argument.type === 'AwaitExpression' ? `async ` : ``}()=>(` ) s.appendLeft( node.end! + startOffset,