mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
TS 2.0 Strict Null Checks refactoring
This commit is contained in:
+2
-1
@@ -60,7 +60,8 @@ let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`,
|
||||
{
|
||||
disableConsoleOutput: false,
|
||||
encodeUnicodeLiterals: true
|
||||
encodeUnicodeLiterals: true,
|
||||
unicodeArrayThreshold: 0
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { NO_CUSTOM_NODES_PRESET } from "../../src/preset-options/NoCustomNodesPr
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
describe('JavaScriptObfuscator', () => {
|
||||
describe('obfuscate (sourceCode: string, customOptions?: IOptionsPreset): IObfuscationResult', () => {
|
||||
describe('obfuscate (sourceCode: string, customOptions?: IObfuscatorOptions): IObfuscationResult', () => {
|
||||
describe('if `sourceMap` option is `false`', () => {
|
||||
it('should returns object with obfuscated code and empty source map', () => {
|
||||
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
|
||||
@@ -59,12 +59,6 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
it('should does not change `BlockStatement` node body if given node is not a valid Node', () => {
|
||||
assert.doesNotChange(
|
||||
() => NodeUtils.appendNode(blockStatementNode.body, <INode>null),
|
||||
blockStatementNode,
|
||||
'body'
|
||||
);
|
||||
|
||||
assert.doesNotChange(
|
||||
() => NodeUtils.appendNode(blockStatementNode.body, <INode>{}),
|
||||
blockStatementNode,
|
||||
@@ -234,12 +228,6 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
it('should does not change `BlockStatement` node body if given node is not a valid Node', () => {
|
||||
assert.doesNotChange(
|
||||
() => NodeUtils.insertNodeAtIndex(blockStatementNode.body, <INode>null, 1),
|
||||
blockStatementNode,
|
||||
'body'
|
||||
);
|
||||
|
||||
assert.doesNotChange(
|
||||
() => NodeUtils.insertNodeAtIndex(blockStatementNode.body, <INode>{}, 1),
|
||||
blockStatementNode,
|
||||
@@ -323,12 +311,6 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
it('should does not change `BlockStatement` node body if given node is not a valid Node', () => {
|
||||
assert.doesNotChange(
|
||||
() => NodeUtils.prependNode(blockStatementNode.body, <INode>null),
|
||||
blockStatementNode,
|
||||
'body'
|
||||
);
|
||||
|
||||
assert.doesNotChange(
|
||||
() => NodeUtils.prependNode(blockStatementNode.body, <INode>{}),
|
||||
blockStatementNode,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IOptionsPreset } from "../../src/interfaces/IOptionsPreset";
|
||||
import { IObfuscatorOptions } from "../../src/interfaces/IObfuscatorOptions";
|
||||
|
||||
import { OptionsNormalizer } from '../../src/OptionsNormalizer';
|
||||
|
||||
@@ -7,9 +7,9 @@ import { DEFAULT_PRESET } from '../../src/preset-options/DefaultPreset';
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
describe('OptionsNormalizer', () => {
|
||||
describe('normalizeOptionsPreset (options: IOptionsPreset): IOptionsPreset', () => {
|
||||
let optionsPreset1: IOptionsPreset,
|
||||
optionsPreset2: IOptionsPreset;
|
||||
describe('normalizeOptionsPreset (options: IObfuscatorOptions): IObfuscatorOptions', () => {
|
||||
let optionsPreset1: IObfuscatorOptions,
|
||||
optionsPreset2: IObfuscatorOptions;
|
||||
|
||||
beforeEach(() => {
|
||||
optionsPreset1 = Object.assign({}, DEFAULT_PRESET, {
|
||||
|
||||
@@ -13,7 +13,7 @@ describe('Utils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('arrayRotate <T> (array: T[], times: number, reverse: boolean = false): T[]', () => {
|
||||
describe('arrayRotate <T> (array: T[], times: number): T[]', () => {
|
||||
let array: number[];
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -24,13 +24,14 @@ describe('Utils', () => {
|
||||
assert.deepEqual(Utils.arrayRotate(array, 2), [5, 6, 1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
it('should rotate (shift) array by a given value in reverse directions', () => {
|
||||
assert.deepEqual(Utils.arrayRotate(array, 2, true), [3, 4, 5, 6, 1, 2]);
|
||||
});
|
||||
|
||||
it('should do nothing if value <= 0', () => {
|
||||
assert.deepEqual(Utils.arrayRotate(array, 0, true), [1, 2, 3, 4, 5, 6]);
|
||||
assert.deepEqual(Utils.arrayRotate(array, -1, true), [1, 2, 3, 4, 5, 6]);
|
||||
assert.deepEqual(Utils.arrayRotate(array, 0), [1, 2, 3, 4, 5, 6]);
|
||||
assert.deepEqual(Utils.arrayRotate(array, -1), [1, 2, 3, 4, 5, 6]);
|
||||
});
|
||||
|
||||
it('should throw exception if array is empty', () => {
|
||||
assert.throws(() => Utils.arrayRotate([], 5), ReferenceError);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ICatchClauseNode } from "../../../src/interfaces/nodes/ICatchClauseNode";
|
||||
import { ICustomNode } from "../../../src/interfaces/ICustomNode";
|
||||
import { ICustomNode } from "../../../src/interfaces/custom-nodes/ICustomNode";
|
||||
import { IExpressionStatementNode } from "../../../src/interfaces/nodes/IExpressionStatementNode";
|
||||
|
||||
import { DEFAULT_PRESET } from "../../../src/preset-options/DefaultPreset";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IBlockStatementNode } from "../../../src/interfaces/nodes/IBlockStatementNode";
|
||||
import { ICustomNode } from "../../../src/interfaces/ICustomNode";
|
||||
import { ICustomNode } from "../../../src/interfaces/custom-nodes/ICustomNode";
|
||||
import { IExpressionStatementNode } from "../../../src/interfaces/nodes/IExpressionStatementNode";
|
||||
import { IFunctionDeclarationNode } from "../../../src/interfaces/nodes/IFunctionDeclarationNode";
|
||||
import { IProgramNode } from "../../../src/interfaces/nodes/IProgramNode";
|
||||
@@ -63,7 +63,7 @@ describe('FunctionDeclarationObfuscator', () => {
|
||||
|
||||
functionDeclarationObfuscator.obfuscateNode(
|
||||
functionDeclarationNode,
|
||||
functionDeclarationNode['parentNode']
|
||||
blockStatementNode
|
||||
);
|
||||
});
|
||||
|
||||
@@ -87,7 +87,7 @@ describe('FunctionDeclarationObfuscator', () => {
|
||||
|
||||
functionDeclarationObfuscator.obfuscateNode(
|
||||
functionDeclarationNode,
|
||||
functionDeclarationNode['parentNode']
|
||||
programNode
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IBlockStatementNode } from "../../../src/interfaces/nodes/IBlockStatementNode";
|
||||
import { ICustomNode } from "../../../src/interfaces/ICustomNode";
|
||||
import { ICustomNode } from "../../../src/interfaces/custom-nodes/ICustomNode";
|
||||
import { IExpressionStatementNode } from "../../../src/interfaces/nodes/IExpressionStatementNode";
|
||||
import { IFunctionDeclarationNode } from "../../../src/interfaces/nodes/IFunctionDeclarationNode";
|
||||
import { IIdentifierNode } from "../../../src/interfaces/nodes/IIdentifierNode";
|
||||
|
||||
Reference in New Issue
Block a user