Skip to content

Commit 270067c

Browse files
authored
Merge pull request #65 from shlensky/ignore_unknown_at_rules
ignore media rules nested to unknown at rules
2 parents 16f07f0 + c595376 commit 270067c

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

__tests__/extraction.spec.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,36 @@ describe('extraction stories', () => {
178178
`);
179179
});
180180

181+
it('should ignore media rules nested to unknown at rules', async () => {
182+
const styles: StyleDefinition = loadStyleDefinitions(
183+
() => ['test.css'],
184+
() => `
185+
@supports (display:grid) {
186+
.a { display: grid; }
187+
188+
@media only print {
189+
.a { color: red; }
190+
}
191+
}
192+
`
193+
);
194+
await styles;
195+
196+
const extracted = getCriticalRules('<div class="a">', styles);
197+
198+
expect(extracted).toMatchInlineSnapshot(`
199+
"
200+
/* test.css */
201+
@supports (display:grid) {
202+
.a { display: grid; }
203+
204+
@media only print {
205+
.a { color: red; }
206+
}
207+
}"
208+
`);
209+
});
210+
181211
describe('CSS Cascade Layers', () => {
182212
it('handles CSS Cascade Layers', async () => {
183213
const styles = loadStyleDefinitions(

__tests__/media.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('media selectors', () => {
3838
expect(css).toEqual('');
3939
});
4040

41-
it('should extract unmatable parts', () => {
41+
it('should extract unmatchable parts', () => {
4242
const css = extractUnmatchableFromAst({ ast });
4343

4444
expect(css[0].css).toEqual(`body { color: red; }

src/parser/toAst.ts

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ export const buildAst = (CSS: string, file = ''): SingleStyleAst => {
9595
return;
9696
}
9797

98+
if (atParents.has(rule.parent)) {
99+
atParents.add(rule);
100+
101+
return;
102+
}
103+
98104
if (rule.name !== 'media' && !isCascadeLayerStyles(rule)) {
99105
atParents.add(rule);
100106

0 commit comments

Comments
 (0)