refactor: add empty v-bind warning(re #7973) (#7988)

* refactor: add empty v-bind warnings

re #7973

* Update index.js
This commit is contained in:
Yuhang Liu 2018-10-25 00:46:38 +08:00 committed by Evan You
parent db7287c23b
commit 1b69cbde74
2 changed files with 13 additions and 0 deletions

View File

@ -528,6 +528,14 @@ function processAttrs (el) {
name = name.replace(bindRE, '')
value = parseFilters(value)
isProp = false
if (
process.env.NODE_ENV !== 'production' &&
value.trim().length === 0
) {
warn(
`The value for a v-bind expression cannot be empty. Found in "v-bind:${name}"`
)
}
if (modifiers) {
if (modifiers.prop) {
isProp = true

View File

@ -510,6 +510,11 @@ describe('parser', () => {
expect(ast.props[0].value).toBe('msg')
})
it('empty v-bind expression', () => {
parse('<div :empty-msg=""></div>', baseOptions)
expect('The value for a v-bind expression cannot be empty. Found in "empty-msg"').toHaveBeenWarned()
})
// #6887
it('special case static attribute that must be props', () => {
const ast = parse('<video muted></video>', baseOptions)