Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export names from global class or id #21

Merged
merged 4 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
node.each(traverseNode);
break;
}
case 'id':
case 'class':
exports[node.value] = [node.value];
break;
}
return node;
}
Expand Down
2 changes: 2 additions & 0 deletions test/test-cases/escape-sequence/expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@
:export {
smile: 😀;
smile_with_A: 😀A;
😀: 😀;
a: a;
}
22 changes: 22 additions & 0 deletions test/test-cases/export-global-class/expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.exportName {
color: green;
}

.exportName:hover {
color: red;
}

@media screen {
body {
background: red;
}
}

._input__testLocal {
color: blue;
}

:export {
exportName: exportName;
testLocal: _input__testLocal;
}
17 changes: 17 additions & 0 deletions test/test-cases/export-global-class/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.exportName {
color: green;
}

.exportName:hover {
color: red;
}

@media screen {
body {
background: red;
}
}

:local(.testLocal) {
color: blue;
}
23 changes: 23 additions & 0 deletions test/test-cases/export-global-id/expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#exportName {
color: green;
}

#exportName:hover {
color: red;
}

@media screen {
#exportName-2 {
background: red;
}
}

#_input__exportName-3 {
color: green;
}

:export {
exportName: exportName;
exportName-2: exportName-2;
exportName-3: _input__exportName-3;
}
17 changes: 17 additions & 0 deletions test/test-cases/export-global-id/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#exportName {
color: green;
}

#exportName:hover {
color: red;
}

@media screen {
#exportName-2 {
background: red;
}
}

:local(#exportName-3) {
color: green;
}
1 change: 1 addition & 0 deletions test/test-cases/export-nested-class/expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
:export {
exportName: _input__exportName;
otherExportName: _input__otherExportName;
global: global;
otherExportName2: _input__otherExportName2;
}
3 changes: 3 additions & 0 deletions test/test-cases/export-with-global-composes/expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
.aThirdClass { color: red; }
._lib_extender__exportName { color: green; }
:export {
otherClass: otherClass;
andAgain: andAgain;
aThirdClass: aThirdClass;
exportName: _lib_extender__exportName otherClass andAgain aThirdClass; }
4 changes: 4 additions & 0 deletions test/test-cases/nothing/expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
background: red;
}
}

:export {
exportName: exportName;
}