Skip to content

Commit

Permalink
fix: don't break @scope at-rule without params (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Apr 3, 2024
1 parent 506ac20 commit c803ea2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,31 +540,33 @@ module.exports = (options = {}) => {
});
});
} else if (/scope$/i.test(atRule.name)) {
atRule.params = atRule.params
.split("to")
.map((item) => {
const selector = item.trim().slice(1, -1).trim();
const context = localizeNode(
selector,
options.mode,
localAliasMap
);

context.options = options;
context.localAliasMap = localAliasMap;

if (pureMode && context.hasPureGlobals) {
throw atRule.error(
'Selector in at-rule"' +
selector +
'" is not pure ' +
"(pure selectors must contain at least one local class or id)"
if (atRule.params) {
atRule.params = atRule.params
.split("to")
.map((item) => {
const selector = item.trim().slice(1, -1).trim();
const context = localizeNode(
selector,
options.mode,
localAliasMap
);
}

return `(${context.selector})`;
})
.join(" to ");
context.options = options;
context.localAliasMap = localAliasMap;

if (pureMode && context.hasPureGlobals) {
throw atRule.error(
'Selector in at-rule"' +
selector +
'" is not pure ' +
"(pure selectors must contain at least one local class or id)"
);
}

return `(${context.selector})`;
})
.join(" to ");
}

atRule.nodes.forEach((declaration) => {
if (declaration.type === "decl") {
Expand Down
12 changes: 12 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,12 @@ const tests = [
background-color: goldenrod;
}
}
@scope {
:scope {
color: red;
}
}
`,
expected: `
:local(.article-header) {
Expand Down Expand Up @@ -1081,6 +1087,12 @@ const tests = [
background-color: goldenrod;
}
}
@scope {
:scope {
color: red;
}
}
`,
},
{
Expand Down

0 comments on commit c803ea2

Please sign in to comment.