Skip to content

Commit

Permalink
fix: preserve @font-face inside :global block (#486)
Browse files Browse the repository at this point in the history
Fixes #236
  • Loading branch information
bfanger committed Apr 11, 2022
1 parent 74a7e17 commit 8064473
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/transformers/globalStyle.ts
Expand Up @@ -23,7 +23,11 @@ const globalifyRulePlugin = (root: pcss.Root) => {
});

if (modifiedSelectors.length === 0) {
rule.remove();
if (rule.parent?.type === 'atrule' && rule.selector === ':global') {
rule.replaceWith(...rule.nodes);
} else {
rule.remove();
}

return;
}
Expand Down
9 changes: 9 additions & 0 deletions test/transformers/globalStyle.test.ts
Expand Up @@ -251,5 +251,14 @@ describe('transformer - globalStyle', () => {
'<style>div{/*comment*/}</style>',
);
});
it('unwraps :global in @font-face', async () => {
const template = `<style>@font-face{:global{font-family:Helvetica}}</style>`;
const opts = autoProcess();
const preprocessed = await preprocess(template, opts);

expect(preprocessed.toString?.()).toContain(
'<style>@font-face{font-family:Helvetica}</style>',
);
});
});
});

0 comments on commit 8064473

Please sign in to comment.