|
@@ -1,9 +1,8 @@
|
|
-import { inject, injectable, postConstruct } from 'inversify';
|
|
|
|
|
|
+import { inject, injectable } 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';
|
|
|
|
|
|
@@ -15,12 +14,7 @@ import { AbstractIdentifierNamesGenerator } from './AbstractIdentifierNamesGener
|
|
import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
|
|
import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
|
|
|
|
|
|
@injectable()
|
|
@injectable()
|
|
-export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator implements IInitializable {
|
|
|
|
- /**
|
|
|
|
- * @type {string[]}
|
|
|
|
- */
|
|
|
|
- protected static nameSequence: string[];
|
|
|
|
-
|
|
|
|
|
|
+export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator {
|
|
/**
|
|
/**
|
|
* @type {string}
|
|
* @type {string}
|
|
*/
|
|
*/
|
|
@@ -31,6 +25,13 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
|
*/
|
|
*/
|
|
private static readonly lastMangledNameInScopeMap: WeakMap <TNodeWithLexicalScope, string> = new WeakMap();
|
|
private static readonly lastMangledNameInScopeMap: WeakMap <TNodeWithLexicalScope, string> = new WeakMap();
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @type {string[]}
|
|
|
|
+ */
|
|
|
|
+ private static readonly nameSequence: string[] = [
|
|
|
|
+ ...`${numbersString}${alphabetString}${alphabetStringUppercase}`
|
|
|
|
+ ];
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Reserved JS words with length of 2-4 symbols that can be possible generated with this replacer
|
|
* Reserved JS words with length of 2-4 symbols that can be possible generated with this replacer
|
|
*
|
|
*
|
|
@@ -58,15 +59,6 @@ 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
|
|
@@ -138,13 +130,20 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
|
&& !MangledIdentifierNamesGenerator.reservedNamesSet.has(mangledName);
|
|
&& !MangledIdentifierNamesGenerator.reservedNamesSet.has(mangledName);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @returns {string[]}
|
|
|
|
+ */
|
|
|
|
+ protected getNameSequence (): string[] {
|
|
|
|
+ return MangledIdentifierNamesGenerator.nameSequence;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param {string} previousMangledName
|
|
* @param {string} previousMangledName
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
- private generateNewMangledName (previousMangledName: string): string {
|
|
|
|
|
|
+ protected generateNewMangledName (previousMangledName: string): string {
|
|
const generateNewMangledName: (name: string) => string = (name: string): string => {
|
|
const generateNewMangledName: (name: string) => string = (name: string): string => {
|
|
- const nameSequence: string[] = MangledIdentifierNamesGenerator.nameSequence;
|
|
|
|
|
|
+ const nameSequence: string[] = this.getNameSequence();
|
|
const nameSequenceLength: number = nameSequence.length;
|
|
const nameSequenceLength: number = nameSequence.length;
|
|
const nameLength: number = name.length;
|
|
const nameLength: number = name.length;
|
|
|
|
|