Skip to content

Commit 8567b56

Browse files
committed
space out the output a bit
1 parent 8a55cb0 commit 8567b56

3 files changed

Lines changed: 56 additions & 8 deletions

File tree

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ var processor = function processor(css, result) {
4444
// If we've found any imports, insert :import rules
4545
Object.keys(imports).forEach(function (path) {
4646
var pathImports = imports[path];
47-
console.log(pathImports);
4847
css.prepend(_postcss2['default'].rule({
4948
selector: ':import("' + path + '")',
49+
before: '\n',
5050
nodes: Object.keys(pathImports).map(function (importedSymbol) {
5151
return _postcss2['default'].decl({
5252
prop: importedSymbol,
53-
value: pathImports[importedSymbol]
53+
value: pathImports[importedSymbol],
54+
before: '\n '
5455
});
5556
})
5657
}));

index.src.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ const processor = (css, result) => {
2323
// If we've found any imports, insert :import rules
2424
Object.keys(imports).forEach(path => {
2525
let pathImports = imports[path]
26-
console.log(pathImports)
2726
css.prepend(postcss.rule({
2827
selector: `:import("${path}")`,
28+
before: "\n",
2929
nodes: Object.keys(pathImports).map(importedSymbol => postcss.decl({
3030
prop: importedSymbol,
31-
value: pathImports[importedSymbol]
31+
value: pathImports[importedSymbol],
32+
before: "\n "
3233
}))
3334
}))
3435
})

test.js

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,70 @@ describe("processor", () => {
1414
check(
1515
"it should extract an import within a :local",
1616
`:local(.exportName) { extends: importName from "path/library.css"; other: rule; }`,
17-
`:import("path/library.css") {importName: __tmp_importName_rand0ml0l0l; }\n:local(.exportName) { extends: __tmp_importName_rand0ml0l0l; other: rule; }`,
17+
`
18+
:import("path/library.css") {
19+
importName: __tmp_importName_rand0ml0l0l; }
20+
:local(.exportName) { extends: __tmp_importName_rand0ml0l0l; other: rule; }`,
1821
["rand0ml0l0l"]
1922
)
2023

2124
check(
2225
"it should not care if single-quotes are used",
2326
`:local(.exportName) { extends: importName from 'path/library.css'; other: rule; }`,
24-
`:import("path/library.css") {importName: __tmp_importName_rand0ml0l0l; }\n:local(.exportName) { extends: __tmp_importName_rand0ml0l0l; other: rule; }`,
27+
`
28+
:import("path/library.css") {
29+
importName: __tmp_importName_rand0ml0l0l; }
30+
:local(.exportName) { extends: __tmp_importName_rand0ml0l0l; other: rule; }`,
2531
["rand0ml0l0l"]
2632
)
2733

2834
check(
2935
"should import multiple classes on a single line",
3036
`:local(.exportName) { extends: importName secondImport from 'path/library.css'; other: rule; }`,
31-
`:import("path/library.css") {importName: __tmp_importName_rand0ml0l0l;secondImport: __tmp_secondImport_rand0ml1l1l; }\n:local(.exportName) { extends: __tmp_importName_rand0ml0l0l __tmp_secondImport_rand0ml1l1l; other: rule; }`,
37+
`
38+
:import("path/library.css") {
39+
importName: __tmp_importName_rand0ml0l0l;
40+
secondImport: __tmp_secondImport_rand0ml1l1l; }
41+
:local(.exportName) { extends: __tmp_importName_rand0ml0l0l __tmp_secondImport_rand0ml1l1l; other: rule; }`,
3242
["rand0ml0l0l", "rand0ml1l1l"]
3343
)
34-
it("should consolidate imports by file for multiple files and multiple classes")
44+
45+
check(
46+
"should consolidate imports by file for multiple files and multiple classes",
47+
48+
/* INPUT */
49+
`
50+
:local(.exportName) {
51+
extends: importName secondImport from 'path/library.css';
52+
other: rule;
53+
}
54+
:local(.otherExport) {
55+
extends: thirdImport from 'path/library.css';
56+
extends: otherLibImport from 'path/other-lib.css';
57+
}`,
58+
59+
/* OUTPUT */
60+
`
61+
:import("path/other-lib.css") {
62+
otherLibImport: __tmp_otherLibImport_rand0ml3l3l3;
63+
}
64+
:import("path/library.css") {
65+
importName: __tmp_importName_rand0ml0l0l;
66+
secondImport: __tmp_secondImport_rand0ml1l1l;
67+
thirdImport: __tmp_thirdImport_rand0ml2l2l;
68+
}
69+
:local(.exportName) {
70+
extends: __tmp_importName_rand0ml0l0l __tmp_secondImport_rand0ml1l1l;
71+
other: rule;
72+
}
73+
:local(.otherExport) {
74+
extends: __tmp_thirdImport_rand0ml2l2l;
75+
extends: __tmp_otherLibImport_rand0ml3l3l3;
76+
}`,
77+
/* RANDOMS */
78+
["rand0ml0l0l", "rand0ml1l1l", "rand0ml2l2l", "rand0ml3l3l3"]
79+
)
80+
3581
it("should ignore imports not inside a :local")
3682
it("should ignore imports not inside our rule whitelist")
3783
})

0 commit comments

Comments
 (0)