Skip to content

Commit 298fd99

Browse files
authored
fix: treat :import and :export statements as pure
1 parent 446dd71 commit 298fd99

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function normalizeNodeArray(nodes) {
4343
function localizeNode(rule, mode, localAliasMap) {
4444
const isScopePseudo = node =>
4545
node.value === ':local' || node.value === ':global';
46+
const isImportExportPseudo = node =>
47+
node.value === ':import' || node.value === ':export';
4648

4749
const transform = (node, context) => {
4850
if (context.ignoreNextSpacing && !isSpacing(node)) {
@@ -115,9 +117,12 @@ function localizeNode(rule, mode, localAliasMap) {
115117
let childContext;
116118
const isNested = !!node.length;
117119
const isScoped = isScopePseudo(node);
120+
const isImportExport = isImportExportPseudo(node);
118121

122+
if (isImportExport) {
123+
context.hasLocals = true;
119124
// :local(.foo)
120-
if (isNested) {
125+
} else if (isNested) {
121126
if (isScoped) {
122127
if (node.nodes.length === 0) {
123128
throw new Error(`${node.value}() can't be empty`);

test.js

+12
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,18 @@ const tests = [
654654
error: /:global\(\) can't be empty/
655655
},
656656
*/
657+
{
658+
should: 'consider :import statements pure',
659+
input: ':import("~/lol.css") { foo: __foo; }',
660+
options: { mode: 'pure' },
661+
expected: ':import("~/lol.css") { foo: __foo; }',
662+
},
663+
{
664+
should: 'consider :export statements pure',
665+
input: ':export { foo: __foo; }',
666+
options: { mode: 'pure' },
667+
expected: ':export { foo: __foo; }',
668+
},
657669
];
658670

659671
function process(css, options) {

0 commit comments

Comments
 (0)