Skip to content

Commit dbe3302

Browse files
committed
fix invalid report from template(v-for) > div(v-for)
fixes vuejs#164 vuejs/vetur#400
1 parent 71929fa commit dbe3302

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/rules/valid-v-for.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,22 @@ function isUsingIterationVar (vFor, vBindKey) {
4141
* @param {RuleContext} context The rule context to report.
4242
* @param {ASTNode} vFor The attribute node of `v-for` to check.
4343
* @param {ASTNode} element The element node to check.
44+
* @param {boolean} child Are we working on child element.
4445
*/
45-
function checkKey (context, vFor, element) {
46+
function checkKey (context, vFor, element, child) {
4647
if (element.name === 'template') {
4748
for (const child of element.children) {
4849
if (child.type === 'VElement') {
49-
checkKey(context, vFor, child)
50+
checkKey(context, vFor, child, true)
5051
}
5152
}
5253
return
5354
}
5455

56+
if (child && utils.hasDirective(element, 'for')) { // template(v-for) > div(v-for)
57+
return
58+
}
59+
5560
const vBindKey = utils.getDirective(element, 'bind', 'key')
5661

5762
if (utils.isCustomComponent(element) && vBindKey == null) {
@@ -83,7 +88,7 @@ function create (context) {
8388
"VAttribute[directive=true][key.name='for']" (node) {
8489
const element = node.parent.parent
8590

86-
checkKey(context, node, element)
91+
checkKey(context, node, element, false)
8792

8893
if (node.key.argument) {
8994
context.report({

tests/lib/rules/valid-v-for.js

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ tester.run('valid-v-for', rule, {
8282
{
8383
filename: 'test.vue',
8484
code: '<template v-for="x of list">foo<div></div></template>'
85+
},
86+
{
87+
filename: 'test.vue',
88+
code: '<template><template v-for="x of list"><div v-for="foo of x" :key="foo"></div></template></template>'
8589
}
8690
],
8791
invalid: [

0 commit comments

Comments
 (0)