Skip to content

Commit 778734a

Browse files
committed
better warning for fragment instance attributes
1 parent 0478f41 commit 778734a

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

src/compiler/compile.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,17 @@ exports.compileRoot = function (el, options, contextOptions) {
208208
}
209209
} else if (process.env.NODE_ENV !== 'production' && containerAttrs) {
210210
// warn container directives for fragment instances
211-
containerAttrs.forEach(function (attr) {
212-
if (attr.name.indexOf('v-') === 0 || attr.name === 'transition') {
213-
_.warn(
214-
attr.name + ' is ignored on component ' +
215-
'<' + options.el.tagName.toLowerCase() + '> because ' +
216-
'the component is a fragment instance: ' +
217-
'http://vuejs.org/guide/components.html#Fragment_Instance'
218-
)
219-
}
220-
})
211+
var names = containerAttrs.map(function (attr) {
212+
return '"' + attr.name + '"'
213+
}).join(', ')
214+
var plural = containerAttrs.length > 1
215+
_.warn(
216+
'Attribute' + (plural ? 's ' : ' ') + names +
217+
(plural ? ' are' : ' is') + ' ignored on component ' +
218+
'<' + options.el.tagName.toLowerCase() + '> because ' +
219+
'the component is a fragment instance: ' +
220+
'http://vuejs.org/guide/components.html#Fragment_Instance'
221+
)
221222
}
222223

223224
return function rootLinkFn (vm, el, scope) {

test/unit/lib/util.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var scope = typeof window === 'undefined'
22
? global
33
: window
44

5-
scope.hasWarned = function (_, msg) {
5+
scope.hasWarned = function (_, msg, silent) {
66
var count = _.warn.calls.count()
77
while (count--) {
88
var args = _.warn.calls.argsFor(count)
@@ -11,7 +11,9 @@ scope.hasWarned = function (_, msg) {
1111
}
1212
}
1313

14-
console.warn('[test] "' + msg + '" was never warned.')
14+
if (!silent) {
15+
console.warn('[test] "' + msg + '" was never warned.')
16+
}
1517

1618
function containsMsg (arg) {
1719
return arg.indexOf(msg) > -1

test/unit/specs/compiler/compile_spec.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,20 @@ if (_.inBrowser) {
517517
it('warn directives on fragment instances', function () {
518518
new Vue({
519519
el: el,
520-
template: '<test v-show="ok"></test>',
520+
template: '<test id="hi" class="ok" :prop="123"></test>',
521521
components: {
522522
test: {
523523
replace: true,
524-
template: '123'
524+
props: ['prop'],
525+
template: '{{prop}}'
525526
}
526527
}
527528
})
528-
expect(hasWarned(_, 'v-show is ignored on component <test>')).toBe(true)
529+
expect(_.warn.calls.count()).toBe(1)
530+
expect(
531+
hasWarned(_, 'Attributes "id", "class" are ignored on component <test>', true) ||
532+
hasWarned(_, 'Attributes "class", "id" are ignored on component <test>')
533+
).toBe(true)
529534
})
530535

531536
it('should compile component container directives using correct context', function () {

0 commit comments

Comments
 (0)