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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 sequential index on the child of the <transtion-group> component, ` +
`this may cause some rendering errors.`
dejour marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
}
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 sequential index on the child of the <transtion-group> component').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