Skip to content

Commit e1330ca

Browse files
committed
Merge pull request #20 from css-modules/compose-with
"Compose with" as well as "composes"
2 parents e150adc + 28ed8b9 commit e1330ca

File tree

10 files changed

+18
-18
lines changed

10 files changed

+18
-18
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Since we're exporting class names, there's no reason to export only one. This ca
4242
box-shadow: 0 0 4px -2px;
4343
}
4444
:local(.continueButton) {
45-
composes: globalButtonStyle;
45+
compose-with: globalButtonStyle;
4646
color: green;
4747
}
4848
```
@@ -59,7 +59,7 @@ becomes:
5959
box-shadow: 0 0 4px -2px;
6060
}
6161
:local(.continueButton) {
62-
extends: globalButtonStyle;
62+
compose-with: globalButtonStyle;
6363
color: green;
6464
}
6565
```
@@ -83,8 +83,7 @@ npm test
8383

8484
## Development
8585

86-
- `npm watch` will watch `src` for changes and rebuild
87-
- `npm autotest` will watch `src` and `test` for changes and retest
86+
- `npm autotest` will watch `src` and `test` for changes and run the tests
8887

8988
## License
9089

src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ let hasOwnProperty = Object.prototype.hasOwnProperty;
66
function getSingleLocalNamesForComposes(selectors) {
77
return selectors.nodes.map((node) => {
88
if(node.type !== 'selector' || node.nodes.length !== 1) {
9-
throw new Error('composes is only allowed when selector is single :local class name not in "' +
9+
throw new Error('composition is only allowed when selector is single :local class name not in "' +
1010
Tokenizer.stringify(selectors) + '"');
1111
}
1212
node = node.nodes[0];
1313
if(node.type !== 'nested-pseudo-class' || node.name !== 'local' || node.nodes.length !== 1) {
14-
throw new Error('composes is only allowed when selector is single :local class name not in "' +
14+
throw new Error('composition is only allowed when selector is single :local class name not in "' +
1515
Tokenizer.stringify(selectors) + '", "' + Tokenizer.stringify(node) + '" is weird');
1616
}
1717
node = node.nodes[0];
1818
if(node.type !== 'selector' || node.nodes.length !== 1) {
19-
throw new Error('composes is only allowed when selector is single :local class name not in "' +
19+
throw new Error('composition is only allowed when selector is single :local class name not in "' +
2020
Tokenizer.stringify(selectors) + '", "' + Tokenizer.stringify(node) + '" is weird');
2121
}
2222
node = node.nodes[0];
2323
if(node.type !== 'class') { // 'id' is not possible, because you can't compose ids
24-
throw new Error('composes is only allowed when selector is single :local class name not in "' +
24+
throw new Error('composition is only allowed when selector is single :local class name not in "' +
2525
Tokenizer.stringify(selectors) + '", "' + Tokenizer.stringify(node) + '" is weird');
2626
}
2727
return node.name;
@@ -92,7 +92,7 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
9292
let selector = Tokenizer.parse(rule.selector);
9393
let newSelector = traverseNode(selector);
9494
rule.selector = Tokenizer.stringify(newSelector);
95-
rule.walkDecls('composes', decl => {
95+
rule.walkDecls(/composes|compose-with/, decl => {
9696
let localNames = getSingleLocalNamesForComposes(selector);
9797
let classes = decl.value.split(/\s+/);
9898
classes.forEach((className) => {
@@ -107,11 +107,12 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
107107
});
108108
});
109109
} else {
110-
throw decl.error('referenced class name "' + className + '" in composes not found');
110+
throw decl.error(`referenced class name "${className}" in ${decl.prop} not found`);
111111
}
112112
});
113113
decl.remove();
114114
});
115+
115116
rule.walkDecls(decl => {
116117
var tokens = decl.value.split(/(,|'[^']*'|"[^"]*")/);
117118
tokens = tokens.map((token, idx) => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
composes is only allowed when selector is single :local class name not in ":local\(#idName\)", "#idName" is weird
1+
composition is only allowed when selector is single :local class name not in ":local\(#idName\)", "#idName" is weird
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
composes is only allowed when selector is single :local class name not in ":local\(\.a\) :local\(\.b\)"
1+
composition is only allowed when selector is single :local class name not in ":local\(\.a\) :local\(\.b\)"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
composes is only allowed when selector is single :local class name not in "body", "body" is weird
1+
composition is only allowed when selector is single :local class name not in "body", "body" is weird
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
composes is only allowed when selector is single :local class name not in ":local\(\.a\.b\)", "\.a\.b" is weird
1+
composition is only allowed when selector is single :local class name not in ":local\(\.a\.b\)", "\.a\.b" is weird
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
referenced class name "otherClassName" in composes not found
1+
referenced class name "otherClassName" in compose-with not found
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
:local(.className) {
2-
composes: otherClassName;
2+
compose-with: otherClassName;
33
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
:local(.otherClass) { background: red; } :local(.exportName) { composes: otherClass; color: green; }
1+
:local(.otherClass) { background: red; } :local(.exportName) { compose-with: otherClass; color: green; }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
:local(.otherClass) { background: red; }
22
:local(.andAgain) { font-size: 2em; }
33
:local(.aThirdClass) { color: red; }
4-
:local(.exportName) { composes: otherClass andAgain; composes: aThirdClass; color: green; }
4+
:local(.exportName) { compose-with: otherClass andAgain; compose-with: aThirdClass; color: green; }

0 commit comments

Comments
 (0)