Skip to content

Commit

Permalink
fix: Babel 7 File API import change fix (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
wietseva authored and yyx990803 committed Mar 5, 2018
1 parent b713118 commit 50fe767
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["./index"],
"presets": ["@babel/preset-env"],
"ignore": ["node_modules"]
}
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var esutils = require('esutils')
var groupProps = require('./lib/group-props')
var mustUseProp = require('./lib/must-use-prop')
var addDefault = require('@babel/helper-module-imports').addDefault

module.exports = function (babel) {
var t = babel.types
Expand Down Expand Up @@ -113,7 +114,7 @@ module.exports = function (babel) {

var attribs = path.node.attributes
if (attribs.length) {
attribs = buildOpeningElementAttributes(attribs, file)
attribs = buildOpeningElementAttributes(attribs, path)
args.push(attribs)
}
return t.callExpression(t.identifier('h'), args)
Expand Down Expand Up @@ -144,7 +145,7 @@ module.exports = function (babel) {
* all prior attributes to an array for later processing.
*/

function buildOpeningElementAttributes (attribs, file) {
function buildOpeningElementAttributes (attribs, path) {
var _props = []
var objs = []

Expand Down Expand Up @@ -176,7 +177,7 @@ module.exports = function (babel) {
attribs = objs[0]
} else if (objs.length) {
// add prop merging helper
var helper = file.addImport('babel-helper-vue-jsx-merge-props', 'default', '_mergeJSXProps')
var helper = addDefault(path, 'babel-helper-vue-jsx-merge-props', { nameHint: '_mergeJSXProps' })
// spread it
attribs = t.callExpression(
helper,
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
],
"scripts": {
"lint": "eslint index.js",
"test": "npm run lint && mocha --compilers js:babel-register",
"test": "npm run lint && mocha --require @babel/register",
"dev": "cd example && webpack --watch",
"build": "webpack -p index.js dist/babel-plugin-transform-vue-jsx.min.js --target=web --output-library=babel-plugin-transform-vue-jsx --output-library-target=umd --module-bind 'js=babel-loader'",
"build": "webpack -d",
"prepublish": "npm run build"
},
"repository": {
Expand All @@ -38,18 +38,18 @@
"babel-helper-vue-jsx-merge-props": "^2.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"@babel/core": "^7.0.0-beta.40",
"@babel/helper-module-imports": "^7.0.0-beta.40",
"@babel/preset-env": "^7.0.0-beta.40",
"@babel/register": "^7.0.0-beta.40",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.2",
"babel-loader": "8.0.0-beta.0",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"eslint": "^4.16.0",
"eslint-plugin-vue-libs": "^2.1.0",
"mocha": "^5.0.0",
"vue": "^2.5.13",
"webpack": "^3.10.0"
"webpack": "^3.11.0"
}
}
5 changes: 5 additions & 0 deletions test/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["../index"],
"ignore": ["node_modules"]
}
23 changes: 23 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var path = require('path')

module.exports = {
target: 'web',
entry: path.join(__dirname, 'index.js'),
output: {
path: path.join(__dirname, 'dist'),
filename: 'babel-plugin-transform-vue-jsx.min.js',
library: 'babel-plugin-transform-vue-jsx',
libraryTarget: 'umd'
},
module: {
rules: [
{
test: /\/jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
}
}

0 comments on commit 50fe767

Please sign in to comment.