})"
`;
-exports[`SFC compile <script setup> async/await detection await in expression statement 1`] = `
+exports[`SFC compile <script setup> async/await detection expression statement 1`] = `
"import { withAsyncContext as _withAsyncContext } from 'vue'
export default {
expose()
let __temp, __restore
-foo()
;(
- ([__temp,__restore] = _withAsyncContext(() => {
- return 1
- })),
- __temp = await __temp,
- __restore(),
- __temp
-) + (
- ([__temp,__restore] = _withAsyncContext(() => {
- return 2
- })),
- __temp = await __temp,
- __restore(),
- __temp
+ ([__temp,__restore] = _withAsyncContext(() => foo)),
+ await __temp,
+ __restore()
)
return { }
}
}"
`;
-exports[`SFC compile <script setup> async/await detection expression statement 1`] = `
+exports[`SFC compile <script setup> async/await detection nested await 1`] = `
"import { withAsyncContext as _withAsyncContext } from 'vue'
export default {
let __temp, __restore
;(
- ([__temp,__restore] = _withAsyncContext(() => {
- return foo
- })),
+ ([__temp,__restore] = _withAsyncContext(async () => ((
+ ([__temp,__restore] = _withAsyncContext(() => foo)),
__temp = await __temp,
__restore(),
__temp
+)))),
+ await __temp,
+ __restore()
)
return { }
}
}"
`;
-exports[`SFC compile <script setup> async/await detection nested await 1`] = `
+exports[`SFC compile <script setup> async/await detection nested await 2`] = `
"import { withAsyncContext as _withAsyncContext } from 'vue'
export default {
let __temp, __restore
;(
- ([__temp,__restore] = _withAsyncContext(async () => {
- return ((
- ([__temp,__restore] = _withAsyncContext(() => {
- return foo
- })),
- __temp = await __temp,
- __restore(),
- __temp
-))
- })),
+ ([__temp,__restore] = _withAsyncContext(async () => (((
+ ([__temp,__restore] = _withAsyncContext(() => foo)),
__temp = await __temp,
__restore(),
__temp
+))))),
+ await __temp,
+ __restore()
)
return { }
}
}"
`;
-exports[`SFC compile <script setup> async/await detection nested await 2`] = `
+exports[`SFC compile <script setup> async/await detection nested await 3`] = `
"import { withAsyncContext as _withAsyncContext } from 'vue'
export default {
let __temp, __restore
;(
- ([__temp,__restore] = _withAsyncContext(async () => {
- return (((
- ([__temp,__restore] = _withAsyncContext(() => {
- return foo
- })),
+ ([__temp,__restore] = _withAsyncContext(async () => ((
+ ([__temp,__restore] = _withAsyncContext(async () => ((
+ ([__temp,__restore] = _withAsyncContext(() => foo)),
__temp = await __temp,
__restore(),
__temp
-)))
- })),
+)))),
__temp = await __temp,
__restore(),
__temp
+)))),
+ await __temp,
+ __restore()
)
return { }
}
}"
`;
-exports[`SFC compile <script setup> async/await detection nested await 3`] = `
+exports[`SFC compile <script setup> async/await detection nested leading await in expression statement 1`] = `
"import { withAsyncContext as _withAsyncContext } from 'vue'
export default {
expose()
let __temp, __restore
+foo()
;(
- ([__temp,__restore] = _withAsyncContext(async () => {
- return ((
- ([__temp,__restore] = _withAsyncContext(async () => {
- return ((
- ([__temp,__restore] = _withAsyncContext(() => {
- return foo
- })),
+ ([__temp,__restore] = _withAsyncContext(() => 1)),
__temp = await __temp,
__restore(),
__temp
-))
- })),
- __temp = await __temp,
- __restore(),
- __temp
-))
- })),
+) + (
+ ([__temp,__restore] = _withAsyncContext(() => 2)),
__temp = await __temp,
__restore(),
__temp
let __temp, __restore
if (ok) { (
- ([__temp,__restore] = _withAsyncContext(() => {
- return foo
- })),
- __temp = await __temp,
- __restore(),
- __temp
+ ([__temp,__restore] = _withAsyncContext(() => foo)),
+ await __temp,
+ __restore()
) } else { (
- ([__temp,__restore] = _withAsyncContext(() => {
- return bar
- })),
- __temp = await __temp,
- __restore(),
- __temp
+ ([__temp,__restore] = _withAsyncContext(() => bar)),
+ await __temp,
+ __restore()
) }
return { }
}
let __temp, __restore
let a = _ref(1 + ((
- ([__temp,__restore] = _withAsyncContext(() => {
- return foo
- })),
+ ([__temp,__restore] = _withAsyncContext(() => foo)),
__temp = await __temp,
__restore(),
__temp
let __temp, __restore
if (false) (
- ([__temp,__restore] = _withAsyncContext(() => {
- return foo()
- })),
- __temp = await __temp,
- __restore(),
- __temp
+ ([__temp,__restore] = _withAsyncContext(() => foo())),
+ await __temp,
+ __restore()
)
return { }
}
let __temp, __restore
const a = 1 + ((
- ([__temp,__restore] = _withAsyncContext(() => {
- return foo
- })),
+ ([__temp,__restore] = _withAsyncContext(() => foo)),
__temp = await __temp,
__restore(),
__temp
}
/**
- * await foo() -->
+ * await foo()
+ * -->
+ * ;(
+ * ([__temp,__restore] = withAsyncContext(() => foo())),
+ * await __temp,
+ * __restore()
+ * )
*
- * (([__temp, __restore] = withAsyncContext(async () => {
- * return foo()
- * })),__temp=await __temp,__restore(),__temp)
+ * const a = await foo()
+ * -->
+ * const a = (
+ * ([__temp, __restore] = withAsyncContext(() => foo())),
+ * __temp = await __temp,
+ * __restore(),
+ * __temp
+ * )
*/
- function processAwait(node: AwaitExpression, needSemi: boolean) {
+ function processAwait(
+ node: AwaitExpression,
+ needSemi: boolean,
+ isStatement: boolean
+ ) {
const argumentStart =
node.argument.extra && node.argument.extra.parenthesized
? (node.argument.extra.parenStart as number)
argumentStart + startOffset,
`${needSemi ? `;` : ``}(\n ([__temp,__restore] = ${helper(
`withAsyncContext`
- )}(${containsNestedAwait ? `async ` : ``}() => {\n return `
+ )}(${containsNestedAwait ? `async ` : ``}() => `
)
s.appendLeft(
node.end! + startOffset,
- `\n })),\n __temp = await __temp,\n __restore(),\n __temp\n)`
+ `)),\n ${isStatement ? `` : `__temp = `}await __temp,\n __restore()${
+ isStatement ? `` : `,\n __temp`
+ }\n)`
)
}
const needsSemi = scriptSetupAst.body.some(n => {
return n.type === 'ExpressionStatement' && n.start === child.start
})
- processAwait(child, needsSemi)
+ processAwait(
+ child,
+ needsSemi,
+ parent.type === 'ExpressionStatement'
+ )
}
}
})