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 { interface Opts {
transformOn?: boolean; transformOn?: boolean;
compatibleProps?: boolean; compatibleProps?: boolean;
usePatchFlag?: boolean;
} }
export type ExcludesBoolean = <T>(x: T | false | true) => x is T; export type ExcludesBoolean = <T>(x: T | false | true) => x is T;

View File

@ -398,7 +398,7 @@ const transformJSXElement = (
.map((n) => PatchFlagNames[n]) .map((n) => PatchFlagNames[n])
.join(', '); .join(', ');
const { compatibleProps } = state.opts; const { compatibleProps = false, usePatchFlag = true } = state.opts;
if (compatibleProps && !state.get('compatibleProps')) { if (compatibleProps && !state.get('compatibleProps')) {
state.set('compatibleProps', addDefault( state.set('compatibleProps', addDefault(
path, '@ant-design-vue/babel-helper-vue-compatible-props', { nameHint: '_compatibleProps' }, path, '@ant-design-vue/babel-helper-vue-compatible-props', { nameHint: '_compatibleProps' },
@ -406,7 +406,7 @@ const transformJSXElement = (
} }
// @ts-ignore // @ts-ignore
const createVNode = t.callExpression(createIdentifier(state, 'createVNode'), [ const createVNode = t.callExpression(createIdentifier(state, usePatchFlag ? 'createVNode' : 'h'), [
tag, tag,
// @ts-ignore // @ts-ignore
compatibleProps ? t.callExpression(state.get('compatibleProps'), [props]) : props, compatibleProps ? t.callExpression(state.get('compatibleProps'), [props]) : props,
@ -425,12 +425,12 @@ const transformJSXElement = (
].filter(Boolean as any as ExcludesBoolean)) ].filter(Boolean as any as ExcludesBoolean))
: t.arrayExpression(children) : t.arrayExpression(children)
) : t.nullLiteral(), ) : t.nullLiteral(),
!!patchFlag && ( !!patchFlag && usePatchFlag && (
useOptimate useOptimate
? t.addComment(t.numericLiteral(patchFlag), 'trailing', ` ${flagNames} `, false) ? t.addComment(t.numericLiteral(patchFlag), 'trailing', ` ${flagNames} `, false)
: t.numericLiteral(PatchFlags.BAIL) : t.numericLiteral(PatchFlags.BAIL)
), ),
!!dynamicPropNames.size !!dynamicPropNames.size && usePatchFlag
&& t.arrayExpression([...dynamicPropNames.keys()].map((name) => t.stringLiteral(name as string))), && t.arrayExpression([...dynamicPropNames.keys()].map((name) => t.stringLiteral(name as string))),
].filter(Boolean as any as ExcludesBoolean)); ].filter(Boolean as any as ExcludesBoolean));