mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Internal fields of TIdentifierNamesCache now are optional. Fixed option validation and added normalization.
This commit is contained in:
@@ -9,6 +9,7 @@ import { ControlFlowFlatteningThresholdRule } from './normalizer-rules/ControlFl
|
||||
import { DeadCodeInjectionRule } from './normalizer-rules/DeadCodeInjectionRule';
|
||||
import { DeadCodeInjectionThresholdRule } from './normalizer-rules/DeadCodeInjectionThresholdRule';
|
||||
import { DomainLockRule } from './normalizer-rules/DomainLockRule';
|
||||
import { IdentifierNamesCacheRule } from './normalizer-rules/IdentifierNamesCacheRule';
|
||||
import { InputFileNameRule } from './normalizer-rules/InputFileNameRule';
|
||||
import { SeedRule } from './normalizer-rules/SeedRule';
|
||||
import { SelfDefendingRule } from './normalizer-rules/SelfDefendingRule';
|
||||
@@ -29,6 +30,7 @@ export class OptionsNormalizer implements IOptionsNormalizer {
|
||||
DeadCodeInjectionRule,
|
||||
DeadCodeInjectionThresholdRule,
|
||||
DomainLockRule,
|
||||
IdentifierNamesCacheRule,
|
||||
InputFileNameRule,
|
||||
SeedRule,
|
||||
SelfDefendingRule,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { TOptionsNormalizerRule } from '../../types/options/TOptionsNormalizerRule';
|
||||
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
|
||||
/**
|
||||
* @param {IOptions} options
|
||||
* @returns {IOptions}
|
||||
*/
|
||||
export const IdentifierNamesCacheRule: TOptionsNormalizerRule = (options: IOptions): IOptions => {
|
||||
let identifierNamesCache = options.identifierNamesCache;
|
||||
|
||||
if (identifierNamesCache && !identifierNamesCache.globalIdentifiers) {
|
||||
identifierNamesCache = {
|
||||
...identifierNamesCache,
|
||||
globalIdentifiers: {}
|
||||
};
|
||||
}
|
||||
|
||||
if (identifierNamesCache && !identifierNamesCache.propertyIdentifiers) {
|
||||
identifierNamesCache = {
|
||||
...identifierNamesCache,
|
||||
propertyIdentifiers: {}
|
||||
};
|
||||
}
|
||||
|
||||
options = {
|
||||
...options,
|
||||
identifierNamesCache
|
||||
};
|
||||
|
||||
return options;
|
||||
};
|
||||
@@ -13,11 +13,11 @@ import { DEFAULT_PRESET } from '../presets/Default';
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const validateDictionary = (value: unknown | TIdentifierNamesCacheDictionary): boolean => {
|
||||
if (typeof value !== 'object') {
|
||||
return false;
|
||||
if (value === undefined) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value === null) {
|
||||
if (typeof value !== 'object' || value === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { TIdentifierNamesCacheDictionary } from './TIdentifierNamesCacheDictionary';
|
||||
|
||||
export type TIdentifierNamesCache = {
|
||||
globalIdentifiers: TIdentifierNamesCacheDictionary;
|
||||
propertyIdentifiers: TIdentifierNamesCacheDictionary;
|
||||
globalIdentifiers?: TIdentifierNamesCacheDictionary;
|
||||
propertyIdentifiers?: TIdentifierNamesCacheDictionary;
|
||||
} | null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user