Skip to content

Commit 12a311e

Browse files
committed
fix: Force html & svg tags to always be treated as string tags
1 parent 51ca488 commit 12a311e

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Diff for: packages/babel-plugin-transform-vue-jsx/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
"@babel/helper-module-imports": "^7.0.0-rc.3",
3838
"@babel/plugin-syntax-jsx": "^7.0.0-rc.3",
3939
"@vue/babel-helper-vue-jsx-merge-props": "^0.1.0",
40-
"lodash.kebabcase": "^4.1.1"
40+
"html-tags": "^2.0.0",
41+
"lodash.kebabcase": "^4.1.1",
42+
"svg-tags": "^1.0.0"
4143
},
4244
"peerDependencies": {
4345
"@vue/babel-helper-vue-jsx-merge-props": "^0.1.0"

Diff for: packages/babel-plugin-transform-vue-jsx/src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import syntaxJsx from '@babel/plugin-syntax-jsx'
22
import { addDefault } from '@babel/helper-module-imports'
33
import kebabcase from 'lodash.kebabcase'
4+
import htmlTags from 'html-tags'
5+
import svgTags from 'svg-tags'
46

57
const xlinkRE = /^xlink([A-Z])/
68
const rootAttributes = ['class', 'style', 'key', 'ref', 'refInFor', 'slot', 'scopedSlots', 'model']
@@ -40,7 +42,7 @@ const getTag = (t, path) => {
4042
const namePath = path.get('name')
4143
if (t.isJSXIdentifier(namePath)) {
4244
const name = namePath.get('name').node
43-
if (path.scope.hasBinding(name)) {
45+
if (path.scope.hasBinding(name) && !htmlTags.includes(name) && !svgTags.includes(name)) {
4446
return t.identifier(name)
4547
} else {
4648
return t.stringLiteral(name)

Diff for: packages/babel-plugin-transform-vue-jsx/test/snapshot.js

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ const tests = [
2424
from: `render(h => <div>test</div>)`,
2525
to: `render(h => h("div", ["test"]));`,
2626
},
27+
{
28+
name: 'HTML tag if variable in scope',
29+
from: `const div = {}; render(h => <div>test</div>)`,
30+
to: `const div = {};
31+
render(h => h("div", ["test"]));`,
32+
},
2733
{
2834
name: 'Tag & Component',
2935
from: `const Alpha = {}; render(h => [<Alpha>test</Alpha>, <Beta>test</Beta>])`,

Diff for: packages/babel-plugin-transform-vue-jsx/yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,11 @@ html-encoding-sniffer@^1.0.2:
25722572
dependencies:
25732573
whatwg-encoding "^1.0.1"
25742574

2575+
html-tags@^2.0.0:
2576+
version "2.0.0"
2577+
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-2.0.0.tgz#10b30a386085f43cede353cc8fa7cb0deeea668b"
2578+
integrity sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos=
2579+
25752580
http-signature@~1.2.0:
25762581
version "1.2.0"
25772582
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
@@ -4591,6 +4596,11 @@ supports-color@^5.0.0, supports-color@^5.3.0:
45914596
dependencies:
45924597
has-flag "^3.0.0"
45934598

4599+
svg-tags@^1.0.0:
4600+
version "1.0.0"
4601+
resolved "https://registry.yarnpkg.com/svg-tags/-/svg-tags-1.0.0.tgz#58f71cee3bd519b59d4b2a843b6c7de64ac04764"
4602+
integrity sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q=
4603+
45944604
symbol-observable@^0.2.2:
45954605
version "0.2.4"
45964606
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-0.2.4.tgz#95a83db26186d6af7e7a18dbd9760a2f86d08f40"

0 commit comments

Comments
 (0)