Skip to content

Commit c803ea2

Browse files
fix: don't break @scope at-rule without params (#71)
1 parent 506ac20 commit c803ea2

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

src/index.js

+25-23
Original file line numberDiff line numberDiff line change
@@ -540,31 +540,33 @@ module.exports = (options = {}) => {
540540
});
541541
});
542542
} else if (/scope$/i.test(atRule.name)) {
543-
atRule.params = atRule.params
544-
.split("to")
545-
.map((item) => {
546-
const selector = item.trim().slice(1, -1).trim();
547-
const context = localizeNode(
548-
selector,
549-
options.mode,
550-
localAliasMap
551-
);
552-
553-
context.options = options;
554-
context.localAliasMap = localAliasMap;
555-
556-
if (pureMode && context.hasPureGlobals) {
557-
throw atRule.error(
558-
'Selector in at-rule"' +
559-
selector +
560-
'" is not pure ' +
561-
"(pure selectors must contain at least one local class or id)"
543+
if (atRule.params) {
544+
atRule.params = atRule.params
545+
.split("to")
546+
.map((item) => {
547+
const selector = item.trim().slice(1, -1).trim();
548+
const context = localizeNode(
549+
selector,
550+
options.mode,
551+
localAliasMap
562552
);
563-
}
564553

565-
return `(${context.selector})`;
566-
})
567-
.join(" to ");
554+
context.options = options;
555+
context.localAliasMap = localAliasMap;
556+
557+
if (pureMode && context.hasPureGlobals) {
558+
throw atRule.error(
559+
'Selector in at-rule"' +
560+
selector +
561+
'" is not pure ' +
562+
"(pure selectors must contain at least one local class or id)"
563+
);
564+
}
565+
566+
return `(${context.selector})`;
567+
})
568+
.join(" to ");
569+
}
568570

569571
atRule.nodes.forEach((declaration) => {
570572
if (declaration.type === "decl") {

test/index.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,12 @@ const tests = [
10521052
background-color: goldenrod;
10531053
}
10541054
}
1055+
1056+
@scope {
1057+
:scope {
1058+
color: red;
1059+
}
1060+
}
10551061
`,
10561062
expected: `
10571063
:local(.article-header) {
@@ -1081,6 +1087,12 @@ const tests = [
10811087
background-color: goldenrod;
10821088
}
10831089
}
1090+
1091+
@scope {
1092+
:scope {
1093+
color: red;
1094+
}
1095+
}
10841096
`,
10851097
},
10861098
{

0 commit comments

Comments
 (0)