feat: optional usePatchFlag

This commit is contained in:
Amour1688 2020-07-12 16:23:13 +08:00
parent 858f39cea2
commit 76f3f17602
2 changed files with 5 additions and 4 deletions

View File

@ -11,6 +11,7 @@ export type State = {
interface Opts {
transformOn?: boolean;
compatibleProps?: boolean;
usePatchFlag?: boolean;
}
export type ExcludesBoolean = <T>(x: T | false | true) => x is T;

View File

@ -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));