Skip to content

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

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

Merged
merged 2 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
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' &&
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check all environments instead of just 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