Skip to content

Print unknown at-rules in the same location#1233

Merged
devongovett merged 2 commits into
parcel-bundler:masterfrom
RobinMalfait:fix/issue-1232
May 17, 2026
Merged

Print unknown at-rules in the same location#1233
devongovett merged 2 commits into
parcel-bundler:masterfrom
RobinMalfait:fix/issue-1232

Conversation

@RobinMalfait

@RobinMalfait RobinMalfait commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

This PR is an attempt in fixing #1232 where unknown at-rules were hoisted outside of its parent instead of staying in place. This PR is not adding proper support for @apply, but is just used as an example.

I added some tests with various syntaxes as seen in https://drafts.csswg.org/css-mixins-1/#apply-rule. I also added some nesting to make sure that works as expected.

Added some tests with the following input:

.foo {
  @apply --mixin;
  @apply --mixin-no-args();
  @apply --mixin-args(1, 2);
  @apply --mixin-with-empty-body {};
  @apply --mixin-with-body {
    color: red;
  }
  .bar {
    @apply --nested;
  }
}

Before, this would generate:

@apply --mixin;

@apply --mixin-no-args();

@apply --mixin-args(1, 2);

@apply --mixin-with-empty-body {
  
}

@apply --mixin-with-body {
  color: red;
}

@apply --nested;

As you can see, the .foo and .bar are even gone, because at some point they won't contain any declarations anymore and are just removed.

But with this PR, it will generate:

.foo {
  @apply --mixin;
  @apply --mixin-no-args();
  @apply --mixin-args(1, 2);
  @apply --mixin-with-empty-body {
    
  }
  @apply --mixin-with-body {
    color: red;
  }
}

.foo .bar {
  @apply --nested;
}

Like I mentioned before, this doesn't add proper support for @apply, so this is just an attempt in properly printing the correct output. There is no validation related to the actual mixins that are being applied here.

Fixes: #1232

@RobinMalfait RobinMalfait marked this pull request as ready for review April 30, 2026 18:50

@devongovett devongovett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this makes sense. With other at rules, the at rule gets hoisted and the style rule gets placed inside it, but I guess if the at rule is unknown we can't do that or even know if it's the desired behavior so just preserving it as is makes sense.

@devongovett devongovett merged commit 729e03e into parcel-bundler:master May 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unknown at-rules, are incorrectly hoisted

2 participants