Eval obfuscation transformers

This commit is contained in:
sanex3339
2018-01-08 20:34:36 +03:00
112 changed files with 2202 additions and 10096 deletions
+6 -3
View File
@@ -1,5 +1,5 @@
'use strict';
import { NO_CUSTOM_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
(function () {
const JavaScriptObfuscator: any = require('../../index');
@@ -8,15 +8,18 @@ import { NO_CUSTOM_NODES_PRESET } from '../../src/options/presets/NoCustomNodes'
`
(function(){
function foo (bar) {
eval('console.log(bar);');
eval('console.log(bar, \\'baz\\');');
console.log(eval('bar; console.log(\\'bark\\')'));
}
foo(1);
})();
`,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
compact: false,
stringArray: true,
stringArrayThreshold: 1
}
).getObfuscatedCode();
@@ -7,7 +7,7 @@ import * as ESTree from 'estree';
import { assert } from 'chai';
import { TNodeWithBlockStatement } from '../../../../src/types/node/TNodeWithBlockStatement';
import { TNodeWithBlockScope } from '../../../../src/types/node/TNodeWithBlockScope';
import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade';
import { IStackTraceAnalyzer } from '../../../../src/interfaces/analyzers/stack-trace-analyzer/IStackTraceAnalyzer';
@@ -165,7 +165,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #1: basic-1', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/basic-1.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -215,7 +215,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #2: basic-2', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/basic-2.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -254,7 +254,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #3: deep conditions nesting', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/deep-conditions-nesting.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -293,7 +293,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #4: call before declaration', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/call-before-declaration.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -316,7 +316,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #5: call expression of object member #1', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/call-expression-of-object-member-1.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -375,7 +375,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #5: call expression of object member #2', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/call-expression-of-object-member-2.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -403,7 +403,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #6: no call expressions', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/no-call-expressions.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -420,7 +420,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #7: only call expression', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/only-call-expression.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -437,7 +437,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #8: self-invoking functions', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/self-invoking-functions.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -472,7 +472,7 @@ describe('StackTraceAnalyzer', () => {
describe('variant #9: no recursion', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/no-recursion.js');
const astTree: TNodeWithBlockStatement = Nodes.getProgramNode(
const astTree: TNodeWithBlockScope = Nodes.getProgramNode(
NodeUtils.convertCodeToStructure(code)
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../helpers/readFileAsString';
@@ -21,7 +21,7 @@ describe('ConsoleOutputDisableExpressionNode', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
disableConsoleOutput: true
}
);
@@ -50,7 +50,7 @@ describe('ConsoleOutputDisableExpressionNode', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
disableConsoleOutput: false
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../helpers/readFileAsString';
@@ -19,7 +19,7 @@ describe('DomainLockNode', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
domainLock: ['.example.com']
}
);
@@ -40,7 +40,7 @@ describe('DomainLockNode', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
domainLock: []
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../helpers/readFileAsString';
@@ -20,7 +20,7 @@ describe('StringArrayCallsWrapper', () => {
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -43,7 +43,7 @@ describe('StringArrayCallsWrapper', () => {
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: false
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../helpers/readFileAsString';
@@ -20,7 +20,7 @@ describe('StringArrayNode', () => {
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -43,7 +43,7 @@ describe('StringArrayNode', () => {
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: false
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../helpers/readFileAsString';
@@ -20,7 +20,7 @@ describe('StringArrayRotateFunctionNode', () => {
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
rotateStringArray: true,
stringArray: true,
stringArrayThreshold: 1
@@ -44,7 +44,7 @@ describe('StringArrayRotateFunctionNode', () => {
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
rotateStringArray: false,
stringArray: true,
stringArrayThreshold: 1
@@ -7,7 +7,7 @@ import { StringArrayEncoding } from '../../../src/enums/StringArrayEncoding';
import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade';
import { NO_CUSTOM_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes';
import { IdentifierNamesGenerator } from '../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
@@ -26,7 +26,7 @@ describe('JavaScriptObfuscator', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -91,7 +91,7 @@ describe('JavaScriptObfuscator', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
sourceMap: true
}
);
@@ -120,7 +120,7 @@ describe('JavaScriptObfuscator', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
sourceMap: true,
sourceMapMode: SourceMapMode.Inline
}
@@ -195,7 +195,7 @@ describe('JavaScriptObfuscator', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -217,7 +217,7 @@ describe('JavaScriptObfuscator', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -240,7 +240,7 @@ describe('JavaScriptObfuscator', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -269,7 +269,7 @@ describe('JavaScriptObfuscator', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -438,7 +438,7 @@ describe('JavaScriptObfuscator', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -494,6 +494,7 @@ describe('JavaScriptObfuscator', () => {
stringArray: true,
stringArrayEncoding: StringArrayEncoding.Rc4,
stringArrayThreshold: 1,
transformObjectKeys: true,
unicodeEscapeSequence: false
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -29,13 +29,14 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
console.log(obfuscatedCode);
});
describe('`console.log` statements', ()=> {
@@ -117,7 +118,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
unicodeEscapeSequence: false
@@ -208,7 +209,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -232,7 +233,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -256,7 +257,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -280,7 +281,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -304,7 +305,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -331,7 +332,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -360,7 +361,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -384,7 +385,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -411,7 +412,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -440,7 +441,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -471,7 +472,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code.repeat(samples),
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: controlFlowFlatteningThreshold,
}
@@ -513,7 +514,7 @@ describe('BlockStatementControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../../helpers/readFileAsString';
@@ -22,7 +22,7 @@ describe('BinaryExpressionControlFlowReplacer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -64,7 +64,7 @@ describe('BinaryExpressionControlFlowReplacer', function () {
obfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../../helpers/readFileAsString';
@@ -22,7 +22,7 @@ describe('CallExpressionControlFlowReplacer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -64,7 +64,7 @@ describe('CallExpressionControlFlowReplacer', function () {
obfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -111,7 +111,7 @@ describe('CallExpressionControlFlowReplacer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../../helpers/readFileAsString';
@@ -22,7 +22,7 @@ describe('LogicalExpressionControlFlowReplacer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -64,7 +64,7 @@ describe('LogicalExpressionControlFlowReplacer', function () {
obfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -111,7 +111,7 @@ describe('LogicalExpressionControlFlowReplacer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -135,7 +135,7 @@ describe('LogicalExpressionControlFlowReplacer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: .1
}
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../../helpers/readFileAsString';
@@ -20,7 +20,7 @@ describe('StringLiteralControlFlowReplacer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -38,7 +38,7 @@ describe('FunctionControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -80,7 +80,7 @@ describe('FunctionControlFlowTransformer', function () {
obfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -123,7 +123,7 @@ describe('FunctionControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -147,7 +147,7 @@ describe('FunctionControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -182,7 +182,7 @@ describe('FunctionControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -211,7 +211,7 @@ describe('FunctionControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0
}
@@ -240,7 +240,7 @@ describe('FunctionControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -264,7 +264,7 @@ describe('FunctionControlFlowTransformer', function () {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -20,7 +20,7 @@ describe('MemberExpressionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -43,7 +43,7 @@ describe('MemberExpressionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -74,7 +74,7 @@ describe('MemberExpressionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -102,7 +102,7 @@ describe('MemberExpressionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -19,7 +19,7 @@ describe('MethodDefinitionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -42,7 +42,7 @@ describe('MethodDefinitionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -70,7 +70,7 @@ describe('MethodDefinitionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -0,0 +1,319 @@
import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../helpers/readFileAsString';
import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
describe('ObjectExpressionKeysTransformer', () => {
const variableMatch: string = '_0x([a-f0-9]){4,6}';
describe('transformation of object keys', () => {
describe('variant #1: simple', () => {
const match: string = `` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['foo'] *= *'bar';` +
`${variableMatch}\\['baz'] *= *'bark';` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/simple.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should correctly transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('variant #2: nested objects #1', () => {
const match: string = `` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['foo'] *= *'bar';` +
`${variableMatch}\\['inner'] *= *{};` +
`${variableMatch}\\['inner']\\['inner1'] *= *{};` +
`${variableMatch}\\['inner']\\['inner1']\\['baz'] *= *'bark';` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/nested-objects-1.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should correctly transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('variant #3: nested objects #2', () => {
const match: string = `` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['foo'] *= *'bar';` +
`${variableMatch}\\['inner'] *= *{};` +
`${variableMatch}\\['ball'] *= *'door';` +
`${variableMatch}\\['inner']\\['baz'] *= *'bark';` +
`${variableMatch}\\['inner']\\['inner1'] *= *{};` +
`${variableMatch}\\['inner']\\['cow'] *= *'bear';` +
`${variableMatch}\\['inner']\\['inner1']\\['hawk'] *= *'geek';` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/nested-objects-2.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should correctly transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('variant #4: correct integration with control flow flattening object', () => {
const match: string = `` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['\\w{5}'] *= *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *{` +
`return *${variableMatch} *\\+ *${variableMatch};` +
`};` +
`var *${variableMatch} *= *${variableMatch}\\['\\w{5}']\\(0x1, *0x2\\);` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/integration-with-control-flow-flattening.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should correctly transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
describe('correct placement of expression statements', () => {
describe('variant #1: if statement', () => {
const match: string = `` +
`if *\\(!!\\[]\\) *{` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['foo'] *= *'bar';` +
`}` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-if-statement.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should correctly transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('variant #2: try statement', () => {
const match: string = `` +
`try *{` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['foo'] *= *'bar';` +
`} *catch *\\(${variableMatch}\\) *{` +
`}` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-try-statement.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should correctly transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('variant #3: catch clause statement', () => {
const match: string = `` +
`try *{` +
`} *catch *\\(${variableMatch}\\) *{` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['foo'] *= *'bar';` +
`}` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-catch-clause.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should correctly transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('variant #4: switch catch statement', () => {
const match: string = `` +
`switch *\\(!!\\[]\\) *{` +
`case *!!\\[]:` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['foo'] *= *'bar';` +
`}` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-switch-case.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
describe('Ignore transformation', () => {
describe('variant #1: disabled option', () => {
const match: string = `` +
`var *${variableMatch} *= *{` +
`'foo': *'bar',` +
`'baz': *'bark'` +
`}` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/simple.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('shouldn\'t transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('variant #2: variable declaration without initialization', () => {
const match: string = `` +
`var *${variableMatch};` +
`${variableMatch} *= *{` +
`'foo': *'bar',` +
`'baz': *'bark'` +
`}` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/variable-declaration-without-initialization.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('shouldn\'t transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
});
@@ -0,0 +1,10 @@
(function(){
var object = {
foo: 'bar',
inner: {
inner1: {
baz: 'bark'
}
}
};
})();
@@ -0,0 +1,14 @@
(function(){
var object = {
foo: 'bar',
inner: {
baz: 'bark',
inner1: {
hawk: 'geek'
},
cow: 'bear',
},
ball: 'door',
};
})();
@@ -0,0 +1,8 @@
(function(){
try {
} catch (e) {
var object = {
foo: 'bar'
};
}
})();
@@ -0,0 +1,7 @@
(function(){
if (true) {
var object = {
foo: 'bar'
};
}
})();
@@ -0,0 +1,8 @@
(function(){
switch (true) {
case true:
var object = {
foo: 'bar'
};
}
})();
@@ -0,0 +1,7 @@
(function(){
try {
var object = {
foo: 'bar'
};
} catch (e) {}
})();
@@ -0,0 +1,6 @@
(function(){
var object = {
foo: 'bar',
baz: 'bark'
};
})();
@@ -0,0 +1,7 @@
(function(){
var object;
object = {
foo: 'bar',
baz: 'bark'
};
})();
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -15,7 +15,7 @@ describe('TemplateLiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
unicodeEscapeSequence: false
}
);
@@ -30,7 +30,7 @@ describe('TemplateLiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
unicodeEscapeSequence: false
}
);
@@ -45,7 +45,7 @@ describe('TemplateLiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
unicodeEscapeSequence: false
}
);
@@ -60,7 +60,7 @@ describe('TemplateLiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
unicodeEscapeSequence: false
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../helpers/readFileAsString';
@@ -33,7 +33,7 @@ describe('DeadCodeInjectionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
stringArray: true,
@@ -69,7 +69,7 @@ describe('DeadCodeInjectionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
stringArray: true,
@@ -105,7 +105,7 @@ describe('DeadCodeInjectionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0,
stringArray: true,
@@ -149,7 +149,7 @@ describe('DeadCodeInjectionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
stringArray: true,
@@ -200,7 +200,7 @@ describe('DeadCodeInjectionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
stringArray: true,
@@ -251,7 +251,7 @@ describe('DeadCodeInjectionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
stringArray: true,
@@ -339,7 +339,7 @@ describe('DeadCodeInjectionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
stringArray: true,
@@ -396,7 +396,7 @@ describe('DeadCodeInjectionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1,
deadCodeInjection: true,
@@ -422,7 +422,7 @@ describe('DeadCodeInjectionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
debugProtection: true
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -24,7 +24,7 @@ describe('CatchClauseTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -55,7 +55,7 @@ describe('CatchClauseTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -24,7 +24,7 @@ describe('ClassDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -50,7 +50,7 @@ describe('ClassDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -77,7 +77,7 @@ describe('ClassDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
renameGlobals: true
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -24,7 +24,7 @@ describe('FunctionDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -50,7 +50,7 @@ describe('FunctionDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -77,7 +77,7 @@ describe('FunctionDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
renameGlobals: true
}
);
@@ -108,7 +108,7 @@ describe('FunctionDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -135,7 +135,7 @@ describe('FunctionDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -24,7 +24,7 @@ describe('FunctionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -60,7 +60,7 @@ describe('FunctionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -87,7 +87,7 @@ describe('FunctionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -116,7 +116,7 @@ describe('FunctionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -148,7 +148,7 @@ describe('FunctionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -198,7 +198,7 @@ describe('FunctionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -265,7 +265,7 @@ describe('FunctionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -25,7 +25,7 @@ describe('LabeledStatementTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -5,7 +5,7 @@ import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationRe
import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
import { StringArrayEncoding } from '../../../../../src/enums/StringArrayEncoding';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -24,7 +24,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -52,7 +52,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -73,7 +73,7 @@ describe('LiteralTransformer', () => {
testFunc = () => JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -96,7 +96,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -124,7 +124,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
unicodeEscapeSequence: true
}
@@ -149,7 +149,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1,
unicodeEscapeSequence: true
@@ -178,7 +178,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -203,7 +203,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayEncoding: StringArrayEncoding.Base64,
stringArrayThreshold: 1
@@ -232,7 +232,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayEncoding: StringArrayEncoding.Rc4,
stringArrayThreshold: 1
@@ -263,7 +263,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
`${code}\n`.repeat(samples),
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: stringArrayThreshold
}
@@ -301,7 +301,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1,
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator
@@ -327,7 +327,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -351,7 +351,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -375,7 +375,7 @@ describe('LiteralTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -19,7 +19,7 @@ describe('ObjectExpressionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -41,7 +41,7 @@ describe('ObjectExpressionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -63,7 +63,7 @@ describe('ObjectExpressionTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -21,7 +21,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -49,7 +49,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -76,7 +76,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
renameGlobals: true
}
);
@@ -104,7 +104,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -126,7 +126,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -149,7 +149,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -183,7 +183,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
@@ -238,7 +238,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
@@ -286,7 +286,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -308,7 +308,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -332,7 +332,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -363,7 +363,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -402,7 +402,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -424,7 +424,7 @@ describe('VariableDeclarationTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -2,7 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../helpers/readFileAsString';
@@ -19,7 +19,7 @@ describe('CommentsTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -41,7 +41,7 @@ describe('CommentsTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -63,7 +63,7 @@ describe('CommentsTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -92,7 +92,7 @@ describe('CommentsTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -112,7 +112,7 @@ describe('CommentsTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -134,7 +134,7 @@ describe('CommentsTransformer', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -4,7 +4,7 @@ import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscatio
import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../../helpers/readFileAsString';
@@ -22,7 +22,7 @@ describe('BlackListObfuscatingGuard', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
@@ -4,7 +4,7 @@ import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscatio
import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../../helpers/readFileAsString';
@@ -22,7 +22,7 @@ describe('ConditionalCommentObfuscatingGuard', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -54,7 +54,7 @@ describe('ConditionalCommentObfuscatingGuard', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -85,7 +85,7 @@ describe('ConditionalCommentObfuscatingGuard', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
...NO_ADDITIONAL_NODES_PRESET
}
);
@@ -123,7 +123,7 @@ describe('ConditionalCommentObfuscatingGuard', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1
}
@@ -183,7 +183,7 @@ describe('ConditionalCommentObfuscatingGuard', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
@@ -5,7 +5,7 @@ import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationRe
import { readFileAsString } from '../../../../helpers/readFileAsString';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
@@ -40,7 +40,7 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
debugProtection: true
}
);
@@ -75,7 +75,7 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
debugProtection: true,
mangle: true
}
@@ -111,7 +111,7 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
debugProtection: true
}
);
@@ -147,7 +147,7 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
debugProtection: true
}
);
+2
View File
@@ -20,6 +20,7 @@ import './unit-tests/generators/identifier-names-generators/MangledlIdentifierNa
import './unit-tests/javascript-obfuscator/JavaScriptObfuscator.spec';
import './unit-tests/logger/Logger.spec';
import './unit-tests/node/node-appender/NodeAppender.spec';
import './unit-tests/node/node-guards/NodeGuards.spec';
import './unit-tests/node/node-utils/NodeUtils.spec';
import './unit-tests/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.spec';
import './unit-tests/obfuscation-result/ObfuscationResult.spec';
@@ -52,6 +53,7 @@ import './functional-tests/node-transformers/control-flow-transformers/control-f
import './functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/string-litertal-control-flow-replacer/StringLiteralControlFlowReplacer.spec';
import './functional-tests/node-transformers/converting-transformers/member-expression-transformer/MemberExpressionTransformer.spec';
import './functional-tests/node-transformers/converting-transformers/method-definition-transformer/MethodDefinitionTransformer.spec';
import './functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec';
import './functional-tests/node-transformers/converting-transformers/template-literal-transformer/TemplateLiteralTransformer.spec';
import './functional-tests/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.spec';
import './functional-tests/node-transformers/obfuscating-transformers/catch-clause-transformer/CatchClauseTransformer.spec';
@@ -22,7 +22,8 @@ describe('JavaScriptObfuscator runtime eval', function () {
deadCodeInjection: true,
debugProtection: true,
selfDefending: true,
stringArrayEncoding: StringArrayEncoding.Rc4
stringArrayEncoding: StringArrayEncoding.Rc4,
transformObjectKeys: true
}
);
@@ -6,7 +6,7 @@ import { IInversifyContainerFacade } from '../../../src/interfaces/container/IIn
import { IJavaScriptObfuscator } from '../../../src/interfaces/IJavaScriptObfsucator';
import { IObfuscationResult } from '../../../src/interfaces/IObfuscationResult';
import { NO_CUSTOM_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes';
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
@@ -30,7 +30,7 @@ describe('JavaScriptObfuscator', () => {
inversifyContainerFacade.load(
'',
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
sourceMap: true,
sourceMapFileName: sourceMapUrl
}
@@ -66,7 +66,7 @@ describe('JavaScriptObfuscator', () => {
inversifyContainerFacade.load(
'',
{
...NO_CUSTOM_NODES_PRESET,
...NO_ADDITIONAL_NODES_PRESET,
sourceMap: true,
sourceMapBaseUrl: sourceMapBaseUrl,
sourceMapFileName: sourceMapUrl
@@ -1,3 +1,5 @@
import 'reflect-metadata';
import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers';
import * as ESTree from 'estree';
@@ -36,7 +38,7 @@ const convertCodeToAst: (fixturePath: string) => ESTree.Program = (fixturePath)
};
describe('NodeAppender', () => {
describe('appendNode (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[]): void', () => {
describe('appendNode (blockScopeNode: TNodeWithBlockScope[], nodeBodyStatements: TStatement[]): void', () => {
let astTree: ESTree.Program,
expectedAstTree: ESTree.Program,
node: TStatement[];
@@ -57,7 +59,7 @@ describe('NodeAppender', () => {
});
});
describe('appendNodeToOptimalBlockScope (blockScopeStackTraceData: IStackTraceData[], blockScopeNode: TNodeWithBlockStatement, nodeBodyStatements: TStatement[], index: number = 0): void', () => {
describe('appendNodeToOptimalBlockScope (blockScopeStackTraceData: IStackTraceData[], blockScopeNode: TNodeWithBlockScope, nodeBodyStatements: TStatement[], index: number = 0): void', () => {
let stackTraceAnalyzer: IStackTraceAnalyzer,
astTree: ESTree.Program,
expectedAstTree: ESTree.Program,
@@ -162,7 +164,30 @@ describe('NodeAppender', () => {
});
});
describe('insertNodeAtIndex (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[], index: number): void', () => {
describe('insertNodeAfter (scopeNode: TNodeWithScope, scopeStatements: TStatement[], targetStatement: ESTree.Statement): void', () => {
let astTree: ESTree.Program,
expectedAstTree: ESTree.Program,
node: TStatement[],
targetStatement: ESTree.Statement;
before(() => {
node = convertCodeToStructure('/fixtures/simple-input.js');
astTree = convertCodeToAst('/fixtures/insert-node-after.js');
expectedAstTree = convertCodeToAst('/fixtures/insert-node-after-expected.js');
targetStatement = <ESTree.Statement>astTree.body[1];
astTree = NodeUtils.parentize(astTree);
expectedAstTree = NodeUtils.parentize(expectedAstTree);
NodeAppender.insertNodeAfter(astTree, node, targetStatement);
});
it('should insert given node in `BlockStatement` node body after target statement', () => {
assert.deepEqual(astTree, expectedAstTree);
});
});
describe('insertNodeAtIndex (blockScopeNode: TNodeWithBlockScope[], nodeBodyStatements: TStatement[], index: number): void', () => {
let astTree: ESTree.Program,
expectedAstTree: ESTree.Program,
node: TStatement[];
@@ -183,7 +208,7 @@ describe('NodeAppender', () => {
});
});
describe('prependNode (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[]): void', () => {
describe('prependNode (blockScopeNode: TNodeWithBlockScope[], nodeBodyStatements: TStatement[]): void', () => {
let astTree: ESTree.Program,
expectedAstTree: ESTree.Program,
node: TStatement[];
@@ -0,0 +1,13 @@
var func1 = function () {
return true;
};
var func2 = function () {
return false;
};
var test = 1;
var func3 = function () {
return 'string';
};
@@ -0,0 +1,11 @@
var func1 = function () {
return true;
};
var func2 = function () {
return false;
};
var func3 = function () {
return 'string';
};
@@ -0,0 +1,437 @@
import * as ESTree from 'estree';
import { assert } from 'chai';
import { Nodes } from '../../../../src/node/Nodes';
import { NodeGuards } from '../../../../src/node/NodeGuards';
import { NodeUtils } from '../../../../src/node/NodeUtils';
describe('NodeGuards', () => {
describe('isNodeHasBlockScope (node: ESTree.Node): node is TNodeWithBlockScope', () => {
describe('truthful checks', () => {
describe('variant #1: block statement of function declaration', () => {
const expectedResult: boolean = true;
const node: ESTree.Node = Nodes.getBlockStatementNode();
const parentNode: ESTree.FunctionDeclaration = Nodes.getFunctionDeclarationNode(
'foo',
[],
node
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
});
it('should check if node has block scope', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #2: block statement of function expression', () => {
const expectedResult: boolean = true;
const node: ESTree.Node = Nodes.getBlockStatementNode();
const parentNode: ESTree.FunctionExpression = Nodes.getFunctionExpressionNode(
[],
node
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
});
it('should check if node has block scope', () => {
assert.equal(result, expectedResult);
});
});
});
describe('false checks', () => {
describe('variant #1: switch-case node', () => {
const expectedResult: boolean = false;
const node: ESTree.Node = Nodes.getSwitchCaseNode(
Nodes.getLiteralNode(1),
[]
);
const parentNode: ESTree.FunctionDeclaration = Nodes.getFunctionDeclarationNode(
'foo',
[],
Nodes.getBlockStatementNode([
Nodes.getSwitchStatementNode(
Nodes.getMemberExpressionNode(
Nodes.getIdentifierNode('bar'),
Nodes.getUpdateExpressionNode(
'++',
Nodes.getIdentifierNode('baz')
),
true
),
[node]
)
])
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
});
it('should check if node has block scope', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #2: literal node', () => {
const expectedResult: boolean = false;
const node: ESTree.Node = Nodes.getLiteralNode(1);
const parentNode: ESTree.FunctionDeclaration = Nodes.getFunctionDeclarationNode(
'foo',
[],
Nodes.getBlockStatementNode([
Nodes.getExpressionStatementNode(
Nodes.getCallExpressionNode(
Nodes.getIdentifierNode('bar'),
[node]
)
)
])
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
});
it('should check if node has block scope', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #3: block statement of if statement', () => {
const expectedResult: boolean = false;
const node: ESTree.Node = Nodes.getBlockStatementNode();
const parentNode: ESTree.IfStatement = Nodes.getIfStatementNode(
Nodes.getIdentifierNode('foo'),
node
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isNodeHasBlockScope(node, parentNode);
});
it('should check if node has block scope', () => {
assert.equal(result, expectedResult);
});
});
});
});
describe('isNodeHasScope (node: ESTree.Node): node is TNodeWithScope', () => {
describe('truthful checks', () => {
describe('variant #1: program node', () => {
const expectedResult: boolean = true;
const node: ESTree.Node = Nodes.getProgramNode();
let result: boolean;
before(() => {
result = NodeGuards.isNodeHasScope(node);
});
it('should check if node has scope', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #2: block statement node', () => {
const expectedResult: boolean = true;
const node: ESTree.Node = Nodes.getBlockStatementNode();
let result: boolean;
before(() => {
result = NodeGuards.isNodeHasScope(node);
});
it('should check if node has scope', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #3: switch case node', () => {
const expectedResult: boolean = true;
const node: ESTree.Node = Nodes.getSwitchCaseNode(
Nodes.getLiteralNode(1),
[]
);
let result: boolean;
before(() => {
result = NodeGuards.isNodeHasScope(node);
});
it('should check if node has scope', () => {
assert.equal(result, expectedResult);
});
});
});
describe('false checks', () => {
describe('variant #1: literal node', () => {
const expectedResult: boolean = false;
const node: ESTree.Node = Nodes.getLiteralNode(1);
let result: boolean;
before(() => {
result = NodeGuards.isNodeHasScope(node);
});
it('should check if node has scope', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #2: identifier node', () => {
const expectedResult: boolean = false;
const node: ESTree.Node = Nodes.getIdentifierNode('foo');
let result: boolean;
before(() => {
result = NodeGuards.isNodeHasScope(node);
});
it('should check if node has scope', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #3: if-statement node', () => {
const expectedResult: boolean = false;
const node: ESTree.Node = Nodes.getIfStatementNode(
Nodes.getIdentifierNode('foo'),
Nodes.getBlockStatementNode()
);
let result: boolean;
before(() => {
result = NodeGuards.isNodeHasScope(node);
});
it('should check if node has scope', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #4: switch-statement node', () => {
const expectedResult: boolean = false;
const node: ESTree.Node = Nodes.getSwitchStatementNode(
Nodes.getIdentifierNode('foo'),
[]
);
let result: boolean;
before(() => {
result = NodeGuards.isNodeHasScope(node);
});
it('should check if node has scope', () => {
assert.equal(result, expectedResult);
});
});
});
});
describe('isReplaceableIdentifierNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier', () => {
describe('truthful checks', () => {
describe('variant #1: parent node is function declaration node', () => {
const expectedResult: boolean = true;
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
const parentNode: ESTree.Node = Nodes.getFunctionDeclarationNode(
'bar',
[identifier],
Nodes.getBlockStatementNode()
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
});
it('should check if input identifier can be replaced by obfuscated one', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #2: parent node is computed property node', () => {
const expectedResult: boolean = true;
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
const parentNode: ESTree.Node = Nodes.getPropertyNode(
identifier,
Nodes.getLiteralNode('bar'),
true
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
});
it('should check if input identifier can be replaced by obfuscated one', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #4: parent node is computed member expression node', () => {
const expectedResult: boolean = true;
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
const parentNode: ESTree.Node = Nodes.getMemberExpressionNode(
Nodes.getIdentifierNode('bar'),
identifier,
true
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
});
it('should check if input identifier can be replaced by obfuscated one', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #4: parent node is computed method definition node', () => {
const expectedResult: boolean = true;
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
const parentNode: ESTree.Node = Nodes.getMethodDefinitionNode(
identifier,
Nodes.getFunctionExpressionNode([], Nodes.getBlockStatementNode()),
'method',
true
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
});
it('should check if input identifier can be replaced by obfuscated one', () => {
assert.equal(result, expectedResult);
});
});
});
describe('false checks', () => {
describe('variant #1: node isn\'t an identifier', () => {
const expectedResult: boolean = false;
const literal: ESTree.Literal = Nodes.getLiteralNode(1);
const parentNode: ESTree.Node = Nodes.getExpressionStatementNode(
Nodes.getCallExpressionNode(
Nodes.getIdentifierNode('foo'),
[literal]
)
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isReplaceableIdentifierNode(literal, parentNode);
});
it('should check if input identifier can be replaced by obfuscated one', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #2: parent node isn\'t computed property node', () => {
const expectedResult: boolean = false;
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
const parentNode: ESTree.Node = Nodes.getPropertyNode(
identifier,
Nodes.getLiteralNode('bar'),
false
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
});
it('should check if input identifier can be replaced by obfuscated one', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #3: parent node isn\'t computed member expression node', () => {
const expectedResult: boolean = false;
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
const parentNode: ESTree.Node = Nodes.getMemberExpressionNode(
Nodes.getIdentifierNode('bar'),
identifier,
false
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
});
it('should check if input identifier can be replaced by obfuscated one', () => {
assert.equal(result, expectedResult);
});
});
describe('variant #4: parent node isn\'t computed method definition node', () => {
const expectedResult: boolean = false;
const identifier: ESTree.Identifier = Nodes.getIdentifierNode('foo');
const parentNode: ESTree.Node = Nodes.getMethodDefinitionNode(
identifier,
Nodes.getFunctionExpressionNode([], Nodes.getBlockStatementNode()),
'method',
false
);
let result: boolean;
before(() => {
NodeUtils.parentize(parentNode);
result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
});
it('should check if input identifier can be replaced by obfuscated one', () => {
assert.equal(result, expectedResult);
});
});
});
});
});
@@ -9,8 +9,8 @@ import { NodeUtils } from '../../../../src/node/NodeUtils';
describe('NodeUtils', () => {
describe('addXVerbatimPropertyToLiterals (node: ESTree.Node): void', () => {
let literalNode: any,
expectedLiteralNode: any;
let literalNode: ESTree.Literal,
expectedLiteralNode: ESTree.Literal;
before(() => {
literalNode = Nodes.getLiteralNode('value');
@@ -179,39 +179,7 @@ describe('NodeUtils', () => {
});
});
describe('getBlockStatementNodeByIndex (node: ESTree.Node, index: number = 0): ESTree.Node', () => {
let blockStatementNode: ESTree.BlockStatement,
expressionStatementNode1: ESTree.ExpressionStatement,
expressionStatementNode2: ESTree.ExpressionStatement;
beforeEach(() => {
expressionStatementNode1 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
expressionStatementNode2 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
blockStatementNode = Nodes.getBlockStatementNode([
expressionStatementNode1,
expressionStatementNode2
]);
});
it('should return block-statement child node of given node if that node has block-statement', () => {
assert.deepEqual(NodeUtils.getBlockStatementNodeByIndex(blockStatementNode), expressionStatementNode1);
});
it('should return block-statement child node of given node with index `1` if that node has block-statement', () => {
assert.deepEqual(NodeUtils.getBlockStatementNodeByIndex(blockStatementNode, 1), expressionStatementNode2);
});
it('should throw a `ReferenceError` if index is out of boundaries', () => {
assert.throws(() => NodeUtils.getBlockStatementNodeByIndex(blockStatementNode, 2), ReferenceError);
});
it('should throw a `TypeError` if node have no a block-statement', () => {
assert.throws(() => NodeUtils.getBlockStatementNodeByIndex(expressionStatementNode1, 1), TypeError);
});
});
describe('getBlockScopesOfNode (node: ESTree.Node, blockScopes: TNodeWithBlockStatement[] = []): TNodeWithBlockStatement[]', () => {
describe('getBlockScopesOfNode (node: ESTree.Node, blockScopes: TNodeWithBlockScope[] = []): TNodeWithBlockScope[]', () => {
let functionDeclarationBlockStatementNode: ESTree.BlockStatement,
ifStatementBlockStatementNode1: ESTree.BlockStatement,
ifStatementBlockStatementNode2: ESTree.BlockStatement,
@@ -326,18 +294,20 @@ describe('NodeUtils', () => {
});
});
describe('getNodeBlockScopeDepth (node: ESTree.Node, depth: number = 0): number', () => {
let functionDeclarationBlockStatementNode1: ESTree.BlockStatement,
functionDeclarationBlockStatementNode2: ESTree.BlockStatement,
describe('getScopeOfNode (node: ESTree.Node): TNodeWithScope | null', () => {
let functionDeclarationBlockStatementNode: ESTree.BlockStatement,
ifStatementBlockStatementNode1: ESTree.BlockStatement,
ifStatementBlockStatementNode2: ESTree.BlockStatement,
ifStatementBlockStatementNode3: ESTree.BlockStatement,
ifStatementNode1: ESTree.IfStatement,
ifStatementNode2: ESTree.IfStatement,
expressionStatementNode1: ESTree.ExpressionStatement,
expressionStatementNode2: ESTree.ExpressionStatement,
ifStatementNode3: ESTree.IfStatement,
switchCaseNode: ESTree.SwitchCase,
switchStatementNode: ESTree.SwitchStatement,
expressionStatementNode3: ESTree.ExpressionStatement,
functionDeclarationNode1: ESTree.FunctionDeclaration,
functionDeclarationNode2: ESTree.FunctionDeclaration,
expressionStatementNode2: ESTree.ExpressionStatement,
expressionStatementNode1: ESTree.ExpressionStatement,
functionDeclarationNode: ESTree.FunctionDeclaration,
programNode: ESTree.Program;
before(() => {
@@ -345,101 +315,123 @@ describe('NodeUtils', () => {
expressionStatementNode2 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
expressionStatementNode3 = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
ifStatementBlockStatementNode2 = Nodes.getBlockStatementNode([
ifStatementBlockStatementNode3 = Nodes.getBlockStatementNode([
expressionStatementNode2,
expressionStatementNode3
]);
ifStatementNode3 = Nodes.getIfStatementNode(
Nodes.getLiteralNode(true),
ifStatementBlockStatementNode3
);
ifStatementBlockStatementNode2 = Nodes.getBlockStatementNode();
ifStatementBlockStatementNode1 = Nodes.getBlockStatementNode([
ifStatementNode3
]);
ifStatementNode2 = Nodes.getIfStatementNode(
Nodes.getLiteralNode(true),
ifStatementBlockStatementNode2
);
functionDeclarationBlockStatementNode2 = Nodes.getBlockStatementNode([
ifStatementNode2,
expressionStatementNode2
]);
functionDeclarationNode2 = Nodes.getFunctionDeclarationNode('test', [], functionDeclarationBlockStatementNode2);
ifStatementBlockStatementNode1 = Nodes.getBlockStatementNode([
functionDeclarationNode2
]);
ifStatementNode1 = Nodes.getIfStatementNode(
Nodes.getLiteralNode(true),
ifStatementBlockStatementNode1
);
functionDeclarationBlockStatementNode1 = Nodes.getBlockStatementNode([
switchCaseNode = Nodes.getSwitchCaseNode(
Nodes.getLiteralNode(1),
[
ifStatementNode2
]
);
switchStatementNode = Nodes.getSwitchStatementNode(
Nodes.getLiteralNode(1),
[
switchCaseNode
]
);
functionDeclarationBlockStatementNode = Nodes.getBlockStatementNode([
expressionStatementNode1,
ifStatementNode1
ifStatementNode1,
switchStatementNode
]);
functionDeclarationNode1 = Nodes.getFunctionDeclarationNode('test', [], functionDeclarationBlockStatementNode1);
functionDeclarationNode = Nodes.getFunctionDeclarationNode('test', [], functionDeclarationBlockStatementNode);
programNode = Nodes.getProgramNode([
functionDeclarationNode1
functionDeclarationNode
]);
programNode.parentNode = programNode;
functionDeclarationNode1.parentNode = programNode;
functionDeclarationBlockStatementNode1.parentNode = functionDeclarationNode1;
expressionStatementNode1.parentNode = functionDeclarationBlockStatementNode1;
ifStatementNode1.parentNode = functionDeclarationBlockStatementNode1;
functionDeclarationNode.parentNode = programNode;
functionDeclarationBlockStatementNode.parentNode = functionDeclarationNode;
expressionStatementNode1.parentNode = functionDeclarationBlockStatementNode;
ifStatementNode1.parentNode = functionDeclarationBlockStatementNode;
ifStatementBlockStatementNode1.parentNode = ifStatementNode1;
functionDeclarationNode2.parentNode = ifStatementBlockStatementNode1;
functionDeclarationBlockStatementNode2.parentNode = functionDeclarationNode2;
expressionStatementNode2.parentNode = functionDeclarationBlockStatementNode2;
ifStatementNode2.parentNode = functionDeclarationBlockStatementNode2;
switchStatementNode.parentNode = functionDeclarationBlockStatementNode;
switchCaseNode.parentNode = switchStatementNode;
ifStatementNode2.parentNode = switchCaseNode;
ifStatementBlockStatementNode2.parentNode = ifStatementNode2;
ifStatementNode3.parentNode = ifStatementBlockStatementNode1;
ifStatementBlockStatementNode3.parentNode = ifStatementNode3;
expressionStatementNode3.parentNode = ifStatementBlockStatementNode3;
});
it('should return block-scope depth for `program` node', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(programNode), 0);
it('should return scope node for `program` node child', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(programNode), programNode);
});
it('should return block-scope depth for `functionDeclaration` node #1', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(functionDeclarationNode1), 0);
it('should return scope node for `functionDeclaration` node child node #1', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(functionDeclarationNode), programNode);
});
it('should return block-scope depth for `functionDeclaration blockStatement` node #1', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(functionDeclarationBlockStatementNode1), 1);
it('should return scope node for `functionDeclaration blockStatement` node child node #1', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(functionDeclarationBlockStatementNode), programNode);
});
it('should return block-scope depth for `expressionStatement` node #1', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(expressionStatementNode1), 1);
it('should return scope node for `expressionStatement` node #1 child node', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(expressionStatementNode1), functionDeclarationBlockStatementNode);
});
it('should return block-scope depth for `ifStatement` node #1', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(ifStatementNode1), 1);
it('should return scope node for `ifStatement` node #1 child node', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(ifStatementNode1), functionDeclarationBlockStatementNode);
});
it('should return block-scope depth for `ifStatement blockStatement` node #1', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(ifStatementBlockStatementNode1), 1);
it('should return scope node for `switchStatement` node child node', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(switchStatementNode), functionDeclarationBlockStatementNode);
});
it('should return block-scope depth for `functionDeclaration` node #2', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(functionDeclarationNode2), 1);
it('should return scope node for `switchCase` node child node', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(switchCaseNode), functionDeclarationBlockStatementNode);
});
it('should return block-scope depth for `functionDeclaration blockStatement` node #2', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(functionDeclarationBlockStatementNode2), 2);
it('should return scope node for `ifStatement` node #2 child node', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(ifStatementNode2), switchCaseNode);
});
it('should return block-scope depth for `expressionStatement` node #2', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(expressionStatementNode2), 2);
it('should return scope node for `ifStatement blockStatement` node #2 child node', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(ifStatementBlockStatementNode2), switchCaseNode);
});
it('should return block-scope depth for `ifStatement` node #2', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(ifStatementNode2), 2);
it('should return scope node for `ifStatement blockStatement` node #1 child node', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(ifStatementBlockStatementNode1), functionDeclarationBlockStatementNode);
});
it('should return block-scope depth for `ifStatement blockStatement` node #2', () => {
assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(ifStatementBlockStatementNode2), 2);
it('should return scope node for `ifStatement blockStatement` node #3 child node', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(ifStatementBlockStatementNode3), ifStatementBlockStatementNode1);
});
it('should return scope node for `expressionStatement` node #3 child node', () => {
assert.deepEqual(NodeUtils.getScopeOfNode(expressionStatementNode3), ifStatementBlockStatementNode3);
});
it('should throw a `ReferenceError` if node has no `parentNode` property', () => {
assert.throws(() => NodeUtils.getNodeBlockScopeDepth(expressionStatementNode3), ReferenceError);
assert.throws(() => NodeUtils.getScopeOfNode(expressionStatementNode2), ReferenceError);
});
});