Skip to content

Commit

Permalink
fix: scoped class attribute (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSTL committed Dec 21, 2023
1 parent c3f5625 commit ab8d7a1
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ const plugin = (options = {}) => {
),
});
}
case "attribute": {
if (node.attribute === "class" && node.operator === "=") {
return selectorParser.attribute({
attribute: node.attribute,
operator: node.operator,
quoteMark: "'",
value: exportScopedName(node.value),
});
}
}
}

throw new Error(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
attribute \("\[href\^="https"]\"\) is not allowed in a :local block
3 changes: 3 additions & 0 deletions test/test-cases/error-when-attribute-is-href/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.exportName1[href^="https"]) {
color: blue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
attribute \("\[target\="_blank"]\"\) is not allowed in a :local block
3 changes: 3 additions & 0 deletions test/test-cases/error-when-attribute-is-target/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.exportName1[target="_blank"]) {
color: blue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
attribute \("\[title\="flower"]\"\) is not allowed in a :local block
3 changes: 3 additions & 0 deletions test/test-cases/error-when-attribute-is-title/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.exportName1[title="flower"]) {
color: blue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
attribute \("\[type\="text"]\"\) is not allowed in a :local block
3 changes: 3 additions & 0 deletions test/test-cases/error-when-attribute-is-type/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.exportName1[type="text"]) {
color: blue;
}
16 changes: 16 additions & 0 deletions test/test-cases/export-class-attribute/expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
._input__exportName1 {
color: red;
}

._input__exportName2 {
color: green;
}

._input__exportName2[class=_input__exportName1] {
color: blue;
}

:export {
exportName1: _input__exportName1;
exportName2: _input__exportName2;
}
11 changes: 11 additions & 0 deletions test/test-cases/export-class-attribute/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:local(.exportName1) {
color: red;
}

:local(.exportName2) {
color: green;
}

:local(.exportName2[class="exportName1"]) {
color: blue;
}

0 comments on commit ab8d7a1

Please sign in to comment.