X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"tslint": "5.9.1",
"tslint-eslint-rules": "5.1.0",
"tslint-language-service": "0.9.9",
"tslint-microsoft-contrib": "5.0.3",
"tslint-webpack-plugin": "1.2.2",
"typescript": "2.8.1",
"webpack": "4.4.1",
Expand Down
20 changes: 12 additions & 8 deletions src/cli/JavaScriptObfuscatorCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
private static filterOptions (options: TInputCLIOptions): TInputOptions {
const filteredOptions: TInputOptions = {};

for (const option in options) {
if (!options.hasOwnProperty(option) || options[option] === undefined) {
continue;
}

filteredOptions[option] = options[option];
}
Object
.keys(options)
.forEach((option: keyof TInputCLIOptions) => {
if (options[option] === undefined) {
return;
}

filteredOptions[option] = options[option];
});

return filteredOptions;
}
Expand Down Expand Up @@ -153,7 +155,9 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
const canShowHelp: boolean = !this.arguments.length || this.arguments.includes('--help');

if (canShowHelp) {
return this.commands.outputHelp();
this.commands.outputHelp();

return;
}

const sourceCodeData: TSourceCodeData = new SourceCodeReader(this.inputCLIOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { inject, injectable, } from 'inversify';
import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';

import * as ESTree from 'estree';

// tslint:disable
import { Expression } from 'estree';
// tslint:enable

import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
import { TStatement } from '../../../types/node/TStatement';
Expand Down Expand Up @@ -65,7 +68,7 @@ export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode
public initialize (
controlFlowStorageName: string,
controlFlowStorageKey: string,
callee: Expression,
callee: ESTree.Expression,
expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[]
): void {
this.controlFlowStorageName = controlFlowStorageName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
}
);

break;
}

return decodeStringArrayTemplate;
Expand Down
3 changes: 1 addition & 2 deletions src/declarations/ESTree.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* tslint:disable:interface-name */

import * as escodegen from 'escodegen-wallaby';
import * as ESTree from 'estree';

