Skip to content

Commit 04d4373

Browse files
authored
Merge pull request #5 from nickmessing/fix/camelCase-directives
fix: Support camelCase directives
2 parents bb5b2af + a903610 commit 04d4373

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

packages/babel-plugin-transform-vue-jsx/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"dependencies": {
3737
"@babel/helper-module-imports": "^7.0.0-beta.49",
3838
"@babel/plugin-syntax-jsx": "^7.0.0-beta.49",
39-
"@vuejs/babel-helper-vue-jsx-merge-props": "^0.1.0"
39+
"@vuejs/babel-helper-vue-jsx-merge-props": "^0.1.0",
40+
"lodash.kebabcase": "^4.1.1"
4041
},
4142
"nyc": {
4243
"exclude": [

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import syntaxJsx from '@babel/plugin-syntax-jsx'
22
import { addDefault } from '@babel/helper-module-imports'
3+
import kebabcase from 'lodash.kebabcase'
34

45
const xlinkRE = /^xlink([A-Z])/
56
const directiveRE = /^v-/
@@ -161,6 +162,9 @@ const parseAttributeJSXAttribute = (t, path, attributes, tagName, elementType) =
161162
if (name.startsWith(`v-`)) {
162163
name = name.replace(directiveRE, '')
163164
prefix = 'directives'
165+
} else if (name.startsWith('v') && name.length >= 2 && name[1] >= 'A' && name[1] <= 'Z') {
166+
name = kebabcase(name.substr(1))
167+
prefix = 'directives'
164168
}
165169
if (name.match(xlinkRE)) {
166170
name = name.replace(xlinkRE, (_, firstCharacter) => {

packages/babel-plugin-transform-vue-jsx/test/functional.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ test('Spread (mixed)', t => {
234234
test('Custom directives', t => {
235235
const wrapper = shallow({
236236
render(h) {
237-
return <div v-test={123} v-other={234} />
237+
return <div v-test={123} vOther={234} />
238238
},
239239
})
240240

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,13 @@ render(h => h("div", _mergeJSXProps([{}, spread, {
215215
},
216216
{
217217
name: 'Directives',
218-
from: `render(h => <div v-test={ 123 } v-other={ 234 } />)`,
218+
from: `render(h => <div v-test={ 123 } vOtherStuff={ 234 } />)`,
219219
to: `render(h => h("div", {
220220
"directives": [{
221221
name: "test",
222222
value: 123
223223
}, {
224-
name: "other",
224+
name: "other-stuff",
225225
value: 234
226226
}]
227227
}));`,

packages/babel-plugin-transform-vue-jsx/yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,6 +2929,10 @@ lodash.isequal@^4.5.0:
29292929
version "4.5.0"
29302930
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
29312931

2932+
lodash.kebabcase@^4.1.1:
2933+
version "4.1.1"
2934+
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
2935+
29322936
lodash.merge@^4.6.0:
29332937
version "4.6.1"
29342938
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54"

0 commit comments

Comments
 (0)