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

fix: Don't break when spreading falsy value #249

Merged
merged 1 commit into from Mar 29, 2019

Conversation

gpittarelli
Copy link
Contributor

The following is valid React:

const props = null;
<div {...props} styleName='a' />;

On master, after #243, this compiles to:

const props = null;
<div {...props} className={"foo__a" + (" " + (props.className || ""))} />;

However, this fails because it is trying to read the className property of null.

This PR fixes this (and updates the tests) by also compiling in a falsy-check around props:

const props = null;
<div {...props} className={"foo__a" + (" " + (props ? props.className || "" : ""))} />;

@gajus gajus merged commit f11d423 into gajus:master Mar 29, 2019
@gajus
Copy link
Owner

gajus commented Mar 29, 2019

🎉 This PR is included in version 5.2.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Mar 29, 2019
@gpittarelli
Copy link
Contributor Author

Thanks!

@gpittarelli gpittarelli deleted the gjp/handle-falsy-spread branch March 29, 2019 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants