Skip to content

Commit c4da800

Browse files
committed
Do not require quotes on rules creation
1 parent f40da13 commit c4da800

File tree

3 files changed

+42
-47
lines changed

3 files changed

+42
-47
lines changed

src/createICSSRules.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
import postcss from 'postcss'
1+
import postcss from "postcss";
22

33
const createImports = imports => {
44
return Object.keys(imports).map(path => {
5-
const aliases = imports[path]
5+
const aliases = imports[path];
66
const declarations = Object.keys(aliases).map(key =>
77
postcss.decl({
88
prop: key,
99
value: aliases[key],
10-
raws: { before: '\n ' }
10+
raws: { before: "\n " }
1111
})
12-
)
12+
);
1313
return postcss
1414
.rule({
15-
selector: `:import(${path})`,
16-
raws: { after: '\n' }
15+
selector: `:import('${path}')`,
16+
raws: { after: "\n" }
1717
})
18-
.append(declarations)
19-
})
20-
}
18+
.append(declarations);
19+
});
20+
};
2121

2222
const createExports = exports => {
2323
const declarations = Object.keys(exports).map(key =>
2424
postcss.decl({
2525
prop: key,
2626
value: exports[key],
27-
raws: { before: '\n ' }
27+
raws: { before: "\n " }
2828
})
29-
)
29+
);
3030
if (declarations.length === 0) {
31-
return []
31+
return [];
3232
}
3333
const rule = postcss
3434
.rule({
3535
selector: `:export`,
36-
raws: { after: '\n' }
36+
raws: { after: "\n" }
3737
})
38-
.append(declarations)
39-
return [rule]
40-
}
38+
.append(declarations);
39+
return [rule];
40+
};
4141

4242
const createICSSRules = (imports, exports) => [
4343
...createImports(imports),
4444
...createExports(exports)
45-
]
45+
];
4646

47-
export default createICSSRules
47+
export default createICSSRules;

src/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default as replaceValueSymbols } from './replaceValueSymbols.js'
2-
export { default as replaceSymbols } from './replaceSymbols.js'
3-
export { default as extractICSS } from './extractICSS.js'
4-
export { default as createICSSRules } from './createICSSRules.js'
1+
export { default as replaceValueSymbols } from "./replaceValueSymbols.js";
2+
export { default as replaceSymbols } from "./replaceSymbols.js";
3+
export { default as extractICSS } from "./extractICSS.js";
4+
export { default as createICSSRules } from "./createICSSRules.js";

test/createICSSRules.test.js

+20-25
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,47 @@
1-
import postcss from 'postcss'
2-
import { createICSSRules } from '../src'
1+
/* eslint-env jest */
2+
import postcss from "postcss";
3+
import { createICSSRules } from "../src";
34

45
const run = (imports, exports) => {
5-
return postcss.root().append(createICSSRules(imports, exports)).toString()
6-
}
6+
return postcss.root().append(createICSSRules(imports, exports)).toString();
7+
};
78

8-
test('create :import statement', () => {
9+
test("create :import statement", () => {
910
expect(
1011
run(
1112
{
12-
colors: {
13-
a: 'b',
14-
c: 'd'
15-
},
16-
'"path/file"': {
17-
e: 'f'
13+
"path/file": {
14+
e: "f"
1815
}
1916
},
2017
{}
2118
)
22-
).toEqual(
23-
':import(colors) {\n a: b;\n c: d\n}\n:import("path/file") {\n e: f\n}'
24-
)
25-
})
19+
).toEqual(":import('path/file') {\n e: f\n}");
20+
});
2621

27-
test('create :export statement', () => {
22+
test("create :export statement", () => {
2823
expect(
2924
run(
3025
{},
3126
{
32-
a: 'b',
33-
c: 'd'
27+
a: "b",
28+
c: "d"
3429
}
3530
)
36-
).toEqual(':export {\n a: b;\n c: d\n}')
37-
})
31+
).toEqual(":export {\n a: b;\n c: d\n}");
32+
});
3833

39-
test('create :import and :export', () => {
34+
test("create :import and :export", () => {
4035
expect(
4136
run(
4237
{
4338
colors: {
44-
a: 'b'
39+
a: "b"
4540
}
4641
},
4742
{
48-
c: 'd'
43+
c: "d"
4944
}
5045
)
51-
).toEqual(':import(colors) {\n a: b\n}\n:export {\n c: d\n}')
52-
})
46+
).toEqual(":import('colors') {\n a: b\n}\n:export {\n c: d\n}");
47+
});

0 commit comments

Comments
 (0)