babel-plugin-transform-vue-jsx
Advanced tools
Comparing version 3.3.0 to 3.4.0
32
index.js
@@ -27,2 +27,34 @@ var esutils = require('esutils') | ||
} | ||
}, | ||
'ObjectExpression|ClassDeclaration' (path) { | ||
path.traverse({ | ||
'ObjectMethod|ClassMethod' (path) { | ||
// do nothing if there is (h) param | ||
if (path.get('params').length) { | ||
return | ||
} | ||
// do nothing if there is no JSX inside | ||
const jsxChecker = { | ||
hasJsx: false | ||
} | ||
path.traverse({ | ||
JSXElement () { | ||
this.hasJsx = true | ||
} | ||
}, jsxChecker) | ||
if (!jsxChecker.hasJsx) { | ||
return | ||
} | ||
// prepend const h = this.$createElement otherwise | ||
path.get('body').unshiftContainer('body', t.variableDeclaration('const', [ | ||
t.variableDeclarator( | ||
t.identifier('h'), | ||
t.memberExpression( | ||
t.thisExpression(), | ||
t.identifier('$createElement') | ||
) | ||
) | ||
])) | ||
} | ||
}) | ||
} | ||
@@ -29,0 +61,0 @@ } |
{ | ||
"name": "babel-plugin-transform-vue-jsx", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Babel plugin for Vue 2.0 JSX", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -56,2 +56,19 @@ # babel-plugin-transform-vue-jsx [![CircleCI](https://img.shields.io/circleci/project/vuejs/babel-plugin-transform-vue-jsx.svg?maxAge=2592000)](https://circleci.com/gh/vuejs/babel-plugin-transform-vue-jsx) | ||
### `h` auto-injection | ||
Starting with version 3.4.0 we automatically inject `const h = this.$createElement` in any method and getter declared in ES2015 syntax that has JSX so you can drop the `(h)` parameter. | ||
``` js | ||
Vue.component('jsx-example', { | ||
render () { // h will be injected | ||
return <div id="foo">bar</div> | ||
}, | ||
myMethod: function () { // h will not be injected | ||
return <div id="foo">bar</div> | ||
} | ||
}) | ||
``` | ||
**Important** `h` does not inject into functions or arrow functions, it works only in ES2015 Method Properties declaration. | ||
### Difference from React JSX | ||
@@ -58,0 +75,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14555
247
199