Skip to content

Commit 1b69cbd

Browse files
lyhperyyx990803
authored andcommitted
refactor: add empty v-bind warning(re #7973) (#7988)
* refactor: add empty v-bind warnings re #7973 * Update index.js
1 parent db7287c commit 1b69cbd

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/compiler/parser/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,14 @@ function processAttrs (el) {
528528
name = name.replace(bindRE, '')
529529
value = parseFilters(value)
530530
isProp = false
531+
if (
532+
process.env.NODE_ENV !== 'production' &&
533+
value.trim().length === 0
534+
) {
535+
warn(
536+
`The value for a v-bind expression cannot be empty. Found in "v-bind:${name}"`
537+
)
538+
}
531539
if (modifiers) {
532540
if (modifiers.prop) {
533541
isProp = true

test/unit/modules/compiler/parser.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,11 @@ describe('parser', () => {
510510
expect(ast.props[0].value).toBe('msg')
511511
})
512512

513+
it('empty v-bind expression', () => {
514+
parse('<div :empty-msg=""></div>', baseOptions)
515+
expect('The value for a v-bind expression cannot be empty. Found in "empty-msg"').toHaveBeenWarned()
516+
})
517+
513518
// #6887
514519
it('special case static attribute that must be props', () => {
515520
const ast = parse('<video muted></video>', baseOptions)

0 commit comments

Comments
 (0)