feat: configurable usePatchFlag

This commit is contained in:
Amour1688 2020-06-21 17:29:07 +08:00
parent 74744fe74b
commit 9b005fcf02

View File

@ -369,14 +369,14 @@ const transformJSXElement = (t, path, state) => {
const child = children.length === 1 && t.isStringLiteral(children[0]) const child = children.length === 1 && t.isStringLiteral(children[0])
? children[0] : t.arrayExpression(children); ? children[0] : t.arrayExpression(children);
const { compatibleProps } = state.opts; const { compatibleProps, usePatchFlag } = 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' },
)); ));
} }
const createVNode = t.callExpression(createIdentifier(t, state, 'createVNode'), [ const createVNode = t.callExpression(createIdentifier(t, state, usePatchFlag ? 'createVNode' : 'h'), [
tag, tag,
compatibleProps ? t.callExpression(state.get('compatibleProps'), [props]) : props, compatibleProps ? t.callExpression(state.get('compatibleProps'), [props]) : props,
children[0] children[0]
@ -400,8 +400,8 @@ const transformJSXElement = (t, path, state) => {
]) ])
: child : child
) : t.nullLiteral(), ) : t.nullLiteral(),
patchFlag && t.addComment(t.numericLiteral(patchFlag), 'trailing', ` ${flagNames} `, false), patchFlag && usePatchFlag && t.addComment(t.numericLiteral(patchFlag), 'trailing', ` ${flagNames} `, false),
dynamicPropNames.size dynamicPropNames.size && usePatchFlag
&& t.arrayExpression([...dynamicPropNames.keys()].map((name) => t.stringLiteral(name))), && t.arrayExpression([...dynamicPropNames.keys()].map((name) => t.stringLiteral(name))),
].filter(Boolean)); ].filter(Boolean));