1+ 'use strict' ;
2+
3+ Object . defineProperty ( exports , '__esModule' , {
4+ value : true
5+ } ) ;
6+
7+ var _slicedToArray = ( function ( ) { function sliceIterator ( arr , i ) { var _arr = [ ] ; var _n = true ; var _d = false ; var _e = undefined ; try { for ( var _i = arr [ Symbol . iterator ] ( ) , _s ; ! ( _n = ( _s = _i . next ( ) ) . done ) ; _n = true ) { _arr . push ( _s . value ) ; if ( i && _arr . length === i ) break ; } } catch ( err ) { _d = true ; _e = err ; } finally { try { if ( ! _n && _i [ 'return' ] ) _i [ 'return' ] ( ) ; } finally { if ( _d ) throw _e ; } } return _arr ; } return function ( arr , i ) { if ( Array . isArray ( arr ) ) { return arr ; } else if ( Symbol . iterator in Object ( arr ) ) { return sliceIterator ( arr , i ) ; } else { throw new TypeError ( 'Invalid attempt to destructure non-iterable instance' ) ; } } ; } ) ( ) ;
8+
9+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { 'default' : obj } ; }
10+
11+ var _postcss = require ( 'postcss' ) ;
12+
13+ var _postcss2 = _interopRequireDefault ( _postcss ) ;
14+
15+ var _icssReplaceSymbols = require ( 'icss-replace-symbols' ) ;
16+
17+ var _icssReplaceSymbols2 = _interopRequireDefault ( _icssReplaceSymbols ) ;
18+
19+ var matchImports = / ^ ( .+ ?) \s + f r o m \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | [ \w - ] + ) $ / ;
20+ var matchLet = / (?: , \s + | ^ ) ( [ \w - ] + ) : ? \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | [ ^ , ] + ) \s ? / g;
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+
28+ exports [ 'default' ] = function ( css ) {
29+ /* Find any local let rules and store them*/
30+ var translations = { } ;
31+ css . eachAtRule ( / ^ d e f i n e $ / , function ( atRule ) {
32+ var matches = undefined ;
33+ while ( matches = matchLet . exec ( atRule . params ) ) {
34+ var _matches = matches ;
35+
36+ var _matches2 = _slicedToArray ( _matches , 3 ) ;
37+
38+ var /*match*/ key = _matches2 [ 1 ] ;
39+ var value = _matches2 [ 2 ] ;
40+
41+ translations [ key ] = value ;
42+ atRule . removeSelf ( ) ;
43+ }
44+ } ) ;
45+
46+ /* We want to export anything defined by now, but don't add it to the CSS yet or
47+ it well get picked up by the replacement stuff */
48+ var exportDeclarations = Object . keys ( translations ) . map ( function ( key ) {
49+ return _postcss2 [ 'default' ] . decl ( {
50+ value : translations [ key ] ,
51+ prop : key ,
52+ before : "\n " ,
53+ _autoprefixerDisabled : true
54+ } ) ;
55+ } ) ;
56+
57+ /* Find imports and insert ICSS tmp vars */
58+ var importAliases = [ ] ;
59+ css . eachAtRule ( / ^ i m p o r t ( - d e f i n e ) ? $ / , function ( atRule ) {
60+ var matches = matchImports . exec ( atRule . params ) ;
61+ if ( matches ) {
62+ var _matches3 = _slicedToArray ( matches , 3 ) ;
63+
64+ var /*match*/ aliases = _matches3 [ 1 ] ;
65+ var path = _matches3 [ 2 ] ;
66+
67+ // We can use constants for path names
68+ if ( translations [ path ] ) path = translations [ path ] ;
69+ var imports = aliases . split ( / \s * , \s * / ) . map ( function ( alias ) {
70+ var tokens = matchImport . exec ( alias ) ;
71+ if ( tokens ) {
72+ var _tokens = _slicedToArray ( tokens , 3 ) ;
73+
74+ var /*match*/ theirName = _tokens [ 1 ] ;
75+ var _tokens$2 = _tokens [ 2 ] ;
76+ var myName = _tokens$2 === undefined ? theirName : _tokens$2 ;
77+
78+ var importedName = createImportedName ( myName ) ;
79+ translations [ myName ] = importedName ;
80+ return { theirName : theirName , importedName : importedName } ;
81+ } else {
82+ throw new Error ( '@import statement "' + alias + '" is invalid!' ) ;
83+ }
84+ } ) ;
85+ importAliases . push ( { path : path , imports : imports } ) ;
86+ atRule . removeSelf ( ) ;
87+ }
88+ } ) ;
89+
90+ /* If we have no translations, don't continue */
91+ if ( ! Object . keys ( translations ) . length ) return ;
92+
93+ /* Perform replacements */
94+ ( 0 , _icssReplaceSymbols2 [ 'default' ] ) ( css , translations ) ;
95+
96+ /* Add import rules */
97+ importAliases . forEach ( function ( _ref ) {
98+ var path = _ref . path ;
99+ var imports = _ref . imports ;
100+
101+ css . prepend ( _postcss2 [ 'default' ] . rule ( {
102+ selector : ':import(' + path + ')' ,
103+ after : "\n" ,
104+ nodes : imports . map ( function ( _ref2 ) {
105+ var theirName = _ref2 . theirName ;
106+ var importedName = _ref2 . importedName ;
107+ return _postcss2 [ 'default' ] . decl ( {
108+ value : theirName ,
109+ prop : importedName ,
110+ before : "\n " ,
111+ _autoprefixerDisabled : true
112+ } ) ;
113+ } )
114+ } ) ) ;
115+ } ) ;
116+
117+ /* Add export rules if any */
118+ if ( exportDeclarations . length > 0 ) {
119+ css . prepend ( _postcss2 [ 'default' ] . rule ( {
120+ selector : ':export' ,
121+ after : "\n" ,
122+ nodes : exportDeclarations
123+ } ) ) ;
124+ }
125+ } ;
126+
127+ module . exports = exports [ 'default' ] ;
0 commit comments