Skip to content

Commit c27a1e6

Browse files
puckowskidylhunn
authored andcommitted
feat(compiler): scope selectors in @scope queries (#50747)
make sure selectors inside @scope queries are correctly scoped PR Close #50747
1 parent 3dafc14 commit c27a1e6

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/compiler/src/shadow_css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ export class ShadowCss {
560560
} else if (
561561
rule.selector.startsWith('@media') || rule.selector.startsWith('@supports') ||
562562
rule.selector.startsWith('@document') || rule.selector.startsWith('@layer') ||
563-
rule.selector.startsWith('@container')) {
563+
rule.selector.startsWith('@container') || rule.selector.startsWith('@scope')) {
564564
content = this._scopeSelectors(rule.content, scopeSelector, hostSelector);
565565
} else if (rule.selector.startsWith('@font-face') || rule.selector.startsWith('@page')) {
566566
content = this._stripScopingSelectors(rule.content);

packages/compiler/test/shadow_css/at_rules_spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,34 @@ describe('ShadowCss, at-rules', () => {
173173
});
174174
});
175175

176+
describe('@scope', () => {
177+
it('should scope normal selectors inside a scope rule with scoping limits', () => {
178+
const css = `
179+
@scope (.media-object) to (.content > *) {
180+
img { border-radius: 50%; }
181+
.content { padding: 1em; }
182+
}`;
183+
const result = shim(css, 'host-a');
184+
expect(result).toEqualCss(`
185+
@scope (.media-object) to (.content > *) {
186+
img[host-a] { border-radius: 50%; }
187+
.content[host-a] { padding: 1em; }
188+
}`);
189+
});
190+
191+
it('should scope normal selectors inside a scope rule', () => {
192+
const css = `
193+
@scope (.light-scheme) {
194+
a { color: darkmagenta; }
195+
}`;
196+
const result = shim(css, 'host-a');
197+
expect(result).toEqualCss(`
198+
@scope (.light-scheme) {
199+
a[host-a] { color: darkmagenta; }
200+
}`);
201+
});
202+
});
203+
176204
describe('@document', () => {
177205
it('should handle document rules', () => {
178206
const css = '@document url(http://www.w3.org/) {div {font-size:50px;}}';

0 commit comments

Comments
 (0)