Skip to content

Commit a394e34

Browse files
committed
use older object literal form
still supported by new styled-components
1 parent 1dd7883 commit a394e34

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/styled-components.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ export default function TaggedTemplateExpression(path, state) {
3636
// hoisted helpers in closure
3737
function insertBefore(node, id) {
3838
return t.callExpression(t.memberExpression(node, t.identifier('attrs')), [
39-
t.arrowFunctionExpression(
40-
[],
41-
t.objectExpression([
42-
t.objectProperty(t.StringLiteral(options.attribute), t.StringLiteral(id))
43-
])
44-
)
39+
t.objectExpression([
40+
t.objectProperty(t.StringLiteral(options.attribute), t.StringLiteral(id))
41+
])
4542
])
4643
}
4744
function isStyledPrefix(node) {

test/fixtures/react/styled-components/actual.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const withChain = styled.div.withConfig()`
1111
color: black;
1212
`
1313

14+
const withInterpolation = styled.div`
15+
color: ${Colors.black};
16+
`
17+
1418
const el = styled(El)`
1519
color: black;
1620
`

test/fixtures/react/styled-components/expected.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,46 @@ import styled from 'styled-components';
33

44
/* should be transformed */
55

6-
const basic = styled.div.attrs(() => ({
6+
const basic = styled.div.attrs({
77
'data-qa': 'basic'
8-
}))`
8+
})`
99
color: black;
1010
`;
1111

12-
const withChain = styled.div.attrs(() => ({
12+
const withChain = styled.div.attrs({
1313
'data-qa': 'withChain'
14-
})).withConfig()`
14+
}).withConfig()`
1515
color: black;
1616
`;
1717

18-
const el = styled(El).attrs(() => ({
18+
const withInterpolation = styled.div.attrs({
19+
'data-qa': 'withInterpolation'
20+
})`
21+
color: ${Colors.black};
22+
`;
23+
24+
const el = styled(El).attrs({
1925
'data-qa': 'el'
20-
}))`
26+
})`
2127
color: black;
2228
`;
2329

24-
const arrowExpr = () => styled.div.attrs(() => ({
30+
const arrowExpr = () => styled.div.attrs({
2531
'data-qa': 'arrowExpr'
26-
}))`
32+
})`
2733
color: black;
2834
`;
2935

3036
// covered by VariableDeclaraion cases
31-
export const exported = styled.div.attrs(() => ({
37+
export const exported = styled.div.attrs({
3238
'data-qa': 'exported'
33-
}))`
39+
})`
3440
color: black;
3541
`;
3642

37-
export default styled.div.attrs(() => ({
43+
export default styled.div.attrs({
3844
'data-qa': 'actual'
39-
}))`
45+
})`
4046
color: black;
4147
`;
4248

0 commit comments

Comments
 (0)