File tree 2 files changed +31
-2
lines changed
2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,22 @@ const getAliasName = (name, index) =>
15
15
`i__value_${ name . replace ( / \W / g, '_' ) } _${ index } `
16
16
17
17
let importIndex = 0
18
- const createImportedName = importName => getAliasName ( importName , importIndex ++ )
19
18
20
19
module . exports = postcss . plugin ( 'postcss-modules-values' , ( ) => (
21
20
css ,
22
21
result
23
22
) => {
24
23
const imports = extractICSSImports ( css )
25
24
const exports = extractICSSExports ( css )
25
+ const createImportedName = ( path , name ) => {
26
+ const importedName = getAliasName ( name , importIndex )
27
+ if ( imports [ path ] && imports [ path ] [ importedName ] ) {
28
+ importIndex += 1
29
+ return createImportedName ( path , name )
30
+ }
31
+ importIndex += 1
32
+ return importedName
33
+ }
26
34
27
35
const addDefinition = atRule => {
28
36
let matches
@@ -47,7 +55,7 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
47
55
let tokens = matchImport . exec ( alias )
48
56
if ( tokens ) {
49
57
let [ , theirName , myName = theirName ] = tokens
50
- let importedName = createImportedName ( myName )
58
+ let importedName = createImportedName ( path , myName )
51
59
exports [ myName ] = importedName
52
60
return { theirName, importedName }
53
61
} else {
Original file line number Diff line number Diff line change @@ -373,3 +373,24 @@ test('reuse existing :import with same name and :export', () => {
373
373
` )
374
374
)
375
375
} )
376
+
377
+ test ( 'prevent imported names collision' , ( ) => {
378
+ return expect (
379
+ runCSS ( `
380
+ :import(colors) {
381
+ i__value_a_13: a;
382
+ }
383
+ @value a from colors;
384
+ ` )
385
+ ) . resolves . toEqual (
386
+ strip ( `
387
+ :import(colors) {
388
+ i__value_a_13: a;
389
+ i__value_a_14: a
390
+ }
391
+ :export {
392
+ a: i__value_a_14
393
+ }
394
+ ` )
395
+ )
396
+ } )
You can’t perform that action at this time.
0 commit comments