declare module 'estree' {
export interface BaseNodeMetadata {
Expand All @@ -18,7 +17,7 @@ declare module 'estree' {

interface BaseNode {
metadata?: BaseNodeMetadata;
parentNode?: ESTree.Node;
parentNode?: Node;
}

interface Identifier extends BaseNode {
Expand Down
5 changes: 2 additions & 3 deletions src/declarations/escodegen.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/* tslint:disable:interface-name */

import * as escodegen from 'escodegen';
import * as ESTree from 'estree';

import { IGeneratorOutput } from '../interfaces/IGeneratorOutput';

declare module 'escodegen' {
export interface XVerbatimProperty {
content?: string;
precedence: escodegen.Precedence;
precedence: Precedence;
}

/**
* @param ast
* @param options
* @returns IGeneratorOutput
*/
export function generate (ast: ESTree.Node, options?: escodegen.GenerateOptions): IGeneratorOutput;
export function generate (ast: ESTree.Node, options?: GenerateOptions): IGeneratorOutput;
}
2 changes: 1 addition & 1 deletion src/logger/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Logger implements ILogger {
): void {
const processedMessage: string = loggingLevelColor(`\n${loggingPrefix} ${loggingMessage}`);

!value ? console.log(processedMessage) : console.log(processedMessage, value);
console.log(processedMessage, value || '');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer {
);

nodes.forEach((node: ESTree.Literal | ESTree.Expression) => {
root = NodeFactory.binaryExpressionNode('+', root, <ESTree.Literal | ESTree.Expression>node);
root = NodeFactory.binaryExpressionNode('+', root, node);
});

return root;
Expand Down
2 changes: 1 addition & 1 deletion src/node/NodeAppender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class NodeAppender {
const firstCall: IStackTraceData = blockScopeTraceData[index];

if (deep <= 0) {
throw new Error(`Invalid \`deep\` argument value. Value should be bigger then 0.`);
throw new Error('Invalid `deep` argument value. Value should be bigger then 0.');
}

if (deep > 1 && firstCall.stackTrace.length) {
Expand Down
44 changes: 23 additions & 21 deletions src/node/NodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,29 @@ export class NodeUtils {

const copy: TObject = {};

for (const property in node) {
if (!node.hasOwnProperty(property) || property === 'parentNode') {
continue;
}

const value: T[keyof T] = node[property];

let clonedValue: T[keyof T] | T[keyof T][] | 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;
}

copy[property] = clonedValue;
}
Object
.keys(node)
.forEach((property: string) => {
if (property === 'parentNode') {
return;
}

const value: T[keyof T] = node[<keyof T>property];

let clonedValue: T[keyof T] | T[keyof T][] | 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;
}

copy[property] = clonedValue;
});

return <T>copy;
}
Expand Down
12 changes: 5 additions & 7 deletions src/options/ValidationErrorsFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ export class ValidationErrorsFormatter {

let errorString: string = `\`${validationError.property}\` errors:\n`;

for (const constraint in constraints) {
if (!constraints.hasOwnProperty(constraint)) {
continue;
}

errorString += ` - ${constraints[constraint]}\n`;
}
Object
.keys(constraints)
.forEach((constraint: string) => {
errorString += ` - ${constraints[constraint]}\n`;
});

return errorString;
}
Expand Down
2 changes: 0 additions & 2 deletions src/source-map/SourceMapCorrector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ export class SourceMapCorrector implements ISourceMapCorrector {
}

sourceMappingUrl += sourceMapUrl;

break;
}

return `${obfuscatedCode}\n${sourceMappingUrl}`;
Expand Down
7 changes: 5 additions & 2 deletions src/utils/ArrayUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ export class ArrayUtils implements IArrayUtils {
let temp: T | undefined;

while (times--) {
temp = newArray.pop()!;
newArray.unshift(temp);
temp = newArray.pop();

if (temp) {
newArray.unshift(temp);
}
}

return newArray;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/CryptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class CryptUtils implements ICryptUtils {
this.randomGenerator = randomGenerator;
}

/* tslint:disable */
// tslint:disable
/**
* @param {string} string
* @returns {string}
Expand Down Expand Up @@ -53,7 +53,7 @@ export class CryptUtils implements ICryptUtils {

return output;
}
/* tslint:enable */
// tslint:enable

/**
* @param {string} str
Expand Down Expand Up @@ -97,7 +97,7 @@ export class CryptUtils implements ICryptUtils {
return [randomMerge(str, randomStringDiff), randomStringDiff];
}

/* tslint:disable */
// tslint:disable
/**
* RC4 symmetric cipher encryption/decryption
* https://gist.github.com/farhadi/2185197
Expand Down Expand Up @@ -137,5 +137,5 @@ export class CryptUtils implements ICryptUtils {

return result;
}
/* tslint:enable */
// tslint:enable
}
33 changes: 32 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": [
"tslint-eslint-rules"
"tslint-eslint-rules",
"tslint-microsoft-contrib"
],
"rules": {
"adjacent-overload-signatures": true,
Expand Down Expand Up @@ -29,33 +30,49 @@
"check-space",
"check-lowercase"
],
"completed-docs": false,
"curly": true,
"cyclomatic-complexity": [true, 10],
"eofline": true,
"export-name": false,
"forin": true,
"function-name": [true, {
"method-regex": "^[a-z][\\w\\d]+$",
"private-method-regex": "^[a-z][\\w\\d]+$",
"protected-method-regex": "^[a-z][\\w\\d]+$",
"static-method-regex": "^[a-z][\\w\\d]+$",
"function-regex": "^[a-zA-Z][\\w\\d]+$"
}],
"indent": [
true,
"spaces"
],
"insecure-random": false,
"interface-name": [
true,
"always-prefix"
],
"interface-over-type-literal": true,
"import-name": false,
"import-spacing": true,
"jsdoc-format": true,
"label-position": true,
"max-classes-per-file": [true, 1],
"max-func-body-length": [true, 200],
"max-line-length": false,
"member-access": [true],
"member-ordering": [
true,
{ "order": "fields-first" }
],
"missing-jsdoc": false,
"newline-before-return": true,
"new-parens": true,
"newline-per-chained-call": false,
"no-angle-bracket-type-assertion": false,
"no-any": false,
"no-arg": true,
"no-banned-terms": false,
"no-bitwise": true,
"no-conditional-assignment": true,
"no-consecutive-blank-lines": true,
Expand All @@ -80,18 +97,22 @@
"no-empty": false,
"no-empty-character-class": true,
"no-empty-interface": true,
"no-empty-line-after-opening-brace": true,
"no-eval": false,
"no-ex-assign": true,
"no-extra-boolean-cast": true,
"no-extra-semi": true,
"no-import-side-effect": false,
"no-inferrable-types": false,
"no-inner-declarations": [true, "both"],
"no-implicit-dependencies": false,
"no-increment-decrement": false,
"no-internal-module": true,
"no-invalid-regexp": true,
"no-invalid-this": true,
"no-misused-new": true,
"no-multi-spaces": [true],
"no-multiline-string": false,
"no-namespace": true,
"no-null-keyword": false,
"no-parameter-properties": true,
Expand All @@ -100,22 +121,30 @@
"no-reference": true,
"no-reference-import": true,
"no-regex-spaces": true,
"no-relative-imports": false,
"no-require-imports": true,
"no-reserved-keywords": false,
"no-shadowed-variable": true,
"no-string-literal": true,
"no-string-throw": true,
"no-submodule-imports": true,
"no-switch-case-fall-through": false,
"no-trailing-whitespace": [true, "ignore-blank-lines"],
"no-typeof-undefined": true,
"no-unnecessary-callback-wrapper": true,
"no-unnecessary-class": [true, "allow-static-only"],
"no-unnecessary-initializer": true,
"no-unnecessary-field-initialization": true,
"no-unnecessary-local-variable": true,
"no-unexpected-multiline": true,
"no-unsafe-any": false,
"no-unsafe-finally": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-useless-files": true,
"no-var-keyword": true,
"no-var-requires": true,
"non-literal-require": false,
"max-file-line-count": [true, 500],
"object-curly-spacing": [true, "always"],
"object-literal-sort-keys": false,
Expand All @@ -138,6 +167,7 @@
}
],
"prefer-const": true,
"prefer-object-spread": false,
"prefer-method-signature": true,
"prefer-readonly": true,
"prefer-template": true,
Expand All @@ -146,6 +176,7 @@
"semicolon": [true, "always"],
"space-before-function-paren": true,
"space-in-parens": [true, "never"],
"strict-boolean-expressions": false,
"switch-default": false,
"ter-arrow-parens": true,
"ter-func-call-spacing": [true, "never"],
Expand Down
Loading
X Tutup