From f4da5d71b3a38392bcfbbd1755213d2b92ebe648 Mon Sep 17 00:00:00 2001 From: daiwei Date: Fri, 27 Aug 2021 22:18:00 +0800 Subject: [PATCH] chore: improve code --- packages/compiler-sfc/__tests__/compileScript.spec.ts | 8 ++++---- packages/compiler-sfc/src/compileScript.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) 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,