MCPcopy
hub / github.com/vuejs/core / processAwait

Function processAwait

packages/compiler-sfc/src/script/topLevelAwait.ts:37–69  ·  view source on GitHub ↗
(
  ctx: ScriptCompileContext,
  node: AwaitExpression,
  needSemi: boolean,
  isStatement: boolean,
)

Source from the content-addressed store, hash-verified

35 * ```
36 */
37export 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}

Callers 1

enterFunction · 0.90

Calls 2

testMethod · 0.80
helperMethod · 0.65

Tested by

no test coverage detected