Skip to content

Commit

Permalink
fix: scoped class attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSTL committed May 1, 2021
1 parent c46d990 commit e6c6b67
Show file tree
Hide file tree
Showing 7 changed files with 45 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 \("\[target\="_blank"]\"\) is not allowed in a :local block
3 changes: 3 additions & 0 deletions test/test-cases/error-other-than-class-attribute/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 \("\[class\*\="exportName2\"]\"\) is not allowed in a :local block
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local(.exportName1[class*="exportName2"]) {
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 e6c6b67

Please sign in to comment.