Skip to content

Commit b0fb8c0

Browse files
authored
fix: jsx slot render unexpected #215 (#218)
* fix: jsx slot render unexpected #215 * test: update test
1 parent 7efda55 commit b0fb8c0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const transformJSXElement = (
122122
t.isCallExpression(child) && child.loc && isComponent
123123
) { // the element was generated and doesn't have location information
124124
const slotId = path.scope.generateUidIdentifier('slot');
125-
const scope = path.hub.getScope();
125+
const scope = path.scope;
126126
if (scope) {
127127
scope.push({
128128
id: slotId,

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,4 +570,24 @@ describe('should support passing object slots via JSX children', () => {
570570

571571
expect(wrapper.html()).toBe('<span>foo<!----></span>');
572572
});
573+
574+
test('single expression, array map expression', () => {
575+
const Test = defineComponent({
576+
setup(_, { slots }) {
577+
return () => <span>{slots.default?.()}</span>;
578+
},
579+
});
580+
581+
const data = ['A', 'B', 'C'];
582+
583+
const wrapper = mount({
584+
render() {
585+
return (
586+
<div>{data.map((item: string) => <Test><span>{item}</span></Test>)}</div>
587+
);
588+
},
589+
});
590+
591+
expect(wrapper.html()).toBe('<div><span><span>A</span></span><span><span>B</span></span><span><span>C</span></span></div>');
592+
});
573593
});

0 commit comments

Comments
 (0)