mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Moved initialisation of nameSequence to the initialize method
This commit is contained in:
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,8 +1,9 @@
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { inject, injectable, postConstruct } 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';
|
||||
|
||||
@@ -14,7 +15,12 @@ import { AbstractIdentifierNamesGenerator } from './AbstractIdentifierNamesGener
|
||||
import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
|
||||
|
||||
@injectable()
|
||||
export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator {
|
||||
export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator implements IInitializable {
|
||||
/**
|
||||
* @type {string[]}
|
||||
*/
|
||||
protected static nameSequence: string[];
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -36,11 +42,6 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
'var', 'void', 'with'
|
||||
]);
|
||||
|
||||
/**
|
||||
* @type {string[]}
|
||||
*/
|
||||
protected nameSequence: string[] = `${numbersString}${alphabetString}${alphabetStringUppercase}`.split('');
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -57,6 +58,15 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
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
|
||||
* @param {number} nameLength
|
||||
@@ -134,7 +144,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
*/
|
||||
private generateNewMangledName (previousMangledName: 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 nameLength: number = name.length;
|
||||
|
||||
|
||||
+11
-5
@@ -1,4 +1,4 @@
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { inject, injectable, postConstruct } from 'inversify';
|
||||
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
|
||||
|
||||
import { IArrayUtils } from '../../interfaces/utils/IArrayUtils';
|
||||
@@ -31,9 +31,15 @@ export class MangledShuffledIdentifierNamesGenerator extends MangledIdentifierNa
|
||||
super(randomGenerator, options);
|
||||
|
||||
this.arrayUtils = arrayUtils;
|
||||
this.nameSequence = [
|
||||
...`${numbersString}`,
|
||||
...this.arrayUtils.shuffle([...`${alphabetString}${alphabetStringUppercase}`])
|
||||
];
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
public initialize (): void {
|
||||
if (!MangledIdentifierNamesGenerator.nameSequence) {
|
||||
MangledIdentifierNamesGenerator.nameSequence = [
|
||||
...`${numbersString}`,
|
||||
...this.arrayUtils.shuffle([...`${alphabetString}${alphabetStringUppercase}`])
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user