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 #360 #361

Merged
merged 1 commit into from Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/visitors/transpileCssProp.js
Expand Up @@ -123,8 +123,10 @@ export default t => (path, state) => {
if (!css) return

// strip off css prop from final output
elem.node.attributes = elem.node.attributes.filter(x =>
t.isJSXAttribute(x) ? x.name.name !== 'css' : false
elem.node.attributes = elem.node.attributes.filter(
x =>
t.isJSXSpreadAttribute(x) ||
(t.isJSXAttribute(x) ? x.name.name !== 'css' : false)
)

elem.node.name = t.jSXIdentifier(id.name)
Expand Down
37 changes: 37 additions & 0 deletions test/fixtures/transpile-css-prop/code.js
Expand Up @@ -232,3 +232,40 @@ const ObjectInterpolationLogical = ({ bg, content, height, width, ...p }) => {
</p>
)
}

const RenderPropComponentCSSProp = () => {
return (
<RenderPropComponent>
{() => (
<div
css={`
color: black;
`}
/>
)}
</RenderPropComponent>
)
}

const RenderPropComponentSpread = props => {
return (
<RenderPropComponent>
{() => <div {...props.derivedProps} />}
</RenderPropComponent>
)
}

const RenderPropComponentSpreadCSSProp = props => {
return (
<RenderPropComponent>
{() => (
<div
css={`
color: black;
`}
{...props.derivedProps}
/>
)}
</RenderPropComponent>
)
}
32 changes: 30 additions & 2 deletions test/fixtures/transpile-css-prop/output.js
Expand Up @@ -4,7 +4,7 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));

var _excluded = ["bg", "content", "height", "width"];

var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

Expand Down Expand Up @@ -201,11 +201,35 @@ var ObjectInterpolationLogical = function ObjectInterpolationLogical(_ref4) {
width = _ref4.width,
p = _objectWithoutProperties(_ref4, _excluded);

return <_StyledP14 $_css15={bg || 'red'} $_css16={height !== null && height !== void 0 ? height : '100%'} $_css17={width ? "".concat(width, "px") : '100%'} $_css18={content}>
return <_StyledP14 {...p} $_css15={bg || 'red'} $_css16={height !== null && height !== void 0 ? height : '100%'} $_css17={width ? "".concat(width, "px") : '100%'} $_css18={content}>
H
</_StyledP14>;
};

var RenderPropComponentCSSProp = function RenderPropComponentCSSProp() {
return <RenderPropComponent>
{function () {
return <_StyledDiv2 />;
}}
</RenderPropComponent>;
};

var RenderPropComponentSpread = function RenderPropComponentSpread(props) {
return <RenderPropComponent>
{function () {
return <div {...props.derivedProps} />;
}}
</RenderPropComponent>;
};

var RenderPropComponentSpreadCSSProp = function RenderPropComponentSpreadCSSProp(props) {
return <RenderPropComponent>
{function () {
return <_StyledDiv3 {...props.derivedProps} />;
}}
</RenderPropComponent>;
};

var _StyledP = (0, _styledComponents["default"])("p")(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["flex: 1;"])));

var _StyledP2 = (0, _styledComponents["default"])("p")(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n flex: 1;\n "])));
Expand Down Expand Up @@ -284,3 +308,7 @@ var _StyledP14 = (0, _styledComponents["default"])("p")(function (p) {
}
};
});

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 "])));