Skip to content

Commit 581689a

Browse files
committed
Fix: crash no-v-invalid-v-for on :key (fixes #37)
1 parent 47532e2 commit 581689a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/rules/no-invalid-v-for.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const utils = require('../utils')
2121
* @returns {boolean} `true` if the node is using the variables which are defined by `v-for` directives.
2222
*/
2323
function isUsingIterationVar (node) {
24+
if (node.value == null) {
25+
return false
26+
}
2427
const references = node.value.references
2528
const variables = node.parent.parent.variables
2629

tests/lib/rules/no-invalid-v-for.js

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ tester.run('no-invalid-v-for', rule, {
144144
filename: 'test.vue',
145145
code: '<template><div><custom-component v-for="x in list" :key="foo"></custom-component></div></template>',
146146
errors: ["Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive."]
147+
},
148+
{
149+
filename: 'test.vue',
150+
code: '<template><div><div v-for="(item, index) in suggestions" :key></div></div></template>',
151+
errors: ["Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive."]
147152
}
148153
]
149154
})

0 commit comments

Comments
 (0)