1
- var postcss = require ( 'postcss' )
1
+ 'use strict'
2
2
3
- module . exports = Pipeline
4
- module . exports . build = build
3
+ const postcss = require ( 'postcss' )
5
4
6
- function Pipeline ( creators ) {
7
- if ( ! ( this instanceof Pipeline ) ) {
8
- return new Pipeline ( creators )
5
+ class Pipeline {
6
+ constructor ( creators ) {
7
+ this . creators = [ ]
8
+ this . splice . apply ( this , [ 0 , 0 ] . concat ( creators || [ ] ) )
9
9
}
10
- this . creators = [ ]
11
- this . splice . apply ( this , [ 0 , 0 ] . concat ( creators || [ ] ) )
12
- }
13
10
14
- Pipeline . prototype . build = function ( ) {
15
- if ( arguments . length === 0 ) {
16
- return build ( this . creators )
17
- }
18
- var creators = [ ]
19
- ; [ ] . forEach . call ( arguments , function ( creator ) {
20
- if (
21
- typeof creator === 'string' ||
22
- typeof creator === 'number'
23
- ) {
24
- creator = this . get ( creator )
11
+ build ( ) {
12
+ if ( arguments . length === 0 ) {
13
+ return build ( this . creators )
25
14
}
26
- creators . push . apply ( creators , this . normalize ( creator ) )
27
- } , this )
28
-
29
- return build ( creators )
30
- }
31
-
32
- Pipeline . prototype . get = function ( i ) {
33
- if ( arguments . length < 1 ) {
34
- return null
15
+ var creators = [ ]
16
+ ; [ ] . forEach . call ( arguments , function ( creator ) {
17
+ if (
18
+ typeof creator === 'string' ||
19
+ typeof creator === 'number'
20
+ ) {
21
+ creator = this . get ( creator )
22
+ }
23
+ creators . push . apply ( creators , this . normalize ( creator ) )
24
+ } , this )
25
+
26
+ return build ( creators )
35
27
}
36
- if ( arguments . length === 1 ) {
37
- i = this . indexOf ( i )
38
- return i === - 1 ? null : this . creators [ i ]
39
- }
40
- return [ ] . map . call ( arguments , function ( n ) {
41
- return this . get ( n )
42
- } , this )
43
- }
44
28
45
- Pipeline . prototype . indexOf = function ( i ) {
46
- if ( typeof i === 'number' ) {
47
- return i
48
- }
49
- for ( var j = 0 , len = this . creators . length ; j < len ; ++ j ) {
50
- if ( equal ( this . creators [ j ] [ 0 ] , i ) ) {
51
- return j
29
+ get ( i ) {
30
+ if ( arguments . length < 1 ) {
31
+ return null
32
+ }
33
+ if ( arguments . length === 1 ) {
34
+ i = this . indexOf ( i )
35
+ return i === - 1 ? null : this . creators [ i ]
52
36
}
37
+ return [ ] . map . call ( arguments , function ( n ) {
38
+ return this . get ( n )
39
+ } , this )
53
40
}
54
- return - 1
55
- }
56
-
57
- Pipeline . prototype . splice = function ( ) {
58
- var args = [ ]
59
41
60
- ; [ ] . forEach . call ( arguments , function ( creator , i ) {
61
- if ( i === 0 ) {
62
- return args . push ( this . indexOf ( creator ) )
42
+ indexOf ( i ) {
43
+ if ( typeof i === 'number' ) {
44
+ return i
63
45
}
64
- if ( i === 1 ) {
65
- return args . push ( creator )
46
+ for ( var j = 0 , len = this . creators . length ; j < len ; ++ j ) {
47
+ if ( equal ( this . creators [ j ] [ 0 ] , i ) ) {
48
+ return j
49
+ }
66
50
}
67
- args . push . apply ( args , this . normalize ( creator ) )
68
- } , this )
69
-
70
- return this . creators . splice . apply ( this . creators , args )
71
- }
72
-
73
- Pipeline . prototype . push = function ( ) {
74
- var args = [ this . creators . length , 0 ]
75
- args . push . apply ( args , arguments )
76
- this . splice . apply ( this , args )
77
- }
51
+ return - 1
52
+ }
78
53
79
- Pipeline . prototype . unshift = function ( ) {
80
- var args = [ 0 , 0 ]
81
- args . push . apply ( args , arguments )
82
- this . splice . apply ( this , args )
83
- }
54
+ splice ( ) {
55
+ var args = [ ]
84
56
85
- Pipeline . prototype . pop = function ( ) {
86
- return this . creators . pop ( )
87
- }
57
+ ; [ ] . forEach . call ( arguments , function ( creator , i ) {
58
+ if ( i === 0 ) {
59
+ return args . push ( this . indexOf ( creator ) )
60
+ }
61
+ if ( i === 1 ) {
62
+ return args . push ( creator )
63
+ }
64
+ args . push . apply ( args , this . normalize ( creator ) )
65
+ } , this )
88
66
89
- Pipeline . prototype . shift = function ( ) {
90
- return this . creators . shift ( )
91
- }
67
+ return this . creators . splice . apply ( this . creators , args )
68
+ }
92
69
93
- Pipeline . prototype . normalize = function ( creator ) {
94
- if ( creator && creator . creators ) {
95
- // Pipeline instance
96
- return creator . creators
70
+ push ( ) {
71
+ var args = [ this . creators . length , 0 ]
72
+ args . push . apply ( args , arguments )
73
+ this . splice . apply ( this , args )
97
74
}
98
- if ( creator && creator . plugins ) {
99
- // postcss Processor instance
100
- return creator . plugins . map ( function ( plugin ) {
101
- return [ plugin ]
102
- } )
75
+
76
+ unshift ( ) {
77
+ var args = [ 0 , 0 ]
78
+ args . push . apply ( args , arguments )
79
+ this . splice . apply ( this , args )
103
80
}
104
- if ( ! Array . isArray ( creator ) ) {
105
- creator = [ creator ]
81
+
82
+ pop ( ) {
83
+ return this . creators . pop ( )
106
84
}
107
- if ( typeof creator [ 0 ] === 'function' ) {
108
- return [ creator ]
85
+
86
+ shift ( ) {
87
+ return this . creators . shift ( )
109
88
}
110
- var crt = this . get ( creator [ 0 ] )
111
- if ( ! crt ) {
112
- return [ ]
89
+
90
+ normalize ( creator ) {
91
+ if ( creator && creator . creators ) {
92
+ // Pipeline instance
93
+ return creator . creators
94
+ }
95
+ if ( creator && creator . plugins ) {
96
+ // postcss Processor instance
97
+ return creator . plugins . map ( function ( plugin ) {
98
+ return [ plugin ]
99
+ } )
100
+ }
101
+ if ( ! Array . isArray ( creator ) ) {
102
+ creator = [ creator ]
103
+ }
104
+ if ( typeof creator [ 0 ] === 'function' ) {
105
+ return [ creator ]
106
+ }
107
+ var crt = this . get ( creator [ 0 ] )
108
+ if ( ! crt ) {
109
+ return [ ]
110
+ }
111
+ crt = crt . slice ( )
112
+ crt . splice . apply ( crt , [ 1 , 0 ] . concat ( creator . slice ( 1 ) ) )
113
+ return [ crt ]
113
114
}
114
- crt = crt . slice ( )
115
- crt . splice . apply ( crt , [ 1 , 0 ] . concat ( creator . slice ( 1 ) ) )
116
- return [ crt ]
117
115
}
118
116
119
117
function equal ( creator , p ) {
@@ -132,3 +130,6 @@ function build(creators) {
132
130
} ) )
133
131
}
134
132
133
+ module . exports = Pipeline
134
+ module . exports . build = build
135
+
0 commit comments