Skip to content

Commit

Permalink
Add tricky expression on object expression (#381)
Browse files Browse the repository at this point in the history
* except if property value is member expression

* apply prettier
  • Loading branch information
healtheloper committed Apr 5, 2023
1 parent a7d8394 commit f701586
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/visitors/transpileCssProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default t => (path, state) => {
? property.key.name !== property.value.name
: true) &&
// and not a tricky expression
!t.isMemberExpression(property.value) &&
!t.isLogicalExpression(property.value) &&
!t.isConditionalExpression(property.value))
) {
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/transpile-css-prop/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ const ObjectInterpolationLogical = ({ bg, content, height, width, ...p }) => {
)
}

const ObjectInterpolationMember = p => {
const theme = useTheme()
const color = 'red'

return (
<p
css={{
color: theme.colors[color],
}}
>
H
</p>
)
}

const RenderPropComponentCSSProp = () => {
return (
<RenderPropComponent>
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/transpile-css-prop/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ var ObjectInterpolationLogical = function ObjectInterpolationLogical(_ref4) {
</_StyledP14>;
};

var ObjectInterpolationMember = function ObjectInterpolationMember(p) {
var theme = useTheme();
var color = 'red';
return <_StyledP15 $_css19={theme.colors[color]}>
H
</_StyledP15>;
};

var RenderPropComponentCSSProp = function RenderPropComponentCSSProp() {
return <RenderPropComponent>
{function () {
Expand Down Expand Up @@ -309,6 +317,12 @@ var _StyledP14 = (0, _styledComponents["default"])("p")(function (p) {
};
});

var _StyledP15 = (0, _styledComponents["default"])("p")(function (p) {
return {
color: p.$_css19
};
});

var _StyledDiv2 = (0, _styledComponents["default"])("div")(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n color: black;\n "])));

var _StyledDiv3 = (0, _styledComponents["default"])("div")(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["\n color: black;\n "])));

0 comments on commit f701586

Please sign in to comment.