Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#8730): Improve error reporting #8748

Merged
merged 4 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,20 @@ export function processElement (element: ASTElement, options: CompilerOptions) {
function processKey (el) {
const exp = getBindingAttr(el, 'key')
if (exp) {
if (process.env.NODE_ENV !== 'production' && el.tag === 'template') {
warn(`<template> cannot be keyed. Place the key on real elements instead.`)
if (process.env.NODE_ENV !== 'production') {
if (el.tag === 'template') {
warn(`<template> cannot be keyed. Place the key on real elements instead.`)
}
if (el.for) {
const iterator = el.iterator2 || el.iterator1
const parent = el.parent
if (iterator && iterator === exp && parent && parent.tag === 'transition-group') {
warn(
`Do not use v-for index as key on <transtion-group> children, ` +
`this is the same as not using keys.`
)
}
}
}
el.key = exp
}
Expand Down
11 changes: 11 additions & 0 deletions test/unit/modules/compiler/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ describe('parser', () => {
expect('<template> cannot be keyed').toHaveBeenWarned()
})

it('warn the child of the <transition-group> component has sequential index', () => {
parse(`
<div>
<transition-group>
<i v-for="(o, i) of arr" :key="i"></i>
</transition-group>
</div>
`, baseOptions)
expect('Do not use v-for index as key on <transtion-group> children').toHaveBeenWarned()
})

it('v-pre directive', () => {
const ast = parse('<div v-pre id="message1"><p>{{msg}}</p></div>', baseOptions)
expect(ast.pre).toBe(true)
Expand Down