mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-11-10 09:39:14 +08:00
feat: optional usePatchFlag
This commit is contained in:
parent
858f39cea2
commit
76f3f17602
@ -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;
|
||||||
|
@ -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));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user