From 0b137e8731b5410feb1477f3595659b14fa0905c Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:04:39 +0800 Subject: [PATCH] Preserve declaration order after @at-root --- index.js | 1 + index.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/index.js b/index.js index e9125de..c228f54 100644 --- a/index.js +++ b/index.js @@ -424,6 +424,7 @@ let nested = (opts = {}) => { ) if (child.name === rootRuleName) { + copyDeclarations = true unwrapped = true atruleChilds(rule, child, true, child[ROOT_RULE_MERGE_SEL]) after = breakOut(child, after) diff --git a/index.test.js b/index.test.js index a5ab0fe..916bb66 100644 --- a/index.test.js +++ b/index.test.js @@ -62,6 +62,20 @@ test('at-root short hand', () => { run('a { & {} @at-root b { } }', 'a {} b {}') }) +test('keeps declarations after at-root shorthand in source order', () => { + run( + 'a { color: red; @at-root a { color: blue; } color: green; }', + 'a { color: red; } a { color: blue; } a { color: green; }' + ) +}) + +test('keeps declarations after an at-root block in source order', () => { + run( + 'a { color: red; @at-root { a { color: blue; } } color: green; }', + 'a { color: red; } a { color: blue; } a { color: green; }' + ) +}) + test('hoists multiple at-roots', () => { run( `a {