From cc1a6219a97ccd199dd7cda7622ae744fa91cca6 Mon Sep 17 00:00:00 2001 From: JuniorTour Date: Tue, 16 Aug 2022 11:32:08 +0800 Subject: [PATCH 1/2] fix: directives shorthand normalize error (fix #12743) --- src/core/vdom/modules/directives.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/vdom/modules/directives.ts b/src/core/vdom/modules/directives.ts index 9e4a87f7f6e..853b20021e7 100644 --- a/src/core/vdom/modules/directives.ts +++ b/src/core/vdom/modules/directives.ts @@ -103,7 +103,15 @@ function normalizeDirectives( } res[getRawDirName(dir)] = dir if (vm._setupState && vm._setupState.__sfc) { - dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name) + const setupDef = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name) + if (typeof setupDef === 'function') { + dir.def = { + bind: setupDef, + update: setupDef, + } + } else { + dir.def = setupDef + } } dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true) } From 69d2622c96099ee6e46ec016b7869006dbcf4e33 Mon Sep 17 00:00:00 2001 From: JuniorTour Date: Tue, 16 Aug 2022 11:40:07 +0800 Subject: [PATCH 2/2] fix: add test case for directive resolution for shorthand --- test/unit/features/v3/apiSetup.spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/features/v3/apiSetup.spec.ts b/test/unit/features/v3/apiSetup.spec.ts index 7c69d06d1c4..11757878e9c 100644 --- a/test/unit/features/v3/apiSetup.spec.ts +++ b/test/unit/features/v3/apiSetup.spec.ts @@ -251,6 +251,19 @@ describe('api: setup context', () => { expect(spy).toHaveBeenCalled() }) + // #12743 + it('directive resolution for shorthand', () => { + const spy = vi.fn() + new Vue({ + setup: () => ({ + __sfc: true, + vDir: spy + }), + template: `
` + }).$mount() + expect(spy).toHaveBeenCalled() + }) + // #12561 it('setup props should be reactive', () => { const msg = ref('hi')