gajus / babel-plugin-react-css-modules

Transforms styleName to className using compile time CSS module resolution.
Other
2.05k stars 162 forks source link

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

Closed gpittarelli closed 5 years ago

gpittarelli commented 5 years ago

The following is valid React:

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

On master, after https://github.com/gajus/babel-plugin-react-css-modules/pull/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 commented 5 years ago

:tada: This PR is included in version 5.2.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

gpittarelli commented 5 years ago

Thanks!