mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2025-03-14 06:34:41 +08:00
fix: deoptimize slots when a directive is used
This commit is contained in:
parent
5e77d5d5e5
commit
a47c692e54
@ -405,7 +405,18 @@ const transformJSXElement = (
|
|||||||
|
|
||||||
const { optimize = false } = state.opts;
|
const { optimize = false } = state.opts;
|
||||||
|
|
||||||
const slotFlag = path.getData('slotFlag') || SlotFlags.STABLE;
|
// #541 - directives can't be resolved in optimized slots
|
||||||
|
// all parents should be deoptimized
|
||||||
|
if (directives.length) {
|
||||||
|
let currentPath = path;
|
||||||
|
while (currentPath.parentPath?.isJSXElement()) {
|
||||||
|
currentPath = currentPath.parentPath;
|
||||||
|
currentPath.setData('slotFlag', 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const slotFlag = path.getData('slotFlag') ?? SlotFlags.STABLE;
|
||||||
|
const optimizeSlots = optimize && slotFlag !== 0;
|
||||||
let VNodeChild;
|
let VNodeChild;
|
||||||
|
|
||||||
if (children.length > 1 || slots) {
|
if (children.length > 1 || slots) {
|
||||||
@ -431,7 +442,7 @@ const transformJSXElement = (
|
|||||||
? (slots! as t.ObjectExpression).properties
|
? (slots! as t.ObjectExpression).properties
|
||||||
: [t.spreadElement(slots!)]
|
: [t.spreadElement(slots!)]
|
||||||
: []),
|
: []),
|
||||||
optimize &&
|
optimizeSlots &&
|
||||||
t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
|
t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
|
||||||
].filter(Boolean as any)
|
].filter(Boolean as any)
|
||||||
)
|
)
|
||||||
@ -452,7 +463,7 @@ const transformJSXElement = (
|
|||||||
t.arrayExpression(buildIIFE(path, [child]))
|
t.arrayExpression(buildIIFE(path, [child]))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
optimize &&
|
optimizeSlots &&
|
||||||
(t.objectProperty(
|
(t.objectProperty(
|
||||||
t.identifier('_'),
|
t.identifier('_'),
|
||||||
t.numericLiteral(slotFlag)
|
t.numericLiteral(slotFlag)
|
||||||
@ -490,7 +501,7 @@ const transformJSXElement = (
|
|||||||
t.arrayExpression(buildIIFE(path, [slotId]))
|
t.arrayExpression(buildIIFE(path, [slotId]))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
optimize &&
|
optimizeSlots &&
|
||||||
(t.objectProperty(
|
(t.objectProperty(
|
||||||
t.identifier('_'),
|
t.identifier('_'),
|
||||||
t.numericLiteral(slotFlag)
|
t.numericLiteral(slotFlag)
|
||||||
@ -517,7 +528,7 @@ const transformJSXElement = (
|
|||||||
VNodeChild = t.objectExpression(
|
VNodeChild = t.objectExpression(
|
||||||
[
|
[
|
||||||
...child.properties,
|
...child.properties,
|
||||||
optimize &&
|
optimizeSlots &&
|
||||||
t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
|
t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
|
||||||
].filter(Boolean as any)
|
].filter(Boolean as any)
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user