Skip to content

Commit 614ec02

Browse files
committed
got 'x from global' meaning 'global(x)'
1 parent 962a597 commit 614ec02

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/index.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import postcss from 'postcss';
22

33
const declWhitelist = ['composes'],
44
declFilter = new RegExp( `^(${declWhitelist.join( '|' )})$` ),
5-
matchImports = /^(.+?)\s+from\s+(?:"([^"]+)"|'([^']+)')$/,
5+
matchImports = /^(.+?)\s+from\s+(?:"([^"]+)"|'([^']+)'|(global))$/,
66
icssImport = /^:import\((?:"([^"]+)"|'([^']+)')\)/;
77

88
const processor = postcss.plugin( 'modules-extract-imports', function ( options ) {
@@ -14,17 +14,23 @@ const processor = postcss.plugin( 'modules-extract-imports', function ( options
1414
// Find any declaration that supports imports
1515
css.walkDecls( declFilter, ( decl ) => {
1616
let matches = decl.value.match( matchImports );
17+
let tmpSymbols;
1718
if ( matches ) {
18-
let [/*match*/, symbols, doubleQuotePath, singleQuotePath] = matches;
19-
let path = doubleQuotePath || singleQuotePath;
20-
imports[path] = imports[path] || {};
21-
let tmpSymbols = symbols.split( /\s+/ )
22-
.map( s => {
23-
if ( !imports[path][s] ) {
24-
imports[path][s] = createImportedName( s, path );
25-
}
26-
return imports[path][s];
27-
} );
19+
let [/*match*/, symbols, doubleQuotePath, singleQuotePath, global] = matches;
20+
if (global) {
21+
// Composing globals simply means changing these classes to wrap them in global(name)
22+
tmpSymbols = symbols.split(/\s+/).map(s => `global(${s})`)
23+
} else {
24+
let path = doubleQuotePath || singleQuotePath;
25+
imports[path] = imports[path] || {};
26+
tmpSymbols = symbols.split(/\s+/)
27+
.map(s => {
28+
if (!imports[path][s]) {
29+
imports[path][s] = createImportedName(s, path);
30+
}
31+
return imports[path][s];
32+
});
33+
}
2834
decl.value = tmpSymbols.join( ' ' );
2935
}
3036
} );
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:local(.exportName) { composes: global(importName) global(secondImport); other: rule; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:local(.exportName) { composes: importName secondImport from global; other: rule; }

0 commit comments

Comments
 (0)