Skip to content

Commit 27c7016

Browse files
author
klarstrup
authored
fix #360 (#361)
1 parent efb7a63 commit 27c7016

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

src/visitors/transpileCssProp.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ export default t => (path, state) => {
123123
if (!css) return
124124

125125
// strip off css prop from final output
126-
elem.node.attributes = elem.node.attributes.filter(x =>
127-
t.isJSXAttribute(x) ? x.name.name !== 'css' : false
126+
elem.node.attributes = elem.node.attributes.filter(
127+
x =>
128+
t.isJSXSpreadAttribute(x) ||
129+
(t.isJSXAttribute(x) ? x.name.name !== 'css' : false)
128130
)
129131

130132
elem.node.name = t.jSXIdentifier(id.name)

test/fixtures/transpile-css-prop/code.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,40 @@ const ObjectInterpolationLogical = ({ bg, content, height, width, ...p }) => {
232232
</p>
233233
)
234234
}
235+
236+
const RenderPropComponentCSSProp = () => {
237+
return (
238+
<RenderPropComponent>
239+
{() => (
240+
<div
241+
css={`
242+
color: black;
243+
`}
244+
/>
245+
)}
246+
</RenderPropComponent>
247+
)
248+
}
249+
250+
const RenderPropComponentSpread = props => {
251+
return (
252+
<RenderPropComponent>
253+
{() => <div {...props.derivedProps} />}
254+
</RenderPropComponent>
255+
)
256+
}
257+
258+
const RenderPropComponentSpreadCSSProp = props => {
259+
return (
260+
<RenderPropComponent>
261+
{() => (
262+
<div
263+
css={`
264+
color: black;
265+
`}
266+
{...props.derivedProps}
267+
/>
268+
)}
269+
</RenderPropComponent>
270+
)
271+
}

test/fixtures/transpile-css-prop/output.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
44

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

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

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

@@ -201,11 +201,35 @@ var ObjectInterpolationLogical = function ObjectInterpolationLogical(_ref4) {
201201
width = _ref4.width,
202202
p = _objectWithoutProperties(_ref4, _excluded);
203203

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

209+
var RenderPropComponentCSSProp = function RenderPropComponentCSSProp() {
210+
return <RenderPropComponent>
211+
{function () {
212+
return <_StyledDiv2 />;
213+
}}
214+
</RenderPropComponent>;
215+
};
216+
217+
var RenderPropComponentSpread = function RenderPropComponentSpread(props) {
218+
return <RenderPropComponent>
219+
{function () {
220+
return <div {...props.derivedProps} />;
221+
}}
222+
</RenderPropComponent>;
223+
};
224+
225+
var RenderPropComponentSpreadCSSProp = function RenderPropComponentSpreadCSSProp(props) {
226+
return <RenderPropComponent>
227+
{function () {
228+
return <_StyledDiv3 {...props.derivedProps} />;
229+
}}
230+
</RenderPropComponent>;
231+
};
232+
209233
var _StyledP = (0, _styledComponents["default"])("p")(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["flex: 1;"])));
210234

211235
var _StyledP2 = (0, _styledComponents["default"])("p")(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n flex: 1;\n "])));
@@ -284,3 +308,7 @@ var _StyledP14 = (0, _styledComponents["default"])("p")(function (p) {
284308
}
285309
};
286310
});
311+
312+
var _StyledDiv2 = (0, _styledComponents["default"])("div")(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n color: black;\n "])));
313+
314+
var _StyledDiv3 = (0, _styledComponents["default"])("div")(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["\n color: black;\n "])));

0 commit comments

Comments
 (0)