From e6c6b671024b571a3ac9ec1690d60aca8d2e7bbf Mon Sep 17 00:00:00 2001 From: ashu Date: Sun, 2 May 2021 00:06:44 +0530 Subject: [PATCH 1/2] fix: scoped class attribute --- src/index.js | 10 ++++++++++ .../expected.error.txt | 1 + .../error-other-than-class-attribute/source.css | 3 +++ .../expected.error.txt | 1 + .../source.css | 3 +++ .../export-class-attribute/expected.css | 16 ++++++++++++++++ .../test-cases/export-class-attribute/source.css | 11 +++++++++++ 7 files changed, 45 insertions(+) create mode 100644 test/test-cases/error-other-than-class-attribute/expected.error.txt create mode 100644 test/test-cases/error-other-than-class-attribute/source.css create mode 100644 test/test-cases/error-other-than-equal- in-class-attribute/expected.error.txt create mode 100644 test/test-cases/error-other-than-equal- in-class-attribute/source.css create mode 100644 test/test-cases/export-class-attribute/expected.css create mode 100644 test/test-cases/export-class-attribute/source.css diff --git a/src/index.js b/src/index.js index 3197752..29df9bc 100644 --- a/src/index.js +++ b/src/index.js @@ -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( diff --git a/test/test-cases/error-other-than-class-attribute/expected.error.txt b/test/test-cases/error-other-than-class-attribute/expected.error.txt new file mode 100644 index 0000000..a7c691f --- /dev/null +++ b/test/test-cases/error-other-than-class-attribute/expected.error.txt @@ -0,0 +1 @@ +attribute \("\[target\="_blank"]\"\) is not allowed in a :local block diff --git a/test/test-cases/error-other-than-class-attribute/source.css b/test/test-cases/error-other-than-class-attribute/source.css new file mode 100644 index 0000000..48d4bdd --- /dev/null +++ b/test/test-cases/error-other-than-class-attribute/source.css @@ -0,0 +1,3 @@ +:local(.exportName1[target="_blank"]) { + color: blue; +} diff --git a/test/test-cases/error-other-than-equal- in-class-attribute/expected.error.txt b/test/test-cases/error-other-than-equal- in-class-attribute/expected.error.txt new file mode 100644 index 0000000..315af92 --- /dev/null +++ b/test/test-cases/error-other-than-equal- in-class-attribute/expected.error.txt @@ -0,0 +1 @@ +attribute \("\[class\*\="exportName2\"]\"\) is not allowed in a :local block diff --git a/test/test-cases/error-other-than-equal- in-class-attribute/source.css b/test/test-cases/error-other-than-equal- in-class-attribute/source.css new file mode 100644 index 0000000..c4742cd --- /dev/null +++ b/test/test-cases/error-other-than-equal- in-class-attribute/source.css @@ -0,0 +1,3 @@ +:local(.exportName1[class*="exportName2"]) { + color: blue; +} diff --git a/test/test-cases/export-class-attribute/expected.css b/test/test-cases/export-class-attribute/expected.css new file mode 100644 index 0000000..802a6d4 --- /dev/null +++ b/test/test-cases/export-class-attribute/expected.css @@ -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; +} diff --git a/test/test-cases/export-class-attribute/source.css b/test/test-cases/export-class-attribute/source.css new file mode 100644 index 0000000..3f38524 --- /dev/null +++ b/test/test-cases/export-class-attribute/source.css @@ -0,0 +1,11 @@ +:local(.exportName1) { + color: red; +} + +:local(.exportName2) { + color: green; +} + +:local(.exportName2[class="exportName1"]) { + color: blue; +} From c2b363e6b028e497bfa33d7e8480ffb4bad6e1fe Mon Sep 17 00:00:00 2001 From: Ashu Deshwal Date: Fri, 15 Sep 2023 02:57:36 +0530 Subject: [PATCH 2/2] chore: add more test case --- .../expected.error.txt | 1 - .../error-other-than-equal- in-class-attribute/source.css | 3 --- .../test-cases/error-when-attribute-is-href/expected.error.txt | 1 + test/test-cases/error-when-attribute-is-href/source.css | 3 +++ .../expected.error.txt | 0 .../source.css | 0 .../error-when-attribute-is-title/expected.error.txt | 1 + test/test-cases/error-when-attribute-is-title/source.css | 3 +++ .../test-cases/error-when-attribute-is-type/expected.error.txt | 1 + test/test-cases/error-when-attribute-is-type/source.css | 3 +++ 10 files changed, 12 insertions(+), 4 deletions(-) delete mode 100644 test/test-cases/error-other-than-equal- in-class-attribute/expected.error.txt delete mode 100644 test/test-cases/error-other-than-equal- in-class-attribute/source.css create mode 100644 test/test-cases/error-when-attribute-is-href/expected.error.txt create mode 100644 test/test-cases/error-when-attribute-is-href/source.css rename test/test-cases/{error-other-than-class-attribute => error-when-attribute-is-target}/expected.error.txt (100%) rename test/test-cases/{error-other-than-class-attribute => error-when-attribute-is-target}/source.css (100%) create mode 100644 test/test-cases/error-when-attribute-is-title/expected.error.txt create mode 100644 test/test-cases/error-when-attribute-is-title/source.css create mode 100644 test/test-cases/error-when-attribute-is-type/expected.error.txt create mode 100644 test/test-cases/error-when-attribute-is-type/source.css diff --git a/test/test-cases/error-other-than-equal- in-class-attribute/expected.error.txt b/test/test-cases/error-other-than-equal- in-class-attribute/expected.error.txt deleted file mode 100644 index 315af92..0000000 --- a/test/test-cases/error-other-than-equal- in-class-attribute/expected.error.txt +++ /dev/null @@ -1 +0,0 @@ -attribute \("\[class\*\="exportName2\"]\"\) is not allowed in a :local block diff --git a/test/test-cases/error-other-than-equal- in-class-attribute/source.css b/test/test-cases/error-other-than-equal- in-class-attribute/source.css deleted file mode 100644 index c4742cd..0000000 --- a/test/test-cases/error-other-than-equal- in-class-attribute/source.css +++ /dev/null @@ -1,3 +0,0 @@ -:local(.exportName1[class*="exportName2"]) { - color: blue; -} diff --git a/test/test-cases/error-when-attribute-is-href/expected.error.txt b/test/test-cases/error-when-attribute-is-href/expected.error.txt new file mode 100644 index 0000000..c8d1dae --- /dev/null +++ b/test/test-cases/error-when-attribute-is-href/expected.error.txt @@ -0,0 +1 @@ +attribute \("\[href\^="https"]\"\) is not allowed in a :local block diff --git a/test/test-cases/error-when-attribute-is-href/source.css b/test/test-cases/error-when-attribute-is-href/source.css new file mode 100644 index 0000000..8eceb47 --- /dev/null +++ b/test/test-cases/error-when-attribute-is-href/source.css @@ -0,0 +1,3 @@ +:local(.exportName1[href^="https"]) { + color: blue; +} diff --git a/test/test-cases/error-other-than-class-attribute/expected.error.txt b/test/test-cases/error-when-attribute-is-target/expected.error.txt similarity index 100% rename from test/test-cases/error-other-than-class-attribute/expected.error.txt rename to test/test-cases/error-when-attribute-is-target/expected.error.txt diff --git a/test/test-cases/error-other-than-class-attribute/source.css b/test/test-cases/error-when-attribute-is-target/source.css similarity index 100% rename from test/test-cases/error-other-than-class-attribute/source.css rename to test/test-cases/error-when-attribute-is-target/source.css diff --git a/test/test-cases/error-when-attribute-is-title/expected.error.txt b/test/test-cases/error-when-attribute-is-title/expected.error.txt new file mode 100644 index 0000000..a679f06 --- /dev/null +++ b/test/test-cases/error-when-attribute-is-title/expected.error.txt @@ -0,0 +1 @@ +attribute \("\[title\="flower"]\"\) is not allowed in a :local block diff --git a/test/test-cases/error-when-attribute-is-title/source.css b/test/test-cases/error-when-attribute-is-title/source.css new file mode 100644 index 0000000..c87f72b --- /dev/null +++ b/test/test-cases/error-when-attribute-is-title/source.css @@ -0,0 +1,3 @@ +:local(.exportName1[title="flower"]) { + color: blue; +} diff --git a/test/test-cases/error-when-attribute-is-type/expected.error.txt b/test/test-cases/error-when-attribute-is-type/expected.error.txt new file mode 100644 index 0000000..593f6df --- /dev/null +++ b/test/test-cases/error-when-attribute-is-type/expected.error.txt @@ -0,0 +1 @@ +attribute \("\[type\="text"]\"\) is not allowed in a :local block diff --git a/test/test-cases/error-when-attribute-is-type/source.css b/test/test-cases/error-when-attribute-is-type/source.css new file mode 100644 index 0000000..e6b3918 --- /dev/null +++ b/test/test-cases/error-when-attribute-is-type/source.css @@ -0,0 +1,3 @@ +:local(.exportName1[type="text"]) { + color: blue; +}