Skip to content

Commit d476194

Browse files
committed
added global class composition
1 parent 4f7e52e commit d476194

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
9696
let localNames = getSingleLocalNamesForComposes(selector);
9797
let classes = decl.value.split(/\s+/);
9898
classes.forEach((className) => {
99-
if(hasOwnProperty.call(importedNames, className)) {
99+
let global = /^global\(([^\)]+)\)$/.exec(className);
100+
if (global) {
101+
localNames.forEach((exportedName) => {
102+
exports[exportedName].push(global[1]);
103+
})
104+
} else if (hasOwnProperty.call(importedNames, className)) {
100105
localNames.forEach((exportedName) => {
101106
exports[exportedName].push(className);
102107
});
103-
} else if(hasOwnProperty.call(exports, className)) {
108+
} else if (hasOwnProperty.call(exports, className)) {
104109
localNames.forEach((exportedName) => {
105110
exports[className].forEach((item) => {
106111
exports[exportedName].push(item);
@@ -112,7 +117,7 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
112117
});
113118
decl.remove();
114119
});
115-
120+
116121
rule.walkDecls(decl => {
117122
var tokens = decl.value.split(/(,|'[^']*'|"[^"]*")/);
118123
tokens = tokens.map((token, idx) => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"from": "/lib/extender.css"
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.otherClass { background: red; }
2+
.andAgain { font-size: 2em; }
3+
.aThirdClass { color: red; }
4+
._lib_extender__exportName { color: green; }
5+
:export {
6+
exportName: _lib_extender__exportName otherClass andAgain aThirdClass; }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.otherClass { background: red; }
2+
.andAgain { font-size: 2em; }
3+
.aThirdClass { color: red; }
4+
:local(.exportName) { compose-with: global(otherClass) global(andAgain); compose-with: global(aThirdClass); color: green; }

0 commit comments

Comments
 (0)