mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Remove few any types
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -126,7 +126,7 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
|
||||
const blockScopeBodyNode: ESTree.Node = blockScopeBody[index];
|
||||
|
||||
estraverse.traverse(blockScopeBodyNode, {
|
||||
enter: (node: ESTree.Node): any => {
|
||||
enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
|
||||
if (!NodeGuards.isCallExpressionNode(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ export class FunctionDeclarationCalleeDataExtractor extends AbstractCalleeDataEx
|
||||
let calleeBlockStatement: ESTree.BlockStatement | null = null;
|
||||
|
||||
estraverse.traverse(targetNode, {
|
||||
enter: (node: ESTree.Node): any => {
|
||||
enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
|
||||
if (NodeGuards.isFunctionDeclarationNode(node) && node.id.name === name) {
|
||||
calleeBlockStatement = node.body;
|
||||
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ export class FunctionExpressionCalleeDataExtractor extends AbstractCalleeDataExt
|
||||
let calleeBlockStatement: ESTree.BlockStatement | null = null;
|
||||
|
||||
estraverse.traverse(targetNode, {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): any => {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): estraverse.VisitorOption | void => {
|
||||
if (
|
||||
NodeGuards.isFunctionExpressionNode(node) &&
|
||||
parentNode &&
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ export class ObjectExpressionCalleeDataExtractor extends AbstractCalleeDataExtra
|
||||
let calleeBlockStatement: ESTree.BlockStatement | null = null;
|
||||
|
||||
estraverse.traverse(targetNode, {
|
||||
enter: (node: ESTree.Node): any => {
|
||||
enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
|
||||
if (
|
||||
NodeGuards.isVariableDeclaratorNode(node) &&
|
||||
NodeGuards.isIdentifierNode(node.id) &&
|
||||
|
||||
@@ -4,7 +4,6 @@ import * as path from 'path';
|
||||
|
||||
import { TInputCLIOptions } from '../types/options/TInputCLIOptions';
|
||||
import { TInputOptions } from '../types/options/TInputOptions';
|
||||
import { TObject } from '../types/TObject';
|
||||
import { TSourceCodeData } from '../types/cli/TSourceCodeData';
|
||||
|
||||
import { IFileData } from '../interfaces/cli/IFileData';
|
||||
@@ -89,7 +88,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
* @param {TObject} options
|
||||
* @returns {TInputOptions}
|
||||
*/
|
||||
private static filterOptions (options: TObject): TInputOptions {
|
||||
private static filterOptions (options: TInputCLIOptions): TInputOptions {
|
||||
const filteredOptions: TInputOptions = {};
|
||||
|
||||
for (const option in options) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
|
||||
* @param {string} value
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export const ArraySanitizer: TCLISanitizer = (value: string): string[] => {
|
||||
export const ArraySanitizer: TCLISanitizer <string[]> = (value: string): string[] => {
|
||||
if (/,$/.test(value)) {
|
||||
throw new SyntaxError(`Multiple <list> values should be wrapped inside quotes: --option-name 'value1, value2'`);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
|
||||
* @param {string} value
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export const BooleanSanitizer: TCLISanitizer = (value: string): boolean => {
|
||||
export const BooleanSanitizer: TCLISanitizer <boolean> = (value: string): boolean => {
|
||||
return value === 'true' || value === '1';
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import { IdentifierNamesGenerator } from '../../enums/generators/identifier-name
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export const IdentifierNamesGeneratorSanitizer: TCLISanitizer = (value: string): string => {
|
||||
export const IdentifierNamesGeneratorSanitizer: TCLISanitizer <string> = (value: string): string => {
|
||||
const isCorrectIdentifierNamesGenerator: boolean = Object
|
||||
.keys(IdentifierNamesGenerator)
|
||||
.some((key: any): boolean => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export const ObfuscationTargetSanitizer: TCLISanitizer = (value: string): string => {
|
||||
export const ObfuscationTargetSanitizer: TCLISanitizer <string> = (value: string): string => {
|
||||
const isCorrectTarget: boolean = Object
|
||||
.keys(ObfuscationTarget)
|
||||
.some((key: any): boolean => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { SourceMapMode } from '../../enums/source-map/SourceMapMode';
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export const SourceMapModeSanitizer: TCLISanitizer = (value: string): string => {
|
||||
export const SourceMapModeSanitizer: TCLISanitizer <string> = (value: string): string => {
|
||||
const isCorrectSourceMapMode: boolean = Object
|
||||
.keys(SourceMapMode)
|
||||
.some((key: any): boolean => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { StringArrayEncoding } from '../../enums/StringArrayEncoding';
|
||||
* @param {string} value
|
||||
* @returns {TStringArrayEncoding}
|
||||
*/
|
||||
export const StringArrayEncodingSanitizer: TCLISanitizer = (value: string): TStringArrayEncoding => {
|
||||
export const StringArrayEncodingSanitizer: TCLISanitizer <TStringArrayEncoding> = (value: string): TStringArrayEncoding => {
|
||||
switch (value) {
|
||||
case 'true':
|
||||
case '1':
|
||||
|
||||
@@ -83,21 +83,24 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
|
||||
|
||||
/**
|
||||
* @param {interfaces.ServiceIdentifier<interfaces.Newable<U>>} serviceIdentifier
|
||||
* @param {any[]} dependencies
|
||||
* @param {interfaces.ServiceIdentifier<interfaces.Newable<Object>>[]} dependencies
|
||||
* @returns {U}
|
||||
*/
|
||||
public static getConstructorFactory <T extends string, U> (
|
||||
serviceIdentifier: interfaces.ServiceIdentifier<interfaces.Newable<U>>,
|
||||
...dependencies: any[]
|
||||
...dependencies: interfaces.ServiceIdentifier<interfaces.Newable<Object>>[]
|
||||
): (context: interfaces.Context) => (bindingName: T) => U {
|
||||
return (context: interfaces.Context): (bindingName: T) => U => {
|
||||
const cache: Map<T, interfaces.Newable<U>> = new Map();
|
||||
const cachedDependencies: any[] = [];
|
||||
const cachedDependencies: Object[] = [];
|
||||
|
||||
return (bindingName: T) => {
|
||||
dependencies.forEach((dependency: any, index: number) => {
|
||||
dependencies.forEach((
|
||||
dependency: interfaces.ServiceIdentifier<interfaces.Newable<Object>>,
|
||||
index: number
|
||||
) => {
|
||||
if (!cachedDependencies[index]) {
|
||||
cachedDependencies[index] = context.container.get<any>(dependency);
|
||||
cachedDependencies[index] = context.container.get(dependency);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Vendored
+3
-2
@@ -1,5 +1,6 @@
|
||||
/* tslint:disable:interface-name */
|
||||
|
||||
import * as escodegen from 'escodegen-wallaby';
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
declare module 'estree' {
|
||||
@@ -14,10 +15,10 @@ declare module 'estree' {
|
||||
}
|
||||
|
||||
interface SimpleLiteral extends ESTree.BaseNode, ESTree.BaseExpression {
|
||||
'x-verbatim-property'?: any;
|
||||
'x-verbatim-property'?: escodegen.XVerbatimProperty;
|
||||
}
|
||||
|
||||
interface RegExpLiteral extends ESTree.BaseNode, ESTree.BaseExpression {
|
||||
'x-verbatim-property'?: any;
|
||||
'x-verbatim-property'?: escodegen.XVerbatimProperty;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+5
@@ -4,6 +4,11 @@ import * as ESTree from 'estree';
|
||||
import { IGeneratorOutput } from '../interfaces/IGeneratorOutput';
|
||||
|
||||
declare module 'escodegen' {
|
||||
export type XVerbatimProperty = {
|
||||
content?: string;
|
||||
precedence: escodegen.Precedence;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param ast
|
||||
* @param options
|
||||
|
||||
+2
-2
@@ -2,9 +2,9 @@ import * as ESTree from 'estree';
|
||||
|
||||
export interface IObfuscatingReplacer <T = ESTree.Node> {
|
||||
/**
|
||||
* @param nodeValue
|
||||
* @param {SimpleLiteral['value']} nodeValue
|
||||
* @param {number} nodeIdentifier
|
||||
* @returns {T}
|
||||
*/
|
||||
replace (nodeValue: any, nodeIdentifier?: number): T;
|
||||
replace (nodeValue: ESTree.SimpleLiteral['value'], nodeIdentifier?: number): T;
|
||||
}
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme
|
||||
let canTransform: boolean = true;
|
||||
|
||||
estraverse.traverse(blockStatementNode, {
|
||||
enter: (node: ESTree.Node): any => {
|
||||
enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
|
||||
if (NodeGuards.isWhileStatementNode(node)) {
|
||||
return estraverse.VisitorOption.Skip;
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
|
||||
*/
|
||||
private transformFunctionBody (functionNodeBody: ESTree.BlockStatement, controlFlowStorage: IStorage<ICustomNode>): void {
|
||||
estraverse.replace(functionNodeBody, {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): any => {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): estraverse.VisitorOption | ESTree.Node => {
|
||||
if (node.ignoredNode) {
|
||||
return estraverse.VisitorOption.Skip;
|
||||
}
|
||||
|
||||
+2
-2
@@ -111,7 +111,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|
||||
isValidBlockStatementNode: boolean = true;
|
||||
|
||||
estraverse.traverse(blockStatementNode, {
|
||||
enter: (node: ESTree.Node): any => {
|
||||
enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
|
||||
if (NodeGuards.isBlockStatementNode(node)) {
|
||||
nestedBlockStatementsCount++;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|
||||
*/
|
||||
public analyzeNode (programNode: ESTree.Node, parentNode: ESTree.Node): void {
|
||||
estraverse.traverse(programNode, {
|
||||
enter: (node: ESTree.Node): any => {
|
||||
enter: (node: ESTree.Node): void => {
|
||||
if (!NodeGuards.isBlockStatementNode(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ export class CatchClauseTransformer extends AbstractNodeTransformer {
|
||||
*/
|
||||
private replaceCatchClauseParam (catchClauseNode: ESTree.CatchClause, nodeIdentifier: number): void {
|
||||
estraverse.replace(catchClauseNode, {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): any => {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
|
||||
if (parentNode && NodeGuards.isReplaceableIdentifierNode(node, parentNode)) {
|
||||
const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
|
||||
.replace(node.name, nodeIdentifier);
|
||||
|
||||
@@ -145,7 +145,7 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
|
||||
const storedReplaceableIdentifiers: ESTree.Identifier[] = [];
|
||||
|
||||
estraverse.replace(blockScopeNode, {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): any => {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
|
||||
if (parentNode && NodeGuards.isReplaceableIdentifierNode(node, parentNode)) {
|
||||
const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
|
||||
.replace(node.name, nodeIdentifier);
|
||||
|
||||
@@ -166,7 +166,7 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
|
||||
const storedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames = new Map();
|
||||
|
||||
estraverse.replace(blockScopeNode, {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): any => {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
|
||||
if (parentNode && NodeGuards.isReplaceableIdentifierNode(node, parentNode)) {
|
||||
const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
|
||||
.replace(node.name, nodeIdentifier);
|
||||
|
||||
@@ -102,7 +102,7 @@ export class FunctionTransformer extends AbstractNodeTransformer {
|
||||
}
|
||||
|
||||
estraverse.traverse(paramsNode, {
|
||||
enter: (node: ESTree.Node): any => {
|
||||
enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
|
||||
if (NodeGuards.isAssignmentPatternNode(node) && NodeGuards.isIdentifierNode(node.left)) {
|
||||
this.identifierObfuscatingReplacer.storeLocalName(node.left.name, nodeIdentifier);
|
||||
|
||||
@@ -142,7 +142,7 @@ export class FunctionTransformer extends AbstractNodeTransformer {
|
||||
const ignoredIdentifierNamesSet: Set<string> = new Set();
|
||||
|
||||
const replaceVisitor: estraverse.Visitor = {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): any => {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
|
||||
if (NodeGuards.isObjectPatternNode(node)) {
|
||||
this.addIdentifiersToIgnoredIdentifierNamesSet(node.properties, ignoredIdentifierNamesSet);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ export class LabeledStatementTransformer extends AbstractNodeTransformer {
|
||||
*/
|
||||
private replaceLabeledStatementName (labeledStatementNode: ESTree.LabeledStatement, nodeIdentifier: number): void {
|
||||
estraverse.replace(labeledStatementNode, {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): any => {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
|
||||
if (parentNode && NodeGuards.isLabelIdentifierNode(node, parentNode)) {
|
||||
const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
|
||||
.replace(node.name, nodeIdentifier);
|
||||
|
||||
@@ -185,7 +185,7 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
|
||||
const storedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames = new Map();
|
||||
|
||||
estraverse.replace(blockScopeNode, {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): any => {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
|
||||
if (parentNode && !node.obfuscatedNode && NodeGuards.isReplaceableIdentifierNode(node, parentNode)) {
|
||||
const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer.replace(node.name, nodeIdentifier);
|
||||
const newIdentifierName: string = newIdentifier.name;
|
||||
|
||||
+2
-2
@@ -23,9 +23,9 @@ export abstract class AbstractObfuscatingReplacer implements IObfuscatingReplace
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} nodeValue
|
||||
* @param {SimpleLiteral['value']} nodeValue
|
||||
* @param {number} nodeIdentifier
|
||||
* @returns {Node}
|
||||
*/
|
||||
public abstract replace (nodeValue: any, nodeIdentifier?: number): ESTree.Node;
|
||||
public abstract replace (nodeValue: ESTree.SimpleLiteral['value'], nodeIdentifier?: number): ESTree.Node;
|
||||
}
|
||||
|
||||
+17
-19
@@ -136,29 +136,27 @@ export class NodeUtils {
|
||||
|
||||
const copy: TObject = {};
|
||||
|
||||
Object
|
||||
.keys(node)
|
||||
.forEach((property: string): void => {
|
||||
if (property === 'parentNode') {
|
||||
return;
|
||||
}
|
||||
for (const property in node) {
|
||||
if (!node.hasOwnProperty(property) || property === 'parentNode') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const value: any = (<TObject>node)[property];
|
||||
const value: any = node[property];
|
||||
|
||||
let clonedValue: any | null;
|
||||
let clonedValue: any | null;
|
||||
|
||||
if (value === null || value instanceof RegExp) {
|
||||
clonedValue = value;
|
||||
} else if (Array.isArray(value)) {
|
||||
clonedValue = value.map(NodeUtils.cloneRecursive);
|
||||
} else if (typeof value === 'object') {
|
||||
clonedValue = NodeUtils.cloneRecursive(value);
|
||||
} else {
|
||||
clonedValue = value;
|
||||
}
|
||||
if (value === null || value instanceof RegExp) {
|
||||
clonedValue = value;
|
||||
} else if (Array.isArray(value)) {
|
||||
clonedValue = value.map(NodeUtils.cloneRecursive);
|
||||
} else if (typeof value === 'object') {
|
||||
clonedValue = NodeUtils.cloneRecursive(value);
|
||||
} else {
|
||||
clonedValue = value;
|
||||
}
|
||||
|
||||
copy[property] = clonedValue;
|
||||
});
|
||||
copy[property] = clonedValue;
|
||||
}
|
||||
|
||||
return <T>copy;
|
||||
}
|
||||
|
||||
+2
-2
@@ -434,10 +434,10 @@ export class Nodes {
|
||||
|
||||
/**
|
||||
* @param {Identifier} id
|
||||
* @param {any} init
|
||||
* @param {Expression | null} init
|
||||
* @returns {VariableDeclarator}
|
||||
*/
|
||||
public static getVariableDeclaratorNode (id: ESTree.Identifier, init: any): ESTree.VariableDeclarator {
|
||||
public static getVariableDeclaratorNode (id: ESTree.Identifier, init: ESTree.Expression | null): ESTree.VariableDeclarator {
|
||||
return {
|
||||
type: NodeType.VariableDeclarator,
|
||||
id,
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
export type TCLISanitizer = (value: string) => any;
|
||||
export type TCLISanitizer <T> = (value: string) => T;
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { TStringArrayEncoding } from '../../../../src/types/options/TStringArrayEncoding';
|
||||
|
||||
import { StringArrayEncoding } from '../../../../src/enums/StringArrayEncoding';
|
||||
|
||||
import { StringArrayEncodingSanitizer } from '../../../../src/cli/sanitizers/StringArrayEncodingSanitizer';
|
||||
|
||||
describe('StringArrayEncodingSanitizer', () => {
|
||||
describe('StringArrayEncodingSanitizer: TCLISanitizer = (value: string): TStringArrayEncoding', () => {
|
||||
describe('variant #1: string array encoding `base64`', () => {
|
||||
const inputValue: string = 'base64';
|
||||
const expectedValue: boolean = true;
|
||||
const expectedValue: TStringArrayEncoding = true;
|
||||
|
||||
let value: boolean;
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
@@ -21,9 +25,9 @@ describe('StringArrayEncodingSanitizer', () => {
|
||||
|
||||
describe('variant #2: string array encoding `true`', () => {
|
||||
const inputValue: string = 'true';
|
||||
const expectedValue: boolean = true;
|
||||
const expectedValue: TStringArrayEncoding = true;
|
||||
|
||||
let value: boolean;
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
@@ -36,9 +40,9 @@ describe('StringArrayEncodingSanitizer', () => {
|
||||
|
||||
describe('variant #3: string array encoding `1`', () => {
|
||||
const inputValue: string = '1';
|
||||
const expectedValue: boolean = true;
|
||||
const expectedValue: TStringArrayEncoding = true;
|
||||
|
||||
let value: boolean;
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
@@ -51,9 +55,9 @@ describe('StringArrayEncodingSanitizer', () => {
|
||||
|
||||
describe('variant #4: string array encoding `rc4`', () => {
|
||||
const inputValue: string = 'rc4';
|
||||
const expectedValue: string = 'rc4';
|
||||
const expectedValue: TStringArrayEncoding = StringArrayEncoding.Rc4;
|
||||
|
||||
let value: string;
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
@@ -66,9 +70,9 @@ describe('StringArrayEncodingSanitizer', () => {
|
||||
|
||||
describe('variant #5: string array encoding `foo`', () => {
|
||||
const inputValue: string = 'foo';
|
||||
const expectedValue: boolean = false;
|
||||
const expectedValue: TStringArrayEncoding = false;
|
||||
|
||||
let value: boolean;
|
||||
let value: TStringArrayEncoding;
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
|
||||
Reference in New Issue
Block a user