From d4b12c43ec04710612cc4b14c9565d7e13a33d09 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 30 Jun 2022 10:37:40 +0800 Subject: [PATCH 1/2] fix(sfc): only include legacy decorator parser plugin when new plugin is not used --- packages/compiler-sfc/src/compileScript.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 7af376bb9cc..ff2b11f78a0 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -126,7 +126,12 @@ export function compileScript( ) } if (options.babelParserPlugins) plugins.push(...options.babelParserPlugins) - if (isTS) plugins.push('typescript', 'decorators-legacy') + if (isTS) { + plugins.push('typescript') + if (plugins.includes('decorators')) { + plugins.push('decorators-legacy') + } + } if (!scriptSetup) { if (!script) { From 183ef1a076587807320595699ee158abf723cd7b Mon Sep 17 00:00:00 2001 From: Kael Date: Fri, 1 Jul 2022 01:17:36 +1000 Subject: [PATCH 2/2] feat: allow passing directive definition directly to h() --- src/core/vdom/modules/directives.ts | 4 ++-- types/vnode.d.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/vdom/modules/directives.ts b/src/core/vdom/modules/directives.ts index 7d475de1fc5..9e4a87f7f6e 100644 --- a/src/core/vdom/modules/directives.ts +++ b/src/core/vdom/modules/directives.ts @@ -94,7 +94,7 @@ function normalizeDirectives( // $flow-disable-line return res } - let i, dir + let i: number, dir: VNodeDirective for (i = 0; i < dirs.length; i++) { dir = dirs[i] if (!dir.modifiers) { @@ -103,7 +103,7 @@ function normalizeDirectives( } res[getRawDirName(dir)] = dir if (vm._setupState && vm._setupState.__sfc) { - dir.def = resolveAsset(vm, '_setupState', 'v-' + dir.name) + dir.def = dir.def || resolveAsset(vm, '_setupState', 'v-' + dir.name) } dir.def = dir.def || resolveAsset(vm.$options, 'directives', dir.name, true) } diff --git a/types/vnode.d.ts b/types/vnode.d.ts index 59eeb032b77..fabfad44c97 100644 --- a/types/vnode.d.ts +++ b/types/vnode.d.ts @@ -1,4 +1,5 @@ import { Vue } from './vue' +import { DirectiveFunction, DirectiveOptions } from './options' export type ScopedSlot = (props: any) => ScopedSlotReturnValue type ScopedSlotReturnValue = @@ -86,4 +87,5 @@ export interface VNodeDirective { arg?: string oldArg?: string modifiers?: { [key: string]: boolean } + def?: DirectiveFunction | DirectiveOptions }