|
@@ -1,8 +1,9 @@
|
|
-import { inject, injectable } from 'inversify';
|
|
|
|
|
|
+import { inject, injectable, postConstruct } from 'inversify';
|
|
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
|
|
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
|
|
|
|
|
|
import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
|
|
import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
|
|
|
|
|
|
|
|
+import { IInitializable } from '../../interfaces/IInitializable';
|
|
import { IOptions } from '../../interfaces/options/IOptions';
|
|
import { IOptions } from '../../interfaces/options/IOptions';
|
|
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
|
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
|
|
|
|
|
@@ -14,7 +15,12 @@ import { AbstractIdentifierNamesGenerator } from './AbstractIdentifierNamesGener
|
|
import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
|
|
import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
|
|
|
|
|
|
@injectable()
|
|
@injectable()
|
|
-export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator {
|
|
|
|
|
|
+export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator implements IInitializable {
|
|
|
|
+ /**
|
|
|
|
+ * @type {string[]}
|
|
|
|
+ */
|
|
|
|
+ protected static nameSequence: string[];
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @type {string}
|
|
* @type {string}
|
|
*/
|
|
*/
|
|
@@ -36,11 +42,6 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
|
'var', 'void', 'with'
|
|
'var', 'void', 'with'
|
|
]);
|
|
]);
|
|
|
|
|
|
- /**
|
|
|
|
- * @type {string[]}
|
|
|
|
- */
|
|
|
|
- protected nameSequence: string[] = `${numbersString}${alphabetString}${alphabetStringUppercase}`.split('');
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* @type {string}
|
|
* @type {string}
|
|
*/
|
|
*/
|
|
@@ -57,6 +58,15 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
|
super(randomGenerator, options);
|
|
super(randomGenerator, options);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @postConstruct()
|
|
|
|
+ public initialize (): void {
|
|
|
|
+ if (!MangledIdentifierNamesGenerator.nameSequence) {
|
|
|
|
+ MangledIdentifierNamesGenerator.nameSequence = [
|
|
|
|
+ ...`${numbersString}${alphabetString}${alphabetStringUppercase}`
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* We can only ignore limited nameLength, it has no sense here
|
|
* We can only ignore limited nameLength, it has no sense here
|
|
* @param {number} nameLength
|
|
* @param {number} nameLength
|
|
@@ -134,7 +144,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
|
*/
|
|
*/
|
|
private generateNewMangledName (previousMangledName: string): string {
|
|
private generateNewMangledName (previousMangledName: string): string {
|
|
const generateNewMangledName: (name: string) => string = (name: string): string => {
|
|
const generateNewMangledName: (name: string) => string = (name: string): string => {
|
|
- const nameSequence: string[] = this.nameSequence;
|
|
|
|
|
|
+ const nameSequence: string[] = MangledIdentifierNamesGenerator.nameSequence;
|
|
const nameSequenceLength: number = nameSequence.length;
|
|
const nameSequenceLength: number = nameSequence.length;
|
|
const nameLength: number = name.length;
|
|
const nameLength: number = name.length;
|
|
|
|
|
|
@@ -161,7 +171,9 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
|
--index;
|
|
--index;
|
|
} while (index >= 0);
|
|
} while (index >= 0);
|
|
|
|
|
|
- return `a${zeroSequence(nameLength)}`;
|
|
|
|
|
|
+ const firstLetterCharacter: string = nameSequence[numbersString.length];
|
|
|
|
+
|
|
|
|
+ return `${firstLetterCharacter}${zeroSequence(nameLength)}`;
|
|
};
|
|
};
|
|
|
|
|
|
let newMangledName: string = generateNewMangledName(previousMangledName);
|
|
let newMangledName: string = generateNewMangledName(previousMangledName);
|