Skip to content

Commit 8064473

Browse files
authoredApr 11, 2022
fix: preserve @font-face inside :global block (#486)
Fixes #236
1 parent 74a7e17 commit 8064473

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

‎src/transformers/globalStyle.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ const globalifyRulePlugin = (root: pcss.Root) => {
2323
});
2424

2525
if (modifiedSelectors.length === 0) {
26-
rule.remove();
26+
if (rule.parent?.type === 'atrule' && rule.selector === ':global') {
27+
rule.replaceWith(...rule.nodes);
28+
} else {
29+
rule.remove();
30+
}
2731

2832
return;
2933
}

‎test/transformers/globalStyle.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,14 @@ describe('transformer - globalStyle', () => {
251251
'<style>div{/*comment*/}</style>',
252252
);
253253
});
254+
it('unwraps :global in @font-face', async () => {
255+
const template = `<style>@font-face{:global{font-family:Helvetica}}</style>`;
256+
const opts = autoProcess();
257+
const preprocessed = await preprocess(template, opts);
258+
259+
expect(preprocessed.toString?.()).toContain(
260+
'<style>@font-face{font-family:Helvetica}</style>',
261+
);
262+
});
254263
});
255264
});

0 commit comments

Comments
 (0)
Please sign in to comment.