Skip to content

Commit 98e16a0

Browse files
committed
v-bind: use less aggressive interpolate warning check (close #1413)
1 parent 82cf99e commit 98e16a0

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

src/directives/public/bind.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ var modelProps = {
2020
'false-value': '_falseValue'
2121
}
2222

23-
// regex to test for globally allowed attributes.
24-
// we only need to include ones that:
25-
// - do not have a corresponding property, e.g. role, dropzone;
26-
// - cannot be camelized into the corresponding property, .e.g class, accesskey, contenteditable;
27-
var globalAllowedAttrRE = /^(class|role|accesskey|contenteditable|contextmenu|dropzone|hidden|tabindex)$|^data-|^aria-/
23+
// check for attribtues that prohibit interpolations
24+
var disallowedInterpAttrRE = /^v-|^(is|transition|transition-mode|debounce|track-by|stagger|enter-stagger|leave-stagger)$/
2825

2926
module.exports = {
3027

@@ -35,21 +32,11 @@ module.exports = {
3532
// handle interpolation bindings
3633
if (this.descriptor.interp) {
3734
// only allow binding on native attributes
38-
if (!(
39-
// globally allowed attributes
40-
globalAllowedAttrRE.test(attr) ||
41-
// check if "for" is available on current element.
42-
// the corresponding property is a special case.
43-
(attr === 'for' && 'htmlFor' in this.el) ||
44-
// other attributes: check if a camelized property
45-
// is available on the element
46-
_.camelize(attr) in this.el
47-
)) {
35+
if (disallowedInterpAttrRE.test(attr)) {
4836
process.env.NODE_ENV !== 'production' && _.warn(
4937
attr + '="' + this.descriptor.raw + '": ' +
50-
'attribute interpolation is allowed only ' +
51-
'in valid native attributes. "' + attr + '" ' +
52-
'is not a valid attribute on <' + this.el.tagName.toLowerCase() + '>.'
38+
'attribute interpolation is not allowed in Vue.js ' +
39+
'directives and special attributes.'
5340
)
5441
this.el.removeAttribute(attr)
5542
this.invalid = true

test/unit/specs/compiler/compile_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,13 @@ if (_.inBrowser) {
508508
it('attribute interpolation: warn invalid', function () {
509509
new Vue({
510510
el: el,
511-
template: '<div hello="{{a}}"></div>',
511+
template: '<div v-text="{{a}}"></div>',
512512
data: {
513513
a: '123'
514514
}
515515
})
516516
expect(el.innerHTML).toBe('<div></div>')
517-
expect(hasWarned(_, 'attribute interpolation is allowed only in valid native attributes')).toBe(true)
517+
expect(hasWarned(_, 'attribute interpolation is not allowed in Vue.js directives')).toBe(true)
518518
})
519519

520520
it('warn directives on fragment instances', function () {

0 commit comments

Comments
 (0)