1- const postcss = require ( 'postcss' )
2- const { default : replaceSymbols , replaceAll } = require ( 'icss-replace-symbols' )
3- const { extractICSS, createICSSRules } = require ( './icss.js' )
1+ import postcss from 'postcss'
2+ import {
3+ replaceSymbols ,
4+ replaceValueSymbols ,
5+ extractICSS ,
6+ createICSSRules
7+ } from 'icss-utils'
48
59const matchImports = / ^ ( .+ ?| \( [ \s \S ] + ?\) ) \s + f r o m \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | [ \w - ] + ) $ /
610const matchValueDefinition = / (?: \s + | ^ ) ( [ \w - ] + ) : ? \s + ( .+ ?) \s * $ / g
@@ -14,11 +18,11 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
1418 css ,
1519 result
1620) => {
17- const { imports , exports } = extractICSS ( css )
21+ const { icssImports , icssExports } = extractICSS ( css )
1822 let importIndex = 0
1923 const createImportedName = ( path , name ) => {
2024 const importedName = getAliasName ( name , importIndex )
21- if ( imports [ path ] && imports [ path ] [ importedName ] ) {
25+ if ( icssImports [ path ] && icssImports [ path ] [ importedName ] ) {
2226 importIndex += 1
2327 return createImportedName ( path , name )
2428 }
@@ -31,7 +35,7 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
3135 while ( ( matches = matchValueDefinition . exec ( atRule . params ) ) ) {
3236 let [ , key , value ] = matches
3337 // Add to the definitions, knowing that values can refer to each other
34- exports [ key ] = replaceAll ( exports , value )
38+ icssExports [ key ] = replaceValueSymbols ( value , icssExports )
3539 atRule . remove ( )
3640 }
3741 }
@@ -41,7 +45,7 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
4145 if ( matches ) {
4246 let [ , aliasesString , path ] = matches
4347 // We can use constants for path names
44- if ( exports [ path ] ) path = exports [ path ]
48+ if ( icssExports [ path ] ) path = icssExports [ path ]
4549 let aliases = aliasesString
4650 . replace ( / ^ \( \s * ( [ \s \S ] + ) \s * \) $ / , '$1' )
4751 . split ( / \s * , \s * / )
@@ -50,7 +54,7 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
5054 if ( tokens ) {
5155 let [ , theirName , myName = theirName ] = tokens
5256 let importedName = createImportedName ( path , myName )
53- exports [ myName ] = importedName
57+ icssExports [ myName ] = importedName
5458 return { theirName, importedName }
5559 } else {
5660 throw new Error ( `@import statement "${ alias } " is invalid!` )
@@ -60,7 +64,7 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
6064 acc [ importedName ] = theirName
6165 return acc
6266 } , { } )
63- imports [ path ] = Object . assign ( { } , imports [ path ] , aliases )
67+ icssImports [ path ] = Object . assign ( { } , icssImports [ path ] , aliases )
6468 atRule . remove ( )
6569 }
6670 }
@@ -79,10 +83,10 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
7983 } )
8084
8185 /* If we have no definitions, don't continue */
82- if ( Object . keys ( exports ) . length === 0 ) return
86+ if ( Object . keys ( icssExports ) . length === 0 ) return
8387
8488 /* Perform replacements */
85- replaceSymbols ( css , exports )
89+ replaceSymbols ( css , icssExports )
8690
87- css . prepend ( createICSSRules ( imports , exports ) )
91+ css . prepend ( createICSSRules ( icssImports , icssExports ) )
8892} )
0 commit comments