Skip to content

Commit c48e9e2

Browse files
fix(vue2): add jsx support
1 parent bb405d1 commit c48e9e2

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
"@types/babel__code-frame": "^7.0.2",
4848
"@types/babel__core": "^7.1.12",
4949
"@types/babel__traverse": "^7.11.0",
50+
"@vue/babel-helper-vue-jsx-merge-props": "^1.2.1",
5051
"@vue/babel-plugin-jsx": "^1.0.3",
52+
"@vue/babel-preset-jsx": "^1.2.4",
5153
"@vue/compiler-dom": "^3.0.7",
5254
"@vue/compiler-sfc": "^3.0.7",
5355
"@vue/component-compiler-utils": "^3.2.0",

src/createVue2SFCModule.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import {
2323
// @ts-ignore (Could not find a declaration file for module '@babel/plugin-transform-modules-commonjs')
2424
import babelPluginTransformModulesCommonjs from '@babel/plugin-transform-modules-commonjs'
2525

26+
// https://github.com/vuejs/jsx
27+
// @ts-ignore
28+
import jsx from '@vue/babel-plugin-transform-vue-jsx'
29+
// @ts-ignore
30+
import babelSugarInjectH from '@vue/babel-sugar-inject-h'
2631

2732
import {
2833
formatError,
@@ -153,6 +158,7 @@ export async function createSFCModule(source : string, filename : string, option
153158
// doc: https://babeljs.io/docs/en/babel-parser#options
154159
// if: https://github.com/babel/babel/blob/main/packages/babel-parser/typings/babel-parser.d.ts#L24
155160
plugins: [
161+
'jsx',
156162
...babelParserPlugins
157163
],
158164
sourceType: 'module',
@@ -172,6 +178,8 @@ export async function createSFCModule(source : string, filename : string, option
172178
sourceMaps: genSourcemap, // https://babeljs.io/docs/en/options#sourcemaps
173179
plugins: [ // https://babeljs.io/docs/en/options#plugins
174180
babelPluginTransformModulesCommonjs, // https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#options
181+
jsx,
182+
babelSugarInjectH,
175183
...additionalBabelPlugins,
176184
],
177185
babelrc: false,

yarn.lock

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@
416416
dependencies:
417417
"@babel/helper-plugin-utils" "^7.8.0"
418418

419-
"@babel/plugin-syntax-jsx@^7.0.0":
419+
"@babel/plugin-syntax-jsx@^7.0.0", "@babel/plugin-syntax-jsx@^7.2.0":
420420
version "7.12.13"
421421
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.12.13.tgz#044fb81ebad6698fe62c478875575bcbb9b70f15"
422422
integrity sha512-d4HM23Q1K7oq/SLNmG6mRt85l2csmQ0cHRaxRXjKW0YFdEXqlZ5kzFQKH5Uc3rDJECgu+yCRgPkG04Mm98R/1g==
@@ -1220,6 +1220,11 @@
12201220
dependencies:
12211221
"@types/node" "*"
12221222

1223+
"@vue/babel-helper-vue-jsx-merge-props@^1.2.1":
1224+
version "1.2.1"
1225+
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.2.1.tgz#31624a7a505fb14da1d58023725a4c5f270e6a81"
1226+
integrity sha512-QOi5OW45e2R20VygMSNhyQHvpdUwQZqGPc748JLGCYEy+yp8fNFNdbNIGAgZmi9e+2JHPd6i6idRuqivyicIkA==
1227+
12231228
"@vue/babel-helper-vue-transform-on@^1.0.2":
12241229
version "1.0.2"
12251230
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-transform-on/-/babel-helper-vue-transform-on-1.0.2.tgz#9b9c691cd06fc855221a2475c3cc831d774bc7dc"
@@ -1240,6 +1245,81 @@
12401245
html-tags "^3.1.0"
12411246
svg-tags "^1.0.0"
12421247

1248+
"@vue/babel-plugin-transform-vue-jsx@^1.2.1":
1249+
version "1.2.1"
1250+
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-transform-vue-jsx/-/babel-plugin-transform-vue-jsx-1.2.1.tgz#646046c652c2f0242727f34519d917b064041ed7"
1251+
integrity sha512-HJuqwACYehQwh1fNT8f4kyzqlNMpBuUK4rSiSES5D4QsYncv5fxFsLyrxFPG2ksO7t5WP+Vgix6tt6yKClwPzA==
1252+
dependencies:
1253+
"@babel/helper-module-imports" "^7.0.0"
1254+
"@babel/plugin-syntax-jsx" "^7.2.0"
1255+
"@vue/babel-helper-vue-jsx-merge-props" "^1.2.1"
1256+
html-tags "^2.0.0"
1257+
lodash.kebabcase "^4.1.1"
1258+
svg-tags "^1.0.0"
1259+
1260+
"@vue/babel-preset-jsx@^1.2.4":
1261+
version "1.2.4"
1262+
resolved "https://registry.yarnpkg.com/@vue/babel-preset-jsx/-/babel-preset-jsx-1.2.4.tgz#92fea79db6f13b01e80d3a0099e2924bdcbe4e87"
1263+
integrity sha512-oRVnmN2a77bYDJzeGSt92AuHXbkIxbf/XXSE3klINnh9AXBmVS1DGa1f0d+dDYpLfsAKElMnqKTQfKn7obcL4w==
1264+
dependencies:
1265+
"@vue/babel-helper-vue-jsx-merge-props" "^1.2.1"
1266+
"@vue/babel-plugin-transform-vue-jsx" "^1.2.1"
1267+
"@vue/babel-sugar-composition-api-inject-h" "^1.2.1"
1268+
"@vue/babel-sugar-composition-api-render-instance" "^1.2.4"
1269+
"@vue/babel-sugar-functional-vue" "^1.2.2"
1270+
"@vue/babel-sugar-inject-h" "^1.2.2"
1271+
"@vue/babel-sugar-v-model" "^1.2.3"
1272+
"@vue/babel-sugar-v-on" "^1.2.3"
1273+
1274+
"@vue/babel-sugar-composition-api-inject-h@^1.2.1":
1275+
version "1.2.1"
1276+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-composition-api-inject-h/-/babel-sugar-composition-api-inject-h-1.2.1.tgz#05d6e0c432710e37582b2be9a6049b689b6f03eb"
1277+
integrity sha512-4B3L5Z2G+7s+9Bwbf+zPIifkFNcKth7fQwekVbnOA3cr3Pq71q71goWr97sk4/yyzH8phfe5ODVzEjX7HU7ItQ==
1278+
dependencies:
1279+
"@babel/plugin-syntax-jsx" "^7.2.0"
1280+
1281+
"@vue/babel-sugar-composition-api-render-instance@^1.2.4":
1282+
version "1.2.4"
1283+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-composition-api-render-instance/-/babel-sugar-composition-api-render-instance-1.2.4.tgz#e4cbc6997c344fac271785ad7a29325c51d68d19"
1284+
integrity sha512-joha4PZznQMsxQYXtR3MnTgCASC9u3zt9KfBxIeuI5g2gscpTsSKRDzWQt4aqNIpx6cv8On7/m6zmmovlNsG7Q==
1285+
dependencies:
1286+
"@babel/plugin-syntax-jsx" "^7.2.0"
1287+
1288+
"@vue/babel-sugar-functional-vue@^1.2.2":
1289+
version "1.2.2"
1290+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-functional-vue/-/babel-sugar-functional-vue-1.2.2.tgz#267a9ac8d787c96edbf03ce3f392c49da9bd2658"
1291+
integrity sha512-JvbgGn1bjCLByIAU1VOoepHQ1vFsroSA/QkzdiSs657V79q6OwEWLCQtQnEXD/rLTA8rRit4rMOhFpbjRFm82w==
1292+
dependencies:
1293+
"@babel/plugin-syntax-jsx" "^7.2.0"
1294+
1295+
"@vue/babel-sugar-inject-h@^1.2.2":
1296+
version "1.2.2"
1297+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-inject-h/-/babel-sugar-inject-h-1.2.2.tgz#d738d3c893367ec8491dcbb669b000919293e3aa"
1298+
integrity sha512-y8vTo00oRkzQTgufeotjCLPAvlhnpSkcHFEp60+LJUwygGcd5Chrpn5480AQp/thrxVm8m2ifAk0LyFel9oCnw==
1299+
dependencies:
1300+
"@babel/plugin-syntax-jsx" "^7.2.0"
1301+
1302+
"@vue/babel-sugar-v-model@^1.2.3":
1303+
version "1.2.3"
1304+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-v-model/-/babel-sugar-v-model-1.2.3.tgz#fa1f29ba51ebf0aa1a6c35fa66d539bc459a18f2"
1305+
integrity sha512-A2jxx87mySr/ulAsSSyYE8un6SIH0NWHiLaCWpodPCVOlQVODCaSpiR4+IMsmBr73haG+oeCuSvMOM+ttWUqRQ==
1306+
dependencies:
1307+
"@babel/plugin-syntax-jsx" "^7.2.0"
1308+
"@vue/babel-helper-vue-jsx-merge-props" "^1.2.1"
1309+
"@vue/babel-plugin-transform-vue-jsx" "^1.2.1"
1310+
camelcase "^5.0.0"
1311+
html-tags "^2.0.0"
1312+
svg-tags "^1.0.0"
1313+
1314+
"@vue/babel-sugar-v-on@^1.2.3":
1315+
version "1.2.3"
1316+
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-v-on/-/babel-sugar-v-on-1.2.3.tgz#342367178586a69f392f04bfba32021d02913ada"
1317+
integrity sha512-kt12VJdz/37D3N3eglBywV8GStKNUhNrsxChXIV+o0MwVXORYuhDTHJRKPgLJRb/EY3vM2aRFQdxJBp9CLikjw==
1318+
dependencies:
1319+
"@babel/plugin-syntax-jsx" "^7.2.0"
1320+
"@vue/babel-plugin-transform-vue-jsx" "^1.2.1"
1321+
camelcase "^5.0.0"
1322+
12431323
12441324
version "3.0.7"
12451325
resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.0.7.tgz#421782a4c67cc3f2b7c30457ef446d74f8524f74"
@@ -3471,6 +3551,11 @@ html-escaper@^2.0.0:
34713551
resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453"
34723552
integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==
34733553

3554+
html-tags@^2.0.0:
3555+
version "2.0.0"
3556+
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-2.0.0.tgz#10b30a386085f43cede353cc8fa7cb0deeea668b"
3557+
integrity sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos=
3558+
34743559
html-tags@^3.1.0:
34753560
version "3.1.0"
34763561
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.1.0.tgz#7b5e6f7e665e9fb41f30007ed9e0d41e97fb2140"
@@ -4556,6 +4641,11 @@ lodash.ismatch@^4.4.0:
45564641
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
45574642
integrity sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc=
45584643

4644+
lodash.kebabcase@^4.1.1:
4645+
version "4.1.1"
4646+
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
4647+
integrity sha1-hImxyw0p/4gZXM7KRI/21swpXDY=
4648+
45594649
lodash.memoize@^4.1.2:
45604650
version "4.1.2"
45614651
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"

0 commit comments

Comments
 (0)