From 76f3f17602bd7bfdd4968ede94aa7ae24bc5ddcd Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Sun, 12 Jul 2020 16:23:13 +0800 Subject: [PATCH] feat: optional usePatchFlag --- packages/babel-plugin-jsx/src/index.ts | 1 + packages/babel-plugin-jsx/src/transform-vue-jsx.ts | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/babel-plugin-jsx/src/index.ts b/packages/babel-plugin-jsx/src/index.ts index 69dc838..a7c1157 100644 --- a/packages/babel-plugin-jsx/src/index.ts +++ b/packages/babel-plugin-jsx/src/index.ts @@ -11,6 +11,7 @@ export type State = { interface Opts { transformOn?: boolean; compatibleProps?: boolean; + usePatchFlag?: boolean; } export type ExcludesBoolean = (x: T | false | true) => x is T; diff --git a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts index 4f5956b..4f5a721 100644 --- a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts +++ b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts @@ -398,7 +398,7 @@ const transformJSXElement = ( .map((n) => PatchFlagNames[n]) .join(', '); - const { compatibleProps } = state.opts; + const { compatibleProps = false, usePatchFlag = true } = state.opts; if (compatibleProps && !state.get('compatibleProps')) { state.set('compatibleProps', addDefault( path, '@ant-design-vue/babel-helper-vue-compatible-props', { nameHint: '_compatibleProps' }, @@ -406,7 +406,7 @@ const transformJSXElement = ( } // @ts-ignore - const createVNode = t.callExpression(createIdentifier(state, 'createVNode'), [ + const createVNode = t.callExpression(createIdentifier(state, usePatchFlag ? 'createVNode' : 'h'), [ tag, // @ts-ignore compatibleProps ? t.callExpression(state.get('compatibleProps'), [props]) : props, @@ -425,12 +425,12 @@ const transformJSXElement = ( ].filter(Boolean as any as ExcludesBoolean)) : t.arrayExpression(children) ) : t.nullLiteral(), - !!patchFlag && ( + !!patchFlag && usePatchFlag && ( useOptimate ? t.addComment(t.numericLiteral(patchFlag), 'trailing', ` ${flagNames} `, false) : t.numericLiteral(PatchFlags.BAIL) ), - !!dynamicPropNames.size + !!dynamicPropNames.size && usePatchFlag && t.arrayExpression([...dynamicPropNames.keys()].map((name) => t.stringLiteral(name as string))), ].filter(Boolean as any as ExcludesBoolean));