@@ -19,118 +19,124 @@ var _icssReplaceSymbols2 = _interopRequireDefault(_icssReplaceSymbols);
19
19
var matchImports = / ^ ( .+ ?) \s + f r o m \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | [ \w - ] + ) $ / ;
20
20
var matchValueDefinition = / (?: , \s + | ^ ) ( [ \w - ] + ) : ? \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | \w + \( [ ^ \) ] + \) | [ ^ , ] + ) \s ? / g;
21
21
var matchImport = / ^ ( [ \w - ] + ) (?: \s + a s \s + ( [ \w - ] + ) ) ? / ;
22
- var options = { } ;
23
- var importIndex = 0 ;
24
- var createImportedName = options && options . createImportedName || function ( importName /*, path*/ ) {
25
- return 'i__const_' + importName . replace ( / \W / g, '_' ) + '_' + importIndex ++ ;
26
- } ;
27
22
28
- exports [ 'default' ] = function ( css ) {
29
- var importAliases = [ ] ;
30
- var definitions = { } ;
23
+ var processor = _postcss2 [ 'default' ] . plugin ( 'postcss-modules-values' , function ( ) {
24
+ var opts = arguments . length <= 0 || arguments [ 0 ] === undefined ? { } : arguments [ 0 ] ;
25
+ var _opts$importIndex = opts . importIndex ;
26
+ var importIndex = _opts$importIndex === undefined ? 0 : _opts$importIndex ;
27
+ var _opts$createImportedName = opts . createImportedName ;
28
+ var createImportedName = _opts$createImportedName === undefined ? function ( importName /*, path*/ ) {
29
+ return 'i__const_' + importName . replace ( / \W / g, '_' ) + '_' + importIndex ++ ;
30
+ } : _opts$createImportedName ;
31
+
32
+ return function ( css ) {
33
+ var importAliases = [ ] ;
34
+ var definitions = { } ;
35
+
36
+ var addDefinition = function addDefinition ( atRule ) {
37
+ var matches = undefined ;
38
+ while ( matches = matchValueDefinition . exec ( atRule . params ) ) {
39
+ var _matches = matches ;
40
+
41
+ var _matches2 = _slicedToArray ( _matches , 3 ) ;
42
+
43
+ var /*match*/ key = _matches2 [ 1 ] ;
44
+ var value = _matches2 [ 2 ] ;
45
+
46
+ // Add to the definitions, knowing that values can refer to each other
47
+ definitions [ key ] = ( 0 , _icssReplaceSymbols . replaceAll ) ( definitions , value ) ;
48
+ atRule . remove ( ) ;
49
+ }
50
+ } ;
51
+
52
+ var addImport = function addImport ( atRule ) {
53
+ var matches = matchImports . exec ( atRule . params ) ;
54
+ if ( matches ) {
55
+ var _matches3 = _slicedToArray ( matches , 3 ) ;
56
+
57
+ var /*match*/ aliases = _matches3 [ 1 ] ;
58
+ var path = _matches3 [ 2 ] ;
59
+
60
+ // We can use constants for path names
61
+ if ( definitions [ path ] ) path = definitions [ path ] ;
62
+ var imports = aliases . split ( / \s * , \s * / ) . map ( function ( alias ) {
63
+ var tokens = matchImport . exec ( alias ) ;
64
+ if ( tokens ) {
65
+ var _tokens = _slicedToArray ( tokens , 3 ) ;
66
+
67
+ var /*match*/ theirName = _tokens [ 1 ] ;
68
+ var _tokens$2 = _tokens [ 2 ] ;
69
+ var myName = _tokens$2 === undefined ? theirName : _tokens$2 ;
70
+
71
+ var importedName = createImportedName ( myName ) ;
72
+ definitions [ myName ] = importedName ;
73
+ return { theirName : theirName , importedName : importedName } ;
74
+ } else {
75
+ throw new Error ( '@import statement "' + alias + '" is invalid!' ) ;
76
+ }
77
+ } ) ;
78
+ importAliases . push ( { path : path , imports : imports } ) ;
79
+ atRule . remove ( ) ;
80
+ }
81
+ } ;
82
+
83
+ /* Look at all the @value statements and treat them as locals or as imports */
84
+ css . walkAtRules ( 'value' , function ( atRule ) {
85
+ if ( matchImports . exec ( atRule . params ) ) {
86
+ addImport ( atRule ) ;
87
+ } else {
88
+ addDefinition ( atRule ) ;
89
+ }
90
+ } ) ;
31
91
32
- var addDefinition = function addDefinition ( atRule ) {
33
- var matches = undefined ;
34
- while ( matches = matchValueDefinition . exec ( atRule . params ) ) {
35
- var _matches = matches ;
92
+ /* We want to export anything defined by now, but don't add it to the CSS yet or
93
+ it well get picked up by the replacement stuff */
94
+ var exportDeclarations = Object . keys ( definitions ) . map ( function ( key ) {
95
+ return _postcss2 [ 'default' ] . decl ( {
96
+ value : definitions [ key ] ,
97
+ prop : key ,
98
+ raws : { before : "\n " } ,
99
+ _autoprefixerDisabled : true
100
+ } ) ;
101
+ } ) ;
36
102
37
- var _matches2 = _slicedToArray ( _matches , 3 ) ;
103
+ /* If we have no definitions, don't continue */
104
+ if ( ! Object . keys ( definitions ) . length ) return ;
38
105
39
- var /*match*/ key = _matches2 [ 1 ] ;
40
- var value = _matches2 [ 2 ] ;
106
+ /* Perform replacements */
107
+ ( 0 , _icssReplaceSymbols2 [ 'default' ] ) ( css , definitions ) ;
41
108
42
- // Add to the definitions, knowing that values can refer to each other
43
- definitions [ key ] = ( 0 , _icssReplaceSymbols . replaceAll ) ( definitions , value ) ;
44
- atRule . remove ( ) ;
109
+ /* Add export rules if any */
110
+ if ( exportDeclarations . length > 0 ) {
111
+ css . prepend ( _postcss2 [ 'default' ] . rule ( {
112
+ selector : ':export' ,
113
+ raws : { after : "\n" } ,
114
+ nodes : exportDeclarations
115
+ } ) ) ;
45
116
}
46
- } ;
47
117
48
- var addImport = function addImport ( atRule ) {
49
- var matches = matchImports . exec ( atRule . params ) ;
50
- if ( matches ) {
51
- var _matches3 = _slicedToArray ( matches , 3 ) ;
52
-
53
- var /*match*/ aliases = _matches3 [ 1 ] ;
54
- var path = _matches3 [ 2 ] ;
55
-
56
- // We can use constants for path names
57
- if ( definitions [ path ] ) path = definitions [ path ] ;
58
- var imports = aliases . split ( / \s * , \s * / ) . map ( function ( alias ) {
59
- var tokens = matchImport . exec ( alias ) ;
60
- if ( tokens ) {
61
- var _tokens = _slicedToArray ( tokens , 3 ) ;
62
-
63
- var /*match*/ theirName = _tokens [ 1 ] ;
64
- var _tokens$2 = _tokens [ 2 ] ;
65
- var myName = _tokens$2 === undefined ? theirName : _tokens$2 ;
66
-
67
- var importedName = createImportedName ( myName ) ;
68
- definitions [ myName ] = importedName ;
69
- return { theirName : theirName , importedName : importedName } ;
70
- } else {
71
- throw new Error ( '@import statement "' + alias + '" is invalid!' ) ;
72
- }
73
- } ) ;
74
- importAliases . push ( { path : path , imports : imports } ) ;
75
- atRule . remove ( ) ;
76
- }
77
- } ;
78
-
79
- /* Look at all the @value statements and treat them as locals or as imports */
80
- css . walkAtRules ( 'value' , function ( atRule ) {
81
- if ( matchImports . exec ( atRule . params ) ) {
82
- addImport ( atRule ) ;
83
- } else {
84
- addDefinition ( atRule ) ;
85
- }
86
- } ) ;
87
-
88
- /* We want to export anything defined by now, but don't add it to the CSS yet or
89
- it well get picked up by the replacement stuff */
90
- var exportDeclarations = Object . keys ( definitions ) . map ( function ( key ) {
91
- return _postcss2 [ 'default' ] . decl ( {
92
- value : definitions [ key ] ,
93
- prop : key ,
94
- raws : { before : "\n " } ,
95
- _autoprefixerDisabled : true
118
+ /* Add import rules */
119
+ importAliases . reverse ( ) . forEach ( function ( _ref ) {
120
+ var path = _ref . path ;
121
+ var imports = _ref . imports ;
122
+
123
+ css . prepend ( _postcss2 [ 'default' ] . rule ( {
124
+ selector : ':import(' + path + ')' ,
125
+ raws : { after : "\n" } ,
126
+ nodes : imports . map ( function ( _ref2 ) {
127
+ var theirName = _ref2 . theirName ;
128
+ var importedName = _ref2 . importedName ;
129
+ return _postcss2 [ 'default' ] . decl ( {
130
+ value : theirName ,
131
+ prop : importedName ,
132
+ raws : { before : "\n " } ,
133
+ _autoprefixerDisabled : true
134
+ } ) ;
135
+ } )
136
+ } ) ) ;
96
137
} ) ;
97
- } ) ;
98
-
99
- /* If we have no definitions, don't continue */
100
- if ( ! Object . keys ( definitions ) . length ) return ;
101
-
102
- /* Perform replacements */
103
- ( 0 , _icssReplaceSymbols2 [ 'default' ] ) ( css , definitions ) ;
104
-
105
- /* Add export rules if any */
106
- if ( exportDeclarations . length > 0 ) {
107
- css . prepend ( _postcss2 [ 'default' ] . rule ( {
108
- selector : ':export' ,
109
- raws : { after : "\n" } ,
110
- nodes : exportDeclarations
111
- } ) ) ;
112
- }
113
-
114
- /* Add import rules */
115
- importAliases . reverse ( ) . forEach ( function ( _ref ) {
116
- var path = _ref . path ;
117
- var imports = _ref . imports ;
118
-
119
- css . prepend ( _postcss2 [ 'default' ] . rule ( {
120
- selector : ':import(' + path + ')' ,
121
- raws : { after : "\n" } ,
122
- nodes : imports . map ( function ( _ref2 ) {
123
- var theirName = _ref2 . theirName ;
124
- var importedName = _ref2 . importedName ;
125
- return _postcss2 [ 'default' ] . decl ( {
126
- value : theirName ,
127
- prop : importedName ,
128
- raws : { before : "\n " } ,
129
- _autoprefixerDisabled : true
130
- } ) ;
131
- } )
132
- } ) ) ;
133
- } ) ;
134
- } ;
138
+ } ;
139
+ } ) ;
135
140
141
+ exports [ 'default' ] = processor ;
136
142
module . exports = exports [ 'default' ] ;
0 commit comments