Skip to content

Commit ee8f6df

Browse files
authored
Merge pull request #28 from vuejs/feat/v-model-kebab-case
Support vModel in kebab-case components
2 parents 565235a + dc0e29f commit ee8f6df

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
@@ -38,7 +38,9 @@
3838
"@babel/plugin-syntax-jsx": "^7.2.0",
3939
"@vue/babel-helper-vue-jsx-merge-props": "^0.1.0",
4040
"@vue/babel-plugin-transform-vue-jsx": "^0.1.0",
41-
"camelcase": "^5.0.0"
41+
"camelcase": "^5.0.0",
42+
"html-tags": "^2.0.0",
43+
"svg-tags": "^1.0.0"
4244
},
4345
"nyc": {
4446
"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
@@ -2659,6 +2659,11 @@ html-encoding-sniffer@^1.0.2:
26592659
dependencies:
26602660
whatwg-encoding "^1.0.1"
26612661

2662+
html-tags@^2.0.0:
2663+
version "2.0.0"
2664+
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-2.0.0.tgz#10b30a386085f43cede353cc8fa7cb0deeea668b"
2665+
integrity sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos=
2666+
26622667
http-signature@~1.2.0:
26632668
version "1.2.0"
26642669
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
@@ -5004,6 +5009,11 @@ supports-color@^5.0.0, supports-color@^5.3.0, supports-color@^5.4.0:
50045009
dependencies:
50055010
has-flag "^3.0.0"
50065011

5012+
svg-tags@^1.0.0:
5013+
version "1.0.0"
5014+
resolved "https://registry.yarnpkg.com/svg-tags/-/svg-tags-1.0.0.tgz#58f71cee3bd519b59d4b2a843b6c7de64ac04764"
5015+
integrity sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q=
5016+
50075017
symbol-observable@^0.2.2:
50085018
version "0.2.4"
50095019
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-0.2.4.tgz#95a83db26186d6af7e7a18dbd9760a2f86d08f40"

0 commit comments

Comments
 (0)