Skip to content

Commit 362ddcb

Browse files
committed
Merge pull request #4 from css-modules/reorder-import-statements
Reorder import statements & use composes from here on in
2 parents 95243ca + a2b0e9d commit 362ddcb

File tree

23 files changed

+70
-70
lines changed

23 files changed

+70
-70
lines changed

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import postcss from 'postcss';
22

3-
const declWhitelist = ['extends'],
3+
const declWhitelist = ['composes'],
44
declFilter = new RegExp(`^(${declWhitelist.join('|')})$`),
55
matchImports = /^([\w\s]+?)\s+from\s+(?:"([^"]+)"|'([^']+)')$/;
66

77
const processor = postcss.plugin('modules-extract-imports', function(options) {
88
return (css) => {
99
let imports = {};
1010
let importIndex = 0;
11-
let createImportedName = options && options.createImportedName || ((importName/*, path*/) => `__imported_${importName}_${importIndex++}`);
11+
let createImportedName = options && options.createImportedName || ((importName/*, path*/) => `i__imported_${importName}_${importIndex++}`);
1212

1313
// Find any declaration that supports imports
1414
css.eachDecl(declFilter, (decl) => {
@@ -35,8 +35,8 @@ const processor = postcss.plugin('modules-extract-imports', function(options) {
3535
selector: `:import("${path}")`,
3636
after: "\n",
3737
nodes: Object.keys(pathImports).map(importedSymbol => postcss.decl({
38-
prop: importedSymbol,
39-
value: pathImports[importedSymbol],
38+
value: importedSymbol,
39+
prop: pathImports[importedSymbol],
4040
before: "\n "
4141
}))
4242
}));

test/custom-import-name.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var processor = require("../");
99

1010
describe("custom-import-name", function() {
1111
it("should allow to provide a custom imported name", function() {
12-
var input = ":local(.name) { extends: abc from \"def\"; }";
13-
var expected = ":import(\"def\") {\n abc: abc-from-def;\n}\n:local(.name) { extends: abc-from-def; }";
12+
var input = ":local(.name) { composes: abc from \"def\"; }";
13+
var expected = ":import(\"def\") {\n abc-from-def: abc;\n}\n:local(.name) { composes: abc-from-def; }";
1414
var pipeline = postcss([processor({
1515
createImportedName: function(importName, path) { return importName + "-from-" + path; }
1616
})]);

test/test-cases.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var processor = require("../");
1111
var pipeline = postcss([processor]);
1212

1313
function normalize(str) {
14-
return str.replace(/\r\n?/g, "\n");
14+
return str.replace(/\r\n?/g, "\n").replace(/\n$/,'');
1515
}
1616

1717
describe("test-cases", function() {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
:local(.exportName) {
3-
extends: importName from "path/library.css";
3+
composes: importName from "path/library.css";
44
other: rule;
55
}
66
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
:local(.exportName) {
3-
extends: importName from "path/library.css";
3+
composes: importName from "path/library.css";
44
other: rule;
55
}
66
*/
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
:import("path/library.css") {
2-
importName: __imported_importName_0;
3-
secondImport: __imported_secondImport_1;
4-
thirdImport: __imported_thirdImport_2;
2+
i__imported_importName_0: importName;
3+
i__imported_secondImport_1: secondImport;
4+
i__imported_thirdImport_2: thirdImport;
55
}
66
:import("path/other-lib.css") {
7-
otherLibImport: __imported_otherLibImport_3;
7+
i__imported_otherLibImport_3: otherLibImport;
88
}
99
:local(.exportName) {
10-
extends: __imported_importName_0 __imported_secondImport_1;
10+
composes: i__imported_importName_0 i__imported_secondImport_1;
1111
other: rule;
1212
}
1313
:local(.otherExport) {
14-
extends: __imported_thirdImport_2;
15-
extends: __imported_otherLibImport_3;
14+
composes: i__imported_thirdImport_2;
15+
composes: i__imported_otherLibImport_3;
1616
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
:local(.exportName) {
3-
extends: importName secondImport from 'path/library.css';
3+
composes: importName secondImport from 'path/library.css';
44
other: rule;
55
}
66
:local(.otherExport) {
7-
extends: thirdImport from 'path/library.css';
8-
extends: otherLibImport from 'path/other-lib.css';
7+
composes: thirdImport from 'path/library.css';
8+
composes: otherLibImport from 'path/other-lib.css';
99
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
:local(.exportName) {
2-
extends: localName;
2+
composes: localName;
33
other: rule;
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
:local(.exportName) {
2-
extends: localName;
2+
composes: localName;
33
other: rule;
44
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
:import("path/library.css") {
2-
importName: __imported_importName_0;
3-
importName2: __imported_importName2_1;
2+
i__imported_importName_0: importName;
3+
i__imported_importName2_1: importName2;
44
}
55

66
@media screen {
77
:local(.exportName) {
8-
extends: __imported_importName_0;
9-
extends: __imported_importName2_1;
8+
composes: i__imported_importName_0;
9+
composes: i__imported_importName2_1;
1010
other: rule2;
1111
}
1212
}
1313

1414
:local(.exportName) {
15-
extends: __imported_importName_0;
15+
composes: i__imported_importName_0;
1616
other: rule;
1717
}

0 commit comments

Comments
 (0)