mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2025-02-10 23:49:09 +08:00
feat: compatible with Vue 2.x
This commit is contained in:
parent
7e0ee7dc5e
commit
dcadabd28a
3
packages/babel-helper-vue-compatible-props/README.md
Normal file
3
packages/babel-helper-vue-compatible-props/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# @ant-design-vue/babel-helper-vue-compatible-props
|
||||||
|
|
||||||
|
> compatible with Vue 2.x
|
12
packages/babel-helper-vue-compatible-props/index.js
Normal file
12
packages/babel-helper-vue-compatible-props/index.js
Normal file
@ -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;
|
16
packages/babel-helper-vue-compatible-props/package.json
Normal file
16
packages/babel-helper-vue-compatible-props/package.json
Normal file
@ -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 <lcz_1996@foxmail.com>",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@
|
|||||||
"url": "https://github.com/vueComponent/jsx/issues"
|
"url": "https://github.com/vueComponent/jsx/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@ant-design-vue/babel-helper-vue-compatible-props": "^1.0.0",
|
||||||
"@ant-design-vue/babel-helper-vue-transform-on": "^1.0.0",
|
"@ant-design-vue/babel-helper-vue-transform-on": "^1.0.0",
|
||||||
"@babel/helper-module-imports": "^7.0.0",
|
"@babel/helper-module-imports": "^7.0.0",
|
||||||
"@babel/plugin-syntax-jsx": "^7.0.0",
|
"@babel/plugin-syntax-jsx": "^7.0.0",
|
||||||
|
@ -292,9 +292,13 @@ const transformJSXElement = (t, path, state) => {
|
|||||||
const directives = [];
|
const directives = [];
|
||||||
const tag = getTag(t, path);
|
const tag = getTag(t, path);
|
||||||
const children = t.arrayExpression(getChildren(t, path.get('children')));
|
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, [
|
const h = t.callExpression(state.h, [
|
||||||
tag,
|
tag,
|
||||||
getAttributes(t, path, state, directives),
|
state.opts.compatibleProps ? t.callExpression(compatibleProps, [attributes]) : attributes,
|
||||||
!t.isStringLiteral(tag) && !tag.name.includes('Fragment')
|
!t.isStringLiteral(tag) && !tag.name.includes('Fragment')
|
||||||
? t.objectExpression([
|
? t.objectExpression([
|
||||||
t.objectProperty(
|
t.objectProperty(
|
||||||
|
Loading…
Reference in New Issue
Block a user