From: Evan You Date: Fri, 2 Jul 2021 12:06:22 +0000 (-0400) Subject: fix(build): avoid using async/await syntax X-Git-Tag: v3.1.4~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=438754a0d1428d10e27d1a290beb4b81da5fdaeb;p=thirdparty%2Fvuejs%2Fcore.git fix(build): avoid using async/await syntax --- diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index c0eb905101..5bbcffd957 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -1,3 +1,4 @@ +import { isPromise } from '../../shared/src' import { getCurrentInstance, SetupContext, @@ -232,19 +233,22 @@ export function mergeDefaults( * Runtime helper for storing and resuming current instance context in * async setup(). */ -export async function withAsyncContext( - awaitable: T | Promise -): Promise { +export function withAsyncContext(awaitable: T | Promise): Promise { const ctx = getCurrentInstance() setCurrentInstance(null) // unset after storing instance if (__DEV__ && !ctx) { warn(`withAsyncContext() called when there is no active context instance.`) } - let res: T - try { - res = await awaitable - } finally { - setCurrentInstance(ctx) - } - return res + return isPromise(awaitable) + ? awaitable.then( + res => { + setCurrentInstance(ctx) + return res + }, + err => { + setCurrentInstance(ctx) + throw err + } + ) + : (awaitable as any) }