Skip to content

Commit a47c692

Browse files
committed
fix: deoptimize slots when a directive is used
1 parent 5e77d5d commit a47c692

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/babel-plugin-jsx/src/transform-vue-jsx.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,18 @@ const transformJSXElement = (
405405

406406
const { optimize = false } = state.opts;
407407

408-
const slotFlag = path.getData('slotFlag') || SlotFlags.STABLE;
408+
// #541 - directives can't be resolved in optimized slots
409+
// all parents should be deoptimized
410+
if (directives.length) {
411+
let currentPath = path;
412+
while (currentPath.parentPath?.isJSXElement()) {
413+
currentPath = currentPath.parentPath;
414+
currentPath.setData('slotFlag', 0);
415+
}
416+
}
417+
418+
const slotFlag = path.getData('slotFlag') ?? SlotFlags.STABLE;
419+
const optimizeSlots = optimize && slotFlag !== 0;
409420
let VNodeChild;
410421

411422
if (children.length > 1 || slots) {
@@ -431,7 +442,7 @@ const transformJSXElement = (
431442
? (slots! as t.ObjectExpression).properties
432443
: [t.spreadElement(slots!)]
433444
: []),
434-
optimize &&
445+
optimizeSlots &&
435446
t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
436447
].filter(Boolean as any)
437448
)
@@ -452,7 +463,7 @@ const transformJSXElement = (
452463
t.arrayExpression(buildIIFE(path, [child]))
453464
)
454465
),
455-
optimize &&
466+
optimizeSlots &&
456467
(t.objectProperty(
457468
t.identifier('_'),
458469
t.numericLiteral(slotFlag)
@@ -490,7 +501,7 @@ const transformJSXElement = (
490501
t.arrayExpression(buildIIFE(path, [slotId]))
491502
)
492503
),
493-
optimize &&
504+
optimizeSlots &&
494505
(t.objectProperty(
495506
t.identifier('_'),
496507
t.numericLiteral(slotFlag)
@@ -517,7 +528,7 @@ const transformJSXElement = (
517528
VNodeChild = t.objectExpression(
518529
[
519530
...child.properties,
520-
optimize &&
531+
optimizeSlots &&
521532
t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
522533
].filter(Boolean as any)
523534
);

0 commit comments

Comments
 (0)