File tree 3 files changed +42
-47
lines changed
3 files changed +42
-47
lines changed Original file line number Diff line number Diff line change 1
- import postcss from ' postcss'
1
+ import postcss from " postcss" ;
2
2
3
3
const createImports = imports => {
4
4
return Object . keys ( imports ) . map ( path => {
5
- const aliases = imports [ path ]
5
+ const aliases = imports [ path ] ;
6
6
const declarations = Object . keys ( aliases ) . map ( key =>
7
7
postcss . decl ( {
8
8
prop : key ,
9
9
value : aliases [ key ] ,
10
- raws : { before : ' \n ' }
10
+ raws : { before : " \n " }
11
11
} )
12
- )
12
+ ) ;
13
13
return postcss
14
14
. rule ( {
15
- selector : `:import(${ path } )` ,
16
- raws : { after : '\n' }
15
+ selector : `:import(' ${ path } ' )` ,
16
+ raws : { after : "\n" }
17
17
} )
18
- . append ( declarations )
19
- } )
20
- }
18
+ . append ( declarations ) ;
19
+ } ) ;
20
+ } ;
21
21
22
22
const createExports = exports => {
23
23
const declarations = Object . keys ( exports ) . map ( key =>
24
24
postcss . decl ( {
25
25
prop : key ,
26
26
value : exports [ key ] ,
27
- raws : { before : ' \n ' }
27
+ raws : { before : " \n " }
28
28
} )
29
- )
29
+ ) ;
30
30
if ( declarations . length === 0 ) {
31
- return [ ]
31
+ return [ ] ;
32
32
}
33
33
const rule = postcss
34
34
. rule ( {
35
35
selector : `:export` ,
36
- raws : { after : '\n' }
36
+ raws : { after : "\n" }
37
37
} )
38
- . append ( declarations )
39
- return [ rule ]
40
- }
38
+ . append ( declarations ) ;
39
+ return [ rule ] ;
40
+ } ;
41
41
42
42
const createICSSRules = ( imports , exports ) => [
43
43
...createImports ( imports ) ,
44
44
...createExports ( exports )
45
- ]
45
+ ] ;
46
46
47
- export default createICSSRules
47
+ export default createICSSRules ;
Original file line number Diff line number Diff line change 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" ;
Original file line number Diff line number Diff line change 1
- import postcss from 'postcss'
2
- import { createICSSRules } from '../src'
1
+ /* eslint-env jest */
2
+ import postcss from "postcss" ;
3
+ import { createICSSRules } from "../src" ;
3
4
4
5
const run = ( imports , exports ) => {
5
- return postcss . root ( ) . append ( createICSSRules ( imports , exports ) ) . toString ( )
6
- }
6
+ return postcss . root ( ) . append ( createICSSRules ( imports , exports ) ) . toString ( ) ;
7
+ } ;
7
8
8
- test ( ' create :import statement' , ( ) => {
9
+ test ( " create :import statement" , ( ) => {
9
10
expect (
10
11
run (
11
12
{
12
- colors : {
13
- a : 'b' ,
14
- c : 'd'
15
- } ,
16
- '"path/file"' : {
17
- e : 'f'
13
+ "path/file" : {
14
+ e : "f"
18
15
}
19
16
} ,
20
17
{ }
21
18
)
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
+ } ) ;
26
21
27
- test ( ' create :export statement' , ( ) => {
22
+ test ( " create :export statement" , ( ) => {
28
23
expect (
29
24
run (
30
25
{ } ,
31
26
{
32
- a : 'b' ,
33
- c : 'd'
27
+ a : "b" ,
28
+ c : "d"
34
29
}
35
30
)
36
- ) . toEqual ( ' :export {\n a: b;\n c: d\n}' )
37
- } )
31
+ ) . toEqual ( " :export {\n a: b;\n c: d\n}" ) ;
32
+ } ) ;
38
33
39
- test ( ' create :import and :export' , ( ) => {
34
+ test ( " create :import and :export" , ( ) => {
40
35
expect (
41
36
run (
42
37
{
43
38
colors : {
44
- a : 'b'
39
+ a : "b"
45
40
}
46
41
} ,
47
42
{
48
- c : 'd'
43
+ c : "d"
49
44
}
50
45
)
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments