diff --git a/packages/babel-plugin-jsx/README-zh_CN.md b/packages/babel-plugin-jsx/README-zh_CN.md index cb8c231..0cbeaa5 100644 --- a/packages/babel-plugin-jsx/README-zh_CN.md +++ b/packages/babel-plugin-jsx/README-zh_CN.md @@ -162,10 +162,14 @@ const App = { ```jsx +// 或者 + ``` ```jsx +// 或者 + ``` 会编译成: diff --git a/packages/babel-plugin-jsx/README.md b/packages/babel-plugin-jsx/README.md index 7e7ddb6..a67ea45 100644 --- a/packages/babel-plugin-jsx/README.md +++ b/packages/babel-plugin-jsx/README.md @@ -166,10 +166,14 @@ const App = { ```jsx +// Or + ``` ```jsx +// Or + ``` Will compile to: diff --git a/packages/babel-plugin-jsx/src/parseDirectives.ts b/packages/babel-plugin-jsx/src/parseDirectives.ts index d6e5b9d..3395ab9 100644 --- a/packages/babel-plugin-jsx/src/parseDirectives.ts +++ b/packages/babel-plugin-jsx/src/parseDirectives.ts @@ -67,7 +67,7 @@ const parseDirectives = (params: { .replace(/^\S/, (s: string) => s.toLowerCase()); if (directiveArgument) { - args.push(t.stringLiteral(directiveArgument)); + args.push(t.stringLiteral(directiveArgument.split('_')[0])); } const isVModels = directiveName === 'models'; diff --git a/packages/babel-plugin-jsx/test/v-model.test.tsx b/packages/babel-plugin-jsx/test/v-model.test.tsx index 2b7b902..3288011 100644 --- a/packages/babel-plugin-jsx/test/v-model.test.tsx +++ b/packages/babel-plugin-jsx/test/v-model.test.tsx @@ -286,3 +286,48 @@ test('Named model', async () => { await wrapper.trigger('click'); expect(wrapper.html()).toBe('
2
'); }); + +test('named model and underscore modifier should work in custom component', async () => { + const Child = defineComponent({ + emits: ['update:value'], + props: { + value: { + type: Number, + default: 0, + }, + valueModifiers: { + default: () => ({ double: false }), + }, + }, + setup(props, { emit }) { + const handleClick = () => { + emit('update:value', 3); + }; + return () => ( +
+ {props.valueModifiers.double ? props.value * 2 : props.value} +
+ ); + }, + }); + + const wrapper = mount( + defineComponent({ + data() { + return { + foo: 1, + }; + }, + render() { + return ; + }, + }) + ); + + expect(wrapper.html()).toBe('
2
'); + wrapper.vm.$data.foo += 1; + await wrapper.vm.$nextTick(); + expect(wrapper.html()).toBe('
4
'); + await wrapper.trigger('click'); + expect(wrapper.html()).toBe('
6
'); +});