| 35 | * ``` |
| 36 | */ |
| 37 | export function processAwait( |
| 38 | ctx: ScriptCompileContext, |
| 39 | node: AwaitExpression, |
| 40 | needSemi: boolean, |
| 41 | isStatement: boolean, |
| 42 | ): void { |
| 43 | const argumentStart = |
| 44 | node.argument.extra && node.argument.extra.parenthesized |
| 45 | ? (node.argument.extra.parenStart as number) |
| 46 | : node.argument.start! |
| 47 | |
| 48 | const startOffset = ctx.startOffset! |
| 49 | const argumentStr = ctx.descriptor.source.slice( |
| 50 | argumentStart + startOffset, |
| 51 | node.argument.end! + startOffset, |
| 52 | ) |
| 53 | |
| 54 | const containsNestedAwait = /\bawait\b/.test(argumentStr) |
| 55 | |
| 56 | ctx.s.overwrite( |
| 57 | node.start! + startOffset, |
| 58 | argumentStart + startOffset, |
| 59 | `${needSemi ? `;` : ``}(\n ([__temp,__restore] = ${ctx.helper( |
| 60 | `withAsyncContext`, |
| 61 | )}(${containsNestedAwait ? `async ` : ``}() => `, |
| 62 | ) |
| 63 | ctx.s.appendLeft( |
| 64 | node.end! + startOffset, |
| 65 | `)),\n ${isStatement ? `` : `__temp = `}await __temp,\n __restore()${ |
| 66 | isStatement ? `` : `,\n __temp` |
| 67 | }\n)`, |
| 68 | ) |
| 69 | } |