mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Simplified initialization of nameSequence for MangledIdentifierNamesGenerator
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { inject, injectable, postConstruct } from 'inversify';
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
|
||||
|
||||
import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
|
||||
|
||||
import { IInitializable } from '../../interfaces/IInitializable';
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
||||
|
||||
@@ -15,12 +14,7 @@ import { AbstractIdentifierNamesGenerator } from './AbstractIdentifierNamesGener
|
||||
import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
|
||||
|
||||
@injectable()
|
||||
export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator implements IInitializable {
|
||||
/**
|
||||
* @type {string[]}
|
||||
*/
|
||||
protected static nameSequence: string[];
|
||||
|
||||
export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -31,6 +25,13 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
*/
|
||||
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
|
||||
*
|
||||
@@ -58,13 +59,6 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
super(randomGenerator, options);
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
public initialize (): void {
|
||||
this.initializeNameSequence([
|
||||
...`${numbersString}${alphabetString}${alphabetStringUppercase}`
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* We can only ignore limited nameLength, it has no sense here
|
||||
* @param {number} nameLength
|
||||
@@ -136,15 +130,6 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
&& !MangledIdentifierNamesGenerator.reservedNamesSet.has(mangledName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string[]} nameSequence
|
||||
*/
|
||||
protected initializeNameSequence (nameSequence: string[]): void {
|
||||
if (!this.getNameSequence()) {
|
||||
MangledIdentifierNamesGenerator.nameSequence = nameSequence;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string[]}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user