From: Evan You Date: Thu, 30 Jan 2025 02:12:36 +0000 (+0800) Subject: test(vapor): enable more test cases X-Git-Tag: v3.6.0-alpha.1~16^2~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e49c5a17da46165f06766c77d782c4069d4fab93;p=thirdparty%2Fvuejs%2Fcore.git test(vapor): enable more test cases --- diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index 2ddaeb509a..6a5532ad55 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -9,9 +9,10 @@ import { isPromise, } from '@vue/shared' import { + type ComponentInternalInstance, type SetupContext, createSetupContext, - getCurrentInstance, + getCurrentGenericInstance, setCurrentInstance, unsetCurrentInstance, } from './component' @@ -381,6 +382,7 @@ export function withDefaults< return null as any } +// TODO return type for Vapor components export function useSlots(): SetupContext['slots'] { return getContext().slots } @@ -390,11 +392,16 @@ export function useAttrs(): SetupContext['attrs'] { } function getContext(): SetupContext { - const i = getCurrentInstance()! + const i = getCurrentGenericInstance()! if (__DEV__ && !i) { warn(`useContext() called without active instance.`) } - return i.setupContext || (i.setupContext = createSetupContext(i)) + if (i.vapor) { + return i as any // vapor instance act as its own setup context + } else { + const ii = i as ComponentInternalInstance + return ii.setupContext || (ii.setupContext = createSetupContext(ii)) + } } /** @@ -496,7 +503,7 @@ export function createPropsRestProxy( * @internal */ export function withAsyncContext(getAwaitable: () => any): [any, () => void] { - const ctx = getCurrentInstance()! + const ctx = getCurrentGenericInstance()! if (__DEV__ && !ctx) { warn( `withAsyncContext called without active current instance. ` + diff --git a/packages/runtime-vapor/__tests__/apiSetupHelpers.spec.ts b/packages/runtime-vapor/__tests__/apiSetupHelpers.spec.ts index d4f7404487..21edc87f01 100644 --- a/packages/runtime-vapor/__tests__/apiSetupHelpers.spec.ts +++ b/packages/runtime-vapor/__tests__/apiSetupHelpers.spec.ts @@ -1,13 +1,18 @@ import { createComponent, defineVaporComponent, template } from '../src' -import { ref, useAttrs, useSlots } from '@vue/runtime-dom' +import { + currentInstance, + onMounted, + ref, + useAttrs, + useSlots, + withAsyncContext, +} from '@vue/runtime-dom' import { makeRender } from './_utils' import type { VaporComponentInstance } from '../src/component' const define = makeRender() -describe.todo('SFC