Skip to content

Commit 0894903

Browse files
committed
add warning for camelCase paramAttributes (vuejs#625)
1 parent 3ea564b commit 0894903

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/compiler/compile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,15 @@ function compileParamAttributes (el, attrs, options) {
333333
var name, value, param
334334
while (i--) {
335335
name = attrs[i]
336+
if (/[A-Z]/.test(name)) {
337+
_.warn(
338+
'You seem to be using camelCase for a paramAttribute, ' +
339+
'but HTML doesn\'t differentiate between upper and ' +
340+
'lower case. You should use hyphen-delimited ' +
341+
'attribute names. For more info see ' +
342+
'http://vuejs.org/api/options.html#paramAttributes'
343+
)
344+
}
336345
value = el.getAttribute(name)
337346
if (value !== null) {
338347
param = {

test/unit/specs/compiler/compile_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ if (_.inBrowser) {
149149

150150
it('param attributes', function () {
151151
var options = merge(Vue.options, {
152-
paramAttributes: ['a', 'data-some-attr', 'some-other-attr', 'invalid']
152+
paramAttributes: ['a', 'data-some-attr', 'some-other-attr', 'invalid', 'camelCase']
153153
})
154154
var def = Vue.options.directives['with']
155155
el.setAttribute('a', '1')
@@ -165,8 +165,8 @@ if (_.inBrowser) {
165165
expect(args[1]).toBe(el)
166166
expect(args[2].arg).toBe('someAttr')
167167
expect(args[3]).toBe(def)
168-
// invalid should've warn
169-
expect(_.warn).toHaveBeenCalled()
168+
// invalid and camelCase should've warn
169+
expect(_.warn.calls.count()).toBe(2)
170170
// literal should've called vm.$set
171171
expect(vm.$set).toHaveBeenCalledWith('a', '1')
172172
expect(vm.$set).toHaveBeenCalledWith('someOtherAttr', '2')

0 commit comments

Comments
 (0)