lightningcss icon indicating copy to clipboard operation
lightningcss copied to clipboard

"&" selector not preserved inside @scope

Open axyz opened this issue 1 year ago • 1 comments

Hi, I noticed an issue with @scope at rules.

When the & selector is used, it does not get preserved and it gets substituted with a :scope selector

can be verified here

Beside being slightly longer for the sake of minification, the selector should be preserved as it is (either & or :scope) due to the different impact on specificity.

Additionally & supports reuse in the same selector.

e.g.

@scope(.foo) {
  & &  {
    --color: yellow;
  }
}

this is valid in CSS, but using lightningcss it outputs

@scope (.foo) {
  :scope :scope {
    --color: yellow;
  }
}

that is invalid. playground here

axyz avatar Mar 14 '24 08:03 axyz

Hmm, I think this isn't really a valid configuration. You've set the target to an old version of chrome that doesn't support @scope or nesting. And since scope is only supported in browsers that also support nesting, this won't actually happen. If you raise your target to a newer version, it works correctly. See example

devongovett avatar May 17 '24 03:05 devongovett