From 87f614b7033ec598d5356265c59459f4c7d9ba0e Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Sat, 12 Dec 2020 00:36:24 +0800 Subject: [PATCH] chore: add test for object slots --- .../babel-plugin-jsx/src/transform-vue-jsx.ts | 4 +- packages/babel-plugin-jsx/test/index.test.tsx | 38 ++++++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts index 59fca37..dda6796 100644 --- a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts +++ b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts @@ -121,8 +121,8 @@ const transformJSXElement = ( } else if ( t.isCallExpression(child) && child.loc && isComponent ) { // the element was generated and doesn't have location information - const slotId = path.scope.generateUidIdentifier('slot'); - const scope = path.scope; + const { scope } = path; + const slotId = scope.generateUidIdentifier('slot'); if (scope) { scope.push({ id: slotId, diff --git a/packages/babel-plugin-jsx/test/index.test.tsx b/packages/babel-plugin-jsx/test/index.test.tsx index 4f6e5f3..df0b6d4 100644 --- a/packages/babel-plugin-jsx/test/index.test.tsx +++ b/packages/babel-plugin-jsx/test/index.test.tsx @@ -571,23 +571,49 @@ describe('should support passing object slots via JSX children', () => { expect(wrapper.html()).toBe('foo'); }); - test('single expression, array map expression', () => { - const Test = defineComponent({ - setup(_, { slots }) { - return () => {slots.default?.()}; + test('single expression, function expression variable', () => { + const foo = () => 'foo'; + + const wrapper = mount({ + render() { + return ( + {foo} + ); }, }); + expect(wrapper.html()).toBe('foo'); + }); + + test('single expression, array map expression', () => { const data = ['A', 'B', 'C']; const wrapper = mount({ render() { return ( -
{data.map((item: string) => {item})}
+ <> + {data.map((item) => {item})} + ); }, }); - expect(wrapper.html()).toBe('
ABC
'); + expect(wrapper.html()).toBe('ABC'); + }); + + test('xx', () => { + const data = ['A', 'B', 'C']; + + const wrapper = mount({ + render() { + return ( + <> + {data.map((item) => {() => {item}})} + + ); + }, + }); + + expect(wrapper.html()).toBe('ABC'); }); });