Skip to content

Commit 45a4744

Browse files
committed
refactor: add empty v-bind warnings
re vuejs#7973
1 parent 6226503 commit 45a4744

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 "${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)