Skip to content

Commit

Permalink
feat: replace babel-plugin-transform-vue-jsx with @vue/babel-preset-j…
Browse files Browse the repository at this point in the history
…sx (#3218)

* feat: replace babel-plugin-transform-vue-jsx with @vue/babel-preset-jsx

* feat: allow jsx options
  • Loading branch information
sodatea committed Jan 8, 2019
1 parent e7af0d8 commit f15dcf7
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 96 deletions.
19 changes: 19 additions & 0 deletions packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,22 @@ test('jsx', () => {
expect(code).toMatch(`var h = arguments[0]`)
expect(code).toMatch(`return h("div", ["bar"])`)
})

test('jsx options', () => {
const { code } = babel.transformSync(`
export default {
render () {
return <div>bar</div>
}
}
`.trim(), {
babelrc: false,
presets: [[preset, {
jsx: {
injectH: false
}
}]]
})
expect(code).not.toMatch(`var h = arguments[0]`)
expect(code).toMatch(`return h("div", ["bar"])`)
})
9 changes: 2 additions & 7 deletions packages/@vue/babel-preset-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ module.exports = (context, options = {}) => {

// JSX
if (options.jsx !== false) {
plugins.push(
require('@babel/plugin-syntax-jsx'),
require('babel-plugin-transform-vue-jsx')
// require('babel-plugin-jsx-event-modifiers'),
// require('babel-plugin-jsx-v-model')
)
presets.push([require('@vue/babel-preset-jsx'), typeof options.jsx === 'object' ? options.jsx : {}])
}

const {
Expand Down Expand Up @@ -125,7 +120,7 @@ module.exports = (context, options = {}) => {
}

// pass options along to babel-preset-env
presets.push([require('@babel/preset-env'), envOptions])
presets.unshift([require('@babel/preset-env'), envOptions])

// additional <= stage-3 plugins
// Babel 7 is removing stage presets altogether because people are using
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/babel-preset-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@babel/preset-env": "^7.0.0",
"@babel/runtime": "^7.0.0",
"@babel/runtime-corejs2": "^7.2.0",
"@vue/babel-preset-jsx": "^1.0.0-beta.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-plugin-dynamic-import-node": "^2.2.0",
"babel-plugin-transform-vue-jsx": "^4.0.1",
Expand Down
Loading

0 comments on commit f15dcf7

Please sign in to comment.