Skip to content

Commit 9c6fb25

Browse files
committed
Fix sorting inside CSS-in-JS css helper
1 parent 572db23 commit 9c6fb25

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

lib/getContainingNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = function getContainingNode(node) {
44
}
55

66
// postcss-styled-syntax: declarations are children of Root node
7-
if (node.parent?.type === 'root' && node.parent?.raws.styledSyntaxIsComponent) {
7+
if (node.parent?.type === 'root' && node.parent?.raws.isRuleLike) {
88
return node.parent;
99
}
1010

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Component = styled.div`
2+
${() => css`
3+
position: absolute;
4+
top: 0;
5+
display: block;
6+
z-index: 2;
7+
`};
8+
`;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Component = styled.div`
2+
${() => css`
3+
z-index: 2;
4+
top: 0;
5+
position: absolute;
6+
display: block;
7+
`};
8+
`;

lib/properties-order/__tests__/properties-order.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ test('Should sort properties in nested rules (styled)', () =>
199199
__dirname
200200
));
201201

202+
test('Should sort properties in css helper (styled)', () =>
203+
runTest(
204+
'inside-css-helper.js',
205+
{
206+
'properties-order': ['position', 'top', 'display', 'z-index'],
207+
},
208+
__dirname
209+
));
210+
202211
test('Ignore template literals in flat components (styled)', () =>
203212
runTest(
204213
'ignore-template-literals-flat.js',

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"lint-staged": "^13.1.0",
3636
"postcss": "^8.4.20",
3737
"postcss-html": "^1.5.0",
38-
"postcss-styled-syntax": "^0.1.0",
38+
"postcss-styled-syntax": "^0.4.0",
3939
"prettier": "^2.8.1",
4040
"prettier-config-hudochenkov": "^0.3.0"
4141
},

0 commit comments

Comments
 (0)