Skip to content

Commit c29d6fe

Browse files
Preserve declaration order after @at-root (#181)
1 parent d7b4e8d commit c29d6fe

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ let nested = (opts = {}) => {
424424
)
425425

426426
if (child.name === rootRuleName) {
427+
copyDeclarations = true
427428
unwrapped = true
428429
atruleChilds(rule, child, true, child[ROOT_RULE_MERGE_SEL])
429430
after = breakOut(child, after)

‎index.test.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ test('at-root short hand', () => {
6262
run('a { & {} @at-root b { } }', 'a {} b {}')
6363
})
6464

65+
test('keeps declarations after at-root shorthand in source order', () => {
66+
run(
67+
'a { color: red; @at-root a { color: blue; } color: green; }',
68+
'a { color: red; } a { color: blue; } a { color: green; }'
69+
)
70+
})
71+
72+
test('keeps declarations after an at-root block in source order', () => {
73+
run(
74+
'a { color: red; @at-root { a { color: blue; } } color: green; }',
75+
'a { color: red; } a { color: blue; } a { color: green; }'
76+
)
77+
})
78+
6579
test('hoists multiple at-roots', () => {
6680
run(
6781
`a {

0 commit comments

Comments
 (0)