diff --git a/packages/babel-helper-vue-compatible-props/README.md b/packages/babel-helper-vue-compatible-props/README.md new file mode 100644 index 0000000..b06fea9 --- /dev/null +++ b/packages/babel-helper-vue-compatible-props/README.md @@ -0,0 +1,3 @@ +# @ant-design-vue/babel-helper-vue-compatible-props + +> compatible with Vue 2.x diff --git a/packages/babel-helper-vue-compatible-props/index.js b/packages/babel-helper-vue-compatible-props/index.js new file mode 100644 index 0000000..ee86108 --- /dev/null +++ b/packages/babel-helper-vue-compatible-props/index.js @@ -0,0 +1,12 @@ +const transformOn = require('@ant-design-vue/babel-helper-vue-transform-on'); + +const compatibleProps = (attr) => { + const { + props, on = {}, attrs, ...rest + } = attr || {}; + return { + ...props, ...attrs, ...transformOn(on), ...rest, + }; +}; + +module.exports = compatibleProps; diff --git a/packages/babel-helper-vue-compatible-props/package.json b/packages/babel-helper-vue-compatible-props/package.json new file mode 100644 index 0000000..4df05f6 --- /dev/null +++ b/packages/babel-helper-vue-compatible-props/package.json @@ -0,0 +1,16 @@ +{ + "name": "@ant-design-vue/babel-helper-vue-compatible-props", + "version": "1.0.0", + "description": "compatible with Vue 2.x", + "author": "Amour1688 ", + "homepage": "https://github.com/vueComponent/jsx#readme", + "license": "MIT", + "main": "index.js", + "repository": { + "type": "git", + "url": "git+https://github.com/vueComponent/jsx.git" + }, + "dependencies": { + "@ant-design-vue/babel-helper-vue-transform-on": "^1.0.1" + } +} diff --git a/packages/babel-plugin-jsx/package.json b/packages/babel-plugin-jsx/package.json index 0fd8a28..eec109f 100644 --- a/packages/babel-plugin-jsx/package.json +++ b/packages/babel-plugin-jsx/package.json @@ -19,6 +19,7 @@ "url": "https://github.com/vueComponent/jsx/issues" }, "dependencies": { + "@ant-design-vue/babel-helper-vue-compatible-props": "^1.0.0", "@ant-design-vue/babel-helper-vue-transform-on": "^1.0.0", "@babel/helper-module-imports": "^7.0.0", "@babel/plugin-syntax-jsx": "^7.0.0", diff --git a/packages/babel-plugin-jsx/src/transform-vue-jsx.js b/packages/babel-plugin-jsx/src/transform-vue-jsx.js index 1077375..bb763d7 100644 --- a/packages/babel-plugin-jsx/src/transform-vue-jsx.js +++ b/packages/babel-plugin-jsx/src/transform-vue-jsx.js @@ -292,9 +292,13 @@ const transformJSXElement = (t, path, state) => { const directives = []; const tag = getTag(t, path); const children = t.arrayExpression(getChildren(t, path.get('children'))); + const attributes = getAttributes(t, path, state, directives); + const compatibleProps = addDefault( + path, '@ant-design-vue/babel-helper-vue-compatible-props', { nameHint: '_compatibleProps' }, + ); const h = t.callExpression(state.h, [ tag, - getAttributes(t, path, state, directives), + state.opts.compatibleProps ? t.callExpression(compatibleProps, [attributes]) : attributes, !t.isStringLiteral(tag) && !tag.name.includes('Fragment') ? t.objectExpression([ t.objectProperty(