@@ -39,7 +39,7 @@ export class BlockFactory {
39
39
postcssImpl : typeof postcss ;
40
40
importer : Importer ;
41
41
configuration : ResolvedConfiguration ;
42
- blockNames : ObjectDictionary < number > ;
42
+ blockNames : ObjectDictionary < string > ;
43
43
parser : BlockParser ;
44
44
preprocessors : Preprocessors ;
45
45
faultTolerant : boolean ;
@@ -207,11 +207,11 @@ export class BlockFactory {
207
207
}
208
208
209
209
// Ensure this block name is unique.
210
- const uniqueName = this . getUniqueBlockName ( block . name , file . type === "ImportedCompiledCssFile" ) ;
210
+ const uniqueName = this . getUniqueBlockName ( block . name , block . identifier , file . type === "ImportedCompiledCssFile" ) ;
211
211
if ( uniqueName === null ) {
212
212
// For ImportedCompiledCssFiles, leave the name alone and add an error.
213
213
block . addError (
214
- new CssBlockError ( " Block uses a name that has already been used! Check dependencies for conflicting block names." , {
214
+ new CssBlockError ( ` Block uses a name that has already been used by ${ this . blockNames [ block . name ] } ` , {
215
215
filename : block . identifier ,
216
216
} ) ,
217
217
) ;
@@ -442,15 +442,21 @@ export class BlockFactory {
442
442
* @return The unique block name that is now registered with the BlockFactory, or null if
443
443
* the name has already been registered and should not be overridden.
444
444
*/
445
- getUniqueBlockName ( name : string , doNotOverride = false ) : string | null {
445
+ getUniqueBlockName ( name : string , identifier : string , doNotOverride = false ) : string | null {
446
446
if ( ! this . blockNames [ name ] ) {
447
- this . blockNames [ name ] = 1 ;
447
+ this . blockNames [ name ] = identifier ;
448
448
return name ;
449
449
}
450
450
if ( doNotOverride ) {
451
451
return null ;
452
452
}
453
- return `${ name } -${ ++ this . blockNames [ name ] } ` ;
453
+ let i = 2 ;
454
+ while ( this . blockNames [ `${ name } -${ i } ` ] ) {
455
+ i ++ ;
456
+ }
457
+ name = `${ name } -${ i } ` ;
458
+ this . blockNames [ name ] = identifier ;
459
+ return name ;
454
460
}
455
461
456
462
preprocessor ( file : ImportedFile ) : Preprocessor {
0 commit comments