Skip to content

Commit 87f614b

Browse files
committed
chore: add test for object slots
1 parent c04904f commit 87f614b

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ const transformJSXElement = (
121121
} else if (
122122
t.isCallExpression(child) && child.loc && isComponent
123123
) { // the element was generated and doesn't have location information
124-
const slotId = path.scope.generateUidIdentifier('slot');
125-
const scope = path.scope;
124+
const { scope } = path;
125+
const slotId = scope.generateUidIdentifier('slot');
126126
if (scope) {
127127
scope.push({
128128
id: slotId,

packages/babel-plugin-jsx/test/index.test.tsx

+31-5
Original file line numberDiff line numberDiff line change
@@ -571,23 +571,49 @@ describe('should support passing object slots via JSX children', () => {
571571
expect(wrapper.html()).toBe('<span>foo<!----></span>');
572572
});
573573

574+
test('single expression, function expression variable', () => {
575+
const foo = () => 'foo';
576+
577+
const wrapper = mount({
578+
render() {
579+
return (
580+
<A>{foo}</A>
581+
);
582+
},
583+
});
584+
585+
expect(wrapper.html()).toBe('<span>foo<!----></span>');
586+
});
587+
574588
test('single expression, array map expression', () => {
575-
const Test = defineComponent({
576-
setup(_, { slots }) {
577-
return () => <span>{slots.default?.()}</span>;
589+
const data = ['A', 'B', 'C'];
590+
591+
const wrapper = mount({
592+
render() {
593+
return (
594+
<>
595+
{data.map((item) => <A><span>{item}</span></A>)}
596+
</>
597+
);
578598
},
579599
});
580600

601+
expect(wrapper.html()).toBe('<span><span>A</span><!----></span><span><span>B</span><!----></span><span><span>C</span><!----></span>');
602+
});
603+
604+
test('xx', () => {
581605
const data = ['A', 'B', 'C'];
582606

583607
const wrapper = mount({
584608
render() {
585609
return (
586-
<div>{data.map((item: string) => <Test><span>{item}</span></Test>)}</div>
610+
<>
611+
{data.map((item) => <A>{() => <span>{item}</span>}</A>)}
612+
</>
587613
);
588614
},
589615
});
590616

591-
expect(wrapper.html()).toBe('<div><span><span>A</span></span><span><span>B</span></span><span><span>C</span></span></div>');
617+
expect(wrapper.html()).toBe('<span><span>A</span><!----></span><span><span>B</span><!----></span><span><span>C</span><!----></span>');
592618
});
593619
});

0 commit comments

Comments
 (0)