This plugin gives an invalid transform result when using css={{...}} (i.e., css prop with object notation), and a local variable name matches a css keyword that is present in the object notation.
I use vite v5.0.12, @babel/core v7.24.6, and babel-plugin-styled-components v2.1.4.
Minimal example
This minimal example shows the bug:
import { css } from "styled-components";
const TestComponent1 = () => {
let position = 1; // assume the variable is used for something else ...
return <div css={{position: "absolute"}} />;
};
Here, the <div> is transformed to this invalid JavaScript:
This plugin gives an invalid transform result when using
css={{...}}
(i.e., css prop with object notation), and a local variable name matches a css keyword that is present in the object notation.I use
vite
v5.0.12,@babel/core
v7.24.6, andbabel-plugin-styled-components
v2.1.4.Minimal example
This minimal example shows the bug:
Here, the
<div>
is transformed to this invalid JavaScript:Correct behavior
These replacements must be restricted to the right side of
:
as in this example which works correctly:In this case, the div is correctly transformed to valid JavaScript:
Full error message