diff --git a/packages/babel-plugin-jsx/src/transform-vue-jsx.js b/packages/babel-plugin-jsx/src/transform-vue-jsx.js index 234866b..ded0d00 100644 --- a/packages/babel-plugin-jsx/src/transform-vue-jsx.js +++ b/packages/babel-plugin-jsx/src/transform-vue-jsx.js @@ -369,14 +369,14 @@ const transformJSXElement = (t, path, state) => { const child = children.length === 1 && t.isStringLiteral(children[0]) ? children[0] : t.arrayExpression(children); - const { compatibleProps, usePatchFlag } = state.opts; + const { compatibleProps } = state.opts; if (compatibleProps && !state.get('compatibleProps')) { state.set('compatibleProps', addDefault( path, '@ant-design-vue/babel-helper-vue-compatible-props', { nameHint: '_compatibleProps' }, )); } - const createVNode = t.callExpression(createIdentifier(t, state, usePatchFlag ? 'createVNode' : 'h'), [ + const createVNode = t.callExpression(createIdentifier(t, state, 'createVNode'), [ tag, compatibleProps ? t.callExpression(state.get('compatibleProps'), [props]) : props, children[0] @@ -400,8 +400,8 @@ const transformJSXElement = (t, path, state) => { ]) : child ) : t.nullLiteral(), - patchFlag && usePatchFlag && t.addComment(t.numericLiteral(patchFlag), 'trailing', ` ${flagNames} `, false), - dynamicPropNames.size && usePatchFlag + patchFlag && t.addComment(t.numericLiteral(patchFlag), 'trailing', ` ${flagNames} `, false), + dynamicPropNames.size && t.arrayExpression([...dynamicPropNames.keys()].map((name) => t.stringLiteral(name))), ].filter(Boolean)); diff --git a/packages/babel-plugin-jsx/test/index.test.js b/packages/babel-plugin-jsx/test/index.test.js index 9a26f3a..330cd78 100644 --- a/packages/babel-plugin-jsx/test/index.test.js +++ b/packages/babel-plugin-jsx/test/index.test.js @@ -1,6 +1,12 @@ -import { ref } from 'vue'; +import { reactive, ref } from 'vue'; import { shallowMount, mount } from '@vue/test-utils'; +const patchFlagExpect = (wrapper, flag, dynamic) => { + const { patchFlag, dynamicProps } = wrapper.vm.$.subTree; + expect(patchFlag).toBe(flag); + expect(dynamicProps).toEqual(dynamic); +}; + describe('Transform JSX', () => { test('should render with render function', () => { const wrapper = shallowMount({ @@ -52,6 +58,7 @@ describe('Transform JSX', () => { ); }, }); + expect(wrapper.classes()).toStrictEqual([]); expect(wrapper.text()).toBe('1'); }); @@ -255,79 +262,49 @@ describe('Transform JSX', () => { }); }); -describe('Patch Flags', () => { - let renders = 0; - const Child = { - props: ['text'], - setup(props) { - return () => { - renders++; - return