Skip to content

Commit dc0e29f

Browse files
committed
feat: Support vModel in kebab-case components
1 parent 566d9b7 commit dc0e29f

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

Diff for: packages/babel-sugar-v-model/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
"@babel/plugin-syntax-jsx": "^7.0.0-rc.3",
3838
"@vue/babel-helper-vue-jsx-merge-props": "^0.1.0",
3939
"@vue/babel-plugin-transform-vue-jsx": "^0.1.0",
40-
"camelcase": "^5.0.0"
40+
"camelcase": "^5.0.0",
41+
"html-tags": "^2.0.0",
42+
"svg-tags": "^1.0.0"
4143
},
4244
"nyc": {
4345
"exclude": [

Diff for: packages/babel-sugar-v-model/src/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import camelCase from 'camelcase'
22
import syntaxJsx from '@babel/plugin-syntax-jsx'
3+
import htmlTags from 'html-tags'
4+
import svgTags from 'svg-tags'
35

46
const RANGE_TOKEN = '__r'
57

@@ -109,10 +111,11 @@ const isComponent = (t, path) => {
109111
const name = path.get('name')
110112
if (t.isJSXMemberExpression(name)) {
111113
return true
112-
} else {
113-
const firstChar = name.get('name').node[0]
114-
return firstChar >= 'A' && firstChar <= 'Z'
115114
}
115+
116+
const tag = name.get('name').node
117+
118+
return !htmlTags.includes(tag) && !svgTags.includes(tag)
116119
}
117120

118121
/**

Diff for: packages/babel-sugar-v-model/test/snapshot.js

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ const tests = [
3232
callback: $$v => {
3333
a.b = $$v;
3434
}
35+
}} />;`,
36+
},
37+
{
38+
name: 'Kebab case component vModel',
39+
from: `const A = <my-component vModel={a.b} />`,
40+
to: `const A = <my-component model={{
41+
value: a.b,
42+
callback: $$v => {
43+
a.b = $$v;
44+
}
3545
}} />;`,
3646
},
3747
{

Diff for: packages/babel-sugar-v-model/yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,11 @@ html-encoding-sniffer@^1.0.2:
24132413
dependencies:
24142414
whatwg-encoding "^1.0.1"
24152415

2416+
html-tags@^2.0.0:
2417+
version "2.0.0"
2418+
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-2.0.0.tgz#10b30a386085f43cede353cc8fa7cb0deeea668b"
2419+
integrity sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos=
2420+
24162421
http-signature@~1.2.0:
24172422
version "1.2.0"
24182423
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
@@ -4407,6 +4412,11 @@ supports-color@^5.0.0, supports-color@^5.3.0:
44074412
dependencies:
44084413
has-flag "^3.0.0"
44094414

4415+
svg-tags@^1.0.0:
4416+
version "1.0.0"
4417+
resolved "https://registry.yarnpkg.com/svg-tags/-/svg-tags-1.0.0.tgz#58f71cee3bd519b59d4b2a843b6c7de64ac04764"
4418+
integrity sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q=
4419+
44104420
symbol-observable@^0.2.2:
44114421
version "0.2.4"
44124422
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-0.2.4.tgz#95a83db26186d6af7e7a18dbd9760a2f86d08f40"

0 commit comments

Comments
 (0)