1
- import { inject , injectable } from 'inversify' ;
1
+ import { inject , injectable , postConstruct } from 'inversify' ;
2
2
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers' ;
3
3
4
4
import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope' ;
5
5
6
+ import { IInitializable } from '../../interfaces/IInitializable' ;
6
7
import { IOptions } from '../../interfaces/options/IOptions' ;
7
8
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator' ;
8
9
@@ -14,7 +15,12 @@ import { AbstractIdentifierNamesGenerator } from './AbstractIdentifierNamesGener
14
15
import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils' ;
15
16
16
17
@injectable ( )
17
- export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator {
18
+ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator implements IInitializable {
19
+ /**
20
+ * @type {string[] }
21
+ */
22
+ protected static nameSequence : string [ ] ;
23
+
18
24
/**
19
25
* @type {string }
20
26
*/
@@ -36,11 +42,6 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
36
42
'var' , 'void' , 'with'
37
43
] ) ;
38
44
39
- /**
40
- * @type {string[] }
41
- */
42
- protected nameSequence : string [ ] = `${ numbersString } ${ alphabetString } ${ alphabetStringUppercase } ` . split ( '' ) ;
43
-
44
45
/**
45
46
* @type {string }
46
47
*/
@@ -57,6 +58,15 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
57
58
super ( randomGenerator , options ) ;
58
59
}
59
60
61
+ @postConstruct ( )
62
+ public initialize ( ) : void {
63
+ if ( ! MangledIdentifierNamesGenerator . nameSequence ) {
64
+ MangledIdentifierNamesGenerator . nameSequence = [
65
+ ...`${ numbersString } ${ alphabetString } ${ alphabetStringUppercase } `
66
+ ] ;
67
+ }
68
+ }
69
+
60
70
/**
61
71
* We can only ignore limited nameLength, it has no sense here
62
72
* @param {number } nameLength
@@ -134,7 +144,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
134
144
*/
135
145
private generateNewMangledName ( previousMangledName : string ) : string {
136
146
const generateNewMangledName : ( name : string ) => string = ( name : string ) : string => {
137
- const nameSequence : string [ ] = this . nameSequence ;
147
+ const nameSequence : string [ ] = MangledIdentifierNamesGenerator . nameSequence ;
138
148
const nameSequenceLength : number = nameSequence . length ;
139
149
const nameLength : number = name . length ;
140
150
@@ -161,7 +171,9 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
161
171
-- index ;
162
172
} while ( index >= 0 ) ;
163
173
164
- return `a${ zeroSequence ( nameLength ) } ` ;
174
+ const firstLetterCharacter : string = nameSequence [ numbersString . length ] ;
175
+
176
+ return `${ firstLetterCharacter } ${ zeroSequence ( nameLength ) } ` ;
165
177
} ;
166
178
167
179
let newMangledName : string = generateNewMangledName ( previousMangledName ) ;
0 commit comments