Skip to content

Commit

Permalink
refactor: add empty v-bind warning(re vuejs#7973) (vuejs#7988)
Browse files Browse the repository at this point in the history
* refactor: add empty v-bind warnings

re vuejs#7973

* Update index.js
  • Loading branch information
lyhper authored and yyx990803 committed Oct 24, 2018
1 parent db7287c commit 1b69cbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/unit/modules/compiler/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1b69cbd

Please sign in to comment.