Skip to content
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

Empty bound prop's cause a render exception #5192

Closed
jameshulse opened this issue Mar 14, 2017 · 3 comments
Closed

Empty bound prop's cause a render exception #5192

jameshulse opened this issue Mar 14, 2017 · 3 comments

Comments

@jameshulse
Copy link

@jameshulse jameshulse commented Mar 14, 2017

Vue.js version

2.2.4

Reproduction Link

https://jsfiddle.net/wwuyv17z/

Steps to reproduce

Pass nothing to a bound prop such as in the example: <test :user=""></test>

What is Expected?

At worst I would expect a warning in the console and no crash; at best I would expect the prop to come through with a null value to the component.

If it is agreed that a warning or null replacement should happen then I am happy to try and pull request this change myself.

What is actually happening?

An error occurs similar to:

[Vue warn]: Failed to generate render function:

SyntaxError: Unexpected token } in

with(this){return _c('div',{attrs:{"id":"app"}},[_c('test',{attrs:{"user":}})],1)}
 
(found in <Root>)
@yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Mar 14, 2017

This is expected. You'd get a syntax error in JS too if you don't give an object field a value.

@jameshulse
Copy link
Author

@jameshulse jameshulse commented Mar 14, 2017

Thanks for the response Evan.

I appreciate that. Once you get your head around the fact that bound props are basically javascript properties.

In that case, does Vue have a concept of error checking in dev mode? I just helped a beginner who ran in to this issue - I think they could have worked out the issue themselves if they had received something similar to:

[Vue warn] Bound property 'user' should not be empty on component 'test'

Again, happy to try and add this if you think it's useful.

@yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Mar 14, 2017

Yes, this should be possible by checking value here. If you work on a PR, make sure to include an accompanying test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants