From 54cbdf6d27041f5a3eed8d2e5a5ff04abf9e1f11 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 5 Sep 2023 11:26:01 +0200 Subject: [PATCH 01/87] Add target 'service-worker' (#1134) --- .../AbstractCustomCodeHelper.ts | 16 +- .../GlobalVariableServiceWorkerTemplate.ts | 6 + .../ConsoleOutputDisableCodeHelper.ts | 8 +- src/enums/ObfuscationTarget.ts | 4 +- src/options/Options.ts | 2 +- ...ebugProtectionFunctionCallTemplate.spec.ts | 37 +++- .../ClassDeclaration.spec.ts | 179 ++++++++++++++++++ .../options/domain-lock/Validation.spec.ts | 42 ++-- 8 files changed, 268 insertions(+), 26 deletions(-) create mode 100644 src/custom-code-helpers/common/templates/GlobalVariableServiceWorkerTemplate.ts diff --git a/src/custom-code-helpers/AbstractCustomCodeHelper.ts b/src/custom-code-helpers/AbstractCustomCodeHelper.ts index d43325cac..a6c550134 100644 --- a/src/custom-code-helpers/AbstractCustomCodeHelper.ts +++ b/src/custom-code-helpers/AbstractCustomCodeHelper.ts @@ -13,6 +13,9 @@ import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator'; import { GlobalVariableTemplate1 } from './common/templates/GlobalVariableTemplate1'; import { GlobalVariableTemplate2 } from './common/templates/GlobalVariableTemplate2'; +import { ObfuscationTarget } from '../enums/ObfuscationTarget'; +import { GlobalVariableNoEvalTemplate } from './common/templates/GlobalVariableNoEvalTemplate'; +import { GlobalVariableServiceWorkerTemplate } from './common/templates/GlobalVariableServiceWorkerTemplate'; @injectable() export abstract class AbstractCustomCodeHelper < @@ -97,9 +100,16 @@ export abstract class AbstractCustomCodeHelper < * @returns {string} */ protected getGlobalVariableTemplate (): string { - return this.randomGenerator - .getRandomGenerator() - .pickone(AbstractCustomCodeHelper.globalVariableTemplateFunctions); + switch (this.options.target) { + case ObfuscationTarget.BrowserNoEval: + return GlobalVariableNoEvalTemplate(); + case ObfuscationTarget.ServiceWorker: + return GlobalVariableServiceWorkerTemplate(); + default: + return this.randomGenerator + .getRandomGenerator() + .pickone(AbstractCustomCodeHelper.globalVariableTemplateFunctions); + } } /** diff --git a/src/custom-code-helpers/common/templates/GlobalVariableServiceWorkerTemplate.ts b/src/custom-code-helpers/common/templates/GlobalVariableServiceWorkerTemplate.ts new file mode 100644 index 000000000..fa07480c7 --- /dev/null +++ b/src/custom-code-helpers/common/templates/GlobalVariableServiceWorkerTemplate.ts @@ -0,0 +1,6 @@ +/** + * @returns {string} + */ +export function GlobalVariableServiceWorkerTemplate (): string { + return `const that = typeof global === 'object' ? global : this;`; +} diff --git a/src/custom-code-helpers/console-output/ConsoleOutputDisableCodeHelper.ts b/src/custom-code-helpers/console-output/ConsoleOutputDisableCodeHelper.ts index 5c67e5e95..8f34a5bc0 100644 --- a/src/custom-code-helpers/console-output/ConsoleOutputDisableCodeHelper.ts +++ b/src/custom-code-helpers/console-output/ConsoleOutputDisableCodeHelper.ts @@ -9,10 +9,8 @@ import { ICustomCodeHelperObfuscator } from '../../interfaces/custom-code-helper import { IOptions } from '../../interfaces/options/IOptions'; import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; -import { ObfuscationTarget } from '../../enums/ObfuscationTarget'; import { ConsoleOutputDisableTemplate } from './templates/ConsoleOutputDisableTemplate'; -import { GlobalVariableNoEvalTemplate } from '../common/templates/GlobalVariableNoEvalTemplate'; import { initializable } from '../../decorators/Initializable'; @@ -78,14 +76,10 @@ export class ConsoleOutputDisableCodeHelper extends AbstractCustomCodeHelper { * @returns {string} */ protected override getCodeHelperTemplate (): string { - const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval - ? this.getGlobalVariableTemplate() - : GlobalVariableNoEvalTemplate(); - return this.customCodeHelperFormatter.formatTemplate(ConsoleOutputDisableTemplate(), { callControllerFunctionName: this.callsControllerFunctionName, consoleLogDisableFunctionName: this.consoleOutputDisableFunctionName, - globalVariableTemplate + globalVariableTemplate: this.getGlobalVariableTemplate(), }); } } diff --git a/src/enums/ObfuscationTarget.ts b/src/enums/ObfuscationTarget.ts index b4fe42e94..7fb67763c 100644 --- a/src/enums/ObfuscationTarget.ts +++ b/src/enums/ObfuscationTarget.ts @@ -4,8 +4,10 @@ export const ObfuscationTarget: Readonly<{ Browser: 'browser'; BrowserNoEval: 'browser-no-eval'; Node: 'node'; + ServiceWorker: 'service-worker'; }> = Utils.makeEnum({ Browser: 'browser', BrowserNoEval: 'browser-no-eval', - Node: 'node' + Node: 'node', + ServiceWorker: 'service-worker', }); diff --git a/src/options/Options.ts b/src/options/Options.ts index 234673a55..c47f091d9 100644 --- a/src/options/Options.ts +++ b/src/options/Options.ts @@ -415,7 +415,7 @@ export class Options implements IOptions { /** * @type {ObfuscationTarget} */ - @IsIn([ObfuscationTarget.Browser, ObfuscationTarget.BrowserNoEval, ObfuscationTarget.Node]) + @IsIn([ObfuscationTarget.Browser, ObfuscationTarget.BrowserNoEval, ObfuscationTarget.Node, ObfuscationTarget.ServiceWorker]) public readonly target!: TTypeFromEnum; /** diff --git a/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-call-template/DebugProtectionFunctionCallTemplate.spec.ts b/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-call-template/DebugProtectionFunctionCallTemplate.spec.ts index a8ebe185b..5a6173647 100644 --- a/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-call-template/DebugProtectionFunctionCallTemplate.spec.ts +++ b/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-call-template/DebugProtectionFunctionCallTemplate.spec.ts @@ -149,7 +149,40 @@ describe('DebugProtectionFunctionCallTemplate', function () { }); }); - describe('Variant #5: obfuscated code with removed debug protection code', () => { + describe('Variant #5: correctly obfuscated code with target `ServiceWorker', () => { + const expectedEvaluationResult: number = 1; + + let obfuscatedCode: string, + evaluationResult: number = 0; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/input.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true, + target: ObfuscationTarget.ServiceWorker + } + ).getObfuscatedCode(); + + return evaluateInWorker(obfuscatedCode, evaluationTimeout) + .then((result: string | null) => { + if (!result) { + return; + } + + evaluationResult = parseInt(result, 10); + }); + }); + + it('should correctly evaluate code with enabled debug protection', () => { + assert.equal(evaluationResult, expectedEvaluationResult); + }); + }); + + describe('Variant #6: obfuscated code with removed debug protection code', () => { const expectedEvaluationResult: number = 0; let obfuscatedCode: string, @@ -182,7 +215,7 @@ describe('DebugProtectionFunctionCallTemplate', function () { }); }); - describe('Variant #6: single call of debug protection code', () => { + describe('Variant #7: single call of debug protection code', () => { const expectedEvaluationResult: number = 1; let obfuscatedCode: string, diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts index 78cbcf726..2be6ed5db 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts @@ -227,6 +227,87 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { }); }); }); + + describe('Variant #3: target `service-worker', () => { + describe('Variant #1: correct class name references in global scope', () => { + const classNameIdentifierRegExp: RegExp = /class A *\{/; + const outerClassNameReferenceRegExp: RegExp = /console\['log']\(A\);/; + const innerClassNameReferenceRegExp: RegExp = /return A;/; + + let obfuscatedCode: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-global-scope.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + target: ObfuscationTarget.ServiceWorker + } + ).getObfuscatedCode(); + }); + + it('match #1: shouldn\'t transform class name', () => { + assert.match(obfuscatedCode, classNameIdentifierRegExp); + }); + + it('match #2: shouldn\'t transform class name reference outside of class', () => { + assert.match(obfuscatedCode, outerClassNameReferenceRegExp); + }); + + it('match #3: shouldn\'t transform class name reference inside class', () => { + assert.match(obfuscatedCode, innerClassNameReferenceRegExp); + }); + }); + + describe('Variant #2: correct class name references in function scope', () => { + const classNameIdentifierRegExp: RegExp = /class (_0x[a-f0-9]{4,6}) *\{/; + const outerClassNameReferenceRegExp: RegExp = /console\['log']\((_0x[a-f0-9]{4,6})\);/; + const innerClassNameReferenceRegExp: RegExp = /return (_0x[a-f0-9]{4,6});/; + + let obfuscatedCode: string; + let classNameIdentifier: string; + let outerClassNameReferenceIdentifierName: string; + let innerClassNameReferenceIdentifierName: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-function-scope.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + target: ObfuscationTarget.ServiceWorker + } + ).getObfuscatedCode(); + + classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); + innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + }); + + it('match #1: should transform class name', () => { + assert.match(obfuscatedCode, classNameIdentifierRegExp); + }); + + it('match #2: should transform class name reference outside of class', () => { + assert.match(obfuscatedCode, outerClassNameReferenceRegExp); + }); + + it('match #3: should transform class name reference inside class', () => { + assert.match(obfuscatedCode, innerClassNameReferenceRegExp); + }); + + it('match #4: should generate same identifier names for class name and outer class name reference', () => { + assert.equal(classNameIdentifier, outerClassNameReferenceIdentifierName); + }); + + it('match #5: should generate same identifier names for class name and inner class name reference', () => { + assert.equal(classNameIdentifier, innerClassNameReferenceIdentifierName); + }); + }); + }); }); describe('Variant #2: `renameGlobals` option is enabled', () => { @@ -479,6 +560,104 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { }); }); }); + + describe('Variant #4: target: `service-worker', () => { + describe('Variant #1: correct class name references in global scope', () => { + const classNameIdentifierRegExp: RegExp = /class (_0x[a-f0-9]{4,6}) *\{/; + const outerClassNameReferenceRegExp: RegExp = /console\['log']\((_0x[a-f0-9]{4,6})\);/; + const innerClassNameReferenceRegExp: RegExp = /return (_0x[a-f0-9]{4,6});/; + + let obfuscatedCode: string; + let classNameIdentifier: string; + let outerClassNameReferenceIdentifierName: string; + let innerClassNameReferenceIdentifierName: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-global-scope.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + target: ObfuscationTarget.ServiceWorker + } + ).getObfuscatedCode(); + + classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); + innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + }); + + it('match #1: should transform class name', () => { + assert.match(obfuscatedCode, classNameIdentifierRegExp); + }); + + it('match #2: should transform class name reference outside of class', () => { + assert.match(obfuscatedCode, outerClassNameReferenceRegExp); + }); + + it('match #3: should transform class name reference inside class', () => { + assert.match(obfuscatedCode, innerClassNameReferenceRegExp); + }); + + it('match #4: should generate same identifier names for class name and outer class name reference', () => { + assert.equal(classNameIdentifier, outerClassNameReferenceIdentifierName); + }); + + it('match #5: should generate same identifier names for class name and inner class name reference', () => { + assert.equal(classNameIdentifier, innerClassNameReferenceIdentifierName); + }); + }); + + describe('Variant #2: correct class name references in function scope', () => { + const classNameIdentifierRegExp: RegExp = /class (_0x[a-f0-9]{4,6}) *\{/; + const outerClassNameReferenceRegExp: RegExp = /console\['log']\((_0x[a-f0-9]{4,6})\);/; + const innerClassNameReferenceRegExp: RegExp = /return (_0x[a-f0-9]{4,6});/; + + let obfuscatedCode: string; + let classNameIdentifier: string; + let outerClassNameReferenceIdentifierName: string; + let innerClassNameReferenceIdentifierName: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-function-scope.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + target: ObfuscationTarget.ServiceWorker + } + ).getObfuscatedCode(); + + classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); + innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + }); + + it('match #1: should transform class name', () => { + assert.match(obfuscatedCode, classNameIdentifierRegExp); + }); + + it('match #2: should transform class name reference outside of class', () => { + assert.match(obfuscatedCode, outerClassNameReferenceRegExp); + }); + + it('match #3: should transform class name reference inside class', () => { + assert.match(obfuscatedCode, innerClassNameReferenceRegExp); + }); + + it('match #4: should generate same identifier names for class name and outer class name reference', () => { + assert.equal(classNameIdentifier, outerClassNameReferenceIdentifierName); + }); + + it('match #5: should generate same identifier names for class name and inner class name reference', () => { + assert.equal(classNameIdentifier, innerClassNameReferenceIdentifierName); + }); + }); + }); }); }); diff --git a/test/functional-tests/options/domain-lock/Validation.spec.ts b/test/functional-tests/options/domain-lock/Validation.spec.ts index 76bd37c76..4ec195dd7 100644 --- a/test/functional-tests/options/domain-lock/Validation.spec.ts +++ b/test/functional-tests/options/domain-lock/Validation.spec.ts @@ -50,22 +50,40 @@ describe('`domainLock` validation', () => { describe('Variant #2: negative validation', () => { const expectedError: string = 'This option allowed only for obfuscation targets'; - let testFunc: () => string; - beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { - ...NO_ADDITIONAL_NODES_PRESET, - domainLock: ['www.example.com'], - target: ObfuscationTarget.Node - } - ).getObfuscatedCode(); + describe('Variant #1: obfuscation target: `node`', () => { + beforeEach(() => { + testFunc = () => JavaScriptObfuscator.obfuscate( + '', + { + ...NO_ADDITIONAL_NODES_PRESET, + domainLock: ['www.example.com'], + target: ObfuscationTarget.Node + } + ).getObfuscatedCode(); + }); + + it('should not pass validation when obfuscation target is `node` and value is not default', () => { + assert.throws(testFunc, expectedError); + }); }); - it('should not pass validation when obfuscation target is `node` and value is not default', () => { - assert.throws(testFunc, expectedError); + describe('Variant #1: obfuscation target: `service-worker`', () => { + beforeEach(() => { + testFunc = () => JavaScriptObfuscator.obfuscate( + '', + { + ...NO_ADDITIONAL_NODES_PRESET, + domainLock: ['www.example.com'], + target: ObfuscationTarget.ServiceWorker + } + ).getObfuscatedCode(); + }); + + it('should not pass validation when obfuscation target is `service-worker` and value is not default', () => { + assert.throws(testFunc, expectedError); + }); }); }); }); From 51540575394fdbb3737c40083b4645a896890f21 Mon Sep 17 00:00:00 2001 From: mkafrin <1360790+mkafrin@users.noreply.github.com> Date: Tue, 5 Sep 2023 05:26:41 -0400 Subject: [PATCH 02/87] Better use of cross-env (#1171) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 35a30c2a4..d19604fe0 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "test:devRuntimePerformance": "ts-node test/dev/dev-runtime-performance.ts", "test:full": "yarn run test:dev && yarn run test:mocha-coverage && yarn run test:mocha-memory-performance", "test:mocha": "mocha --require source-map-support/register test/index.spec.ts --exit", - "test:mocha-coverage": "NODE_OPTIONS=--max-old-space-size=4096 nyc --reporter text-summary --no-clean yarn run test:mocha", + "test:mocha-coverage": "cross-env NODE_OPTIONS=--max-old-space-size=4096 nyc --reporter text-summary --no-clean yarn run test:mocha", "test:mocha-coverage:report": "nyc report --reporter=lcov", "test:mocha-memory-performance": "cross-env NODE_OPTIONS=--max-old-space-size=280 mocha test/performance-tests/JavaScriptObfuscatorMemory.spec.ts", "test": "yarn run test:full", From 712c319b0dbec194c3ff6f1ed31395c0cb181d9d Mon Sep 17 00:00:00 2001 From: Mark Eriksson Date: Tue, 5 Sep 2023 10:27:01 +0100 Subject: [PATCH 03/87] add snowpack plugin link (#1064) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c850f60f1..eaf34f646 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ The example of obfuscated code: [github.com](https://github.com/javascript-obfus * Weex: [weex-devtool](https://www.npmjs.com/package/weex-devtool) * Malta: [malta-js-obfuscator](https://github.com/fedeghe/malta-js-obfuscator) * Netlify plugin: [netlify-plugin-js-obfuscator](https://www.npmjs.com/package/netlify-plugin-js-obfuscator) +* Snowpack plugin: [snowpack-javascript-obfuscator](https://www.npmjs.com/package/snowpack-javascript-obfuscator) [![npm version](https://badge.fury.io/js/javascript-obfuscator.svg)](https://badge.fury.io/js/javascript-obfuscator) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjavascript-obfuscator%2Fjavascript-obfuscator.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjavascript-obfuscator%2Fjavascript-obfuscator?ref=badge_shield) From 1000402f10f61bd367cd971d55f0f832d940d60e Mon Sep 17 00:00:00 2001 From: sanex Date: Tue, 5 Sep 2023 20:12:05 +0400 Subject: [PATCH 04/87] Version update to 4.1.0 --- CHANGELOG.md | 4 ++++ package.json | 2 +- .../common/templates/GlobalVariableServiceWorkerTemplate.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 279789018..2021dcc59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log +v4.1.0 +--- +* Add target `service-worker` + v4.0.2 --- * Add support for `node@18` diff --git a/package.json b/package.json index d19604fe0..bfe1143ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "4.0.2", + "version": "4.1.0", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", diff --git a/src/custom-code-helpers/common/templates/GlobalVariableServiceWorkerTemplate.ts b/src/custom-code-helpers/common/templates/GlobalVariableServiceWorkerTemplate.ts index fa07480c7..ec5d6d99e 100644 --- a/src/custom-code-helpers/common/templates/GlobalVariableServiceWorkerTemplate.ts +++ b/src/custom-code-helpers/common/templates/GlobalVariableServiceWorkerTemplate.ts @@ -2,5 +2,5 @@ * @returns {string} */ export function GlobalVariableServiceWorkerTemplate (): string { - return `const that = typeof global === 'object' ? global : this;`; + return 'const that = typeof global === \'object\' ? global : this;'; } From 0c1c4326ba8e5f8f065b8ef9d7aebfff2c41da0f Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sat, 15 Jun 2024 03:06:56 +0400 Subject: [PATCH 05/87] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eaf34f646..a992efdf2 100644 --- a/README.md +++ b/README.md @@ -1674,6 +1674,10 @@ See: [`Kind of variables`](#kind-of-variables) Try `renamePropertiesMode: 'safe'` option, if it still doesn't work, just disable this option. +## GitHub Sponsors + + + ## Backers Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/javascript-obfuscator#backer)] @@ -1710,7 +1714,7 @@ Support us with a monthly donation and help us continue our activities. [[Become -## Sponsors +## Open Collective Sponsors Become a sponsor and get your logo on our README on Github with a link to your site. @@ -1729,7 +1733,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s ## License [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjavascript-obfuscator%2Fjavascript-obfuscator.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjavascript-obfuscator%2Fjavascript-obfuscator?ref=badge_large) -Copyright (C) 2016-2022 [Timofey Kachalov](http://github.com/sanex3339). +Copyright (C) 2016-2024 [Timofey Kachalov](http://github.com/sanex3339). Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: From 07ec2879f177477250d2863e6f34e6d49cc44b89 Mon Sep 17 00:00:00 2001 From: Smell of curry <75345244+smell-of-curry@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:09:30 -0400 Subject: [PATCH 06/87] Fixed Grammatical Error in README.md (#1249) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a992efdf2..a1dae1340 100644 --- a/README.md +++ b/README.md @@ -1188,7 +1188,7 @@ Each `stringArray` value will be encoded by the randomly picked encoding from th Available values: * `'none'` (`boolean`): doesn't encode `stringArray` value * `'base64'` (`string`): encodes `stringArray` value using `base64` -* `'rc4'` (`string`): encodes `stringArray` value using `rc4`. **About 30-50% slower than `base64`, but more harder to get initial values.** It's recommended to disable [`unicodeEscapeSequence`](#unicodeescapesequence) option when using `rc4` encoding to prevent very large size of obfuscated code. +* `'rc4'` (`string`): encodes `stringArray` value using `rc4`. **About 30-50% slower than `base64`, but harder to get initial values.** It's recommended to disable [`unicodeEscapeSequence`](#unicodeescapesequence) option when using `rc4` encoding to prevent very large size of obfuscated code. For example with the following option values some `stringArray` value won't be encoded, and some values will be encoded with `base64` and `rc4` encoding: From 4e4efb7f92bd8b345ff733d088ee8e750e845d7b Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sat, 15 Jun 2024 14:53:48 +0400 Subject: [PATCH 07/87] Support new nodejs version (#1261) --- .github/workflows/ci.yml | 12 ++-- .mocharc.json | 2 +- package.json | 10 +-- src/node/NodeFactory.ts | 6 +- yarn.lock | 135 ++++++++++++++++++++++----------------- 5 files changed, 94 insertions(+), 71 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e45571de4..a64df512a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,15 +17,17 @@ jobs: matrix: include: - os: ubuntu-latest, - node-version: 14.x + node-version: 18.x - os: ubuntu-latest, - node-version: 16.x + node-version: 20.x - os: ubuntu-latest, - node-version: 18.x + node-version: 21.x + - os: ubuntu-latest, + node-version: 22.x - os: windows-latest, - node-version: 16.x + node-version: 20.x - os: windows-latest, - node-version: 18.x + node-version: 22.x steps: - uses: actions/checkout@v2 diff --git a/.mocharc.json b/.mocharc.json index 0ca796a9e..a854da57e 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,3 +1,3 @@ { - "node-option": ["experimental-specifier-resolution=node", "loader=ts-node/esm"] + "node-option": [] } \ No newline at end of file diff --git a/package.json b/package.json index bfe1143ba..0b8d94610 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "js obfuscator" ], "engines": { - "node": "^12.22.0 || ^14.0.0 || ^16.0.0 || ^17.0.0 || >=18.0.0" + "node": ">=12.22.0" }, "main": "dist/index.js", "browser": "dist/index.browser.js", @@ -72,7 +72,7 @@ "cross-env": "7.0.3", "eslint": "8.34.0", "eslint-plugin-import": "2.27.5", - "eslint-plugin-jsdoc": "40.0.0", + "eslint-plugin-jsdoc": "48.2.12", "eslint-plugin-no-null": "1.0.2", "eslint-plugin-prefer-arrow": "1.2.3", "eslint-plugin-unicorn": "45.0.2", @@ -81,7 +81,7 @@ "fork-ts-checker-webpack-plugin": "7.3.0", "husky": "8.0.3", "js-beautify": "1.14.7", - "mocha": "10.2.0", + "mocha": "10.4.0", "nyc": "15.1.0", "pjson": "1.0.9", "rimraf": "4.1.2", @@ -111,10 +111,10 @@ "test:devCompilePerformance": "ts-node test/dev/dev-compile-performance.ts", "test:devRuntimePerformance": "ts-node test/dev/dev-runtime-performance.ts", "test:full": "yarn run test:dev && yarn run test:mocha-coverage && yarn run test:mocha-memory-performance", - "test:mocha": "mocha --require source-map-support/register test/index.spec.ts --exit", + "test:mocha": "mocha --require ts-node/register --require source-map-support/register test/index.spec.ts --exit", "test:mocha-coverage": "cross-env NODE_OPTIONS=--max-old-space-size=4096 nyc --reporter text-summary --no-clean yarn run test:mocha", "test:mocha-coverage:report": "nyc report --reporter=lcov", - "test:mocha-memory-performance": "cross-env NODE_OPTIONS=--max-old-space-size=280 mocha test/performance-tests/JavaScriptObfuscatorMemory.spec.ts", + "test:mocha-memory-performance": "cross-env NODE_OPTIONS=--max-old-space-size=280 mocha --require ts-node/register test/performance-tests/JavaScriptObfuscatorMemory.spec.ts", "test": "yarn run test:full", "eslint": "eslint src/**/*.ts", "git:addFiles": "git add .", diff --git a/src/node/NodeFactory.ts b/src/node/NodeFactory.ts index 09a43854f..99c7e69ba 100644 --- a/src/node/NodeFactory.ts +++ b/src/node/NodeFactory.ts @@ -271,21 +271,21 @@ export class NodeFactory { } /** - * @param {boolean} await + * @param {boolean} asAwait * @param {VariableDeclaration | Pattern} left * @param {Expression} right * @param {Statement} body * @returns {ForOfStatement} */ public static forOfStatementNode ( - await: boolean, + asAwait: boolean, left: ESTree.VariableDeclaration | ESTree.Pattern, right: ESTree.Expression, body: ESTree.Statement ): ESTree.ForOfStatement { return { type: NodeType.ForOfStatement, - await, + await: asAwait, left, right, body, diff --git a/yarn.lock b/yarn.lock index 561e2ce05..72865b848 100644 --- a/yarn.lock +++ b/yarn.lock @@ -215,14 +215,17 @@ resolved "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.2.tgz" integrity sha512-HyYEUDeIj5rRQU2Hk5HTB2uHsbRQpF70nvMhVzi+VJR0X+xNEhjPui4/kBf3VeH/wqD28PT4sVOm8qqLjBrSZg== -"@es-joy/jsdoccomment@~0.36.1": - version "0.36.1" - resolved "https://registry.yarnpkg.com/@es-joy/jsdoccomment/-/jsdoccomment-0.36.1.tgz#c37db40da36e4b848da5fd427a74bae3b004a30f" - integrity sha512-922xqFsTpHs6D0BUiG4toiyPOMc8/jafnWKxz1KWgS4XzKPy2qXf1Pe6UFuNSCQqt6tOuhAWXBNuuyUhJmw9Vg== - dependencies: - comment-parser "1.3.1" - esquery "^1.4.0" - jsdoc-type-pratt-parser "~3.1.0" +"@es-joy/jsdoccomment@~0.43.1": + version "0.43.1" + resolved "https://registry.yarnpkg.com/@es-joy/jsdoccomment/-/jsdoccomment-0.43.1.tgz#4b1979b7b4ff8b596fb19a3aa696a438e44608d7" + integrity sha512-I238eDtOolvCuvtxrnqtlBaw0BwdQuYqK7eA6XIonicMdOOOb75mqdIzkGDUbS04+1Di007rgm9snFRNeVrOog== + dependencies: + "@types/eslint" "^8.56.5" + "@types/estree" "^1.0.5" + "@typescript-eslint/types" "^7.2.0" + comment-parser "1.4.1" + esquery "^1.5.0" + jsdoc-type-pratt-parser "~4.0.0" "@eslint-community/eslint-utils@^4.1.2": version "4.1.2" @@ -520,6 +523,14 @@ "@types/estree" "*" "@types/json-schema" "*" +"@types/eslint@^8.56.5": + version "8.56.10" + resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.56.10.tgz#eb2370a73bf04a901eeba8f22595c7ee0f7eb58d" + integrity sha512-Shavhk87gCtY2fhXDctcfS3e6FdxWkCx1iUZ9eEUbh7rTqlZT0/IzOkCOVt0fCjcFuZ9FPYfuezTBImfHCDBGQ== + dependencies: + "@types/estree" "*" + "@types/json-schema" "*" + "@types/estraverse@5.1.2": version "5.1.2" resolved "https://registry.yarnpkg.com/@types/estraverse/-/estraverse-5.1.2.tgz#44672ec45591f54bad039ac243d05826b7e3d825" @@ -532,6 +543,11 @@ resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40" integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ== +"@types/estree@^1.0.5": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4" + integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw== + "@types/events@*": version "3.0.0" resolved "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz" @@ -750,6 +766,11 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.51.0.tgz#e7c1622f46c7eea7e12bbf1edfb496d4dec37c90" integrity sha512-SqOn0ANn/v6hFn0kjvLwiDi4AzR++CBZz0NV5AnusT2/3y32jdc0G4woXPWHCumWtUXZKPAS27/9vziSsC9jnw== +"@typescript-eslint/types@^7.2.0": + version "7.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.13.0.tgz#0cca95edf1f1fdb0cfe1bb875e121b49617477c5" + integrity sha512-QWuwm9wcGMAuTsxP+qz6LBBd3Uq8I5Nv8xb0mk54jmNoCyDspnMvVsOxI6IsMmway5d1S9Su2+sCKv1st2l6eA== + "@typescript-eslint/typescript-estree@5.51.0": version "5.51.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.51.0.tgz#0ec8170d7247a892c2b21845b06c11eb0718f8de" @@ -1053,6 +1074,11 @@ archy@^1.0.0: resolved "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz" integrity sha1-+cjBN1fMHde8N5rHeyxipcKGjEA= +are-docs-informative@^0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/are-docs-informative/-/are-docs-informative-0.0.2.tgz#387f0e93f5d45280373d387a59d34c96db321963" + integrity sha512-ixiS0nLNNG5jNQzgZJNoUpBKdo9yTYZMGJ+QgT2jmjR7G7+QHRCc4v6LQ3NgE7EBJq+o0ams3waJwkrlBom8Ig== + arg@^4.1.0: version "4.1.3" resolved "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz" @@ -1446,10 +1472,10 @@ commander@^9.4.1: resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30" integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ== -comment-parser@1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/comment-parser/-/comment-parser-1.3.1.tgz#3d7ea3adaf9345594aedee6563f422348f165c1b" - integrity sha512-B52sN2VNghyq5ofvUsqZjmk6YkihBX5vMSChmSK9v4ShjKf3Vk5Xcmgpw4o+iIgtrnM/u5FiMpz9VKb8lpBveA== +comment-parser@1.4.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/comment-parser/-/comment-parser-1.4.1.tgz#bdafead37961ac079be11eb7ec65c4d021eaf9cc" + integrity sha512-buhp5kePrmda3vhc5B9t7pUQXAb2Tnd0qgpkIhPhkHXxJpiPJ11H0ZEU0oBpJ2QztSbzG/ZxMj/CHsYJqRHmyg== commondir@^1.0.1: version "1.0.1" @@ -1908,18 +1934,19 @@ eslint-plugin-import@2.27.5: semver "^6.3.0" tsconfig-paths "^3.14.1" -eslint-plugin-jsdoc@40.0.0: - version "40.0.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-40.0.0.tgz#7f433757aa91721e4b88a527dc17ac0437c3c075" - integrity sha512-LOPyIu1vAVvGPkye3ci0moj0iNf3f8bmin6do2DYDj+77NRXWnkmhKRy8swWsatUs3mB5jYPWPUsFg9pyfEiyA== +eslint-plugin-jsdoc@48.2.12: + version "48.2.12" + resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-48.2.12.tgz#e8411c87e55db3f21a288e04bf7e1fb5fa62dfa9" + integrity sha512-sO9sKkJx5ovWoRk9hV0YiNzXQ4Z6j27CqE/po2E3wddZVuy9wvKPSTiIhpxMTrP/qURvKayJIDB2+o9kyCW1Fw== dependencies: - "@es-joy/jsdoccomment" "~0.36.1" - comment-parser "1.3.1" + "@es-joy/jsdoccomment" "~0.43.1" + are-docs-informative "^0.0.2" + comment-parser "1.4.1" debug "^4.3.4" escape-string-regexp "^4.0.0" - esquery "^1.4.0" - semver "^7.3.8" - spdx-expression-parse "^3.0.1" + esquery "^1.5.0" + semver "^7.6.2" + spdx-expression-parse "^4.0.0" eslint-plugin-no-null@1.0.2: version "1.0.2" @@ -2068,6 +2095,13 @@ esquery@^1.4.0: dependencies: estraverse "^5.1.0" +esquery@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.5.0.tgz#6ce17738de8577694edd7361c57182ac8cb0db0b" + integrity sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg== + dependencies: + estraverse "^5.1.0" + esrecurse@^4.3.0: version "4.3.0" resolved "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz" @@ -2359,17 +2393,16 @@ glob-to-regexp@^0.4.1: resolved "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz" integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw== -glob@7.2.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" - integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q== +glob@8.1.0, glob@^8.0.3: + version "8.1.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" + integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== dependencies: fs.realpath "^1.0.0" inflight "^1.0.4" inherits "2" - minimatch "^3.0.4" + minimatch "^5.0.1" once "^1.3.0" - path-is-absolute "^1.0.0" glob@^7.1.3, glob@^7.1.4, glob@^7.1.6: version "7.1.6" @@ -2383,17 +2416,6 @@ glob@^7.1.3, glob@^7.1.4, glob@^7.1.6: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^8.0.3: - version "8.1.0" - resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" - integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^5.0.1" - once "^1.3.0" - globals@^11.1.0: version "11.12.0" resolved "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz" @@ -3072,10 +3094,10 @@ js-yaml@^3.13.1: argparse "^1.0.7" esprima "^4.0.0" -jsdoc-type-pratt-parser@~3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-3.1.0.tgz#a4a56bdc6e82e5865ffd9febc5b1a227ff28e67e" - integrity sha512-MgtD0ZiCDk9B+eI73BextfRrVQl0oyzRG8B2BjORts6jbunj4ScKPcyXGTbB6eXL4y9TzxCm6hyeLq/2ASzNdw== +jsdoc-type-pratt-parser@~4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-4.0.0.tgz#136f0571a99c184d84ec84662c45c29ceff71114" + integrity sha512-YtOli5Cmzy3q4dP26GraSOeAhqecewG04hoO8DY56CH4KJ9Fvv5qKWUCCo3HZob7esJQHCv6/+bnTy72xZZaVQ== jsesc@^2.5.1: version "2.5.2" @@ -3367,10 +3389,10 @@ mkdirp@2.1.3: resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.3.tgz#b083ff37be046fd3d6552468c1f0ff44c1545d1f" integrity sha512-sjAkg21peAG9HS+Dkx7hlG9Ztx7HLeKnvB3NQRcu/mltCVmvkF0pisbiTSfDVYTT86XEfZrTUosLdZLStquZUw== -mocha@10.2.0: - version "10.2.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8" - integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg== +mocha@10.4.0: + version "10.4.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.4.0.tgz#ed03db96ee9cfc6d20c56f8e2af07b961dbae261" + integrity sha512-eqhGB8JKapEYcC4ytX/xrzKforgEc3j1pGlAXVy3eRwrtAy5/nIfT1SvgGzfN0XZZxeLq0aQWkOUAmqIJiv+bA== dependencies: ansi-colors "4.1.1" browser-stdout "1.3.1" @@ -3379,13 +3401,12 @@ mocha@10.2.0: diff "5.0.0" escape-string-regexp "4.0.0" find-up "5.0.0" - glob "7.2.0" + glob "8.1.0" he "1.2.0" js-yaml "4.1.0" log-symbols "4.1.0" minimatch "5.0.1" ms "2.1.3" - nanoid "3.3.3" serialize-javascript "6.0.0" strip-json-comments "3.1.1" supports-color "8.1.1" @@ -3426,11 +3447,6 @@ multimatch@5.0.0: arrify "^2.0.1" minimatch "^3.0.4" -nanoid@3.3.3: - version "3.3.3" - resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25" - integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w== - natural-compare-lite@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4" @@ -4092,6 +4108,11 @@ semver@^7.3.5: dependencies: lru-cache "^6.0.0" +semver@^7.6.2: + version "7.6.2" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13" + integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w== + serialize-javascript@6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" @@ -4251,10 +4272,10 @@ spdx-expression-parse@^3.0.0: spdx-exceptions "^2.1.0" spdx-license-ids "^3.0.0" -spdx-expression-parse@^3.0.1: - version "3.0.1" - resolved "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz" - integrity sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q== +spdx-expression-parse@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/spdx-expression-parse/-/spdx-expression-parse-4.0.0.tgz#a23af9f3132115465dac215c099303e4ceac5794" + integrity sha512-Clya5JIij/7C6bRR22+tnGXbc4VKlibKSVj2iHvVeX5iMW7s1SIQlqu699JkODJJIhh/pUu8L0/VLh8xflD+LQ== dependencies: spdx-exceptions "^2.1.0" spdx-license-ids "^3.0.0" From f886c6c044612e99e229bb03da9fcca201aa0fcd Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sat, 15 Jun 2024 17:57:23 +0400 Subject: [PATCH 08/87] Update class-validator and version (#1262) --- package.json | 4 ++-- webpack/utils/WebpackUtils.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0b8d94610..472dcb1fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "4.1.0", + "version": "4.1.1", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", @@ -27,7 +27,7 @@ "assert": "2.0.0", "chalk": "4.1.2", "chance": "1.1.9", - "class-validator": "0.14.0", + "class-validator": "0.14.1", "commander": "10.0.0", "eslint-scope": "7.1.1", "eslint-visitor-keys": "3.3.0", diff --git a/webpack/utils/WebpackUtils.js b/webpack/utils/WebpackUtils.js index 637958d7e..572e41051 100644 --- a/webpack/utils/WebpackUtils.js +++ b/webpack/utils/WebpackUtils.js @@ -1,6 +1,6 @@ const fs = require('fs'); -const copyright = 'Copyright (C) 2016-2022 Timofey Kachalov '; +const copyright = 'Copyright (C) 2016-2024 Timofey Kachalov '; const sourceMapSupportRequire = 'require("source-map-support").install();'; class WebpackUtils { From 828a190cf80a86227ef77be38e99aad9838aed70 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sat, 15 Jun 2024 21:29:00 +0400 Subject: [PATCH 09/87] Update CHANGELOG.md --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2021dcc59..8f2a55c88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ Change Log +v4.1.1 +--- +* Update supported Node.js versions up to `node@22`. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/pull/1100 +* Update `class-validator` version. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1247 +* Fixed CI + v4.1.0 --- * Add target `service-worker` @@ -938,4 +944,4 @@ v0.7.0-dev.1 * **Breaking API change:** now `obfuscate(sourceCode, options)` returns `ObfuscationResult` object instead `string`. `ObfuscationResult` object contains two public methods: `getObfuscatedCode()` and `getSourceMap()`. * CLI. Now any code can be obfuscated through CLI `javascript-obfuscator` command. See `README.md` for available options. * New option `sourceMap` enables source map generation for obfuscated code. -* New option `sourceMapMode` specifies source map generation mode. \ No newline at end of file +* New option `sourceMapMode` specifies source map generation mode. From d5497db9d62784e91ab7aa7824b054701a556934 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Thu, 30 Oct 2025 10:18:54 +0400 Subject: [PATCH 10/87] Add claude.md file (#1326) --- .github/workflows/ci.yml | 2 +- .gitignore | 1 + .npmignore | 1 + CLAUDE.md | 1478 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 1481 insertions(+), 1 deletion(-) create mode 100644 CLAUDE.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a64df512a..930f6ca04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - uses: actions/cache@v2 + - uses: actions/cache@v4 with: path: '**/node_modules' key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} diff --git a/.gitignore b/.gitignore index b79ba16a5..cfe4fd231 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.claude .DS_Store .idea .nyc_output diff --git a/.npmignore b/.npmignore index 217c06850..d202d73b5 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,5 @@ .awcache +.claude .github .idea .nyc_output diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 000000000..ae03f9f12 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,1478 @@ +# JavaScript Obfuscator - Project Documentation + +## Project Overview + +**JavaScript Obfuscator** is a powerful, enterprise-grade code obfuscation tool for JavaScript and Node.js applications. It transforms readable JavaScript code into a protected, difficult-to-understand format while maintaining full functionality. The project is widely used for protecting intellectual property and preventing reverse engineering. + +- **Version**: 4.1.1 +- **Author**: Timofey Kachalov (@sanex3339) +- **License**: BSD-2-Clause +- **Repository**: https://github.com/javascript-obfuscator/javascript-obfuscator +- **Homepage**: https://obfuscator.io/ +- **Node Requirement**: >=12.22.0 + +## Key Features + +### Core Obfuscation Techniques + +1. **Variable & Function Renaming**: Replaces identifiable names with cryptic hexadecimal or mangled identifiers +2. **String Extraction & Encryption**: Moves string literals to an encoded array with base64/rc4 encryption +3. **Dead Code Injection**: Inserts non-functional code blocks to confuse static analysis +4. **Control Flow Flattening**: Restructures code flow using switch statements to obscure logic +5. **Code Transformations**: Multiple AST-level transformations including: + - Boolean literal obfuscation + - Number to expression conversion + - Object key transformation + - Template literal transformation + - Property renaming (safe/unsafe modes) + +### Advanced Protection Features + +- **Self-Defending Code**: Code that breaks when beautified or modified +- **Debug Protection**: Anti-debugging mechanisms to prevent DevTools usage +- **Domain Lock**: Restricts code execution to specific domains/subdomains +- **Console Output Disabling**: Removes console.* functionality +- **Unicode Escape Sequences**: Additional string obfuscation layer + +## Architecture Overview + +### Technology Stack + +- **Language**: TypeScript 4.9.5 +- **Parser**: Acorn 8.8.2 (ES3-ES2020 support) +- **Code Generator**: @javascript-obfuscator/escodegen 2.3.0 +- **AST Traversal**: @javascript-obfuscator/estraverse 5.4.0 +- **DI Framework**: InversifyJS 6.0.1 +- **Testing**: Mocha 10.4.0 + Chai 4.3.7 +- **Build System**: Webpack 5.75.0 + +### Project Structure + +``` +javascript-obfuscator/ +├── src/ # Source code +│ ├── JavaScriptObfuscator.ts # Main obfuscator class +│ ├── JavaScriptObfuscatorFacade.ts # Public API facade +│ ├── JavaScriptObfuscatorCLIFacade.ts # CLI interface +│ ├── ASTParserFacade.ts # AST parsing wrapper +│ │ +│ ├── analyzers/ # Code analysis components +│ │ ├── calls-graph-analyzer/ # Function call graph analysis +│ │ ├── scope-analyzer/ # Variable scope analysis +│ │ ├── string-array-storage-analyzer/ # String array optimization +│ │ ├── number-numerical-expression-analyzer/ +│ │ └── prevailing-kind-of-variables-analyzer/ +│ │ +│ ├── node-transformers/ # AST transformation pipeline +│ │ ├── AbstractNodeTransformer.ts +│ │ ├── NodeTransformersRunner.ts +│ │ ├── converting-transformers/ # Node type conversions +│ │ ├── control-flow-transformers/ # Control flow flattening +│ │ ├── dead-code-injection-transformers/ # Dead code generation +│ │ ├── finalizing-transformers/ # Post-processing transforms +│ │ ├── initializing-transformers/ # Pre-processing transforms +│ │ ├── preparing-transformers/ # Preparation phase +│ │ ├── rename-identifiers-transformers/ # Variable renaming +│ │ ├── rename-properties-transformers/ # Property renaming +│ │ ├── simplifying-transformers/ # Code simplification +│ │ └── string-array-transformers/ # String array handling +│ │ +│ ├── code-transformers/ # Code-level (not AST) transformers +│ │ ├── AbstractCodeTransformer.ts +│ │ ├── CodeTransformersRunner.ts +│ │ └── CodeTransformerNamesGroupsBuilder.ts +│ │ +│ ├── custom-code-helpers/ # Injectable code helpers +│ │ ├── common/ # Global variable templates +│ │ ├── console-output/ # Console disabling templates +│ │ ├── debug-protection/ # Anti-debugging templates +│ │ ├── domain-lock/ # Domain restriction templates +│ │ ├── self-defending/ # Self-defense templates +│ │ └── string-array/ # String array wrapper templates +│ │ +│ ├── custom-nodes/ # Custom AST node generators +│ │ ├── control-flow-flattening-nodes/ +│ │ ├── dead-code-injection-nodes/ +│ │ ├── object-expression-keys-transformer-nodes/ +│ │ └── string-array-nodes/ +│ │ +│ ├── container/ # Dependency injection +│ │ ├── InversifyContainerFacade.ts +│ │ ├── ServiceIdentifiers.ts +│ │ └── modules/ # DI module definitions +│ │ +│ ├── options/ # Configuration system +│ │ ├── Options.ts +│ │ ├── OptionsNormalizer.ts +│ │ ├── validators/ # Option validation +│ │ ├── normalizer-rules/ # Option normalization +│ │ └── presets/ # Obfuscation presets +│ │ +│ ├── storages/ # Data storage components +│ │ ├── string-array-transformers/ +│ │ ├── control-flow-transformers/ +│ │ ├── custom-code-helpers/ +│ │ └── identifier-names-cache/ +│ │ +│ ├── node/ # AST node utilities +│ │ ├── NodeGuards.ts # Type guards +│ │ ├── NodeFactory.ts # Node creation +│ │ ├── NodeAppender.ts # Node insertion +│ │ ├── NodeStatementUtils.ts +│ │ └── NodeUtils.ts +│ │ +│ ├── generators/ # Name/value generators +│ │ ├── identifier-names-generators/ +│ │ └── string-array-index-nodes-generators/ +│ │ +│ ├── utils/ # Utility functions +│ │ ├── RandomGenerator.ts +│ │ ├── ArrayUtils.ts +│ │ ├── CryptUtils.ts +│ │ ├── LevelledTopologicalSorter.ts +│ │ └── Utils.ts +│ │ +│ ├── cli/ # CLI utilities +│ │ ├── sanitizers/ # Input sanitizers +│ │ └── utils/ # File handling +│ │ +│ ├── enums/ # Enumerations +│ ├── interfaces/ # TypeScript interfaces +│ ├── types/ # Type definitions +│ ├── constants/ # Constants +│ ├── decorators/ # Decorators +│ └── logger/ # Logging system +│ +├── test/ # Test suite +│ ├── functional-tests/ # Feature tests +│ ├── unit-tests/ # Unit tests +│ ├── performance-tests/ # Performance benchmarks +│ └── index.spec.ts +│ +├── webpack/ # Build configurations +│ ├── webpack.node.config.js +│ └── webpack.browser.config.js +│ +├── dist/ # Compiled output +│ ├── index.js # Node.js bundle +│ └── index.browser.js # Browser bundle +│ +├── bin/ # CLI executable +│ └── javascript-obfuscator +│ +└── typings/ # TypeScript declarations +``` + +## Core Workflow + +### Obfuscation Pipeline + +The obfuscation process follows a multi-stage pipeline defined in `JavaScriptObfuscator.ts`: + +``` +1. Code Transformation Stage: PreparingTransformers + └─> Raw code preprocessing (e.g., hashbang handling) + +2. AST Parsing + └─> Parse source code into ESTree-compliant AST using Acorn + +3. Node Transformation Stages (sequential): + ├─> Initializing + │ └─> Initial AST setup, parentification, metadata + ├─> Preparing + │ └─> Scope analysis, obfuscating guards, identifier collection + ├─> DeadCodeInjection (optional) + │ └─> Insert dead code blocks + ├─> ControlFlowFlattening (optional) + │ └─> Flatten control flow with switch statements + ├─> RenameProperties (optional) + │ └─> Rename object properties + ├─> Converting + │ └─> Transform nodes (literals, expressions, etc.) + ├─> RenameIdentifiers + │ └─> Rename variables and functions + ├─> StringArray + │ └─> Extract strings to array, add wrappers + ├─> Simplifying (optional) + │ └─> Simplify and merge statements + └─> Finalizing + └─> Final cleanup, directive placement + +4. Code Generation + └─> Generate obfuscated code using escodegen + +5. Code Transformation Stage: FinalizingTransformers + └─> Post-processing on generated code + +6. Source Map Generation (optional) + └─> Create source maps for debugging +``` + +### Dependency Injection Architecture + +The project uses **InversifyJS** for dependency injection, providing: + +- **Modularity**: Clean separation of concerns +- **Testability**: Easy mocking and testing +- **Flexibility**: Runtime configuration of transformers +- **Scalability**: Easy addition of new transformers + +All components are registered in container modules located in `src/container/modules/`. + +## Key Components Deep Dive + +### 1. JavaScriptObfuscator (Main Engine) + +**Location**: `src/JavaScriptObfuscator.ts` + +The core orchestrator that: +- Manages the complete obfuscation pipeline +- Coordinates code and node transformers +- Handles AST parsing and code generation +- Integrates with logger and random generator + +**Key Methods**: +- `obfuscate(sourceCode: string): IObfuscationResult` - Main entry point +- `parseCode()` - AST parsing with Acorn +- `transformAstTree()` - Applies transformation stages +- `generateCode()` - Code generation with escodegen + +### 2. Node Transformers + +**Location**: `src/node-transformers/` + +Each transformer implements `INodeTransformer` interface with: +- `getVisitor(stage): IVisitor | null` - Returns visitor for specific stage +- `transformNode(node, parent): Node` - Transforms individual AST node + +**Key Transformers**: + +- **StringArrayTransformer**: Extracts string literals to centralized array +- **BooleanLiteralTransformer**: Converts true/false to `!![]` and `![]` +- **NumberToNumericalExpressionTransformer**: Converts numbers to expressions +- **BlockStatementControlFlowTransformer**: Implements control flow flattening +- **DeadCodeInjectionTransformer**: Injects dead code blocks +- **RenamePropertiesTransformer**: Renames object properties +- **ScopeIdentifiersTransformer**: Renames variables based on scope + +### 3. Analyzers + +**Location**: `src/analyzers/` + +- **CallsGraphAnalyzer**: Builds function call dependency graph +- **ScopeAnalyzer**: Analyzes variable scopes using eslint-scope +- **StringArrayStorageAnalyzer**: Optimizes string array storage +- **PrevailingKindOfVariablesAnalyzer**: Determines var/let/const usage +- **NumberNumericalExpressionAnalyzer**: Analyzes numeric expressions + +### 4. Custom Code Helpers + +**Location**: `src/custom-code-helpers/` + +Injectable runtime helpers that provide: +- **String Array Decoders**: Base64/RC4 decoding functions +- **Debug Protection**: Anti-debugging wrapper code +- **Domain Lock**: Domain validation code +- **Self-Defending**: Code integrity checks +- **Console Output Disable**: Console method replacements + +### 5. Options System + +**Location**: `src/options/` + +Sophisticated configuration system with: +- **Validation**: Using class-validator decorators +- **Normalization**: Automatic option interdependency handling +- **Presets**: Default, low, medium, and high obfuscation presets +- **Type Safety**: Full TypeScript support + +**Key Option Categories**: +- Code output (compact, target) +- String transformations (stringArray*, splitStrings) +- Control flow (controlFlowFlattening, deadCodeInjection) +- Naming (identifierNamesGenerator, renameGlobals, renameProperties) +- Protection (selfDefending, debugProtection, domainLock) +- Advanced (numbersToExpressions, simplify, transformObjectKeys) + +## Important Patterns and Conventions + +### 1. Visitor Pattern + +Transformers use the visitor pattern for AST traversal: + +```typescript +interface IVisitor { + enter?: (node: Node, parent: Node) => Node | VisitorOption; + leave?: (node: Node, parent: Node) => Node | VisitorOption; +} +``` + +### 2. Initializable Pattern + +Many components implement `IInitializable` for lazy initialization: + +```typescript +interface IInitializable { + initialize(...args: any[]): void; +} +``` + +Managed via `@Initializable()` decorator. + +### 3. Stage-Based Processing + +Both code and node transformers operate in stages: + +**Code Transformation Stages**: +- PreparingTransformers +- FinalizingTransformers + +**Node Transformation Stages**: +- Initializing +- Preparing +- DeadCodeInjection +- ControlFlowFlattening +- RenameProperties +- Converting +- RenameIdentifiers +- StringArray +- Simplifying +- Finalizing + +### 4. Factory Pattern + +Extensive use of factories for object creation: +- `TObfuscationResultFactory` +- Custom node factories +- Identifier name generators + +### 5. Storage Pattern + +Centralized storages for shared data: +- String array storage +- Custom code helpers storage +- Identifier names cache storage +- Control flow transformers storage + +## CLI Usage + +**Location**: `bin/javascript-obfuscator`, `src/JavaScriptObfuscatorCLIFacade.ts` + +### Basic Commands + +```bash +# Obfuscate single file +javascript-obfuscator input.js --output output.js + +# Obfuscate directory +javascript-obfuscator ./src --output ./dist + +# Use configuration file +javascript-obfuscator input.js --config config.json + +# High obfuscation preset +javascript-obfuscator input.js --options-preset high-obfuscation +``` + +### CLI Features + +- Automatic identifier prefix for multiple files +- Glob pattern exclusions +- Source map support +- Identifier names cache (cross-file consistency) +- Progress logging + +## API Usage + +### Basic Obfuscation + +```javascript +const JavaScriptObfuscator = require('javascript-obfuscator'); + +const obfuscationResult = JavaScriptObfuscator.obfuscate( + ` + var foo = 'Hello World'; + console.log(foo); + `, + { + compact: true, + controlFlowFlattening: true + } +); + +console.log(obfuscationResult.getObfuscatedCode()); +console.log(obfuscationResult.getSourceMap()); +console.log(obfuscationResult.getIdentifierNamesCache()); +``` + +### Multiple Files + +```javascript +const sourceCodesObject = { + 'file1.js': 'var foo = 1;', + 'file2.js': 'var bar = 2;' +}; + +const obfuscationResults = JavaScriptObfuscator.obfuscateMultiple( + sourceCodesObject, + options +); +``` + +### Identifier Names Cache (Cross-File Consistency) + +```javascript +// First file +const result1 = JavaScriptObfuscator.obfuscate(code1, { + identifierNamesCache: {}, + renameGlobals: true +}); +const cache = result1.getIdentifierNamesCache(); + +// Second file using same cache +const result2 = JavaScriptObfuscator.obfuscate(code2, { + identifierNamesCache: cache, + renameGlobals: true +}); +``` + +## Browser Support + +The project includes a browser build at `dist/index.browser.js` that can be used in web environments: + +```html + + +``` + +**Note**: No eval() in `browser-no-eval` target. + +## Build System + +### Webpack Configuration + +- **Node.js build**: `webpack/webpack.node.config.js` + - Target: CommonJS module + - External dependencies: node_modules + - Output: `dist/index.js` + +- **Browser build**: `webpack/webpack.browser.config.js` + - Target: UMD module + - Bundled dependencies + - Output: `dist/index.browser.js` + +### Build Scripts + +```bash +# Production build +npm run build + +# Development watch mode +npm run watch + +# Build TypeScript typings +npm run build:typings + +# Linting +npm run eslint +``` + +## Testing + +### Test Structure + +**Location**: `test/` + +- **Functional tests**: Feature-level tests for transformers and options +- **Unit tests**: Component-level tests +- **Performance tests**: Memory and speed benchmarks + +### Running Tests + +#### Quick Start + +```bash +# Install dependencies first +npm install +# or +yarn install + +# Run all tests (includes dev test, coverage, and memory performance) +npm test +# or +yarn test +``` + +#### Individual Test Commands + +```bash +# Run full test suite (test:dev + test:mocha-coverage + test:mocha-memory-performance). This is slow. +npm run test:full +yarn run test:full + +# Run Mocha tests only (no coverage) +npm run test:mocha +yarn run test:mocha + +# Run tests with coverage report +npm run test:mocha-coverage +yarn run test:mocha-coverage + +# Generate detailed coverage report (after running test:mocha-coverage) +npm run test:mocha-coverage:report +yarn run test:mocha-coverage:report + +# Run memory performance tests (tests memory constraints) +npm run test:mocha-memory-performance +yarn run test:mocha-memory-performance + +# Run development test (custom dev test file) +npm run test:dev +yarn run test:dev + +# Run compile performance test +npm run test:devCompilePerformance +yarn run test:devCompilePerformance + +# Run runtime performance test +npm run test:devRuntimePerformance +yarn run test:devRuntimePerformance +``` + +#### Test Details + +**test:full** +- Runs the complete test suite +- Includes: development tests, coverage tests, and memory performance tests +- This is what runs when you execute `npm test` + +**test:mocha** +- Runs all Mocha tests from `test/index.spec.ts` +- Uses ts-node for TypeScript execution +- No code coverage reporting + +**test:mocha-coverage** +- Runs Mocha tests with NYC (Istanbul) code coverage +- Allocates up to 4GB memory (`--max-old-space-size=4096`) +- Generates coverage reports (text-summary by default) +- Use `test:mocha-coverage:report` to generate detailed lcov report + +**test:mocha-memory-performance** +- Tests obfuscator memory usage under constraints +- Allocates only 280MB memory to test memory efficiency +- Located at: `test/performance-tests/JavaScriptObfuscatorMemory.spec.ts` + +**test:dev** +- Custom development test script +- Located at: `test/dev/dev.ts` +- Useful for quick testing during development + +### Test Configuration Files + +- **`.mocharc.json`**: Mocha test runner configuration +- **`.nycrc.json`**: NYC (Istanbul) coverage tool configuration +- **TypeScript**: Uses ts-node for direct TS execution without compilation + +### Running Specific Test Files + +You can run individual test files or groups of tests for faster iteration during development. + +#### Basic Command Format + +```bash +npx mocha --require ts-node/register --require source-map-support/register +``` + +#### Common Examples + +```bash +# Run a specific test file by exact path +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/options/Options.spec.ts + +# Run CLI tests +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/cli/JavaScriptObfuscatorCLI.spec.ts + +# Run a specific analyzer test +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.spec.ts + +# Run scope analyzer tests +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts + +# Run string array tests +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/custom-code-helpers/string-array/StringArrayCodeHelper.spec.ts + +# Run self-defending code tests +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/custom-code-helpers/self-defending/SelfDefendingCodeHelper.spec.ts +``` + +#### Pattern Matching + +Use glob patterns to run multiple related test files: + +```bash +# Run all options-related tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/options/**/*.spec.ts" + +# Run all analyzer tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/analyzers/**/*.spec.ts" + +# Run all string array related tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/**/*StringArray*.spec.ts" + +# Run all control flow tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/**/*ControlFlow*.spec.ts" + +# Run all node transformer tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/node-transformers/**/*.spec.ts" + +# Run all unit tests only +npx mocha --require ts-node/register --require source-map-support/register "test/unit-tests/**/*.spec.ts" + +# Run all functional tests only +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/**/*.spec.ts" +``` + +#### Running Tests by Category + +The test suite is organized into these main categories: + +**Functional Tests** (`test/functional-tests/`): +```bash +# Options tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/options/**/*.spec.ts" + +# Analyzers tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/analyzers/**/*.spec.ts" + +# Node transformers tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/node-transformers/**/*.spec.ts" + +# Code transformers tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/code-transformers/**/*.spec.ts" + +# Custom code helpers tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/custom-code-helpers/**/*.spec.ts" + +# Storage tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/storages/**/*.spec.ts" + +# CLI tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/cli/**/*.spec.ts" + +# Generator tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/generators/**/*.spec.ts" + +# Main obfuscator tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/javascript-obfuscator/**/*.spec.ts" + +# Issue regression tests +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/issues/**/*.spec.ts" +``` + +**Unit Tests** (`test/unit-tests/`): +```bash +# All unit tests +npx mocha --require ts-node/register --require source-map-support/register "test/unit-tests/**/*.spec.ts" + +# Options unit tests +npx mocha --require ts-node/register --require source-map-support/register "test/unit-tests/options/**/*.spec.ts" + +# Utils unit tests +npx mocha --require ts-node/register --require source-map-support/register "test/unit-tests/utils/**/*.spec.ts" + +# Node utilities unit tests +npx mocha --require ts-node/register --require source-map-support/register "test/unit-tests/node/**/*.spec.ts" +``` + +**Performance Tests** (`test/performance-tests/`): +```bash +# Memory performance tests +npx mocha --require ts-node/register --require source-map-support/register test/performance-tests/JavaScriptObfuscatorMemory.spec.ts +``` + +#### Using Mocha Options with Individual Tests + +```bash +# Run with grep to filter by test description +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/options/Options.spec.ts --grep "compact" + +# Run and show slow tests +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/options/Options.spec.ts --reporter spec + +# Run with timeout override (default is 10000ms) +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/options/Options.spec.ts --timeout 20000 + +# Run with bail (stop on first failure) +npx mocha --require ts-node/register --require source-map-support/register "test/functional-tests/**/*.spec.ts" --bail + +# Run and watch for changes +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/options/Options.spec.ts --watch + +# Run with specific reporter +npx mocha --require ts-node/register --require source-map-support/register test/functional-tests/options/Options.spec.ts --reporter json +``` + +#### Creating Test Aliases (Optional) + +For convenience, you can add these aliases to your `package.json` scripts: + +```json +{ + "scripts": { + "test:options": "mocha --require ts-node/register --require source-map-support/register 'test/functional-tests/options/**/*.spec.ts'", + "test:analyzers": "mocha --require ts-node/register --require source-map-support/register 'test/functional-tests/analyzers/**/*.spec.ts'", + "test:transformers": "mocha --require ts-node/register --require source-map-support/register 'test/functional-tests/node-transformers/**/*.spec.ts'", + "test:unit": "mocha --require ts-node/register --require source-map-support/register 'test/unit-tests/**/*.spec.ts'", + "test:functional": "mocha --require ts-node/register --require source-map-support/register 'test/functional-tests/**/*.spec.ts'" + } +} +``` + +Then run with: +```bash +npm run test:options +npm run test:analyzers +npm run test:transformers +``` + +#### Tips for Running Individual Tests + +1. **Use quotes around glob patterns** to prevent shell expansion: + ```bash + # Good + npx mocha "test/**/*.spec.ts" + + # Bad (shell will expand the pattern) + npx mocha test/**/*.spec.ts + ``` + +2. **Use --grep to run specific test cases** within a file: + ```bash + npx mocha --require ts-node/register test/functional-tests/options/Options.spec.ts --grep "should enable compact" + ``` + +3. **Use --bail to stop on first failure** when debugging: + ```bash + npx mocha --require ts-node/register "test/**/*.spec.ts" --bail + ``` + +4. **Check the exit code** to verify test success in scripts: + ```bash + npx mocha --require ts-node/register test/functional-tests/options/Options.spec.ts && echo "Tests passed!" + ``` + +5. **Combine with watch mode** for TDD workflow: + ```bash + npx mocha --require ts-node/register test/functional-tests/options/Options.spec.ts --watch --reporter min + ``` + +## Linting + +### Running ESLint + +#### Quick Start + +```bash +# Lint all TypeScript files in src/ +npm run eslint +yarn run eslint +``` + +This runs: `eslint src/**/*.ts` + +#### Linting Individual Files + +You can lint specific files or directories for faster feedback during development. + +**Basic Command Format:** +```bash +npx eslint +``` + +**Common Examples:** + +```bash +# Lint a specific file +npx eslint src/JavaScriptObfuscator.ts + +# Lint the main facade file +npx eslint src/JavaScriptObfuscatorFacade.ts + +# Lint a specific transformer +npx eslint src/node-transformers/converting-transformers/StringArrayTransformer.ts + +# Lint a specific analyzer +npx eslint src/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.ts + +# Lint options file +npx eslint src/options/Options.ts + +# Lint a custom code helper +npx eslint src/custom-code-helpers/string-array/StringArrayCodeHelper.ts + +# Lint container files +npx eslint src/container/InversifyContainerFacade.ts +``` + +#### Linting Multiple Files or Directories + +```bash +# Lint entire src directory +npx eslint src/ + +# Lint all files in a specific subdirectory +npx eslint src/node-transformers/ + +# Lint all analyzers +npx eslint src/analyzers/ + +# Lint all transformers +npx eslint src/node-transformers/**/*.ts + +# Lint all options-related files +npx eslint src/options/ + +# Lint all custom code helpers +npx eslint src/custom-code-helpers/ + +# Lint all utils +npx eslint src/utils/ + +# Lint CLI files +npx eslint src/cli/ + +# Lint container modules +npx eslint src/container/ + +# Lint storage files +npx eslint src/storages/ +``` + +#### Using Glob Patterns + +```bash +# Lint all TypeScript files in src (same as npm run eslint) +npx eslint "src/**/*.ts" + +# Lint all transformer files +npx eslint "src/**/*Transformer.ts" + +# Lint all analyzer files +npx eslint "src/**/*Analyzer.ts" + +# Lint all storage files +npx eslint "src/**/*Storage.ts" + +# Lint all helper files +npx eslint "src/**/*Helper.ts" + +# Lint all files containing "String" in the name +npx eslint "src/**/*String*.ts" + +# Lint all files in node-transformers subdirectories +npx eslint "src/node-transformers/**/*.ts" +``` + +#### Auto-fixing Issues + +ESLint can automatically fix many issues: + +```bash +# Auto-fix all files in src/ +npx eslint src/**/*.ts --fix + +# Auto-fix a specific file +npx eslint src/JavaScriptObfuscator.ts --fix + +# Auto-fix specific directory +npx eslint src/node-transformers/ --fix + +# Auto-fix with glob pattern +npx eslint "src/analyzers/**/*.ts" --fix + +# Auto-fix only safe fixes (no potentially breaking changes) +npx eslint src/JavaScriptObfuscator.ts --fix --fix-type suggestion,layout +``` + +#### Checking Specific Rules + +```bash +# Show only errors (no warnings) +npx eslint src/JavaScriptObfuscator.ts --quiet + +# Check specific rule only +npx eslint src/JavaScriptObfuscator.ts --rule 'no-console: error' + +# Disable specific rules for a file check +npx eslint src/JavaScriptObfuscator.ts --rule 'no-console: off' + +# Output format options +npx eslint src/JavaScriptObfuscator.ts --format stylish # Default +npx eslint src/JavaScriptObfuscator.ts --format json # JSON output +npx eslint src/JavaScriptObfuscator.ts --format compact # Compact output +npx eslint src/JavaScriptObfuscator.ts --format unix # Unix style +``` + +#### Getting Detailed Information + +```bash +# Show more details about errors +npx eslint src/JavaScriptObfuscator.ts --format stylish + +# List all files that would be linted (dry-run) +npx eslint src/ --debug 2>&1 | grep "Processing" + +# Show timing information for rules +npx eslint src/JavaScriptObfuscator.ts --debug + +# Get statistics about linting +npx eslint src/ --format json | jq '.[] | {file: .filePath, errors: .errorCount, warnings: .warningCount}' +``` + +#### Linting by Component + +Organized by project structure: + +**Core Files:** +```bash +npx eslint src/JavaScriptObfuscator.ts +npx eslint src/JavaScriptObfuscatorFacade.ts +npx eslint src/ASTParserFacade.ts +``` + +**Node Transformers:** +```bash +# All node transformers +npx eslint src/node-transformers/ + +# Converting transformers +npx eslint src/node-transformers/converting-transformers/ + +# Control flow transformers +npx eslint src/node-transformers/control-flow-transformers/ + +# String array transformers +npx eslint src/node-transformers/string-array-transformers/ + +# Rename transformers +npx eslint src/node-transformers/rename-identifiers-transformers/ +npx eslint src/node-transformers/rename-properties-transformers/ +``` + +**Analyzers:** +```bash +# All analyzers +npx eslint src/analyzers/ + +# Specific analyzers +npx eslint src/analyzers/calls-graph-analyzer/ +npx eslint src/analyzers/scope-analyzer/ +npx eslint src/analyzers/string-array-storage-analyzer/ +``` + +**Options System:** +```bash +# All options files +npx eslint src/options/ + +# Core options +npx eslint src/options/Options.ts +npx eslint src/options/OptionsNormalizer.ts + +# Validators +npx eslint src/options/validators/ + +# Presets +npx eslint src/options/presets/ +``` + +**Custom Code Helpers:** +```bash +# All helpers +npx eslint src/custom-code-helpers/ + +# String array helpers +npx eslint src/custom-code-helpers/string-array/ + +# Debug protection helpers +npx eslint src/custom-code-helpers/debug-protection/ + +# Self-defending helpers +npx eslint src/custom-code-helpers/self-defending/ +``` + +**Utilities:** +```bash +# All utils +npx eslint src/utils/ + +# Specific utils +npx eslint src/utils/RandomGenerator.ts +npx eslint src/utils/ArrayUtils.ts +npx eslint src/utils/CryptUtils.ts +``` + +#### Integrating with Git + +```bash +# Lint only staged files (useful for pre-commit) +git diff --cached --name-only --diff-filter=ACM | grep '\.ts$' | xargs npx eslint + +# Lint files changed in current branch +git diff --name-only master | grep '\.ts$' | xargs npx eslint + +# Lint files changed in last commit +git diff HEAD~1 --name-only | grep '\.ts$' | xargs npx eslint +``` + +#### Creating Lint Aliases (Optional) + +Add these to your `package.json` scripts for convenience: + +```json +{ + "scripts": { + "lint": "eslint src/**/*.ts", + "lint:fix": "eslint src/**/*.ts --fix", + "lint:transformers": "eslint src/node-transformers/**/*.ts", + "lint:analyzers": "eslint src/analyzers/**/*.ts", + "lint:options": "eslint src/options/**/*.ts", + "lint:utils": "eslint src/utils/**/*.ts", + "lint:quiet": "eslint src/**/*.ts --quiet", + "lint:staged": "git diff --cached --name-only --diff-filter=ACM | grep '\\.ts$' | xargs eslint" + } +} +``` + +Then run with: +```bash +npm run lint:transformers +npm run lint:analyzers +npm run lint:fix +``` + +### ESLint Configuration + +**Location**: `.eslintrc.js` + +The project uses: +- **@typescript-eslint**: TypeScript-specific linting rules +- **eslint-plugin-import**: Import/export validation +- **eslint-plugin-jsdoc**: JSDoc comment validation +- **eslint-plugin-no-null**: Prevents null usage (prefer undefined) +- **eslint-plugin-prefer-arrow**: Enforces arrow functions +- **eslint-plugin-unicorn**: Additional code quality rules + +**Ignored files**: `.eslintignore` + +#### Viewing Current ESLint Config + +```bash +# Print effective configuration for a file +npx eslint --print-config src/JavaScriptObfuscator.ts + +# List all rules being applied +npx eslint --print-config src/JavaScriptObfuscator.ts | grep rules -A 1000 +``` + +### Code Quality Checks + +```bash +# Run full build (includes webpack, eslint, and tests) +npm run build +yarn run build + +# The build script runs: +# 1. webpack:prod (production build) +# 2. eslint (linting) +# 3. test (full test suite) +``` + +### Tips for Effective Linting + +1. **Lint before committing**: Always run linting before creating commits + ```bash + npx eslint src/ && git commit -m "Your message" + ``` + +2. **Use --fix cautiously**: Review changes before committing auto-fixes + ```bash + npx eslint src/MyFile.ts --fix + git diff # Review changes + ``` + +3. **Focus on errors first**: Use `--quiet` to see only errors + ```bash + npx eslint src/ --quiet + ``` + +4. **Lint specific files during development**: Don't lint everything when working on one file + ```bash + npx eslint src/node-transformers/MyNewTransformer.ts + ``` + +5. **Check exit code**: Useful in scripts and CI/CD + ```bash + npx eslint src/ || echo "Linting failed!" + ``` + +## Development Workflow + +### Setting Up Development Environment + +```bash +# 1. Clone the repository +git clone https://github.com/javascript-obfuscator/javascript-obfuscator.git +cd javascript-obfuscator + +# 2. Install dependencies +npm install +# or +yarn install + +# 3. Install Husky hooks (for pre-commit checks) +npm run prepare +# or +yarn run prepare +``` + +### Development Commands + +```bash +# Start development mode with watch (auto-recompile on changes) +npm start +# or +npm run watch +# or +yarn run watch + +# Build for production +npm run webpack:prod +yarn run webpack:prod + +# Build TypeScript type definitions +npm run build:typings +yarn run build:typings + +# Full build (webpack + eslint + tests) +npm run build +yarn run build +``` + +### Pre-commit Hooks + +The project uses **Husky** for git hooks: + +- **pre-commit**: Automatically runs `npm run build` before each commit + - Ensures code compiles + - Ensures linting passes + - Ensures all tests pass + +**Configuration**: `.husky/` directory + +### Development Tips + +1. **Use watch mode during development**: + ```bash + npm run watch + ``` + This rebuilds automatically when you save files. + +2. **Run specific tests during development**: + ```bash + npm run test:dev + ``` + Faster than full test suite. + +3. **Check linting before committing**: + ```bash + npm run eslint + ``` + Fix issues before the pre-commit hook runs. + +4. **Test memory usage**: + ```bash + npm run test:mocha-memory-performance + ``` + Ensure your changes don't cause memory issues. + +5. **Generate coverage reports**: + ```bash + npm run test:mocha-coverage + npm run test:mocha-coverage:report + ``` + Check test coverage in the generated `coverage/` directory. + +## Performance Considerations + +### Impact on Code Size + +- **Default**: ~15-30% increase +- **Dead Code Injection**: Up to 200% increase +- **String Array**: 20-50% increase +- **Control Flow Flattening**: 30-80% increase + +### Runtime Performance + +- **No obfuscation**: Baseline +- **Low preset**: ~10-20% slower +- **Medium preset**: ~30-50% slower +- **High preset**: ~50-80% slower + +### Optimization Tips + +1. Use **thresholds** to apply transformations selectively: + - `controlFlowFlatteningThreshold` + - `deadCodeInjectionThreshold` + - `stringArrayThreshold` + +2. Avoid obfuscating: + - Third-party libraries + - Polyfills + - Large vendor bundles + +3. Use **seed** option for reproducible builds + +4. Enable **simplify** for better performance (enabled by default) + +## Security Considerations + +### What It Protects + +- Makes reverse engineering harder +- Prevents casual code inspection +- Protects string literals and algorithms +- Adds anti-debugging measures +- Can lock code to specific domains + +### What It Doesn't Protect + +- Determined attackers with time and tools +- Network traffic and API endpoints +- Runtime behavior analysis +- Secrets embedded in code (use environment variables!) + +### Best Practices + +1. **Never obfuscate secrets**: Use environment variables or secure vaults +2. **Combine with other protections**: Minification, HTTPS, CSP headers +3. **Test thoroughly**: Obfuscation can introduce subtle bugs +4. **Monitor performance**: High obfuscation impacts runtime speed +5. **Use source maps carefully**: Keep them private for debugging + +## Conditional Comments + +Control obfuscation for specific code sections: + +```javascript +var foo = 1; +// javascript-obfuscator:disable +var bar = 2; // This won't be obfuscated +// javascript-obfuscator:enable +var baz = 3; +``` + +## Integration with Build Tools + +### Webpack + +Use [webpack-obfuscator](https://github.com/javascript-obfuscator/webpack-obfuscator) plugin + +### Gulp + +Use [gulp-javascript-obfuscator](https://github.com/javascript-obfuscator/gulp-javascript-obfuscator) + +### Rollup + +Use [rollup-plugin-javascript-obfuscator](https://github.com/javascript-obfuscator/rollup-plugin-javascript-obfuscator) + +### Grunt + +Use [grunt-contrib-obfuscator](https://github.com/javascript-obfuscator/grunt-contrib-obfuscator) + +## Common Issues and Solutions + +### Issue: Code breaks after obfuscation + +**Solutions**: +- Add function/variable names to `reservedNames` +- Add strings to `reservedStrings` +- Use `renamePropertiesMode: 'safe'` instead of 'unsafe' +- Disable `renameProperties` if safe mode doesn't work +- Check for dynamic property access like `obj[dynamicKey]` + +### Issue: Performance is too slow + +**Solutions**: +- Use lower obfuscation preset +- Reduce threshold values +- Disable `controlFlowFlattening` and `deadCodeInjection` +- Use `target: 'browser-no-eval'` if applicable + +### Issue: Code size is too large + +**Solutions**: +- Disable `deadCodeInjection` +- Reduce `stringArrayWrappersCount` +- Use lower `stringArrayThreshold` +- Disable `unicodeEscapeSequence` + +### Issue: Source maps not working + +**Solutions**: +- Ensure `sourceMap: true` in options +- Set correct `sourceMapMode` ('inline' or 'separate') +- Specify `inputFileName` when using NodeJS API +- Use `sourceMapSourcesMode: 'sources-content'` for embedded source + +### Issue: Domain lock not working + +**Solutions**: +- Don't use with `target: 'node'` +- Test in actual browser environment +- Check domain format (`.example.com` for all subdomains) +- Ensure `domainLockRedirectUrl` is set + +## Extension Points + +### Adding Custom Transformers + +1. Create transformer class extending `AbstractNodeTransformer` +2. Implement `getVisitor()` and `transformNode()` methods +3. Register in appropriate module (`src/container/modules/node-transformers/`) +4. Add to transformer list in `JavaScriptObfuscator.ts` +5. Add to `NodeTransformer` enum + +### Adding Custom Options + +1. Add property to `IOptions` interface +2. Add validation decorator in `Options.ts` +3. Add normalizer rule if needed in `options/normalizer-rules/` +4. Add preset values if applicable + +### Adding Custom Code Helpers + +1. Create helper group extending `AbstractCustomCodeHelperGroup` +2. Create template files in `custom-code-helpers/[group]/templates/` +3. Register in `CustomCodeHelpersModule` +4. Add to `CustomCodeHelper` enum + +## TypeScript Configuration + +### Main Config + +**Location**: `tsconfig.json` + +- **Target**: ES2018 +- **Module**: CommonJS +- **Strict mode**: Enabled +- **Decorators**: Enabled (experimental) +- **Emit decorator metadata**: Enabled + +### Special Configs + +- `tsconfig.browser.json`: Browser-specific settings +- `tsconfig.node.json`: Node.js-specific settings +- `tsconfig.typings.json`: Type declarations generation + +## Dependencies Overview + +### Production Dependencies + +- **@javascript-obfuscator/escodegen**: Modified escodegen for code generation +- **@javascript-obfuscator/estraverse**: Modified estraverse for AST traversal +- **acorn**: JavaScript parser (ES3-ES2020) +- **inversify**: Dependency injection container +- **eslint-scope**: Scope analysis (from ESLint) +- **class-validator**: Options validation +- **chance**: Random data generation +- **commander**: CLI argument parsing +- **chalk**: Terminal colors +- **md5**: Hashing for identifiers + +### Development Dependencies + +- **TypeScript**: Type system and compiler +- **Webpack**: Module bundler +- **Mocha + Chai**: Testing framework +- **NYC**: Code coverage +- **ESLint**: Code linting +- **Sinon**: Test mocking + +## Contributing + +**Location**: `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md` + +1. Fork the repository +2. Create feature branch +3. Write tests for new features +4. Ensure all tests pass +5. Follow existing code style (ESLint) +6. Submit pull request + +## Versioning and Releases + +- Follows semantic versioning (SemVer) +- Changelog maintained in `CHANGELOG.md` +- Precommit hooks run build and tests (Husky) +- Automated CI/CD via GitHub Actions + +## Support and Community + +- **GitHub Issues**: Bug reports and feature requests +- **GitHub Discussions**: Questions and general discussion +- **OpenCollective**: Financial support and sponsorship +- **GitHub Sponsors**: Direct sponsorship + +## License + +**BSD-2-Clause License** + +Copyright (C) 2016-2024 Timofey Kachalov + +See `LICENSE.BSD` for full license text. + +## Project Statistics + +- **First Release**: 2016 +- **Language**: TypeScript (~90% of codebase) +- **Test Coverage**: Extensive functional and unit test suite +- **Supported JavaScript Versions**: ES3, ES5, ES2015-ES2019, partial ES2020 +- **Downloads**: Widely used in production applications +- **Maintenance**: Actively maintained + +## Resources + +- **Main Repository**: https://github.com/javascript-obfuscator/javascript-obfuscator +- **Online Tool**: https://obfuscator.io +- **NPM Package**: https://www.npmjs.com/package/javascript-obfuscator +- **Documentation**: In README.md and inline code comments + +--- + +## Quick Reference: File Locations + +| Component | Primary Location | +|-----------|------------------| +| Main Obfuscator | `src/JavaScriptObfuscator.ts` | +| Public API | `src/JavaScriptObfuscatorFacade.ts` | +| CLI | `bin/javascript-obfuscator`, `src/JavaScriptObfuscatorCLIFacade.ts` | +| Options | `src/options/Options.ts` | +| Transformers | `src/node-transformers/` | +| Analyzers | `src/analyzers/` | +| DI Container | `src/container/InversifyContainerFacade.ts` | +| Tests | `test/` | +| Build Config | `webpack/` | +| Distribution | `dist/` | + +## Quick Reference: Key Enums + +- **CodeTransformationStage**: PreparingTransformers, FinalizingTransformers +- **NodeTransformationStage**: Initializing, Preparing, DeadCodeInjection, ControlFlowFlattening, RenameProperties, Converting, RenameIdentifiers, StringArray, Simplifying, Finalizing +- **OptionsPreset**: default, low-obfuscation, medium-obfuscation, high-obfuscation +- **StringArrayEncoding**: none, base64, rc4 +- **IdentifierNamesGenerator**: hexadecimal, mangled, mangled-shuffled, dictionary +- **RenamePropertiesMode**: safe, unsafe +- **Target**: browser, browser-no-eval, node From 39f7ff43e64abbc8251f28dd1f98b821b68f2c02 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Thu, 30 Oct 2025 11:32:28 +0400 Subject: [PATCH 11/87] Update dependencies (#1327) --- .eslintrc.js | 2 +- .github/workflows/ci.yml | 14 +- CLAUDE.md | 2 +- package.json | 100 +- src/analyzers/scope-analyzer/ScopeAnalyzer.ts | 1 + src/node/NodeFactory.ts | 2 +- yarn.lock | 4202 ++++++++++------- 7 files changed, 2486 insertions(+), 1837 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2e2f5f3bd..19606656b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -129,7 +129,7 @@ module.exports = { "@typescript-eslint/no-non-null-asserted-optional-chain": "error", "@typescript-eslint/no-non-null-assertion": "error", "@typescript-eslint/no-param-reassign": "off", - "@typescript-eslint/no-parameter-properties": "error", + "@typescript-eslint/parameter-properties": "error", "@typescript-eslint/no-require-imports": "off", "@typescript-eslint/no-shadow": "error", "@typescript-eslint/no-this-alias": "error", diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 930f6ca04..6bb2352bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,26 +16,26 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-latest, - node-version: 18.x - os: ubuntu-latest, node-version: 20.x - - os: ubuntu-latest, - node-version: 21.x - os: ubuntu-latest, node-version: 22.x + - os: ubuntu-latest, + node-version: 24.x - os: windows-latest, node-version: 20.x - os: windows-latest, node-version: 22.x + - os: windows-latest, + node-version: 24.x steps: - - uses: actions/checkout@v2 - - uses: styfle/cancel-workflow-action@0.6.0 + - uses: actions/checkout@v4 + - uses: styfle/cancel-workflow-action@0.12.1 with: access_token: ${{ github.token }} - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - uses: actions/cache@v4 diff --git a/CLAUDE.md b/CLAUDE.md index ae03f9f12..e55ec6c9c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,7 +9,7 @@ - **License**: BSD-2-Clause - **Repository**: https://github.com/javascript-obfuscator/javascript-obfuscator - **Homepage**: https://obfuscator.io/ -- **Node Requirement**: >=12.22.0 +- **Node Requirement**: >=18.0.0 ## Key Features diff --git a/package.json b/package.json index 472dcb1fc..c7d7dc0c0 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "js obfuscator" ], "engines": { - "node": ">=12.22.0" + "node": ">=18.0.0" }, "main": "dist/index.js", "browser": "dist/index.browser.js", @@ -23,77 +23,77 @@ "dependencies": { "@javascript-obfuscator/escodegen": "2.3.0", "@javascript-obfuscator/estraverse": "5.4.0", - "acorn": "8.8.2", - "assert": "2.0.0", + "acorn": "8.15.0", + "assert": "2.1.0", "chalk": "4.1.2", - "chance": "1.1.9", - "class-validator": "0.14.1", - "commander": "10.0.0", - "eslint-scope": "7.1.1", - "eslint-visitor-keys": "3.3.0", + "chance": "1.1.13", + "class-validator": "0.14.2", + "commander": "12.1.0", + "eslint-scope": "8.4.0", + "eslint-visitor-keys": "4.2.1", "fast-deep-equal": "3.1.3", - "inversify": "6.0.1", + "inversify": "6.1.4", "js-string-escape": "1.0.1", "md5": "2.3.0", - "mkdirp": "2.1.3", - "multimatch": "5.0.0", + "mkdirp": "3.0.1", + "multimatch": "7.0.0", "opencollective-postinstall": "2.0.3", "process": "0.11.10", - "reflect-metadata": "0.1.13", + "reflect-metadata": "0.2.2", "source-map-support": "0.5.21", "string-template": "1.0.0", "stringz": "2.1.0", - "tslib": "2.5.0" + "tslib": "2.8.1" }, "devDependencies": { "@istanbuljs/nyc-config-typescript": "1.0.2", - "@types/chai": "4.3.4", - "@types/chance": "1.1.3", - "@types/escodegen": "0.0.7", - "@types/eslint-scope": "3.7.4", + "@types/chai": "4.3.20", + "@types/chance": "1.1.7", + "@types/escodegen": "0.0.10", + "@types/eslint-scope": "3.7.7", "@types/eslint-visitor-keys": "1.0.0", - "@types/estraverse": "5.1.2", + "@types/estraverse": "5.1.7", "@types/estree": "0.0.51", - "@types/js-beautify": "1.13.3", - "@types/js-string-escape": "1.0.1", - "@types/md5": "2.3.2", + "@types/js-beautify": "1.14.3", + "@types/js-string-escape": "1.0.3", + "@types/md5": "2.3.6", "@types/mkdirp": "1.0.2", - "@types/mocha": "10.0.1", + "@types/mocha": "10.0.10", "@types/multimatch": "4.0.0", - "@types/node": "18.13.0", + "@types/node": "22.10.2", "@types/rimraf": "3.0.2", - "@types/sinon": "10.0.13", - "@types/string-template": "1.0.2", - "@types/webpack-env": "1.18.0", - "@typescript-eslint/eslint-plugin": "5.51.0", - "@typescript-eslint/parser": "5.51.0", - "chai": "4.3.7", - "chai-exclude": "2.1.0", - "cross-env": "7.0.3", - "eslint": "8.34.0", - "eslint-plugin-import": "2.27.5", - "eslint-plugin-jsdoc": "48.2.12", + "@types/sinon": "17.0.4", + "@types/string-template": "1.0.7", + "@types/webpack-env": "1.18.8", + "@typescript-eslint/eslint-plugin": "7.18.0", + "@typescript-eslint/parser": "7.18.0", + "chai": "4.5.0", + "chai-exclude": "3.0.1", + "cross-env": "10.1.0", + "eslint": "8.57.1", + "eslint-plugin-import": "2.32.0", + "eslint-plugin-jsdoc": "50.6.3", "eslint-plugin-no-null": "1.0.2", "eslint-plugin-prefer-arrow": "1.2.3", - "eslint-plugin-unicorn": "45.0.2", - "eslint-webpack-plugin": "4.0.0", - "fork-ts-checker-notifier-webpack-plugin": "6.0.0", - "fork-ts-checker-webpack-plugin": "7.3.0", - "husky": "8.0.3", - "js-beautify": "1.14.7", - "mocha": "10.4.0", - "nyc": "15.1.0", + "eslint-plugin-unicorn": "56.0.1", + "eslint-webpack-plugin": "4.2.0", + "fork-ts-checker-notifier-webpack-plugin": "9.0.0", + "fork-ts-checker-webpack-plugin": "9.1.0", + "husky": "9.1.7", + "js-beautify": "1.15.4", + "mocha": "11.7.4", + "nyc": "17.1.0", "pjson": "1.0.9", - "rimraf": "4.1.2", - "sinon": "15.0.1", + "rimraf": "6.0.1", + "sinon": "19.0.2", "source-map-resolve": "0.6.0", - "terser": "5.16.3", + "terser": "5.44.0", "threads": "1.7.0", - "ts-loader": "9.4.2", - "ts-node": "10.9.1", - "typescript": "4.9.5", - "webpack": "5.75.0", - "webpack-cli": "5.0.1", + "ts-loader": "9.5.4", + "ts-node": "10.9.2", + "typescript": "5.9.3", + "webpack": "5.102.1", + "webpack-cli": "6.0.1", "webpack-node-externals": "3.0.0" }, "repository": { diff --git a/src/analyzers/scope-analyzer/ScopeAnalyzer.ts b/src/analyzers/scope-analyzer/ScopeAnalyzer.ts index 2d04ae1d4..f4ea1f2c0 100644 --- a/src/analyzers/scope-analyzer/ScopeAnalyzer.ts +++ b/src/analyzers/scope-analyzer/ScopeAnalyzer.ts @@ -1,5 +1,6 @@ import { injectable, } from 'inversify'; +import * as acorn from 'acorn'; import * as eslintScope from 'eslint-scope'; import * as estraverse from '@javascript-obfuscator/estraverse'; import { KEYS, VisitorKeys } from 'eslint-visitor-keys'; diff --git a/src/node/NodeFactory.ts b/src/node/NodeFactory.ts index 99c7e69ba..534cb9c62 100644 --- a/src/node/NodeFactory.ts +++ b/src/node/NodeFactory.ts @@ -404,7 +404,7 @@ export class NodeFactory { * @returns {Literal} */ public static literalNode (value: boolean | number | string, raw?: string): ESTree.Literal { - raw = raw !== undefined ? raw : `'${value}'`; + raw = raw ?? `'${value}'`; return { type: NodeType.Literal, diff --git a/yarn.lock b/yarn.lock index 72865b848..59a16797f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,7 +2,7 @@ # yarn lockfile v1 -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.8.3": +"@babel/code-frame@^7.0.0": version "7.8.3" resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.8.3.tgz" integrity sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g== @@ -16,136 +16,117 @@ dependencies: "@babel/highlight" "^7.16.7" -"@babel/core@^7.7.5": - version "7.9.0" - resolved "https://registry.npmjs.org/@babel/core/-/core-7.9.0.tgz" - integrity sha512-kWc7L0fw1xwvI0zi8OKVBuxRVefwGOrKSQMvrQ3dW+bIIavBY3/NpXmpjMy7bQnLgwgzWQZ8TlM57YHpHNHz4w== - dependencies: - "@babel/code-frame" "^7.8.3" - "@babel/generator" "^7.9.0" - "@babel/helper-module-transforms" "^7.9.0" - "@babel/helpers" "^7.9.0" - "@babel/parser" "^7.9.0" - "@babel/template" "^7.8.6" - "@babel/traverse" "^7.9.0" - "@babel/types" "^7.9.0" - convert-source-map "^1.7.0" - debug "^4.1.0" - gensync "^1.0.0-beta.1" - json5 "^2.1.2" - lodash "^4.17.13" - resolve "^1.3.2" - semver "^5.4.1" - source-map "^0.5.0" - -"@babel/generator@^7.9.0": - version "7.9.3" - resolved "https://registry.npmjs.org/@babel/generator/-/generator-7.9.3.tgz" - integrity sha512-RpxM252EYsz9qLUIq6F7YJyK1sv0wWDBFuztfDGWaQKzHjqDHysxSiRUpA/X9jmfqo+WzkAVKFaUily5h+gDCQ== - dependencies: - "@babel/types" "^7.9.0" - jsesc "^2.5.1" - lodash "^4.17.13" - source-map "^0.5.0" - -"@babel/helper-function-name@^7.8.3": - version "7.8.3" - resolved "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.8.3.tgz" - integrity sha512-BCxgX1BC2hD/oBlIFUgOCQDOPV8nSINxCwM3o93xP4P9Fq6aV5sgv2cOOITDMtCfQ+3PvHp3l689XZvAM9QyOA== - dependencies: - "@babel/helper-get-function-arity" "^7.8.3" - "@babel/template" "^7.8.3" - "@babel/types" "^7.8.3" - -"@babel/helper-get-function-arity@^7.8.3": - version "7.8.3" - resolved "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.8.3.tgz" - integrity sha512-FVDR+Gd9iLjUMY1fzE2SR0IuaJToR4RkCDARVfsBBPSP53GEqSFjD8gNyxg246VUyc/ALRxFaAK8rVG7UT7xRA== - dependencies: - "@babel/types" "^7.8.3" - -"@babel/helper-member-expression-to-functions@^7.8.3": - version "7.8.3" - resolved "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.8.3.tgz" - integrity sha512-fO4Egq88utkQFjbPrSHGmGLFqmrshs11d46WI+WZDESt7Wu7wN2G2Iu+NMMZJFDOVRHAMIkB5SNh30NtwCA7RA== +"@babel/code-frame@^7.27.1": + version "7.27.1" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.27.1.tgz#200f715e66d52a23b221a9435534a91cc13ad5be" + integrity sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg== dependencies: - "@babel/types" "^7.8.3" + "@babel/helper-validator-identifier" "^7.27.1" + js-tokens "^4.0.0" + picocolors "^1.1.1" + +"@babel/compat-data@^7.27.2": + version "7.28.5" + resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.28.5.tgz#a8a4962e1567121ac0b3b487f52107443b455c7f" + integrity sha512-6uFXyCayocRbqhZOB+6XcuZbkMNimwfVGFji8CTZnCzOHVGvDqzvitu1re2AU5LROliz7eQPhB8CpAMvnx9EjA== + +"@babel/core@^7.23.9": + version "7.28.5" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.28.5.tgz#4c81b35e51e1b734f510c99b07dfbc7bbbb48f7e" + integrity sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw== + dependencies: + "@babel/code-frame" "^7.27.1" + "@babel/generator" "^7.28.5" + "@babel/helper-compilation-targets" "^7.27.2" + "@babel/helper-module-transforms" "^7.28.3" + "@babel/helpers" "^7.28.4" + "@babel/parser" "^7.28.5" + "@babel/template" "^7.27.2" + "@babel/traverse" "^7.28.5" + "@babel/types" "^7.28.5" + "@jridgewell/remapping" "^2.3.5" + convert-source-map "^2.0.0" + debug "^4.1.0" + gensync "^1.0.0-beta.2" + json5 "^2.2.3" + semver "^6.3.1" + +"@babel/generator@^7.28.5": + version "7.28.5" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.28.5.tgz#712722d5e50f44d07bc7ac9fe84438742dd61298" + integrity sha512-3EwLFhZ38J4VyIP6WNtt2kUdW9dokXA9Cr4IVIFHuCpZ3H8/YFOl5JjZHisrn1fATPBmKKqXzDFvh9fUwHz6CQ== + dependencies: + "@babel/parser" "^7.28.5" + "@babel/types" "^7.28.5" + "@jridgewell/gen-mapping" "^0.3.12" + "@jridgewell/trace-mapping" "^0.3.28" + jsesc "^3.0.2" -"@babel/helper-module-imports@^7.8.3": - version "7.8.3" - resolved "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.8.3.tgz" - integrity sha512-R0Bx3jippsbAEtzkpZ/6FIiuzOURPcMjHp+Z6xPe6DtApDJx+w7UYyOLanZqO8+wKR9G10s/FmHXvxaMd9s6Kg== +"@babel/helper-compilation-targets@^7.27.2": + version "7.27.2" + resolved "https://registry.yarnpkg.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.27.2.tgz#46a0f6efab808d51d29ce96858dd10ce8732733d" + integrity sha512-2+1thGUUWWjLTYTHZWK1n8Yga0ijBz1XAhUXcKy81rd5g6yh7hGqMp45v7cadSbEHc9G3OTv45SyneRN3ps4DQ== dependencies: - "@babel/types" "^7.8.3" + "@babel/compat-data" "^7.27.2" + "@babel/helper-validator-option" "^7.27.1" + browserslist "^4.24.0" + lru-cache "^5.1.1" + semver "^6.3.1" -"@babel/helper-module-transforms@^7.9.0": - version "7.9.0" - resolved "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.9.0.tgz" - integrity sha512-0FvKyu0gpPfIQ8EkxlrAydOWROdHpBmiCiRwLkUiBGhCUPRRbVD2/tm3sFr/c/GWFrQ/ffutGUAnx7V0FzT2wA== - dependencies: - "@babel/helper-module-imports" "^7.8.3" - "@babel/helper-replace-supers" "^7.8.6" - "@babel/helper-simple-access" "^7.8.3" - "@babel/helper-split-export-declaration" "^7.8.3" - "@babel/template" "^7.8.6" - "@babel/types" "^7.9.0" - lodash "^4.17.13" - -"@babel/helper-optimise-call-expression@^7.8.3": - version "7.8.3" - resolved "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.8.3.tgz" - integrity sha512-Kag20n86cbO2AvHca6EJsvqAd82gc6VMGule4HwebwMlwkpXuVqrNRj6CkCV2sKxgi9MyAUnZVnZ6lJ1/vKhHQ== - dependencies: - "@babel/types" "^7.8.3" +"@babel/helper-globals@^7.28.0": + version "7.28.0" + resolved "https://registry.yarnpkg.com/@babel/helper-globals/-/helper-globals-7.28.0.tgz#b9430df2aa4e17bc28665eadeae8aa1d985e6674" + integrity sha512-+W6cISkXFa1jXsDEdYA8HeevQT/FULhxzR99pxphltZcVaugps53THCeiWA8SguxxpSp3gKPiuYfSWopkLQ4hw== -"@babel/helper-replace-supers@^7.8.6": - version "7.8.6" - resolved "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.8.6.tgz" - integrity sha512-PeMArdA4Sv/Wf4zXwBKPqVj7n9UF/xg6slNRtZW84FM7JpE1CbG8B612FyM4cxrf4fMAMGO0kR7voy1ForHHFA== +"@babel/helper-module-imports@^7.27.1": + version "7.27.1" + resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.27.1.tgz#7ef769a323e2655e126673bb6d2d6913bbead204" + integrity sha512-0gSFWUPNXNopqtIPQvlD5WgXYI5GY2kP2cCvoT8kczjbfcfuIljTbcWrulD1CIPIX2gt1wghbDy08yE1p+/r3w== dependencies: - "@babel/helper-member-expression-to-functions" "^7.8.3" - "@babel/helper-optimise-call-expression" "^7.8.3" - "@babel/traverse" "^7.8.6" - "@babel/types" "^7.8.6" + "@babel/traverse" "^7.27.1" + "@babel/types" "^7.27.1" -"@babel/helper-simple-access@^7.8.3": - version "7.8.3" - resolved "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.8.3.tgz" - integrity sha512-VNGUDjx5cCWg4vvCTR8qQ7YJYZ+HBjxOgXEl7ounz+4Sn7+LMD3CFrCTEU6/qXKbA2nKg21CwhhBzO0RpRbdCw== +"@babel/helper-module-transforms@^7.28.3": + version "7.28.3" + resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.28.3.tgz#a2b37d3da3b2344fe085dab234426f2b9a2fa5f6" + integrity sha512-gytXUbs8k2sXS9PnQptz5o0QnpLL51SwASIORY6XaBKF88nsOT0Zw9szLqlSGQDP/4TljBAD5y98p2U1fqkdsw== dependencies: - "@babel/template" "^7.8.3" - "@babel/types" "^7.8.3" + "@babel/helper-module-imports" "^7.27.1" + "@babel/helper-validator-identifier" "^7.27.1" + "@babel/traverse" "^7.28.3" -"@babel/helper-split-export-declaration@^7.8.3": - version "7.8.3" - resolved "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.8.3.tgz" - integrity sha512-3x3yOeyBhW851hroze7ElzdkeRXQYQbFIb7gLK1WQYsw2GWDay5gAJNw1sWJ0VFP6z5J1whqeXH/WCdCjZv6dA== - dependencies: - "@babel/types" "^7.8.3" +"@babel/helper-string-parser@^7.27.1": + version "7.27.1" + resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz#54da796097ab19ce67ed9f88b47bb2ec49367687" + integrity sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA== "@babel/helper-validator-identifier@^7.16.7": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.16.7.tgz#e8c602438c4a8195751243da9031d1607d247cad" integrity sha512-hsEnFemeiW4D08A5gUAZxLBTXpZ39P+a+DGDsHw1yxqyQ/jzFEnxf5uTEGp+3bzAbNOxU1paTgYS4ECU/IgfDw== -"@babel/helper-validator-identifier@^7.19.1": - version "7.19.1" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz#7eea834cf32901ffdc1a7ee555e2f9c27e249ca2" - integrity sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w== +"@babel/helper-validator-identifier@^7.24.7", "@babel/helper-validator-identifier@^7.27.1", "@babel/helper-validator-identifier@^7.28.5": + version "7.28.5" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.28.5.tgz#010b6938fab7cb7df74aa2bbc06aa503b8fe5fb4" + integrity sha512-qSs4ifwzKJSV39ucNjsvc6WVHs6b7S03sOh2OcHF9UHfVPqWWALUsNUVzhSBiItjRZoLHx7nIarVjqKVusUZ1Q== "@babel/helper-validator-identifier@^7.9.0": version "7.9.0" resolved "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.0.tgz" integrity sha512-6G8bQKjOh+of4PV/ThDm/rRqlU7+IGoJuofpagU5GlEl29Vv0RGqqt86ZGRV8ZuSOY3o+8yXl5y782SMcG7SHw== -"@babel/helpers@^7.9.0": - version "7.9.2" - resolved "https://registry.npmjs.org/@babel/helpers/-/helpers-7.9.2.tgz" - integrity sha512-JwLvzlXVPjO8eU9c/wF9/zOIN7X6h8DYf7mG4CiFRZRvZNKEF5dQ3H3V+ASkHoIB3mWhatgl5ONhyqHRI6MppA== +"@babel/helper-validator-option@^7.27.1": + version "7.27.1" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.27.1.tgz#fa52f5b1e7db1ab049445b421c4471303897702f" + integrity sha512-YvjJow9FxbhFFKDSuFnVCe2WxXk1zWc22fFePVNEaWJEu8IrZVlda6N0uHwzZrUM1il7NC9Mlp4MaJYbYd9JSg== + +"@babel/helpers@^7.28.4": + version "7.28.4" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.28.4.tgz#fe07274742e95bdf7cf1443593eeb8926ab63827" + integrity sha512-HFN59MmQXGHVyYadKLVumYsA9dBFun/ldYxipEjzA4196jpLZd8UjEEBLkbEkvfYreDqJhZxYAWFPtrfhNpj4w== dependencies: - "@babel/template" "^7.8.3" - "@babel/traverse" "^7.9.0" - "@babel/types" "^7.9.0" + "@babel/template" "^7.27.2" + "@babel/types" "^7.28.4" "@babel/highlight@^7.16.7": version "7.16.10" @@ -165,43 +146,42 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@^7.7.5", "@babel/parser@^7.8.6", "@babel/parser@^7.9.0": - version "7.9.3" - resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.9.3.tgz" - integrity sha512-E6SpIDJZ0cZAKoCNk+qSDd0ChfTnpiJN9FfNf3RZ20dzwA2vL2oq5IX1XTVT+4vDmRlta2nGk5HGMMskJAR+4A== +"@babel/parser@^7.23.9", "@babel/parser@^7.27.2", "@babel/parser@^7.28.5": + version "7.28.5" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.28.5.tgz#0b0225ee90362f030efd644e8034c99468893b08" + integrity sha512-KKBU1VGYR7ORr3At5HAtUQ+TV3SzRCXmA/8OdDZiLDBIZxVyzXuztPjfLd3BV1PRAQGCMWWSHYhL0F8d5uHBDQ== + dependencies: + "@babel/types" "^7.28.5" -"@babel/template@^7.7.4", "@babel/template@^7.8.3", "@babel/template@^7.8.6": - version "7.8.6" - resolved "https://registry.npmjs.org/@babel/template/-/template-7.8.6.tgz" - integrity sha512-zbMsPMy/v0PWFZEhQJ66bqjhH+z0JgMoBWuikXybgG3Gkd/3t5oQ1Rw2WQhnSrsOmsKXnZOx15tkC4qON/+JPg== +"@babel/template@^7.27.2": + version "7.27.2" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.27.2.tgz#fa78ceed3c4e7b63ebf6cb39e5852fca45f6809d" + integrity sha512-LPDZ85aEJyYSd18/DkjNh4/y1ntkE5KwUHWTiqgRxruuZL2F1yuHligVHLvcHY2vMHXttKFpJn6LwfI7cw7ODw== dependencies: - "@babel/code-frame" "^7.8.3" - "@babel/parser" "^7.8.6" - "@babel/types" "^7.8.6" + "@babel/code-frame" "^7.27.1" + "@babel/parser" "^7.27.2" + "@babel/types" "^7.27.1" -"@babel/traverse@^7.7.4", "@babel/traverse@^7.8.6", "@babel/traverse@^7.9.0": - version "7.9.0" - resolved "https://registry.npmjs.org/@babel/traverse/-/traverse-7.9.0.tgz" - integrity sha512-jAZQj0+kn4WTHO5dUZkZKhbFrqZE7K5LAQ5JysMnmvGij+wOdr+8lWqPeW0BcF4wFwrEXXtdGO7wcV6YPJcf3w== - dependencies: - "@babel/code-frame" "^7.8.3" - "@babel/generator" "^7.9.0" - "@babel/helper-function-name" "^7.8.3" - "@babel/helper-split-export-declaration" "^7.8.3" - "@babel/parser" "^7.9.0" - "@babel/types" "^7.9.0" - debug "^4.1.0" - globals "^11.1.0" - lodash "^4.17.13" +"@babel/traverse@^7.27.1", "@babel/traverse@^7.28.3", "@babel/traverse@^7.28.5": + version "7.28.5" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.28.5.tgz#450cab9135d21a7a2ca9d2d35aa05c20e68c360b" + integrity sha512-TCCj4t55U90khlYkVV/0TfkJkAkUg3jZFA3Neb7unZT8CPok7iiRfaX0F+WnqWqt7OxhOn0uBKXCw4lbL8W0aQ== + dependencies: + "@babel/code-frame" "^7.27.1" + "@babel/generator" "^7.28.5" + "@babel/helper-globals" "^7.28.0" + "@babel/parser" "^7.28.5" + "@babel/template" "^7.27.2" + "@babel/types" "^7.28.5" + debug "^4.3.1" -"@babel/types@^7.8.3", "@babel/types@^7.8.6", "@babel/types@^7.9.0": - version "7.9.0" - resolved "https://registry.npmjs.org/@babel/types/-/types-7.9.0.tgz" - integrity sha512-BS9JKfXkzzJl8RluW4JGknzpiUV7ZrvTayM6yfqLTVBEnFtyowVIOu6rqxRd5cVO6yGoWf4T8u8dgK9oB+GCng== +"@babel/types@^7.27.1", "@babel/types@^7.28.4", "@babel/types@^7.28.5": + version "7.28.5" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.28.5.tgz#10fc405f60897c35f07e85493c932c7b5ca0592b" + integrity sha512-qQ5m48eI/MFLQ5PxQj4PFaprjyCTLI37ElWMmNs0K8Lk3dVeOdNpB3ks8jc7yM5CDmVC73eMVk/trk3fgmrUpA== dependencies: - "@babel/helper-validator-identifier" "^7.9.0" - lodash "^4.17.13" - to-fast-properties "^2.0.0" + "@babel/helper-string-parser" "^7.27.1" + "@babel/helper-validator-identifier" "^7.28.5" "@cspotcode/source-map-support@^0.8.0": version "0.8.1" @@ -210,38 +190,45 @@ dependencies: "@jridgewell/trace-mapping" "0.3.9" -"@discoveryjs/json-ext@^0.5.0": - version "0.5.2" - resolved "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.2.tgz" - integrity sha512-HyYEUDeIj5rRQU2Hk5HTB2uHsbRQpF70nvMhVzi+VJR0X+xNEhjPui4/kBf3VeH/wqD28PT4sVOm8qqLjBrSZg== +"@discoveryjs/json-ext@^0.6.1": + version "0.6.3" + resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.6.3.tgz#f13c7c205915eb91ae54c557f5e92bddd8be0e83" + integrity sha512-4B4OijXeVNOPZlYA2oEwWOTkzyltLao+xbotHQeqN++Rv27Y6s818+n2Qkp8q+Fxhn0t/5lA5X1Mxktud8eayQ== + +"@epic-web/invariant@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@epic-web/invariant/-/invariant-1.0.0.tgz#1073e5dee6dd540410784990eb73e4acd25c9813" + integrity sha512-lrTPqgvfFQtR/eY/qkIzp98OGdNJu0m5ji3q/nJI8v3SXkRKEnWiOxMmbvcSoAIzv/cGiuvRy57k4suKQSAdwA== -"@es-joy/jsdoccomment@~0.43.1": - version "0.43.1" - resolved "https://registry.yarnpkg.com/@es-joy/jsdoccomment/-/jsdoccomment-0.43.1.tgz#4b1979b7b4ff8b596fb19a3aa696a438e44608d7" - integrity sha512-I238eDtOolvCuvtxrnqtlBaw0BwdQuYqK7eA6XIonicMdOOOb75mqdIzkGDUbS04+1Di007rgm9snFRNeVrOog== +"@es-joy/jsdoccomment@~0.49.0": + version "0.49.0" + resolved "https://registry.yarnpkg.com/@es-joy/jsdoccomment/-/jsdoccomment-0.49.0.tgz#e5ec1eda837c802eca67d3b29e577197f14ba1db" + integrity sha512-xjZTSFgECpb9Ohuk5yMX5RhUEbfeQcuOp8IF60e+wyzWEF0M5xeSgqsfLtvPEX8BIyOX9saZqzuGPmZ8oWc+5Q== dependencies: - "@types/eslint" "^8.56.5" - "@types/estree" "^1.0.5" - "@typescript-eslint/types" "^7.2.0" comment-parser "1.4.1" - esquery "^1.5.0" - jsdoc-type-pratt-parser "~4.0.0" + esquery "^1.6.0" + jsdoc-type-pratt-parser "~4.1.0" -"@eslint-community/eslint-utils@^4.1.2": - version "4.1.2" - resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.1.2.tgz#14ca568ddaa291dd19a4a54498badc18c6cfab78" - integrity sha512-7qELuQWWjVDdVsFQ5+beUl+KPczrEDA7S3zM4QUd/bJl7oXgsmpXaEVqrRTnOBqenOV4rWf2kVZk2Ot085zPWA== +"@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": + version "4.9.0" + resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.9.0.tgz#7308df158e064f0dd8b8fdb58aa14fa2a7f913b3" + integrity sha512-ayVFHdtZ+hsq1t2Dy24wCmGXGe4q9Gu3smhLYALJrr473ZH27MsnSL+LKUlimp4BWJqMDMLmPpx/Q9R3OAlL4g== dependencies: - eslint-visitor-keys "^3.3.0" + eslint-visitor-keys "^3.4.3" -"@eslint/eslintrc@^1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.4.1.tgz#af58772019a2d271b7e2d4c23ff4ddcba3ccfb3e" - integrity sha512-XXrH9Uarn0stsyldqDYq8r++mROmWRI1xKMXa640Bb//SY1+ECYX6VzT6Lcx5frD0V30XieqJ0oX9I2Xj5aoMA== +"@eslint-community/regexpp@^4.10.0", "@eslint-community/regexpp@^4.6.1": + version "4.12.2" + resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.12.2.tgz#bccdf615bcf7b6e8db830ec0b8d21c9a25de597b" + integrity sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew== + +"@eslint/eslintrc@^2.1.4": + version "2.1.4" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.4.tgz#388a269f0f25c1b6adc317b5a2c55714894c70ad" + integrity sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ== dependencies: ajv "^6.12.4" debug "^4.3.2" - espree "^9.4.0" + espree "^9.6.0" globals "^13.19.0" ignore "^5.2.0" import-fresh "^3.2.1" @@ -249,13 +236,18 @@ minimatch "^3.1.2" strip-json-comments "^3.1.1" -"@humanwhocodes/config-array@^0.11.8": - version "0.11.8" - resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.8.tgz#03595ac2075a4dc0f191cc2131de14fbd7d410b9" - integrity sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g== +"@eslint/js@8.57.1": + version "8.57.1" + resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.1.tgz#de633db3ec2ef6a3c89e2f19038063e8a122e2c2" + integrity sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q== + +"@humanwhocodes/config-array@^0.13.0": + version "0.13.0" + resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.13.0.tgz#fb907624df3256d04b9aa2df50d7aa97ec648748" + integrity sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw== dependencies: - "@humanwhocodes/object-schema" "^1.2.1" - debug "^4.1.1" + "@humanwhocodes/object-schema" "^2.0.3" + debug "^4.3.1" minimatch "^3.0.5" "@humanwhocodes/module-importer@^1.0.1": @@ -263,10 +255,52 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz#af5b2691a22b44be847b0ca81641c5fb6ad0172c" integrity sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA== -"@humanwhocodes/object-schema@^1.2.1": - version "1.2.1" - resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" - integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== +"@humanwhocodes/object-schema@^2.0.3": + version "2.0.3" + resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz#4a2868d75d6d6963e423bcf90b7fd1be343409d3" + integrity sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA== + +"@inversifyjs/common@1.3.3": + version "1.3.3" + resolved "https://registry.yarnpkg.com/@inversifyjs/common/-/common-1.3.3.tgz#c34bba10be8c511bf3cd25473bd32c2a08987111" + integrity sha512-ZH0wrgaJwIo3s9gMCDM2wZoxqrJ6gB97jWXncROfYdqZJv8f3EkqT57faZqN5OTeHWgtziQ6F6g3L8rCvGceCw== + +"@inversifyjs/core@1.3.4": + version "1.3.4" + resolved "https://registry.yarnpkg.com/@inversifyjs/core/-/core-1.3.4.tgz#17d2614ff48fc6e0db20c2fe3258c3d5bef9b5e0" + integrity sha512-gCCmA4BdbHEFwvVZ2elWgHuXZWk6AOu/1frxsS+2fWhjEk2c/IhtypLo5ytSUie1BCiT6i9qnEo4bruBomQsAA== + dependencies: + "@inversifyjs/common" "1.3.3" + "@inversifyjs/reflect-metadata-utils" "0.2.3" + +"@inversifyjs/reflect-metadata-utils@0.2.3": + version "0.2.3" + resolved "https://registry.yarnpkg.com/@inversifyjs/reflect-metadata-utils/-/reflect-metadata-utils-0.2.3.tgz#b17359fd4fdfc85726d3b1af7ad3647136950ea0" + integrity sha512-d3D0o9TeSlvaGM2I24wcNw/Aj3rc4OYvHXOKDC09YEph5fMMiKd6fq1VTQd9tOkDNWvVbw+cnt45Wy9P/t5Lvw== + +"@isaacs/balanced-match@^4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz#3081dadbc3460661b751e7591d7faea5df39dd29" + integrity sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ== + +"@isaacs/brace-expansion@^5.0.0": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@isaacs/brace-expansion/-/brace-expansion-5.0.0.tgz#4b3dabab7d8e75a429414a96bd67bf4c1d13e0f3" + integrity sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA== + dependencies: + "@isaacs/balanced-match" "^4.0.1" + +"@isaacs/cliui@^8.0.2": + version "8.0.2" + resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550" + integrity sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA== + dependencies: + string-width "^5.1.2" + string-width-cjs "npm:string-width@^4.2.0" + strip-ansi "^7.0.1" + strip-ansi-cjs "npm:strip-ansi@^6.0.1" + wrap-ansi "^8.1.0" + wrap-ansi-cjs "npm:wrap-ansi@^7.0.0" "@istanbuljs/load-nyc-config@^1.0.0": version "1.0.0" @@ -290,6 +324,11 @@ resolved "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.2.tgz" integrity sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw== +"@istanbuljs/schema@^0.1.3": + version "0.1.3" + resolved "https://registry.yarnpkg.com/@istanbuljs/schema/-/schema-0.1.3.tgz#e45e384e4b8ec16bce2fd903af78450f6bf7ec98" + integrity sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA== + "@javascript-obfuscator/escodegen@2.3.0": version "2.3.0" resolved "https://registry.yarnpkg.com/@javascript-obfuscator/escodegen/-/escodegen-2.3.0.tgz#ff7eb7f8a7c004532e93b14ae8b2196dcf9a1a9e" @@ -312,57 +351,69 @@ resolved "https://registry.yarnpkg.com/@javascript-obfuscator/estraverse/-/estraverse-5.3.0.tgz#eadd3c00ede6a05b75aa585c7b7a3ac58adb1755" integrity sha512-SxIFtV5/wlXYS7G3zLVj7CddLolX8Bm/hr68fiyNL3MyG2k4FwF9B5Z5GTpVLhw2EELYNwyoYBvFlR4gGnQPdw== -"@jest/schemas@^29.4.2": - version "29.4.2" - resolved "https://registry.yarnpkg.com/@jest/schemas/-/schemas-29.4.2.tgz#cf7cfe97c5649f518452b176c47ed07486270fc1" - integrity sha512-ZrGzGfh31NtdVH8tn0mgJw4khQuNHiKqdzJAFbCaERbyCP9tHlxWuL/mnMu8P7e/+k4puWjI1NOzi/sFsjce/g== +"@jest/schemas@^29.6.3": + version "29.6.3" + resolved "https://registry.yarnpkg.com/@jest/schemas/-/schemas-29.6.3.tgz#430b5ce8a4e0044a7e3819663305a7b3091c8e03" + integrity sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA== dependencies: - "@sinclair/typebox" "^0.25.16" + "@sinclair/typebox" "^0.27.8" -"@jest/types@^29.4.2": - version "29.4.2" - resolved "https://registry.yarnpkg.com/@jest/types/-/types-29.4.2.tgz#8f724a414b1246b2bfd56ca5225d9e1f39540d82" - integrity sha512-CKlngyGP0fwlgC1BRUtPZSiWLBhyS9dKwKmyGxk8Z6M82LBEGB2aLQSg+U1MyLsU+M7UjnlLllBM2BLWKVm/Uw== +"@jest/types@^29.6.3": + version "29.6.3" + resolved "https://registry.yarnpkg.com/@jest/types/-/types-29.6.3.tgz#1131f8cf634e7e84c5e77bab12f052af585fba59" + integrity sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw== dependencies: - "@jest/schemas" "^29.4.2" + "@jest/schemas" "^29.6.3" "@types/istanbul-lib-coverage" "^2.0.0" "@types/istanbul-reports" "^3.0.0" "@types/node" "*" "@types/yargs" "^17.0.8" chalk "^4.0.0" -"@jridgewell/gen-mapping@^0.3.0": - version "0.3.2" - resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz#c1aedc61e853f2bb9f5dfe6d4442d3b565b253b9" - integrity sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A== +"@jridgewell/gen-mapping@^0.3.12", "@jridgewell/gen-mapping@^0.3.5": + version "0.3.13" + resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz#6342a19f44347518c93e43b1ac69deb3c4656a1f" + integrity sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA== dependencies: - "@jridgewell/set-array" "^1.0.1" - "@jridgewell/sourcemap-codec" "^1.4.10" - "@jridgewell/trace-mapping" "^0.3.9" + "@jridgewell/sourcemap-codec" "^1.5.0" + "@jridgewell/trace-mapping" "^0.3.24" + +"@jridgewell/remapping@^2.3.5": + version "2.3.5" + resolved "https://registry.yarnpkg.com/@jridgewell/remapping/-/remapping-2.3.5.tgz#375c476d1972947851ba1e15ae8f123047445aa1" + integrity sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ== + dependencies: + "@jridgewell/gen-mapping" "^0.3.5" + "@jridgewell/trace-mapping" "^0.3.24" -"@jridgewell/resolve-uri@3.1.0", "@jridgewell/resolve-uri@^3.0.3": +"@jridgewell/resolve-uri@^3.0.3": version "3.1.0" resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== -"@jridgewell/set-array@^1.0.1": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72" - integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== +"@jridgewell/resolve-uri@^3.1.0": + version "3.1.2" + resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz#7a0ee601f60f99a20c7c7c5ff0c80388c1189bd6" + integrity sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw== -"@jridgewell/source-map@^0.3.2": - version "0.3.2" - resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.2.tgz#f45351aaed4527a298512ec72f81040c998580fb" - integrity sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw== +"@jridgewell/source-map@^0.3.3": + version "0.3.11" + resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.11.tgz#b21835cbd36db656b857c2ad02ebd413cc13a9ba" + integrity sha512-ZMp1V8ZFcPG5dIWnQLr3NSI1MiCU7UETdS/A0G8V/XWHvJv3ZsFqutJn1Y5RPmAPX6F3BiE397OqveU/9NCuIA== dependencies: - "@jridgewell/gen-mapping" "^0.3.0" - "@jridgewell/trace-mapping" "^0.3.9" + "@jridgewell/gen-mapping" "^0.3.5" + "@jridgewell/trace-mapping" "^0.3.25" -"@jridgewell/sourcemap-codec@1.4.14", "@jridgewell/sourcemap-codec@^1.4.10": +"@jridgewell/sourcemap-codec@^1.4.10": version "1.4.14" resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== +"@jridgewell/sourcemap-codec@^1.4.14", "@jridgewell/sourcemap-codec@^1.5.0": + version "1.5.5" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz#6912b00d2c631c0d15ce1a7ab57cd657f2a8f8ba" + integrity sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og== + "@jridgewell/trace-mapping@0.3.9": version "0.3.9" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9" @@ -371,13 +422,13 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@jridgewell/trace-mapping@^0.3.9": - version "0.3.17" - resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz#793041277af9073b0951a7fe0f0d8c4c98c36985" - integrity sha512-MCNzAp77qzKca9+W/+I0+sEpaUnZoeasnghNeVc41VZCEKaCH73Vq3BZZ/SzWIgrqE4H4ceI+p+b6C0mHf9T4g== +"@jridgewell/trace-mapping@^0.3.24", "@jridgewell/trace-mapping@^0.3.25", "@jridgewell/trace-mapping@^0.3.28": + version "0.3.31" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz#db15d6781c931f3a251a3dac39501c98a6082fd0" + integrity sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw== dependencies: - "@jridgewell/resolve-uri" "3.1.0" - "@jridgewell/sourcemap-codec" "1.4.14" + "@jridgewell/resolve-uri" "^3.1.0" + "@jridgewell/sourcemap-codec" "^1.4.14" "@nodelib/fs.scandir@2.1.4": version "2.1.4" @@ -421,38 +472,57 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@sinclair/typebox@^0.25.16": - version "0.25.21" - resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.25.21.tgz#763b05a4b472c93a8db29b2c3e359d55b29ce272" - integrity sha512-gFukHN4t8K4+wVC+ECqeqwzBDeFeTzBXroBTqE6vcWrQGbEUpHO7LYdG0f4xnvYq4VOEwITSlHlp0JBAIFMS/g== +"@one-ini/wasm@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@one-ini/wasm/-/wasm-0.1.1.tgz#6013659736c9dbfccc96e8a9c2b3de317df39323" + integrity sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw== + +"@pkgjs/parseargs@^0.11.0": + version "0.11.0" + resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33" + integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg== -"@sinonjs/commons@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-2.0.0.tgz#fd4ca5b063554307e8327b4564bd56d3b73924a3" - integrity sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg== +"@pkgr/core@^0.1.0": + version "0.1.2" + resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.2.tgz#1cf95080bb7072fafaa3cb13b442fab4695c3893" + integrity sha512-fdDH1LSGfZdTH2sxdpVMw31BanV28K/Gry0cVFxaNP77neJSkd82mM8ErPNYs9e+0O7SdHBLTDzDgwUuy18RnQ== + +"@rtsao/scc@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@rtsao/scc/-/scc-1.1.0.tgz#927dd2fae9bc3361403ac2c7a00c32ddce9ad7e8" + integrity sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g== + +"@sinclair/typebox@^0.27.8": + version "0.27.8" + resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" + integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA== + +"@sinonjs/commons@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.1.tgz#1029357e44ca901a615585f6d27738dbc89084cd" + integrity sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ== dependencies: type-detect "4.0.8" -"@sinonjs/fake-timers@10.0.2", "@sinonjs/fake-timers@^10.0.2": - version "10.0.2" - resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.0.2.tgz#d10549ed1f423d80639c528b6c7f5a1017747d0c" - integrity sha512-SwUDyjWnah1AaNl7kxsa7cfLhlTYoiyhDAIgyh+El30YvXs/o7OLXpYH88Zdhyx9JExKrmHDJ+10bwIcY80Jmw== +"@sinonjs/fake-timers@^13.0.1", "@sinonjs/fake-timers@^13.0.2": + version "13.0.5" + resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-13.0.5.tgz#36b9dbc21ad5546486ea9173d6bea063eb1717d5" + integrity sha512-36/hTbH2uaWuGVERyC6da9YwGWnzUZXuPro/F2LfsdOsLnCojz/iSH8MxUt/FD2S5XBSVPhmArFUXcpCQ2Hkiw== dependencies: - "@sinonjs/commons" "^2.0.0" + "@sinonjs/commons" "^3.0.1" -"@sinonjs/samsam@^7.0.1": - version "7.0.1" - resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-7.0.1.tgz#5b5fa31c554636f78308439d220986b9523fc51f" - integrity sha512-zsAk2Jkiq89mhZovB2LLOdTCxJF4hqqTToGP0ASWlhp4I1hqOjcfmZGafXntCN7MDC6yySH0mFHrYtHceOeLmw== +"@sinonjs/samsam@^8.0.1": + version "8.0.3" + resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-8.0.3.tgz#eb6ffaef421e1e27783cc9b52567de20cb28072d" + integrity sha512-hw6HbX+GyVZzmaYNh82Ecj1vdGZrqVIn/keDTg63IgAwiQPO+xCz99uG6Woqgb4tM0mUiFENKZ4cqd7IX94AXQ== dependencies: - "@sinonjs/commons" "^2.0.0" - lodash.get "^4.4.2" - type-detect "^4.0.8" + "@sinonjs/commons" "^3.0.1" + type-detect "^4.1.0" -"@sinonjs/text-encoding@^0.7.1": - version "0.7.1" - resolved "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz" - integrity sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ== +"@sinonjs/text-encoding@^0.7.3": + version "0.7.3" + resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.3.tgz#282046f03e886e352b2d5f5da5eb755e01457f3f" + integrity sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA== "@tsconfig/node10@^1.0.7": version "1.0.7" @@ -474,30 +544,30 @@ resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== -"@types/chai@4.3.4": - version "4.3.4" - resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4" - integrity sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw== +"@types/chai@4.3.20": + version "4.3.20" + resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.20.tgz#cb291577ed342ca92600430841a00329ba05cecc" + integrity sha512-/pC9HAB5I/xMlc5FP77qjCnI16ChlJfW0tGa0IUcFn38VJrTV6DeZ60NU5KZBtaOZqjdpwTWohz5HU1RrhiYxQ== -"@types/chance@1.1.3": - version "1.1.3" - resolved "https://registry.yarnpkg.com/@types/chance/-/chance-1.1.3.tgz#d19fe9391288d60fdccd87632bfc9ab2b4523fea" - integrity sha512-X6c6ghhe4/sQh4XzcZWSFaTAUOda38GQHmq9BUanYkOE/EO7ZrkazwKmtsj3xzTjkLWmwULE++23g3d3CCWaWw== +"@types/chance@1.1.7": + version "1.1.7" + resolved "https://registry.yarnpkg.com/@types/chance/-/chance-1.1.7.tgz#388c19748fe97bbe60552c83a056001a3c973082" + integrity sha512-40you9610GTQPJyvjMBgmj9wiDO6qXhbfjizNYod/fmvLSfUUxURAJMTD8tjmbcZSsyYE5iEUox61AAcCjW/wQ== "@types/color-name@^1.1.1": version "1.1.1" resolved "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz" integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== -"@types/escodegen@0.0.7": - version "0.0.7" - resolved "https://registry.yarnpkg.com/@types/escodegen/-/escodegen-0.0.7.tgz#a1c3e3dfd76da89f01d7d196eebe227ebe4b6eec" - integrity sha512-46oENdSRNEJXCNrPJoC3vRolZJpfeEm7yvATkd2bCncKFG0PUEyfBCaoacfpcXH4Y5RRuqdVj3J7TI+wwn2SbQ== +"@types/escodegen@0.0.10": + version "0.0.10" + resolved "https://registry.yarnpkg.com/@types/escodegen/-/escodegen-0.0.10.tgz#1699fef93d85f6457c67450d9c318c8e11e8dfc2" + integrity sha512-IVvcNLEFbiL17qiGRGzyfx/u9K6lA5w6wcQSIgv2h4JG3ZAFIY1Be9ITTSPuARIxRpzW54s8OvcF6PdonBbDzg== -"@types/eslint-scope@3.7.4", "@types/eslint-scope@^3.7.3": - version "3.7.4" - resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.4.tgz#37fc1223f0786c39627068a12e94d6e6fc61de16" - integrity sha512-9K4zoImiZc3HlIp6AVUDE4CWYx22a+lhSZMYNpbjW04+YF0KWj4pJXnEMjdnFTiQibFFmElcsasJXDbdI/EPhA== +"@types/eslint-scope@3.7.7", "@types/eslint-scope@^3.7.7": + version "3.7.7" + resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.7.tgz#3108bd5f18b0cdb277c867b3dd449c9ed7079ac5" + integrity sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg== dependencies: "@types/eslint" "*" "@types/estree" "*" @@ -515,38 +585,30 @@ "@types/estree" "*" "@types/json-schema" "*" -"@types/eslint@^8.4.10": - version "8.21.0" - resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.21.0.tgz#21724cfe12b96696feafab05829695d4d7bd7c48" - integrity sha512-35EhHNOXgxnUgh4XCJsGhE7zdlDhYDN/aMG6UbkByCFFNgQ7b3U+uVoqBpicFydR8JEfgdjCF7SJ7MiJfzuiTA== - dependencies: - "@types/estree" "*" - "@types/json-schema" "*" - -"@types/eslint@^8.56.5": - version "8.56.10" - resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.56.10.tgz#eb2370a73bf04a901eeba8f22595c7ee0f7eb58d" - integrity sha512-Shavhk87gCtY2fhXDctcfS3e6FdxWkCx1iUZ9eEUbh7rTqlZT0/IzOkCOVt0fCjcFuZ9FPYfuezTBImfHCDBGQ== +"@types/eslint@^8.56.10": + version "8.56.12" + resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.56.12.tgz#1657c814ffeba4d2f84c0d4ba0f44ca7ea1ca53a" + integrity sha512-03ruubjWyOHlmljCVoxSuNDdmfZDzsrrz0P2LeJsOXr+ZwFQ+0yQIwNCwt/GYhV7Z31fgtXJTAEs+FYlEL851g== dependencies: "@types/estree" "*" "@types/json-schema" "*" -"@types/estraverse@5.1.2": - version "5.1.2" - resolved "https://registry.yarnpkg.com/@types/estraverse/-/estraverse-5.1.2.tgz#44672ec45591f54bad039ac243d05826b7e3d825" - integrity sha512-3Rndn7sxqRc57WCN+LEaTmwgHAxrGUylgUk5zZsKzqioCbXpk7nSBxDWjPLoE96ZeykGFORMJ45V7N1TFaPg6A== +"@types/estraverse@5.1.7": + version "5.1.7" + resolved "https://registry.yarnpkg.com/@types/estraverse/-/estraverse-5.1.7.tgz#d0e45194ba425cf31f3740ee8cc46ca8aa768a7c" + integrity sha512-JRVtdKYZz7VkNp7hMC/WKoiZ8DS3byw20ZGoMZ1R8eBrBPIY7iBaDAS1zcrnXQCwK44G4vbXkimeU7R0VLG8UQ== dependencies: "@types/estree" "*" -"@types/estree@*", "@types/estree@0.0.51", "@types/estree@^0.0.51": +"@types/estree@*", "@types/estree@0.0.51": version "0.0.51" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40" integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ== -"@types/estree@^1.0.5": - version "1.0.5" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4" - integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw== +"@types/estree@^1.0.8": + version "1.0.8" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.8.tgz#958b91c991b1867ced318bedea0e215ee050726e" + integrity sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w== "@types/events@*": version "3.0.0" @@ -581,25 +643,25 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/js-beautify@1.13.3": - version "1.13.3" - resolved "https://registry.yarnpkg.com/@types/js-beautify/-/js-beautify-1.13.3.tgz#53839bb5b766d0fb45e87386100bb3bcbb7dca9d" - integrity sha512-ucIPw5gmNyvRKi6mpeojlqp+T+6ZBJeU+kqMDnIEDlijEU4QhLTon90sZ3cz9HZr+QTwXILjNsMZImzA7+zuJA== +"@types/js-beautify@1.14.3": + version "1.14.3" + resolved "https://registry.yarnpkg.com/@types/js-beautify/-/js-beautify-1.14.3.tgz#6ced76f79935e37e0d613110dea369881d93c1ff" + integrity sha512-FMbQHz+qd9DoGvgLHxeqqVPaNRffpIu5ZjozwV8hf9JAGpIOzuAf4wGbRSo8LNITHqGjmmVjaMggTT5P4v4IHg== -"@types/js-string-escape@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@types/js-string-escape/-/js-string-escape-1.0.1.tgz#662b8795ac2842981f6c46dc2289c0a81940f605" - integrity sha512-s3Tz/P+u4X78n0TdgNR0l9Yu1jyH2dRwofi/DqGLpbbjiuIs0n6W8W4XfUI6+9K0lPK1fF4KHA5HcqtOsy1V0Q== +"@types/js-string-escape@1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@types/js-string-escape/-/js-string-escape-1.0.3.tgz#2ca3200f96e176125e577247d7cbb0c6a80d728c" + integrity sha512-D3SEAdmrWQTAVR3fQVc/idOCSqXINe8JoRAW3k6pOVgCO74aPs5KJql8sDxXlo2DNE+u0N2pnqFQL8VR9hGd6w== "@types/json-schema@*": version "7.0.4" resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.4.tgz" integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA== -"@types/json-schema@^7.0.6": - version "7.0.6" - resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.6.tgz" - integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw== +"@types/json-schema@^7.0.15": + version "7.0.15" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" + integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== "@types/json-schema@^7.0.8": version "7.0.8" @@ -616,10 +678,10 @@ resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz" integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4= -"@types/md5@2.3.2": - version "2.3.2" - resolved "https://registry.yarnpkg.com/@types/md5/-/md5-2.3.2.tgz#529bb3f8a7e9e9f621094eb76a443f585d882528" - integrity sha512-v+JFDu96+UYJ3/UWzB0mEglIS//MZXgRaJ4ubUPwOM0gvLc/kcQ3TWNYwENEK7/EcXGQVrW8h/XqednSjBd/Og== +"@types/md5@2.3.6": + version "2.3.6" + resolved "https://registry.yarnpkg.com/@types/md5/-/md5-2.3.6.tgz#db6901a9fc1d95eeed851a62c5ce5dedfac8ff9a" + integrity sha512-WD69gNXtRBnpknfZcb4TRQ0XJQbUPZcai/Qdhmka3sxUR3Et8NrXoeAoknG/LghYHTf4ve795rInVYHBTQdNVA== "@types/minimatch@*", "@types/minimatch@^3.0.3": version "3.0.3" @@ -633,10 +695,10 @@ dependencies: "@types/node" "*" -"@types/mocha@10.0.1": - version "10.0.1" - resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.1.tgz#2f4f65bb08bc368ac39c96da7b2f09140b26851b" - integrity sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q== +"@types/mocha@10.0.10": + version "10.0.10" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.10.tgz#91f62905e8d23cbd66225312f239454a23bebfa0" + integrity sha512-xPyYSz1cMPnJQhl0CLMH68j3gprKZaTjG3s5Vi+fDgx+uhG9NOXwbVt52eFS8ECyXhyKcjDLCBEqBExKuiZb7Q== "@types/multimatch@4.0.0": version "4.0.0" @@ -650,21 +712,18 @@ resolved "https://registry.npmjs.org/@types/node/-/node-13.9.3.tgz" integrity sha512-01s+ac4qerwd6RHD+mVbOEsraDHSgUaefQlEdBbUolnQFjKwCr7luvAlEwW1RFojh67u0z4OUTjPn9LEl4zIkA== -"@types/node@18.13.0": - version "18.13.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.13.0.tgz#0400d1e6ce87e9d3032c19eb6c58205b0d3f7850" - integrity sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg== +"@types/node@22.10.2": + version "22.10.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.10.2.tgz#a485426e6d1fdafc7b0d4c7b24e2c78182ddabb9" + integrity sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ== + dependencies: + undici-types "~6.20.0" "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz" integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA== -"@types/parse-json@^4.0.0": - version "4.0.0" - resolved "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz" - integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA== - "@types/rimraf@3.0.2": version "3.0.2" resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-3.0.2.tgz#a63d175b331748e5220ad48c901d7bbf1f44eef8" @@ -673,15 +732,10 @@ "@types/glob" "*" "@types/node" "*" -"@types/semver@^7.3.12": - version "7.3.13" - resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91" - integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw== - -"@types/sinon@10.0.13": - version "10.0.13" - resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-10.0.13.tgz#60a7a87a70d9372d0b7b38cc03e825f46981fb83" - integrity sha512-UVjDqJblVNQYvVNUsj0PuYYw0ELRmgt1Nt5Vk0pT5f16ROGfcKJY8o1HVuMOJOpD727RrGB9EGvoaTQE5tgxZQ== +"@types/sinon@17.0.4": + version "17.0.4" + resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-17.0.4.tgz#fd9a3e8e07eea1a3f4a6f82a972c899e5778f369" + integrity sha512-RHnIrhfPO3+tJT0s7cFaXGZvsL4bbR3/k7z3P312qMS4JaS2Tk+KiwiLx1S0rQ56ERj00u1/BtdyVd0FY+Pdew== dependencies: "@types/sinonjs__fake-timers" "*" @@ -690,20 +744,20 @@ resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz#bf2e02a3dbd4aecaf95942ecd99b7402e03fad5e" integrity sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA== -"@types/string-template@1.0.2": - version "1.0.2" - resolved "https://registry.npmjs.org/@types/string-template/-/string-template-1.0.2.tgz" - integrity sha1-NjsnPJtFZwXjER41cekkj2R066Q= +"@types/string-template@1.0.7": + version "1.0.7" + resolved "https://registry.yarnpkg.com/@types/string-template/-/string-template-1.0.7.tgz#593fd97fd7515ae6eba80a142738daadc961c895" + integrity sha512-sQWEsTbB0pKCc1eAC9mwTKftyXuWfSZVfDTskhlQLE/xTtuevqOlFG/t4Djf/VFbRdt7PROaovoqpWfZWhMRfA== -"@types/validator@^13.7.10": - version "13.7.10" - resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.7.10.tgz#f9763dc0933f8324920afa9c0790308eedf55ca7" - integrity sha512-t1yxFAR2n0+VO6hd/FJ9F2uezAZVWHLmpmlJzm1eX03+H7+HsuTAp7L8QJs+2pQCfWkP1+EXsGK9Z9v7o/qPVQ== +"@types/validator@^13.11.8": + version "13.15.4" + resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.15.4.tgz#38a97ae54747416f745afdfc678f041713082635" + integrity sha512-LSFfpSnJJY9wbC0LQxgvfb+ynbHftFo0tMsFOl/J4wexLnYMmDSPaj2ZyDv3TkfL1UePxPrxOWJfbiRS8mQv7A== -"@types/webpack-env@1.18.0": - version "1.18.0" - resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.0.tgz#ed6ecaa8e5ed5dfe8b2b3d00181702c9925f13fb" - integrity sha512-56/MAlX5WMsPVbOg7tAxnYvNYMMWr/QJiIp6BxVSW3JJXUVzzOn64qW8TzQyMSqSUFM2+PVI4aUHcHOzIz/1tg== +"@types/webpack-env@1.18.8": + version "1.18.8" + resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.8.tgz#71f083718c094204d7b64443701d32f1db3989e3" + integrity sha512-G9eAoJRMLjcvN4I08wB5I7YofOb/kaJNd5uoCMX+LbKXTPCF+ZIHuqTnFaK9Jz1rgs035f9JUPUhNFtqgucy/A== "@types/yargs-parser@*": version "21.0.0" @@ -717,230 +771,227 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@5.51.0": - version "5.51.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.51.0.tgz#da3f2819633061ced84bb82c53bba45a6fe9963a" - integrity sha512-wcAwhEWm1RgNd7dxD/o+nnLW8oH+6RK1OGnmbmkj/GGoDPV1WWMVP0FXYQBivKHdwM1pwii3bt//RC62EriIUQ== +"@typescript-eslint/eslint-plugin@7.18.0": + version "7.18.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.18.0.tgz#b16d3cf3ee76bf572fdf511e79c248bdec619ea3" + integrity sha512-94EQTWZ40mzBc42ATNIBimBEDltSJ9RQHCC8vc/PDbxi4k8dVwUAv4o98dk50M1zB+JGFxp43FP7f8+FP8R6Sw== + dependencies: + "@eslint-community/regexpp" "^4.10.0" + "@typescript-eslint/scope-manager" "7.18.0" + "@typescript-eslint/type-utils" "7.18.0" + "@typescript-eslint/utils" "7.18.0" + "@typescript-eslint/visitor-keys" "7.18.0" + graphemer "^1.4.0" + ignore "^5.3.1" + natural-compare "^1.4.0" + ts-api-utils "^1.3.0" + +"@typescript-eslint/parser@7.18.0": + version "7.18.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.18.0.tgz#83928d0f1b7f4afa974098c64b5ce6f9051f96a0" + integrity sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg== dependencies: - "@typescript-eslint/scope-manager" "5.51.0" - "@typescript-eslint/type-utils" "5.51.0" - "@typescript-eslint/utils" "5.51.0" - debug "^4.3.4" - grapheme-splitter "^1.0.4" - ignore "^5.2.0" - natural-compare-lite "^1.4.0" - regexpp "^3.2.0" - semver "^7.3.7" - tsutils "^3.21.0" - -"@typescript-eslint/parser@5.51.0": - version "5.51.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.51.0.tgz#2d74626652096d966ef107f44b9479f02f51f271" - integrity sha512-fEV0R9gGmfpDeRzJXn+fGQKcl0inIeYobmmUWijZh9zA7bxJ8clPhV9up2ZQzATxAiFAECqPQyMDB4o4B81AaA== - dependencies: - "@typescript-eslint/scope-manager" "5.51.0" - "@typescript-eslint/types" "5.51.0" - "@typescript-eslint/typescript-estree" "5.51.0" + "@typescript-eslint/scope-manager" "7.18.0" + "@typescript-eslint/types" "7.18.0" + "@typescript-eslint/typescript-estree" "7.18.0" + "@typescript-eslint/visitor-keys" "7.18.0" debug "^4.3.4" -"@typescript-eslint/scope-manager@5.51.0": - version "5.51.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.51.0.tgz#ad3e3c2ecf762d9a4196c0fbfe19b142ac498990" - integrity sha512-gNpxRdlx5qw3yaHA0SFuTjW4rxeYhpHxt491PEcKF8Z6zpq0kMhe0Tolxt0qjlojS+/wArSDlj/LtE69xUJphQ== +"@typescript-eslint/scope-manager@7.18.0": + version "7.18.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.18.0.tgz#c928e7a9fc2c0b3ed92ab3112c614d6bd9951c83" + integrity sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA== dependencies: - "@typescript-eslint/types" "5.51.0" - "@typescript-eslint/visitor-keys" "5.51.0" + "@typescript-eslint/types" "7.18.0" + "@typescript-eslint/visitor-keys" "7.18.0" -"@typescript-eslint/type-utils@5.51.0": - version "5.51.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.51.0.tgz#7af48005531700b62a20963501d47dfb27095988" - integrity sha512-QHC5KKyfV8sNSyHqfNa0UbTbJ6caB8uhcx2hYcWVvJAZYJRBo5HyyZfzMdRx8nvS+GyMg56fugMzzWnojREuQQ== +"@typescript-eslint/type-utils@7.18.0": + version "7.18.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.18.0.tgz#2165ffaee00b1fbbdd2d40aa85232dab6998f53b" + integrity sha512-XL0FJXuCLaDuX2sYqZUUSOJ2sG5/i1AAze+axqmLnSkNEVMVYLF+cbwlB2w8D1tinFuSikHmFta+P+HOofrLeA== dependencies: - "@typescript-eslint/typescript-estree" "5.51.0" - "@typescript-eslint/utils" "5.51.0" + "@typescript-eslint/typescript-estree" "7.18.0" + "@typescript-eslint/utils" "7.18.0" debug "^4.3.4" - tsutils "^3.21.0" - -"@typescript-eslint/types@5.51.0": - version "5.51.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.51.0.tgz#e7c1622f46c7eea7e12bbf1edfb496d4dec37c90" - integrity sha512-SqOn0ANn/v6hFn0kjvLwiDi4AzR++CBZz0NV5AnusT2/3y32jdc0G4woXPWHCumWtUXZKPAS27/9vziSsC9jnw== + ts-api-utils "^1.3.0" -"@typescript-eslint/types@^7.2.0": - version "7.13.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.13.0.tgz#0cca95edf1f1fdb0cfe1bb875e121b49617477c5" - integrity sha512-QWuwm9wcGMAuTsxP+qz6LBBd3Uq8I5Nv8xb0mk54jmNoCyDspnMvVsOxI6IsMmway5d1S9Su2+sCKv1st2l6eA== +"@typescript-eslint/types@7.18.0": + version "7.18.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.18.0.tgz#b90a57ccdea71797ffffa0321e744f379ec838c9" + integrity sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ== -"@typescript-eslint/typescript-estree@5.51.0": - version "5.51.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.51.0.tgz#0ec8170d7247a892c2b21845b06c11eb0718f8de" - integrity sha512-TSkNupHvNRkoH9FMA3w7TazVFcBPveAAmb7Sz+kArY6sLT86PA5Vx80cKlYmd8m3Ha2SwofM1KwraF24lM9FvA== +"@typescript-eslint/typescript-estree@7.18.0": + version "7.18.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.18.0.tgz#b5868d486c51ce8f312309ba79bdb9f331b37931" + integrity sha512-aP1v/BSPnnyhMHts8cf1qQ6Q1IFwwRvAQGRvBFkWlo3/lH29OXA3Pts+c10nxRxIBrDnoMqzhgdwVe5f2D6OzA== dependencies: - "@typescript-eslint/types" "5.51.0" - "@typescript-eslint/visitor-keys" "5.51.0" + "@typescript-eslint/types" "7.18.0" + "@typescript-eslint/visitor-keys" "7.18.0" debug "^4.3.4" globby "^11.1.0" is-glob "^4.0.3" - semver "^7.3.7" - tsutils "^3.21.0" + minimatch "^9.0.4" + semver "^7.6.0" + ts-api-utils "^1.3.0" -"@typescript-eslint/utils@5.51.0": - version "5.51.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.51.0.tgz#074f4fabd5b12afe9c8aa6fdee881c050f8b4d47" - integrity sha512-76qs+5KWcaatmwtwsDJvBk4H76RJQBFe+Gext0EfJdC3Vd2kpY2Pf//OHHzHp84Ciw0/rYoGTDnIAr3uWhhJYw== - dependencies: - "@types/json-schema" "^7.0.9" - "@types/semver" "^7.3.12" - "@typescript-eslint/scope-manager" "5.51.0" - "@typescript-eslint/types" "5.51.0" - "@typescript-eslint/typescript-estree" "5.51.0" - eslint-scope "^5.1.1" - eslint-utils "^3.0.0" - semver "^7.3.7" - -"@typescript-eslint/visitor-keys@5.51.0": - version "5.51.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.51.0.tgz#c0147dd9a36c0de758aaebd5b48cae1ec59eba87" - integrity sha512-Oh2+eTdjHjOFjKA27sxESlA87YPSOJafGCR0md5oeMdh1ZcCfAGCIOL216uTBAkAIptvLIfKQhl7lHxMJet4GQ== - dependencies: - "@typescript-eslint/types" "5.51.0" - eslint-visitor-keys "^3.3.0" - -"@webassemblyjs/ast@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" - integrity sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw== +"@typescript-eslint/utils@7.18.0": + version "7.18.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.18.0.tgz#bca01cde77f95fc6a8d5b0dbcbfb3d6ca4be451f" + integrity sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw== dependencies: - "@webassemblyjs/helper-numbers" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - -"@webassemblyjs/floating-point-hex-parser@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.1.tgz#f6c61a705f0fd7a6aecaa4e8198f23d9dc179e4f" - integrity sha512-iGRfyc5Bq+NnNuX8b5hwBrRjzf0ocrJPI6GWFodBFzmFnyvrQ83SHKhmilCU/8Jv67i4GJZBMhEzltxzcNagtQ== - -"@webassemblyjs/helper-api-error@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.1.tgz#1a63192d8788e5c012800ba6a7a46c705288fd16" - integrity sha512-RlhS8CBCXfRUR/cwo2ho9bkheSXG0+NwooXcc3PAILALf2QLdFyj7KGsKRbVc95hZnhnERon4kW/D3SZpp6Tcg== - -"@webassemblyjs/helper-buffer@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.1.tgz#832a900eb444884cde9a7cad467f81500f5e5ab5" - integrity sha512-gwikF65aDNeeXa8JxXa2BAk+REjSyhrNC9ZwdT0f8jc4dQQeDQ7G4m0f2QCLPJiMTTO6wfDmRmj/pW0PsUvIcA== + "@eslint-community/eslint-utils" "^4.4.0" + "@typescript-eslint/scope-manager" "7.18.0" + "@typescript-eslint/types" "7.18.0" + "@typescript-eslint/typescript-estree" "7.18.0" -"@webassemblyjs/helper-numbers@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.1.tgz#64d81da219fbbba1e3bd1bfc74f6e8c4e10a62ae" - integrity sha512-vDkbxiB8zfnPdNK9Rajcey5C0w+QJugEglN0of+kmO8l7lDb77AnlKYQF7aarZuCrv+l0UvqL+68gSDr3k9LPQ== +"@typescript-eslint/visitor-keys@7.18.0": + version "7.18.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.18.0.tgz#0564629b6124d67607378d0f0332a0495b25e7d7" + integrity sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg== dependencies: - "@webassemblyjs/floating-point-hex-parser" "1.11.1" - "@webassemblyjs/helper-api-error" "1.11.1" + "@typescript-eslint/types" "7.18.0" + eslint-visitor-keys "^3.4.3" + +"@ungap/structured-clone@^1.2.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.3.0.tgz#d06bbb384ebcf6c505fde1c3d0ed4ddffe0aaff8" + integrity sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g== + +"@webassemblyjs/ast@1.14.1", "@webassemblyjs/ast@^1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.14.1.tgz#a9f6a07f2b03c95c8d38c4536a1fdfb521ff55b6" + integrity sha512-nuBEDgQfm1ccRp/8bCQrx1frohyufl4JlbMMZ4P1wpeOfDhF6FQkxZJ1b/e+PLwr6X1Nhw6OLme5usuBWYBvuQ== + dependencies: + "@webassemblyjs/helper-numbers" "1.13.2" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" + +"@webassemblyjs/floating-point-hex-parser@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.13.2.tgz#fcca1eeddb1cc4e7b6eed4fc7956d6813b21b9fb" + integrity sha512-6oXyTOzbKxGH4steLbLNOu71Oj+C8Lg34n6CqRvqfS2O71BxY6ByfMDRhBytzknj9yGUPVJ1qIKhRlAwO1AovA== + +"@webassemblyjs/helper-api-error@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.13.2.tgz#e0a16152248bc38daee76dd7e21f15c5ef3ab1e7" + integrity sha512-U56GMYxy4ZQCbDZd6JuvvNV/WFildOjsaWD3Tzzvmw/mas3cXzRJPMjP83JqEsgSbyrmaGjBfDtV7KDXV9UzFQ== + +"@webassemblyjs/helper-buffer@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.14.1.tgz#822a9bc603166531f7d5df84e67b5bf99b72b96b" + integrity sha512-jyH7wtcHiKssDtFPRB+iQdxlDf96m0E39yb0k5uJVhFGleZFoNw1c4aeIcVUPPbXUVJ94wwnMOAqUHyzoEPVMA== + +"@webassemblyjs/helper-numbers@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.13.2.tgz#dbd932548e7119f4b8a7877fd5a8d20e63490b2d" + integrity sha512-FE8aCmS5Q6eQYcV3gI35O4J789wlQA+7JrqTTpJqn5emA4U2hvwJmvFRC0HODS+3Ye6WioDklgd6scJ3+PLnEA== + dependencies: + "@webassemblyjs/floating-point-hex-parser" "1.13.2" + "@webassemblyjs/helper-api-error" "1.13.2" "@xtuc/long" "4.2.2" -"@webassemblyjs/helper-wasm-bytecode@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.1.tgz#f328241e41e7b199d0b20c18e88429c4433295e1" - integrity sha512-PvpoOGiJwXeTrSf/qfudJhwlvDQxFgelbMqtq52WWiXC6Xgg1IREdngmPN3bs4RoO83PnL/nFrxucXj1+BX62Q== +"@webassemblyjs/helper-wasm-bytecode@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.13.2.tgz#e556108758f448aae84c850e593ce18a0eb31e0b" + integrity sha512-3QbLKy93F0EAIXLh0ogEVR6rOubA9AoZ+WRYhNbFyuB70j3dRdwH9g+qXhLAO0kiYGlg3TxDV+I4rQTr/YNXkA== -"@webassemblyjs/helper-wasm-section@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.1.tgz#21ee065a7b635f319e738f0dd73bfbda281c097a" - integrity sha512-10P9No29rYX1j7F3EVPX3JvGPQPae+AomuSTPiF9eBQeChHI6iqjMIwR9JmOJXwpnn/oVGDk7I5IlskuMwU/pg== +"@webassemblyjs/helper-wasm-section@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.14.1.tgz#9629dda9c4430eab54b591053d6dc6f3ba050348" + integrity sha512-ds5mXEqTJ6oxRoqjhWDU83OgzAYjwsCV8Lo/N+oRsNDmx/ZDpqalmrtgOMkHwxsG0iI//3BwWAErYRHtgn0dZw== dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-buffer" "1.14.1" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" + "@webassemblyjs/wasm-gen" "1.14.1" -"@webassemblyjs/ieee754@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.1.tgz#963929e9bbd05709e7e12243a099180812992614" - integrity sha512-hJ87QIPtAMKbFq6CGTkZYJivEwZDbQUgYd3qKSadTNOhVY7p+gfP6Sr0lLRVTaG1JjFj+r3YchoqRYxNH3M0GQ== +"@webassemblyjs/ieee754@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.13.2.tgz#1c5eaace1d606ada2c7fd7045ea9356c59ee0dba" + integrity sha512-4LtOzh58S/5lX4ITKxnAK2USuNEvpdVV9AlgGQb8rJDHaLeHciwG4zlGr0j/SNWlr7x3vO1lDEsuePvtcDNCkw== dependencies: "@xtuc/ieee754" "^1.2.0" -"@webassemblyjs/leb128@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.1.tgz#ce814b45574e93d76bae1fb2644ab9cdd9527aa5" - integrity sha512-BJ2P0hNZ0u+Th1YZXJpzW6miwqQUGcIHT1G/sf72gLVD9DZ5AdYTqPNbHZh6K1M5VmKvFXwGSWZADz+qBWxeRw== +"@webassemblyjs/leb128@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.13.2.tgz#57c5c3deb0105d02ce25fa3fd74f4ebc9fd0bbb0" + integrity sha512-Lde1oNoIdzVzdkNEAWZ1dZ5orIbff80YPdHx20mrHwHrVNNTjNr8E3xz9BdpcGqRQbAEa+fkrCb+fRFTl/6sQw== dependencies: "@xtuc/long" "4.2.2" -"@webassemblyjs/utf8@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.1.tgz#d1f8b764369e7c6e6bae350e854dec9a59f0a3ff" - integrity sha512-9kqcxAEdMhiwQkHpkNiorZzqpGrodQQ2IGrHHxCy+Ozng0ofyMA0lTqiLkVs1uzTRejX+/O0EOT7KxqVPuXosQ== - -"@webassemblyjs/wasm-edit@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.1.tgz#ad206ebf4bf95a058ce9880a8c092c5dec8193d6" - integrity sha512-g+RsupUC1aTHfR8CDgnsVRVZFJqdkFHpsHMfJuWQzWU3tvnLC07UqHICfP+4XyL2tnr1amvl1Sdp06TnYCmVkA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/helper-wasm-section" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" - "@webassemblyjs/wasm-opt" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" - "@webassemblyjs/wast-printer" "1.11.1" - -"@webassemblyjs/wasm-gen@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.1.tgz#86c5ea304849759b7d88c47a32f4f039ae3c8f76" - integrity sha512-F7QqKXwwNlMmsulj6+O7r4mmtAlCWfO/0HdgOxSklZfQcDu0TpLiD1mRt/zF25Bk59FIjEuGAIyn5ei4yMfLhA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/ieee754" "1.11.1" - "@webassemblyjs/leb128" "1.11.1" - "@webassemblyjs/utf8" "1.11.1" - -"@webassemblyjs/wasm-opt@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.1.tgz#657b4c2202f4cf3b345f8a4c6461c8c2418985f2" - integrity sha512-VqnkNqnZlU5EB64pp1l7hdm3hmQw7Vgqa0KF/KCNO9sIpI6Fk6brDEiX+iCOYrvMuBWDws0NkTOxYEb85XQHHw== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-buffer" "1.11.1" - "@webassemblyjs/wasm-gen" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" - -"@webassemblyjs/wasm-parser@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.1.tgz#86ca734534f417e9bd3c67c7a1c75d8be41fb199" - integrity sha512-rrBujw+dJu32gYB7/Lup6UhdkPx9S9SnobZzRVL7VcBH9Bt9bCBLEuX/YXOOtBsOZ4NQrRykKhffRWHvigQvOA== - dependencies: - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/helper-api-error" "1.11.1" - "@webassemblyjs/helper-wasm-bytecode" "1.11.1" - "@webassemblyjs/ieee754" "1.11.1" - "@webassemblyjs/leb128" "1.11.1" - "@webassemblyjs/utf8" "1.11.1" - -"@webassemblyjs/wast-printer@1.11.1": - version "1.11.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.1.tgz#d0c73beda8eec5426f10ae8ef55cee5e7084c2f0" - integrity sha512-IQboUWM4eKzWW+N/jij2sRatKMh99QEelo3Eb2q0qXkvPRISAj8Qxtmw5itwqK+TTkBuUIE45AxYPToqPtL5gg== - dependencies: - "@webassemblyjs/ast" "1.11.1" +"@webassemblyjs/utf8@1.13.2": + version "1.13.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.13.2.tgz#917a20e93f71ad5602966c2d685ae0c6c21f60f1" + integrity sha512-3NQWGjKTASY1xV5m7Hr0iPeXD9+RDobLll3T9d2AO+g3my8xy5peVyjSag4I50mR1bBSN/Ct12lo+R9tJk0NZQ== + +"@webassemblyjs/wasm-edit@^1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.14.1.tgz#ac6689f502219b59198ddec42dcd496b1004d597" + integrity sha512-RNJUIQH/J8iA/1NzlE4N7KtyZNHi3w7at7hDjvRNm5rcUXa00z1vRz3glZoULfJ5mpvYhLybmVcwcjGrC1pRrQ== + dependencies: + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-buffer" "1.14.1" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" + "@webassemblyjs/helper-wasm-section" "1.14.1" + "@webassemblyjs/wasm-gen" "1.14.1" + "@webassemblyjs/wasm-opt" "1.14.1" + "@webassemblyjs/wasm-parser" "1.14.1" + "@webassemblyjs/wast-printer" "1.14.1" + +"@webassemblyjs/wasm-gen@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.14.1.tgz#991e7f0c090cb0bb62bbac882076e3d219da9570" + integrity sha512-AmomSIjP8ZbfGQhumkNvgC33AY7qtMCXnN6bL2u2Js4gVCg8fp735aEiMSBbDR7UQIj90n4wKAFUSEd0QN2Ukg== + dependencies: + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" + "@webassemblyjs/ieee754" "1.13.2" + "@webassemblyjs/leb128" "1.13.2" + "@webassemblyjs/utf8" "1.13.2" + +"@webassemblyjs/wasm-opt@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.14.1.tgz#e6f71ed7ccae46781c206017d3c14c50efa8106b" + integrity sha512-PTcKLUNvBqnY2U6E5bdOQcSM+oVP/PmrDY9NzowJjislEjwP/C4an2303MCVS2Mg9d3AJpIGdUFIQQWbPds0Sw== + dependencies: + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-buffer" "1.14.1" + "@webassemblyjs/wasm-gen" "1.14.1" + "@webassemblyjs/wasm-parser" "1.14.1" + +"@webassemblyjs/wasm-parser@1.14.1", "@webassemblyjs/wasm-parser@^1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.14.1.tgz#b3e13f1893605ca78b52c68e54cf6a865f90b9fb" + integrity sha512-JLBl+KZ0R5qB7mCnud/yyX08jWFw5MsoalJ1pQ4EdFlgj9VdXKGuENGsiCIjegI1W7p91rUlcB/LB5yRJKNTcQ== + dependencies: + "@webassemblyjs/ast" "1.14.1" + "@webassemblyjs/helper-api-error" "1.13.2" + "@webassemblyjs/helper-wasm-bytecode" "1.13.2" + "@webassemblyjs/ieee754" "1.13.2" + "@webassemblyjs/leb128" "1.13.2" + "@webassemblyjs/utf8" "1.13.2" + +"@webassemblyjs/wast-printer@1.14.1": + version "1.14.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.14.1.tgz#3bb3e9638a8ae5fdaf9610e7a06b4d9f9aa6fe07" + integrity sha512-kPSSXE6De1XOR820C90RIo2ogvZG+c3KiHzqUoO/F34Y2shGzesfqv7o57xrxovZJH/MetF5UjroJ/R/3isoiw== + dependencies: + "@webassemblyjs/ast" "1.14.1" "@xtuc/long" "4.2.2" -"@webpack-cli/configtest@^2.0.1": - version "2.0.1" - resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-2.0.1.tgz#a69720f6c9bad6aef54a8fa6ba9c3533e7ef4c7f" - integrity sha512-njsdJXJSiS2iNbQVS0eT8A/KPnmyH4pv1APj2K0d1wrZcBLw+yppxOy4CGqa0OxDJkzfL/XELDhD8rocnIwB5A== +"@webpack-cli/configtest@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-3.0.1.tgz#76ac285b9658fa642ce238c276264589aa2b6b57" + integrity sha512-u8d0pJ5YFgneF/GuvEiDA61Tf1VDomHHYMjv/wc9XzYj7nopltpG96nXN5dJRstxZhcNpV1g+nT6CydO7pHbjA== -"@webpack-cli/info@^2.0.1": - version "2.0.1" - resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-2.0.1.tgz#eed745799c910d20081e06e5177c2b2569f166c0" - integrity sha512-fE1UEWTwsAxRhrJNikE7v4EotYflkEhBL7EbajfkPlf6E37/2QshOy/D48Mw8G5XMFlQtS6YV42vtbG9zBpIQA== +"@webpack-cli/info@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-3.0.1.tgz#3cff37fabb7d4ecaab6a8a4757d3826cf5888c63" + integrity sha512-coEmDzc2u/ffMvuW9aCjoRzNSPDl/XLuhPdlFRpT9tZHmJ/039az33CE7uH+8s0uL1j5ZNtfdv0HkfaKRBGJsQ== -"@webpack-cli/serve@^2.0.1": - version "2.0.1" - resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-2.0.1.tgz#34bdc31727a1889198855913db2f270ace6d7bf8" - integrity sha512-0G7tNyS+yW8TdgHwZKlDWYXFA6OJQnoLCQvYKkQP0Q2X205PSQ6RNUj0M+1OB/9gRQaUZ/ccYfaxd0nhaWKfjw== +"@webpack-cli/serve@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-3.0.1.tgz#bd8b1f824d57e30faa19eb78e4c0951056f72f00" + integrity sha512-sbgw03xQaCLiT6gcY/6u3qBDn01CWw/nbaXl3gTdTFuJJ75Gffv3E3DBpgvY2fkkrdS1fpjaXNOmJlnbtKauKg== "@xtuc/ieee754@^1.2.0": version "1.2.0" @@ -952,15 +1003,15 @@ resolved "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz" integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ== -abbrev@^1.0.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" - integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== +abbrev@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-2.0.0.tgz#cf59829b8b4f03f89dda2771cb7f3653828c89bf" + integrity sha512-6/mh1E2u2YgEsCHdY0Yx5oW+61gZU+1vXaoiHHrpKeuRNNgFvS+/jrwHiQhB5apAf5oB7UB7E19ol2R2LKH8hQ== -acorn-import-assertions@^1.7.6: - version "1.8.0" - resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz#ba2b5939ce62c238db6d93d81c9b111b29b855e9" - integrity sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw== +acorn-import-phases@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/acorn-import-phases/-/acorn-import-phases-1.0.4.tgz#16eb850ba99a056cb7cbfe872ffb8972e18c8bd7" + integrity sha512-wKmbr/DDiIXzEOiWrTTUcDm24kQ2vGfZQvM2fwg2vXqR5uW6aapr7ObPtj1th32b9u90/Pf4AItvdTh42fBmVQ== acorn-jsx@^5.3.2: version "5.3.2" @@ -972,10 +1023,10 @@ acorn-walk@^8.1.1: resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== -acorn@8.8.2, acorn@^8.5.0, acorn@^8.7.1, acorn@^8.8.0: - version "8.8.2" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a" - integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw== +acorn@8.15.0, acorn@^8.15.0, acorn@^8.9.0: + version "8.15.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.15.0.tgz#a360898bc415edaac46c8241f6383975b930b816" + integrity sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg== acorn@^8.4.1: version "8.4.1" @@ -1002,14 +1053,14 @@ ajv-keywords@^3.5.2: resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== -ajv-keywords@^5.0.0: +ajv-keywords@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-5.1.0.tgz#69d4d385a4733cdbeab44964a1170a88f87f0e16" integrity sha512-YCS/JNFAUyr5vAuhk1DWm1CBxRHW9LbJ2ozWeemrIqpbsqKjHVxYPyi5GC0rjZIT5JxJ3virVTS8wk4i/Z+krw== dependencies: fast-deep-equal "^3.1.3" -ajv@^6.10.0, ajv@^6.12.4, ajv@^6.12.5: +ajv@^6.12.4, ajv@^6.12.5: version "6.12.6" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== @@ -1019,7 +1070,7 @@ ajv@^6.10.0, ajv@^6.12.4, ajv@^6.12.5: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ajv@^8.0.0, ajv@^8.8.0: +ajv@^8.0.0: version "8.10.0" resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.10.0.tgz#e573f719bd3af069017e3b66538ab968d040e54d" integrity sha512-bzqAEZOjkrUMl2afH8dknrq5KEk2SrwdBROR+vH1EKVQTqaUbJVPdc/gEdggTMM0Se+s+Ja4ju4TlNcStKl2Hw== @@ -1029,16 +1080,26 @@ ajv@^8.0.0, ajv@^8.8.0: require-from-string "^2.0.2" uri-js "^4.2.2" -ansi-colors@4.1.1: - version "4.1.1" - resolved "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz" - integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== +ajv@^8.9.0: + version "8.17.1" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.17.1.tgz#37d9a5c776af6bc92d7f4f9510eba4c0a60d11a6" + integrity sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g== + dependencies: + fast-deep-equal "^3.1.3" + fast-uri "^3.0.1" + json-schema-traverse "^1.0.0" + require-from-string "^2.0.2" ansi-regex@^5.0.0, ansi-regex@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== +ansi-regex@^6.0.1: + version "6.2.2" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.2.2.tgz#60216eea464d864597ce2832000738a0589650c1" + integrity sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg== + ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz" @@ -1054,13 +1115,10 @@ ansi-styles@^4.0.0, ansi-styles@^4.1.0: "@types/color-name" "^1.1.1" color-convert "^2.0.1" -anymatch@~3.1.2: - version "3.1.2" - resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.2.tgz#c0557c096af32f106198f4f4e2a383537e378716" - integrity sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg== - dependencies: - normalize-path "^3.0.0" - picomatch "^2.0.4" +ansi-styles@^6.1.0: + version "6.2.3" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.3.tgz#c044d5dcc521a076413472597a1acb1f103c4041" + integrity sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg== append-transform@^2.0.0: version "2.0.0" @@ -1096,72 +1154,125 @@ argparse@^2.0.1: resolved "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz" integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== +array-buffer-byte-length@^1.0.1, array-buffer-byte-length@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/array-buffer-byte-length/-/array-buffer-byte-length-1.0.2.tgz#384d12a37295aec3769ab022ad323a18a51ccf8b" + integrity sha512-LHE+8BuR7RYGDKvnrmcuSq3tDcKv9OFEXQt/HpbZhY7V6h0zlUXutnAD82GiFx9rdieCMjkvtcsPqBwgUl1Iiw== + dependencies: + call-bound "^1.0.3" + is-array-buffer "^3.0.5" + array-differ@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/array-differ/-/array-differ-3.0.0.tgz" integrity sha512-THtfYS6KtME/yIAhKjZ2ul7XI96lQGHRputJQHO80LAWQnuGP4iCIN8vdMRboGbIEYBwU33q8Tch1os2+X0kMg== +array-differ@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/array-differ/-/array-differ-4.0.0.tgz#aa3c891c653523290c880022f45b06a42051b026" + integrity sha512-Q6VPTLMsmXZ47ENG3V+wQyZS1ZxXMxFyYzA+Z/GMrJ6yIutAIEf9wTyroTzmGjNfox9/h3GdGBCVh43GVFx4Uw== + array-filter@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/array-filter/-/array-filter-1.0.0.tgz" integrity sha1-uveeYubvTCpMC4MSMtr/7CUfnYM= -array-includes@^3.1.6: - version "3.1.6" - resolved "https://registry.yarnpkg.com/array-includes/-/array-includes-3.1.6.tgz#9e9e720e194f198266ba9e18c29e6a9b0e4b225f" - integrity sha512-sgTbLvL6cNnw24FnbaDyjmvddQ2ML8arZsgaJhoABMoplz/4QRhtrYS+alr1BUM1Bwp6dhx8vVCBSLG+StwOFw== +array-includes@^3.1.9: + version "3.1.9" + resolved "https://registry.yarnpkg.com/array-includes/-/array-includes-3.1.9.tgz#1f0ccaa08e90cdbc3eb433210f903ad0f17c3f3a" + integrity sha512-FmeCCAenzH0KH381SPT5FZmiA/TmpndpcaShhfgEN9eCVjnFBqq3l1xrI42y8+PPLI6hypzou4GXw00WHmPBLQ== dependencies: - call-bind "^1.0.2" - define-properties "^1.1.4" - es-abstract "^1.20.4" - get-intrinsic "^1.1.3" - is-string "^1.0.7" + call-bind "^1.0.8" + call-bound "^1.0.4" + define-properties "^1.2.1" + es-abstract "^1.24.0" + es-object-atoms "^1.1.1" + get-intrinsic "^1.3.0" + is-string "^1.1.1" + math-intrinsics "^1.1.0" array-union@^2.1.0: version "2.1.0" resolved "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz" integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== -array.prototype.flat@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/array.prototype.flat/-/array.prototype.flat-1.3.1.tgz#ffc6576a7ca3efc2f46a143b9d1dda9b4b3cf5e2" - integrity sha512-roTU0KWIOmJ4DRLmwKd19Otg0/mT3qPNt0Qb3GWW8iObuZXxrjB/pzn0R3hqpRSWg4HCwqx+0vwOnWnvlOyeIA== - dependencies: - call-bind "^1.0.2" - define-properties "^1.1.4" - es-abstract "^1.20.4" - es-shim-unscopables "^1.0.0" +array-union@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/array-union/-/array-union-3.0.1.tgz#da52630d327f8b88cfbfb57728e2af5cd9b6b975" + integrity sha512-1OvF9IbWwaeiM9VhzYXVQacMibxpXOMYVNIvMtKRyX9SImBXpKcFr8XvFDeEslCyuH/t6KRt7HEO94AlP8Iatw== -array.prototype.flatmap@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/array.prototype.flatmap/-/array.prototype.flatmap-1.3.1.tgz#1aae7903c2100433cb8261cd4ed310aab5c4a183" - integrity sha512-8UGn9O1FDVvMNB0UlLv4voxRMze7+FpHyF5mSMRjWHUMlpoDViniy05870VlxhfgTnLbpuwTzvD76MTtWxB/mQ== +array.prototype.findlastindex@^1.2.6: + version "1.2.6" + resolved "https://registry.yarnpkg.com/array.prototype.findlastindex/-/array.prototype.findlastindex-1.2.6.tgz#cfa1065c81dcb64e34557c9b81d012f6a421c564" + integrity sha512-F/TKATkzseUExPlfvmwQKGITM3DGTK+vkAsCZoDc5daVygbJBnjEUCbgkAvVFsgfXfX4YIqZ/27G3k3tdXrTxQ== + dependencies: + call-bind "^1.0.8" + call-bound "^1.0.4" + define-properties "^1.2.1" + es-abstract "^1.23.9" + es-errors "^1.3.0" + es-object-atoms "^1.1.1" + es-shim-unscopables "^1.1.0" + +array.prototype.flat@^1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/array.prototype.flat/-/array.prototype.flat-1.3.3.tgz#534aaf9e6e8dd79fb6b9a9917f839ef1ec63afe5" + integrity sha512-rwG/ja1neyLqCuGZ5YYrznA62D4mZXg0i1cIskIUKSiqF3Cje9/wXAls9B9s1Wa2fomMsIv8czB8jZcPmxCXFg== + dependencies: + call-bind "^1.0.8" + define-properties "^1.2.1" + es-abstract "^1.23.5" + es-shim-unscopables "^1.0.2" + +array.prototype.flatmap@^1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/array.prototype.flatmap/-/array.prototype.flatmap-1.3.3.tgz#712cc792ae70370ae40586264629e33aab5dd38b" + integrity sha512-Y7Wt51eKJSyi80hFrJCePGGNo5ktJCslFuboqJsbf57CCPcm5zztluPlc4/aD8sWsKvlwatezpV4U1efk8kpjg== + dependencies: + call-bind "^1.0.8" + define-properties "^1.2.1" + es-abstract "^1.23.5" + es-shim-unscopables "^1.0.2" + +arraybuffer.prototype.slice@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/arraybuffer.prototype.slice/-/arraybuffer.prototype.slice-1.0.4.tgz#9d760d84dbdd06d0cbf92c8849615a1a7ab3183c" + integrity sha512-BNoCY6SXXPQ7gF2opIP4GBE+Xw7U+pHMYKuzjgCN3GwiaIR09UUeKfheyIry77QtrCBlC0KK0q5/TER/tYh3PQ== dependencies: - call-bind "^1.0.2" - define-properties "^1.1.4" - es-abstract "^1.20.4" - es-shim-unscopables "^1.0.0" + array-buffer-byte-length "^1.0.1" + call-bind "^1.0.8" + define-properties "^1.2.1" + es-abstract "^1.23.5" + es-errors "^1.3.0" + get-intrinsic "^1.2.6" + is-array-buffer "^3.0.4" arrify@^2.0.1: version "2.0.1" resolved "https://registry.npmjs.org/arrify/-/arrify-2.0.1.tgz" integrity sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug== -assert@2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/assert/-/assert-2.0.0.tgz" - integrity sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A== +assert@2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/assert/-/assert-2.1.0.tgz#6d92a238d05dc02e7427c881fb8be81c8448b2dd" + integrity sha512-eLHpSK/Y4nhMJ07gDaAzoX/XAKS8PSaojml3M0DM4JpV1LAi5JOJ/p6H/XWrl8L+DzVEvVCW1z3vWAaB9oTsQw== dependencies: - es6-object-assign "^1.1.0" - is-nan "^1.2.1" - object-is "^1.0.1" - util "^0.12.0" + call-bind "^1.0.2" + is-nan "^1.3.2" + object-is "^1.1.5" + object.assign "^4.1.4" + util "^0.12.5" assertion-error@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz" integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== +async-function@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/async-function/-/async-function-1.0.0.tgz#509c9fca60eaf85034c6829838188e4e4c8ffb2b" + integrity sha512-hsU18Ae8CDTR6Kgu9DYf0EbCr/a5iGL0rytQDobUcdpYOKokk8LEjVphnXkDkgpi0wYVsqrXuP0bZxJaTqdgoA== + atob@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" @@ -1174,20 +1285,22 @@ available-typed-arrays@^1.0.0, available-typed-arrays@^1.0.2: dependencies: array-filter "^1.0.0" -available-typed-arrays@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7" - integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== +available-typed-arrays@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz#a5cc375d6a03c2efc87a553f3e0b1522def14846" + integrity sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ== + dependencies: + possible-typed-array-names "^1.0.0" balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz" integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= -binary-extensions@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz" - integrity sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow== +baseline-browser-mapping@^2.8.19: + version "2.8.21" + resolved "https://registry.yarnpkg.com/baseline-browser-mapping/-/baseline-browser-mapping-2.8.21.tgz#2f9cccde871bfa4aec9dbf92d0ee746e4f1892e4" + integrity sha512-JU0h5APyQNsHOlAM7HnQnPToSDQoEBZqzu/YBlqDnEeymPnZDREeXJA3KBMQee+dKteAxZ2AtvQEvVYdZf241Q== brace-expansion@^1.1.7: version "1.1.11" @@ -1204,28 +1317,35 @@ brace-expansion@^2.0.1: dependencies: balanced-match "^1.0.0" -braces@^3.0.1, braces@^3.0.2, braces@~3.0.2: +braces@^3.0.1: version "3.0.2" resolved "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz" integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== dependencies: fill-range "^7.0.1" -browser-stdout@1.3.1: +braces@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== + dependencies: + fill-range "^7.1.1" + +browser-stdout@^1.3.1: version "1.3.1" - resolved "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz" + resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60" integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw== -browserslist@^4.14.5: - version "4.16.6" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.16.6.tgz#d7901277a5a88e554ed305b183ec9b0c08f66fa2" - integrity sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ== +browserslist@^4.24.0, browserslist@^4.26.3: + version "4.27.0" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.27.0.tgz#755654744feae978fbb123718b2f139bc0fa6697" + integrity sha512-AXVQwdhot1eqLihwasPElhX2tAZiBjWdJ9i/Zcj2S6QYIjkx62OKSfnobkriB81C3l4w0rVy3Nt4jaTBltYEpw== dependencies: - caniuse-lite "^1.0.30001219" - colorette "^1.2.2" - electron-to-chromium "^1.3.723" - escalade "^3.1.1" - node-releases "^1.1.71" + baseline-browser-mapping "^2.8.19" + caniuse-lite "^1.0.30001751" + electron-to-chromium "^1.5.238" + node-releases "^2.0.26" + update-browserslist-db "^1.1.4" buffer-from@^1.0.0: version "1.1.1" @@ -1247,6 +1367,14 @@ caching-transform@^4.0.0: package-hash "^4.0.0" write-file-atomic "^3.0.0" +call-bind-apply-helpers@^1.0.0, call-bind-apply-helpers@^1.0.1, call-bind-apply-helpers@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz#4b5428c222be985d79c3d82657479dbe0b59b2d6" + integrity sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ== + dependencies: + es-errors "^1.3.0" + function-bind "^1.1.2" + call-bind@^1.0.0, call-bind@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" @@ -1255,6 +1383,24 @@ call-bind@^1.0.0, call-bind@^1.0.2: function-bind "^1.1.1" get-intrinsic "^1.0.2" +call-bind@^1.0.7, call-bind@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.8.tgz#0736a9660f537e3388826f440d5ec45f744eaa4c" + integrity sha512-oKlSFMcMwpUg2ednkhQ454wfWiU/ul3CkJe/PEHcTKuiX6RpbehUiFMXu13HalGZxfUwCQzZG747YXBn1im9ww== + dependencies: + call-bind-apply-helpers "^1.0.0" + es-define-property "^1.0.0" + get-intrinsic "^1.2.4" + set-function-length "^1.2.2" + +call-bound@^1.0.2, call-bound@^1.0.3, call-bound@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/call-bound/-/call-bound-1.0.4.tgz#238de935d2a2a692928c538c7ccfa91067fd062a" + integrity sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg== + dependencies: + call-bind-apply-helpers "^1.0.2" + get-intrinsic "^1.3.0" + callsites@^3.0.0, callsites@^3.1.0: version "3.1.0" resolved "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz" @@ -1270,30 +1416,30 @@ camelcase@^6.0.0: resolved "https://registry.npmjs.org/camelcase/-/camelcase-6.1.0.tgz" integrity sha512-WCMml9ivU60+8rEJgELlFp1gxFcEGxwYleE3bziHEDeqsqAWGHdimB7beBFGjLzVNgPGyDsfgXLQEYMpmIFnVQ== -caniuse-lite@^1.0.30001219: - version "1.0.30001228" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001228.tgz#bfdc5942cd3326fa51ee0b42fbef4da9d492a7fa" - integrity sha512-QQmLOGJ3DEgokHbMSA8cj2a+geXqmnpyOFT0lhQV6P3/YOJvGDEwoedcwxEQ30gJIwIIunHIicunJ2rzK5gB2A== +caniuse-lite@^1.0.30001751: + version "1.0.30001751" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001751.tgz#dacd5d9f4baeea841641640139d2b2a4df4226ad" + integrity sha512-A0QJhug0Ly64Ii3eIqHu5X51ebln3k4yTUkY1j8drqpWHVreg/VLijN48cZ1bYPiqOQuqpkIKnzr/Ul8V+p6Cw== -chai-exclude@2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/chai-exclude/-/chai-exclude-2.1.0.tgz#653d1218144eafb49b563684ad90b76d12bbc3f9" - integrity sha512-IBnm50Mvl3O1YhPpTgbU8MK0Gw7NHcb18WT2TxGdPKOMtdtZVKLHmQwdvOF7mTlHVQStbXuZKFwkevFtbHjpVg== +chai-exclude@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/chai-exclude/-/chai-exclude-3.0.1.tgz#576b3db23003e84e0bc576694e9a0969e4fbefa3" + integrity sha512-cx7nCdrlkS4xiLTWJ2ewhCi34EeJLt0bWpR+ZUMHT1yrXUeOEtJElXj1rOEm8J3CjU0QlSkHaV/4CRM0cX6yfg== dependencies: fclone "^1.0.11" -chai@4.3.7: - version "4.3.7" - resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.7.tgz#ec63f6df01829088e8bf55fca839bcd464a8ec51" - integrity sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A== +chai@4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/chai/-/chai-4.5.0.tgz#707e49923afdd9b13a8b0b47d33d732d13812fd8" + integrity sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw== dependencies: assertion-error "^1.1.0" - check-error "^1.0.2" - deep-eql "^4.1.2" - get-func-name "^2.0.0" - loupe "^2.3.1" + check-error "^1.0.3" + deep-eql "^4.1.3" + get-func-name "^2.0.2" + loupe "^2.3.6" pathval "^1.1.1" - type-detect "^4.0.5" + type-detect "^4.1.0" chalk@4.1.2, chalk@^4.1.2: version "4.1.2" @@ -1328,10 +1474,10 @@ chalk@^4.1.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chance@1.1.9: - version "1.1.9" - resolved "https://registry.yarnpkg.com/chance/-/chance-1.1.9.tgz#fbf409726a956415b4bde0e8db010f60b60fc01b" - integrity sha512-TfxnA/DcZXRTA4OekA2zL9GH8qscbbl6X0ZqU4tXhGveVY/mXWvEQLt5GwZcYXTEyEFflVtj+pG8nc8EwSm1RQ== +chance@1.1.13: + version "1.1.13" + resolved "https://registry.yarnpkg.com/chance/-/chance-1.1.13.tgz#d4ecfd20c5e6799aaf5c2270d7653b32385cd6e3" + integrity sha512-V6lQCljcLznE7tUYUM9EOAnnKXbctE6j/rdQkYOHIWbfGQbrzTsAXNW9CdU5XCo4ArXQCj/rb6HgxPlmGJcaUg== char-regex@^1.0.2: version "1.0.2" @@ -1343,25 +1489,19 @@ charenc@0.0.2: resolved "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz" integrity sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc= -check-error@^1.0.2: - version "1.0.2" - resolved "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz" - integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII= - -chokidar@3.5.3, chokidar@^3.5.3: - version "3.5.3" - resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" - integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== - dependencies: - anymatch "~3.1.2" - braces "~3.0.2" - glob-parent "~5.1.2" - is-binary-path "~2.1.0" - is-glob "~4.0.1" - normalize-path "~3.0.0" - readdirp "~3.6.0" - optionalDependencies: - fsevents "~2.3.2" +check-error@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.3.tgz#a6502e4312a7ee969f646e83bb3ddd56281bd694" + integrity sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg== + dependencies: + get-func-name "^2.0.2" + +chokidar@^4.0.1: + version "4.0.3" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-4.0.3.tgz#7be37a4c03c9aee1ecfe862a4a23b2c70c205d30" + integrity sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA== + dependencies: + readdirp "^4.0.1" chrome-trace-event@^1.0.2: version "1.0.2" @@ -1370,19 +1510,24 @@ chrome-trace-event@^1.0.2: dependencies: tslib "^1.9.0" -ci-info@^3.2.0, ci-info@^3.6.1: +ci-info@^3.2.0: version "3.8.0" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.8.0.tgz#81408265a5380c929f0bc665d62256628ce9ef91" integrity sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw== -class-validator@0.14.0: - version "0.14.0" - resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.14.0.tgz#40ed0ecf3c83b2a8a6a320f4edb607be0f0df159" - integrity sha512-ct3ltplN8I9fOwUd8GrP8UQixwff129BkEtuWDKL5W45cQuLd19xqmTLu5ge78YDm/fdje6FMt0hGOhl0lii3A== +ci-info@^4.0.0: + version "4.3.1" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-4.3.1.tgz#355ad571920810b5623e11d40232f443f16f1daa" + integrity sha512-Wdy2Igu8OcBpI2pZePZ5oWjPC38tmDVx5WKUXKwlLYkA0ozo85sLsLvkBbBn/sZaSCMFOGZJ14fvW9t5/d7kdA== + +class-validator@0.14.2: + version "0.14.2" + resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.14.2.tgz#a3de95edd26b703e89c151a2023d3c115030340d" + integrity sha512-3kMVRF2io8N8pY1IFIXlho9r8IPUUIfHe2hYVtiebvAzU2XeQFXTv+XI4WX+TnXmtwXMDcjngcpkiPM0O9PvLw== dependencies: - "@types/validator" "^13.7.10" - libphonenumber-js "^1.10.14" - validator "^13.7.0" + "@types/validator" "^13.11.8" + libphonenumber-js "^1.11.1" + validator "^13.9.0" clean-regexp@^1.0.0: version "1.0.0" @@ -1405,13 +1550,13 @@ cliui@^6.0.0: strip-ansi "^6.0.0" wrap-ansi "^6.2.0" -cliui@^7.0.2: - version "7.0.4" - resolved "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz" - integrity sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ== +cliui@^8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa" + integrity sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ== dependencies: string-width "^4.2.0" - strip-ansi "^6.0.0" + strip-ansi "^6.0.1" wrap-ansi "^7.0.0" clone-deep@^4.0.1: @@ -1447,31 +1592,26 @@ color-name@~1.1.4: resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -colorette@^1.2.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.2.tgz#cbcc79d5e99caea2dbf10eb3a26fd8b3e6acfa94" - integrity sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w== - colorette@^2.0.14: version "2.0.16" resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.16.tgz#713b9af84fdb000139f04546bd4a93f62a5085da" integrity sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g== -commander@10.0.0: - version "10.0.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.0.tgz#71797971162cd3cf65f0b9d24eb28f8d303acdf1" - integrity sha512-zS5PnTI22FIRM6ylNW8G4Ap0IEOyk62fhLSD0+uHRT9McRCLGpkVNvao4bjimpK/GShynyQkFFxHhwMcETmduA== +commander@12.1.0, commander@^12.1.0: + version "12.1.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3" + integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA== + +commander@^10.0.0: + version "10.0.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06" + integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug== -commander@^2.19.0, commander@^2.20.0: +commander@^2.20.0: version "2.20.3" resolved "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^9.4.1: - version "9.5.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30" - integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ== - comment-parser@1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/comment-parser/-/comment-parser-1.4.1.tgz#bdafead37961ac079be11eb7ec65c4d021eaf9cc" @@ -1502,28 +1642,40 @@ convert-source-map@^1.7.0: dependencies: safe-buffer "~5.1.1" -cosmiconfig@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-7.0.1.tgz#714d756522cace867867ccb4474c5d01bbae5d6d" - integrity sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ== +convert-source-map@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a" + integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg== + +core-js-compat@^3.38.1: + version "3.46.0" + resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.46.0.tgz#0c87126a19a1af00371e12b02a2b088a40f3c6f7" + integrity sha512-p9hObIIEENxSV8xIu+V68JjSeARg6UVMG5mR+JEUguG3sI6MsiS1njz2jHmyJDvA+8jX/sytkBHup6kxhM9law== dependencies: - "@types/parse-json" "^4.0.0" - import-fresh "^3.2.1" - parse-json "^5.0.0" + browserslist "^4.26.3" + +cosmiconfig@^8.2.0: + version "8.3.6" + resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-8.3.6.tgz#060a2b871d66dba6c8538ea1118ba1ac16f5fae3" + integrity sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA== + dependencies: + import-fresh "^3.3.0" + js-yaml "^4.1.0" + parse-json "^5.2.0" path-type "^4.0.0" - yaml "^1.10.0" create-require@^1.1.0: version "1.1.1" resolved "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz" integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== -cross-env@7.0.3: - version "7.0.3" - resolved "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz" - integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== +cross-env@10.1.0: + version "10.1.0" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-10.1.0.tgz#cfd2a6200df9ed75bfb9cb3d7ce609c13ea21783" + integrity sha512-GsYosgnACZTADcmEyJctkJIoqAhHjttw7RsFrVoJNXbsWWqaq6Ym+7kZjq6mS45O0jij6vtiReppKQEtqWy6Dw== dependencies: - cross-spawn "^7.0.1" + "@epic-web/invariant" "^1.0.0" + cross-spawn "^7.0.6" cross-spawn@^7.0.0: version "7.0.1" @@ -1534,7 +1686,16 @@ cross-spawn@^7.0.0: shebang-command "^2.0.0" which "^2.0.1" -cross-spawn@^7.0.1, cross-spawn@^7.0.3: +cross-spawn@^7.0.2: + version "7.0.2" + resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.2.tgz" + integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw== + dependencies: + path-key "^3.1.0" + shebang-command "^2.0.0" + which "^2.0.1" + +cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== @@ -1543,10 +1704,10 @@ cross-spawn@^7.0.1, cross-spawn@^7.0.3: shebang-command "^2.0.0" which "^2.0.1" -cross-spawn@^7.0.2: - version "7.0.2" - resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.2.tgz" - integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw== +cross-spawn@^7.0.6: + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== dependencies: path-key "^3.1.0" shebang-command "^2.0.0" @@ -1557,12 +1718,32 @@ crypt@0.0.2: resolved "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz" integrity sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs= -debug@4.3.4, debug@^4.3.4: - version "4.3.4" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" - integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== +data-view-buffer@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/data-view-buffer/-/data-view-buffer-1.0.2.tgz#211a03ba95ecaf7798a8c7198d79536211f88570" + integrity sha512-EmKO5V3OLXh1rtK2wgXRansaK1/mtVdTUEiEI0W8RkvgT05kfxaH29PliLnpLP73yYO6142Q72QNa8Wx/A5CqQ== dependencies: - ms "2.1.2" + call-bound "^1.0.3" + es-errors "^1.3.0" + is-data-view "^1.0.2" + +data-view-byte-length@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/data-view-byte-length/-/data-view-byte-length-1.0.2.tgz#9e80f7ca52453ce3e93d25a35318767ea7704735" + integrity sha512-tuhGbE6CfTM9+5ANGf+oQb72Ky/0+s3xKUpHvShfiz2RxMFgFPjsXuRLBVMtvMs15awe45SRb83D6wH4ew6wlQ== + dependencies: + call-bound "^1.0.3" + es-errors "^1.3.0" + is-data-view "^1.0.2" + +data-view-byte-offset@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/data-view-byte-offset/-/data-view-byte-offset-1.0.1.tgz#068307f9b71ab76dbbe10291389e020856606191" + integrity sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ== + dependencies: + call-bound "^1.0.2" + es-errors "^1.3.0" + is-data-view "^1.0.1" debug@^3.2.7: version "3.2.7" @@ -1585,6 +1766,13 @@ debug@^4.2.0: dependencies: ms "2.1.2" +debug@^4.3.1, debug@^4.3.5, debug@^4.3.6: + version "4.4.3" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.3.tgz#c6ae432d9bd9662582fce08709b038c58e9e3d6a" + integrity sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA== + dependencies: + ms "^2.1.3" + debug@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b" @@ -1592,6 +1780,13 @@ debug@^4.3.2: dependencies: ms "2.1.2" +debug@^4.3.4: + version "4.3.4" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + decamelize@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" @@ -1607,10 +1802,10 @@ decode-uri-component@^0.2.0: resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9" integrity sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ== -deep-eql@^4.1.2: - version "4.1.3" - resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.3.tgz#7c7775513092f7df98d8df9996dd085eb668cc6d" - integrity sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw== +deep-eql@^4.1.3: + version "4.1.4" + resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.4.tgz#d0d3912865911bb8fac5afb4e3acfa6a28dc72b7" + integrity sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg== dependencies: type-detect "^4.0.0" @@ -1631,6 +1826,15 @@ default-require-extensions@^3.0.0: dependencies: strip-bom "^4.0.0" +define-data-property@^1.0.1, define-data-property@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/define-data-property/-/define-data-property-1.1.4.tgz#894dc141bb7d3060ae4366f6a0107e68fbe48c5e" + integrity sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A== + dependencies: + es-define-property "^1.0.0" + es-errors "^1.3.0" + gopd "^1.0.1" + define-properties@^1.1.2, define-properties@^1.1.3: version "1.1.3" resolved "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz" @@ -1646,19 +1850,28 @@ define-properties@^1.1.4: has-property-descriptors "^1.0.0" object-keys "^1.1.1" -diff@5.0.0, diff@^5.0.0: - version "5.0.0" - resolved "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz" - integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w== - -diff@^4.0.1: - version "4.0.2" +define-properties@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.2.1.tgz#10781cc616eb951a80a034bafcaa7377f6af2b6c" + integrity sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg== + dependencies: + define-data-property "^1.0.1" + has-property-descriptors "^1.0.0" + object-keys "^1.1.1" + +diff@^4.0.1: + version "4.0.2" resolved "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== +diff@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-7.0.0.tgz#3fb34d387cd76d803f6eebea67b921dab0182a9a" + integrity sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw== + dir-glob@^3.0.1: version "3.0.1" - resolved "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz" + resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" integrity sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA== dependencies: path-type "^4.0.0" @@ -1677,26 +1890,45 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" -editorconfig@^0.15.3: - version "0.15.3" - resolved "https://registry.yarnpkg.com/editorconfig/-/editorconfig-0.15.3.tgz#bef84c4e75fb8dcb0ce5cee8efd51c15999befc5" - integrity sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g== +dunder-proto@^1.0.0, dunder-proto@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/dunder-proto/-/dunder-proto-1.0.1.tgz#d7ae667e1dc83482f8b70fd0f6eefc50da30f58a" + integrity sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A== + dependencies: + call-bind-apply-helpers "^1.0.1" + es-errors "^1.3.0" + gopd "^1.2.0" + +eastasianwidth@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/eastasianwidth/-/eastasianwidth-0.2.0.tgz#696ce2ec0aa0e6ea93a397ffcf24aa7840c827cb" + integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA== + +editorconfig@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/editorconfig/-/editorconfig-1.0.4.tgz#040c9a8e9a6c5288388b87c2db07028aa89f53a3" + integrity sha512-L9Qe08KWTlqYMVvMcTIvMAdl1cDUubzRNYL+WfA4bLDMHe4nemKkpmYzkznE1FwLKu0EEmy6obgQKzMJrg4x9Q== dependencies: - commander "^2.19.0" - lru-cache "^4.1.5" - semver "^5.6.0" - sigmund "^1.0.1" + "@one-ini/wasm" "0.1.1" + commander "^10.0.0" + minimatch "9.0.1" + semver "^7.5.3" -electron-to-chromium@^1.3.723: - version "1.3.736" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.736.tgz#f632d900a1f788dab22fec9c62ec5c9c8f0c4052" - integrity sha512-DY8dA7gR51MSo66DqitEQoUMQ0Z+A2DSXFi7tK304bdTVqczCAfUuyQw6Wdg8hIoo5zIxkU1L24RQtUce1Ioig== +electron-to-chromium@^1.5.238: + version "1.5.243" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.243.tgz#b13b4a046f49f46574d643d4e2ec2ea33ce8cfe7" + integrity sha512-ZCphxFW3Q1TVhcgS9blfut1PX8lusVi2SvXQgmEEnK4TCmE1JhH2JkjJN+DNt0pJJwfBri5AROBnz2b/C+YU9g== emoji-regex@^8.0.0: version "8.0.0" resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz" integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== +emoji-regex@^9.2.2: + version "9.2.2" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.2.tgz#840c8803b0d8047f4ff0cf963176b32d4ef3ed72" + integrity sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg== + enhanced-resolve@^5.0.0: version "5.8.0" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.8.0.tgz#d9deae58f9d3773b6a111a5a46831da5be5c9ac0" @@ -1705,18 +1937,18 @@ enhanced-resolve@^5.0.0: graceful-fs "^4.2.4" tapable "^2.2.0" -enhanced-resolve@^5.10.0: - version "5.12.0" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.12.0.tgz#300e1c90228f5b570c4d35babf263f6da7155634" - integrity sha512-QHTXI/sZQmko1cbDoNAa3mJ5qhWUUNAq3vR0/YiD379fWQrcfuoX1+HW2S0MTt7XmoPLapdaDKUtelUSPic7hQ== +enhanced-resolve@^5.17.3: + version "5.18.3" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.18.3.tgz#9b5f4c5c076b8787c78fe540392ce76a88855b44" + integrity sha512-d4lC8xfavMeBjzGr2vECC3fsGXziXZQyJxD868h2M/mBI3PwAuODxAkLkq5HYuvrPYcUtiLzsTo8U3PgX3Ocww== dependencies: graceful-fs "^4.2.4" tapable "^2.2.0" -envinfo@^7.7.3: - version "7.7.4" - resolved "https://registry.npmjs.org/envinfo/-/envinfo-7.7.4.tgz" - integrity sha512-TQXTYFVVwwluWSFis6K2XKxgrD22jEv0FTuLCQI+OjH7rn93+iY0fSSFM5lrSxFY+H1+B0/cvvlamr3UsBivdQ== +envinfo@^7.14.0: + version "7.19.0" + resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.19.0.tgz#b4b4507a27e9900b0175f556167fd3a95f8623f1" + integrity sha512-DoSM9VyG6O3vqBf+p3Gjgr/Q52HYBBtO3v+4koAxt1MnWr+zEnxE+nke/yXS4lt2P4SYCHQ4V3f1i88LQVOpAw== error-ex@^1.3.1: version "1.3.2" @@ -1759,7 +1991,7 @@ es-abstract@^1.17.5: string.prototype.trimend "^1.0.1" string.prototype.trimstart "^1.0.1" -es-abstract@^1.18.0-next.0, es-abstract@^1.18.0-next.1: +es-abstract@^1.18.0-next.0: version "1.18.0-next.1" resolved "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz" integrity sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA== @@ -1777,91 +2009,104 @@ es-abstract@^1.18.0-next.0, es-abstract@^1.18.0-next.1: string.prototype.trimend "^1.0.1" string.prototype.trimstart "^1.0.1" -es-abstract@^1.19.0: - version "1.19.1" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.19.1.tgz#d4885796876916959de78edaa0df456627115ec3" - integrity sha512-2vJ6tjA/UfqLm2MPs7jxVybLoB8i1t1Jd9R3kISld20sIxPcTbLuggQOUxeWeAvIUkduv/CfMjuh4WmiXr2v9w== - dependencies: - call-bind "^1.0.2" - es-to-primitive "^1.2.1" - function-bind "^1.1.1" - get-intrinsic "^1.1.1" - get-symbol-description "^1.0.0" - has "^1.0.3" - has-symbols "^1.0.2" - internal-slot "^1.0.3" - is-callable "^1.2.4" - is-negative-zero "^2.0.1" - is-regex "^1.1.4" - is-shared-array-buffer "^1.0.1" - is-string "^1.0.7" - is-weakref "^1.0.1" - object-inspect "^1.11.0" +es-abstract@^1.23.2, es-abstract@^1.23.5, es-abstract@^1.23.9, es-abstract@^1.24.0: + version "1.24.0" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.24.0.tgz#c44732d2beb0acc1ed60df840869e3106e7af328" + integrity sha512-WSzPgsdLtTcQwm4CROfS5ju2Wa1QQcVeT37jFjYzdFz1r9ahadC8B8/a4qxJxM+09F18iumCdRmlr96ZYkQvEg== + dependencies: + array-buffer-byte-length "^1.0.2" + arraybuffer.prototype.slice "^1.0.4" + available-typed-arrays "^1.0.7" + call-bind "^1.0.8" + call-bound "^1.0.4" + data-view-buffer "^1.0.2" + data-view-byte-length "^1.0.2" + data-view-byte-offset "^1.0.1" + es-define-property "^1.0.1" + es-errors "^1.3.0" + es-object-atoms "^1.1.1" + es-set-tostringtag "^2.1.0" + es-to-primitive "^1.3.0" + function.prototype.name "^1.1.8" + get-intrinsic "^1.3.0" + get-proto "^1.0.1" + get-symbol-description "^1.1.0" + globalthis "^1.0.4" + gopd "^1.2.0" + has-property-descriptors "^1.0.2" + has-proto "^1.2.0" + has-symbols "^1.1.0" + hasown "^2.0.2" + internal-slot "^1.1.0" + is-array-buffer "^3.0.5" + is-callable "^1.2.7" + is-data-view "^1.0.2" + is-negative-zero "^2.0.3" + is-regex "^1.2.1" + is-set "^2.0.3" + is-shared-array-buffer "^1.0.4" + is-string "^1.1.1" + is-typed-array "^1.1.15" + is-weakref "^1.1.1" + math-intrinsics "^1.1.0" + object-inspect "^1.13.4" object-keys "^1.1.1" - object.assign "^4.1.2" - string.prototype.trimend "^1.0.4" - string.prototype.trimstart "^1.0.4" - unbox-primitive "^1.0.1" + object.assign "^4.1.7" + own-keys "^1.0.1" + regexp.prototype.flags "^1.5.4" + safe-array-concat "^1.1.3" + safe-push-apply "^1.0.0" + safe-regex-test "^1.1.0" + set-proto "^1.0.0" + stop-iteration-iterator "^1.1.0" + string.prototype.trim "^1.2.10" + string.prototype.trimend "^1.0.9" + string.prototype.trimstart "^1.0.8" + typed-array-buffer "^1.0.3" + typed-array-byte-length "^1.0.3" + typed-array-byte-offset "^1.0.4" + typed-array-length "^1.0.7" + unbox-primitive "^1.1.0" + which-typed-array "^1.1.19" + +es-define-property@^1.0.0, es-define-property@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/es-define-property/-/es-define-property-1.0.1.tgz#983eb2f9a6724e9303f61addf011c72e09e0b0fa" + integrity sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g== + +es-errors@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/es-errors/-/es-errors-1.3.0.tgz#05f75a25dab98e4fb1dcd5e1472c0546d5057c8f" + integrity sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw== + +es-module-lexer@^1.2.1, es-module-lexer@^1.5.3: + version "1.7.0" + resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.7.0.tgz#9159601561880a85f2734560a9099b2c31e5372a" + integrity sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA== -es-abstract@^1.20.4: - version "1.21.1" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.21.1.tgz#e6105a099967c08377830a0c9cb589d570dd86c6" - integrity sha512-QudMsPOz86xYz/1dG1OuGBKOELjCh99IIWHLzy5znUB6j8xG2yMA7bfTV86VSqKF+Y/H08vQPR+9jyXpuC6hfg== +es-object-atoms@^1.0.0, es-object-atoms@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/es-object-atoms/-/es-object-atoms-1.1.1.tgz#1c4f2c4837327597ce69d2ca190a7fdd172338c1" + integrity sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA== dependencies: - available-typed-arrays "^1.0.5" - call-bind "^1.0.2" - es-set-tostringtag "^2.0.1" - es-to-primitive "^1.2.1" - function-bind "^1.1.1" - function.prototype.name "^1.1.5" - get-intrinsic "^1.1.3" - get-symbol-description "^1.0.0" - globalthis "^1.0.3" - gopd "^1.0.1" - has "^1.0.3" - has-property-descriptors "^1.0.0" - has-proto "^1.0.1" - has-symbols "^1.0.3" - internal-slot "^1.0.4" - is-array-buffer "^3.0.1" - is-callable "^1.2.7" - is-negative-zero "^2.0.2" - is-regex "^1.1.4" - is-shared-array-buffer "^1.0.2" - is-string "^1.0.7" - is-typed-array "^1.1.10" - is-weakref "^1.0.2" - object-inspect "^1.12.2" - object-keys "^1.1.1" - object.assign "^4.1.4" - regexp.prototype.flags "^1.4.3" - safe-regex-test "^1.0.0" - string.prototype.trimend "^1.0.6" - string.prototype.trimstart "^1.0.6" - typed-array-length "^1.0.4" - unbox-primitive "^1.0.2" - which-typed-array "^1.1.9" - -es-module-lexer@^0.9.0: - version "0.9.3" - resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19" - integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ== + es-errors "^1.3.0" -es-set-tostringtag@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/es-set-tostringtag/-/es-set-tostringtag-2.0.1.tgz#338d502f6f674301d710b80c8592de8a15f09cd8" - integrity sha512-g3OMbtlwY3QewlqAiMLI47KywjWZoEytKr8pf6iTC8uJq5bIAH52Z9pnQ8pVL6whrCto53JZDuUIsifGeLorTg== +es-set-tostringtag@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz#f31dbbe0c183b00a6d26eb6325c810c0fd18bd4d" + integrity sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA== dependencies: - get-intrinsic "^1.1.3" - has "^1.0.3" - has-tostringtag "^1.0.0" + es-errors "^1.3.0" + get-intrinsic "^1.2.6" + has-tostringtag "^1.0.2" + hasown "^2.0.2" -es-shim-unscopables@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/es-shim-unscopables/-/es-shim-unscopables-1.0.0.tgz#702e632193201e3edf8713635d083d378e510241" - integrity sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w== +es-shim-unscopables@^1.0.2, es-shim-unscopables@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/es-shim-unscopables/-/es-shim-unscopables-1.1.0.tgz#438df35520dac5d105f3943d927549ea3b00f4b5" + integrity sha512-d9T8ucsEhh8Bi1woXCf+TIKDIROLG5WCkxg8geBCbvk22kzwC5G2OnXVMO6FUsvQlgUUXQ2itephWDLqDzbeCw== dependencies: - has "^1.0.3" + hasown "^2.0.2" es-to-primitive@^1.2.1: version "1.2.1" @@ -1872,81 +2117,97 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" +es-to-primitive@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.3.0.tgz#96c89c82cc49fd8794a24835ba3e1ff87f214e18" + integrity sha512-w+5mJ3GuFL+NjVtJlvydShqE1eN3h3PbI7/5LAsYJP/2qtuMXjfL2LpHSRqo4b4eSF5K/DH1JXKUAHSB2UW50g== + dependencies: + is-callable "^1.2.7" + is-date-object "^1.0.5" + is-symbol "^1.0.4" + es6-error@^4.0.1: version "4.1.1" resolved "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz" integrity sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg== -es6-object-assign@^1.1.0: - version "1.1.0" - resolved "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz" - integrity sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw= - escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw== -escape-string-regexp@4.0.0, escape-string-regexp@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" - integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== +escalade@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.2.0.tgz#011a3f69856ba189dffa7dc8fcce99d2a87903e5" + integrity sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA== escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= -eslint-import-resolver-node@^0.3.7: - version "0.3.7" - resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.7.tgz#83b375187d412324a1963d84fa664377a23eb4d7" - integrity sha512-gozW2blMLJCeFpBwugLTGyvVjNoeo1knonXAcatC6bjPBZitotxdWf7Gimr25N4c0AAOo4eOUfaG82IJPDpqCA== +escape-string-regexp@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" + integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== + +eslint-import-resolver-node@^0.3.9: + version "0.3.9" + resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.9.tgz#d4eaac52b8a2e7c3cd1903eb00f7e053356118ac" + integrity sha512-WFj2isz22JahUv+B788TlO3N6zL3nNJGU8CcZbPZvVEkBPaJdCV4vy5wyghty5ROFbCRnm132v8BScu5/1BQ8g== dependencies: debug "^3.2.7" - is-core-module "^2.11.0" - resolve "^1.22.1" + is-core-module "^2.13.0" + resolve "^1.22.4" -eslint-module-utils@^2.7.4: - version "2.7.4" - resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.7.4.tgz#4f3e41116aaf13a20792261e61d3a2e7e0583974" - integrity sha512-j4GT+rqzCoRKHwURX7pddtIPGySnX9Si/cgMI5ztrcqOPtk5dDEeZ34CQVPphnqkJytlc97Vuk05Um2mJ3gEQA== +eslint-module-utils@^2.12.1: + version "2.12.1" + resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.12.1.tgz#f76d3220bfb83c057651359295ab5854eaad75ff" + integrity sha512-L8jSWTze7K2mTg0vos/RuLRS5soomksDPoJLXIslC7c8Wmut3bx7CPpJijDcBZtxQ5lrbUdM+s0OlNbz0DCDNw== dependencies: debug "^3.2.7" -eslint-plugin-import@2.27.5: - version "2.27.5" - resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz#876a6d03f52608a3e5bb439c2550588e51dd6c65" - integrity sha512-LmEt3GVofgiGuiE+ORpnvP+kAm3h6MLZJ4Q5HCyHADofsb4VzXFsRiWj3c0OFiV+3DWFh0qg3v9gcPlfc3zRow== +eslint-plugin-import@2.32.0: + version "2.32.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.32.0.tgz#602b55faa6e4caeaa5e970c198b5c00a37708980" + integrity sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA== dependencies: - array-includes "^3.1.6" - array.prototype.flat "^1.3.1" - array.prototype.flatmap "^1.3.1" + "@rtsao/scc" "^1.1.0" + array-includes "^3.1.9" + array.prototype.findlastindex "^1.2.6" + array.prototype.flat "^1.3.3" + array.prototype.flatmap "^1.3.3" debug "^3.2.7" doctrine "^2.1.0" - eslint-import-resolver-node "^0.3.7" - eslint-module-utils "^2.7.4" - has "^1.0.3" - is-core-module "^2.11.0" + eslint-import-resolver-node "^0.3.9" + eslint-module-utils "^2.12.1" + hasown "^2.0.2" + is-core-module "^2.16.1" is-glob "^4.0.3" minimatch "^3.1.2" - object.values "^1.1.6" - resolve "^1.22.1" - semver "^6.3.0" - tsconfig-paths "^3.14.1" - -eslint-plugin-jsdoc@48.2.12: - version "48.2.12" - resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-48.2.12.tgz#e8411c87e55db3f21a288e04bf7e1fb5fa62dfa9" - integrity sha512-sO9sKkJx5ovWoRk9hV0YiNzXQ4Z6j27CqE/po2E3wddZVuy9wvKPSTiIhpxMTrP/qURvKayJIDB2+o9kyCW1Fw== - dependencies: - "@es-joy/jsdoccomment" "~0.43.1" + object.fromentries "^2.0.8" + object.groupby "^1.0.3" + object.values "^1.2.1" + semver "^6.3.1" + string.prototype.trimend "^1.0.9" + tsconfig-paths "^3.15.0" + +eslint-plugin-jsdoc@50.6.3: + version "50.6.3" + resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.6.3.tgz#668dc4d32e823c84ede7310cffbf70c9d370d291" + integrity sha512-NxbJyt1M5zffPcYZ8Nb53/8nnbIScmiLAMdoe0/FAszwb7lcSiX3iYBTsuF7RV84dZZJC8r3NghomrUXsmWvxQ== + dependencies: + "@es-joy/jsdoccomment" "~0.49.0" are-docs-informative "^0.0.2" comment-parser "1.4.1" - debug "^4.3.4" + debug "^4.3.6" escape-string-regexp "^4.0.0" - esquery "^1.5.0" - semver "^7.6.2" + espree "^10.1.0" + esquery "^1.6.0" + parse-imports "^2.1.1" + semver "^7.6.3" spdx-expression-parse "^4.0.0" + synckit "^0.9.1" eslint-plugin-no-null@1.0.2: version "1.0.2" @@ -1958,29 +2219,29 @@ eslint-plugin-prefer-arrow@1.2.3: resolved "https://registry.npmjs.org/eslint-plugin-prefer-arrow/-/eslint-plugin-prefer-arrow-1.2.3.tgz" integrity sha512-J9I5PKCOJretVuiZRGvPQxCbllxGAV/viI20JO3LYblAodofBxyMnZAJ+WGeClHgANnSJberTNoFWWjrWKBuXQ== -eslint-plugin-unicorn@45.0.2: - version "45.0.2" - resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-45.0.2.tgz#d6ba704793a6909fe5dfe013900d2b05b715284c" - integrity sha512-Y0WUDXRyGDMcKLiwgL3zSMpHrXI00xmdyixEGIg90gHnj0PcHY4moNv3Ppje/kDivdAy5vUeUr7z211ImPv2gw== +eslint-plugin-unicorn@56.0.1: + version "56.0.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-56.0.1.tgz#d10a3df69ba885939075bdc95a65a0c872e940d4" + integrity sha512-FwVV0Uwf8XPfVnKSGpMg7NtlZh0G0gBarCaFcMUOoqPxXryxdYxTRRv4kH6B9TFCVIrjRXG+emcxIk2ayZilog== dependencies: - "@babel/helper-validator-identifier" "^7.19.1" - "@eslint-community/eslint-utils" "^4.1.2" - ci-info "^3.6.1" + "@babel/helper-validator-identifier" "^7.24.7" + "@eslint-community/eslint-utils" "^4.4.0" + ci-info "^4.0.0" clean-regexp "^1.0.0" - esquery "^1.4.0" + core-js-compat "^3.38.1" + esquery "^1.6.0" + globals "^15.9.0" indent-string "^4.0.0" - is-builtin-module "^3.2.0" + is-builtin-module "^3.2.1" jsesc "^3.0.2" - lodash "^4.17.21" pluralize "^8.0.0" read-pkg-up "^7.0.1" - regexp-tree "^0.1.24" - regjsparser "^0.9.1" - safe-regex "^2.1.1" - semver "^7.3.8" + regexp-tree "^0.1.27" + regjsparser "^0.10.0" + semver "^7.6.3" strip-indent "^3.0.0" -eslint-scope@5.1.1, eslint-scope@^5.1.1: +eslint-scope@5.1.1: version "5.1.1" resolved "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz" integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw== @@ -1988,85 +2249,85 @@ eslint-scope@5.1.1, eslint-scope@^5.1.1: esrecurse "^4.3.0" estraverse "^4.1.1" -eslint-scope@7.1.1, eslint-scope@^7.1.1: - version "7.1.1" - resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.1.1.tgz#fff34894c2f65e5226d3041ac480b4513a163642" - integrity sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw== +eslint-scope@8.4.0: + version "8.4.0" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-8.4.0.tgz#88e646a207fad61436ffa39eb505147200655c82" + integrity sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg== dependencies: esrecurse "^4.3.0" estraverse "^5.2.0" -eslint-utils@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-3.0.0.tgz#8aebaface7345bb33559db0a1f13a1d2d48c3672" - integrity sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA== +eslint-scope@^7.2.2: + version "7.2.2" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.2.2.tgz#deb4f92563390f32006894af62a22dba1c46423f" + integrity sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg== dependencies: - eslint-visitor-keys "^2.0.0" + esrecurse "^4.3.0" + estraverse "^5.2.0" -eslint-visitor-keys@3.3.0, eslint-visitor-keys@^3.3.0: - version "3.3.0" - resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826" - integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA== +eslint-visitor-keys@4.2.1, eslint-visitor-keys@^4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz#4cfea60fe7dd0ad8e816e1ed026c1d5251b512c1" + integrity sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ== -eslint-visitor-keys@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz" - integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ== +eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4.3: + version "3.4.3" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800" + integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== -eslint-webpack-plugin@4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/eslint-webpack-plugin/-/eslint-webpack-plugin-4.0.0.tgz#f77f37b2bbb8ad5c4197b5e55f5f2a49365a1a81" - integrity sha512-eM9ccGRWkU+btBSVfABRn8CjT7jZ2Q+UV/RfErMDVCFXpihEbvajNrLltZpwTAcEoXSqESGlEPIUxl7PoDlLWw== +eslint-webpack-plugin@4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/eslint-webpack-plugin/-/eslint-webpack-plugin-4.2.0.tgz#41f54b25379908eb9eca8645bc997c90cfdbd34e" + integrity sha512-rsfpFQ01AWQbqtjgPRr2usVRxhWDuG0YDYcG8DJOteD3EFnpeuYuOwk0PQiN7PRBTqS6ElNdtPZPggj8If9WnA== dependencies: - "@types/eslint" "^8.4.10" - jest-worker "^29.4.1" + "@types/eslint" "^8.56.10" + jest-worker "^29.7.0" micromatch "^4.0.5" normalize-path "^3.0.0" - schema-utils "^4.0.0" - -eslint@8.34.0: - version "8.34.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.34.0.tgz#fe0ab0ef478104c1f9ebc5537e303d25a8fb22d6" - integrity sha512-1Z8iFsucw+7kSqXNZVslXS8Ioa4u2KM7GPwuKtkTFAqZ/cHMcEaR+1+Br0wLlot49cNxIiZk5wp8EAbPcYZxTg== - dependencies: - "@eslint/eslintrc" "^1.4.1" - "@humanwhocodes/config-array" "^0.11.8" + schema-utils "^4.2.0" + +eslint@8.57.1: + version "8.57.1" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.57.1.tgz#7df109654aba7e3bbe5c8eae533c5e461d3c6ca9" + integrity sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA== + dependencies: + "@eslint-community/eslint-utils" "^4.2.0" + "@eslint-community/regexpp" "^4.6.1" + "@eslint/eslintrc" "^2.1.4" + "@eslint/js" "8.57.1" + "@humanwhocodes/config-array" "^0.13.0" "@humanwhocodes/module-importer" "^1.0.1" "@nodelib/fs.walk" "^1.2.8" - ajv "^6.10.0" + "@ungap/structured-clone" "^1.2.0" + ajv "^6.12.4" chalk "^4.0.0" cross-spawn "^7.0.2" debug "^4.3.2" doctrine "^3.0.0" escape-string-regexp "^4.0.0" - eslint-scope "^7.1.1" - eslint-utils "^3.0.0" - eslint-visitor-keys "^3.3.0" - espree "^9.4.0" - esquery "^1.4.0" + eslint-scope "^7.2.2" + eslint-visitor-keys "^3.4.3" + espree "^9.6.1" + esquery "^1.4.2" esutils "^2.0.2" fast-deep-equal "^3.1.3" file-entry-cache "^6.0.1" find-up "^5.0.0" glob-parent "^6.0.2" globals "^13.19.0" - grapheme-splitter "^1.0.4" + graphemer "^1.4.0" ignore "^5.2.0" - import-fresh "^3.0.0" imurmurhash "^0.1.4" is-glob "^4.0.0" is-path-inside "^3.0.3" - js-sdsl "^4.1.4" js-yaml "^4.1.0" json-stable-stringify-without-jsonify "^1.0.1" levn "^0.4.1" lodash.merge "^4.6.2" minimatch "^3.1.2" natural-compare "^1.4.0" - optionator "^0.9.1" - regexpp "^3.2.0" + optionator "^0.9.3" strip-ansi "^6.0.1" - strip-json-comments "^3.1.0" text-table "^0.2.0" esm@^3.2.25: @@ -2074,31 +2335,33 @@ esm@^3.2.25: resolved "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz" integrity sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA== -espree@^9.4.0: - version "9.4.1" - resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.1.tgz#51d6092615567a2c2cff7833445e37c28c0065bd" - integrity sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg== +espree@^10.1.0: + version "10.4.0" + resolved "https://registry.yarnpkg.com/espree/-/espree-10.4.0.tgz#d54f4949d4629005a1fa168d937c3ff1f7e2a837" + integrity sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ== + dependencies: + acorn "^8.15.0" + acorn-jsx "^5.3.2" + eslint-visitor-keys "^4.2.1" + +espree@^9.6.0, espree@^9.6.1: + version "9.6.1" + resolved "https://registry.yarnpkg.com/espree/-/espree-9.6.1.tgz#a2a17b8e434690a5432f2f8018ce71d331a48c6f" + integrity sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ== dependencies: - acorn "^8.8.0" + acorn "^8.9.0" acorn-jsx "^5.3.2" - eslint-visitor-keys "^3.3.0" + eslint-visitor-keys "^3.4.1" esprima@^4.0.0, esprima@^4.0.1: version "4.0.1" resolved "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== -esquery@^1.4.0: - version "1.4.0" - resolved "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz" - integrity sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w== - dependencies: - estraverse "^5.1.0" - -esquery@^1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.5.0.tgz#6ce17738de8577694edd7361c57182ac8cb0db0b" - integrity sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg== +esquery@^1.4.2, esquery@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.6.0.tgz#91419234f804d852a82dceec3e16cdc22cf9dae7" + integrity sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg== dependencies: estraverse "^5.1.0" @@ -2140,15 +2403,15 @@ fast-deep-equal@3.1.3, fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== fast-glob@^3.2.9: - version "3.2.12" - resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80" - integrity sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w== + version "3.3.3" + resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.3.tgz#d06d585ce8dba90a16b0505c543c3ccfb3aeb818" + integrity sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg== dependencies: "@nodelib/fs.stat" "^2.0.2" "@nodelib/fs.walk" "^1.2.3" glob-parent "^5.1.2" merge2 "^1.3.0" - micromatch "^4.0.4" + micromatch "^4.0.8" fast-json-stable-stringify@^2.0.0: version "2.1.0" @@ -2160,6 +2423,11 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: resolved "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz" integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= +fast-uri@^3.0.1: + version "3.1.0" + resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-3.1.0.tgz#66eecff6c764c0df9b762e62ca7edcfb53b4edfa" + integrity sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA== + fastest-levenshtein@^1.0.12: version "1.0.12" resolved "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.12.tgz" @@ -2191,6 +2459,13 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== + dependencies: + to-regex-range "^5.0.1" + find-cache-dir@^3.2.0: version "3.3.1" resolved "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz" @@ -2200,14 +2475,6 @@ find-cache-dir@^3.2.0: make-dir "^3.0.2" pkg-dir "^4.1.0" -find-up@5.0.0, find-up@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" - integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== - dependencies: - locate-path "^6.0.0" - path-exists "^4.0.0" - find-up@^4.0.0, find-up@^4.1.0: version "4.1.0" resolved "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz" @@ -2216,6 +2483,14 @@ find-up@^4.0.0, find-up@^4.1.0: locate-path "^5.0.0" path-exists "^4.0.0" +find-up@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" + integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== + dependencies: + locate-path "^6.0.0" + path-exists "^4.0.0" + flat-cache@^3.0.4: version "3.0.4" resolved "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz" @@ -2241,6 +2516,13 @@ for-each@^0.3.3: dependencies: is-callable "^1.1.3" +for-each@^0.3.5: + version "0.3.5" + resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.5.tgz#d650688027826920feeb0af747ee7b9421a41d47" + integrity sha512-dKx12eRCVIzqCxFGplyFKJMPvLEWgmNtUrpTiJIR5u97zEhRG8ySrtboPHZXx7daLxQVrl643cTzbab2tkQjxg== + dependencies: + is-callable "^1.2.7" + foreach@^2.0.5: version "2.0.5" resolved "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz" @@ -2254,22 +2536,30 @@ foreground-child@^2.0.0: cross-spawn "^7.0.0" signal-exit "^3.0.2" -fork-ts-checker-notifier-webpack-plugin@6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/fork-ts-checker-notifier-webpack-plugin/-/fork-ts-checker-notifier-webpack-plugin-6.0.0.tgz#d42447c3b02e734098cde7fa9fd02031e24adec8" - integrity sha512-Gzop95yFefJu9P68BBQ+Gsu5hjF7DQQTCcEM0Ns0WaXKD9CR0qqCJkjRrE+2gZG7PhdK8ccfxiexFvPZHbb4Tg== +foreground-child@^3.1.0, foreground-child@^3.3.0, foreground-child@^3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/foreground-child/-/foreground-child-3.3.1.tgz#32e8e9ed1b68a3497befb9ac2b6adf92a638576f" + integrity sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw== dependencies: - node-notifier "^8.0.2" + cross-spawn "^7.0.6" + signal-exit "^4.0.1" -fork-ts-checker-webpack-plugin@7.3.0: - version "7.3.0" - resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-7.3.0.tgz#a9c984a018493962360d7c7e77a67b44a2d5f3aa" - integrity sha512-IN+XTzusCjR5VgntYFgxbxVx3WraPRnKehBFrf00cMSrtUuW9MsG9dhL6MWpY6MkjC3wVwoujfCDgZZCQwbswA== +fork-ts-checker-notifier-webpack-plugin@9.0.0: + version "9.0.0" + resolved "https://registry.yarnpkg.com/fork-ts-checker-notifier-webpack-plugin/-/fork-ts-checker-notifier-webpack-plugin-9.0.0.tgz#5ee57baab812a3cfd9592beb81c6e2733923d4c2" + integrity sha512-G9lIXCacvYoEtZh8X0emvGUuU0isK74OYUwTiULOs9xP4QvZY8udK00vsS5Ylwh7TdInlCsaj5eCMH17QeVrGg== + dependencies: + node-notifier "^10.0.1" + +fork-ts-checker-webpack-plugin@9.1.0: + version "9.1.0" + resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-9.1.0.tgz#433481c1c228c56af111172fcad7df79318c915a" + integrity sha512-mpafl89VFPJmhnJ1ssH+8wmM2b50n+Rew5x42NeI2U78aRWgtkEtGmctp7iT16UjquJTjorEmIfESj3DxdW84Q== dependencies: "@babel/code-frame" "^7.16.7" chalk "^4.1.2" - chokidar "^3.5.3" - cosmiconfig "^7.0.1" + chokidar "^4.0.1" + cosmiconfig "^8.2.0" deepmerge "^4.2.2" fs-extra "^10.0.0" memfs "^3.4.1" @@ -2303,47 +2593,54 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= -fsevents@~2.3.2: - version "2.3.2" - resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" - integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== - function-bind@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== -function.prototype.name@^1.1.5: - version "1.1.5" - resolved "https://registry.yarnpkg.com/function.prototype.name/-/function.prototype.name-1.1.5.tgz#cce0505fe1ffb80503e6f9e46cc64e46a12a9621" - integrity sha512-uN7m/BzVKQnCUF/iW8jYea67v++2u7m5UgENbHRtdDVclOUP+FMPlCNdmk0h/ysGyo2tavMJEDqJAkJdRa1vMA== - dependencies: - call-bind "^1.0.2" - define-properties "^1.1.3" - es-abstract "^1.19.0" - functions-have-names "^1.2.2" +function-bind@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c" + integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA== + +function.prototype.name@^1.1.6, function.prototype.name@^1.1.8: + version "1.1.8" + resolved "https://registry.yarnpkg.com/function.prototype.name/-/function.prototype.name-1.1.8.tgz#e68e1df7b259a5c949eeef95cdbde53edffabb78" + integrity sha512-e5iwyodOHhbMr/yNrc7fDYG4qlbIvI5gajyzPnb5TCwyhjApznQh1BMFou9b30SevY43gCJKXycoCBjMbsuW0Q== + dependencies: + call-bind "^1.0.8" + call-bound "^1.0.3" + define-properties "^1.2.1" + functions-have-names "^1.2.3" + hasown "^2.0.2" + is-callable "^1.2.7" -functions-have-names@^1.2.2: +functions-have-names@^1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834" integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ== -gensync@^1.0.0-beta.1: - version "1.0.0-beta.1" - resolved "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.1.tgz" - integrity sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg== +generator-function@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/generator-function/-/generator-function-2.0.1.tgz#0e75dd410d1243687a0ba2e951b94eedb8f737a2" + integrity sha512-SFdFmIJi+ybC0vjlHN0ZGVGHc3lgE0DxPAT0djjVg+kjOnSqclqmj0KQ7ykTOLP6YxoqOvuAODGdcHJn+43q3g== + +gensync@^1.0.0-beta.2: + version "1.0.0-beta.2" + resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" + integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg== get-caller-file@^2.0.1, get-caller-file@^2.0.5: version "2.0.5" resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== -get-func-name@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz" - integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE= +get-func-name@^2.0.1, get-func-name@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41" + integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ== -get-intrinsic@^1.0.2, get-intrinsic@^1.1.0, get-intrinsic@^1.1.1: +get-intrinsic@^1.0.2, get-intrinsic@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.1.tgz#15f59f376f855c446963948f0d24cd3637b4abc6" integrity sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q== @@ -2352,7 +2649,7 @@ get-intrinsic@^1.0.2, get-intrinsic@^1.1.0, get-intrinsic@^1.1.1: has "^1.0.3" has-symbols "^1.0.1" -get-intrinsic@^1.1.3, get-intrinsic@^1.2.0: +get-intrinsic@^1.1.3: version "1.2.0" resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.2.0.tgz#7ad1dc0535f3a2904bba075772763e5051f6d05f" integrity sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q== @@ -2361,20 +2658,45 @@ get-intrinsic@^1.1.3, get-intrinsic@^1.2.0: has "^1.0.3" has-symbols "^1.0.3" +get-intrinsic@^1.2.4, get-intrinsic@^1.2.5, get-intrinsic@^1.2.6, get-intrinsic@^1.2.7, get-intrinsic@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.3.0.tgz#743f0e3b6964a93a5491ed1bffaae054d7f98d01" + integrity sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ== + dependencies: + call-bind-apply-helpers "^1.0.2" + es-define-property "^1.0.1" + es-errors "^1.3.0" + es-object-atoms "^1.1.1" + function-bind "^1.1.2" + get-proto "^1.0.1" + gopd "^1.2.0" + has-symbols "^1.1.0" + hasown "^2.0.2" + math-intrinsics "^1.1.0" + get-package-type@^0.1.0: version "0.1.0" resolved "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz" integrity sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q== -get-symbol-description@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/get-symbol-description/-/get-symbol-description-1.0.0.tgz#7fdb81c900101fbd564dd5f1a30af5aadc1e58d6" - integrity sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw== +get-proto@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/get-proto/-/get-proto-1.0.1.tgz#150b3f2743869ef3e851ec0c49d15b1d14d00ee1" + integrity sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g== dependencies: - call-bind "^1.0.2" - get-intrinsic "^1.1.1" + dunder-proto "^1.0.1" + es-object-atoms "^1.0.0" -glob-parent@^5.1.2, glob-parent@~5.1.2: +get-symbol-description@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/get-symbol-description/-/get-symbol-description-1.1.0.tgz#7bdd54e0befe8ffc9f3b4e203220d9f1e881b6ee" + integrity sha512-w9UMqWwJxHNOvoNzSJ2oPF5wvYcvP7jUvYzhp67yEhTi17ZDBBC1z9pTdGuzjD+EFIqLSYRweZjqfiPzQ06Ebg== + dependencies: + call-bound "^1.0.3" + es-errors "^1.3.0" + get-intrinsic "^1.2.6" + +glob-parent@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== @@ -2393,16 +2715,29 @@ glob-to-regexp@^0.4.1: resolved "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz" integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw== -glob@8.1.0, glob@^8.0.3: - version "8.1.0" - resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" - integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^5.0.1" - once "^1.3.0" +glob@^10.4.2, glob@^10.4.5: + version "10.4.5" + resolved "https://registry.yarnpkg.com/glob/-/glob-10.4.5.tgz#f4d9f0b90ffdbab09c9d77f5f29b4262517b0956" + integrity sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg== + dependencies: + foreground-child "^3.1.0" + jackspeak "^3.1.2" + minimatch "^9.0.4" + minipass "^7.1.2" + package-json-from-dist "^1.0.0" + path-scurry "^1.11.1" + +glob@^11.0.0: + version "11.0.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-11.0.3.tgz#9d8087e6d72ddb3c4707b1d2778f80ea3eaefcd6" + integrity sha512-2Nim7dha1KVkaiF4q6Dj+ngPPMdfvLJEOpZk/jKiUAkqKebpGAWQXAq9z1xu9HKu5lWfqw/FASuccEjyznjPaA== + dependencies: + foreground-child "^3.3.1" + jackspeak "^4.1.1" + minimatch "^10.0.3" + minipass "^7.1.2" + package-json-from-dist "^1.0.0" + path-scurry "^2.0.0" glob@^7.1.3, glob@^7.1.4, glob@^7.1.6: version "7.1.6" @@ -2416,11 +2751,6 @@ glob@^7.1.3, glob@^7.1.4, glob@^7.1.6: once "^1.3.0" path-is-absolute "^1.0.0" -globals@^11.1.0: - version "11.12.0" - resolved "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz" - integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== - globals@^13.19.0: version "13.20.0" resolved "https://registry.yarnpkg.com/globals/-/globals-13.20.0.tgz#ea276a1e508ffd4f1612888f9d1bad1e2717bf82" @@ -2428,12 +2758,18 @@ globals@^13.19.0: dependencies: type-fest "^0.20.2" -globalthis@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/globalthis/-/globalthis-1.0.3.tgz#5852882a52b80dc301b0660273e1ed082f0b6ccf" - integrity sha512-sFdI5LyBiNTHjRd7cGPWapiHWMOXKyuBNX/cWJ3NfzrZQVa8GI/8cofCl74AOVqq9W5kNmguTIzJ/1s2gyI9wA== +globals@^15.9.0: + version "15.15.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-15.15.0.tgz#7c4761299d41c32b075715a4ce1ede7897ff72a8" + integrity sha512-7ACyT3wmyp3I61S4fG682L0VA2RGD9otkqGJIwNUMF1SWUombIIk+af1unuDYgMm082aHYwD+mzJvv9Iu8dsgg== + +globalthis@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/globalthis/-/globalthis-1.0.4.tgz#7430ed3a975d97bfb59bcce41f5cabbafa651236" + integrity sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ== dependencies: - define-properties "^1.1.3" + define-properties "^1.2.1" + gopd "^1.0.1" globby@^11.1.0: version "11.1.0" @@ -2454,6 +2790,11 @@ gopd@^1.0.1: dependencies: get-intrinsic "^1.1.3" +gopd@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.2.0.tgz#89f56b8217bdbc8802bd299df6d7f1081d7e51a1" + integrity sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg== + graceful-fs@^4.1.15, graceful-fs@^4.1.2: version "4.2.3" resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz" @@ -2464,26 +2805,26 @@ graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4: resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz" integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== +graceful-fs@^4.2.11: + version "4.2.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" + integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== + graceful-fs@^4.2.9: version "4.2.9" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96" integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ== -grapheme-splitter@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz#9cf3a665c6247479896834af35cf1dbb4400767e" - integrity sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ== +graphemer@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/graphemer/-/graphemer-1.4.0.tgz#fb2f1d55e0e3a1849aeffc90c4fa0dd53a0e66c6" + integrity sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag== growly@^1.3.0: version "1.3.0" resolved "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz" integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE= -has-bigints@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/has-bigints/-/has-bigints-1.0.1.tgz#64fe6acb020673e3b78db035a5af69aa9d07b113" - integrity sha512-LSBS2LjbNBTf6287JEbEzvJgftkF5qFkmCo9hDRpAzKhUOlJ+hx8dd4USs00SgsUNwc4617J9ki5YtEClM2ffA== - has-bigints@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/has-bigints/-/has-bigints-1.0.2.tgz#0871bd3e3d51626f6ca0966668ba35d5602d6eaa" @@ -2506,32 +2847,41 @@ has-property-descriptors@^1.0.0: dependencies: get-intrinsic "^1.1.1" -has-proto@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/has-proto/-/has-proto-1.0.1.tgz#1885c1305538958aff469fef37937c22795408e0" - integrity sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg== +has-property-descriptors@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz#963ed7d071dc7bf5f084c5bfbe0d1b6222586854" + integrity sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg== + dependencies: + es-define-property "^1.0.0" + +has-proto@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/has-proto/-/has-proto-1.2.0.tgz#5de5a6eabd95fdffd9818b43055e8065e39fe9d5" + integrity sha512-KIL7eQPfHQRC8+XluaIw7BHUwwqL19bQn4hzNgdr+1wXoU0KKj6rufu47lhY7KbJR2C6T6+PfyN0Ea7wkSS+qQ== + dependencies: + dunder-proto "^1.0.0" has-symbols@^1.0.0, has-symbols@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz" integrity sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg== -has-symbols@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.2.tgz#165d3070c00309752a1236a479331e3ac56f1423" - integrity sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw== - has-symbols@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.3.tgz#bb7b2c4349251dce87b125f7bdf874aa7c8b39f8" integrity sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A== -has-tostringtag@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/has-tostringtag/-/has-tostringtag-1.0.0.tgz#7e133818a7d394734f941e73c3d3f9291e658b25" - integrity sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ== +has-symbols@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.1.0.tgz#fc9c6a783a084951d0b971fe1018de813707a338" + integrity sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ== + +has-tostringtag@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-tostringtag/-/has-tostringtag-1.0.2.tgz#2cdc42d40bef2e5b4eeab7c01a73c54ce7ab5abc" + integrity sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw== dependencies: - has-symbols "^1.0.2" + has-symbols "^1.0.3" has@^1.0.3: version "1.0.3" @@ -2548,9 +2898,16 @@ hasha@^5.0.0: is-stream "^2.0.0" type-fest "^0.8.0" -he@1.2.0: +hasown@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.2.tgz#003eaf91be7adc372e84ec59dc37252cedb80003" + integrity sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ== + dependencies: + function-bind "^1.1.2" + +he@^1.2.0: version "1.2.0" - resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz" + resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== hosted-git-info@^2.1.4: @@ -2563,17 +2920,22 @@ html-escaper@^2.0.0: resolved "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.1.tgz" integrity sha512-hNX23TjWwD3q56HpWjUHOKj1+4KKlnjv9PcmBUYKVpga+2cnb9nDx/B1o0yO4n+RZXZdiNxzx6B24C9aNMTkkQ== -husky@8.0.3: - version "8.0.3" - resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184" - integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg== +husky@9.1.7: + version "9.1.7" + resolved "https://registry.yarnpkg.com/husky/-/husky-9.1.7.tgz#d46a38035d101b46a70456a850ff4201344c0b2d" + integrity sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA== ignore@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a" integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ== -import-fresh@^3.0.0, import-fresh@^3.2.1: +ignore@^5.3.1: + version "5.3.2" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.2.tgz#3cd40e729f3643fd87cb04e50bf0eb722bc596f5" + integrity sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g== + +import-fresh@^3.2.1: version "3.2.1" resolved "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz" integrity sha512-6e1q1cnWP2RXD9/keSkxHScg508CdXqXWgWBaETNhyuBFz+kUZlKboh+ISK+bU++DmbHimVBrOz/zzPe0sZ3sQ== @@ -2581,6 +2943,14 @@ import-fresh@^3.0.0, import-fresh@^3.2.1: parent-module "^1.0.0" resolve-from "^4.0.0" +import-fresh@^3.3.0: + version "3.3.1" + resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.1.tgz#9cecb56503c0ada1f2741dbbd6546e4b13b57ccf" + integrity sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ== + dependencies: + parent-module "^1.0.0" + resolve-from "^4.0.0" + import-local@^3.0.2: version "3.0.2" resolved "https://registry.npmjs.org/import-local/-/import-local-3.0.2.tgz" @@ -2617,78 +2987,79 @@ ini@^1.3.4: resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== -internal-slot@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.3.tgz#7347e307deeea2faac2ac6205d4bc7d34967f59c" - integrity sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA== - dependencies: - get-intrinsic "^1.1.0" - has "^1.0.3" - side-channel "^1.0.4" - -internal-slot@^1.0.4: - version "1.0.5" - resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.5.tgz#f2a2ee21f668f8627a4667f309dc0f4fb6674986" - integrity sha512-Y+R5hJrzs52QCG2laLn4udYVnxsfny9CpOhNhUvk/SSSVyF6T27FzRbF0sroPidSu3X8oEAkOn2K804mjpt6UQ== +internal-slot@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.1.0.tgz#1eac91762947d2f7056bc838d93e13b2e9604961" + integrity sha512-4gd7VpWNQNB4UKKCFFVcp1AVv+FMOgs9NKzjHKusc8jTMhd5eL1NqQqOpE0KzMds804/yHlglp3uxgluOqAPLw== dependencies: - get-intrinsic "^1.2.0" - has "^1.0.3" - side-channel "^1.0.4" + es-errors "^1.3.0" + hasown "^2.0.2" + side-channel "^1.1.0" interpret@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/interpret/-/interpret-3.1.1.tgz#5be0ceed67ca79c6c4bc5cf0d7ee843dcea110c4" integrity sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ== -inversify@6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/inversify/-/inversify-6.0.1.tgz#b20d35425d5d8c5cd156120237aad0008d969f02" - integrity sha512-B3ex30927698TJENHR++8FfEaJGqoWOgI6ZY5Ht/nLUsFCwHn6akbwtnUAPCgUepAnTpe2qHxhDNjoKLyz6rgQ== +inversify@6.1.4: + version "6.1.4" + resolved "https://registry.yarnpkg.com/inversify/-/inversify-6.1.4.tgz#7dc288b190bc6c0e2081d7a003cbf6c4f94d946f" + integrity sha512-PbxrZH/gTa1fpPEEGAjJQzK8tKMIp5gRg6EFNJlCtzUcycuNdmhv3uk5P8Itm/RIjgHJO16oQRLo9IHzQN51bA== + dependencies: + "@inversifyjs/common" "1.3.3" + "@inversifyjs/core" "1.3.4" is-arguments@^1.0.4: version "1.0.4" resolved "https://registry.npmjs.org/is-arguments/-/is-arguments-1.0.4.tgz" integrity sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA== -is-array-buffer@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/is-array-buffer/-/is-array-buffer-3.0.1.tgz#deb1db4fcae48308d54ef2442706c0393997052a" - integrity sha512-ASfLknmY8Xa2XtB4wmbz13Wu202baeA18cJBCeCy0wXUHZF0IPyVEXqKEcd+t2fNSLLL1vC6k7lxZEojNbISXQ== +is-array-buffer@^3.0.4, is-array-buffer@^3.0.5: + version "3.0.5" + resolved "https://registry.yarnpkg.com/is-array-buffer/-/is-array-buffer-3.0.5.tgz#65742e1e687bd2cc666253068fd8707fe4d44280" + integrity sha512-DDfANUiiG2wC1qawP66qlTugJeL5HyzMpfr8lLK+jMQirGzNod0B12cFB/9q838Ru27sBwfw78/rdoU7RERz6A== dependencies: - call-bind "^1.0.2" - get-intrinsic "^1.1.3" - is-typed-array "^1.1.10" + call-bind "^1.0.8" + call-bound "^1.0.3" + get-intrinsic "^1.2.6" is-arrayish@^0.2.1: version "0.2.1" resolved "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz" integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= -is-bigint@^1.0.1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.2.tgz#ffb381442503235ad245ea89e45b3dbff040ee5a" - integrity sha512-0JV5+SOCQkIdzjBK9buARcV804Ddu7A0Qet6sHi3FimE9ne6m4BGQZfRn+NZiXbBk4F4XmHfDZIipLj9pX8dSA== +is-async-function@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/is-async-function/-/is-async-function-2.1.1.tgz#3e69018c8e04e73b738793d020bfe884b9fd3523" + integrity sha512-9dgM/cZBnNvjzaMYHVoxxfPj2QXt22Ev7SuuPrs+xav0ukGB0S6d4ydZdEiM48kLx5kDV+QBPrpVnFyefL8kkQ== + dependencies: + async-function "^1.0.0" + call-bound "^1.0.3" + get-proto "^1.0.1" + has-tostringtag "^1.0.2" + safe-regex-test "^1.1.0" -is-binary-path@~2.1.0: - version "2.1.0" - resolved "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz" - integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== +is-bigint@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.1.0.tgz#dda7a3445df57a42583db4228682eba7c4170672" + integrity sha512-n4ZT37wG78iz03xPRKJrHTdZbe3IicyucEtdRsV5yglwc3GyUfbAfpSeD0FJ41NbUNSt5wbhqfp1fS+BgnvDFQ== dependencies: - binary-extensions "^2.0.0" + has-bigints "^1.0.2" -is-boolean-object@^1.1.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.1.1.tgz#3c0878f035cb821228d350d2e1e36719716a3de8" - integrity sha512-bXdQWkECBUIAcCkeH1unwJLIpZYaa5VvuygSyS/c2lf719mTKZDU5UdDRlpd01UjADgmW8RfqaP+mRaVPdr/Ng== +is-boolean-object@^1.2.1: + version "1.2.2" + resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.2.2.tgz#7067f47709809a393c71ff5bb3e135d8a9215d9e" + integrity sha512-wa56o2/ElJMYqjCjGkXri7it5FbebW5usLw/nPmCMs5DeZ7eziSYZhSmPRn0txqeW4LnAmQQU7FgqLpsEFKM4A== dependencies: - call-bind "^1.0.2" + call-bound "^1.0.3" + has-tostringtag "^1.0.2" is-buffer@~1.1.6: version "1.1.6" resolved "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz" integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== -is-builtin-module@^3.2.0: +is-builtin-module@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-3.2.1.tgz#f03271717d8654cfcaf07ab0463faa3571581169" integrity sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A== @@ -2710,17 +3081,12 @@ is-callable@^1.2.2: resolved "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz" integrity sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA== -is-callable@^1.2.4: - version "1.2.4" - resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.4.tgz#47301d58dd0259407865547853df6d61fe471945" - integrity sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w== - -is-core-module@^2.11.0, is-core-module@^2.9.0: - version "2.11.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.11.0.tgz#ad4cb3e3863e814523c96f3f58d26cc570ff0144" - integrity sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw== +is-core-module@^2.13.0, is-core-module@^2.16.1: + version "2.16.1" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.16.1.tgz#2a98801a849f43e2add644fbb6bc6229b19a4ef4" + integrity sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w== dependencies: - has "^1.0.3" + hasown "^2.0.2" is-core-module@^2.2.0: version "2.4.0" @@ -2729,11 +3095,28 @@ is-core-module@^2.2.0: dependencies: has "^1.0.3" +is-data-view@^1.0.1, is-data-view@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-data-view/-/is-data-view-1.0.2.tgz#bae0a41b9688986c2188dda6657e56b8f9e63b8e" + integrity sha512-RKtWF8pGmS87i2D6gqQu/l7EYRlVdfzemCJN/P3UOs//x1QE7mfhvzHIApBTRf7axvT6DMGwSwBXYCT0nfB9xw== + dependencies: + call-bound "^1.0.2" + get-intrinsic "^1.2.6" + is-typed-array "^1.1.13" + is-date-object@^1.0.1: version "1.0.2" resolved "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz" integrity sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g== +is-date-object@^1.0.5, is-date-object@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.1.0.tgz#ad85541996fc7aa8b2729701d27b7319f95d82f7" + integrity sha512-PwwhEakHVKTdRNVOw+/Gyh0+MzlCl4R6qKvkhuvLtPMggI1WAHt9sOwZxQLSGpUaDnrdyDsomoRgNnCfKNSXXg== + dependencies: + call-bound "^1.0.2" + has-tostringtag "^1.0.2" + is-docker@^2.0.0: version "2.2.1" resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa" @@ -2744,17 +3127,35 @@ is-extglob@^2.1.1: resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI= +is-finalizationregistry@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/is-finalizationregistry/-/is-finalizationregistry-1.1.1.tgz#eefdcdc6c94ddd0674d9c85887bf93f944a97c90" + integrity sha512-1pC6N8qWJbWoPtEjgcL2xyhQOP491EQjeUo3qTKcmV8YSDDJrOepfG8pcC7h/QgnQHYSv0mJ3Z/ZWxmatVrysg== + dependencies: + call-bound "^1.0.3" + is-fullwidth-code-point@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz" integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== +is-generator-function@^1.0.10: + version "1.1.2" + resolved "https://registry.yarnpkg.com/is-generator-function/-/is-generator-function-1.1.2.tgz#ae3b61e3d5ea4e4839b90bad22b02335051a17d5" + integrity sha512-upqt1SkGkODW9tsGNG5mtXTXtECizwtS2kA161M+gJPc1xdb/Ax629af6YrTwcOeQHbewrPNlE5Dx7kzvXTizA== + dependencies: + call-bound "^1.0.4" + generator-function "^2.0.0" + get-proto "^1.0.1" + has-tostringtag "^1.0.2" + safe-regex-test "^1.1.0" + is-generator-function@^1.0.7: version "1.0.7" resolved "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.7.tgz" integrity sha512-YZc5EwyO4f2kWCax7oegfuSr9mFz1ZvieNYBEjmukLxgXfBUbxAWGVF7GZf0zidYtoBl3WvC07YK0wT76a+Rtw== -is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: +is-glob@^4.0.0, is-glob@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc" integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg== @@ -2768,11 +3169,17 @@ is-glob@^4.0.3: dependencies: is-extglob "^2.1.1" -is-nan@^1.2.1: - version "1.3.0" - resolved "https://registry.npmjs.org/is-nan/-/is-nan-1.3.0.tgz" - integrity sha512-z7bbREymOqt2CCaZVly8aC4ML3Xhfi0ekuOnjO2L8vKdl+CttdVoGZQhd4adMFAsxQ5VeRVwORs4tU8RH+HFtQ== +is-map@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/is-map/-/is-map-2.0.3.tgz#ede96b7fe1e270b3c4465e3a465658764926d62e" + integrity sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw== + +is-nan@^1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/is-nan/-/is-nan-1.3.2.tgz#043a54adea31748b55b6cd4e09aadafa69bd9e1d" + integrity sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w== dependencies: + call-bind "^1.0.0" define-properties "^1.1.3" is-negative-zero@^2.0.0: @@ -2780,20 +3187,18 @@ is-negative-zero@^2.0.0: resolved "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.0.tgz" integrity sha1-lVOxIbD6wohp2p7UWeIMdUN4hGE= -is-negative-zero@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.1.tgz#3de746c18dda2319241a53675908d8f766f11c24" - integrity sha512-2z6JzQvZRa9A2Y7xC6dQQm4FSTSTNWjKIYYTt4246eMTJmIo0Q+ZyOsU66X8lxK1AbB92dFeglPLrhwpeRKO6w== - -is-negative-zero@^2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.2.tgz#7bf6f03a28003b8b3965de3ac26f664d765f3150" - integrity sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA== +is-negative-zero@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.3.tgz#ced903a027aca6381b777a5743069d7376a49747" + integrity sha512-5KoIu2Ngpyek75jXodFvnafB6DJgr3u8uuK0LEZJjrU19DrMD3EVERaR8sjz8CCGgpZvxPl9SuE1GMVPFHx1mw== -is-number-object@^1.0.4: - version "1.0.5" - resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.5.tgz#6edfaeed7950cff19afedce9fbfca9ee6dd289eb" - integrity sha512-RU0lI/n95pMoUKu9v1BZP5MBcZuNSVJkMkAG2dJqC4z2GlkGUNeH68SuHuBKBD/XFe+LHZ+f9BKkLET60Niedw== +is-number-object@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.1.1.tgz#144b21e95a1bc148205dcc2814a9134ec41b2541" + integrity sha512-lZhclumE1G6VYD8VHe35wFaIif+CTy5SJIi5+3y4psDgWu4wPDoBhF8NxUOinEc7pHgiTsT6MaBb92rKhhD+Xw== + dependencies: + call-bound "^1.0.3" + has-tostringtag "^1.0.2" is-number@^7.0.0: version "7.0.0" @@ -2836,42 +3241,40 @@ is-regex@^1.1.1: dependencies: has-symbols "^1.0.1" -is-regex@^1.1.4: - version "1.1.4" - resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.4.tgz#eef5663cd59fa4c0ae339505323df6854bb15958" - integrity sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg== +is-regex@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.2.1.tgz#76d70a3ed10ef9be48eb577887d74205bf0cad22" + integrity sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g== dependencies: - call-bind "^1.0.2" - has-tostringtag "^1.0.0" + call-bound "^1.0.2" + gopd "^1.2.0" + has-tostringtag "^1.0.2" + hasown "^2.0.2" -is-shared-array-buffer@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/is-shared-array-buffer/-/is-shared-array-buffer-1.0.1.tgz#97b0c85fbdacb59c9c446fe653b82cf2b5b7cfe6" - integrity sha512-IU0NmyknYZN0rChcKhRO1X8LYz5Isj/Fsqh8NJOSf+N/hCOTwy29F32Ik7a+QszE63IdvmwdTPDd6cZ5pg4cwA== +is-set@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/is-set/-/is-set-2.0.3.tgz#8ab209ea424608141372ded6e0cb200ef1d9d01d" + integrity sha512-iPAjerrse27/ygGLxw+EBR9agv9Y6uLeYVJMu+QNCoouJ1/1ri0mGrcWpfCqFZuzzx3WjtwxG098X+n4OuRkPg== -is-shared-array-buffer@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz#8f259c573b60b6a32d4058a1a07430c0a7344c79" - integrity sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA== +is-shared-array-buffer@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/is-shared-array-buffer/-/is-shared-array-buffer-1.0.4.tgz#9b67844bd9b7f246ba0708c3a93e34269c774f6f" + integrity sha512-ISWac8drv4ZGfwKl5slpHG9OwPNty4jOWPRIhBpxOoD+hqITiwuipOQ2bNthAzwA3B4fIjO4Nln74N0S9byq8A== dependencies: - call-bind "^1.0.2" + call-bound "^1.0.3" is-stream@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz" integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw== -is-string@^1.0.5: - version "1.0.5" - resolved "https://registry.npmjs.org/is-string/-/is-string-1.0.5.tgz" - integrity sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ== - -is-string@^1.0.7: - version "1.0.7" - resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.7.tgz#0dd12bf2006f255bb58f695110eff7491eebc0fd" - integrity sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg== +is-string@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.1.1.tgz#92ea3f3d5c5b6e039ca8677e5ac8d07ea773cbb9" + integrity sha512-BtEeSsoaQjlSPBemMQIrY1MY0uM6vnS1g5fmufYOtnxLGUZM2178PKbhsk7Ffv58IX+ZtcvoGwccYsh0PglkAA== dependencies: - has-tostringtag "^1.0.0" + call-bound "^1.0.3" + has-tostringtag "^1.0.2" is-symbol@^1.0.2: version "1.0.3" @@ -2880,23 +3283,21 @@ is-symbol@^1.0.2: dependencies: has-symbols "^1.0.1" -is-symbol@^1.0.3: - version "1.0.4" - resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.4.tgz#a6dac93b635b063ca6872236de88910a57af139c" - integrity sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg== +is-symbol@^1.0.4, is-symbol@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.1.1.tgz#f47761279f532e2b05a7024a7506dbbedacd0634" + integrity sha512-9gGx6GTtCQM73BgmHQXfDmLtfjjTUDSyoxTCbp5WtoixAhfgsDirWIcVQ/IHpvI5Vgd5i/J5F7B9cN/WlVbC/w== dependencies: - has-symbols "^1.0.2" + call-bound "^1.0.2" + has-symbols "^1.1.0" + safe-regex-test "^1.1.0" -is-typed-array@^1.1.10, is-typed-array@^1.1.9: - version "1.1.10" - resolved "https://registry.yarnpkg.com/is-typed-array/-/is-typed-array-1.1.10.tgz#36a5b5cb4189b575d1a3e4b08536bfb485801e3f" - integrity sha512-PJqgEHiWZvMpaFZ3uTc8kHPM4+4ADTlDniuQL7cU/UDA0Ql7F70yGfHph3cLNe+c9toaigv+DFzTJKhc2CtO6A== +is-typed-array@^1.1.13, is-typed-array@^1.1.14, is-typed-array@^1.1.15: + version "1.1.15" + resolved "https://registry.yarnpkg.com/is-typed-array/-/is-typed-array-1.1.15.tgz#4bfb4a45b61cee83a5a46fba778e4e8d59c0ce0b" + integrity sha512-p3EcsicXjit7SaskXHs1hA91QxgTw46Fv6EFKKGS5DRFLD8yKnohjF3hxoju94b/OcMZoQukzpPpBE9uLVKzgQ== dependencies: - available-typed-arrays "^1.0.5" - call-bind "^1.0.2" - for-each "^0.3.3" - gopd "^1.0.1" - has-tostringtag "^1.0.0" + which-typed-array "^1.1.16" is-typed-array@^1.1.3: version "1.1.3" @@ -2918,12 +3319,10 @@ is-unicode-supported@^0.1.0: resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7" integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== -is-weakref@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.0.1.tgz#842dba4ec17fa9ac9850df2d6efbc1737274f2a2" - integrity sha512-b2jKc2pQZjaeFYWEf7ScFj+Be1I+PXmlu572Q8coTXZ+LD/QQZ7ShPMst8h16riVgyXTQwUsFEl74mDvc/3MHQ== - dependencies: - call-bind "^1.0.0" +is-weakmap@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.2.tgz#bf72615d649dfe5f699079c54b83e47d1ae19cfd" + integrity sha512-K5pXYOm9wqY1RgjpL3YTkF39tni1XajUIkawTLUo9EZEVUFga5gSQJF8nNS7ZwJQ02y+1YCNYcMh+HIf1ZqE+w== is-weakref@^1.0.2: version "1.0.2" @@ -2932,6 +3331,21 @@ is-weakref@^1.0.2: dependencies: call-bind "^1.0.2" +is-weakref@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.1.1.tgz#eea430182be8d64174bd96bffbc46f21bf3f9293" + integrity sha512-6i9mGWSlqzNMEqpCp93KwRS1uUOodk2OJ6b+sq7ZPDSy2WuI5NFIxp/254TytR8ftefexkWn5xNiHUNpPOfSew== + dependencies: + call-bound "^1.0.3" + +is-weakset@^2.0.3: + version "2.0.4" + resolved "https://registry.yarnpkg.com/is-weakset/-/is-weakset-2.0.4.tgz#c9f5deb0bc1906c6d6f1027f284ddf459249daca" + integrity sha512-mfcwb6IzQyOKTs84CQMrOwW4gQcaTOAWJ0zzJCl2WSPDrWk/OzDaImWFH3djXhb24g4eudZfLRozAvPGw4d9hQ== + dependencies: + call-bound "^1.0.3" + get-intrinsic "^1.2.6" + is-windows@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz" @@ -2944,10 +3358,10 @@ is-wsl@^2.2.0: dependencies: is-docker "^2.0.0" -isarray@0.0.1: - version "0.0.1" - resolved "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz" - integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= +isarray@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723" + integrity sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw== isexe@^2.0.0: version "2.0.0" @@ -2964,6 +3378,11 @@ istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.0.0-alpha.1: resolved "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.0.0.tgz" integrity sha512-UiUIqxMgRDET6eR+o5HbfRYP1l0hqkWOs7vNxC/mggutCMUIhWMm8gAHb8tHlyfD3/l6rlgNA5cKdDzEAf6hEg== +istanbul-lib-coverage@^3.2.0: + version "3.2.2" + resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz#2d166c4b0644d43a39f04bf6c2edd1e585f31756" + integrity sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg== + istanbul-lib-hook@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-3.0.0.tgz" @@ -2971,18 +3390,16 @@ istanbul-lib-hook@^3.0.0: dependencies: append-transform "^2.0.0" -istanbul-lib-instrument@^4.0.0: - version "4.0.1" - resolved "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-4.0.1.tgz" - integrity sha512-imIchxnodll7pvQBYOqUu88EufLCU56LMeFPZZM/fJZ1irYcYdqroaV+ACK1Ila8ls09iEYArp+nqyC6lW1Vfg== +istanbul-lib-instrument@^6.0.2: + version "6.0.3" + resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-6.0.3.tgz#fa15401df6c15874bcb2105f773325d78c666765" + integrity sha512-Vtgk7L/R2JHyyGW07spoFlB8/lpjiOLTjMdms6AFMraYt3BaJauod/NGrfnVG/y4Ix1JEuMRPDPEj2ua+zz1/Q== dependencies: - "@babel/core" "^7.7.5" - "@babel/parser" "^7.7.5" - "@babel/template" "^7.7.4" - "@babel/traverse" "^7.7.4" - "@istanbuljs/schema" "^0.1.2" - istanbul-lib-coverage "^3.0.0" - semver "^6.3.0" + "@babel/core" "^7.23.9" + "@babel/parser" "^7.23.9" + "@istanbuljs/schema" "^0.1.3" + istanbul-lib-coverage "^3.2.0" + semver "^7.5.4" istanbul-lib-processinfo@^2.0.2: version "2.0.2" @@ -3023,51 +3440,68 @@ istanbul-reports@^3.0.2: html-escaper "^2.0.0" istanbul-lib-report "^3.0.0" -jest-util@^29.4.2: - version "29.4.2" - resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.4.2.tgz#3db8580b295df453a97de4a1b42dd2578dabd2c2" - integrity sha512-wKnm6XpJgzMUSRFB7YF48CuwdzuDIHenVuoIb1PLuJ6F+uErZsuDkU+EiExkChf6473XcawBrSfDSnXl+/YG4g== +jackspeak@^3.1.2: + version "3.4.3" + resolved "https://registry.yarnpkg.com/jackspeak/-/jackspeak-3.4.3.tgz#8833a9d89ab4acde6188942bd1c53b6390ed5a8a" + integrity sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw== dependencies: - "@jest/types" "^29.4.2" + "@isaacs/cliui" "^8.0.2" + optionalDependencies: + "@pkgjs/parseargs" "^0.11.0" + +jackspeak@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/jackspeak/-/jackspeak-4.1.1.tgz#96876030f450502047fc7e8c7fcf8ce8124e43ae" + integrity sha512-zptv57P3GpL+O0I7VdMJNBZCu+BPHVQUk55Ft8/QCJjTVxrnJHuVuX/0Bl2A6/+2oyR/ZMEuFKwmzqqZ/U5nPQ== + dependencies: + "@isaacs/cliui" "^8.0.2" + +jest-util@^29.7.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.7.0.tgz#23c2b62bfb22be82b44de98055802ff3710fc0bc" + integrity sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA== + dependencies: + "@jest/types" "^29.6.3" "@types/node" "*" chalk "^4.0.0" ci-info "^3.2.0" graceful-fs "^4.2.9" picomatch "^2.2.3" -jest-worker@^27.0.2: - version "27.0.2" - resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.0.2.tgz#4ebeb56cef48b3e7514552f80d0d80c0129f0b05" - integrity sha512-EoBdilOTTyOgmHXtw/cPc+ZrCA0KJMrkXzkrPGNwLmnvvlN1nj7MPrxpT7m+otSv2e1TLaVffzDnE/LB14zJMg== +jest-worker@^27.4.5: + version "27.5.1" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.5.1.tgz#8d146f0900e8973b106b6f73cc1e9a8cb86f8db0" + integrity sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg== dependencies: "@types/node" "*" merge-stream "^2.0.0" supports-color "^8.0.0" -jest-worker@^29.4.1: - version "29.4.2" - resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-29.4.2.tgz#d9b2c3bafc69311d84d94e7fb45677fc8976296f" - integrity sha512-VIuZA2hZmFyRbchsUCHEehoSf2HEl0YVF8SDJqtPnKorAaBuh42V8QsLnde0XP5F6TyCynGPEGgBOn3Fc+wZGw== +jest-worker@^29.7.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-29.7.0.tgz#acad073acbbaeb7262bd5389e1bcf43e10058d4a" + integrity sha512-eIz2msL/EzL9UFTFFx7jBTkeZfku0yUAyZZZmJ93H2TYEiroIx2PQjEXcwYtYl8zXCxb+PAmA2hLIt/6ZEkPHw== dependencies: "@types/node" "*" - jest-util "^29.4.2" + jest-util "^29.7.0" merge-stream "^2.0.0" supports-color "^8.0.0" -js-beautify@1.14.7: - version "1.14.7" - resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.14.7.tgz#9206296de33f86dc106d3e50a35b7cf8729703b2" - integrity sha512-5SOX1KXPFKx+5f6ZrPsIPEY7NwKeQz47n3jm2i+XeHx9MoRsfQenlOP13FQhWvg8JRS0+XLO6XYUQ2GX+q+T9A== +js-beautify@1.15.4: + version "1.15.4" + resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.15.4.tgz#f579f977ed4c930cef73af8f98f3f0a608acd51e" + integrity sha512-9/KXeZUKKJwqCXUdBxFJ3vPh467OCckSBmYDwSK/EtV090K+iMJ7zx2S3HLVDIWFQdqMIsZWbnaGiba18aWhaA== dependencies: config-chain "^1.1.13" - editorconfig "^0.15.3" - glob "^8.0.3" - nopt "^6.0.0" + editorconfig "^1.0.4" + glob "^10.4.2" + js-cookie "^3.0.5" + nopt "^7.2.1" -js-sdsl@^4.1.4: - version "4.3.0" - resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.3.0.tgz#aeefe32a451f7af88425b11fdb5f58c90ae1d711" - integrity sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ== +js-cookie@^3.0.5: + version "3.0.5" + resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-3.0.5.tgz#0b7e2fd0c01552c58ba86e0841f94dc2557dcdbc" + integrity sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw== js-string-escape@1.0.1: version "1.0.1" @@ -3079,13 +3513,6 @@ js-tokens@^4.0.0: resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== -js-yaml@4.1.0, js-yaml@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" - integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== - dependencies: - argparse "^2.0.1" - js-yaml@^3.13.1: version "3.13.1" resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz" @@ -3094,15 +3521,17 @@ js-yaml@^3.13.1: argparse "^1.0.7" esprima "^4.0.0" -jsdoc-type-pratt-parser@~4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-4.0.0.tgz#136f0571a99c184d84ec84662c45c29ceff71114" - integrity sha512-YtOli5Cmzy3q4dP26GraSOeAhqecewG04hoO8DY56CH4KJ9Fvv5qKWUCCo3HZob7esJQHCv6/+bnTy72xZZaVQ== +js-yaml@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" + integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== + dependencies: + argparse "^2.0.1" -jsesc@^2.5.1: - version "2.5.2" - resolved "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz" - integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== +jsdoc-type-pratt-parser@~4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-4.1.0.tgz#ff6b4a3f339c34a6c188cbf50a16087858d22113" + integrity sha512-Hicd6JK5Njt2QB6XYFS7ok9e37O8AYk3jTcppG4YVQnYjOemymvTcmc7OWsmq/Qqj5TdRFO5/x/tIPmBeRtGHg== jsesc@^3.0.2: version "3.0.2" @@ -3119,7 +3548,7 @@ json-parse-better-errors@^1.0.1: resolved "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz" integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw== -json-parse-even-better-errors@^2.3.1: +json-parse-even-better-errors@^2.3.0, json-parse-even-better-errors@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d" integrity sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w== @@ -3139,19 +3568,17 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz" integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE= -json5@^1.0.1: +json5@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593" integrity sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA== dependencies: minimist "^1.2.0" -json5@^2.1.2: - version "2.1.2" - resolved "https://registry.npmjs.org/json5/-/json5-2.1.2.tgz" - integrity sha512-MoUOQ4WdiN3yxhm7NEVJSJrieAo5hNSLQ5sj05OTRHPL9HOBy8u4Bu88jsC1jvqAdN+E1bJmsUcZH+1HQxliqQ== - dependencies: - minimist "^1.2.5" +json5@^2.2.3: + version "2.2.3" + resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283" + integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg== jsonfile@^6.0.1: version "6.0.1" @@ -3162,10 +3589,10 @@ jsonfile@^6.0.1: optionalDependencies: graceful-fs "^4.1.6" -just-extend@^4.0.2: - version "4.1.0" - resolved "https://registry.npmjs.org/just-extend/-/just-extend-4.1.0.tgz" - integrity sha512-ApcjaOdVTJ7y4r08xI5wIqpvwS48Q0PBG4DJROcEkH1f8MdAiNFyFxz3xoL0LWAVwjrwPYZdVHHxhRHcx/uGLA== +just-extend@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-6.2.0.tgz#b816abfb3d67ee860482e7401564672558163947" + integrity sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw== kind-of@^6.0.2: version "6.0.3" @@ -3188,10 +3615,10 @@ levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -libphonenumber-js@^1.10.14: - version "1.10.18" - resolved "https://registry.yarnpkg.com/libphonenumber-js/-/libphonenumber-js-1.10.18.tgz#657c419071c8a02c638c0e80d9ee1232f152f280" - integrity sha512-NS4ZEgNhwbcPz1gfSXCGFnQm0xEiyTSPRthIuWytDzOiEG9xnZ2FbLyfJC4tI2BMAAXpoWbNxHYH75pa3Dq9og== +libphonenumber-js@^1.11.1: + version "1.12.25" + resolved "https://registry.yarnpkg.com/libphonenumber-js/-/libphonenumber-js-1.12.25.tgz#1af48b816082100bf88f47d342387fbac1f1a773" + integrity sha512-u90tUu/SEF8b+RaDKCoW7ZNFDakyBtFlX1ex3J+VH+ElWes/UaitJLt/w4jGu8uAE41lltV/s+kMVtywcMEg7g== lines-and-columns@^1.1.6: version "1.1.6" @@ -3222,22 +3649,12 @@ lodash.flattendeep@^4.4.0: resolved "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz" integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI= -lodash.get@^4.4.2: - version "4.4.2" - resolved "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz" - integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk= - lodash.merge@^4.6.2: version "4.6.2" resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== -lodash@^4.17.13, lodash@^4.17.21: - version "4.17.21" - resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz" - integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== - -log-symbols@4.1.0: +log-symbols@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503" integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== @@ -3245,20 +3662,29 @@ log-symbols@4.1.0: chalk "^4.1.0" is-unicode-supported "^0.1.0" -loupe@^2.3.1: - version "2.3.1" - resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.1.tgz#a2e1192c9f452e4e85089766da10ac8288383947" - integrity sha512-EN1D3jyVmaX4tnajVlfbREU4axL647hLec1h/PXAb8CPDMJiYitcWF2UeLVNttRqaIqQs4x+mRvXf+d+TlDrCA== +loupe@^2.3.6: + version "2.3.7" + resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.7.tgz#6e69b7d4db7d3ab436328013d37d1c8c3540c697" + integrity sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA== dependencies: - get-func-name "^2.0.0" + get-func-name "^2.0.1" + +lru-cache@^10.2.0: + version "10.4.3" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119" + integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ== -lru-cache@^4.1.5: - version "4.1.5" - resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz" - integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g== +lru-cache@^11.0.0: + version "11.2.2" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-11.2.2.tgz#40fd37edffcfae4b2940379c0722dc6eeaa75f24" + integrity sha512-F9ODfyqML2coTIsQpSkRHnLSZMtkU8Q+mSfcaIyKwy58u+8k5nvAYeiNhsyMARvzNcXJ9QfWVrcPsC9e9rAxtg== + +lru-cache@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" + integrity sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w== dependencies: - pseudomap "^1.0.2" - yallist "^2.1.2" + yallist "^3.0.2" lru-cache@^6.0.0: version "6.0.0" @@ -3279,6 +3705,11 @@ make-error@^1.1.1: resolved "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz" integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== +math-intrinsics@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/math-intrinsics/-/math-intrinsics-1.1.0.tgz#a0dd74be81e2aa5c2f27e65ce283605ee4e2b7f9" + integrity sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g== + md5@2.3.0: version "2.3.0" resolved "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz" @@ -3313,20 +3744,12 @@ micromatch@^4.0.0: braces "^3.0.1" picomatch "^2.0.5" -micromatch@^4.0.4: - version "4.0.4" - resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.4.tgz#896d519dfe9db25fce94ceb7a500919bf881ebf9" - integrity sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg== - dependencies: - braces "^3.0.1" - picomatch "^2.2.3" - -micromatch@^4.0.5: - version "4.0.5" - resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" - integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA== +micromatch@^4.0.5, micromatch@^4.0.8: + version "4.0.8" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202" + integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA== dependencies: - braces "^3.0.2" + braces "^3.0.3" picomatch "^2.3.1" mime-db@1.44.0: @@ -3346,13 +3769,20 @@ min-indent@^1.0.0: resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869" integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg== -minimatch@5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.0.1.tgz#fb9022f7528125187c92bd9e9b6366be1cf3415b" - integrity sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g== +minimatch@9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.1.tgz#8a555f541cf976c622daf078bb28f29fb927c253" + integrity sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w== dependencies: brace-expansion "^2.0.1" +minimatch@^10.0.3: + version "10.1.1" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-10.1.1.tgz#e6e61b9b0c1dcab116b5a7d1458e8b6ae9e73a55" + integrity sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ== + dependencies: + "@isaacs/brace-expansion" "^5.0.0" + minimatch@^3.0.4: version "3.0.4" resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz" @@ -3367,14 +3797,14 @@ minimatch@^3.0.5, minimatch@^3.1.2: dependencies: brace-expansion "^1.1.7" -minimatch@^5.0.1: - version "5.1.6" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" - integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== +minimatch@^9.0.3, minimatch@^9.0.4, minimatch@^9.0.5: + version "9.0.5" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.5.tgz#d74f9dd6b57d83d8e98cfb82133b03978bc929e5" + integrity sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow== dependencies: brace-expansion "^2.0.1" -minimist@^1.2.0, minimist@^1.2.5: +minimist@^1.2.0: version "1.2.7" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18" integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g== @@ -3384,45 +3814,51 @@ minimist@^1.2.6: resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== -mkdirp@2.1.3: - version "2.1.3" - resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.3.tgz#b083ff37be046fd3d6552468c1f0ff44c1545d1f" - integrity sha512-sjAkg21peAG9HS+Dkx7hlG9Ztx7HLeKnvB3NQRcu/mltCVmvkF0pisbiTSfDVYTT86XEfZrTUosLdZLStquZUw== +"minipass@^5.0.0 || ^6.0.2 || ^7.0.0", minipass@^7.1.2: + version "7.1.2" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.1.2.tgz#93a9626ce5e5e66bd4db86849e7515e92340a707" + integrity sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw== -mocha@10.4.0: - version "10.4.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.4.0.tgz#ed03db96ee9cfc6d20c56f8e2af07b961dbae261" - integrity sha512-eqhGB8JKapEYcC4ytX/xrzKforgEc3j1pGlAXVy3eRwrtAy5/nIfT1SvgGzfN0XZZxeLq0aQWkOUAmqIJiv+bA== - dependencies: - ansi-colors "4.1.1" - browser-stdout "1.3.1" - chokidar "3.5.3" - debug "4.3.4" - diff "5.0.0" - escape-string-regexp "4.0.0" - find-up "5.0.0" - glob "8.1.0" - he "1.2.0" - js-yaml "4.1.0" - log-symbols "4.1.0" - minimatch "5.0.1" - ms "2.1.3" - serialize-javascript "6.0.0" - strip-json-comments "3.1.1" - supports-color "8.1.1" - workerpool "6.2.1" - yargs "16.2.0" - yargs-parser "20.2.4" - yargs-unparser "2.0.0" +mkdirp@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-3.0.1.tgz#e44e4c5607fb279c168241713cc6e0fea9adcb50" + integrity sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg== + +mocha@11.7.4: + version "11.7.4" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-11.7.4.tgz#f161b17aeccb0762484b33bdb3f7ab9410ba5c82" + integrity sha512-1jYAaY8x0kAZ0XszLWu14pzsf4KV740Gld4HXkhNTXwcHx4AUEDkPzgEHg9CM5dVcW+zv036tjpsEbLraPJj4w== + dependencies: + browser-stdout "^1.3.1" + chokidar "^4.0.1" + debug "^4.3.5" + diff "^7.0.0" + escape-string-regexp "^4.0.0" + find-up "^5.0.0" + glob "^10.4.5" + he "^1.2.0" + is-path-inside "^3.0.3" + js-yaml "^4.1.0" + log-symbols "^4.1.0" + minimatch "^9.0.5" + ms "^2.1.3" + picocolors "^1.1.1" + serialize-javascript "^6.0.2" + strip-json-comments "^3.1.1" + supports-color "^8.1.1" + workerpool "^9.2.0" + yargs "^17.7.2" + yargs-parser "^21.1.1" + yargs-unparser "^2.0.0" ms@2.1.2, ms@^2.1.1: version "2.1.2" resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== -ms@2.1.3: +ms@^2.1.3: version "2.1.3" - resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== multimatch@*: @@ -3436,21 +3872,14 @@ multimatch@*: arrify "^2.0.1" minimatch "^3.0.4" -multimatch@5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/multimatch/-/multimatch-5.0.0.tgz#932b800963cea7a31a033328fa1e0c3a1874dbe6" - integrity sha512-ypMKuglUrZUD99Tk2bUQ+xNQj43lPEfAeX2o9cTteAmShXy2VHDJpuwu1o0xqoKCt9jLVAvwyFKdLTPXKAfJyA== +multimatch@7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/multimatch/-/multimatch-7.0.0.tgz#d0a1bf144db9106b8d19e3cb8cabec1a8986c27f" + integrity sha512-SYU3HBAdF4psHEL/+jXDKHO95/m5P2RvboHT2Y0WtTttvJLP4H/2WS9WlQPFvF6C8d6SpLw8vjCnQOnVIVOSJQ== dependencies: - "@types/minimatch" "^3.0.3" - array-differ "^3.0.0" - array-union "^2.1.0" - arrify "^2.0.1" - minimatch "^3.0.4" - -natural-compare-lite@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4" - integrity sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g== + array-differ "^4.0.0" + array-union "^3.0.1" + minimatch "^9.0.3" natural-compare@^1.4.0: version "1.4.0" @@ -3462,32 +3891,32 @@ neo-async@^2.6.2: resolved "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== -nise@^5.1.2: - version "5.1.4" - resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.4.tgz#491ce7e7307d4ec546f5a659b2efe94a18b4bbc0" - integrity sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg== +nise@^6.1.1: + version "6.1.1" + resolved "https://registry.yarnpkg.com/nise/-/nise-6.1.1.tgz#78ea93cc49be122e44cb7c8fdf597b0e8778b64a" + integrity sha512-aMSAzLVY7LyeM60gvBS423nBmIPP+Wy7St7hsb+8/fc1HmeoHJfLO8CKse4u3BtOZvQLJghYPI2i/1WZrEj5/g== dependencies: - "@sinonjs/commons" "^2.0.0" - "@sinonjs/fake-timers" "^10.0.2" - "@sinonjs/text-encoding" "^0.7.1" - just-extend "^4.0.2" - path-to-regexp "^1.7.0" + "@sinonjs/commons" "^3.0.1" + "@sinonjs/fake-timers" "^13.0.1" + "@sinonjs/text-encoding" "^0.7.3" + just-extend "^6.2.0" + path-to-regexp "^8.1.0" node-abort-controller@^3.0.1: version "3.1.1" resolved "https://registry.yarnpkg.com/node-abort-controller/-/node-abort-controller-3.1.1.tgz#a94377e964a9a37ac3976d848cb5c765833b8548" integrity sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ== -node-notifier@^8.0.2: - version "8.0.2" - resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-8.0.2.tgz#f3167a38ef0d2c8a866a83e318c1ba0efeb702c5" - integrity sha512-oJP/9NAdd9+x2Q+rfphB2RJCHjod70RcRLjosiPMMu5gjIfwVnOUGq2nbTjTUbmy0DJ/tFIVT30+Qe3nzl4TJg== +node-notifier@^10.0.1: + version "10.0.1" + resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-10.0.1.tgz#0e82014a15a8456c4cfcdb25858750399ae5f1c7" + integrity sha512-YX7TSyDukOZ0g+gmzjB6abKu+hTGvO8+8+gIFDsRCU2t8fLV/P2unmt+LGFaIa4y64aX98Qksa97rgz4vMNeLQ== dependencies: growly "^1.3.0" is-wsl "^2.2.0" - semver "^7.3.2" + semver "^7.3.5" shellwords "^0.1.1" - uuid "^8.3.0" + uuid "^8.3.2" which "^2.0.2" node-preload@^0.2.1: @@ -3497,17 +3926,17 @@ node-preload@^0.2.1: dependencies: process-on-spawn "^1.0.0" -node-releases@^1.1.71: - version "1.1.72" - resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.72.tgz#14802ab6b1039a79a0c7d662b610a5bbd76eacbe" - integrity sha512-LLUo+PpH3dU6XizX3iVoubUNheF/owjXCZZ5yACDxNnPtgFuludV1ZL3ayK1kVep42Rmm0+R9/Y60NQbZ2bifw== +node-releases@^2.0.26: + version "2.0.27" + resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.27.tgz#eedca519205cf20f650f61d56b070db111231e4e" + integrity sha512-nmh3lCkYZ3grZvqcCH+fjmQ7X+H0OeZgP40OierEaAptX4XofMh5kwNbWh7lBduUzCcV/8kZ+NDLCwm2iorIlA== -nopt@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/nopt/-/nopt-6.0.0.tgz#245801d8ebf409c6df22ab9d95b65e1309cdb16d" - integrity sha512-ZwLpbTgdhuZUnZzjd7nb1ZV+4DoiC6/sfiVKok72ym/4Tlf+DFdlHYmT2JPmcNNWV6Pi3SDf1kT+A4r9RTuT9g== +nopt@^7.2.1: + version "7.2.1" + resolved "https://registry.yarnpkg.com/nopt/-/nopt-7.2.1.tgz#1cac0eab9b8e97c9093338446eddd40b2c8ca1e7" + integrity sha512-taM24ViiimT/XntxbPyJQzCG+p4EKOpgD3mxFwW38mGjVUrfERQOeY4EDHjdnptttfHuHQXFx+lTP08Q+mLa/w== dependencies: - abbrev "^1.0.0" + abbrev "^2.0.0" normalize-package-data@^2.5.0: version "2.5.0" @@ -3519,15 +3948,15 @@ normalize-package-data@^2.5.0: semver "2 || 3 || 4 || 5" validate-npm-package-license "^3.0.1" -normalize-path@^3.0.0, normalize-path@~3.0.0: +normalize-path@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz" integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== -nyc@15.1.0: - version "15.1.0" - resolved "https://registry.npmjs.org/nyc/-/nyc-15.1.0.tgz" - integrity sha512-jMW04n9SxKdKi1ZMGhvUTHBN0EICCRkHemEoE5jm6mTYcqcdas0ATzgUgejlQUHMvpnOZqGB5Xxsv9KxJW1j8A== +nyc@17.1.0: + version "17.1.0" + resolved "https://registry.yarnpkg.com/nyc/-/nyc-17.1.0.tgz#b6349a401a62ffeb912bd38ea9a018839fdb6eb1" + integrity sha512-U42vQ4czpKa0QdI1hu950XuNhYqgoM+ZF1HT+VuUHL9hPfDPVvNQyltmMqdE9bUHMVa+8yNbc3QKTj8zQhlVxQ== dependencies: "@istanbuljs/load-nyc-config" "^1.0.0" "@istanbuljs/schema" "^0.1.2" @@ -3536,12 +3965,12 @@ nyc@15.1.0: decamelize "^1.2.0" find-cache-dir "^3.2.0" find-up "^4.1.0" - foreground-child "^2.0.0" + foreground-child "^3.3.0" get-package-type "^0.1.0" glob "^7.1.6" istanbul-lib-coverage "^3.0.0" istanbul-lib-hook "^3.0.0" - istanbul-lib-instrument "^4.0.0" + istanbul-lib-instrument "^6.0.2" istanbul-lib-processinfo "^2.0.2" istanbul-lib-report "^3.0.0" istanbul-lib-source-maps "^4.0.0" @@ -3557,15 +3986,10 @@ nyc@15.1.0: test-exclude "^6.0.0" yargs "^15.0.2" -object-inspect@^1.11.0, object-inspect@^1.9.0: - version "1.11.0" - resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.11.0.tgz#9dceb146cedd4148a0d9e51ab88d34cf509922b1" - integrity sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg== - -object-inspect@^1.12.2: - version "1.12.3" - resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.3.tgz#ba62dffd67ee256c8c086dfae69e016cd1f198b9" - integrity sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g== +object-inspect@^1.13.3, object-inspect@^1.13.4: + version "1.13.4" + resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.4.tgz#8375265e21bc20d0fa582c22e1b13485d6e00213" + integrity sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew== object-inspect@^1.7.0: version "1.7.0" @@ -3577,13 +4001,13 @@ object-inspect@^1.8.0: resolved "https://registry.npmjs.org/object-inspect/-/object-inspect-1.8.0.tgz" integrity sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA== -object-is@^1.0.1: - version "1.1.3" - resolved "https://registry.npmjs.org/object-is/-/object-is-1.1.3.tgz" - integrity sha512-teyqLvFWzLkq5B9ki8FVWA902UER2qkxmdA4nLf+wjOLAWgxzCWZNCxpDq9MvE8MmhWNr+I8w3BN49Vx36Y6Xg== +object-is@^1.1.5: + version "1.1.6" + resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.1.6.tgz#1a6a53aed2dd8f7e6775ff870bea58545956ab07" + integrity sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q== dependencies: - define-properties "^1.1.3" - es-abstract "^1.18.0-next.1" + call-bind "^1.0.7" + define-properties "^1.2.1" object-keys@^1.0.11, object-keys@^1.0.12, object-keys@^1.1.1: version "1.1.1" @@ -3610,16 +4034,6 @@ object.assign@^4.1.1: has-symbols "^1.0.1" object-keys "^1.1.1" -object.assign@^4.1.2: - version "4.1.2" - resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.2.tgz#0ed54a342eceb37b38ff76eb831a0e788cb63940" - integrity sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ== - dependencies: - call-bind "^1.0.0" - define-properties "^1.1.3" - has-symbols "^1.0.1" - object-keys "^1.1.1" - object.assign@^4.1.4: version "4.1.4" resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.4.tgz#9673c7c7c351ab8c4d0b516f4343ebf4dfb7799f" @@ -3630,14 +4044,46 @@ object.assign@^4.1.4: has-symbols "^1.0.3" object-keys "^1.1.1" -object.values@^1.1.6: - version "1.1.6" - resolved "https://registry.yarnpkg.com/object.values/-/object.values-1.1.6.tgz#4abbaa71eba47d63589d402856f908243eea9b1d" - integrity sha512-FVVTkD1vENCsAcwNs9k6jea2uHC/X0+JcjG8YA60FN5CMaJmG95wT9jek/xX9nornqGRrBkKtzuAu2wuHpKqvw== +object.assign@^4.1.7: + version "4.1.7" + resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.7.tgz#8c14ca1a424c6a561b0bb2a22f66f5049a945d3d" + integrity sha512-nK28WOo+QIjBkDduTINE4JkF/UJJKyf2EJxvJKfblDpyg0Q+pkOHNTL0Qwy6NP6FhE/EnzV73BxxqcJaXY9anw== + dependencies: + call-bind "^1.0.8" + call-bound "^1.0.3" + define-properties "^1.2.1" + es-object-atoms "^1.0.0" + has-symbols "^1.1.0" + object-keys "^1.1.1" + +object.fromentries@^2.0.8: + version "2.0.8" + resolved "https://registry.yarnpkg.com/object.fromentries/-/object.fromentries-2.0.8.tgz#f7195d8a9b97bd95cbc1999ea939ecd1a2b00c65" + integrity sha512-k6E21FzySsSK5a21KRADBd/NGneRegFO5pLHfdQLpRDETUNJueLXs3WCzyQ3tFRDYgbq3KHGXfTbi2bs8WQ6rQ== dependencies: - call-bind "^1.0.2" - define-properties "^1.1.4" - es-abstract "^1.20.4" + call-bind "^1.0.7" + define-properties "^1.2.1" + es-abstract "^1.23.2" + es-object-atoms "^1.0.0" + +object.groupby@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/object.groupby/-/object.groupby-1.0.3.tgz#9b125c36238129f6f7b61954a1e7176148d5002e" + integrity sha512-+Lhy3TQTuzXI5hevh8sBGqbmurHbbIjAi0Z4S63nthVLmLxfbj4T54a4CfZrXIrt9iP4mVAPYMo/v99taj3wjQ== + dependencies: + call-bind "^1.0.7" + define-properties "^1.2.1" + es-abstract "^1.23.2" + +object.values@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/object.values/-/object.values-1.2.1.tgz#deed520a50809ff7f75a7cfd4bc64c7a038c6216" + integrity sha512-gXah6aZrcUxjWg2zR2MwouP2eHlCBzdV4pygudehaKXSGW4v2AsRQUK+lwwXhii6KFZcunEnmSUoYp5CXibxtA== + dependencies: + call-bind "^1.0.8" + call-bound "^1.0.3" + define-properties "^1.2.1" + es-object-atoms "^1.0.0" observable-fns@^0.6.1: version "0.6.1" @@ -3668,17 +4114,26 @@ optionator@^0.8.1: type-check "~0.3.2" word-wrap "~1.2.3" -optionator@^0.9.1: - version "0.9.1" - resolved "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz" - integrity sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw== +optionator@^0.9.3: + version "0.9.4" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.4.tgz#7ea1c1a5d91d764fb282139c88fe11e182a3a734" + integrity sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g== dependencies: deep-is "^0.1.3" fast-levenshtein "^2.0.6" levn "^0.4.1" prelude-ls "^1.2.1" type-check "^0.4.0" - word-wrap "^1.2.3" + word-wrap "^1.2.5" + +own-keys@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/own-keys/-/own-keys-1.0.1.tgz#e4006910a2bf913585289676eebd6f390cf51358" + integrity sha512-qFOyK5PjiWZd+QQIh+1jhdb9LpxTF0qs7Pm8o5QHYZ0M3vKqSqzsZaEB6oWlxZ+q2sJBMI/Ktgd2N5ZwQoRHfg== + dependencies: + get-intrinsic "^1.2.6" + object-keys "^1.1.1" + safe-push-apply "^1.0.0" p-limit@^2.2.0: version "2.2.2" @@ -3694,13 +4149,6 @@ p-limit@^3.0.2: dependencies: p-try "^2.0.0" -p-limit@^3.1.0: - version "3.1.0" - resolved "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz" - integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== - dependencies: - yocto-queue "^0.1.0" - p-locate@^4.1.0: version "4.1.0" resolved "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz" @@ -3737,6 +4185,11 @@ package-hash@^4.0.0: lodash.flattendeep "^4.4.0" release-zalgo "^1.0.0" +package-json-from-dist@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz#4f1471a010827a86f94cfd9b0727e36d267de505" + integrity sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw== + parent-module@^1.0.0: version "1.0.1" resolved "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz" @@ -3744,6 +4197,14 @@ parent-module@^1.0.0: dependencies: callsites "^3.0.0" +parse-imports@^2.1.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/parse-imports/-/parse-imports-2.2.1.tgz#0a6e8b5316beb5c9905f50eb2bbb8c64a4805642" + integrity sha512-OL/zLggRp8mFhKL0rNORUTR4yBYujK/uU+xZL+/0Rgm2QE4nLO9v8PzEweSJEbMGKmDRjJE4R3IMJlL2di4JeQ== + dependencies: + es-module-lexer "^1.5.3" + slashes "^3.0.12" + parse-json@^5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/parse-json/-/parse-json-5.0.0.tgz" @@ -3754,6 +4215,16 @@ parse-json@^5.0.0: json-parse-better-errors "^1.0.1" lines-and-columns "^1.1.6" +parse-json@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.2.0.tgz#c76fc66dee54231c962b22bcc8a72cf2f99753cd" + integrity sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg== + dependencies: + "@babel/code-frame" "^7.0.0" + error-ex "^1.3.1" + json-parse-even-better-errors "^2.3.0" + lines-and-columns "^1.1.6" + path-exists@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz" @@ -3774,12 +4245,26 @@ path-parse@^1.0.6, path-parse@^1.0.7: resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== -path-to-regexp@^1.7.0: - version "1.8.0" - resolved "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz" - integrity sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA== +path-scurry@^1.11.1: + version "1.11.1" + resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-1.11.1.tgz#7960a668888594a0720b12a911d1a742ab9f11d2" + integrity sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA== + dependencies: + lru-cache "^10.2.0" + minipass "^5.0.0 || ^6.0.2 || ^7.0.0" + +path-scurry@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-2.0.0.tgz#9f052289f23ad8bf9397a2a0425e7b8615c58580" + integrity sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg== dependencies: - isarray "0.0.1" + lru-cache "^11.0.0" + minipass "^7.1.2" + +path-to-regexp@^8.1.0: + version "8.3.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-8.3.0.tgz#aa818a6981f99321003a08987d3cec9c3474cd1f" + integrity sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA== path-type@^4.0.0: version "4.0.0" @@ -3791,7 +4276,12 @@ pathval@^1.1.1: resolved "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz" integrity sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ== -picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1: +picocolors@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b" + integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA== + +picomatch@^2.0.5: version "2.2.2" resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz" integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg== @@ -3818,6 +4308,11 @@ pluralize@^8.0.0: resolved "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz" integrity sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA== +possible-typed-array-names@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz#93e3582bc0e5426586d9d07b79ee40fc841de4ae" + integrity sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg== + prelude-ls@^1.2.1: version "1.2.1" resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz" @@ -3845,11 +4340,6 @@ proto-list@~1.2.1: resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849" integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk= -pseudomap@^1.0.2: - version "1.0.2" - resolved "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz" - integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM= - punycode@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" @@ -3886,12 +4376,10 @@ read-pkg@^5.2.0: parse-json "^5.0.0" type-fest "^0.6.0" -readdirp@~3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7" - integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA== - dependencies: - picomatch "^2.2.1" +readdirp@^4.0.1: + version "4.1.2" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-4.1.2.tgz#eb85801435fbf2a7ee58f19e0921b068fc69948d" + integrity sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg== rechoir@^0.8.0: version "0.8.0" @@ -3900,39 +4388,46 @@ rechoir@^0.8.0: dependencies: resolve "^1.20.0" -reflect-metadata@0.1.13: - version "0.1.13" - resolved "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz" - integrity sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg== - -regexp-tree@^0.1.24: - version "0.1.24" - resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.24.tgz#3d6fa238450a4d66e5bc9c4c14bb720e2196829d" - integrity sha512-s2aEVuLhvnVJW6s/iPgEGK6R+/xngd2jNQ+xy4bXNDKxZKJH6jpPHY6kVeVv1IeLCHgswRj+Kl3ELaDjG6V1iw== - -regexp-tree@~0.1.1: - version "0.1.21" - resolved "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.21.tgz" - integrity sha512-kUUXjX4AnqnR8KRTCrayAo9PzYMRKmVoGgaz2tBuz0MF3g1ZbGebmtW0yFHfFK9CmBjQKeYIgoL22pFLBJY7sw== - -regexp.prototype.flags@^1.4.3: - version "1.4.3" - resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.4.3.tgz#87cab30f80f66660181a3bb7bf5981a872b367ac" - integrity sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA== - dependencies: - call-bind "^1.0.2" - define-properties "^1.1.3" - functions-have-names "^1.2.2" - -regexpp@^3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2" - integrity sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg== +reflect-metadata@0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.2.2.tgz#400c845b6cba87a21f2c65c4aeb158f4fa4d9c5b" + integrity sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q== -regjsparser@^0.9.1: - version "0.9.1" - resolved "https://registry.yarnpkg.com/regjsparser/-/regjsparser-0.9.1.tgz#272d05aa10c7c1f67095b1ff0addae8442fc5709" - integrity sha512-dQUtn90WanSNl+7mQKcXAgZxvUe7Z0SqXlgzv0za4LwiUhyzBC58yQO3liFoUgu8GiJVInAhJjkj1N0EtQ5nkQ== +reflect.getprototypeof@^1.0.6, reflect.getprototypeof@^1.0.9: + version "1.0.10" + resolved "https://registry.yarnpkg.com/reflect.getprototypeof/-/reflect.getprototypeof-1.0.10.tgz#c629219e78a3316d8b604c765ef68996964e7bf9" + integrity sha512-00o4I+DVrefhv+nX0ulyi3biSHCPDe+yLv5o/p6d/UVlirijB8E16FtfwSAi4g3tcqrQ4lRAqQSoFEZJehYEcw== + dependencies: + call-bind "^1.0.8" + define-properties "^1.2.1" + es-abstract "^1.23.9" + es-errors "^1.3.0" + es-object-atoms "^1.0.0" + get-intrinsic "^1.2.7" + get-proto "^1.0.1" + which-builtin-type "^1.2.1" + +regexp-tree@^0.1.27: + version "0.1.27" + resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.27.tgz#2198f0ef54518ffa743fe74d983b56ffd631b6cd" + integrity sha512-iETxpjK6YoRWJG5o6hXLwvjYAoW+FEZn9os0PD/b6AP6xQwsa/Y7lCVgIixBbUPMfhu+i2LtdeAqVTgGlQarfA== + +regexp.prototype.flags@^1.5.4: + version "1.5.4" + resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.4.tgz#1ad6c62d44a259007e55b3970e00f746efbcaa19" + integrity sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA== + dependencies: + call-bind "^1.0.8" + define-properties "^1.2.1" + es-errors "^1.3.0" + get-proto "^1.0.1" + gopd "^1.2.0" + set-function-name "^2.0.2" + +regjsparser@^0.10.0: + version "0.10.0" + resolved "https://registry.yarnpkg.com/regjsparser/-/regjsparser-0.10.0.tgz#b1ed26051736b436f22fdec1c8f72635f9f44892" + integrity sha512-qx+xQGZVsy55CH0a1hiVwHmqjLryfh7wQyF5HO07XJ9f7dQMY/gPQHhlyDkIzJKC+x2fUCpCcUODUUUFrm7SHA== dependencies: jsesc "~0.5.0" @@ -3975,7 +4470,7 @@ resolve-from@^5.0.0: resolved "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== -resolve@^1.10.0, resolve@^1.3.2: +resolve@^1.10.0: version "1.15.1" resolved "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz" integrity sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w== @@ -3990,12 +4485,12 @@ resolve@^1.20.0: is-core-module "^2.2.0" path-parse "^1.0.6" -resolve@^1.22.1: - version "1.22.1" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177" - integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw== +resolve@^1.22.4: + version "1.22.11" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.11.tgz#aad857ce1ffb8bfa9b0b1ac29f1156383f68c262" + integrity sha512-RfqAvLnMl313r7c9oclB1HhUEAezcpLjz95wFH4LVuhk9JF/r22qmVP9AMmOU4vMX7Q8pN8jwNg/CSpdFnMjTQ== dependencies: - is-core-module "^2.9.0" + is-core-module "^2.16.1" path-parse "^1.0.7" supports-preserve-symlinks-flag "^1.0.0" @@ -4004,10 +4499,13 @@ reusify@^1.0.4: resolved "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== -rimraf@4.1.2: - version "4.1.2" - resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-4.1.2.tgz#20dfbc98083bdfaa28b01183162885ef213dbf7c" - integrity sha512-BlIbgFryTbw3Dz6hyoWFhKk+unCcHMSkZGrTFVAx2WmttdBSonsdtRlwiuTbDqTKr+UlXIUqJVS4QT5tUzGENQ== +rimraf@6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-6.0.1.tgz#ffb8ad8844dd60332ab15f52bc104bc3ed71ea4e" + integrity sha512-9dkvaxAsk/xNXSJzMgFqqMCuFgt2+KsOFek3TMLfo8NCPfWpBmqwyNn5Y+NX56QUYfCtsyhF3ayiboEoUmJk/A== + dependencies: + glob "^11.0.0" + package-json-from-dist "^1.0.0" rimraf@^3.0.0, rimraf@^3.0.2: version "3.0.2" @@ -4023,7 +4521,18 @@ run-parallel@^1.1.9: dependencies: queue-microtask "^1.2.2" -safe-buffer@^5.1.0, safe-buffer@^5.1.2: +safe-array-concat@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/safe-array-concat/-/safe-array-concat-1.1.3.tgz#c9e54ec4f603b0bbb8e7e5007a5ee7aecd1538c3" + integrity sha512-AURm5f0jYEOydBj7VQlVvDrjeFgthDdEF5H1dP+6mNpoXOMo1quQqJ4wvJDyRZ9+pO3kGWoOdmV08cSv2aJV6Q== + dependencies: + call-bind "^1.0.8" + call-bound "^1.0.2" + get-intrinsic "^1.2.6" + has-symbols "^1.1.0" + isarray "^2.0.5" + +safe-buffer@^5.1.0: version "5.2.0" resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz" integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg== @@ -4033,32 +4542,24 @@ safe-buffer@~5.1.1: resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz" integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== -safe-regex-test@^1.0.0: +safe-push-apply@^1.0.0: version "1.0.0" - resolved "https://registry.yarnpkg.com/safe-regex-test/-/safe-regex-test-1.0.0.tgz#793b874d524eb3640d1873aad03596db2d4f2295" - integrity sha512-JBUUzyOgEwXQY1NuPtvcj/qcBDbDmEvWufhlnXZIm75DEHp+afM1r1ujJpJsV/gSM4t59tpDyPi1sd6ZaPFfsA== - dependencies: - call-bind "^1.0.2" - get-intrinsic "^1.1.3" - is-regex "^1.1.4" - -safe-regex@^2.1.1: - version "2.1.1" - resolved "https://registry.npmjs.org/safe-regex/-/safe-regex-2.1.1.tgz" - integrity sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A== + resolved "https://registry.yarnpkg.com/safe-push-apply/-/safe-push-apply-1.0.0.tgz#01850e981c1602d398c85081f360e4e6d03d27f5" + integrity sha512-iKE9w/Z7xCzUMIZqdBsp6pEQvwuEebH4vdpjcDWnyzaI6yl6O9FHvVpmGelvEHNsoY6wGblkxR6Zty/h00WiSA== dependencies: - regexp-tree "~0.1.1" + es-errors "^1.3.0" + isarray "^2.0.5" -schema-utils@^3.0.0: - version "3.0.0" - resolved "https://registry.npmjs.org/schema-utils/-/schema-utils-3.0.0.tgz" - integrity sha512-6D82/xSzO094ajanoOSbe4YvXWMfn2A//8Y1+MUqFAJul5Bs+yn36xbK9OtNDcRVSBJ9jjeoXftM6CfztsjOAA== +safe-regex-test@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/safe-regex-test/-/safe-regex-test-1.1.0.tgz#7f87dfb67a3150782eaaf18583ff5d1711ac10c1" + integrity sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw== dependencies: - "@types/json-schema" "^7.0.6" - ajv "^6.12.5" - ajv-keywords "^3.5.2" + call-bound "^1.0.2" + es-errors "^1.3.0" + is-regex "^1.2.1" -schema-utils@^3.1.0, schema-utils@^3.1.1: +schema-utils@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281" integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw== @@ -4067,32 +4568,30 @@ schema-utils@^3.1.0, schema-utils@^3.1.1: ajv "^6.12.5" ajv-keywords "^3.5.2" -schema-utils@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-4.0.0.tgz#60331e9e3ae78ec5d16353c467c34b3a0a1d3df7" - integrity sha512-1edyXKgh6XnJsJSQ8mKWXnN/BVaIbFMLpouRUrXgVq7WYne5kw3MW7UPhO44uRXQSIpTSXoJbmrR2X0w9kUTyg== +schema-utils@^4.2.0, schema-utils@^4.3.0, schema-utils@^4.3.3: + version "4.3.3" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-4.3.3.tgz#5b1850912fa31df90716963d45d9121fdfc09f46" + integrity sha512-eflK8wEtyOE6+hsaRVPxvUKYCpRgzLqDTb8krvAsRIwOGlHoSgYLgBXoubGgLd2fT41/OUYdb48v4k4WWHQurA== dependencies: "@types/json-schema" "^7.0.9" - ajv "^8.8.0" + ajv "^8.9.0" ajv-formats "^2.1.1" - ajv-keywords "^5.0.0" + ajv-keywords "^5.1.0" -"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.6.0: +"semver@2 || 3 || 4 || 5": version "5.7.1" resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== -semver@^6.0.0, semver@^6.3.0: +semver@^6.0.0: version "6.3.0" resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== -semver@^7.3.2, semver@^7.3.7, semver@^7.3.8: - version "7.3.8" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798" - integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A== - dependencies: - lru-cache "^6.0.0" +semver@^6.3.1: + version "6.3.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" + integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== semver@^7.3.4: version "7.3.4" @@ -4108,22 +4607,15 @@ semver@^7.3.5: dependencies: lru-cache "^6.0.0" -semver@^7.6.2: - version "7.6.2" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13" - integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w== +semver@^7.5.3, semver@^7.5.4, semver@^7.6.0, semver@^7.6.3: + version "7.7.3" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.3.tgz#4b5f4143d007633a8dc671cd0a6ef9147b8bb946" + integrity sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q== -serialize-javascript@6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" - integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag== - dependencies: - randombytes "^2.1.0" - -serialize-javascript@^5.0.1: - version "5.0.1" - resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-5.0.1.tgz" - integrity sha512-SaaNal9imEO737H2c05Og0/8LUXG7EnsZyMa8MzkmuHoELfT6txuj0cMqRj6zfPKnmQ1yasR4PCJc8x+M4JSPA== +serialize-javascript@^6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.2.tgz#defa1e055c83bf6d59ea805d8da862254eb6a6c2" + integrity sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g== dependencies: randombytes "^2.1.0" @@ -4132,6 +4624,37 @@ set-blocking@^2.0.0: resolved "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz" integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= +set-function-length@^1.2.2: + version "1.2.2" + resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.2.tgz#aac72314198eaed975cf77b2c3b6b880695e5449" + integrity sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg== + dependencies: + define-data-property "^1.1.4" + es-errors "^1.3.0" + function-bind "^1.1.2" + get-intrinsic "^1.2.4" + gopd "^1.0.1" + has-property-descriptors "^1.0.2" + +set-function-name@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/set-function-name/-/set-function-name-2.0.2.tgz#16a705c5a0dc2f5e638ca96d8a8cd4e1c2b90985" + integrity sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ== + dependencies: + define-data-property "^1.1.4" + es-errors "^1.3.0" + functions-have-names "^1.2.3" + has-property-descriptors "^1.0.2" + +set-proto@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/set-proto/-/set-proto-1.0.0.tgz#0760dbcff30b2d7e801fd6e19983e56da337565e" + integrity sha512-RJRdvCo6IAnPdsvP/7m6bsQqNnn1FCBX5ZNtFL98MmFF/4xAIJTIg1YbHW5DC2W5SKZanrC6i4HsJqlajw/dZw== + dependencies: + dunder-proto "^1.0.1" + es-errors "^1.3.0" + es-object-atoms "^1.0.0" + shallow-clone@^3.0.0: version "3.0.1" resolved "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz" @@ -4156,42 +4679,78 @@ shellwords@^0.1.1: resolved "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz" integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww== -side-channel@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" - integrity sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw== +side-channel-list@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/side-channel-list/-/side-channel-list-1.0.0.tgz#10cb5984263115d3b7a0e336591e290a830af8ad" + integrity sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA== dependencies: - call-bind "^1.0.0" - get-intrinsic "^1.0.2" - object-inspect "^1.9.0" + es-errors "^1.3.0" + object-inspect "^1.13.3" -sigmund@^1.0.1: +side-channel-map@^1.0.1: version "1.0.1" - resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" - integrity sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA= + resolved "https://registry.yarnpkg.com/side-channel-map/-/side-channel-map-1.0.1.tgz#d6bb6b37902c6fef5174e5f533fab4c732a26f42" + integrity sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA== + dependencies: + call-bound "^1.0.2" + es-errors "^1.3.0" + get-intrinsic "^1.2.5" + object-inspect "^1.13.3" + +side-channel-weakmap@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz#11dda19d5368e40ce9ec2bdc1fb0ecbc0790ecea" + integrity sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A== + dependencies: + call-bound "^1.0.2" + es-errors "^1.3.0" + get-intrinsic "^1.2.5" + object-inspect "^1.13.3" + side-channel-map "^1.0.1" + +side-channel@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.1.0.tgz#c3fcff9c4da932784873335ec9765fa94ff66bc9" + integrity sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw== + dependencies: + es-errors "^1.3.0" + object-inspect "^1.13.3" + side-channel-list "^1.0.0" + side-channel-map "^1.0.1" + side-channel-weakmap "^1.0.2" signal-exit@^3.0.2: version "3.0.2" resolved "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz" integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= -sinon@15.0.1: - version "15.0.1" - resolved "https://registry.yarnpkg.com/sinon/-/sinon-15.0.1.tgz#ce062611a0b131892e2c18f03055b8eb6e8dc234" - integrity sha512-PZXKc08f/wcA/BMRGBze2Wmw50CWPiAH3E21EOi4B49vJ616vW4DQh4fQrqsYox2aNR/N3kCqLuB0PwwOucQrg== - dependencies: - "@sinonjs/commons" "^2.0.0" - "@sinonjs/fake-timers" "10.0.2" - "@sinonjs/samsam" "^7.0.1" - diff "^5.0.0" - nise "^5.1.2" +signal-exit@^4.0.1: + version "4.1.0" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.1.0.tgz#952188c1cbd546070e2dd20d0f41c0ae0530cb04" + integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw== + +sinon@19.0.2: + version "19.0.2" + resolved "https://registry.yarnpkg.com/sinon/-/sinon-19.0.2.tgz#944cf771d22236aa84fc1ab70ce5bffc3a215dad" + integrity sha512-euuToqM+PjO4UgXeLETsfQiuoyPXlqFezr6YZDFwHR3t4qaX0fZUe1MfPMznTL5f8BWrVS89KduLdMUsxFCO6g== + dependencies: + "@sinonjs/commons" "^3.0.1" + "@sinonjs/fake-timers" "^13.0.2" + "@sinonjs/samsam" "^8.0.1" + diff "^7.0.0" + nise "^6.1.1" supports-color "^7.2.0" slash@^3.0.0: version "3.0.0" - resolved "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz" + resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== +slashes@^3.0.12: + version "3.0.12" + resolved "https://registry.yarnpkg.com/slashes/-/slashes-3.0.12.tgz#3d664c877ad542dc1509eaf2c50f38d483a6435a" + integrity sha512-Q9VME8WyGkc7pJf6QEkj3wE+2CnvZMI+XJhwdTPR8Z/kWQRXi7boAWLDibRPyHRTUTPx5FaU7MsyrjI3yLB4HA== + source-map-resolve@0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.6.0.tgz#3d9df87e236b53f16d01e58150fc7711138e5ed2" @@ -4208,14 +4767,6 @@ source-map-support@0.5.21: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-support@~0.5.19: - version "0.5.19" - resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz" - integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw== - dependencies: - buffer-from "^1.0.0" - source-map "^0.6.0" - source-map-support@~0.5.20: version "0.5.20" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.20.tgz#12166089f8f5e5e8c56926b377633392dd2cb6c9" @@ -4224,20 +4775,15 @@ source-map-support@~0.5.20: buffer-from "^1.0.0" source-map "^0.6.0" -source-map@^0.5.0: - version "0.5.7" - resolved "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz" - integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= - source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: version "0.6.1" resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@~0.7.2: - version "0.7.3" - resolved "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz" - integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ== +source-map@^0.7.4: + version "0.7.6" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.6.tgz#a3658ab87e5b6429c8a1f3ba0083d4c61ca3ef02" + integrity sha512-i5uvt8C3ikiWeNZSVZNWcfZPItFQOsYTUAOkcUPGd8DqDy1uOUikjt5dG+uRlwyvR108Fb9DOd4GvXfT0N2/uQ== spawn-wrap@^2.0.0: version "2.0.0" @@ -4290,11 +4836,29 @@ sprintf-js@~1.0.2: resolved "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz" integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= +stop-iteration-iterator@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/stop-iteration-iterator/-/stop-iteration-iterator-1.1.0.tgz#f481ff70a548f6124d0312c3aa14cbfa7aa542ad" + integrity sha512-eLoXW/DHyl62zxY4SCaIgnRhuMr6ri4juEYARS8E6sCEqzKpOiE521Ucofdx+KnDZl5xmvGYaaKCk5FEOxJCoQ== + dependencies: + es-errors "^1.3.0" + internal-slot "^1.1.0" + string-template@1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/string-template/-/string-template-1.0.0.tgz" integrity sha1-np8iM9wA8hhxjsN5oopWc+zKi5Y= +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.2.3: + name string-width-cjs + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + string-width@^4.1.0, string-width@^4.2.0: version "4.2.0" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz" @@ -4304,6 +4868,28 @@ string-width@^4.1.0, string-width@^4.2.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.0" +string-width@^5.0.1, string-width@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" + integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA== + dependencies: + eastasianwidth "^0.2.0" + emoji-regex "^9.2.2" + strip-ansi "^7.0.1" + +string.prototype.trim@^1.2.10: + version "1.2.10" + resolved "https://registry.yarnpkg.com/string.prototype.trim/-/string.prototype.trim-1.2.10.tgz#40b2dd5ee94c959b4dcfb1d65ce72e90da480c81" + integrity sha512-Rs66F0P/1kedk5lyYyH9uBzuiI/kNRmwJAR9quK6VOtIpZ2G+hMZd+HQbbv25MgCA6gEffoMZYxlTod4WcdrKA== + dependencies: + call-bind "^1.0.8" + call-bound "^1.0.2" + define-data-property "^1.1.4" + define-properties "^1.2.1" + es-abstract "^1.23.5" + es-object-atoms "^1.0.0" + has-property-descriptors "^1.0.2" + string.prototype.trimend@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz" @@ -4312,22 +4898,15 @@ string.prototype.trimend@^1.0.1: define-properties "^1.1.3" es-abstract "^1.17.5" -string.prototype.trimend@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.4.tgz#e75ae90c2942c63504686c18b287b4a0b1a45f80" - integrity sha512-y9xCjw1P23Awk8EvTpcyL2NIr1j7wJ39f+k6lvRnSMz+mz9CGz9NYPelDk42kOz6+ql8xjfK8oYzy3jAP5QU5A== - dependencies: - call-bind "^1.0.2" - define-properties "^1.1.3" - -string.prototype.trimend@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.6.tgz#c4a27fa026d979d79c04f17397f250a462944533" - integrity sha512-JySq+4mrPf9EsDBEDYMOb/lM7XQLulwg5R/m1r0PXEFqrV0qHvl58sdTilSXtKOflCsK2E8jxf+GKC0T07RWwQ== +string.prototype.trimend@^1.0.9: + version "1.0.9" + resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.9.tgz#62e2731272cd285041b36596054e9f66569b6942" + integrity sha512-G7Ok5C6E/j4SGfyLCloXTrngQIQU3PWtXGst3yM7Bea9FRURf1S42ZHlZZtsNque2FN2PoUhfZXYLNWwEr4dLQ== dependencies: - call-bind "^1.0.2" - define-properties "^1.1.4" - es-abstract "^1.20.4" + call-bind "^1.0.8" + call-bound "^1.0.2" + define-properties "^1.2.1" + es-object-atoms "^1.0.0" string.prototype.trimleft@^2.1.1: version "2.1.1" @@ -4353,22 +4932,14 @@ string.prototype.trimstart@^1.0.1: define-properties "^1.1.3" es-abstract "^1.17.5" -string.prototype.trimstart@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.4.tgz#b36399af4ab2999b4c9c648bd7a3fb2bb26feeed" - integrity sha512-jh6e984OBfvxS50tdY2nRZnoC5/mLFKOREQfw8t5yytkoUsJRNxvI/E39qu1sD0OtWI3OC0XgKSmcWwziwYuZw== - dependencies: - call-bind "^1.0.2" - define-properties "^1.1.3" - -string.prototype.trimstart@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.6.tgz#e90ab66aa8e4007d92ef591bbf3cd422c56bdcf4" - integrity sha512-omqjMDaY92pbn5HOX7f9IccLA+U1tA9GvtU4JrodiXFfYB7jPzzHpRzpglLAjtUV6bB557zwClJezTqnAiYnQA== +string.prototype.trimstart@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.8.tgz#7ee834dda8c7c17eff3118472bb35bfedaa34dde" + integrity sha512-UXSH262CSZY1tfu3G3Secr6uGLCFVPMhIqHjlgCUtCCcgihYc/xKs9djMTMUOb2j1mVSeU8EU6NWc/iQKU6Gfg== dependencies: - call-bind "^1.0.2" - define-properties "^1.1.4" - es-abstract "^1.20.4" + call-bind "^1.0.7" + define-properties "^1.2.1" + es-object-atoms "^1.0.0" stringz@2.1.0: version "2.1.0" @@ -4377,6 +4948,13 @@ stringz@2.1.0: dependencies: char-regex "^1.0.2" +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + strip-ansi@^6.0.0: version "6.0.0" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz" @@ -4384,12 +4962,12 @@ strip-ansi@^6.0.0: dependencies: ansi-regex "^5.0.0" -strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== +strip-ansi@^7.0.1: + version "7.1.2" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.2.tgz#132875abde678c7ea8d691533f2e7e22bb744dba" + integrity sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA== dependencies: - ansi-regex "^5.0.1" + ansi-regex "^6.0.1" strip-bom@^3.0.0: version "3.0.0" @@ -4408,23 +4986,11 @@ strip-indent@^3.0.0: dependencies: min-indent "^1.0.0" -strip-json-comments@3.1.1, strip-json-comments@^3.1.1: +strip-json-comments@^3.1.1: version "3.1.1" resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== -strip-json-comments@^3.1.0: - version "3.1.0" - resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.0.tgz" - integrity sha512-e6/d0eBu7gHtdCqFt0xJr642LdToM5/cN4Qb9DbHjVx1CP5RyeM+zH7pbecEmDv/lBqb0QH+6Uqq75rxFPkM0w== - -supports-color@8.1.1, supports-color@^8.0.0: - version "8.1.1" - resolved "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz" - integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== - dependencies: - has-flag "^4.0.0" - supports-color@^5.3.0: version "5.5.0" resolved "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz" @@ -4446,15 +5012,25 @@ supports-color@^7.2.0: dependencies: has-flag "^4.0.0" +supports-color@^8.0.0, supports-color@^8.1.1: + version "8.1.1" + resolved "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz" + integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== + dependencies: + has-flag "^4.0.0" + supports-preserve-symlinks-flag@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== -tapable@^2.1.1: - version "2.1.1" - resolved "https://registry.npmjs.org/tapable/-/tapable-2.1.1.tgz" - integrity sha512-Wib1S8m2wdpLbmQz0RBEVosIyvb/ykfKXf3ZIDqvWoMg/zTNm6G/tDSuUM61J1kNCDXWJrLHGSFeMhAG+gAGpQ== +synckit@^0.9.1: + version "0.9.3" + resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.9.3.tgz#1cfd60d9e61f931e07fb7f56f474b5eb31b826a7" + integrity sha512-JJoOEKTfL1urb1mDoEblhD9NhEbWmq9jHEMEnxoC4ujUaZ4itA8vKgwkFAyNClgxplLi9tsUKX+EduK0p/l7sg== + dependencies: + "@pkgr/core" "^0.1.0" + tslib "^2.6.2" tapable@^2.2.0: version "2.2.0" @@ -4466,37 +5042,32 @@ tapable@^2.2.1: resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ== -terser-webpack-plugin@^5.1.3: - version "5.1.3" - resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.1.3.tgz#30033e955ca28b55664f1e4b30a1347e61aa23af" - integrity sha512-cxGbMqr6+A2hrIB5ehFIF+F/iST5ZOxvOmy9zih9ySbP1C2oEWQSOUS+2SNBTjzx5xLKO4xnod9eywdfq1Nb9A== - dependencies: - jest-worker "^27.0.2" - p-limit "^3.1.0" - schema-utils "^3.0.0" - serialize-javascript "^5.0.1" - source-map "^0.6.1" - terser "^5.7.0" - -terser@5.16.3: - version "5.16.3" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.16.3.tgz#3266017a9b682edfe019b8ecddd2abaae7b39c6b" - integrity sha512-v8wWLaS/xt3nE9dgKEWhNUFP6q4kngO5B8eYFUuebsu7Dw/UNAnpUod6UHo04jSSkv8TzKHjZDSd7EXdDQAl8Q== - dependencies: - "@jridgewell/source-map" "^0.3.2" - acorn "^8.5.0" +tapable@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.3.0.tgz#7e3ea6d5ca31ba8e078b560f0d83ce9a14aa8be6" + integrity sha512-g9ljZiwki/LfxmQADO3dEY1CbpmXT5Hm2fJ+QaGKwSXUylMybePR7/67YW7jOrrvjEgL1Fmz5kzyAjWVWLlucg== + +terser-webpack-plugin@^5.3.11: + version "5.3.14" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.14.tgz#9031d48e57ab27567f02ace85c7d690db66c3e06" + integrity sha512-vkZjpUjb6OMS7dhV+tILUW6BhpDR7P2L/aQSAv+Uwk+m8KATX9EccViHTJR2qDtACKPIYndLGCyl3FMo+r2LMw== + dependencies: + "@jridgewell/trace-mapping" "^0.3.25" + jest-worker "^27.4.5" + schema-utils "^4.3.0" + serialize-javascript "^6.0.2" + terser "^5.31.1" + +terser@5.44.0, terser@^5.31.1: + version "5.44.0" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.44.0.tgz#ebefb8e5b8579d93111bfdfc39d2cf63879f4a82" + integrity sha512-nIVck8DK+GM/0Frwd+nIhZ84pR/BX7rmXMfYwyg+Sri5oGVE99/E3KvXqpC2xHFxyqXyGHTKBSioxxplrO4I4w== + dependencies: + "@jridgewell/source-map" "^0.3.3" + acorn "^8.15.0" commander "^2.20.0" source-map-support "~0.5.20" -terser@^5.7.0: - version "5.7.0" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.7.0.tgz#a761eeec206bc87b605ab13029876ead938ae693" - integrity sha512-HP5/9hp2UaZt5fYkuhNBR8YyRcT8juw8+uFbAme53iN9hblvKnLUTKkmwJG6ocWpIKf8UK4DoeWG4ty0J6S6/g== - dependencies: - commander "^2.20.0" - source-map "~0.7.2" - source-map-support "~0.5.19" - test-exclude@^6.0.0: version "6.0.0" resolved "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz" @@ -4530,11 +5101,6 @@ threads@1.7.0: dependencies: esm "^3.2.25" -to-fast-properties@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz" - integrity sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4= - to-regex-range@^5.0.1: version "5.0.1" resolved "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz" @@ -4542,20 +5108,26 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" -ts-loader@9.4.2: - version "9.4.2" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.4.2.tgz#80a45eee92dd5170b900b3d00abcfa14949aeb78" - integrity sha512-OmlC4WVmFv5I0PpaxYb+qGeGOdm5giHU7HwDDUjw59emP2UYMHy9fFSDcYgSNoH8sXcj4hGCSEhlDZ9ULeDraA== +ts-api-utils@^1.3.0: + version "1.4.3" + resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.4.3.tgz#bfc2215fe6528fecab2b0fba570a2e8a4263b064" + integrity sha512-i3eMG77UTMD0hZhgRS562pv83RC6ukSAC2GMNWc+9dieh/+jDM5u5YG+NHX6VNDRHQcHwmsTHctP9LhbC3WxVw== + +ts-loader@9.5.4: + version "9.5.4" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.5.4.tgz#44b571165c10fb5a90744aa5b7e119233c4f4585" + integrity sha512-nCz0rEwunlTZiy6rXFByQU1kVVpCIgUpc/psFiKVrUwrizdnIbRFu8w7bxhUF0X613DYwT4XzrZHpVyMe758hQ== dependencies: chalk "^4.1.0" enhanced-resolve "^5.0.0" micromatch "^4.0.0" semver "^7.3.4" + source-map "^0.7.4" -ts-node@10.9.1: - version "10.9.1" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b" - integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw== +ts-node@10.9.2: + version "10.9.2" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.2.tgz#70f021c9e185bccdca820e26dc413805c101c71f" + integrity sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ== dependencies: "@cspotcode/source-map-support" "^0.8.0" "@tsconfig/node10" "^1.0.7" @@ -4571,33 +5143,26 @@ ts-node@10.9.1: v8-compile-cache-lib "^3.0.1" yn "3.1.1" -tsconfig-paths@^3.14.1: - version "3.14.1" - resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz#ba0734599e8ea36c862798e920bcf163277b137a" - integrity sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ== +tsconfig-paths@^3.15.0: + version "3.15.0" + resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz#5299ec605e55b1abb23ec939ef15edaf483070d4" + integrity sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg== dependencies: "@types/json5" "^0.0.29" - json5 "^1.0.1" + json5 "^1.0.2" minimist "^1.2.6" strip-bom "^3.0.0" -tslib@2.5.0: - version "2.5.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" - integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== +tslib@2.8.1, tslib@^2.6.2: + version "2.8.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f" + integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w== -tslib@^1.8.1, tslib@^1.9.0: +tslib@^1.9.0: version "1.11.1" resolved "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz" integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA== -tsutils@^3.21.0: - version "3.21.0" - resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623" - integrity sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA== - dependencies: - tslib "^1.8.1" - type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz" @@ -4612,11 +5177,16 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" -type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.5, type-detect@^4.0.8: +type-detect@4.0.8, type-detect@^4.0.0: version "4.0.8" resolved "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz" integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== +type-detect@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.1.0.tgz#deb2453e8f08dcae7ae98c626b13dddb0155906c" + integrity sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw== + type-fest@^0.20.2: version "0.20.2" resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz" @@ -4632,14 +5202,50 @@ type-fest@^0.8.0, type-fest@^0.8.1: resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== -typed-array-length@^1.0.4: +typed-array-buffer@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/typed-array-buffer/-/typed-array-buffer-1.0.3.tgz#a72395450a4869ec033fd549371b47af3a2ee536" + integrity sha512-nAYYwfY3qnzX30IkA6AQZjVbtK6duGontcQm1WSG1MD94YLqK0515GNApXkoxKOWMusVssAHWLh9SeaoefYFGw== + dependencies: + call-bound "^1.0.3" + es-errors "^1.3.0" + is-typed-array "^1.1.14" + +typed-array-byte-length@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/typed-array-byte-length/-/typed-array-byte-length-1.0.3.tgz#8407a04f7d78684f3d252aa1a143d2b77b4160ce" + integrity sha512-BaXgOuIxz8n8pIq3e7Atg/7s+DpiYrxn4vdot3w9KbnBhcRQq6o3xemQdIfynqSeXeDrF32x+WvfzmOjPiY9lg== + dependencies: + call-bind "^1.0.8" + for-each "^0.3.3" + gopd "^1.2.0" + has-proto "^1.2.0" + is-typed-array "^1.1.14" + +typed-array-byte-offset@^1.0.4: version "1.0.4" - resolved "https://registry.yarnpkg.com/typed-array-length/-/typed-array-length-1.0.4.tgz#89d83785e5c4098bec72e08b319651f0eac9c1bb" - integrity sha512-KjZypGq+I/H7HI5HlOoGHkWUUGq+Q0TPhQurLbyrVrvnKTBgzLhIJ7j6J/XTQOi0d1RjyZ0wdas8bKs2p0x3Ng== + resolved "https://registry.yarnpkg.com/typed-array-byte-offset/-/typed-array-byte-offset-1.0.4.tgz#ae3698b8ec91a8ab945016108aef00d5bff12355" + integrity sha512-bTlAFB/FBYMcuX81gbL4OcpH5PmlFHqlCCpAl8AlEzMz5k53oNDvN8p1PNOWLEmI2x4orp3raOFB51tv9X+MFQ== dependencies: - call-bind "^1.0.2" + available-typed-arrays "^1.0.7" + call-bind "^1.0.8" + for-each "^0.3.3" + gopd "^1.2.0" + has-proto "^1.2.0" + is-typed-array "^1.1.15" + reflect.getprototypeof "^1.0.9" + +typed-array-length@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/typed-array-length/-/typed-array-length-1.0.7.tgz#ee4deff984b64be1e118b0de8c9c877d5ce73d3d" + integrity sha512-3KS2b+kL7fsuk/eJZ7EQdnEmQoaho/r6KUef7hxvltNA5DR8NAUM+8wJMbJyZ4G9/7i3v5zPBIMN5aybAh2/Jg== + dependencies: + call-bind "^1.0.7" for-each "^0.3.3" - is-typed-array "^1.1.9" + gopd "^1.0.1" + is-typed-array "^1.1.13" + possible-typed-array-names "^1.0.0" + reflect.getprototypeof "^1.0.6" typedarray-to-buffer@^3.1.5: version "3.1.5" @@ -4648,30 +5254,25 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@4.9.5: - version "4.9.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" - integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== - -unbox-primitive@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471" - integrity sha512-tZU/3NqK3dA5gpE1KtyiJUrEB0lxnGkMFHptJ7q6ewdZ8s12QrODwNbhIJStmJkd1QDXa1NRA8aF2A1zk/Ypyw== - dependencies: - function-bind "^1.1.1" - has-bigints "^1.0.1" - has-symbols "^1.0.2" - which-boxed-primitive "^1.0.2" +typescript@5.9.3: + version "5.9.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.9.3.tgz#5b4f59e15310ab17a216f5d6cf53ee476ede670f" + integrity sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw== -unbox-primitive@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.2.tgz#29032021057d5e6cdbd08c5129c226dff8ed6f9e" - integrity sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw== +unbox-primitive@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.1.0.tgz#8d9d2c9edeea8460c7f35033a88867944934d1e2" + integrity sha512-nWJ91DjeOkej/TA8pXQ3myruKpKEYgqvpw9lz4OPHj/NWFNluYrjbz9j01CJ8yKQd2g4jFoOkINCTW2I5LEEyw== dependencies: - call-bind "^1.0.2" + call-bound "^1.0.3" has-bigints "^1.0.2" - has-symbols "^1.0.3" - which-boxed-primitive "^1.0.2" + has-symbols "^1.1.0" + which-boxed-primitive "^1.1.1" + +undici-types@~6.20.0: + version "6.20.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.20.0.tgz#8171bf22c1f588d1554d55bf204bc624af388433" + integrity sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg== universalify@^1.0.0: version "1.0.0" @@ -4683,6 +5284,14 @@ universalify@^2.0.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== +update-browserslist-db@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.1.4.tgz#7802aa2ae91477f255b86e0e46dbc787a206ad4a" + integrity sha512-q0SPT4xyU84saUX+tomz1WLkxUbuaJnR1xWt17M7fJtEJigJeWUNGUqrauFXsHnqev9y9JTRGwk13tFBuKby4A== + dependencies: + escalade "^3.2.0" + picocolors "^1.1.1" + uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" @@ -4690,16 +5299,15 @@ uri-js@^4.2.2: dependencies: punycode "^2.1.0" -util@^0.12.0: - version "0.12.3" - resolved "https://registry.npmjs.org/util/-/util-0.12.3.tgz" - integrity sha512-I8XkoQwE+fPQEhy9v012V+TSdH2kp9ts29i20TaaDUXsg7x/onePbhFJUExBfv/2ay1ZOp/Vsm3nDlmnFGSAog== +util@^0.12.5: + version "0.12.5" + resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc" + integrity sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA== dependencies: inherits "^2.0.3" is-arguments "^1.0.4" is-generator-function "^1.0.7" is-typed-array "^1.1.3" - safe-buffer "^5.1.2" which-typed-array "^1.1.2" uuid@^3.3.3: @@ -4707,7 +5315,7 @@ uuid@^3.3.3: resolved "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^8.3.0: +uuid@^8.3.2: version "8.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== @@ -4725,102 +5333,146 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -validator@^13.7.0: - version "13.7.0" - resolved "https://registry.yarnpkg.com/validator/-/validator-13.7.0.tgz#4f9658ba13ba8f3d82ee881d3516489ea85c0857" - integrity sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw== +validator@^13.9.0: + version "13.15.20" + resolved "https://registry.yarnpkg.com/validator/-/validator-13.15.20.tgz#054e9238109538a1bf46ae3e1290845a64fa2186" + integrity sha512-KxPOq3V2LmfQPP4eqf3Mq/zrT0Dqp2Vmx2Bn285LwVahLc+CsxOM0crBHczm8ijlcjZ0Q5Xd6LW3z3odTPnlrw== -watchpack@^2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.4.0.tgz#fa33032374962c78113f93c7f2fb4c54c9862a5d" - integrity sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg== +watchpack@^2.4.4: + version "2.4.4" + resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.4.4.tgz#473bda72f0850453da6425081ea46fc0d7602947" + integrity sha512-c5EGNOiyxxV5qmTtAB7rbiXxi1ooX1pQKMLX/MIabJjRA0SJBQOjKF+KSVfHkr9U1cADPon0mRiVe/riyaiDUA== dependencies: glob-to-regexp "^0.4.1" graceful-fs "^4.1.2" -webpack-cli@5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-5.0.1.tgz#95fc0495ac4065e9423a722dec9175560b6f2d9a" - integrity sha512-S3KVAyfwUqr0Mo/ur3NzIp6jnerNpo7GUO6so51mxLi1spqsA17YcMXy0WOIJtBSnj748lthxC6XLbNKh/ZC+A== +webpack-cli@6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-6.0.1.tgz#a1ce25da5ba077151afd73adfa12e208e5089207" + integrity sha512-MfwFQ6SfwinsUVi0rNJm7rHZ31GyTcpVE5pgVA3hwFRb7COD4TzjUUwhGWKfO50+xdc2MQPuEBBJoqIMGt3JDw== dependencies: - "@discoveryjs/json-ext" "^0.5.0" - "@webpack-cli/configtest" "^2.0.1" - "@webpack-cli/info" "^2.0.1" - "@webpack-cli/serve" "^2.0.1" + "@discoveryjs/json-ext" "^0.6.1" + "@webpack-cli/configtest" "^3.0.1" + "@webpack-cli/info" "^3.0.1" + "@webpack-cli/serve" "^3.0.1" colorette "^2.0.14" - commander "^9.4.1" + commander "^12.1.0" cross-spawn "^7.0.3" - envinfo "^7.7.3" + envinfo "^7.14.0" fastest-levenshtein "^1.0.12" import-local "^3.0.2" interpret "^3.1.1" rechoir "^0.8.0" - webpack-merge "^5.7.3" + webpack-merge "^6.0.1" -webpack-merge@^5.7.3: - version "5.7.3" - resolved "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.7.3.tgz" - integrity sha512-6/JUQv0ELQ1igjGDzHkXbVDRxkfA57Zw7PfiupdLFJYrgFqY5ZP8xxbpp2lU3EPwYx89ht5Z/aDkD40hFCm5AA== +webpack-merge@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-6.0.1.tgz#50c776868e080574725abc5869bd6e4ef0a16c6a" + integrity sha512-hXXvrjtx2PLYx4qruKl+kyRSLc52V+cCvMxRjmKwoA+CBbbF5GfIBtR6kCvl0fYGqTUPKB+1ktVmTHqMOzgCBg== dependencies: clone-deep "^4.0.1" - wildcard "^2.0.0" + flat "^5.0.2" + wildcard "^2.0.1" webpack-node-externals@3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz#1a3407c158d547a9feb4229a9e3385b7b60c9917" integrity sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ== -webpack-sources@^3.2.3: - version "3.2.3" - resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" - integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== - -webpack@5.75.0: - version "5.75.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.75.0.tgz#1e440468647b2505860e94c9ff3e44d5b582c152" - integrity sha512-piaIaoVJlqMsPtX/+3KTTO6jfvrSYgauFVdt8cr9LTHKmcq/AMd4mhzsiP7ZF/PGRNPGA8336jldh9l2Kt2ogQ== - dependencies: - "@types/eslint-scope" "^3.7.3" - "@types/estree" "^0.0.51" - "@webassemblyjs/ast" "1.11.1" - "@webassemblyjs/wasm-edit" "1.11.1" - "@webassemblyjs/wasm-parser" "1.11.1" - acorn "^8.7.1" - acorn-import-assertions "^1.7.6" - browserslist "^4.14.5" +webpack-sources@^3.3.3: + version "3.3.3" + resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.3.3.tgz#d4bf7f9909675d7a070ff14d0ef2a4f3c982c723" + integrity sha512-yd1RBzSGanHkitROoPFd6qsrxt+oFhg/129YzheDGqeustzX0vTZJZsSsQjVQC4yzBQ56K55XU8gaNCtIzOnTg== + +webpack@5.102.1: + version "5.102.1" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.102.1.tgz#1003a3024741a96ba99c37431938bf61aad3d988" + integrity sha512-7h/weGm9d/ywQ6qzJ+Xy+r9n/3qgp/thalBbpOi5i223dPXKi04IBtqPN9nTd+jBc7QKfvDbaBnFipYp4sJAUQ== + dependencies: + "@types/eslint-scope" "^3.7.7" + "@types/estree" "^1.0.8" + "@types/json-schema" "^7.0.15" + "@webassemblyjs/ast" "^1.14.1" + "@webassemblyjs/wasm-edit" "^1.14.1" + "@webassemblyjs/wasm-parser" "^1.14.1" + acorn "^8.15.0" + acorn-import-phases "^1.0.3" + browserslist "^4.26.3" chrome-trace-event "^1.0.2" - enhanced-resolve "^5.10.0" - es-module-lexer "^0.9.0" + enhanced-resolve "^5.17.3" + es-module-lexer "^1.2.1" eslint-scope "5.1.1" events "^3.2.0" glob-to-regexp "^0.4.1" - graceful-fs "^4.2.9" + graceful-fs "^4.2.11" json-parse-even-better-errors "^2.3.1" loader-runner "^4.2.0" mime-types "^2.1.27" neo-async "^2.6.2" - schema-utils "^3.1.0" - tapable "^2.1.1" - terser-webpack-plugin "^5.1.3" - watchpack "^2.4.0" - webpack-sources "^3.2.3" + schema-utils "^4.3.3" + tapable "^2.3.0" + terser-webpack-plugin "^5.3.11" + watchpack "^2.4.4" + webpack-sources "^3.3.3" + +which-boxed-primitive@^1.1.0, which-boxed-primitive@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.1.1.tgz#d76ec27df7fa165f18d5808374a5fe23c29b176e" + integrity sha512-TbX3mj8n0odCBFVlY8AxkqcHASw3L60jIuF8jFP78az3C2YhmGvqbHBpAjTRH2/xqYunrJ9g1jSyjCjpoWzIAA== + dependencies: + is-bigint "^1.1.0" + is-boolean-object "^1.2.1" + is-number-object "^1.1.1" + is-string "^1.1.1" + is-symbol "^1.1.1" + +which-builtin-type@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/which-builtin-type/-/which-builtin-type-1.2.1.tgz#89183da1b4907ab089a6b02029cc5d8d6574270e" + integrity sha512-6iBczoX+kDQ7a3+YJBnh3T+KZRxM/iYNPXicqk66/Qfm1b93iu+yOImkg0zHbj5LNOcNv1TEADiZ0xa34B4q6Q== + dependencies: + call-bound "^1.0.2" + function.prototype.name "^1.1.6" + has-tostringtag "^1.0.2" + is-async-function "^2.0.0" + is-date-object "^1.1.0" + is-finalizationregistry "^1.1.0" + is-generator-function "^1.0.10" + is-regex "^1.2.1" + is-weakref "^1.0.2" + isarray "^2.0.5" + which-boxed-primitive "^1.1.0" + which-collection "^1.0.2" + which-typed-array "^1.1.16" -which-boxed-primitive@^1.0.2: +which-collection@^1.0.2: version "1.0.2" - resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6" - integrity sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg== + resolved "https://registry.yarnpkg.com/which-collection/-/which-collection-1.0.2.tgz#627ef76243920a107e7ce8e96191debe4b16c2a0" + integrity sha512-K4jVyjnBdgvc86Y6BkaLZEN933SwYOuBFkdmBu9ZfkcAbdVbpITnDmjvZ/aQjRXQrv5EPkTnD1s39GiiqbngCw== dependencies: - is-bigint "^1.0.1" - is-boolean-object "^1.1.0" - is-number-object "^1.0.4" - is-string "^1.0.5" - is-symbol "^1.0.3" + is-map "^2.0.3" + is-set "^2.0.3" + is-weakmap "^2.0.2" + is-weakset "^2.0.3" which-module@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz" integrity sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho= +which-typed-array@^1.1.16, which-typed-array@^1.1.19: + version "1.1.19" + resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.19.tgz#df03842e870b6b88e117524a4b364b6fc689f956" + integrity sha512-rEvr90Bck4WZt9HHFC4DJMsjvu7x+r6bImz0/BrbWb7A2djJ8hnZMrWnHo9F8ssv0OMErasDhftrfROTyqSDrw== + dependencies: + available-typed-arrays "^1.0.7" + call-bind "^1.0.8" + call-bound "^1.0.4" + for-each "^0.3.5" + get-proto "^1.0.1" + gopd "^1.2.0" + has-tostringtag "^1.0.2" + which-typed-array@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.2.tgz" @@ -4833,18 +5485,6 @@ which-typed-array@^1.1.2: has-symbols "^1.0.1" is-typed-array "^1.1.3" -which-typed-array@^1.1.9: - version "1.1.9" - resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.9.tgz#307cf898025848cf995e795e8423c7f337efbde6" - integrity sha512-w9c4xkx6mPidwp7180ckYWfMmvxpjlZuIudNtDf4N/tTAUB8VJbX25qZoAsrtGuYNnGw3pa0AXgbGKRB8/EceA== - dependencies: - available-typed-arrays "^1.0.5" - call-bind "^1.0.2" - for-each "^0.3.3" - gopd "^1.0.1" - has-tostringtag "^1.0.0" - is-typed-array "^1.1.10" - which@^2.0.1, which@^2.0.2: version "2.0.2" resolved "https://registry.npmjs.org/which/-/which-2.0.2.tgz" @@ -4852,20 +5492,34 @@ which@^2.0.1, which@^2.0.2: dependencies: isexe "^2.0.0" -wildcard@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/wildcard/-/wildcard-2.0.0.tgz" - integrity sha512-JcKqAHLPxcdb9KM49dufGXn2x3ssnfjbcaQdLlfZsL9rH9wgDQjUtDxbo8NE0F6SFvydeu1VhZe7hZuHsB2/pw== +wildcard@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/wildcard/-/wildcard-2.0.1.tgz#5ab10d02487198954836b6349f74fff961e10f67" + integrity sha512-CC1bOL87PIWSBhDcTrdeLo6eGT7mCFtrg0uIJtqJUFyK+eJnzl8A1niH56uu7KMa5XFrtiV+AQuHO3n7DsHnLQ== -word-wrap@^1.2.3, word-wrap@~1.2.3: +word-wrap@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" + integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== + +word-wrap@~1.2.3: version "1.2.3" resolved "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== -workerpool@6.2.1: - version "6.2.1" - resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343" - integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== +workerpool@^9.2.0: + version "9.3.4" + resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-9.3.4.tgz#f6c92395b2141afd78e2a889e80cb338fe9fca41" + integrity sha512-TmPRQYYSAnnDiEB0P/Ytip7bFGvqnSU6I2BcuSw7Hx+JSg/DsUi5ebYfc8GYaSdpuvOcEs6dXxPurOYpe9QFwg== + +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" wrap-ansi@^6.2.0: version "6.2.0" @@ -4885,6 +5539,15 @@ wrap-ansi@^7.0.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" + integrity sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ== + dependencies: + ansi-styles "^6.1.0" + string-width "^5.0.1" + strip-ansi "^7.0.1" + wrappy@1: version "1.0.2" resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" @@ -4910,26 +5573,16 @@ y18n@^5.0.5: resolved "https://registry.npmjs.org/y18n/-/y18n-5.0.5.tgz" integrity sha512-hsRUr4FFrvhhRH12wOdfs38Gy7k2FFzB9qgN9v3aLykRq0dRcdcpz5C9FxdS2NuhOrI/628b/KSTJ3rwHysYSg== -yallist@^2.1.2: - version "2.1.2" - resolved "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz" - integrity sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI= +yallist@^3.0.2: + version "3.1.1" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" + integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== yallist@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz" integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== -yaml@^1.10.0: - version "1.10.2" - resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b" - integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg== - -yargs-parser@20.2.4: - version "20.2.4" - resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz" - integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA== - yargs-parser@^18.1.1: version "18.1.3" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0" @@ -4938,14 +5591,14 @@ yargs-parser@^18.1.1: camelcase "^5.0.0" decamelize "^1.2.0" -yargs-parser@^20.2.2: - version "20.2.5" - resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.5.tgz" - integrity sha512-jYRGS3zWy20NtDtK2kBgo/TlAoy5YUuhD9/LZ7z7W4j1Fdw2cqD0xEEclf8fxc8xjD6X5Qr+qQQwCEsP8iRiYg== +yargs-parser@^21.1.1: + version "21.1.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35" + integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw== -yargs-unparser@2.0.0: +yargs-unparser@^2.0.0: version "2.0.0" - resolved "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz" + resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz#f131f9226911ae5d9ad38c432fe809366c2325eb" integrity sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA== dependencies: camelcase "^6.0.0" @@ -4953,19 +5606,6 @@ yargs-unparser@2.0.0: flat "^5.0.2" is-plain-obj "^2.1.0" -yargs@16.2.0: - version "16.2.0" - resolved "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz" - integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== - dependencies: - cliui "^7.0.2" - escalade "^3.1.1" - get-caller-file "^2.0.5" - require-directory "^2.1.1" - string-width "^4.2.0" - y18n "^5.0.5" - yargs-parser "^20.2.2" - yargs@^15.0.2: version "15.3.1" resolved "https://registry.npmjs.org/yargs/-/yargs-15.3.1.tgz" @@ -4983,12 +5623,20 @@ yargs@^15.0.2: y18n "^4.0.0" yargs-parser "^18.1.1" +yargs@^17.7.2: + version "17.7.2" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269" + integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w== + dependencies: + cliui "^8.0.1" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.3" + y18n "^5.0.5" + yargs-parser "^21.1.1" + yn@3.1.1: version "3.1.1" resolved "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz" integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== - -yocto-queue@^0.1.0: - version "0.1.0" - resolved "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz" - integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== From 6640907504a35a0962733fb37569e0667f47f717 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sat, 29 Nov 2025 21:40:32 +0400 Subject: [PATCH 12/87] Speedup ObjectExpressionKeysTransformer.ts (#1331) --- CHANGELOG.md | 6 ++++ package.json | 4 +-- .../ObjectExpressionKeysTransformer.ts | 8 ++++-- .../BasePropertiesExtractor.ts | 6 +++- yarn.lock | 28 +++++++++---------- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f2a55c88..78f4a67c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ Change Log +v4.1.2 +--- +* Fix `transformObjectKeys` performance in some edge-cases +* Update `class-validator` version. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1324 +* Update other dependencies + v4.1.1 --- * Update supported Node.js versions up to `node@22`. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/pull/1100 diff --git a/package.json b/package.json index c7d7dc0c0..666183d5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "4.1.1", + "version": "4.1.2", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", @@ -27,7 +27,7 @@ "assert": "2.1.0", "chalk": "4.1.2", "chance": "1.1.13", - "class-validator": "0.14.2", + "class-validator": "0.14.3", "commander": "12.1.0", "eslint-scope": "8.4.0", "eslint-visitor-keys": "4.2.1", diff --git a/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts b/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts index 312d5ee6a..20efc1d37 100644 --- a/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts +++ b/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts @@ -102,7 +102,7 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { objectExpressionNode: ESTree.ObjectExpression, objectExpressionHostNode: ESTree.Node, ): boolean { - const identifierNamesSet: string[] = []; + const identifierNamesSet: Set = new Set(); let isReferencedIdentifierName: boolean = false; let isCurrentNode: boolean = false; @@ -119,17 +119,19 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { } if (!isCurrentNode) { - identifierNamesSet.push(ObjectExpressionKeysTransformer.getReferencedIdentifierName(node)); + identifierNamesSet.add(ObjectExpressionKeysTransformer.getReferencedIdentifierName(node)); return; } - const hasReferencedIdentifierName: boolean = identifierNamesSet.includes( + const hasReferencedIdentifierName: boolean = identifierNamesSet.has( ObjectExpressionKeysTransformer.getReferencedIdentifierName(node) ); if (hasReferencedIdentifierName) { isReferencedIdentifierName = true; + + return estraverse.VisitorOption.Break; } }, leave: (node: ESTree.Node): void | estraverse.VisitorOption => { diff --git a/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts b/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts index 49575ddf8..ee45587a2 100644 --- a/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts +++ b/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts @@ -128,7 +128,11 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { this.filterExtractedObjectExpressionProperties(objectExpressionNode, removablePropertyIds); NodeAppender.insertAfter(hostNodeWithStatements, expressionStatements, hostStatement); - NodeUtils.parentizeAst(hostNodeWithStatements); + // Only parentize the newly inserted statements, not the entire scope + expressionStatements.forEach((statement) => { + NodeUtils.parentizeAst(statement); + NodeUtils.parentizeNode(statement, hostNodeWithStatements); + }); return { nodeToReplace: objectExpressionNode, diff --git a/yarn.lock b/yarn.lock index 59a16797f..d2fddd2f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -749,10 +749,10 @@ resolved "https://registry.yarnpkg.com/@types/string-template/-/string-template-1.0.7.tgz#593fd97fd7515ae6eba80a142738daadc961c895" integrity sha512-sQWEsTbB0pKCc1eAC9mwTKftyXuWfSZVfDTskhlQLE/xTtuevqOlFG/t4Djf/VFbRdt7PROaovoqpWfZWhMRfA== -"@types/validator@^13.11.8": - version "13.15.4" - resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.15.4.tgz#38a97ae54747416f745afdfc678f041713082635" - integrity sha512-LSFfpSnJJY9wbC0LQxgvfb+ynbHftFo0tMsFOl/J4wexLnYMmDSPaj2ZyDv3TkfL1UePxPrxOWJfbiRS8mQv7A== +"@types/validator@^13.15.3": + version "13.15.10" + resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.15.10.tgz#742b77ec34d58554b94a76a14cef30d59e3c16b9" + integrity sha512-T8L6i7wCuyoK8A/ZeLYt1+q0ty3Zb9+qbSSvrIVitzT3YjZqkTZ40IbRsPanlB4h1QB3JVL1SYCdR6ngtFYcuA== "@types/webpack-env@1.18.8": version "1.18.8" @@ -1520,14 +1520,14 @@ ci-info@^4.0.0: resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-4.3.1.tgz#355ad571920810b5623e11d40232f443f16f1daa" integrity sha512-Wdy2Igu8OcBpI2pZePZ5oWjPC38tmDVx5WKUXKwlLYkA0ozo85sLsLvkBbBn/sZaSCMFOGZJ14fvW9t5/d7kdA== -class-validator@0.14.2: - version "0.14.2" - resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.14.2.tgz#a3de95edd26b703e89c151a2023d3c115030340d" - integrity sha512-3kMVRF2io8N8pY1IFIXlho9r8IPUUIfHe2hYVtiebvAzU2XeQFXTv+XI4WX+TnXmtwXMDcjngcpkiPM0O9PvLw== +class-validator@0.14.3: + version "0.14.3" + resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.14.3.tgz#834a4caafa8359aed73d7708badb4cf271be50fe" + integrity sha512-rXXekcjofVN1LTOSw+u4u9WXVEUvNBVjORW154q/IdmYWy1nMbOU9aNtZB0t8m+FJQ9q91jlr2f9CwwUFdFMRA== dependencies: - "@types/validator" "^13.11.8" + "@types/validator" "^13.15.3" libphonenumber-js "^1.11.1" - validator "^13.9.0" + validator "^13.15.20" clean-regexp@^1.0.0: version "1.0.0" @@ -5333,10 +5333,10 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -validator@^13.9.0: - version "13.15.20" - resolved "https://registry.yarnpkg.com/validator/-/validator-13.15.20.tgz#054e9238109538a1bf46ae3e1290845a64fa2186" - integrity sha512-KxPOq3V2LmfQPP4eqf3Mq/zrT0Dqp2Vmx2Bn285LwVahLc+CsxOM0crBHczm8ijlcjZ0Q5Xd6LW3z3odTPnlrw== +validator@^13.15.20: + version "13.15.23" + resolved "https://registry.yarnpkg.com/validator/-/validator-13.15.23.tgz#59a874f84e4594588e3409ab1edbe64e96d0c62d" + integrity sha512-4yoz1kEWqUjzi5zsPbAS/903QXSYp0UOtHsPpp7p9rHAw/W+dkInskAE386Fat3oKRROwO98d9ZB0G4cObgUyw== watchpack@^2.4.4: version "2.4.4" From 64edd44d68c76cd14dbf2829e9b2ff48f38a7700 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sun, 30 Nov 2025 00:39:32 +0400 Subject: [PATCH 13/87] Revert 5683e75 (#1332) --- CHANGELOG.md | 1 + ...StringArrayCallsWrapperBase64CodeHelper.ts | 2 +- .../StringArrayCallsWrapperCodeHelper.ts | 1 - .../StringArrayCallsWrapperRc4CodeHelper.ts | 2 +- .../StringArrayBase64DecodeTemplate.ts | 7 +++--- .../StringArrayCallsWrapperTemplate.ts | 22 ++++++------------- .../StringArrayRC4DecodeTemplate.ts | 7 +++--- .../StringArrayCallsWrapperCodeHelper.spec.ts | 7 +++--- 8 files changed, 21 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78f4a67c1..140f80acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Change Log v4.1.2 --- * Fix `transformObjectKeys` performance in some edge-cases +* Revert `Improved stringArray calls wrapper templates` commit. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1330 * Update `class-validator` version. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1324 * Update other dependencies diff --git a/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts index 80afd3e43..43f60033d 100644 --- a/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts @@ -29,7 +29,7 @@ export class StringArrayCallsWrapperBase64CodeHelper extends StringArrayCallsWra atobFunctionName, selfDefendingCode, stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, - stringArrayCacheName: this.stringArrayCacheName + stringArrayFunctionName: this.stringArrayFunctionName } ); } diff --git a/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts index 5d684915f..e599643dd 100644 --- a/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts @@ -114,7 +114,6 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper this.customCodeHelperFormatter.formatTemplate(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate, stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, - stringArrayCacheName: this.stringArrayCacheName, stringArrayFunctionName: this.stringArrayFunctionName, indexShiftAmount: this.indexShiftAmount }), diff --git a/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts index c1ce13a8d..48074fc00 100644 --- a/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts @@ -39,7 +39,7 @@ export class StringArrayCallsWrapperRc4CodeHelper extends StringArrayCallsWrappe rc4Polyfill, selfDefendingCode, stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, - stringArrayCacheName: this.stringArrayCacheName + stringArrayFunctionName: this.stringArrayFunctionName } ); } diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts index df56184c8..b1b0a4f89 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts @@ -11,26 +11,27 @@ export function StringArrayBase64DecodeTemplate ( const identifierLength: number = 6; const initializedIdentifier: string = randomGenerator.getRandomString(identifierLength); const base64Identifier: string = randomGenerator.getRandomString(identifierLength); + const dataIdentifier: string = randomGenerator.getRandomString(identifierLength); return ` if ({stringArrayCallsWrapperName}.${initializedIdentifier} === undefined) { {atobPolyfill} {stringArrayCallsWrapperName}.${base64Identifier} = {atobFunctionName}; - {stringArrayCacheName} = arguments; + {stringArrayCallsWrapperName}.${dataIdentifier} = {}; {stringArrayCallsWrapperName}.${initializedIdentifier} = true; } const firstValue = stringArray[0]; const cacheKey = index + firstValue; - const cachedValue = {stringArrayCacheName}[cacheKey]; + const cachedValue = {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey]; if (!cachedValue) { {selfDefendingCode} value = {stringArrayCallsWrapperName}.${base64Identifier}(value); - {stringArrayCacheName}[cacheKey] = value; + {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey] = value; } else { value = cachedValue; } diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts index 9ef2e4f79..c7dcaca94 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts @@ -1,25 +1,17 @@ /** - * The first parameter of the outer stringArrayCallsWrapperName function will be used as an initial index - * and later as a cache variable that will be captured by the inner function - * * @returns {string} */ export function StringArrayCallsWrapperTemplate (): string { return ` - function {stringArrayCallsWrapperName} ({stringArrayCacheName}, key) { + function {stringArrayCallsWrapperName} (index, key) { + index = index - {indexShiftAmount}; + const stringArray = {stringArrayFunctionName}(); - - {stringArrayCallsWrapperName} = function (index, key) { - index = index - {indexShiftAmount}; + let value = stringArray[index]; - let value = stringArray[index]; - - {decodeCodeHelperTemplate} - - return value; - }; - - return {stringArrayCallsWrapperName}({stringArrayCacheName}, key); + {decodeCodeHelperTemplate} + + return value; } `; } diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts index 0459e8fe1..4a8bcbf68 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts @@ -11,6 +11,7 @@ export function StringArrayRC4DecodeTemplate ( const identifierLength: number = 6; const initializedIdentifier: string = randomGenerator.getRandomString(identifierLength); const rc4Identifier: string = randomGenerator.getRandomString(identifierLength); + const dataIdentifier: string = randomGenerator.getRandomString(identifierLength); const onceIdentifier: string = randomGenerator.getRandomString(identifierLength); return ` @@ -19,14 +20,14 @@ export function StringArrayRC4DecodeTemplate ( {rc4Polyfill} {stringArrayCallsWrapperName}.${rc4Identifier} = {rc4FunctionName}; - {stringArrayCacheName} = arguments; + {stringArrayCallsWrapperName}.${dataIdentifier} = {}; {stringArrayCallsWrapperName}.${initializedIdentifier} = true; } const firstValue = stringArray[0]; const cacheKey = index + firstValue; - const cachedValue = {stringArrayCacheName}[cacheKey]; + const cachedValue = {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey]; if (!cachedValue) { if ({stringArrayCallsWrapperName}.${onceIdentifier} === undefined) { @@ -36,7 +37,7 @@ export function StringArrayRC4DecodeTemplate ( } value = {stringArrayCallsWrapperName}.${rc4Identifier}(value, key); - {stringArrayCacheName}[cacheKey] = value; + {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey] = value; } else { value = cachedValue; } diff --git a/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts b/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts index f537f85b3..b5efc053c 100644 --- a/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts +++ b/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts @@ -97,10 +97,9 @@ describe('StringArrayCallsWrapperCodeHelper', () => { describe('Preserve string array name', () => { const callsWrapperRegExp: RegExp = new RegExp(`` + `function *b *\\(c, *d\\) *{ *` + - `var e *= *a\\(\\); *` + - `b *= *function *\\(f, *g\\) *{` + - `f *= *f *- *0x0; *` + - `var h *= *e\\[f]; *` + + `c *= *c *- *0x0; *` + + `var e *= *a *\\(\\);` + + `var f *= *e\\[c]; *` + ``); let obfuscatedCode: string; From bb9b33fb155c8687a3f71ee9f7b5f076ecb19d8e Mon Sep 17 00:00:00 2001 From: Fern Lane Date: Sat, 29 Nov 2025 23:52:27 +0300 Subject: [PATCH 14/87] fix: .mjs and .cjs in availableInputExtensions (#1301) --- src/cli/JavaScriptObfuscatorCLI.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cli/JavaScriptObfuscatorCLI.ts b/src/cli/JavaScriptObfuscatorCLI.ts index 2a10bd115..8a7621d4c 100644 --- a/src/cli/JavaScriptObfuscatorCLI.ts +++ b/src/cli/JavaScriptObfuscatorCLI.ts @@ -40,7 +40,9 @@ export class JavaScriptObfuscatorCLI implements IInitializable { * @type {string[]} */ public static readonly availableInputExtensions: string[] = [ - '.js' + '.js', + '.mjs', + '.cjs' ]; /** From 145746c8674b219639140f153a8097c207c3fd59 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Sun, 30 Nov 2025 00:55:18 +0400 Subject: [PATCH 15/87] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 140f80acf..c0f281641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ v4.1.2 * Revert `Improved stringArray calls wrapper templates` commit. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1330 * Update `class-validator` version. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1324 * Update other dependencies +* CLI: support `.mjs` and `.cjs` extensions. Kudos to https://github.com/javascript-obfuscator/javascript-obfuscator/pull/1301 v4.1.1 --- From 301b049c99aed4cf607e295688beec5d08322d15 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sun, 30 Nov 2025 01:25:47 +0400 Subject: [PATCH 16/87] Don't publish root index.ts files to NPM as we have typings (#1333) --- .npmignore | 2 ++ CHANGELOG.md | 1 + 2 files changed, 3 insertions(+) diff --git a/.npmignore b/.npmignore index d202d73b5..e7fb7148d 100644 --- a/.npmignore +++ b/.npmignore @@ -10,3 +10,5 @@ /src/ /test/ /test*.js +index.ts +index.cli.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index c0f281641..19305ca74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ v4.1.2 --- * Fix `transformObjectKeys` performance in some edge-cases * Revert `Improved stringArray calls wrapper templates` commit. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1330 +* Don't publish root index.ts files to NPM. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1252 * Update `class-validator` version. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1324 * Update other dependencies * CLI: support `.mjs` and `.cjs` extensions. Kudos to https://github.com/javascript-obfuscator/javascript-obfuscator/pull/1301 From b36951af3750245fa91849183718ec1890501530 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sun, 30 Nov 2025 01:53:25 +0400 Subject: [PATCH 17/87] Fix control flow flattening + optional chaining compatibility (#1334) --- CHANGELOG.md | 1 + .../CallExpressionFunctionNode.ts | 24 ++++++++++--- .../CallExpressionControlFlowReplacer.ts | 6 ++-- src/node/NodeFactory.ts | 14 ++++++++ src/node/NodeGuards.ts | 8 +++++ .../CallExpressionControlFlowReplacer.spec.ts | 36 ++++++++++++++++++- .../fixtures/optional-chaining-call.js | 5 +++ 7 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/optional-chaining-call.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 19305ca74..a4bbce6ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Change Log v4.1.2 --- * Fix `transformObjectKeys` performance in some edge-cases +* Fix `controlFlowFlattening` + optional chaining compatibility. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1325 * Revert `Improved stringArray calls wrapper templates` commit. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1330 * Don't publish root index.ts files to NPM. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1252 * Update `class-validator` version. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1324 diff --git a/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts b/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts index 1c4fd44e9..88f34b03f 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts @@ -25,6 +25,13 @@ export class CallExpressionFunctionNode extends AbstractCustomNode { @initializable() private expressionArguments!: (ESTree.Expression | ESTree.SpreadElement)[]; + /** + * @type {boolean} + * @private + */ + @initializable() + private isChainExpressionParent!: boolean; + /** * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory * @param {ICustomCodeHelperFormatter} customCodeHelperFormatter @@ -48,9 +55,11 @@ export class CallExpressionFunctionNode extends AbstractCustomNode { /** * @param {(Expression | SpreadElement)[]} expressionArguments + * @param {boolean} isChainExpressionParent */ - public initialize (expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[]): void { + public initialize (expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[], isChainExpressionParent: boolean): void { this.expressionArguments = expressionArguments; + this.isChainExpressionParent = isChainExpressionParent; } /** @@ -82,6 +91,12 @@ export class CallExpressionFunctionNode extends AbstractCustomNode { } } + const callExpression = NodeFactory.callExpressionNode( + calleeIdentifier, + callArguments, + this.isChainExpressionParent + ); + const structure: TStatement = NodeFactory.expressionStatementNode( NodeFactory.functionExpressionNode( [ @@ -90,10 +105,9 @@ export class CallExpressionFunctionNode extends AbstractCustomNode { ], NodeFactory.blockStatementNode([ NodeFactory.returnStatementNode( - NodeFactory.callExpressionNode( - calleeIdentifier, - callArguments - ) + this.isChainExpressionParent + ? NodeFactory.chainExpressionNode(callExpression) + : callExpression ) ]) ) diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.ts index 61824f685..17e2bf4d0 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.ts @@ -66,12 +66,14 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac return callExpressionNode; } + const isChainExpressionParent = NodeGuards.isChainExpressionNode(parentNode); + const replacerId: number = callExpressionNode.arguments.length; const callExpressionFunctionCustomNode: ICustomNode> = this.controlFlowCustomNodeFactory(ControlFlowCustomNode.CallExpressionFunctionNode); const expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[] = callExpressionNode.arguments; - callExpressionFunctionCustomNode.initialize(expressionArguments); + callExpressionFunctionCustomNode.initialize(expressionArguments, isChainExpressionParent); const storageKey: string = this.insertCustomNodeToControlFlowStorage( callExpressionFunctionCustomNode, @@ -84,7 +86,7 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac controlFlowStorage.getStorageId(), storageKey, callee, - expressionArguments + expressionArguments, ); } diff --git a/src/node/NodeFactory.ts b/src/node/NodeFactory.ts index 534cb9c62..3449f2ef3 100644 --- a/src/node/NodeFactory.ts +++ b/src/node/NodeFactory.ts @@ -118,6 +118,20 @@ export class NodeFactory { }; } + /** + * @param {ChainElement} expression + * @return {ChainExpression} + */ + public static chainExpressionNode ( + expression: ESTree.ChainElement, + ): ESTree.ChainExpression { + return { + type: NodeType.ChainExpression, + expression, + metadata: { ignoredNode: false } + }; + } + /** * @param {ESTree.Expression} test * @param {ESTree.Expression} consequent diff --git a/src/node/NodeGuards.ts b/src/node/NodeGuards.ts index 0cec976da..3a4da04b5 100644 --- a/src/node/NodeGuards.ts +++ b/src/node/NodeGuards.ts @@ -91,6 +91,14 @@ export class NodeGuards { return node.type === NodeType.CallExpression; } + /** + * @param {Node} node + * @returns {boolean} + */ + public static isChainExpressionNode (node: ESTree.Node): node is ESTree.ChainExpression { + return node.type === NodeType.ChainExpression; + } + /** * @param {Node} node * @returns {boolean} diff --git a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts index 10a260bdc..a1d0699d7 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts @@ -229,5 +229,39 @@ describe('CallExpressionControlFlowReplacer', function () { assert.match(obfuscatedCode, controlFlowStorageNodeRegExp); }); }); - }); + + describe('Variant #7 - keep optional chaining operator', () => { + const controlFlowStorageCallRegExp: RegExp = new RegExp( + `${variableMatch}\\['\\w{5}']\\(${variableMatch}, *0x1, *0x2\\);` + ); + const controlFlowStorageNodeRegExp: RegExp = new RegExp(`` + + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}, *${variableMatch}\\) *\\{` + + `return *${variableMatch}\\?\\.\\(${variableMatch}, *${variableMatch}\\);` + + `\\}` + + ``); + + let obfuscatedCode: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/optional-chaining-call.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + } + ).getObfuscatedCode(); + }); + + it('should replace call expression node with call to control flow storage node', () => { + assert.match(obfuscatedCode, controlFlowStorageCallRegExp); + }); + + it('should wrap call expression into chain expression', () => { + assert.match(obfuscatedCode, controlFlowStorageNodeRegExp); + }); + }); + }); }); diff --git a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/optional-chaining-call.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/optional-chaining-call.js new file mode 100644 index 000000000..5d579c7f8 --- /dev/null +++ b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/optional-chaining-call.js @@ -0,0 +1,5 @@ +(function () { + const sum = null; + + var variable = sum?.(1, 2); +})(); From cd63f590990b6c83773df3ededc18a044139c36f Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sun, 30 Nov 2025 02:33:15 +0400 Subject: [PATCH 18/87] Don't obfuscate import.meta.* (#1335) --- CHANGELOG.md | 1 + .../PreparingTransformersModule.ts | 8 +++++++ .../obfuscating-guards/ObfuscatingGuard.ts | 1 + src/enums/node/NodeType.ts | 1 + .../MemberExpressionTransformer.ts | 5 ++++ .../ObfuscatingGuardsTransformer.ts | 1 + .../ImportMetaObfuscationGuard.ts | 23 +++++++++++++++++++ src/node/NodeGuards.ts | 8 +++++++ .../JavaScriptObfuscator.spec.ts | 2 +- 9 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index a4bbce6ee..e65d3f70c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ v4.1.2 --- * Fix `transformObjectKeys` performance in some edge-cases * Fix `controlFlowFlattening` + optional chaining compatibility. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1325 +* Don't obfuscate import.meta.*. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1267 * Revert `Improved stringArray calls wrapper templates` commit. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1330 * Don't publish root index.ts files to NPM. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1252 * Update `class-validator` version. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1324 diff --git a/src/container/modules/node-transformers/PreparingTransformersModule.ts b/src/container/modules/node-transformers/PreparingTransformersModule.ts index 57dd7f132..f7309b4a6 100644 --- a/src/container/modules/node-transformers/PreparingTransformersModule.ts +++ b/src/container/modules/node-transformers/PreparingTransformersModule.ts @@ -14,6 +14,9 @@ import { CustomCodeHelpersTransformer } from '../../../node-transformers/prepari import { EvalCallExpressionTransformer } from '../../../node-transformers/preparing-transformers/EvalCallExpressionTransformer'; import { ForceTransformStringObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ForceTransformStringObfuscatingGuard'; import { IgnoredImportObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/IgnoredImportObfuscatingGuard'; +import { + ImportMetaObfuscationGuard +} from '../../../node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard'; import { MetadataTransformer } from '../../../node-transformers/preparing-transformers/MetadataTransformer'; import { ObfuscatingGuardsTransformer } from '../../../node-transformers/preparing-transformers/ObfuscatingGuardsTransformer'; import { ParentificationTransformer } from '../../../node-transformers/preparing-transformers/ParentificationTransformer'; @@ -67,6 +70,11 @@ export const preparingTransformersModule: interfaces.ContainerModule = new Conta .inSingletonScope() .whenTargetNamed(ObfuscatingGuard.IgnoredImportObfuscatingGuard); + bind(ServiceIdentifiers.INodeGuard) + .to(ImportMetaObfuscationGuard) + .inSingletonScope() + .whenTargetNamed(ObfuscatingGuard.ImportMetaObfuscationGuard); + bind(ServiceIdentifiers.INodeGuard) .to(ReservedStringObfuscatingGuard) .inSingletonScope() diff --git a/src/enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard.ts b/src/enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard.ts index 023c70726..3da243455 100644 --- a/src/enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard.ts +++ b/src/enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard.ts @@ -3,5 +3,6 @@ export enum ObfuscatingGuard { ConditionalCommentObfuscatingGuard = 'ConditionalCommentObfuscatingGuard', ForceTransformStringObfuscatingGuard = 'ForceTransformStringObfuscatingGuard', IgnoredImportObfuscatingGuard = 'IgnoredImportObfuscatingGuard', + ImportMetaObfuscationGuard = 'ImportMetaObfuscationGuard', ReservedStringObfuscatingGuard = 'ReservedStringObfuscatingGuard' } diff --git a/src/enums/node/NodeType.ts b/src/enums/node/NodeType.ts index 4d35273bc..65baf57c1 100644 --- a/src/enums/node/NodeType.ts +++ b/src/enums/node/NodeType.ts @@ -36,6 +36,7 @@ export enum NodeType { Literal = 'Literal', LogicalExpression = 'LogicalExpression', MemberExpression = 'MemberExpression', + MetaProperty = 'MetaProperty', MethodDefinition = 'MethodDefinition', NewExpression = 'NewExpression', ObjectExpression = 'ObjectExpression', diff --git a/src/node-transformers/converting-transformers/MemberExpressionTransformer.ts b/src/node-transformers/converting-transformers/MemberExpressionTransformer.ts index 300d66c46..731244995 100644 --- a/src/node-transformers/converting-transformers/MemberExpressionTransformer.ts +++ b/src/node-transformers/converting-transformers/MemberExpressionTransformer.ts @@ -12,6 +12,7 @@ import { NodeTransformationStage } from '../../enums/node-transformers/NodeTrans import { AbstractNodeTransformer } from '../AbstractNodeTransformer'; import { NodeFactory } from '../../node/NodeFactory'; import { NodeGuards } from '../../node/NodeGuards'; +import { NodeMetadata } from '../../node/NodeMetadata'; @injectable() export class MemberExpressionTransformer extends AbstractNodeTransformer { @@ -63,6 +64,10 @@ export class MemberExpressionTransformer extends AbstractNodeTransformer { * @returns {NodeGuards} */ public transformNode (memberExpressionNode: ESTree.MemberExpression, parentNode: ESTree.Node): ESTree.Node { + if (NodeMetadata.isIgnoredNode(memberExpressionNode.object) || NodeMetadata.isIgnoredNode(memberExpressionNode.property)) { + return memberExpressionNode; + } + if (NodeGuards.isIdentifierNode(memberExpressionNode.property)) { if (memberExpressionNode.computed) { return memberExpressionNode; diff --git a/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts b/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts index d8cb9d134..dad6fc5dc 100644 --- a/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts +++ b/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts @@ -32,6 +32,7 @@ export class ObfuscatingGuardsTransformer extends AbstractNodeTransformer { ObfuscatingGuard.ConditionalCommentObfuscatingGuard, ObfuscatingGuard.ForceTransformStringObfuscatingGuard, ObfuscatingGuard.IgnoredImportObfuscatingGuard, + ObfuscatingGuard.ImportMetaObfuscationGuard, ObfuscatingGuard.ReservedStringObfuscatingGuard ]; diff --git a/src/node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard.ts b/src/node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard.ts new file mode 100644 index 000000000..32ebd4b89 --- /dev/null +++ b/src/node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard.ts @@ -0,0 +1,23 @@ +import { injectable } from 'inversify'; + +import * as ESTree from 'estree'; + +import { IObfuscatingGuard } from '../../../interfaces/node-transformers/preparing-transformers/obfuscating-guards/IObfuscatingGuard'; + +import { ObfuscatingGuardResult } from '../../../enums/node/ObfuscatingGuardResult'; + +import { NodeGuards } from '../../../node/NodeGuards'; + +@injectable() +export class ImportMetaObfuscationGuard implements IObfuscatingGuard { + /** + * @param {Node} node + * @returns {ObfuscatingGuardResult} + */ + public check (node: ESTree.Node): ObfuscatingGuardResult { + const isMetaProperty = NodeGuards.isMetaPropertyNode(node); + const isMetaPropertyParent = !!node?.parentNode && NodeGuards.isMetaPropertyNode(node.parentNode); + + return isMetaProperty || isMetaPropertyParent ? ObfuscatingGuardResult.Ignore : ObfuscatingGuardResult.Transform; + } +} diff --git a/src/node/NodeGuards.ts b/src/node/NodeGuards.ts index 3a4da04b5..ee6d3568a 100644 --- a/src/node/NodeGuards.ts +++ b/src/node/NodeGuards.ts @@ -335,6 +335,14 @@ export class NodeGuards { return node.type === NodeType.MemberExpression; } + /** + * @param {Node} node + * @returns {boolean} + */ + public static isMetaPropertyNode (node: ESTree.Node): node is ESTree.MetaProperty { + return node.type === NodeType.MetaProperty; + } + /** * @param {Node} node * @returns {boolean} diff --git a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts index e264a30fd..483a9489b 100644 --- a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts +++ b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts @@ -806,7 +806,7 @@ describe('JavaScriptObfuscator', () => { }); describe('import.meta support', () => { - const regExp: RegExp = /console\['log']\(import\.meta\['url']\);/; + const regExp: RegExp = /console\['log']\(import\.meta\.url\);/; let obfuscatedCode: string; From 964376363ead537f9d777d0d9975c79f14b88054 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sun, 30 Nov 2025 03:15:42 +0400 Subject: [PATCH 19/87] Fix error when ClassExpression is the CallExpression callee (#1336) --- CHANGELOG.md | 1 + package.json | 2 +- .../JavaScriptObfuscator.spec.ts | 22 +++++++++++++++++++ .../call-expression-class-expression.js | 1 + yarn.lock | 8 +++---- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 test/functional-tests/javascript-obfuscator/fixtures/call-expression-class-expression.js diff --git a/CHANGELOG.md b/CHANGELOG.md index e65d3f70c..39c156f9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ v4.1.2 * Fix `controlFlowFlattening` + optional chaining compatibility. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1325 * Don't obfuscate import.meta.*. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1267 * Revert `Improved stringArray calls wrapper templates` commit. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1330 +* Fix error when ClassExpression is the CallExpression callee. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1132 * Don't publish root index.ts files to NPM. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1252 * Update `class-validator` version. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1324 * Update other dependencies diff --git a/package.json b/package.json index 666183d5e..5af236840 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "types": "typings/index.d.ts", "dependencies": { - "@javascript-obfuscator/escodegen": "2.3.0", + "@javascript-obfuscator/escodegen": "2.3.1", "@javascript-obfuscator/estraverse": "5.4.0", "acorn": "8.15.0", "assert": "2.1.0", diff --git a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts index 483a9489b..07761c9f3 100644 --- a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts +++ b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts @@ -1049,6 +1049,28 @@ describe('JavaScriptObfuscator', () => { }); }); + // https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1132 + describe('CallExpression ClassExpression crash fix', () => { + const regExp: RegExp = /try *\{!class *\{} *\(\);} *catch *\{}/; + + let obfuscatedCode: string; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/call-expression-class-expression.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET + } + ).getObfuscatedCode(); + }); + + it('should not throw', () => { + assert.match(obfuscatedCode, regExp); + }); + }); + describe('mangled identifier names generator', () => { const regExp: RegExp = /var c *= *0x1/; diff --git a/test/functional-tests/javascript-obfuscator/fixtures/call-expression-class-expression.js b/test/functional-tests/javascript-obfuscator/fixtures/call-expression-class-expression.js new file mode 100644 index 000000000..c7cfc847a --- /dev/null +++ b/test/functional-tests/javascript-obfuscator/fixtures/call-expression-class-expression.js @@ -0,0 +1 @@ +try { ! class { } ( ) ; } catch { } diff --git a/yarn.lock b/yarn.lock index d2fddd2f5..6c1be1ca4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -329,10 +329,10 @@ resolved "https://registry.yarnpkg.com/@istanbuljs/schema/-/schema-0.1.3.tgz#e45e384e4b8ec16bce2fd903af78450f6bf7ec98" integrity sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA== -"@javascript-obfuscator/escodegen@2.3.0": - version "2.3.0" - resolved "https://registry.yarnpkg.com/@javascript-obfuscator/escodegen/-/escodegen-2.3.0.tgz#ff7eb7f8a7c004532e93b14ae8b2196dcf9a1a9e" - integrity sha512-QVXwMIKqYMl3KwtTirYIA6gOCiJ0ZDtptXqAv/8KWLG9uQU2fZqTVy7a/A5RvcoZhbDoFfveTxuGxJ5ibzQtkw== +"@javascript-obfuscator/escodegen@2.3.1": + version "2.3.1" + resolved "https://registry.yarnpkg.com/@javascript-obfuscator/escodegen/-/escodegen-2.3.1.tgz#a534e73740830d6c7546ca686773b40b09a6b9d1" + integrity sha512-Z0HEAVwwafOume+6LFXirAVZeuEMKWuPzpFbQhCEU9++BMz0IwEa9bmedJ+rMn/IlXRBID9j3gQ0XYAa6jM10g== dependencies: "@javascript-obfuscator/estraverse" "^5.3.0" esprima "^4.0.1" From f5f2cbc2a89055b4419e11873ddf2d1bbe0aac6c Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Sun, 30 Nov 2025 03:16:46 +0400 Subject: [PATCH 20/87] Version update --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39c156f9d..ed61ef1c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ Change Log -v4.1.2 +v4.2.0 --- * Fix `transformObjectKeys` performance in some edge-cases * Fix `controlFlowFlattening` + optional chaining compatibility. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1325 diff --git a/package.json b/package.json index 5af236840..e6f51f02c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "4.1.2", + "version": "4.2.0", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", From 01465a233c977c45d2f238806a95a06387cc7a39 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Sun, 30 Nov 2025 04:18:04 +0400 Subject: [PATCH 21/87] Version update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed61ef1c5..2bbe7204f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Change Log v4.2.0 --- +* Dropped support of Node versions 17 and below * Fix `transformObjectKeys` performance in some edge-cases * Fix `controlFlowFlattening` + optional chaining compatibility. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1325 * Don't obfuscate import.meta.*. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1267 From 4ee4b219e50ac06a8ddeaaf478bb57b1c7b610d6 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Thu, 4 Dec 2025 00:09:10 +0400 Subject: [PATCH 22/87] Add prettier (#1339) --- .eslintrc.js | 534 +++-- .prettierignore | 34 + .prettierrc.js | 50 + package.json | 6 + src/ASTParserFacade.ts | 30 +- src/JavaScriptObfuscator.ts | 60 +- src/JavaScriptObfuscatorCLIFacade.ts | 2 +- src/JavaScriptObfuscatorFacade.ts | 61 +- .../CallsGraphAnalyzer.ts | 25 +- .../AbstractCalleeDataExtractor.ts | 2 +- .../FunctionDeclarationCalleeDataExtractor.ts | 4 +- .../FunctionExpressionCalleeDataExtractor.ts | 7 +- .../ObjectExpressionCalleeDataExtractor.ts | 21 +- .../NumberNumericalExpressionAnalyzer.ts | 17 +- .../PrevailingKindOfVariablesAnalyzer.ts | 18 +- src/analyzers/scope-analyzer/ScopeAnalyzer.ts | 34 +- .../StringArrayStorageAnalyzer.ts | 29 +- src/cli/JavaScriptObfuscatorCLI.ts | 213 +- src/cli/sanitizers/ArraySanitizer.ts | 6 +- src/cli/sanitizers/BooleanSanitizer.ts | 2 +- src/cli/utils/CLIUtils.ts | 10 +- .../utils/IdentifierNamesCacheFileUtils.ts | 28 +- src/cli/utils/ObfuscatedCodeFileUtils.ts | 29 +- src/cli/utils/SourceCodeFileUtils.ts | 91 +- .../AbstractCodeTransformer.ts | 4 +- .../CodeTransformersRunner.ts | 40 +- .../HashbangOperatorTransformer.ts | 10 +- src/constants/ReservedIdentifierNames.ts | 52 +- src/container/InversifyContainerFacade.ts | 63 +- .../modules/analyzers/AnalyzersModule.ts | 21 +- .../CodeTransformersModule.ts | 10 +- .../CustomCodeHelpersModule.ts | 18 +- .../modules/custom-nodes/CustomNodesModule.ts | 101 +- .../modules/generators/GeneratorsModule.ts | 79 +- .../ControlFlowTransformersModule.ts | 87 +- .../ConvertingTransformersModule.ts | 13 +- .../DeadCodeInjectionTransformersModule.ts | 14 +- .../InitializingTransformersModule.ts | 14 +- .../NodeTransformersModule.ts | 10 +- .../PreparingTransformersModule.ts | 12 +- .../RenameIdentifiersTransformersModule.ts | 54 +- .../RenamePropertiesTransformersModule.ts | 19 +- .../SimplifyingTransformersModule.ts | 32 +- .../StringArrayTransformersModule.ts | 26 +- .../modules/options/OptionsModule.ts | 8 +- .../modules/storages/StoragesModule.ts | 25 +- src/container/modules/utils/UtilsModule.ts | 19 +- .../AbstractCustomCodeHelper.ts | 24 +- .../AbstractCustomCodeHelperGroup.ts | 17 +- .../CustomCodeHelperFormatter.ts | 11 +- .../CustomCodeHelperObfuscator.ts | 25 +- .../CallsControllerFunctionCodeHelper.ts | 12 +- .../ConsoleOutputDisableCodeHelper.ts | 15 +- .../group/ConsoleOutputCodeHelperGroup.ts | 23 +- .../DebugProtectionFunctionCallCodeHelper.ts | 12 +- .../DebugProtectionFunctionCodeHelper.ts | 17 +- ...bugProtectionFunctionIntervalCodeHelper.ts | 19 +- .../group/DebugProtectionCodeHelperGroup.ts | 35 +- .../DebugProtectionFunctionCallTemplate.ts | 2 +- ...DebugProtectionFunctionIntervalTemplate.ts | 2 +- .../DebugProtectionFunctionTemplate.ts | 2 +- .../DebuggerTemplate.ts | 2 +- .../DebuggerTemplateNoEval.ts | 2 +- .../domain-lock/DomainLockCodeHelper.ts | 19 +- .../group/DomainLockCustomCodeHelperGroup.ts | 18 +- .../self-defending/SelfDefendingCodeHelper.ts | 12 +- .../group/SelfDefendingCodeHelperGroup.ts | 18 +- ...StringArrayCallsWrapperBase64CodeHelper.ts | 21 +- .../StringArrayCallsWrapperCodeHelper.ts | 21 +- .../StringArrayCallsWrapperRc4CodeHelper.ts | 34 +- .../string-array/StringArrayCodeHelper.ts | 20 +- .../StringArrayRotateFunctionCodeHelper.ts | 25 +- .../group/StringArrayCodeHelperGroup.ts | 61 +- .../AtobTemplate.ts | 8 +- .../string-array-calls-wrapper/Rc4Template.ts | 2 +- .../SelfDefendingTemplate.ts | 12 +- .../StringArrayBase64DecodeTemplate.ts | 4 +- .../StringArrayCallsWrapperTemplate.ts | 2 +- .../StringArrayRC4DecodeTemplate.ts | 4 +- .../StringArrayRotateFunctionTemplate.ts | 2 +- .../string-array/StringArrayTemplate.ts | 2 +- src/custom-nodes/AbstractCustomNode.ts | 20 +- .../BinaryExpressionFunctionNode.ts | 22 +- ...BlockStatementControlFlowFlatteningNode.ts | 31 +- .../CallExpressionFunctionNode.ts | 37 +- .../LiteralNode.ts | 17 +- .../LogicalExpressionFunctionNode.ts | 22 +- ...allExpressionControlFlowStorageCallNode.ts | 22 +- .../ControlFlowStorageNode.ts | 28 +- ...nWithOperatorControlFlowStorageCallNode.ts | 24 +- ...StringLiteralControlFlowStorageCallNode.ts | 20 +- .../BlockStatementDeadCodeInjectionNode.ts | 29 +- ...ctExpressionVariableDeclarationHostNode.ts | 20 +- .../AbstractStringArrayCallNode.ts | 38 +- .../string-array-nodes/StringArrayCallNode.ts | 24 +- ...tringArrayScopeCallsWrapperFunctionNode.ts | 61 +- ...tringArrayScopeCallsWrapperVariableNode.ts | 17 +- .../AbstractStringArrayIndexNode.ts | 4 +- .../StringArrayHexadecimalNumberIndexNode.ts | 4 +- ...gArrayHexadecimalNumericStringIndexNode.ts | 4 +- src/declarations/ESTree.d.ts | 10 +- src/declarations/acorn-import-meta.d.ts | 2 +- src/declarations/environment.d.ts | 2 +- src/declarations/escodegen.d.ts | 2 +- src/decorators/Initializable.ts | 58 +- src/enums/ObfuscationTarget.ts | 2 +- .../CalleeDataExtractor.ts | 2 +- .../CodeTransformationStage.ts | 2 +- ...jectExpressionKeysTransformerCustomNode.ts | 3 +- .../StringArrayWrappersType.ts | 2 +- .../AbstractIdentifierNamesGenerator.ts | 32 +- .../DictionaryIdentifierNamesGenerator.ts | 34 +- .../HexadecimalIdentifierNamesGenerator.ts | 14 +- .../MangledIdentifierNamesGenerator.ts | 52 +- ...MangledShuffledIdentifierNamesGenerator.ts | 8 +- src/interfaces/IInitializable.ts | 4 +- src/interfaces/IJavaScriptObfsucator.ts | 2 +- src/interfaces/ITransformer.ts | 2 +- src/interfaces/analyzers/IAnalyzer.ts | 4 +- .../ICalleeDataExtractor.ts | 2 +- .../ICallsGraphAnalyzer.ts | 2 +- .../IPrevailingKindOfVariablesAnalyzer.ts | 4 +- .../INumberNumericalExpressionAnalyzer.ts | 8 +- .../scope-analyzer/IScopeAnalyzer.ts | 4 +- .../IStringArrayStorageAnalyzer.ts | 8 +- .../code-transformers/ICodeTransformer.ts | 4 +- .../ICodeTransformersRunner.ts | 2 +- .../container/IInversifyContainerFacade.ts | 8 +- .../custom-code-helpers/ICustomCodeHelper.ts | 6 +- .../ICustomCodeHelperFormatter.ts | 7 +- .../ICustomCodeHelperGroup.ts | 4 +- .../ICustomCodeHelperObfuscator.ts | 2 +- src/interfaces/custom-nodes/ICustomNode.ts | 6 +- .../IIdentifierNamesGenerator.ts | 18 +- src/interfaces/logger/ILogger.ts | 6 +- .../node-transformers/INodeTransformer.ts | 10 +- .../INodeTransformersRunner.ts | 2 +- src/interfaces/node-transformers/IVisitor.ts | 6 +- .../IControlFlowReplacer.ts | 8 +- .../IObjectExpressionExtractor.ts | 2 +- .../replacer/IIdentifierReplacer.ts | 14 +- .../replacer/IThroughIdentifierReplacer.ts | 2 +- .../replacer/IRenamePropertiesReplacer.ts | 4 +- .../node/IScopeIdentifiersTraverser.ts | 5 +- src/interfaces/options/IOptionsNormalizer.ts | 2 +- .../source-code/IObfuscationResult.ts | 10 +- src/interfaces/source-code/ISourceCode.ts | 4 +- src/interfaces/storages/IArrayStorage.ts | 22 +- src/interfaces/storages/IMapStorage.ts | 24 +- src/interfaces/storages/IWeakMapStorage.ts | 14 +- .../IControlFlowStorage.ts | 2 +- .../IGlobalIdentifierNamesCacheStorage.ts | 2 +- .../IPropertyIdentifierNamesCacheStorage.ts | 2 +- .../ILiteralNodesCacheStorage.ts | 12 +- ...tringArrayScopeCallsWrappersDataStorage.ts | 6 +- .../IStringArrayStorage.ts | 14 +- .../IVisitedLexicalScopeNodesStackStorage.ts | 8 +- src/interfaces/utils/IArrayUtils.ts | 14 +- src/interfaces/utils/ICryptUtils.ts | 6 +- .../utils/IEscapeSequenceEncoder.ts | 2 +- .../utils/ILevelledTopologicalSorter.ts | 11 +- src/interfaces/utils/IRandomGenerator.ts | 14 +- src/interfaces/utils/ISetUtils.ts | 2 +- .../utils/ITransformerNamesGroupsBuilder.ts | 7 +- src/logger/Logger.ts | 14 +- .../AbstractNodeTransformer.ts | 6 +- .../NodeTransformersRunner.ts | 52 +- .../BlockStatementControlFlowTransformer.ts | 41 +- .../FunctionControlFlowTransformer.ts | 78 +- .../StringArrayControlFlowTransformer.ts | 30 +- .../AbstractControlFlowReplacer.ts | 24 +- .../BinaryExpressionControlFlowReplacer.ts | 17 +- .../CallExpressionControlFlowReplacer.ts | 25 +- ...pressionWithOperatorControlFlowReplacer.ts | 26 +- .../LogicalExpressionControlFlowReplacer.ts | 28 +- .../StringArrayCallControlFlowReplacer.ts | 48 +- .../StringLiteralControlFlowReplacer.ts | 31 +- .../BooleanLiteralTransformer.ts | 22 +- .../ClassFieldTransformer.ts | 30 +- .../ExportSpecifierTransformer.ts | 8 +- .../MemberExpressionTransformer.ts | 13 +- .../NumberLiteralTransformer.ts | 18 +- .../NumberToNumericalExpressionTransformer.ts | 23 +- .../ObjectExpressionKeysTransformer.ts | 91 +- .../ObjectExpressionTransformer.ts | 43 +- .../ObjectPatternPropertiesTransformer.ts | 11 +- .../SplitStringTransformer.ts | 44 +- .../TemplateLiteralTransformer.ts | 15 +- .../BasePropertiesExtractor.ts | 68 +- ...xpressionToVariableDeclarationExtractor.ts | 55 +- ...DeadCodeInjectionIdentifiersTransformer.ts | 27 +- .../DeadCodeInjectionTransformer.ts | 92 +- .../DirectivePlacementTransformer.ts | 20 +- .../EscapeSequenceTransformer.ts | 12 +- .../CommentsTransformer.ts | 37 +- .../CustomCodeHelpersTransformer.ts | 36 +- .../EvalCallExpressionTransformer.ts | 55 +- .../MetadataTransformer.ts | 8 +- .../ObfuscatingGuardsTransformer.ts | 27 +- .../ParentificationTransformer.ts | 8 +- .../VariablePreserveTransformer.ts | 25 +- .../BlackListObfuscatingGuard.ts | 8 +- .../ConditionalCommentObfuscatingGuard.ts | 16 +- .../ForceTransformStringObfuscatingGuard.ts | 21 +- .../IgnoredImportObfuscatingGuard.ts | 23 +- .../ImportMetaObfuscationGuard.ts | 6 +- .../ReservedStringObfuscatingGuard.ts | 21 +- .../LabeledStatementTransformer.ts | 18 +- .../ScopeIdentifiersTransformer.ts | 182 +- .../ScopeThroughIdentifiersTransformer.ts | 24 +- .../replacer/IdentifierReplacer.ts | 30 +- .../ThroughIdentifierReplacer.ts | 24 +- .../RenamePropertiesTransformer.ts | 46 +- .../replacer/RenamePropertiesReplacer.ts | 49 +- .../AbstractStatementSimplifyTransformer.ts | 45 +- .../BlockStatementSimplifyTransformer.ts | 20 +- .../ExpressionStatementsMergeTransformer.ts | 11 +- .../IfStatementSimplifyTransformer.ts | 72 +- .../VariableDeclarationsMergeTransformer.ts | 11 +- .../StringArrayRotateFunctionTransformer.ts | 89 +- ...StringArrayScopeCallsWrapperTransformer.ts | 106 +- .../StringArrayTransformer.ts | 92 +- src/node/NodeAppender.ts | 30 +- src/node/NodeFactory.ts | 106 +- src/node/NodeGuards.ts | 224 +- src/node/NodeLexicalScopeUtils.ts | 6 +- src/node/NodeLiteralUtils.ts | 6 +- src/node/NodeMetadata.ts | 44 +- src/node/NodeStatementUtils.ts | 27 +- src/node/NodeUtils.ts | 71 +- .../NumericalExpressionDataToNodeConverter.ts | 65 +- src/node/ScopeIdentifiersTraverser.ts | 40 +- src/options/Options.ts | 21 +- src/options/OptionsNormalizer.ts | 4 +- src/options/ValidationErrorsFormatter.ts | 7 +- .../normalizer-rules/InputFileNameRule.ts | 8 +- .../normalizer-rules/SourceMapFileNameRule.ts | 4 +- .../StringArrayEncodingRule.ts | 6 +- .../normalizer-rules/StringArrayRule.ts | 4 +- src/options/presets/Default.ts | 8 +- src/options/presets/HighObfuscation.ts | 4 +- src/options/presets/MediumObfuscation.ts | 4 +- src/options/presets/NoCustomNodes.ts | 8 +- .../IsAllowedForObfuscationTargets.ts | 10 +- .../validators/IsDomainLockRedirectUrl.ts | 10 +- .../validators/IsIdentifierNamesCache.ts | 6 +- src/options/validators/IsInputFileName.ts | 2 +- src/source-code/ObfuscationResult.ts | 20 +- src/source-code/SourceCode.ts | 8 +- src/storages/ArrayStorage.ts | 24 +- src/storages/MapStorage.ts | 32 +- src/storages/WeakMapStorage.ts | 22 +- .../FunctionControlFlowStorage.ts | 10 +- .../StringControlFlowStorage.ts | 7 +- .../CustomCodeHelperGroupStorage.ts | 20 +- .../GlobalIdentifierNamesCacheStorage.ts | 13 +- .../PropertyIdentifierNamesCacheStorage.ts | 13 +- .../LiteralNodesCacheStorage.ts | 19 +- ...tringArrayScopeCallsWrappersDataStorage.ts | 10 +- .../StringArrayStorage.ts | 105 +- .../VisitedLexicalScopeNodesStackStorage.ts | 17 +- src/types/TDictionary.ts | 2 +- src/types/TIdentifierNamesCache.ts | 1 - src/types/TInitialData.ts | 2 +- src/types/TObfuscationResultsObject.ts | 2 +- src/types/cli/TCLISanitizer.ts | 2 +- .../TCustomCodeHelperFactory.ts | 6 +- .../TCustomCodeHelperGroupFactory.ts | 4 +- .../TControlFlowCustomNodeFactory.ts | 6 +- .../TDeadNodeInjectionCustomNodeFactory.ts | 6 +- ...ressionKeysTransformerCustomNodeFactory.ts | 6 +- .../TStringArrayCustomNodeFactory.ts | 6 +- .../TControlFlowStorageFactoryCreator.ts | 4 +- .../TObjectExpressionExtractorFactory.ts | 5 +- .../node/TNodeWithSingleStatementBody.ts | 35 +- src/types/node/TNumberLiteralNode.ts | 2 +- .../TScopeIdentifiersTraverserCallback.ts | 2 +- src/types/node/TStringLiteralNode.ts | 2 +- .../storages/TCustomCodeHelperGroupStorage.ts | 2 +- src/types/utils/TTransformersRelationEdge.ts | 2 +- src/types/utils/TTypeFromEnum.ts | 2 +- .../AbstractTransformerNamesGroupsBuilder.ts | 16 +- src/utils/ArrayUtils.ts | 20 +- src/utils/CryptUtils.ts | 32 +- src/utils/CryptUtilsStringArray.ts | 6 +- src/utils/EscapeSequenceEncoder.ts | 8 +- src/utils/LevelledTopologicalSorter.ts | 33 +- src/utils/NumberUtils.ts | 32 +- src/utils/RandomGenerator.ts | 18 +- src/utils/SetUtils.ts | 6 +- src/utils/StringUtils.ts | 2 +- src/utils/Utils.ts | 15 +- test/declarations/index.d.ts | 2 +- test/declarations/source-map-resolve.d.ts | 4 +- test/dev/dev-compile-performance.ts | 4 +- test/dev/dev-runtime-performance.ts | 5 +- test/dev/dev.ts | 46 +- test/fixtures/directory-obfuscation/baz.ts | 2 +- .../CallsGraphAnalyzer.spec.ts | 175 +- .../scope-analyzer/ScopeAnalyzer.spec.ts | 23 +- .../cli/JavaScriptObfuscatorCLI.spec.ts | 156 +- .../HashbangOperatorTransformer.spec.ts | 70 +- ...eOutputDisableExpressionCodeHelper.spec.ts | 29 +- .../ConsoleOutputDisableTemplate.spec.ts | 29 +- ...ebugProtectionFunctionCallTemplate.spec.ts | 180 +- ...ProtectionFunctionIntervalTemplate.spec.ts | 51 +- .../domain-lock/DomainLockCodeHelper.spec.ts | 56 +- .../templates/DomainLockNodeTemplate.spec.ts | 404 ++-- .../SelfDefendingCodeHelper.spec.ts | 30 +- .../templates/SelfDefendingTemplate.spec.ts | 154 +- .../StringArrayCallsWrapperCodeHelper.spec.ts | 72 +- .../StringArrayCodeHelper.spec.ts | 28 +- ...tringArrayRotateFunctionCodeHelper.spec.ts | 69 +- .../group/StringArrayCodeHelperGroup.spec.ts | 29 +- .../StringArrayCallsWrapperTemplate.spec.ts | 222 +- .../StringArrayRotateFunctionTemplate.spec.ts | 75 +- .../StringArrayTemplate.spec.ts | 45 +- ...DictionaryIdentifierNamesGenerator.spec.ts | 160 +- .../MangledIdentifierNamesGenerator.spec.ts | 212 +- ...edShuffledIdentifierNamesGenerator.spec.ts | 26 +- test/functional-tests/issues/issue321.spec.ts | 12 +- test/functional-tests/issues/issue355.spec.ts | 16 +- test/functional-tests/issues/issue419.spec.ts | 11 +- test/functional-tests/issues/issue424.spec.ts | 12 +- test/functional-tests/issues/issue437.spec.ts | 8 +- .../JavaScriptObfuscator.spec.ts | 828 +++----- ...ockStatementControlFlowTransformer.spec.ts | 415 ++-- ...inaryExpressionControlFlowReplacer.spec.ts | 26 +- .../CallExpressionControlFlowReplacer.spec.ts | 147 +- ...gicalExpressionControlFlowReplacer.spec.ts | 54 +- .../StringLiteralControlFlowReplacer.spec.ts | 37 +- .../FunctionControlFlowTransformer.spec.ts | 209 +- .../StringArrayControlFlowTransformer.spec.ts | 277 +-- .../BooleanLiteralTransformer.spec.ts | 26 +- .../ClassFieldTransformer.spec.ts | 144 +- .../ExportSpecifierTransformer.spec.ts | 58 +- .../MemberExpressionTransformer.spec.ts | 46 +- .../NumberLiteralTransformer.spec.ts | 26 +- ...sToNumericalExpressionsTransformer.spec.ts | 114 +- .../ObjectExpressionKeysTransformer.spec.ts | 1873 ++++++++--------- .../ObjectExpressionTransformer.spec.ts | 98 +- ...ObjectPatternPropertiesTransformer.spec.ts | 81 +- .../SplitStringTransformer.spec.ts | 339 ++- .../TemplateLiteralTransformer.spec.ts | 191 +- .../DeadCodeInjectionTransformer.spec.ts | 639 +++--- .../DirectivePlacementTransformer.spec.ts | 144 +- .../EscapeSequenceTransformer.spec.ts | 119 +- .../CommentsTransformer.spec.ts | 115 +- .../EvalCallExpressionTransformer.spec.ts | 145 +- .../BlackListObfuscatingGuard.spec.ts | 17 +- ...ConditionalCommentObfuscatingGuard.spec.ts | 75 +- ...rceTransformStringObfuscatingGuard.spec.ts | 46 +- .../IgnoredImportObfuscatingGuard.spec.ts | 46 +- .../ReservedStringObfuscatingGuard.spec.ts | 38 +- .../VariablePreserveTransformer.spec.ts | 154 +- .../IdentifierReplacer.spec.ts | 34 +- .../LabeledStatementTransformer.spec.ts | 15 +- .../catch-clause/CatchClause.spec.ts | 56 +- .../ClassDeclaration.spec.ts | 435 ++-- .../class-expression/ClassExpression.spec.ts | 26 +- .../FunctionDeclaration.spec.ts | 133 +- .../function/Function.spec.ts | 330 ++- .../ImportDeclaration.spec.ts | 89 +- .../VariableDeclaration.spec.ts | 349 ++- .../ClassDeclaration.spec.ts | 59 +- .../FunctionDeclaration.spec.ts | 59 +- .../VariableDeclaration.spec.ts | 179 +- .../RenamePropertiesTransformer.spec.ts | 512 ++--- .../BlockStatementSimplifyTransformer.spec.ts | 152 +- ...pressionStatementsMergeTransformer.spec.ts | 44 +- .../IfStatementSimplifyTransformer.spec.ts | 843 ++++---- ...riableDeclarationsMergeTransformer.spec.ts | 161 +- ...ringArrayRotateFunctionTransformer.spec.ts | 185 +- ...gArrayScopeCallsWrapperTransformer.spec.ts | 891 ++++---- .../StringArrayTransformer.spec.ts | 630 +++--- test/functional-tests/options/Options.spec.ts | 8 +- .../options/OptionsNormalizer.spec.ts | 41 +- .../Validation.spec.ts | 40 +- .../options/domain-lock/Validation.spec.ts | 32 +- .../identifier-names-cache/Validation.spec.ts | 96 +- .../input-file-name/Validation.spec.ts | 30 +- .../StringArrayStorage.spec.ts | 141 +- test/helpers/atob.ts | 2 +- test/helpers/beautifyCode.ts | 4 +- test/helpers/buildLargeCode.ts | 8 +- test/helpers/checkCodeEvaluation.ts | 4 +- test/helpers/evaluateInWorker.ts | 7 +- test/helpers/get-string-array-regexp.ts | 13 +- test/helpers/getRegExpMatch.ts | 2 +- test/helpers/minimizeCode.ts | 6 +- .../parseSourceMapFromObfuscatedCode.ts | 2 +- test/helpers/readFileAsString.ts | 4 +- test/helpers/removeRangesFromStructure.ts | 4 +- test/helpers/stubNodeTransformers.ts | 6 +- test/helpers/swapLettersCase.ts | 8 +- test/index.spec.ts | 2 +- test/mocks/StdoutWriteMock.ts | 8 +- .../JavaScriptObfuscatorMemory.spec.ts | 51 +- .../JavaScriptObfuscatorRuntime.spec.ts | 46 +- .../NumberNumericalExpressionAnalyzer.spec.ts | 18 +- .../PrevailingKindOfVariablesAnalyzer.spec.ts | 68 +- .../scope-analyzer/ScopeAnalyzer.spec.ts | 32 +- .../StringArrayStorageAnalyzer.spec.ts | 14 +- .../cli/sanitizers/BooleanSanitizer.spec.ts | 1 - .../IdentifierNamesCacheFileUtils.spec.ts | 2 +- .../cli/utils/ObfuscatedCodeFileUtils.spec.ts | 269 +-- .../cli/utils/SourceCodeFileUtils.spec.ts | 110 +- .../initializable/Initializable.spec.ts | 44 +- ...ictionarylIdentifierNamesGenerator.spec.ts | 3 +- ...exadecimalIdentifierNamesGenerator.spec.ts | 31 +- ...dShuffledlIdentifierNamesGenerator.spec.ts | 30 +- .../MangledlIdentifierNamesGenerator.spec.ts | 42 +- .../ASTParserFacade.spec.ts | 23 +- .../JavaScriptObfuscator.spec.ts | 44 +- test/unit-tests/logger/Logger.spec.ts | 10 +- .../ObfuscatingGuardsTransformer.spec.ts | 31 +- .../node/node-appender/NodeAppender.spec.ts | 60 +- .../node/node-guards/NodeGuards.spec.ts | 220 +- .../NodeLexicalScopeUtils.spec.ts | 73 +- .../NodeLiteralUtils.spec.ts | 58 +- .../node/node-metadata/NodeMetadata.spec.ts | 26 +- .../NodeStatementUtils.spec.ts | 300 +-- .../node/node-utils/NodeUtils.spec.ts | 108 +- ...ricalExpressionDataToNodeConverter.spec.ts | 32 +- .../options/ValidationErrorsFormatter.spec.ts | 100 +- .../source-code/ObfuscationResult.spec.ts | 58 +- test/unit-tests/storages/ArrayStorage.spec.ts | 36 +- test/unit-tests/storages/MapStorage.spec.ts | 26 +- .../GlobalIdentifierNamesCacheStorage.spec.ts | 4 +- ...ropertyIdentifierNamesCacheStorage.spec.ts | 2 +- .../LiteralNodesCacheStorage.spec.ts | 78 +- .../string-array/StringArrayStorage.spec.ts | 32 +- ...sitedLexicalScopeNodesStackStorage.spec.ts | 82 +- test/unit-tests/utils/ArrayUtils.spec.ts | 13 +- test/unit-tests/utils/CryptUtils.spec.ts | 46 +- .../utils/CryptUtilsStringArray.spec.ts | 8 +- .../utils/EscapeSequenceEncoder.spec.ts | 8 +- .../utils/LevelledTopologicalSorter.spec.ts | 34 +- test/unit-tests/utils/NumberUtils.spec.ts | 80 +- .../utils/ObfuscatedCodeFileUtils.spec.ts | 18 +- test/unit-tests/utils/RandomGenerator.spec.ts | 14 +- test/unit-tests/utils/StringUtils.spec.ts | 4 +- test/unit-tests/utils/Utils.spec.ts | 10 +- yarn.lock | 42 + 444 files changed, 10690 insertions(+), 13351 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.js diff --git a/.eslintrc.js b/.eslintrc.js index 19606656b..a18e32d6d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,336 +1,292 @@ module.exports = { - "env": { - "browser": true, - "es6": true, - "node": true + env: { + browser: true, + es6: true, + node: true }, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": "src/tsconfig.node.json", - "sourceType": "module" + parser: '@typescript-eslint/parser', + parserOptions: { + project: 'src/tsconfig.node.json', + sourceType: 'module' }, - "plugins": [ - "@typescript-eslint", - "import", - "jsdoc", - "prefer-arrow", - "unicorn" - ], - "rules": { - "@typescript-eslint/adjacent-overload-signatures": "error", - "@typescript-eslint/array-type": [ - "error", + plugins: ['@typescript-eslint', 'import', 'jsdoc', 'prefer-arrow', 'unicorn', 'prettier'], + extends: ['prettier'], + rules: { + '@typescript-eslint/adjacent-overload-signatures': 'error', + '@typescript-eslint/array-type': [ + 'error', { - "default": "array" + default: 'array' } ], - "@typescript-eslint/await-thenable": "error", - "@typescript-eslint/ban-ts-comment": "error", - "@typescript-eslint/ban-types": "off", - "@typescript-eslint/brace-style": [ - "error", - "1tbs", + '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/ban-ts-comment': 'error', + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/brace-style': 'off', + '@typescript-eslint/camelcase': 'off', + '@typescript-eslint/comma-spacing': 'error', + '@typescript-eslint/consistent-type-assertions': [ + 'error', { - "allowSingleLine": true + assertionStyle: 'angle-bracket' } ], - "@typescript-eslint/camelcase": "off", - "@typescript-eslint/comma-spacing": "error", - "@typescript-eslint/consistent-type-assertions": [ - "error", + '@typescript-eslint/consistent-type-definitions': 'error', + '@typescript-eslint/default-param-last': 'error', + '@typescript-eslint/explicit-function-return-type': 'error', + '@typescript-eslint/explicit-member-accessibility': [ + 'error', { - "assertionStyle": "angle-bracket" + accessibility: 'explicit' } ], - "@typescript-eslint/consistent-type-definitions": "error", - "@typescript-eslint/default-param-last": "error", - "@typescript-eslint/explicit-function-return-type": "error", - "@typescript-eslint/explicit-member-accessibility": [ - "error", + '@typescript-eslint/explicit-module-boundary-types': 'error', + '@typescript-eslint/func-call-spacing': 'error', + '@typescript-eslint/indent': ['off', 4], + '@typescript-eslint/member-delimiter-style': [ + 'error', { - "accessibility": "explicit" - } - ], - "@typescript-eslint/explicit-module-boundary-types": "error", - "@typescript-eslint/func-call-spacing": "error", - "@typescript-eslint/indent": [ - "off", - 4 - ], - "@typescript-eslint/member-delimiter-style": [ - "error", - { - "multiline": { - "delimiter": "semi", - "requireLast": true + multiline: { + delimiter: 'semi', + requireLast: true }, - "singleline": { - "delimiter": "semi", - "requireLast": false + singleline: { + delimiter: 'semi', + requireLast: false } } ], - "@typescript-eslint/member-ordering": "error", - "@typescript-eslint/naming-convention": [ - "error", + '@typescript-eslint/member-ordering': 'error', + '@typescript-eslint/naming-convention': [ + 'error', { - "selector": "default", - "format": ["camelCase", "PascalCase"] + selector: 'default', + format: ['camelCase', 'PascalCase'] }, { - "selector": "variable", - "format": ["camelCase", "PascalCase", "UPPER_CASE"] + selector: 'variable', + format: ['camelCase', 'PascalCase', 'UPPER_CASE'] }, { - "selector": "function", - "format": ["camelCase", "PascalCase"] + selector: 'function', + format: ['camelCase', 'PascalCase'] }, { - "selector": "class", - "format": ["PascalCase"] + selector: 'class', + format: ['PascalCase'] }, { - "selector": "interface", - "format": ["PascalCase"], - "prefix": ["I"] + selector: 'interface', + format: ['PascalCase'], + prefix: ['I'] }, { - "selector": "typeAlias", - "format": ["PascalCase"], - "prefix": ["T"] + selector: 'typeAlias', + format: ['PascalCase'], + prefix: ['T'] }, { - "selector": "typeParameter", - "format": ["PascalCase"] + selector: 'typeParameter', + format: ['PascalCase'] }, { - "selector": "enum", - "format": ["PascalCase"] + selector: 'enum', + format: ['PascalCase'] }, { - "selector": "enumMember", - "format": null + selector: 'enumMember', + format: null }, { - "selector": "property", - "format": ["camelCase", "PascalCase", "snake_case"] + selector: 'property', + format: ['camelCase', 'PascalCase', 'snake_case'] } ], - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-empty-interface": "error", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-extra-parens": "off", - "@typescript-eslint/no-floating-promises": "error", - "@typescript-eslint/no-for-in-array": "error", - "@typescript-eslint/no-inferrable-types": "off", - "@typescript-eslint/no-magic-numbers": "off", - "@typescript-eslint/no-misused-new": "error", - "@typescript-eslint/no-namespace": "error", - "@typescript-eslint/no-non-null-asserted-optional-chain": "error", - "@typescript-eslint/no-non-null-assertion": "error", - "@typescript-eslint/no-param-reassign": "off", - "@typescript-eslint/parameter-properties": "error", - "@typescript-eslint/no-require-imports": "off", - "@typescript-eslint/no-shadow": "error", - "@typescript-eslint/no-this-alias": "error", - "@typescript-eslint/no-unnecessary-qualifier": "error", - "@typescript-eslint/no-unnecessary-type-arguments": "error", - "@typescript-eslint/no-unnecessary-type-assertion": "error", - "@typescript-eslint/no-unused-expressions": "error", - "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/no-var-requires": "error", - "@typescript-eslint/prefer-for-of": "error", - "@typescript-eslint/prefer-function-type": "error", - "@typescript-eslint/prefer-namespace-keyword": "error", - "@typescript-eslint/prefer-nullish-coalescing": "error", - "@typescript-eslint/prefer-optional-chain": "error", - "@typescript-eslint/prefer-readonly": "error", - "@typescript-eslint/promise-function-async": "error", - "@typescript-eslint/quotes": [ - "error", - "single" - ], - "@typescript-eslint/require-array-sort-compare": "error", - "@typescript-eslint/restrict-plus-operands": "error", - "@typescript-eslint/semi": [ - "error", - "always" - ], - "@typescript-eslint/space-before-function-paren": "error", - "@typescript-eslint/strict-boolean-expressions": "off", - "@typescript-eslint/triple-slash-reference": "error", - "@typescript-eslint/type-annotation-spacing": "error", - "@typescript-eslint/typedef": "error", - "@typescript-eslint/unified-signatures": "error", - "arrow-body-style": "off", - "arrow-parens": [ - "off", - "as-needed" - ], - "brace-style": "off", - "capitalized-comments": "off", - "comma-dangle": "off", - "comma-spacing": "off", - "complexity": [ - "error", + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-empty-interface': 'error', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-extra-parens': 'off', + '@typescript-eslint/no-floating-promises': 'error', + '@typescript-eslint/no-for-in-array': 'error', + '@typescript-eslint/no-inferrable-types': 'off', + '@typescript-eslint/no-magic-numbers': 'off', + '@typescript-eslint/no-misused-new': 'error', + '@typescript-eslint/no-namespace': 'error', + '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-param-reassign': 'off', + '@typescript-eslint/parameter-properties': 'error', + '@typescript-eslint/no-require-imports': 'off', + '@typescript-eslint/no-shadow': 'error', + '@typescript-eslint/no-this-alias': 'error', + '@typescript-eslint/no-unnecessary-qualifier': 'error', + '@typescript-eslint/no-unnecessary-type-arguments': 'error', + '@typescript-eslint/no-unnecessary-type-assertion': 'error', + '@typescript-eslint/no-unused-expressions': 'error', + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/no-var-requires': 'error', + '@typescript-eslint/prefer-for-of': 'error', + '@typescript-eslint/prefer-function-type': 'error', + '@typescript-eslint/prefer-namespace-keyword': 'error', + '@typescript-eslint/prefer-nullish-coalescing': 'error', + '@typescript-eslint/prefer-optional-chain': 'error', + '@typescript-eslint/prefer-readonly': 'error', + '@typescript-eslint/promise-function-async': 'error', + '@typescript-eslint/quotes': ['error', 'single', { avoidEscape: true }], + '@typescript-eslint/require-array-sort-compare': 'error', + '@typescript-eslint/restrict-plus-operands': 'error', + '@typescript-eslint/semi': ['error', 'always'], + '@typescript-eslint/space-before-function-paren': 'off', + '@typescript-eslint/strict-boolean-expressions': 'off', + '@typescript-eslint/triple-slash-reference': 'error', + '@typescript-eslint/type-annotation-spacing': 'error', + '@typescript-eslint/typedef': 'error', + '@typescript-eslint/unified-signatures': 'error', + 'arrow-body-style': 'off', + 'arrow-parens': ['off', 'as-needed'], + 'brace-style': 'off', + 'capitalized-comments': 'off', + 'comma-dangle': 'off', + 'comma-spacing': 'off', + 'complexity': [ + 'error', { - "max": 10 + max: 10 } ], - "constructor-super": "error", - "curly": "error", - "default-case": "off", - "dot-notation": "error", - "eol-last": "error", - "eqeqeq": [ - "error", - "smart" - ], - "func-call-spacing": "off", - "guard-for-in": "error", - "id-blacklist": "off", - "id-match": "off", - "import/export": "error", - "import/first": "error", - "import/newline-after-import": "error", - "import/no-absolute-path": "error", - "import/no-cycle": "error", - "import/no-default-export": "error", - "import/no-deprecated": "error", - "import/no-extraneous-dependencies": "error", - "import/no-internal-modules": "error", - "import/no-mutable-exports": "error", - "import/no-unassigned-import": "off", - "import/no-useless-path-segments": "error", - "import/order": "off", - "indent": "off", - "jsdoc/no-types": "off", - "linebreak-style": "off", - "max-classes-per-file": [ - "error", - 1 - ], - "max-len": "off", - "max-lines": [ - "error", - 500 - ], - "new-parens": "error", - "newline-per-chained-call": "off", - "no-bitwise": "off", - "no-caller": "error", - "no-cond-assign": "error", - "no-console": [ - "error", + 'constructor-super': 'error', + 'curly': 'error', + 'default-case': 'off', + 'dot-notation': 'error', + 'eol-last': 'error', + 'eqeqeq': ['error', 'smart'], + 'func-call-spacing': 'off', + 'guard-for-in': 'error', + 'id-blacklist': 'off', + 'id-match': 'off', + 'import/export': 'error', + 'import/first': 'error', + 'import/newline-after-import': 'error', + 'import/no-absolute-path': 'error', + 'import/no-cycle': 'error', + 'import/no-default-export': 'error', + 'import/no-deprecated': 'error', + 'import/no-extraneous-dependencies': 'error', + 'import/no-internal-modules': 'error', + 'import/no-mutable-exports': 'error', + 'import/no-unassigned-import': 'off', + 'import/no-useless-path-segments': 'error', + 'import/order': 'off', + 'indent': 'off', + 'jsdoc/no-types': 'off', + 'linebreak-style': 'off', + 'max-classes-per-file': ['error', 1], + 'max-len': 'off', + 'max-lines': ['error', { max: 500, skipComments: true }], + 'new-parens': 'error', + 'newline-per-chained-call': 'off', + 'no-bitwise': 'off', + 'no-caller': 'error', + 'no-cond-assign': 'error', + 'no-console': [ + 'error', { - "allow": [ - "log", - "warn", - "dir", - "timeLog", - "assert", - "clear", - "count", - "countReset", - "group", - "groupEnd", - "table", - "dirxml", - "error", - "groupCollapsed", - "Console", - "profile", - "profileEnd", - "timeStamp", - "context" + allow: [ + 'log', + 'warn', + 'dir', + 'timeLog', + 'assert', + 'clear', + 'count', + 'countReset', + 'group', + 'groupEnd', + 'table', + 'dirxml', + 'error', + 'groupCollapsed', + 'Console', + 'profile', + 'profileEnd', + 'timeStamp', + 'context' ] } ], - "no-constant-condition": "error", - "no-control-regex": "off", - "no-debugger": "error", - "no-duplicate-case": "error", - "no-duplicate-imports": "error", - "no-empty": "off", - "no-eval": "off", - "no-extra-bind": "error", - "no-extra-parens": "off", - "no-extra-semi": "error", - "no-fallthrough": "error", - "no-invalid-regexp": "error", - "no-invalid-this": "off", - "no-irregular-whitespace": "error", - "no-magic-numbers": "off", - "no-multi-str": "error", - "no-multiple-empty-lines": "error", - "no-new-wrappers": "error", - "no-null/no-null": "off", - "no-octal": "error", - "no-octal-escape": "error", - "no-redeclare": "error", - "no-regex-spaces": "error", - "no-restricted-syntax": [ - "error", - "ForInStatement" - ], - "no-return-await": "error", - "no-sequences": "error", - "no-shadow": "off", - "no-sparse-arrays": "error", - "no-template-curly-in-string": "error", - "no-throw-literal": "error", - "no-trailing-spaces": [ - "error", + 'no-constant-condition': 'error', + 'no-control-regex': 'off', + 'no-debugger': 'error', + 'no-duplicate-case': 'error', + 'no-duplicate-imports': 'error', + 'no-empty': 'off', + 'no-eval': 'off', + 'no-extra-bind': 'error', + 'no-extra-parens': 'off', + 'no-extra-semi': 'error', + 'no-fallthrough': 'error', + 'no-invalid-regexp': 'error', + 'no-invalid-this': 'off', + 'no-irregular-whitespace': 'error', + 'no-magic-numbers': 'off', + 'no-multi-str': 'error', + 'no-multiple-empty-lines': 'error', + 'no-new-wrappers': 'error', + 'no-null/no-null': 'off', + 'no-octal': 'error', + 'no-octal-escape': 'error', + 'no-redeclare': 'error', + 'no-regex-spaces': 'error', + 'no-restricted-syntax': ['error', 'ForInStatement'], + 'no-return-await': 'error', + 'no-sequences': 'error', + 'no-shadow': 'off', + 'no-sparse-arrays': 'error', + 'no-template-curly-in-string': 'error', + 'no-throw-literal': 'error', + 'no-trailing-spaces': [ + 'error', { - "skipBlankLines": true + skipBlankLines: true } ], - "no-undef-init": "error", - "no-underscore-dangle": "off", - "no-unsafe-finally": "error", - "no-unused-expressions": "off", - "no-unused-labels": "error", - "no-var": "error", - "no-void": "error", - "object-shorthand": "off", - "one-var": [ - "error", - "never" - ], - "padding-line-between-statements": [ - "error", + 'no-undef-init': 'error', + 'no-underscore-dangle': 'off', + 'no-unsafe-finally': 'error', + 'no-unused-expressions': 'off', + 'no-unused-labels': 'error', + 'no-var': 'error', + 'no-void': 'error', + 'object-shorthand': 'off', + 'one-var': ['error', 'never'], + 'padding-line-between-statements': [ + 'error', { - "blankLine": "always", - "prev": "*", - "next": "return" + blankLine: 'always', + prev: '*', + next: 'return' } ], - "prefer-arrow/prefer-arrow-functions": "off", - "prefer-const": "error", - "prefer-object-spread": "error", - "prefer-template": "error", - "quote-props": [ - "error", - "as-needed" - ], - "quotes": "off", - "radix": "error", - "space-before-function-paren": "off", - "spaced-comment": "error", - "space-in-parens": [ - "error", - "never" - ], - "unicorn/catch-error-name": [ - "error", + 'prefer-arrow/prefer-arrow-functions': 'off', + 'prefer-const': 'error', + 'prefer-object-spread': 'error', + 'prefer-template': 'error', + 'quote-props': ['error', 'as-needed'], + 'quotes': 'off', + 'radix': 'error', + 'space-before-function-paren': 'off', + 'spaced-comment': 'error', + 'space-in-parens': ['error', 'never'], + 'unicorn/catch-error-name': [ + 'error', { - "name": "error" + name: 'error' } ], - "unicorn/no-nested-ternary": "error", - "unicorn/no-unreadable-array-destructuring": "error", - "unicorn/numeric-separators-style": [ - "error", + 'unicorn/no-nested-ternary': 'off', + 'unicorn/no-unreadable-array-destructuring': 'error', + 'unicorn/numeric-separators-style': [ + 'error', { number: { minimumDigits: 7, @@ -338,15 +294,15 @@ module.exports = { } } ], - "unicorn/prefer-array-find": "error", - "unicorn/prefer-includes": "error", - "unicorn/prefer-optional-catch-binding": "error", - "unicorn/prefer-starts-ends-with": "error", - "unicorn/prefer-set-has": "error", - "unicorn/prefer-string-slice": "error", - "unicorn/prefer-string-trim-start-end": "error", - "use-isnan": "error", - "valid-typeof": "error", - "yoda": "error" + 'unicorn/prefer-array-find': 'error', + 'unicorn/prefer-includes': 'error', + 'unicorn/prefer-optional-catch-binding': 'error', + 'unicorn/prefer-starts-ends-with': 'error', + 'unicorn/prefer-set-has': 'error', + 'unicorn/prefer-string-slice': 'error', + 'unicorn/prefer-string-trim-start-end': 'error', + 'use-isnan': 'error', + 'valid-typeof': 'error', + 'yoda': 'error' } }; diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..859bd06b4 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,34 @@ +# Dependencies +node_modules + +# Build output +dist +*.browser.js + +# Coverage +coverage +.nyc_output + +# Type definitions +typings + +# Webpack bundles +webpack + +# Lock files +package-lock.json +yarn.lock + +# Logs +*.log + +# Temporary files +*.tmp +.DS_Store + +# Test fixtures and expected output +test/**/*.expected.js +test/**/*.fixture.js + +# Templates (custom code helpers - these are code templates, not regular code) +src/custom-code-helpers/**/templates/*.ts diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 000000000..09aeed300 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,50 @@ +module.exports = { + // Basic formatting + printWidth: 120, + tabWidth: 4, + useTabs: false, + semi: true, + singleQuote: true, + quoteProps: 'consistent', + trailingComma: 'none', + + // Spacing + bracketSpacing: true, + arrowParens: 'always', + + // Line breaks + endOfLine: 'lf', + + // TypeScript + parser: 'typescript', + + // Override for specific file types + overrides: [ + { + files: '*.ts', + options: { + parser: 'typescript' + } + }, + { + files: '*.js', + options: { + parser: 'babel' + } + }, + { + files: '*.json', + options: { + parser: 'json', + tabWidth: 2 + } + }, + { + files: '*.md', + options: { + parser: 'markdown', + proseWrap: 'preserve' + } + } + ] +}; diff --git a/package.json b/package.json index e6f51f02c..dfc99ba17 100644 --- a/package.json +++ b/package.json @@ -71,10 +71,12 @@ "chai-exclude": "3.0.1", "cross-env": "10.1.0", "eslint": "8.57.1", + "eslint-config-prettier": "10.1.8", "eslint-plugin-import": "2.32.0", "eslint-plugin-jsdoc": "50.6.3", "eslint-plugin-no-null": "1.0.2", "eslint-plugin-prefer-arrow": "1.2.3", + "eslint-plugin-prettier": "5.5.4", "eslint-plugin-unicorn": "56.0.1", "eslint-webpack-plugin": "4.2.0", "fork-ts-checker-notifier-webpack-plugin": "9.0.0", @@ -84,6 +86,7 @@ "mocha": "11.7.4", "nyc": "17.1.0", "pjson": "1.0.9", + "prettier": "3.6.2", "rimraf": "6.0.1", "sinon": "19.0.2", "source-map-resolve": "0.6.0", @@ -117,6 +120,9 @@ "test:mocha-memory-performance": "cross-env NODE_OPTIONS=--max-old-space-size=280 mocha --require ts-node/register test/performance-tests/JavaScriptObfuscatorMemory.spec.ts", "test": "yarn run test:full", "eslint": "eslint src/**/*.ts", + "prettier": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "prettier:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"", + "format": "yarn run prettier && yarn run eslint --fix", "git:addFiles": "git add .", "postinstall": "opencollective-postinstall", "precommit": "npm run build", diff --git a/src/ASTParserFacade.ts b/src/ASTParserFacade.ts index 565a3df97..796f2ad8b 100644 --- a/src/ASTParserFacade.ts +++ b/src/ASTParserFacade.ts @@ -19,17 +19,14 @@ export class ASTParserFacade { /** * @type {acorn.Options['sourceType'][]} */ - private static readonly sourceTypes: acorn.Options['sourceType'][] = [ - 'script', - 'module' - ]; + private static readonly sourceTypes: acorn.Options['sourceType'][] = ['script', 'module']; /** * @param {string} sourceCode * @param {Options} config * @returns {Program} */ - public static parse (sourceCode: string, config: acorn.Options): ESTree.Program | never { + public static parse(sourceCode: string, config: acorn.Options): ESTree.Program | never { const sourceTypeLength: number = ASTParserFacade.sourceTypes.length; for (let i: number = 0; i < sourceTypeLength; i++) { @@ -40,11 +37,7 @@ export class ASTParserFacade { continue; } - throw new Error(ASTParserFacade.processParsingError( - sourceCode, - error.message, - error.loc - )); + throw new Error(ASTParserFacade.processParsingError(sourceCode, error.message, error.loc)); } } @@ -57,7 +50,7 @@ export class ASTParserFacade { * @param {acorn.Options["sourceType"]} sourceType * @returns {Program} */ - private static parseType ( + private static parseType( sourceCode: string, inputConfig: acorn.Options, sourceType: acorn.Options['sourceType'] @@ -70,8 +63,7 @@ export class ASTParserFacade { sourceType }; - const program: acorn.Node & ESTree.Program = acorn - .parse(sourceCode, config); + const program: acorn.Node & ESTree.Program = acorn.parse(sourceCode, config); if (comments.length) { program.comments = comments; @@ -86,7 +78,7 @@ export class ASTParserFacade { * @param {Position | null} position * @returns {never} */ - private static processParsingError ( + private static processParsingError( sourceCode: string, errorMessage: string, position: ESTree.Position | null @@ -108,12 +100,10 @@ export class ASTParserFacade { const endErrorIndex: number = Math.min(errorLine.length, position.column + ASTParserFacade.nearestSymbolsCount); const formattedPointer: string = ASTParserFacade.colorError('>'); - const formattedCodeSlice: string = `...${ - errorLine.slice(startErrorIndex, endErrorIndex).replace(/^\s+/, '') - }...`; + const formattedCodeSlice: string = `...${errorLine + .slice(startErrorIndex, endErrorIndex) + .replace(/^\s+/, '')}...`; - throw new Error( - `ERROR at line ${position.line}: ${errorMessage}\n${formattedPointer} ${formattedCodeSlice}` - ); + throw new Error(`ERROR at line ${position.line}: ${errorMessage}\n${formattedPointer} ${formattedCodeSlice}`); } } diff --git a/src/JavaScriptObfuscator.ts b/src/JavaScriptObfuscator.ts index 4728c05a3..f6f91a5dd 100644 --- a/src/JavaScriptObfuscator.ts +++ b/src/JavaScriptObfuscator.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from './container/ServiceIdentifiers'; import * as acorn from 'acorn'; @@ -55,9 +55,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { /** * @type {CodeTransformer[]} */ - private static readonly codeTransformersList: CodeTransformer[] = [ - CodeTransformer.HashbangOperatorTransformer - ]; + private static readonly codeTransformersList: CodeTransformer[] = [CodeTransformer.HashbangOperatorTransformer]; /** * @type {NodeTransformer[]} @@ -138,7 +136,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { * @param {ILogger} logger * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.ICodeTransformersRunner) codeTransformersRunner: ICodeTransformersRunner, @inject(ServiceIdentifiers.INodeTransformersRunner) nodeTransformersRunner: INodeTransformersRunner, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -158,13 +156,16 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { * @param {string} sourceCode * @returns {IObfuscationResult} */ - public obfuscate (sourceCode: string): IObfuscationResult { + public obfuscate(sourceCode: string): IObfuscationResult { if (typeof sourceCode !== 'string') { sourceCode = ''; } const timeStart: number = Date.now(); - this.logger.info(LoggingMessage.Version, Utils.buildVersionMessage(process.env.VERSION, process.env.BUILD_TIMESTAMP)); + this.logger.info( + LoggingMessage.Version, + Utils.buildVersionMessage(process.env.VERSION, process.env.BUILD_TIMESTAMP) + ); this.logger.info(LoggingMessage.ObfuscationStarted); this.logger.info(LoggingMessage.RandomGeneratorSeed, this.randomGenerator.getInputSeed()); @@ -181,7 +182,10 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { const generatorOutput: IGeneratorOutput = this.generateCode(sourceCode, obfuscatedAstTree); // finalizing code transformations - generatorOutput.code = this.runCodeTransformationStage(generatorOutput.code, CodeTransformationStage.FinalizingTransformers); + generatorOutput.code = this.runCodeTransformationStage( + generatorOutput.code, + CodeTransformationStage.FinalizingTransformers + ); const obfuscationTime: number = (Date.now() - timeStart) / 1000; this.logger.success(LoggingMessage.ObfuscationCompleted, obfuscationTime); @@ -193,7 +197,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { * @param {string} sourceCode * @returns {Program} */ - private parseCode (sourceCode: string): ESTree.Program { + private parseCode(sourceCode: string): ESTree.Program { return ASTParserFacade.parse(sourceCode, JavaScriptObfuscator.parseOptions); } @@ -201,13 +205,14 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { * @param {Program} astTree * @returns {Program} */ - private transformAstTree (astTree: ESTree.Program): ESTree.Program { + private transformAstTree(astTree: ESTree.Program): ESTree.Program { astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Initializing); - const isEmptyAstTree: boolean = NodeGuards.isProgramNode(astTree) - && !astTree.body.length - && !astTree.leadingComments - && !astTree.trailingComments; + const isEmptyAstTree: boolean = + NodeGuards.isProgramNode(astTree) && + !astTree.body.length && + !astTree.leadingComments && + !astTree.trailingComments; if (isEmptyAstTree) { this.logger.warn(LoggingMessage.EmptySourceCode); @@ -245,22 +250,22 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { * @param {Program} astTree * @returns {IGeneratorOutput} */ - private generateCode (sourceCode: string, astTree: ESTree.Program): IGeneratorOutput { + private generateCode(sourceCode: string, astTree: ESTree.Program): IGeneratorOutput { const escodegenParams: escodegen.GenerateOptions = { ...JavaScriptObfuscator.escodegenParams, format: { compact: this.options.compact }, - ...this.options.sourceMap && { - ...this.options.sourceMapSourcesMode === SourceMapSourcesMode.SourcesContent + ...(this.options.sourceMap && { + ...(this.options.sourceMapSourcesMode === SourceMapSourcesMode.SourcesContent ? { - sourceMap: 'sourceMap', - sourceContent: sourceCode - } + sourceMap: 'sourceMap', + sourceContent: sourceCode + } : { - sourceMap: this.options.inputFileName || 'sourceMap' - } - } + sourceMap: this.options.inputFileName || 'sourceMap' + }) + }) }; const generatorOutput: IGeneratorOutput = escodegen.generate(astTree, escodegenParams); @@ -274,7 +279,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { * @param {IGeneratorOutput} generatorOutput * @returns {IObfuscationResult} */ - private getObfuscationResult (generatorOutput: IGeneratorOutput): IObfuscationResult { + private getObfuscationResult(generatorOutput: IGeneratorOutput): IObfuscationResult { return this.obfuscationResultFactory(generatorOutput.code, generatorOutput.map); } @@ -283,7 +288,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { * @param {CodeTransformationStage} codeTransformationStage * @returns {string} */ - private runCodeTransformationStage (code: string, codeTransformationStage: CodeTransformationStage): string { + private runCodeTransformationStage(code: string, codeTransformationStage: CodeTransformationStage): string { this.logger.info(LoggingMessage.CodeTransformationStage, codeTransformationStage); return this.codeTransformersRunner.transform( @@ -298,7 +303,10 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { * @param {NodeTransformationStage} nodeTransformationStage * @returns {Program} */ - private runNodeTransformationStage (astTree: ESTree.Program, nodeTransformationStage: NodeTransformationStage): ESTree.Program { + private runNodeTransformationStage( + astTree: ESTree.Program, + nodeTransformationStage: NodeTransformationStage + ): ESTree.Program { this.logger.info(LoggingMessage.NodeTransformationStage, nodeTransformationStage); return this.nodeTransformersRunner.transform( diff --git a/src/JavaScriptObfuscatorCLIFacade.ts b/src/JavaScriptObfuscatorCLIFacade.ts index eb3f632c8..09a66604b 100644 --- a/src/JavaScriptObfuscatorCLIFacade.ts +++ b/src/JavaScriptObfuscatorCLIFacade.ts @@ -6,7 +6,7 @@ class JavaScriptObfuscatorCLIFacade { /** * @param {string[]} argv */ - public static obfuscate (argv: string[]): void { + public static obfuscate(argv: string[]): void { const javaScriptObfuscatorCLI: JavaScriptObfuscatorCLI = new JavaScriptObfuscatorCLI(argv); javaScriptObfuscatorCLI.initialize(); diff --git a/src/JavaScriptObfuscatorFacade.ts b/src/JavaScriptObfuscatorFacade.ts index 2489c40b2..abc6e2606 100644 --- a/src/JavaScriptObfuscatorFacade.ts +++ b/src/JavaScriptObfuscatorFacade.ts @@ -26,13 +26,14 @@ class JavaScriptObfuscatorFacade { * @param {TInputOptions} inputOptions * @returns {IObfuscationResult} */ - public static obfuscate (sourceCode: string, inputOptions: TInputOptions = {}): IObfuscationResult { + public static obfuscate(sourceCode: string, inputOptions: TInputOptions = {}): IObfuscationResult { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load(sourceCode, '', inputOptions); - const javaScriptObfuscator: IJavaScriptObfuscator = inversifyContainerFacade - .get(ServiceIdentifiers.IJavaScriptObfuscator); + const javaScriptObfuscator: IJavaScriptObfuscator = inversifyContainerFacade.get( + ServiceIdentifiers.IJavaScriptObfuscator + ); const obfuscationResult: IObfuscationResult = javaScriptObfuscator.obfuscate(sourceCode); inversifyContainerFacade.unload(); @@ -45,7 +46,7 @@ class JavaScriptObfuscatorFacade { * @param {TInputOptions} inputOptions * @returns {TObfuscationResultsObject} */ - public static obfuscateMultiple > ( + public static obfuscateMultiple>( sourceCodesObject: TSourceCodesObject, inputOptions: TInputOptions = {} ): TObfuscationResultsObject { @@ -53,39 +54,37 @@ class JavaScriptObfuscatorFacade { throw new Error('Source codes object should be a plain object'); } - return Object - .keys(sourceCodesObject) - .reduce( - ( - acc: TObfuscationResultsObject, - sourceCodeIdentifier: keyof TSourceCodesObject, - index: number - ) => { - const identifiersPrefix: string = Utils.getIdentifiersPrefixForMultipleSources( - inputOptions.identifiersPrefix, - index - ); - - const sourceCode: string = sourceCodesObject[sourceCodeIdentifier]; - const sourceCodeOptions: TInputOptions = { - ...inputOptions, - identifiersPrefix - }; - - return { - ...acc, - [sourceCodeIdentifier]: JavaScriptObfuscatorFacade.obfuscate(sourceCode, sourceCodeOptions) - }; - }, - >{} - ); + return Object.keys(sourceCodesObject).reduce( + ( + acc: TObfuscationResultsObject, + sourceCodeIdentifier: keyof TSourceCodesObject, + index: number + ) => { + const identifiersPrefix: string = Utils.getIdentifiersPrefixForMultipleSources( + inputOptions.identifiersPrefix, + index + ); + + const sourceCode: string = sourceCodesObject[sourceCodeIdentifier]; + const sourceCodeOptions: TInputOptions = { + ...inputOptions, + identifiersPrefix + }; + + return { + ...acc, + [sourceCodeIdentifier]: JavaScriptObfuscatorFacade.obfuscate(sourceCode, sourceCodeOptions) + }; + }, + >{} + ); } /** * @param {TOptionsPreset} optionsPreset * @returns {TInputOptions} */ - public static getOptionsByPreset (optionsPreset: TOptionsPreset): TInputOptions { + public static getOptionsByPreset(optionsPreset: TOptionsPreset): TInputOptions { return Options.getOptionsByPreset(optionsPreset); } } diff --git a/src/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.ts b/src/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.ts index 99c9b1db0..7e5d80960 100644 --- a/src/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.ts +++ b/src/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -72,8 +72,9 @@ export class CallsGraphAnalyzer implements ICallsGraphAnalyzer { */ private readonly calleeDataExtractorFactory: TCalleeDataExtractorFactory; - public constructor ( - @inject(ServiceIdentifiers.Factory__ICalleeDataExtractor) calleeDataExtractorFactory: TCalleeDataExtractorFactory + public constructor( + @inject(ServiceIdentifiers.Factory__ICalleeDataExtractor) + calleeDataExtractorFactory: TCalleeDataExtractorFactory ) { this.calleeDataExtractorFactory = calleeDataExtractorFactory; } @@ -82,16 +83,14 @@ export class CallsGraphAnalyzer implements ICallsGraphAnalyzer { * @param {number} blockScopeBodyLength * @returns {number} */ - public static getLimitIndex (blockScopeBodyLength: number): number { + public static getLimitIndex(blockScopeBodyLength: number): number { const lastIndex: number = blockScopeBodyLength - 1; const limitThresholdActivationIndex: number = CallsGraphAnalyzer.limitThresholdActivationLength - 1; let limitIndex: number = lastIndex; if (lastIndex > limitThresholdActivationIndex) { - limitIndex = Math.round( - limitThresholdActivationIndex + (lastIndex * CallsGraphAnalyzer.limitThreshold) - ); + limitIndex = Math.round(limitThresholdActivationIndex + lastIndex * CallsGraphAnalyzer.limitThreshold); if (limitIndex > lastIndex) { limitIndex = lastIndex; @@ -105,7 +104,7 @@ export class CallsGraphAnalyzer implements ICallsGraphAnalyzer { * @param {Program} astTree * @returns {ICallsGraphData[]} */ - public analyze (astTree: ESTree.Program): ICallsGraphData[] { + public analyze(astTree: ESTree.Program): ICallsGraphData[] { return this.analyzeRecursive(astTree.body); } @@ -113,7 +112,7 @@ export class CallsGraphAnalyzer implements ICallsGraphAnalyzer { * @param {NodeGuards[]} blockScopeBody * @returns {ICallsGraphData[]} */ - private analyzeRecursive (blockScopeBody: ESTree.Node[]): ICallsGraphData[] { + private analyzeRecursive(blockScopeBody: ESTree.Node[]): ICallsGraphData[] { const limitIndex: number = CallsGraphAnalyzer.getLimitIndex(blockScopeBody.length); const callsGraphData: ICallsGraphData[] = []; const blockScopeBodyLength: number = blockScopeBody.length; @@ -148,14 +147,16 @@ export class CallsGraphAnalyzer implements ICallsGraphAnalyzer { * @param {NodeGuards[]} blockScopeBody * @param {CallExpression} callExpressionNode */ - private analyzeCallExpressionNode ( + private analyzeCallExpressionNode( callsGraphData: ICallsGraphData[], blockScopeBody: ESTree.Node[], callExpressionNode: ESTree.CallExpression ): void { CallsGraphAnalyzer.calleeDataExtractorsList.forEach((calleeDataExtractorName: CalleeDataExtractor) => { - const calleeData: ICalleeData | null = this.calleeDataExtractorFactory(calleeDataExtractorName) - .extract(blockScopeBody, callExpressionNode.callee); + const calleeData: ICalleeData | null = this.calleeDataExtractorFactory(calleeDataExtractorName).extract( + blockScopeBody, + callExpressionNode.callee + ); if (!calleeData) { return; diff --git a/src/analyzers/calls-graph-analyzer/callee-data-extractors/AbstractCalleeDataExtractor.ts b/src/analyzers/calls-graph-analyzer/callee-data-extractors/AbstractCalleeDataExtractor.ts index 34381f6f1..444701c9a 100644 --- a/src/analyzers/calls-graph-analyzer/callee-data-extractors/AbstractCalleeDataExtractor.ts +++ b/src/analyzers/calls-graph-analyzer/callee-data-extractors/AbstractCalleeDataExtractor.ts @@ -12,5 +12,5 @@ export abstract class AbstractCalleeDataExtractor implements ICalleeDataExtracto * @param {Node} callee * @returns {ICalleeData} */ - public abstract extract (blockScopeBody: ESTree.Node[], callee: ESTree.Node): ICalleeData | null; + public abstract extract(blockScopeBody: ESTree.Node[], callee: ESTree.Node): ICalleeData | null; } diff --git a/src/analyzers/calls-graph-analyzer/callee-data-extractors/FunctionDeclarationCalleeDataExtractor.ts b/src/analyzers/calls-graph-analyzer/callee-data-extractors/FunctionDeclarationCalleeDataExtractor.ts index 8d7816462..2a3667155 100644 --- a/src/analyzers/calls-graph-analyzer/callee-data-extractors/FunctionDeclarationCalleeDataExtractor.ts +++ b/src/analyzers/calls-graph-analyzer/callee-data-extractors/FunctionDeclarationCalleeDataExtractor.ts @@ -16,7 +16,7 @@ export class FunctionDeclarationCalleeDataExtractor extends AbstractCalleeDataEx * @param {Identifier} callee * @returns {ICalleeData} */ - public extract (blockScopeBody: ESTree.Node[], callee: ESTree.Identifier): ICalleeData | null { + public extract(blockScopeBody: ESTree.Node[], callee: ESTree.Identifier): ICalleeData | null { if (!NodeGuards.isIdentifierNode(callee)) { return null; } @@ -41,7 +41,7 @@ export class FunctionDeclarationCalleeDataExtractor extends AbstractCalleeDataEx * @param {string} name * @returns {BlockStatement} */ - private getCalleeBlockStatement (targetNode: ESTree.Node, name: string): ESTree.BlockStatement | null { + private getCalleeBlockStatement(targetNode: ESTree.Node, name: string): ESTree.BlockStatement | null { let calleeBlockStatement: ESTree.BlockStatement | null = null; estraverse.traverse(targetNode, { diff --git a/src/analyzers/calls-graph-analyzer/callee-data-extractors/FunctionExpressionCalleeDataExtractor.ts b/src/analyzers/calls-graph-analyzer/callee-data-extractors/FunctionExpressionCalleeDataExtractor.ts index 606ca2384..a24cb5c04 100644 --- a/src/analyzers/calls-graph-analyzer/callee-data-extractors/FunctionExpressionCalleeDataExtractor.ts +++ b/src/analyzers/calls-graph-analyzer/callee-data-extractors/FunctionExpressionCalleeDataExtractor.ts @@ -16,7 +16,10 @@ export class FunctionExpressionCalleeDataExtractor extends AbstractCalleeDataExt * @param {Identifier} callee * @returns {ICalleeData} */ - public extract (blockScopeBody: ESTree.Node[], callee: ESTree.Identifier | ESTree.FunctionExpression): ICalleeData | null { + public extract( + blockScopeBody: ESTree.Node[], + callee: ESTree.Identifier | ESTree.FunctionExpression + ): ICalleeData | null { let calleeName: string | null = null; let calleeBlockStatement: ESTree.BlockStatement | null = null; @@ -46,7 +49,7 @@ export class FunctionExpressionCalleeDataExtractor extends AbstractCalleeDataExt * @param {string} name * @returns {BlockStatement} */ - private getCalleeBlockStatement (targetNode: ESTree.Node, name: string): ESTree.BlockStatement | null { + private getCalleeBlockStatement(targetNode: ESTree.Node, name: string): ESTree.BlockStatement | null { let calleeBlockStatement: ESTree.BlockStatement | null = null; estraverse.traverse(targetNode, { diff --git a/src/analyzers/calls-graph-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor.ts b/src/analyzers/calls-graph-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor.ts index 1fabd1da7..57e22783e 100644 --- a/src/analyzers/calls-graph-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor.ts +++ b/src/analyzers/calls-graph-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor.ts @@ -18,7 +18,10 @@ export class ObjectExpressionCalleeDataExtractor extends AbstractCalleeDataExtra * @param {string | number} nextItemInCallsChain * @returns {boolean} */ - private static isValidTargetPropertyNode (propertyNode: ESTree.Property, nextItemInCallsChain: string | number): boolean { + private static isValidTargetPropertyNode( + propertyNode: ESTree.Property, + nextItemInCallsChain: string | number + ): boolean { if (!propertyNode.key) { return false; } @@ -38,7 +41,7 @@ export class ObjectExpressionCalleeDataExtractor extends AbstractCalleeDataExtra * @param {MemberExpression} callee * @returns {ICalleeData} */ - public extract (blockScopeBody: ESTree.Node[], callee: ESTree.MemberExpression): ICalleeData | null { + public extract(blockScopeBody: ESTree.Node[], callee: ESTree.MemberExpression): ICalleeData | null { if (!NodeGuards.isMemberExpressionNode(callee)) { return null; } @@ -49,7 +52,8 @@ export class ObjectExpressionCalleeDataExtractor extends AbstractCalleeDataExtra return null; } - const functionExpressionName: string | number | null = objectMembersCallsChain[objectMembersCallsChain.length - 1]; + const functionExpressionName: string | number | null = + objectMembersCallsChain[objectMembersCallsChain.length - 1]; const calleeBlockStatement: ESTree.BlockStatement | null = this.getCalleeBlockStatement( NodeStatementUtils.getParentNodeWithStatements(blockScopeBody[0]), objectMembersCallsChain @@ -74,7 +78,7 @@ export class ObjectExpressionCalleeDataExtractor extends AbstractCalleeDataExtra * @param {MemberExpression} memberExpression * @returns {TObjectMembersCallsChain} */ - private createObjectMembersCallsChain ( + private createObjectMembersCallsChain( currentChain: TObjectMembersCallsChain, memberExpression: ESTree.MemberExpression ): TObjectMembersCallsChain { @@ -83,10 +87,7 @@ export class ObjectExpressionCalleeDataExtractor extends AbstractCalleeDataExtra currentChain.unshift(memberExpression.property.name); } else if ( NodeGuards.isLiteralNode(memberExpression.property) && - ( - typeof memberExpression.property.value === 'string' || - typeof memberExpression.property.value === 'number' - ) + (typeof memberExpression.property.value === 'string' || typeof memberExpression.property.value === 'number') ) { currentChain.unshift(memberExpression.property.value); } else { @@ -108,7 +109,7 @@ export class ObjectExpressionCalleeDataExtractor extends AbstractCalleeDataExtra * @param {TObjectMembersCallsChain} objectMembersCallsChain * @returns {BlockStatement} */ - private getCalleeBlockStatement ( + private getCalleeBlockStatement( targetNode: ESTree.Node, objectMembersCallsChain: TObjectMembersCallsChain ): ESTree.BlockStatement | null { @@ -144,7 +145,7 @@ export class ObjectExpressionCalleeDataExtractor extends AbstractCalleeDataExtra * @param {TObjectMembersCallsChain} objectMembersCallsChain * @returns {BlockStatement} */ - private findCalleeBlockStatement ( + private findCalleeBlockStatement( objectExpressionProperties: (ESTree.Property | ESTree.SpreadElement)[], objectMembersCallsChain: TObjectMembersCallsChain ): ESTree.BlockStatement | null { diff --git a/src/analyzers/number-numerical-expression-analyzer/NumberNumericalExpressionAnalyzer.ts b/src/analyzers/number-numerical-expression-analyzer/NumberNumericalExpressionAnalyzer.ts index 79efad5c9..557e3bed5 100644 --- a/src/analyzers/number-numerical-expression-analyzer/NumberNumericalExpressionAnalyzer.ts +++ b/src/analyzers/number-numerical-expression-analyzer/NumberNumericalExpressionAnalyzer.ts @@ -37,9 +37,7 @@ export class NumberNumericalExpressionAnalyzer implements INumberNumericalExpres /** * @param {IRandomGenerator} randomGenerator */ - public constructor ( - @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator - ) { + public constructor(@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator) { this.randomGenerator = randomGenerator; } @@ -48,10 +46,7 @@ export class NumberNumericalExpressionAnalyzer implements INumberNumericalExpres * @param {number} additionalPartsCount * @returns {TNumberNumericalExpressionData} */ - public analyze ( - number: number, - additionalPartsCount: number - ): TNumberNumericalExpressionData { + public analyze(number: number, additionalPartsCount: number): TNumberNumericalExpressionData { if (isNaN(number)) { throw new Error('Given value is NaN'); } @@ -70,7 +65,7 @@ export class NumberNumericalExpressionAnalyzer implements INumberNumericalExpres * @param {number} additionalPartsCount * @returns {number[]} */ - private generateAdditionParts (number: number, additionalPartsCount: number): number[] { + private generateAdditionParts(number: number, additionalPartsCount: number): number[] { const additionParts = []; const upperNumberLimit: number = Math.min(Math.abs(number * 2), Number.MAX_SAFE_INTEGER); @@ -115,7 +110,7 @@ export class NumberNumericalExpressionAnalyzer implements INumberNumericalExpres * @param {number} number * @returns {number | number[]} */ - private mixWithMultiplyParts (number: number): number | number[] { + private mixWithMultiplyParts(number: number): number | number[] { const shouldMixWithMultiplyParts: boolean = this.randomGenerator.getMathRandom() > 0.5; if (!shouldMixWithMultiplyParts || number === 0) { @@ -125,8 +120,8 @@ export class NumberNumericalExpressionAnalyzer implements INumberNumericalExpres let factors: number[] | null = this.numberFactorsMap.get(number) ?? null; if (!factors) { - factors = NumberUtils.getFactors(number); - this.numberFactorsMap.set(number, factors); + factors = NumberUtils.getFactors(number); + this.numberFactorsMap.set(number, factors); } if (!factors.length) { diff --git a/src/analyzers/prevailing-kind-of-variables-analyzer/PrevailingKindOfVariablesAnalyzer.ts b/src/analyzers/prevailing-kind-of-variables-analyzer/PrevailingKindOfVariablesAnalyzer.ts index c3e2fa623..cbfb43f50 100644 --- a/src/analyzers/prevailing-kind-of-variables-analyzer/PrevailingKindOfVariablesAnalyzer.ts +++ b/src/analyzers/prevailing-kind-of-variables-analyzer/PrevailingKindOfVariablesAnalyzer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -24,18 +24,17 @@ export class PrevailingKindOfVariablesAnalyzer implements IPrevailingKindOfVaria /** * @type {ESTree.VariableDeclaration['kind']} */ - private prevailingKindOfVariables: ESTree.VariableDeclaration['kind'] = PrevailingKindOfVariablesAnalyzer.defaultKindOfVariables; + private prevailingKindOfVariables: ESTree.VariableDeclaration['kind'] = + PrevailingKindOfVariablesAnalyzer.defaultKindOfVariables; - public constructor ( - @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils - ) { + public constructor(@inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils) { this.arrayUtils = arrayUtils; } /** * @param {Program} astTree */ - public analyze (astTree: ESTree.Program): void { + public analyze(astTree: ESTree.Program): void { const variableKinds: ESTree.VariableDeclaration['kind'][] = []; estraverse.traverse(astTree, { @@ -48,14 +47,15 @@ export class PrevailingKindOfVariablesAnalyzer implements IPrevailingKindOfVaria } }); - this.prevailingKindOfVariables = this.arrayUtils.findMostOccurringElement(variableKinds) - ?? PrevailingKindOfVariablesAnalyzer.defaultKindOfVariables; + this.prevailingKindOfVariables = + this.arrayUtils.findMostOccurringElement(variableKinds) ?? + PrevailingKindOfVariablesAnalyzer.defaultKindOfVariables; } /** * @returns {VariableDeclaration["kind"]} */ - public getPrevailingKind (): ESTree.VariableDeclaration['kind'] { + public getPrevailingKind(): ESTree.VariableDeclaration['kind'] { return this.prevailingKindOfVariables; } } diff --git a/src/analyzers/scope-analyzer/ScopeAnalyzer.ts b/src/analyzers/scope-analyzer/ScopeAnalyzer.ts index f4ea1f2c0..169e33397 100644 --- a/src/analyzers/scope-analyzer/ScopeAnalyzer.ts +++ b/src/analyzers/scope-analyzer/ScopeAnalyzer.ts @@ -1,4 +1,4 @@ -import { injectable, } from 'inversify'; +import { injectable } from 'inversify'; import * as acorn from 'acorn'; import * as eslintScope from 'eslint-scope'; @@ -28,10 +28,7 @@ export class ScopeAnalyzer implements IScopeAnalyzer { /** * @type {acorn.Options['sourceType'][]} */ - private static readonly sourceTypes: acorn.Options['sourceType'][] = [ - 'script', - 'module' - ]; + private static readonly sourceTypes: acorn.Options['sourceType'][] = ['script', 'module']; /** * @type {number} @@ -49,7 +46,7 @@ export class ScopeAnalyzer implements IScopeAnalyzer { * * @param {Node} astTree */ - private static attachMissingRanges (astTree: ESTree.Node): void { + private static attachMissingRanges(astTree: ESTree.Node): void { estraverse.replace(astTree, { enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node => { if (!node.range) { @@ -68,14 +65,14 @@ export class ScopeAnalyzer implements IScopeAnalyzer { * @param {Node} node * @returns {boolean} */ - private static isRootNode (node: ESTree.Node): boolean { + private static isRootNode(node: ESTree.Node): boolean { return NodeGuards.isProgramNode(node) || node.parentNode === node; } /** * @param {Program} astTree */ - public analyze (astTree: ESTree.Node): void { + public analyze(astTree: ESTree.Node): void { const sourceTypeLength: number = ScopeAnalyzer.sourceTypes.length; ScopeAnalyzer.attachMissingRanges(astTree); @@ -104,15 +101,12 @@ export class ScopeAnalyzer implements IScopeAnalyzer { * @param {Node} node * @returns {Scope} */ - public acquireScope (node: ESTree.Node): eslintScope.Scope { + public acquireScope(node: ESTree.Node): eslintScope.Scope { if (!this.scopeManager) { throw new Error('Scope manager is not defined'); } - const scope: eslintScope.Scope | null = this.scopeManager.acquire( - node, - ScopeAnalyzer.isRootNode(node) - ); + const scope: eslintScope.Scope | null = this.scopeManager.acquire(node, ScopeAnalyzer.isRootNode(node)); if (!scope) { throw new Error('Cannot acquire scope for node'); @@ -126,7 +120,7 @@ export class ScopeAnalyzer implements IScopeAnalyzer { /** * @param {Scope} scope */ - private sanitizeScopes (scope: eslintScope.Scope): void { + private sanitizeScopes(scope: eslintScope.Scope): void { scope.childScopes.forEach((childScope: eslintScope.Scope) => { // fix of class scopes // trying to move class scope references to the parent scope @@ -138,13 +132,15 @@ export class ScopeAnalyzer implements IScopeAnalyzer { // class name variable is always first const classNameVariable: eslintScope.Variable = childScope.variables[0]; - const upperVariable: eslintScope.Variable | undefined = childScope.upper.variables - .find((variable: eslintScope.Variable) => { - const isValidClassNameVariable: boolean = classNameVariable.defs - .some((definition: eslintScope.Definition) => definition.type === 'ClassName'); + const upperVariable: eslintScope.Variable | undefined = childScope.upper.variables.find( + (variable: eslintScope.Variable) => { + const isValidClassNameVariable: boolean = classNameVariable.defs.some( + (definition: eslintScope.Definition) => definition.type === 'ClassName' + ); return isValidClassNameVariable && variable.name === classNameVariable.name; - }); + } + ); upperVariable?.references.push(...childScope.variables[0].references); } diff --git a/src/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.ts b/src/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.ts index f10acb78d..c6cce7c3b 100644 --- a/src/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.ts +++ b/src/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -51,10 +51,10 @@ export class StringArrayStorageAnalyzer implements IStringArrayStorageAnalyzer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, - @inject(ServiceIdentifiers.IOptions) options: IOptions, + @inject(ServiceIdentifiers.IOptions) options: IOptions ) { this.stringArrayStorage = stringArrayStorage; this.randomGenerator = randomGenerator; @@ -64,7 +64,7 @@ export class StringArrayStorageAnalyzer implements IStringArrayStorageAnalyzer { /** * @param {Program} astTree */ - public analyze (astTree: ESTree.Program): void { + public analyze(astTree: ESTree.Program): void { if (!this.options.stringArray) { return; } @@ -92,7 +92,7 @@ export class StringArrayStorageAnalyzer implements IStringArrayStorageAnalyzer { * @param {Literal} literalNode * @param {Node} parentNode */ - public analyzeLiteralNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): void { + public analyzeLiteralNode(literalNode: ESTree.Literal, parentNode: ESTree.Node): void { if (!NodeLiteralUtils.isStringLiteralNode(literalNode)) { return; } @@ -111,18 +111,15 @@ export class StringArrayStorageAnalyzer implements IStringArrayStorageAnalyzer { /** * @param {TStringLiteralNode} literalNode */ - public addItemDataForLiteralNode (literalNode: TStringLiteralNode): void { - this.stringArrayStorageData.set( - literalNode, - this.stringArrayStorage.getOrThrow(literalNode.value) - ); + public addItemDataForLiteralNode(literalNode: TStringLiteralNode): void { + this.stringArrayStorageData.set(literalNode, this.stringArrayStorage.getOrThrow(literalNode.value)); } /** * @param {Literal} literalNode * @returns {IStringArrayStorageItemData | undefined} */ - public getItemDataForLiteralNode (literalNode: ESTree.Literal): IStringArrayStorageItemData | undefined { + public getItemDataForLiteralNode(literalNode: ESTree.Literal): IStringArrayStorageItemData | undefined { return this.stringArrayStorageData.get(literalNode); } @@ -130,15 +127,17 @@ export class StringArrayStorageAnalyzer implements IStringArrayStorageAnalyzer { * @param {TStringLiteralNode} literalNode * @returns {boolean} */ - private shouldAddValueToStringArray (literalNode: TStringLiteralNode): boolean { + private shouldAddValueToStringArray(literalNode: TStringLiteralNode): boolean { const isForceTransformNode: boolean = NodeMetadata.isForceTransformNode(literalNode); if (isForceTransformNode) { return true; } - return literalNode.value.length >= StringArrayStorageAnalyzer.minimumLengthForStringArray - && !!this.options.stringArrayThreshold - && this.randomGenerator.getMathRandom() <= this.options.stringArrayThreshold; + return ( + literalNode.value.length >= StringArrayStorageAnalyzer.minimumLengthForStringArray && + !!this.options.stringArrayThreshold && + this.randomGenerator.getMathRandom() <= this.options.stringArrayThreshold + ); } } diff --git a/src/cli/JavaScriptObfuscatorCLI.ts b/src/cli/JavaScriptObfuscatorCLI.ts index 8a7621d4c..9d905accd 100644 --- a/src/cli/JavaScriptObfuscatorCLI.ts +++ b/src/cli/JavaScriptObfuscatorCLI.ts @@ -39,11 +39,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { /** * @type {string[]} */ - public static readonly availableInputExtensions: string[] = [ - '.js', - '.mjs', - '.cjs' - ]; + public static readonly availableInputExtensions: string[] = ['.js', '.mjs', '.cjs']; /** * @type {BufferEncoding} @@ -104,7 +100,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { /** * @param {string[]} argv */ - public constructor (argv: string[]) { + public constructor(argv: string[]) { this.rawArguments = argv; this.arguments = argv.slice(2); } @@ -113,7 +109,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { * @param {TInputCLIOptions} inputOptions * @returns {TInputOptions} */ - private static buildOptions (inputOptions: TInputCLIOptions): TInputOptions { + private static buildOptions(inputOptions: TInputCLIOptions): TInputOptions { const inputCLIOptions: TInputOptions = JavaScriptObfuscatorCLI.filterOptions(inputOptions); const configFilePath: string | undefined = inputOptions.config; const configFileLocation: string = configFilePath ? path.resolve(configFilePath, '.') : ''; @@ -130,23 +126,21 @@ export class JavaScriptObfuscatorCLI implements IInitializable { * @param {TObject} options * @returns {TInputOptions} */ - private static filterOptions (options: TInputCLIOptions): TInputOptions { + private static filterOptions(options: TInputCLIOptions): TInputOptions { const filteredOptions: TInputOptions = {}; - Object - .keys(options) - .forEach((option: keyof TInputCLIOptions) => { - if (options[option] === undefined) { - return; - } + Object.keys(options).forEach((option: keyof TInputCLIOptions) => { + if (options[option] === undefined) { + return; + } - filteredOptions[option] = options[option]; - }); + filteredOptions[option] = options[option]; + }); return filteredOptions; } - public initialize (): void { + public initialize(): void { this.commands = new commander.Command(); this.configureCommands(); @@ -154,18 +148,14 @@ export class JavaScriptObfuscatorCLI implements IInitializable { this.inputPath = path.normalize(this.commands.args[0] || ''); this.inputCLIOptions = JavaScriptObfuscatorCLI.buildOptions(this.commands.opts()); - this.sourceCodeFileUtils = new SourceCodeFileUtils( - this.inputPath, - this.inputCLIOptions - ); - this.obfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - this.inputPath, - this.inputCLIOptions + this.sourceCodeFileUtils = new SourceCodeFileUtils(this.inputPath, this.inputCLIOptions); + this.obfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(this.inputPath, this.inputCLIOptions); + this.identifierNamesCacheFileUtils = new IdentifierNamesCacheFileUtils( + this.inputCLIOptions.identifierNamesCachePath ); - this.identifierNamesCacheFileUtils = new IdentifierNamesCacheFileUtils(this.inputCLIOptions.identifierNamesCachePath); } - public run (): void { + public run(): void { const canShowHelp: boolean = !this.arguments.length || this.arguments.includes('--help'); if (canShowHelp) { @@ -179,41 +169,20 @@ export class JavaScriptObfuscatorCLI implements IInitializable { this.processSourceCodeData(sourceCodeData); } - private configureCommands (): void { + private configureCommands(): void { this.commands .usage(' [options]') - .version( - Utils.buildVersionMessage(process.env.VERSION, process.env.BUILD_TIMESTAMP), - '-v, --version' - ) - .option( - '-o, --output ', - 'Output path for obfuscated code' - ) - .option( - '--compact ', - 'Disable one line output code compacting', - BooleanSanitizer - ) - .option( - '--config ', - 'Name of js / json config file' - ) - .option( - '--control-flow-flattening ', - 'Enables control flow flattening', - BooleanSanitizer - ) + .version(Utils.buildVersionMessage(process.env.VERSION, process.env.BUILD_TIMESTAMP), '-v, --version') + .option('-o, --output ', 'Output path for obfuscated code') + .option('--compact ', 'Disable one line output code compacting', BooleanSanitizer) + .option('--config ', 'Name of js / json config file') + .option('--control-flow-flattening ', 'Enables control flow flattening', BooleanSanitizer) .option( '--control-flow-flattening-threshold ', 'The probability that the control flow flattening transformation will be applied to the node', parseFloat ) - .option( - '--dead-code-injection ', - 'Enables dead code injection', - BooleanSanitizer - ) + .option('--dead-code-injection ', 'Enables dead code injection', BooleanSanitizer) .option( '--dead-code-injection-threshold ', 'The probability that the dead code injection transformation will be applied to the node', @@ -241,7 +210,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { ) .option( '--domain-lock-redirect-url ', - 'Allows the browser to be redirected to a passed URL if the source code isn\'t run on the domains specified by --domain-lock', + 'Allows the browser to be redirected to a passed URL if the source code isn\'t run on the domains specified by --domain-lock' ) .option( '--exclude (comma separated, without whitespaces)', @@ -253,42 +222,31 @@ export class JavaScriptObfuscatorCLI implements IInitializable { 'Enables force transformation of string literals, which being matched by passed RegExp patterns (comma separated)', ArraySanitizer ) - .option( - '--identifier-names-cache-path ', - 'Sets path for identifier names cache' - ) + .option('--identifier-names-cache-path ', 'Sets path for identifier names cache') .option( '--identifier-names-generator ', 'Sets identifier names generator. ' + - `Values: ${CLIUtils.stringifyOptionAvailableValues(IdentifierNamesGenerator)}. ` + - `Default: ${IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator}` - ) - .option( - '--identifiers-prefix ', - 'Sets prefix for all global identifiers' + `Values: ${CLIUtils.stringifyOptionAvailableValues(IdentifierNamesGenerator)}. ` + + `Default: ${IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator}` ) + .option('--identifiers-prefix ', 'Sets prefix for all global identifiers') .option( '--identifiers-dictionary (comma separated, without whitespaces)', 'Identifiers dictionary (comma separated) for `--identifier-names-generator dictionary` option', ArraySanitizer ) .option( - '--ignore-imports ', 'Prevents obfuscation of `require` and `dynamic` imports', - BooleanSanitizer - ) - .option( - '--log ', 'Enables logging of the information to the console', - BooleanSanitizer - ) - .option( - '--numbers-to-expressions ', 'Enables numbers conversion to expressions', + '--ignore-imports ', + 'Prevents obfuscation of `require` and `dynamic` imports', BooleanSanitizer ) + .option('--log ', 'Enables logging of the information to the console', BooleanSanitizer) + .option('--numbers-to-expressions ', 'Enables numbers conversion to expressions', BooleanSanitizer) .option( '--options-preset ', 'Allows to set options preset. ' + - `Values: ${CLIUtils.stringifyOptionAvailableValues(OptionsPreset)}. ` + - `Default: ${OptionsPreset.Default}` + `Values: ${CLIUtils.stringifyOptionAvailableValues(OptionsPreset)}. ` + + `Default: ${OptionsPreset.Default}` ) .option( '--reserved-names (comma separated, without whitespaces)', @@ -301,38 +259,33 @@ export class JavaScriptObfuscatorCLI implements IInitializable { ArraySanitizer ) .option( - '--rename-globals ', 'Allows to enable obfuscation of global variable and function names with declaration', + '--rename-globals ', + 'Allows to enable obfuscation of global variable and function names with declaration', BooleanSanitizer ) .option( - '--rename-properties ', 'UNSAFE: Enables renaming of property names. This probably MAY break your code', + '--rename-properties ', + 'UNSAFE: Enables renaming of property names. This probably MAY break your code', BooleanSanitizer ) .option( '--rename-properties-mode ', 'Specify `--rename-properties` option mode. ' + - `Values: ${CLIUtils.stringifyOptionAvailableValues(RenamePropertiesMode)}. ` + - `Default: ${RenamePropertiesMode.Safe}` + `Values: ${CLIUtils.stringifyOptionAvailableValues(RenamePropertiesMode)}. ` + + `Default: ${RenamePropertiesMode.Safe}` ) .option( '--seed ', 'Sets seed for random generator. This is useful for creating repeatable results.', parseFloat ) + .option('--self-defending ', 'Disables self-defending for obfuscated code', BooleanSanitizer) .option( - '--self-defending ', - 'Disables self-defending for obfuscated code', - BooleanSanitizer - ) - .option( - '--simplify ', 'Enables additional code obfuscation through simplification', - BooleanSanitizer - ) - .option( - '--source-map ', - 'Enables source map generation', + '--simplify ', + 'Enables additional code obfuscation through simplification', BooleanSanitizer ) + .option('--source-map ', 'Enables source map generation', BooleanSanitizer) .option( '--source-map-base-url ', 'Sets base url to the source map import url when `--source-map-mode=separate`' @@ -344,25 +297,21 @@ export class JavaScriptObfuscatorCLI implements IInitializable { .option( '--source-map-mode ', 'Specify source map output mode. ' + - `Values: ${CLIUtils.stringifyOptionAvailableValues(SourceMapMode)}. ` + - `Default: ${SourceMapMode.Separate}` + `Values: ${CLIUtils.stringifyOptionAvailableValues(SourceMapMode)}. ` + + `Default: ${SourceMapMode.Separate}` ) .option( '--source-map-sources-mode ', 'Specify source map sources mode. ' + - `Values: ${CLIUtils.stringifyOptionAvailableValues(SourceMapSourcesMode)}. ` + - `Default: ${SourceMapSourcesMode.SourcesContent}` + `Values: ${CLIUtils.stringifyOptionAvailableValues(SourceMapSourcesMode)}. ` + + `Default: ${SourceMapSourcesMode.SourcesContent}` ) .option( '--split-strings ', 'Splits literal strings into chunks with length of `splitStringsChunkLength` option value', BooleanSanitizer ) - .option( - '--split-strings-chunk-length ', - 'Sets chunk length of `splitStrings` option', - parseFloat - ) + .option('--split-strings-chunk-length ', 'Sets chunk length of `splitStrings` option', parseFloat) .option( '--string-array ', 'Enables gathering of all literal strings into an array and replacing every literal string with an array call', @@ -381,15 +330,15 @@ export class JavaScriptObfuscatorCLI implements IInitializable { .option( '--string-array-encoding (comma separated, without whitespaces)', 'Encodes each string in strings array using base64 or rc4 (this option can slow down your code speed). ' + - `Values: ${CLIUtils.stringifyOptionAvailableValues(StringArrayEncoding)}. ` + - `Default: ${StringArrayEncoding.None}`, + `Values: ${CLIUtils.stringifyOptionAvailableValues(StringArrayEncoding)}. ` + + `Default: ${StringArrayEncoding.None}`, ArraySanitizer ) .option( '--string-array-indexes-type (comma separated, without whitespaces)', 'Encodes each string in strings array using base64 or rc4 (this option can slow down your code speed). ' + - `Values: ${CLIUtils.stringifyOptionAvailableValues(StringArrayIndexesType)}. ` + - `Default: ${StringArrayIndexesType.HexadecimalNumber}`, + `Values: ${CLIUtils.stringifyOptionAvailableValues(StringArrayIndexesType)}. ` + + `Default: ${StringArrayIndexesType.HexadecimalNumber}`, ArraySanitizer ) .option( @@ -398,13 +347,11 @@ export class JavaScriptObfuscatorCLI implements IInitializable { BooleanSanitizer ) .option( - '--string-array-rotate ', 'Enable rotation of string array values during obfuscation', - BooleanSanitizer - ) - .option( - '--string-array-shuffle ', 'Randomly shuffles string array items', + '--string-array-rotate ', + 'Enable rotation of string array values during obfuscation', BooleanSanitizer ) + .option('--string-array-shuffle ', 'Randomly shuffles string array items', BooleanSanitizer) .option( '--string-array-wrappers-count ', 'Sets the count of wrappers for the string array inside each root or function scope', @@ -423,8 +370,8 @@ export class JavaScriptObfuscatorCLI implements IInitializable { .option( '--string-array-wrappers-type ', 'Allows to select a type of the wrappers that are appending by the `--string-array-wrappers-count` option. ' + - `Values: ${CLIUtils.stringifyOptionAvailableValues(StringArrayWrappersType)}. ` + - `Default: ${StringArrayWrappersType.Variable}` + `Values: ${CLIUtils.stringifyOptionAvailableValues(StringArrayWrappersType)}. ` + + `Default: ${StringArrayWrappersType.Variable}` ) .option( '--string-array-threshold ', @@ -434,14 +381,10 @@ export class JavaScriptObfuscatorCLI implements IInitializable { .option( '--target ', 'Allows to set target environment for obfuscated code. ' + - `Values: ${CLIUtils.stringifyOptionAvailableValues(ObfuscationTarget)}. ` + - `Default: ${ObfuscationTarget.Browser}` - ) - .option( - '--transform-object-keys ', - 'Enables transformation of object keys', - BooleanSanitizer + `Values: ${CLIUtils.stringifyOptionAvailableValues(ObfuscationTarget)}. ` + + `Default: ${ObfuscationTarget.Browser}` ) + .option('--transform-object-keys ', 'Enables transformation of object keys', BooleanSanitizer) .option( '--unicode-escape-sequence ', 'Allows to enable/disable string conversion to unicode escape sequence', @@ -450,11 +393,13 @@ export class JavaScriptObfuscatorCLI implements IInitializable { .parse(this.rawArguments); } - private configureHelp (): void { + private configureHelp(): void { this.commands.on('--help', () => { console.log(' Examples:\n'); console.log(' %> javascript-obfuscator input_file_name.js --compact true --self-defending false'); - console.log(' %> javascript-obfuscator input_file_name.js --output output_file_name.js --compact true --self-defending false'); + console.log( + ' %> javascript-obfuscator input_file_name.js --output output_file_name.js --compact true --self-defending false' + ); console.log(' %> javascript-obfuscator input_directory_name --compact true --self-defending false'); console.log(''); }); @@ -463,24 +408,16 @@ export class JavaScriptObfuscatorCLI implements IInitializable { /** * @param {IFileData[]} sourceCodeData */ - private processSourceCodeData (sourceCodeData: IFileData[]): void { + private processSourceCodeData(sourceCodeData: IFileData[]): void { sourceCodeData.forEach(({ filePath, content }: IFileData, index: number) => { const outputCodePath: string = this.obfuscatedCodeFileUtils.getOutputCodePath(filePath); try { - Logger.log( - Logger.colorInfo, - LoggingPrefix.CLI, - `Obfuscating file: ${filePath}...` - ); + Logger.log(Logger.colorInfo, LoggingPrefix.CLI, `Obfuscating file: ${filePath}...`); this.processSourceCode(content, filePath, outputCodePath, index); } catch (error) { - Logger.log( - Logger.colorInfo, - LoggingPrefix.CLI, - `Error in file: ${filePath}...` - ); + Logger.log(Logger.colorInfo, LoggingPrefix.CLI, `Error in file: ${filePath}...`); throw error; } @@ -493,7 +430,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { * @param {string} outputCodePath * @param {number | null} sourceCodeIndex */ - private processSourceCode ( + private processSourceCode( sourceCode: string, inputCodePath: string, outputCodePath: string, @@ -503,12 +440,12 @@ export class JavaScriptObfuscatorCLI implements IInitializable { ...this.inputCLIOptions, identifierNamesCache: this.identifierNamesCacheFileUtils.readFile(), inputFileName: path.basename(inputCodePath), - ...sourceCodeIndex !== null && { + ...(sourceCodeIndex !== null && { identifiersPrefix: Utils.getIdentifiersPrefixForMultipleSources( this.inputCLIOptions.identifiersPrefix, sourceCodeIndex ) - } + }) }; if (options.sourceMap) { @@ -523,7 +460,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { * @param {string} outputCodePath * @param {TInputOptions} options */ - private processSourceCodeWithoutSourceMap ( + private processSourceCodeWithoutSourceMap( sourceCode: string, outputCodePath: string, options: TInputOptions @@ -539,11 +476,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { * @param {string} outputCodePath * @param {TInputOptions} options */ - private processSourceCodeWithSourceMap ( - sourceCode: string, - outputCodePath: string, - options: TInputOptions - ): void { + private processSourceCodeWithSourceMap(sourceCode: string, outputCodePath: string, options: TInputOptions): void { const outputSourceMapPath: string = this.obfuscatedCodeFileUtils.getOutputSourceMapPath( outputCodePath, options.sourceMapFileName ?? '' diff --git a/src/cli/sanitizers/ArraySanitizer.ts b/src/cli/sanitizers/ArraySanitizer.ts index c52ff71a9..07b2e5632 100644 --- a/src/cli/sanitizers/ArraySanitizer.ts +++ b/src/cli/sanitizers/ArraySanitizer.ts @@ -4,9 +4,11 @@ import { TCLISanitizer } from '../../types/cli/TCLISanitizer'; * @param {string} value * @returns {string[]} */ -export const ArraySanitizer: TCLISanitizer = (value: string): string[] => { +export const ArraySanitizer: TCLISanitizer = (value: string): string[] => { if (value.endsWith(',')) { - throw new SyntaxError('Multiple values should be wrapped inside quotes: --option-name \'value1\',\'value2\''); + throw new SyntaxError( + "Multiple values should be wrapped inside quotes: --option-name 'value1','value2'" + ); } return value.split(',').map((string: string) => string.trim()); diff --git a/src/cli/sanitizers/BooleanSanitizer.ts b/src/cli/sanitizers/BooleanSanitizer.ts index 2bbfb2223..2e58866a5 100644 --- a/src/cli/sanitizers/BooleanSanitizer.ts +++ b/src/cli/sanitizers/BooleanSanitizer.ts @@ -4,6 +4,6 @@ import { TCLISanitizer } from '../../types/cli/TCLISanitizer'; * @param {string} value * @returns {boolean} */ -export const BooleanSanitizer: TCLISanitizer = (value: string): boolean => { +export const BooleanSanitizer: TCLISanitizer = (value: string): boolean => { return value === 'true' || value === '1'; }; diff --git a/src/cli/utils/CLIUtils.ts b/src/cli/utils/CLIUtils.ts index 50ce31869..4dcc4a860 100644 --- a/src/cli/utils/CLIUtils.ts +++ b/src/cli/utils/CLIUtils.ts @@ -8,17 +8,13 @@ export class CLIUtils { /** * @type {string[]} */ - public static readonly allowedConfigFileExtensions: string[] = [ - '.js', - '.json', - '.cjs' - ]; + public static readonly allowedConfigFileExtensions: string[] = ['.js', '.json', '.cjs']; /** * @param {string} configPath * @returns {TDictionary} */ - public static getUserConfig (configPath: string): TDictionary { + public static getUserConfig(configPath: string): TDictionary { let config: TDictionary; const configFileExtension: string = path.extname(configPath); @@ -45,7 +41,7 @@ export class CLIUtils { * @param {TDictionary} optionEnum * @returns {string} */ - public static stringifyOptionAvailableValues (optionEnum: TDictionary): string { + public static stringifyOptionAvailableValues(optionEnum: TDictionary): string { return Object.values(optionEnum).join(`${StringSeparator.Comma} `); } } diff --git a/src/cli/utils/IdentifierNamesCacheFileUtils.ts b/src/cli/utils/IdentifierNamesCacheFileUtils.ts index f7f76808a..47170dea0 100644 --- a/src/cli/utils/IdentifierNamesCacheFileUtils.ts +++ b/src/cli/utils/IdentifierNamesCacheFileUtils.ts @@ -24,7 +24,7 @@ export class IdentifierNamesCacheFileUtils { /** * @param {string} identifierNamesCachePath */ - public constructor (identifierNamesCachePath: string | undefined) { + public constructor(identifierNamesCachePath: string | undefined) { this.identifierNamesCachePath = identifierNamesCachePath; } @@ -32,10 +32,12 @@ export class IdentifierNamesCacheFileUtils { * @param {string} filePath * @returns {boolean} */ - private static isValidFilePath (filePath: string): boolean { + private static isValidFilePath(filePath: string): boolean { try { - return fs.statSync(filePath).isFile() - && path.extname(filePath) === IdentifierNamesCacheFileUtils.identifierNamesCacheExtension; + return ( + fs.statSync(filePath).isFile() && + path.extname(filePath) === IdentifierNamesCacheFileUtils.identifierNamesCacheExtension + ); } catch { return false; } @@ -45,7 +47,7 @@ export class IdentifierNamesCacheFileUtils { * @param {string} filePath * @returns {IFileData} */ - private static readFile (filePath: string): IFileData { + private static readFile(filePath: string): IFileData { return { filePath: path.normalize(filePath), content: fs.readFileSync(filePath, JavaScriptObfuscatorCLI.encoding) @@ -55,15 +57,17 @@ export class IdentifierNamesCacheFileUtils { /** * @returns {TIdentifierNamesCache | null} */ - public readFile (): TIdentifierNamesCache | null { + public readFile(): TIdentifierNamesCache | null { if (!this.identifierNamesCachePath) { return null; } if (!IdentifierNamesCacheFileUtils.isValidFilePath(this.identifierNamesCachePath)) { - throw new ReferenceError(`Given identifier names cache path must be a valid ${ - IdentifierNamesCacheFileUtils.identifierNamesCacheExtension - } file path`); + throw new ReferenceError( + `Given identifier names cache path must be a valid ${ + IdentifierNamesCacheFileUtils.identifierNamesCacheExtension + } file path` + ); } const fileData: IFileData = IdentifierNamesCacheFileUtils.readFile(this.identifierNamesCachePath); @@ -77,14 +81,16 @@ export class IdentifierNamesCacheFileUtils { // Already written identifier names cache file return JSON.parse(fileData.content); } catch { - throw new ReferenceError('Identifier names cache file must contains a json dictionary with identifier names'); + throw new ReferenceError( + 'Identifier names cache file must contains a json dictionary with identifier names' + ); } } /** * @param {TIdentifierNamesCache} identifierNamesCache */ - public writeFile (identifierNamesCache: TIdentifierNamesCache): void { + public writeFile(identifierNamesCache: TIdentifierNamesCache): void { if (!this.identifierNamesCachePath) { return; } diff --git a/src/cli/utils/ObfuscatedCodeFileUtils.ts b/src/cli/utils/ObfuscatedCodeFileUtils.ts index de7824f2a..da157c6a8 100644 --- a/src/cli/utils/ObfuscatedCodeFileUtils.ts +++ b/src/cli/utils/ObfuscatedCodeFileUtils.ts @@ -23,10 +23,7 @@ export class ObfuscatedCodeFileUtils { * @param {string} inputPath * @param {TInputCLIOptions} options */ - public constructor ( - inputPath: string, - options: TInputCLIOptions - ) { + public constructor(inputPath: string, options: TInputCLIOptions) { this.inputPath = path.normalize(inputPath); this.options = options; } @@ -35,11 +32,9 @@ export class ObfuscatedCodeFileUtils { * @param {string} filePath * @returns {string} */ - public getOutputCodePath (filePath: string): string { + public getOutputCodePath(filePath: string): string { const normalizedFilePath: string = path.normalize(filePath); - const normalizedRawOutputPath: string | null = this.options.output - ? path.normalize(this.options.output) - : null; + const normalizedRawOutputPath: string | null = this.options.output ? path.normalize(this.options.output) : null; if (!normalizedRawOutputPath) { return normalizedFilePath @@ -54,9 +49,8 @@ export class ObfuscatedCodeFileUtils { const outputPathExtName: string = path.extname(normalizedRawOutputPath); const isDirectoryRawInputPath: boolean = rawInputPathStats.isDirectory(); - const isDirectoryRawOutputPath: boolean = !JavaScriptObfuscatorCLI - .availableInputExtensions - .includes(outputPathExtName); + const isDirectoryRawOutputPath: boolean = + !JavaScriptObfuscatorCLI.availableInputExtensions.includes(outputPathExtName); if (isDirectoryRawInputPath) { if (isDirectoryRawOutputPath) { @@ -90,7 +84,7 @@ export class ObfuscatedCodeFileUtils { * @param {string} sourceMapFileName * @returns {string} */ - public getOutputSourceMapPath (outputCodePath: string, sourceMapFileName: string = ''): string { + public getOutputSourceMapPath(outputCodePath: string, sourceMapFileName: string = ''): string { if (!outputCodePath) { throw new Error('Output code path is empty'); } @@ -110,9 +104,7 @@ export class ObfuscatedCodeFileUtils { // File path with directory, like: `foo/bar.js`, or without, like: `bar.js` const isFilePathWithDirectory: boolean = indexOfLastSeparator > 0; - sourceMapPath = isFilePathWithDirectory - ? normalizedOutputCodePath.slice(0, indexOfLastSeparator) - : ''; + sourceMapPath = isFilePathWithDirectory ? normalizedOutputCodePath.slice(0, indexOfLastSeparator) : ''; } else { sourceMapPath = normalizedOutputCodePath; } @@ -125,7 +117,10 @@ export class ObfuscatedCodeFileUtils { if (!/\.js\.map$/.test(normalizedOutputCodePath)) { parsedOutputCodePath = path.parse(normalizedOutputCodePath); - const outputCodePathWithoutExtension: string = path.join(parsedOutputCodePath.dir, parsedOutputCodePath.name); + const outputCodePathWithoutExtension: string = path.join( + parsedOutputCodePath.dir, + parsedOutputCodePath.name + ); normalizedOutputCodePath = `${outputCodePathWithoutExtension}.js.map`; } else if (/\.js$/.test(normalizedOutputCodePath)) { @@ -139,7 +134,7 @@ export class ObfuscatedCodeFileUtils { * @param {string} outputPath * @param {string} data */ - public writeFile (outputPath: string, data: string): void { + public writeFile(outputPath: string, data: string): void { mkdirp.sync(path.dirname(outputPath)); fs.writeFileSync(outputPath, data, { diff --git a/src/cli/utils/SourceCodeFileUtils.ts b/src/cli/utils/SourceCodeFileUtils.ts index f89610c64..5d979e36d 100644 --- a/src/cli/utils/SourceCodeFileUtils.ts +++ b/src/cli/utils/SourceCodeFileUtils.ts @@ -23,10 +23,7 @@ export class SourceCodeFileUtils { * @param {string} inputPath * @param {TInputCLIOptions} options */ - public constructor ( - inputPath: string, - options: TInputCLIOptions - ) { + public constructor(inputPath: string, options: TInputCLIOptions) { this.inputPath = inputPath; this.options = options; } @@ -36,15 +33,15 @@ export class SourceCodeFileUtils { * @param {string[]} excludePatterns * @returns {boolean} */ - private static isExcludedPath (filePath: string, excludePatterns: string[] = []): boolean { + private static isExcludedPath(filePath: string, excludePatterns: string[] = []): boolean { if (!excludePatterns.length) { return false; } const fileName: string = path.basename(filePath); const isExcludedFilePathByGlobPattern: boolean = !!multimatch([filePath], excludePatterns).length; - const isExcludedFilePathByInclusion: boolean = excludePatterns.some((excludePattern: string) => - filePath.includes(excludePattern) || fileName.includes(excludePattern) + const isExcludedFilePathByInclusion: boolean = excludePatterns.some( + (excludePattern: string) => filePath.includes(excludePattern) || fileName.includes(excludePattern) ); return isExcludedFilePathByInclusion || isExcludedFilePathByGlobPattern; @@ -54,7 +51,7 @@ export class SourceCodeFileUtils { * @param {string} filePath * @returns {boolean} */ - private static isDirectoryPath (filePath: string): boolean { + private static isDirectoryPath(filePath: string): boolean { try { return fs.statSync(filePath).isDirectory(); } catch { @@ -66,7 +63,7 @@ export class SourceCodeFileUtils { * @param {string} filePath * @returns {boolean} */ - private static isFilePath (filePath: string): boolean { + private static isFilePath(filePath: string): boolean { try { return fs.statSync(filePath).isFile(); } catch { @@ -79,7 +76,7 @@ export class SourceCodeFileUtils { * @param {string[]} excludePatterns * @returns {boolean} */ - private static isValidDirectory (directoryPath: string, excludePatterns: string[] = []): boolean { + private static isValidDirectory(directoryPath: string, excludePatterns: string[] = []): boolean { return !SourceCodeFileUtils.isExcludedPath(directoryPath, excludePatterns); } @@ -88,17 +85,19 @@ export class SourceCodeFileUtils { * @param {string[]} excludePatterns * @returns {boolean} */ - private static isValidFile (filePath: string, excludePatterns: string[] = []): boolean { - return JavaScriptObfuscatorCLI.availableInputExtensions.includes(path.extname(filePath)) - && !filePath.includes(JavaScriptObfuscatorCLI.obfuscatedFilePrefix) - && !SourceCodeFileUtils.isExcludedPath(filePath, excludePatterns); + private static isValidFile(filePath: string, excludePatterns: string[] = []): boolean { + return ( + JavaScriptObfuscatorCLI.availableInputExtensions.includes(path.extname(filePath)) && + !filePath.includes(JavaScriptObfuscatorCLI.obfuscatedFilePrefix) && + !SourceCodeFileUtils.isExcludedPath(filePath, excludePatterns) + ); } /** * @param {string} filePath * @returns {string} */ - private static readFile (filePath: string): IFileData { + private static readFile(filePath: string): IFileData { return { filePath: path.normalize(filePath), content: fs.readFileSync(filePath, JavaScriptObfuscatorCLI.encoding) @@ -108,23 +107,22 @@ export class SourceCodeFileUtils { /** * @returns {IFileData[]} */ - public readSourceCode (): IFileData[] { + public readSourceCode(): IFileData[] { if ( - SourceCodeFileUtils.isFilePath(this.inputPath) - && SourceCodeFileUtils.isValidFile(this.inputPath, this.options.exclude) + SourceCodeFileUtils.isFilePath(this.inputPath) && + SourceCodeFileUtils.isValidFile(this.inputPath, this.options.exclude) ) { return [SourceCodeFileUtils.readFile(this.inputPath)]; } if ( - SourceCodeFileUtils.isDirectoryPath(this.inputPath) - && SourceCodeFileUtils.isValidDirectory(this.inputPath, this.options.exclude) + SourceCodeFileUtils.isDirectoryPath(this.inputPath) && + SourceCodeFileUtils.isValidDirectory(this.inputPath, this.options.exclude) ) { return this.readDirectoryRecursive(this.inputPath); } - const availableFilePaths: string = JavaScriptObfuscatorCLI - .availableInputExtensions + const availableFilePaths: string = JavaScriptObfuscatorCLI.availableInputExtensions .map((extension: string) => `\`${extension}\``) .join(', '); @@ -136,31 +134,30 @@ export class SourceCodeFileUtils { * @param {IFileData[]} filesData * @returns {IFileData[]} */ - private readDirectoryRecursive (directoryPath: string, filesData: IFileData[] = []): IFileData[] { - fs.readdirSync(directoryPath, JavaScriptObfuscatorCLI.encoding) - .forEach((fileName: string) => { - const filePath: string = path.join(directoryPath, fileName); - - if ( - SourceCodeFileUtils.isDirectoryPath(filePath) - && SourceCodeFileUtils.isValidDirectory(filePath, this.options.exclude) - ) { - filesData.push(...this.readDirectoryRecursive(filePath)); - - return; - } - - if ( - SourceCodeFileUtils.isFilePath(filePath) - && SourceCodeFileUtils.isValidFile(filePath, this.options.exclude) - ) { - const fileData: IFileData = SourceCodeFileUtils.readFile(filePath); - - filesData.push(fileData); - - return; - } - }); + private readDirectoryRecursive(directoryPath: string, filesData: IFileData[] = []): IFileData[] { + fs.readdirSync(directoryPath, JavaScriptObfuscatorCLI.encoding).forEach((fileName: string) => { + const filePath: string = path.join(directoryPath, fileName); + + if ( + SourceCodeFileUtils.isDirectoryPath(filePath) && + SourceCodeFileUtils.isValidDirectory(filePath, this.options.exclude) + ) { + filesData.push(...this.readDirectoryRecursive(filePath)); + + return; + } + + if ( + SourceCodeFileUtils.isFilePath(filePath) && + SourceCodeFileUtils.isValidFile(filePath, this.options.exclude) + ) { + const fileData: IFileData = SourceCodeFileUtils.readFile(filePath); + + filesData.push(fileData); + + return; + } + }); return filesData; } diff --git a/src/code-transformers/AbstractCodeTransformer.ts b/src/code-transformers/AbstractCodeTransformer.ts index 10fde1725..513a8171b 100644 --- a/src/code-transformers/AbstractCodeTransformer.ts +++ b/src/code-transformers/AbstractCodeTransformer.ts @@ -29,7 +29,7 @@ export abstract class AbstractCodeTransformer implements ICodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -42,5 +42,5 @@ export abstract class AbstractCodeTransformer implements ICodeTransformer { * @param {CodeTransformationStage} codeTransformationStage * @returns {string} */ - public abstract transformCode (code: string, codeTransformationStage: CodeTransformationStage): string; + public abstract transformCode(code: string, codeTransformationStage: CodeTransformationStage): string; } diff --git a/src/code-transformers/CodeTransformersRunner.ts b/src/code-transformers/CodeTransformersRunner.ts index 35c1b9968..0998e2f64 100644 --- a/src/code-transformers/CodeTransformersRunner.ts +++ b/src/code-transformers/CodeTransformersRunner.ts @@ -31,14 +31,11 @@ export class CodeTransformersRunner implements ICodeTransformersRunner { * @param {TNodeTransformerFactory} codeTransformerFactory * @param {ITransformerNamesGroupsBuilder} codeTransformerNamesGroupsBuilder */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__ICodeTransformer) - codeTransformerFactory: TCodeTransformerFactory, + codeTransformerFactory: TCodeTransformerFactory, @inject(ServiceIdentifiers.ICodeTransformerNamesGroupsBuilder) - codeTransformerNamesGroupsBuilder: ITransformerNamesGroupsBuilder< - CodeTransformer, - ICodeTransformer - >, + codeTransformerNamesGroupsBuilder: ITransformerNamesGroupsBuilder ) { this.codeTransformerFactory = codeTransformerFactory; this.codeTransformerNamesGroupsBuilder = codeTransformerNamesGroupsBuilder; @@ -50,7 +47,7 @@ export class CodeTransformersRunner implements ICodeTransformersRunner { * @param {CodeTransformationStage} codeTransformationStage * @returns {string} */ - public transform ( + public transform( code: string, codeTransformerNames: CodeTransformer[], codeTransformationStage: CodeTransformationStage @@ -59,8 +56,10 @@ export class CodeTransformersRunner implements ICodeTransformersRunner { return code; } - const normalizedCodeTransformers: TDictionary = - this.buildNormalizedCodeTransformers(codeTransformerNames, codeTransformationStage); + const normalizedCodeTransformers: TDictionary = this.buildNormalizedCodeTransformers( + codeTransformerNames, + codeTransformationStage + ); const codeTransformerNamesGroups: CodeTransformer[][] = this.codeTransformerNamesGroupsBuilder.build(normalizedCodeTransformers); @@ -80,21 +79,20 @@ export class CodeTransformersRunner implements ICodeTransformersRunner { * @param {NodeTransformationStage} codeTransformationStage * @returns {TDictionary} */ - private buildNormalizedCodeTransformers ( + private buildNormalizedCodeTransformers( codeTransformerNames: CodeTransformer[], codeTransformationStage: CodeTransformationStage ): TDictionary { - return codeTransformerNames - .reduce>( - (acc: TDictionary, codeTransformerName: CodeTransformer) => { - const codeTransformer: ICodeTransformer = this.codeTransformerFactory(codeTransformerName); + return codeTransformerNames.reduce>( + (acc: TDictionary, codeTransformerName: CodeTransformer) => { + const codeTransformer: ICodeTransformer = this.codeTransformerFactory(codeTransformerName); - return { - ...acc, - [codeTransformerName]: codeTransformer - }; - }, - {} - ); + return { + ...acc, + [codeTransformerName]: codeTransformer + }; + }, + {} + ); } } diff --git a/src/code-transformers/preparing-transformers/HashbangOperatorTransformer.ts b/src/code-transformers/preparing-transformers/HashbangOperatorTransformer.ts index 08b3e4526..02cdbd4b8 100644 --- a/src/code-transformers/preparing-transformers/HashbangOperatorTransformer.ts +++ b/src/code-transformers/preparing-transformers/HashbangOperatorTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { IOptions } from '../../interfaces/options/IOptions'; @@ -19,7 +19,7 @@ export class HashbangOperatorTransformer extends AbstractCodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -33,7 +33,7 @@ export class HashbangOperatorTransformer extends AbstractCodeTransformer { * @param {CodeTransformationStage} codeTransformationStage * @returns {string} */ - public transformCode (code: string, codeTransformationStage: CodeTransformationStage): string { + public transformCode(code: string, codeTransformationStage: CodeTransformationStage): string { switch (codeTransformationStage) { case CodeTransformationStage.PreparingTransformers: return this.removeAndSaveHashbangOperatorLine(code); @@ -50,7 +50,7 @@ export class HashbangOperatorTransformer extends AbstractCodeTransformer { * @param {string} code * @returns {string} */ - private removeAndSaveHashbangOperatorLine (code: string): string { + private removeAndSaveHashbangOperatorLine(code: string): string { return code .replace(/^#!.*$(\r?\n)*/m, (substring: string) => { if (substring) { @@ -66,7 +66,7 @@ export class HashbangOperatorTransformer extends AbstractCodeTransformer { * @param {string} code * @returns {string} */ - private appendSavedHashbangOperatorLine (code: string): string { + private appendSavedHashbangOperatorLine(code: string): string { return `${this.hashbangOperatorLine ?? ''}${code}`; } } diff --git a/src/constants/ReservedIdentifierNames.ts b/src/constants/ReservedIdentifierNames.ts index 9ba8e37d2..e5c104244 100644 --- a/src/constants/ReservedIdentifierNames.ts +++ b/src/constants/ReservedIdentifierNames.ts @@ -1,11 +1,51 @@ export const reservedIdentifierNames = [ // reserved identifiers - 'byte', 'case', 'char', 'do', 'else', 'enum', 'eval', 'for', 'goto', - 'if', 'in', 'int', 'let', 'long', 'new', 'null', 'this', 'true', 'try', - 'var', 'void', 'with', + 'byte', + 'case', + 'char', + 'do', + 'else', + 'enum', + 'eval', + 'for', + 'goto', + 'if', + 'in', + 'int', + 'let', + 'long', + 'new', + 'null', + 'this', + 'true', + 'try', + 'var', + 'void', + 'with', // reserved global object identifiers - 'Array', 'Attr', 'Audio', 'Blob', 'Cache', 'Date', 'Error', 'Event', - 'Feed', 'File', 'Hz', 'Image', 'Intl', 'Lock', 'Map', 'Math', 'Node', - 'Proxy', 'Range', 'Rect', 'Set', 'Table', 'Text', 'Touch' + 'Array', + 'Attr', + 'Audio', + 'Blob', + 'Cache', + 'Date', + 'Error', + 'Event', + 'Feed', + 'File', + 'Hz', + 'Image', + 'Intl', + 'Lock', + 'Map', + 'Math', + 'Node', + 'Proxy', + 'Range', + 'Rect', + 'Set', + 'Table', + 'Text', + 'Touch' ]; diff --git a/src/container/InversifyContainerFacade.ts b/src/container/InversifyContainerFacade.ts index bacf27130..21eac245e 100644 --- a/src/container/InversifyContainerFacade.ts +++ b/src/container/InversifyContainerFacade.ts @@ -46,7 +46,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { */ private readonly container: interfaces.Container; - public constructor () { + public constructor() { this.container = new Container(); } @@ -54,10 +54,10 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { * @param {interfaces.ServiceIdentifier} serviceIdentifier * @returns {U} */ - public static getFactory ( + public static getFactory( serviceIdentifier: interfaces.ServiceIdentifier ): (context: interfaces.Context) => (bindingName: T) => U { - return (context: interfaces.Context): (bindingName: T) => U => { + return (context: interfaces.Context): ((bindingName: T) => U) => { return (bindingName: T): U => { return context.container.getNamed(serviceIdentifier, bindingName); }; @@ -68,11 +68,11 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { * @param {interfaces.ServiceIdentifier} serviceIdentifier * @returns {U} */ - public static getCacheFactory ( + public static getCacheFactory( serviceIdentifier: interfaces.ServiceIdentifier ): (context: interfaces.Context) => (bindingName: T) => U { - return (context: interfaces.Context): (bindingName: T) => U => { - const cache: Map = new Map(); + return (context: interfaces.Context): ((bindingName: T) => U) => { + const cache: Map = new Map(); return (bindingName: T): U => { if (cache.has(bindingName)) { @@ -93,33 +93,34 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { * @param {interfaces.ServiceIdentifier[], U>>} dependencies * @returns {(context: interfaces.Context) => (bindingName: T) => U} */ - public static getConstructorFactory ( + public static getConstructorFactory( serviceIdentifier: interfaces.ServiceIdentifier[], U>>, ...dependencies: interfaces.ServiceIdentifier[], U>>[] ): (context: interfaces.Context) => (bindingName: T) => U { - return (context: interfaces.Context): (bindingName: T) => U => { + return (context: interfaces.Context): ((bindingName: T) => U) => { const cache: Map[], U>> = new Map(); const cachedDependencies: Record[] = []; return (bindingName: T): U => { - dependencies.forEach(( - dependency: interfaces.ServiceIdentifier[], U>>, - index: number - ) => { - if (!cachedDependencies[index]) { - cachedDependencies[index] = context.container.get(dependency); + dependencies.forEach( + ( + dependency: interfaces.ServiceIdentifier[], U>>, + index: number + ) => { + if (!cachedDependencies[index]) { + cachedDependencies[index] = context.container.get(dependency); + } } - }); + ); if (cache.has(bindingName)) { return new ([], U>>cache.get(bindingName))(...cachedDependencies); } - const constructor = context.container - .getNamed[], U>>( - serviceIdentifier, - bindingName - ); + const constructor = context.container.getNamed[], U>>( + serviceIdentifier, + bindingName + ); cache.set(bindingName, constructor); @@ -132,7 +133,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { * @param {interfaces.ServiceIdentifier} serviceIdentifier * @returns {T} */ - public get (serviceIdentifier: interfaces.ServiceIdentifier): T { + public get(serviceIdentifier: interfaces.ServiceIdentifier): T { return this.container.get(serviceIdentifier); } @@ -141,7 +142,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { * @param {string | number | symbol} named * @returns {T} */ - public getNamed (serviceIdentifier: interfaces.ServiceIdentifier, named: string | number | symbol): T { + public getNamed(serviceIdentifier: interfaces.ServiceIdentifier, named: string | number | symbol): T { return this.container.getNamed(serviceIdentifier, named); } @@ -150,7 +151,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { * @param {string} sourceMap * @param {TInputOptions} options */ - public load (sourceCode: string, sourceMap: string, options: TInputOptions): void { + public load(sourceCode: string, sourceMap: string, options: TInputOptions): void { this.container .bind(ServiceIdentifiers.ISourceCode) .toDynamicValue(() => new SourceCode(sourceCode, sourceMap)) @@ -161,10 +162,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { .toDynamicValue(() => options) .inSingletonScope(); - this.container - .bind(ServiceIdentifiers.ILogger) - .to(Logger) - .inSingletonScope(); + this.container.bind(ServiceIdentifiers.ILogger).to(Logger).inSingletonScope(); this.container .bind(ServiceIdentifiers.IJavaScriptObfuscator) @@ -181,16 +179,15 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { .to(NodeTransformersRunner) .inSingletonScope(); - this.container - .bind(ServiceIdentifiers.IObfuscationResult) - .to(ObfuscationResult); + this.container.bind(ServiceIdentifiers.IObfuscationResult).to(ObfuscationResult); this.container .bind(ServiceIdentifiers.Factory__IObfuscationResult) .toFactory((context: interfaces.Context) => { return (obfuscatedCodeAsString: string, sourceMapAsString: string): IObfuscationResult => { - const obfuscationResult: IObfuscationResult = context.container - .get(ServiceIdentifiers.IObfuscationResult); + const obfuscationResult: IObfuscationResult = context.container.get( + ServiceIdentifiers.IObfuscationResult + ); obfuscationResult.initialize(obfuscatedCodeAsString, sourceMapAsString); @@ -221,7 +218,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { this.container.load(utilsModule); } - public unload (): void { + public unload(): void { this.container.unbindAll(); } } diff --git a/src/container/modules/analyzers/AnalyzersModule.ts b/src/container/modules/analyzers/AnalyzersModule.ts index ce76b1985..ae327cc2b 100644 --- a/src/container/modules/analyzers/AnalyzersModule.ts +++ b/src/container/modules/analyzers/AnalyzersModule.ts @@ -21,9 +21,7 @@ import { StringArrayStorageAnalyzer } from '../../../analyzers/string-array-stor export const analyzersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { // calls graph analyzer - bind(ServiceIdentifiers.ICallsGraphAnalyzer) - .to(CallsGraphAnalyzer) - .inSingletonScope(); + bind(ServiceIdentifiers.ICallsGraphAnalyzer).to(CallsGraphAnalyzer).inSingletonScope(); // number numerical expression analyzer bind(ServiceIdentifiers.INumberNumericalExpressionAnalyzer) @@ -36,9 +34,7 @@ export const analyzersModule: interfaces.ContainerModule = new ContainerModule(( .inSingletonScope(); // scope analyzer - bind(ServiceIdentifiers.IScopeAnalyzer) - .to(ScopeAnalyzer) - .inSingletonScope(); + bind(ServiceIdentifiers.IScopeAnalyzer).to(ScopeAnalyzer).inSingletonScope(); // string array storage analyzer bind(ServiceIdentifiers.IStringArrayStorageAnalyzer) @@ -59,9 +55,12 @@ export const analyzersModule: interfaces.ContainerModule = new ContainerModule(( .whenTargetNamed(CalleeDataExtractor.ObjectExpressionCalleeDataExtractor); // callee data extractor factory - bind(ServiceIdentifiers.Factory__ICalleeDataExtractor) - .toFactory(InversifyContainerFacade - .getCacheFactory( - ServiceIdentifiers.ICalleeDataExtractor - )); + bind(ServiceIdentifiers.Factory__ICalleeDataExtractor).toFactory< + ICalleeDataExtractor, + [CalleeDataExtractor] + >( + InversifyContainerFacade.getCacheFactory( + ServiceIdentifiers.ICalleeDataExtractor + ) + ); }); diff --git a/src/container/modules/code-transformers/CodeTransformersModule.ts b/src/container/modules/code-transformers/CodeTransformersModule.ts index 7c2fb3d64..ad8af23e3 100644 --- a/src/container/modules/code-transformers/CodeTransformersModule.ts +++ b/src/container/modules/code-transformers/CodeTransformersModule.ts @@ -12,12 +12,14 @@ import { HashbangOperatorTransformer } from '../../../code-transformers/preparin export const codeTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { // code transformers factory - bind(ServiceIdentifiers.Factory__ICodeTransformer) - .toFactory(InversifyContainerFacade - .getCacheFactory(ServiceIdentifiers.ICodeTransformer)); + bind(ServiceIdentifiers.Factory__ICodeTransformer).toFactory( + InversifyContainerFacade.getCacheFactory(ServiceIdentifiers.ICodeTransformer) + ); // code transformer names groups builder - bind>(ServiceIdentifiers.ICodeTransformerNamesGroupsBuilder) + bind>( + ServiceIdentifiers.ICodeTransformerNamesGroupsBuilder + ) .to(CodeTransformerNamesGroupsBuilder) .inSingletonScope(); diff --git a/src/container/modules/custom-code-helpers/CustomCodeHelpersModule.ts b/src/container/modules/custom-code-helpers/CustomCodeHelpersModule.ts index de96a08d1..6ddca83dd 100644 --- a/src/container/modules/custom-code-helpers/CustomCodeHelpersModule.ts +++ b/src/container/modules/custom-code-helpers/CustomCodeHelpersModule.ts @@ -103,14 +103,20 @@ export const customCodeHelpersModule: interfaces.ContainerModule = new Container .whenTargetNamed(CustomCodeHelperGroup.StringArray); // customCodeHelper factory - bind(ServiceIdentifiers.Factory__ICustomCodeHelper) - .toFactory(InversifyContainerFacade - .getFactory(ServiceIdentifiers.ICustomCodeHelper)); + bind(ServiceIdentifiers.Factory__ICustomCodeHelper).toFactory< + ICustomCodeHelper, + [CustomCodeHelper] + >(InversifyContainerFacade.getFactory(ServiceIdentifiers.ICustomCodeHelper)); // customCodeHelperGroup factory - bind(ServiceIdentifiers.Factory__ICustomCodeHelperGroup) - .toFactory(InversifyContainerFacade - .getFactory(ServiceIdentifiers.ICustomCodeHelperGroup)); + bind(ServiceIdentifiers.Factory__ICustomCodeHelperGroup).toFactory< + ICustomCodeHelperGroup, + [CustomCodeHelperGroup] + >( + InversifyContainerFacade.getFactory( + ServiceIdentifiers.ICustomCodeHelperGroup + ) + ); // custom code helper formatter bind(ServiceIdentifiers.ICustomCodeHelperFormatter) diff --git a/src/container/modules/custom-nodes/CustomNodesModule.ts b/src/container/modules/custom-nodes/CustomNodesModule.ts index b73aa8b8f..2d813f0c5 100644 --- a/src/container/modules/custom-nodes/CustomNodesModule.ts +++ b/src/container/modules/custom-nodes/CustomNodesModule.ts @@ -101,54 +101,71 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule .whenTargetNamed(StringArrayIndexNode.StringArrayHexadecimalNumericStringIndexNode); // control flow customNode constructor factory - bind(ServiceIdentifiers.Factory__IControlFlowCustomNode) - .toFactory(InversifyContainerFacade - .getConstructorFactory( - ServiceIdentifiers.Newable__ICustomNode, - ServiceIdentifiers.Factory__IIdentifierNamesGenerator, - ServiceIdentifiers.ICustomCodeHelperFormatter, - ServiceIdentifiers.IRandomGenerator, - ServiceIdentifiers.IOptions - )); + bind(ServiceIdentifiers.Factory__IControlFlowCustomNode).toFactory< + ICustomNode, + [ControlFlowCustomNode] + >( + InversifyContainerFacade.getConstructorFactory( + ServiceIdentifiers.Newable__ICustomNode, + ServiceIdentifiers.Factory__IIdentifierNamesGenerator, + ServiceIdentifiers.ICustomCodeHelperFormatter, + ServiceIdentifiers.IRandomGenerator, + ServiceIdentifiers.IOptions + ) + ); // dead code injection customNode constructor factory - bind(ServiceIdentifiers.Factory__IDeadCodeInjectionCustomNode) - .toFactory(InversifyContainerFacade - .getConstructorFactory( - ServiceIdentifiers.Newable__ICustomNode, - ServiceIdentifiers.Factory__IIdentifierNamesGenerator, - ServiceIdentifiers.ICustomCodeHelperFormatter, - ServiceIdentifiers.IRandomGenerator, - ServiceIdentifiers.IOptions - )); + bind(ServiceIdentifiers.Factory__IDeadCodeInjectionCustomNode).toFactory< + ICustomNode, + [DeadCodeInjectionCustomNode] + >( + InversifyContainerFacade.getConstructorFactory( + ServiceIdentifiers.Newable__ICustomNode, + ServiceIdentifiers.Factory__IIdentifierNamesGenerator, + ServiceIdentifiers.ICustomCodeHelperFormatter, + ServiceIdentifiers.IRandomGenerator, + ServiceIdentifiers.IOptions + ) + ); // object expression keys transformer customNode constructor factory - bind(ServiceIdentifiers.Factory__IObjectExpressionKeysTransformerCustomNode) - .toFactory(InversifyContainerFacade - .getConstructorFactory( - ServiceIdentifiers.Newable__ICustomNode, - ServiceIdentifiers.Factory__IIdentifierNamesGenerator, - ServiceIdentifiers.ICustomCodeHelperFormatter, - ServiceIdentifiers.IRandomGenerator, - ServiceIdentifiers.IOptions - )); + bind(ServiceIdentifiers.Factory__IObjectExpressionKeysTransformerCustomNode).toFactory< + ICustomNode, + [ObjectExpressionKeysTransformerCustomNode] + >( + InversifyContainerFacade.getConstructorFactory( + ServiceIdentifiers.Newable__ICustomNode, + ServiceIdentifiers.Factory__IIdentifierNamesGenerator, + ServiceIdentifiers.ICustomCodeHelperFormatter, + ServiceIdentifiers.IRandomGenerator, + ServiceIdentifiers.IOptions + ) + ); // string array customNode constructor factory - bind(ServiceIdentifiers.Factory__IStringArrayCustomNode) - .toFactory(InversifyContainerFacade - .getConstructorFactory( - ServiceIdentifiers.Newable__ICustomNode, - ServiceIdentifiers.Factory__IIdentifierNamesGenerator, - ServiceIdentifiers.Factory__IStringArrayIndexNode, - ServiceIdentifiers.ICustomCodeHelperFormatter, - ServiceIdentifiers.IStringArrayStorage, - ServiceIdentifiers.IArrayUtils, - ServiceIdentifiers.IRandomGenerator, - ServiceIdentifiers.IOptions - )); + bind(ServiceIdentifiers.Factory__IStringArrayCustomNode).toFactory< + ICustomNode, + [StringArrayCustomNode] + >( + InversifyContainerFacade.getConstructorFactory( + ServiceIdentifiers.Newable__ICustomNode, + ServiceIdentifiers.Factory__IIdentifierNamesGenerator, + ServiceIdentifiers.Factory__IStringArrayIndexNode, + ServiceIdentifiers.ICustomCodeHelperFormatter, + ServiceIdentifiers.IStringArrayStorage, + ServiceIdentifiers.IArrayUtils, + ServiceIdentifiers.IRandomGenerator, + ServiceIdentifiers.IOptions + ) + ); // string array index node factory - bind(ServiceIdentifiers.Factory__IStringArrayIndexNode) - .toFactory(InversifyContainerFacade - .getCacheFactory(ServiceIdentifiers.IStringArrayIndexNode)); + bind(ServiceIdentifiers.Factory__IStringArrayIndexNode).toFactory< + IStringArrayIndexNode, + [StringArrayIndexNode] + >( + InversifyContainerFacade.getCacheFactory( + ServiceIdentifiers.IStringArrayIndexNode + ) + ); }); diff --git a/src/container/modules/generators/GeneratorsModule.ts b/src/container/modules/generators/GeneratorsModule.ts index f65bd6169..c1ff48e3e 100644 --- a/src/container/modules/generators/GeneratorsModule.ts +++ b/src/container/modules/generators/GeneratorsModule.ts @@ -34,54 +34,59 @@ export const generatorsModule: interfaces.ContainerModule = new ContainerModule( .whenTargetNamed(IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator); // identifier name generator factory - function identifierNameGeneratorFactory (): (context: interfaces.Context) => (options: IOptions) => IIdentifierNamesGenerator { + function identifierNameGeneratorFactory(): ( + context: interfaces.Context + ) => (options: IOptions) => IIdentifierNamesGenerator { let cachedIdentifierNamesGenerator: IIdentifierNamesGenerator | null = null; - return (context: interfaces.Context): (options: IOptions) => IIdentifierNamesGenerator => (options: IOptions): IIdentifierNamesGenerator => { - if (cachedIdentifierNamesGenerator) { - return cachedIdentifierNamesGenerator; - } + return (context: interfaces.Context): ((options: IOptions) => IIdentifierNamesGenerator) => + (options: IOptions): IIdentifierNamesGenerator => { + if (cachedIdentifierNamesGenerator) { + return cachedIdentifierNamesGenerator; + } - let identifierNamesGenerator: IIdentifierNamesGenerator; + let identifierNamesGenerator: IIdentifierNamesGenerator; - switch (options.identifierNamesGenerator) { - case IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator: - identifierNamesGenerator = context.container.getNamed( - ServiceIdentifiers.IIdentifierNamesGenerator, - IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator - ); + switch (options.identifierNamesGenerator) { + case IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator: + identifierNamesGenerator = context.container.getNamed( + ServiceIdentifiers.IIdentifierNamesGenerator, + IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator + ); - break; + break; - case IdentifierNamesGenerator.MangledIdentifierNamesGenerator: - identifierNamesGenerator = context.container.getNamed( - ServiceIdentifiers.IIdentifierNamesGenerator, - IdentifierNamesGenerator.MangledIdentifierNamesGenerator - ); + case IdentifierNamesGenerator.MangledIdentifierNamesGenerator: + identifierNamesGenerator = context.container.getNamed( + ServiceIdentifiers.IIdentifierNamesGenerator, + IdentifierNamesGenerator.MangledIdentifierNamesGenerator + ); - break; + break; - case IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator: - identifierNamesGenerator = context.container.getNamed( - ServiceIdentifiers.IIdentifierNamesGenerator, - IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator - ); + case IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator: + identifierNamesGenerator = context.container.getNamed( + ServiceIdentifiers.IIdentifierNamesGenerator, + IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator + ); - break; + break; - case IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator: - default: - identifierNamesGenerator = context.container.getNamed( - ServiceIdentifiers.IIdentifierNamesGenerator, - IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator - ); - } + case IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator: + default: + identifierNamesGenerator = context.container.getNamed( + ServiceIdentifiers.IIdentifierNamesGenerator, + IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator + ); + } - cachedIdentifierNamesGenerator = identifierNamesGenerator; + cachedIdentifierNamesGenerator = identifierNamesGenerator; - return identifierNamesGenerator; - }; + return identifierNamesGenerator; + }; } - bind(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - .toFactory(identifierNameGeneratorFactory()); + bind(ServiceIdentifiers.Factory__IIdentifierNamesGenerator).toFactory< + IIdentifierNamesGenerator, + [IOptions] + >(identifierNameGeneratorFactory()); }); diff --git a/src/container/modules/node-transformers/ControlFlowTransformersModule.ts b/src/container/modules/node-transformers/ControlFlowTransformersModule.ts index a2406c1b3..02a458e5c 100644 --- a/src/container/modules/node-transformers/ControlFlowTransformersModule.ts +++ b/src/container/modules/node-transformers/ControlFlowTransformersModule.ts @@ -17,43 +17,50 @@ import { StringArrayCallControlFlowReplacer } from '../../../node-transformers/c import { StringArrayControlFlowTransformer } from '../../../node-transformers/control-flow-transformers/StringArrayControlFlowTransformer'; import { StringLiteralControlFlowReplacer } from '../../../node-transformers/control-flow-transformers/control-flow-replacers/StringLiteralControlFlowReplacer'; -export const controlFlowTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { - // control flow transformers - bind(ServiceIdentifiers.INodeTransformer) - .to(BlockStatementControlFlowTransformer) - .whenTargetNamed(NodeTransformer.BlockStatementControlFlowTransformer); - - bind(ServiceIdentifiers.INodeTransformer) - .to(FunctionControlFlowTransformer) - .whenTargetNamed(NodeTransformer.FunctionControlFlowTransformer); - - bind(ServiceIdentifiers.INodeTransformer) - .to(StringArrayControlFlowTransformer) - .whenTargetNamed(NodeTransformer.StringArrayControlFlowTransformer); - - // control flow replacers - bind(ServiceIdentifiers.IControlFlowReplacer) - .to(BinaryExpressionControlFlowReplacer) - .whenTargetNamed(ControlFlowReplacer.BinaryExpressionControlFlowReplacer); - - bind(ServiceIdentifiers.IControlFlowReplacer) - .to(CallExpressionControlFlowReplacer) - .whenTargetNamed(ControlFlowReplacer.CallExpressionControlFlowReplacer); - - bind(ServiceIdentifiers.IControlFlowReplacer) - .to(LogicalExpressionControlFlowReplacer) - .whenTargetNamed(ControlFlowReplacer.LogicalExpressionControlFlowReplacer); - - bind(ServiceIdentifiers.IControlFlowReplacer) - .to(StringArrayCallControlFlowReplacer) - .whenTargetNamed(ControlFlowReplacer.StringArrayCallControlFlowReplacer); - - bind(ServiceIdentifiers.IControlFlowReplacer) - .to(StringLiteralControlFlowReplacer) - .whenTargetNamed(ControlFlowReplacer.StringLiteralControlFlowReplacer); - - // control flow replacer factory - bind(ServiceIdentifiers.Factory__IControlFlowReplacer) - .toFactory(InversifyContainerFacade - .getCacheFactory(ServiceIdentifiers.IControlFlowReplacer)); -}); +export const controlFlowTransformersModule: interfaces.ContainerModule = new ContainerModule( + (bind: interfaces.Bind) => { + // control flow transformers + bind(ServiceIdentifiers.INodeTransformer) + .to(BlockStatementControlFlowTransformer) + .whenTargetNamed(NodeTransformer.BlockStatementControlFlowTransformer); + + bind(ServiceIdentifiers.INodeTransformer) + .to(FunctionControlFlowTransformer) + .whenTargetNamed(NodeTransformer.FunctionControlFlowTransformer); + + bind(ServiceIdentifiers.INodeTransformer) + .to(StringArrayControlFlowTransformer) + .whenTargetNamed(NodeTransformer.StringArrayControlFlowTransformer); + + // control flow replacers + bind(ServiceIdentifiers.IControlFlowReplacer) + .to(BinaryExpressionControlFlowReplacer) + .whenTargetNamed(ControlFlowReplacer.BinaryExpressionControlFlowReplacer); + + bind(ServiceIdentifiers.IControlFlowReplacer) + .to(CallExpressionControlFlowReplacer) + .whenTargetNamed(ControlFlowReplacer.CallExpressionControlFlowReplacer); + + bind(ServiceIdentifiers.IControlFlowReplacer) + .to(LogicalExpressionControlFlowReplacer) + .whenTargetNamed(ControlFlowReplacer.LogicalExpressionControlFlowReplacer); + + bind(ServiceIdentifiers.IControlFlowReplacer) + .to(StringArrayCallControlFlowReplacer) + .whenTargetNamed(ControlFlowReplacer.StringArrayCallControlFlowReplacer); + + bind(ServiceIdentifiers.IControlFlowReplacer) + .to(StringLiteralControlFlowReplacer) + .whenTargetNamed(ControlFlowReplacer.StringLiteralControlFlowReplacer); + + // control flow replacer factory + bind(ServiceIdentifiers.Factory__IControlFlowReplacer).toFactory< + IControlFlowReplacer, + [ControlFlowReplacer] + >( + InversifyContainerFacade.getCacheFactory( + ServiceIdentifiers.IControlFlowReplacer + ) + ); + } +); diff --git a/src/container/modules/node-transformers/ConvertingTransformersModule.ts b/src/container/modules/node-transformers/ConvertingTransformersModule.ts index cf9874df0..682550e0c 100644 --- a/src/container/modules/node-transformers/ConvertingTransformersModule.ts +++ b/src/container/modules/node-transformers/ConvertingTransformersModule.ts @@ -78,9 +78,12 @@ export const convertingTransformersModule: interfaces.ContainerModule = new Cont .whenTargetNamed(ObjectExpressionExtractor.BasePropertiesExtractor); // object expression extractor factory - bind(ServiceIdentifiers.Factory__IObjectExpressionExtractor) - .toFactory(InversifyContainerFacade - .getCacheFactory( - ServiceIdentifiers.IObjectExpressionExtractor - )); + bind(ServiceIdentifiers.Factory__IObjectExpressionExtractor).toFactory< + IObjectExpressionExtractor, + [ObjectExpressionExtractor] + >( + InversifyContainerFacade.getCacheFactory( + ServiceIdentifiers.IObjectExpressionExtractor + ) + ); }); diff --git a/src/container/modules/node-transformers/DeadCodeInjectionTransformersModule.ts b/src/container/modules/node-transformers/DeadCodeInjectionTransformersModule.ts index cbb869cb8..211d510b2 100644 --- a/src/container/modules/node-transformers/DeadCodeInjectionTransformersModule.ts +++ b/src/container/modules/node-transformers/DeadCodeInjectionTransformersModule.ts @@ -7,9 +7,11 @@ import { NodeTransformer } from '../../../enums/node-transformers/NodeTransforme import { DeadCodeInjectionTransformer } from '../../../node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer'; -export const deadCodeInjectionTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { - // dead code injection - bind(ServiceIdentifiers.INodeTransformer) - .to(DeadCodeInjectionTransformer) - .whenTargetNamed(NodeTransformer.DeadCodeInjectionTransformer); -}); +export const deadCodeInjectionTransformersModule: interfaces.ContainerModule = new ContainerModule( + (bind: interfaces.Bind) => { + // dead code injection + bind(ServiceIdentifiers.INodeTransformer) + .to(DeadCodeInjectionTransformer) + .whenTargetNamed(NodeTransformer.DeadCodeInjectionTransformer); + } +); diff --git a/src/container/modules/node-transformers/InitializingTransformersModule.ts b/src/container/modules/node-transformers/InitializingTransformersModule.ts index a64d03815..b7753ba5f 100644 --- a/src/container/modules/node-transformers/InitializingTransformersModule.ts +++ b/src/container/modules/node-transformers/InitializingTransformersModule.ts @@ -7,9 +7,11 @@ import { NodeTransformer } from '../../../enums/node-transformers/NodeTransforme import { CommentsTransformer } from '../../../node-transformers/initializing-transformers/CommentsTransformer'; -export const initializingTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { - // preparing transformers - bind(ServiceIdentifiers.INodeTransformer) - .to(CommentsTransformer) - .whenTargetNamed(NodeTransformer.CommentsTransformer); -}); +export const initializingTransformersModule: interfaces.ContainerModule = new ContainerModule( + (bind: interfaces.Bind) => { + // preparing transformers + bind(ServiceIdentifiers.INodeTransformer) + .to(CommentsTransformer) + .whenTargetNamed(NodeTransformer.CommentsTransformer); + } +); diff --git a/src/container/modules/node-transformers/NodeTransformersModule.ts b/src/container/modules/node-transformers/NodeTransformersModule.ts index 05fb80209..a637ce34b 100644 --- a/src/container/modules/node-transformers/NodeTransformersModule.ts +++ b/src/container/modules/node-transformers/NodeTransformersModule.ts @@ -11,12 +11,14 @@ import { NodeTransformerNamesGroupsBuilder } from '../../../node-transformers/No export const nodeTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { // node transformers factory - bind(ServiceIdentifiers.Factory__INodeTransformer) - .toFactory(InversifyContainerFacade - .getCacheFactory(ServiceIdentifiers.INodeTransformer)); + bind(ServiceIdentifiers.Factory__INodeTransformer).toFactory( + InversifyContainerFacade.getCacheFactory(ServiceIdentifiers.INodeTransformer) + ); // node transformer names groups builder - bind>(ServiceIdentifiers.INodeTransformerNamesGroupsBuilder) + bind>( + ServiceIdentifiers.INodeTransformerNamesGroupsBuilder + ) .to(NodeTransformerNamesGroupsBuilder) .inSingletonScope(); }); diff --git a/src/container/modules/node-transformers/PreparingTransformersModule.ts b/src/container/modules/node-transformers/PreparingTransformersModule.ts index f7309b4a6..da19c7a6a 100644 --- a/src/container/modules/node-transformers/PreparingTransformersModule.ts +++ b/src/container/modules/node-transformers/PreparingTransformersModule.ts @@ -14,9 +14,7 @@ import { CustomCodeHelpersTransformer } from '../../../node-transformers/prepari import { EvalCallExpressionTransformer } from '../../../node-transformers/preparing-transformers/EvalCallExpressionTransformer'; import { ForceTransformStringObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ForceTransformStringObfuscatingGuard'; import { IgnoredImportObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/IgnoredImportObfuscatingGuard'; -import { - ImportMetaObfuscationGuard -} from '../../../node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard'; +import { ImportMetaObfuscationGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard'; import { MetadataTransformer } from '../../../node-transformers/preparing-transformers/MetadataTransformer'; import { ObfuscatingGuardsTransformer } from '../../../node-transformers/preparing-transformers/ObfuscatingGuardsTransformer'; import { ParentificationTransformer } from '../../../node-transformers/preparing-transformers/ParentificationTransformer'; @@ -81,9 +79,7 @@ export const preparingTransformersModule: interfaces.ContainerModule = new Conta .whenTargetNamed(ObfuscatingGuard.ReservedStringObfuscatingGuard); // obfuscating guards factory - bind(ServiceIdentifiers.Factory__INodeGuard) - .toFactory(InversifyContainerFacade - .getCacheFactory( - ServiceIdentifiers.INodeGuard - )); + bind(ServiceIdentifiers.Factory__INodeGuard).toFactory( + InversifyContainerFacade.getCacheFactory(ServiceIdentifiers.INodeGuard) + ); }); diff --git a/src/container/modules/node-transformers/RenameIdentifiersTransformersModule.ts b/src/container/modules/node-transformers/RenameIdentifiersTransformersModule.ts index 63d0777cb..00fcaf836 100644 --- a/src/container/modules/node-transformers/RenameIdentifiersTransformersModule.ts +++ b/src/container/modules/node-transformers/RenameIdentifiersTransformersModule.ts @@ -14,30 +14,30 @@ import { ScopeThroughIdentifiersTransformer } from '../../../node-transformers/r import { ThroughIdentifierReplacer } from '../../../node-transformers/rename-identifiers-transformers/through-replacer/ThroughIdentifierReplacer'; import { IThroughIdentifierReplacer } from '../../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer'; -export const renameIdentifiersTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { - // rename identifiers transformers - bind(ServiceIdentifiers.INodeTransformer) - .to(DeadCodeInjectionIdentifiersTransformer) - .whenTargetNamed(NodeTransformer.DeadCodeInjectionIdentifiersTransformer); - - bind(ServiceIdentifiers.INodeTransformer) - .to(LabeledStatementTransformer) - .whenTargetNamed(NodeTransformer.LabeledStatementTransformer); - - bind(ServiceIdentifiers.INodeTransformer) - .to(ScopeIdentifiersTransformer) - .whenTargetNamed(NodeTransformer.ScopeIdentifiersTransformer); - - bind(ServiceIdentifiers.INodeTransformer) - .to(ScopeThroughIdentifiersTransformer) - .whenTargetNamed(NodeTransformer.ScopeThroughIdentifiersTransformer); - - // identifier replacer - bind(ServiceIdentifiers.IIdentifierReplacer) - .to(IdentifierReplacer) - .inSingletonScope(); - - bind(ServiceIdentifiers.IThroughIdentifierReplacer) - .to(ThroughIdentifierReplacer) - .inSingletonScope(); -}); +export const renameIdentifiersTransformersModule: interfaces.ContainerModule = new ContainerModule( + (bind: interfaces.Bind) => { + // rename identifiers transformers + bind(ServiceIdentifiers.INodeTransformer) + .to(DeadCodeInjectionIdentifiersTransformer) + .whenTargetNamed(NodeTransformer.DeadCodeInjectionIdentifiersTransformer); + + bind(ServiceIdentifiers.INodeTransformer) + .to(LabeledStatementTransformer) + .whenTargetNamed(NodeTransformer.LabeledStatementTransformer); + + bind(ServiceIdentifiers.INodeTransformer) + .to(ScopeIdentifiersTransformer) + .whenTargetNamed(NodeTransformer.ScopeIdentifiersTransformer); + + bind(ServiceIdentifiers.INodeTransformer) + .to(ScopeThroughIdentifiersTransformer) + .whenTargetNamed(NodeTransformer.ScopeThroughIdentifiersTransformer); + + // identifier replacer + bind(ServiceIdentifiers.IIdentifierReplacer).to(IdentifierReplacer).inSingletonScope(); + + bind(ServiceIdentifiers.IThroughIdentifierReplacer) + .to(ThroughIdentifierReplacer) + .inSingletonScope(); + } +); diff --git a/src/container/modules/node-transformers/RenamePropertiesTransformersModule.ts b/src/container/modules/node-transformers/RenamePropertiesTransformersModule.ts index 6812e7861..2d1c79c07 100644 --- a/src/container/modules/node-transformers/RenamePropertiesTransformersModule.ts +++ b/src/container/modules/node-transformers/RenamePropertiesTransformersModule.ts @@ -9,13 +9,14 @@ import { NodeTransformer } from '../../../enums/node-transformers/NodeTransforme import { RenamePropertiesReplacer } from '../../../node-transformers/rename-properties-transformers/replacer/RenamePropertiesReplacer'; import { RenamePropertiesTransformer } from '../../../node-transformers/rename-properties-transformers/RenamePropertiesTransformer'; -export const renamePropertiesTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { - // rename properties transformers - bind(ServiceIdentifiers.INodeTransformer) - .to(RenamePropertiesTransformer) - .whenTargetNamed(NodeTransformer.RenamePropertiesTransformer); +export const renamePropertiesTransformersModule: interfaces.ContainerModule = new ContainerModule( + (bind: interfaces.Bind) => { + // rename properties transformers + bind(ServiceIdentifiers.INodeTransformer) + .to(RenamePropertiesTransformer) + .whenTargetNamed(NodeTransformer.RenamePropertiesTransformer); - // rename properties obfuscating replacer - bind(ServiceIdentifiers.IRenamePropertiesReplacer) - .to(RenamePropertiesReplacer); -}); + // rename properties obfuscating replacer + bind(ServiceIdentifiers.IRenamePropertiesReplacer).to(RenamePropertiesReplacer); + } +); diff --git a/src/container/modules/node-transformers/SimplifyingTransformersModule.ts b/src/container/modules/node-transformers/SimplifyingTransformersModule.ts index 145d15f17..ea1c8163c 100644 --- a/src/container/modules/node-transformers/SimplifyingTransformersModule.ts +++ b/src/container/modules/node-transformers/SimplifyingTransformersModule.ts @@ -10,21 +10,23 @@ import { ExpressionStatementsMergeTransformer } from '../../../node-transformers import { IfStatementSimplifyTransformer } from '../../../node-transformers/simplifying-transformers/IfStatementSimplifyTransformer'; import { VariableDeclarationsMergeTransformer } from '../../../node-transformers/simplifying-transformers/VariableDeclarationsMergeTransformer'; -export const simplifyingTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { - // simplifying transformers - bind(ServiceIdentifiers.INodeTransformer) - .to(BlockStatementSimplifyTransformer) - .whenTargetNamed(NodeTransformer.BlockStatementSimplifyTransformer); +export const simplifyingTransformersModule: interfaces.ContainerModule = new ContainerModule( + (bind: interfaces.Bind) => { + // simplifying transformers + bind(ServiceIdentifiers.INodeTransformer) + .to(BlockStatementSimplifyTransformer) + .whenTargetNamed(NodeTransformer.BlockStatementSimplifyTransformer); - bind(ServiceIdentifiers.INodeTransformer) - .to(ExpressionStatementsMergeTransformer) - .whenTargetNamed(NodeTransformer.ExpressionStatementsMergeTransformer); + bind(ServiceIdentifiers.INodeTransformer) + .to(ExpressionStatementsMergeTransformer) + .whenTargetNamed(NodeTransformer.ExpressionStatementsMergeTransformer); - bind(ServiceIdentifiers.INodeTransformer) - .to(IfStatementSimplifyTransformer) - .whenTargetNamed(NodeTransformer.IfStatementSimplifyTransformer); + bind(ServiceIdentifiers.INodeTransformer) + .to(IfStatementSimplifyTransformer) + .whenTargetNamed(NodeTransformer.IfStatementSimplifyTransformer); - bind(ServiceIdentifiers.INodeTransformer) - .to(VariableDeclarationsMergeTransformer) - .whenTargetNamed(NodeTransformer.VariableDeclarationsMergeTransformer); -}); + bind(ServiceIdentifiers.INodeTransformer) + .to(VariableDeclarationsMergeTransformer) + .whenTargetNamed(NodeTransformer.VariableDeclarationsMergeTransformer); + } +); diff --git a/src/container/modules/node-transformers/StringArrayTransformersModule.ts b/src/container/modules/node-transformers/StringArrayTransformersModule.ts index 2ab43e489..1c5d1c4ae 100644 --- a/src/container/modules/node-transformers/StringArrayTransformersModule.ts +++ b/src/container/modules/node-transformers/StringArrayTransformersModule.ts @@ -9,17 +9,19 @@ import { StringArrayRotateFunctionTransformer } from '../../../node-transformers import { StringArrayScopeCallsWrapperTransformer } from '../../../node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer'; import { StringArrayTransformer } from '../../../node-transformers/string-array-transformers/StringArrayTransformer'; -export const stringArrayTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { - // strings transformers - bind(ServiceIdentifiers.INodeTransformer) - .to(StringArrayRotateFunctionTransformer) - .whenTargetNamed(NodeTransformer.StringArrayRotateFunctionTransformer); +export const stringArrayTransformersModule: interfaces.ContainerModule = new ContainerModule( + (bind: interfaces.Bind) => { + // strings transformers + bind(ServiceIdentifiers.INodeTransformer) + .to(StringArrayRotateFunctionTransformer) + .whenTargetNamed(NodeTransformer.StringArrayRotateFunctionTransformer); - bind(ServiceIdentifiers.INodeTransformer) - .to(StringArrayScopeCallsWrapperTransformer) - .whenTargetNamed(NodeTransformer.StringArrayScopeCallsWrapperTransformer); + bind(ServiceIdentifiers.INodeTransformer) + .to(StringArrayScopeCallsWrapperTransformer) + .whenTargetNamed(NodeTransformer.StringArrayScopeCallsWrapperTransformer); - bind(ServiceIdentifiers.INodeTransformer) - .to(StringArrayTransformer) - .whenTargetNamed(NodeTransformer.StringArrayTransformer); -}); + bind(ServiceIdentifiers.INodeTransformer) + .to(StringArrayTransformer) + .whenTargetNamed(NodeTransformer.StringArrayTransformer); + } +); diff --git a/src/container/modules/options/OptionsModule.ts b/src/container/modules/options/OptionsModule.ts index 5e4644164..1e6fc1502 100644 --- a/src/container/modules/options/OptionsModule.ts +++ b/src/container/modules/options/OptionsModule.ts @@ -8,11 +8,7 @@ import { Options } from '../../../options/Options'; import { OptionsNormalizer } from '../../../options/OptionsNormalizer'; export const optionsModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { - bind(ServiceIdentifiers.IOptions) - .to(Options) - .inSingletonScope(); + bind(ServiceIdentifiers.IOptions).to(Options).inSingletonScope(); - bind(ServiceIdentifiers.IOptionsNormalizer) - .to(OptionsNormalizer) - .inSingletonScope(); + bind(ServiceIdentifiers.IOptionsNormalizer).to(OptionsNormalizer).inSingletonScope(); }); diff --git a/src/container/modules/storages/StoragesModule.ts b/src/container/modules/storages/StoragesModule.ts index 52bc65055..ead8cdc42 100644 --- a/src/container/modules/storages/StoragesModule.ts +++ b/src/container/modules/storages/StoragesModule.ts @@ -2,9 +2,7 @@ import { ContainerModule, interfaces } from 'inversify'; import { ServiceIdentifiers } from '../../ServiceIdentifiers'; import { TControlFlowStorageFactory } from '../../../types/container/node-transformers/TControlFlowStorageFactory'; -import { - TControlFlowStorageFactoryCreator -} from '../../../types/container/node-transformers/TControlFlowStorageFactoryCreator'; +import { TControlFlowStorageFactoryCreator } from '../../../types/container/node-transformers/TControlFlowStorageFactoryCreator'; import { TCustomCodeHelperGroupStorage } from '../../../types/storages/TCustomCodeHelperGroupStorage'; import { IControlFlowStorage } from '../../../interfaces/storages/control-flow-transformers/IControlFlowStorage'; @@ -23,9 +21,7 @@ import { GlobalIdentifierNamesCacheStorage } from '../../../storages/identifier- import { LiteralNodesCacheStorage } from '../../../storages/string-array-transformers/LiteralNodesCacheStorage'; import { PropertyIdentifierNamesCacheStorage } from '../../../storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage'; import { StringArrayScopeCallsWrappersDataStorage } from '../../../storages/string-array-transformers/StringArrayScopeCallsWrappersDataStorage'; -import { - StringControlFlowStorage -} from '../../../storages/control-flow-transformers/StringControlFlowStorage'; +import { StringControlFlowStorage } from '../../../storages/control-flow-transformers/StringControlFlowStorage'; import { StringArrayStorage } from '../../../storages/string-array-transformers/StringArrayStorage'; import { VisitedLexicalScopeNodesStackStorage } from '../../../storages/string-array-transformers/VisitedLexicalScopeNodesStackStorage'; @@ -51,9 +47,7 @@ export const storagesModule: interfaces.ContainerModule = new ContainerModule((b .to(PropertyIdentifierNamesCacheStorage) .inSingletonScope(); - bind(ServiceIdentifiers.IStringArrayStorage) - .to(StringArrayStorage) - .inSingletonScope(); + bind(ServiceIdentifiers.IStringArrayStorage).to(StringArrayStorage).inSingletonScope(); bind(ServiceIdentifiers.IStringArrayScopeCallsWrappersDataStorage) .to(StringArrayScopeCallsWrappersDataStorage) @@ -68,12 +62,13 @@ export const storagesModule: interfaces.ContainerModule = new ContainerModule((b .inSingletonScope(); // controlFlowStorage factory - bind(ServiceIdentifiers.Factory__TControlFlowStorage) - .toFactory((context: interfaces.Context): TControlFlowStorageFactoryCreator => - (controlFlowStorageName: ControlFlowStorage): TControlFlowStorageFactory => (): IControlFlowStorage => + bind(ServiceIdentifiers.Factory__TControlFlowStorage).toFactory( + (context: interfaces.Context): TControlFlowStorageFactoryCreator => + (controlFlowStorageName: ControlFlowStorage): TControlFlowStorageFactory => + (): IControlFlowStorage => context.container.getNamed( - ServiceIdentifiers.IControlFlowStorage, - controlFlowStorageName + ServiceIdentifiers.IControlFlowStorage, + controlFlowStorageName ) - ); + ); }); diff --git a/src/container/modules/utils/UtilsModule.ts b/src/container/modules/utils/UtilsModule.ts index 8ec11832a..5b31f33ae 100644 --- a/src/container/modules/utils/UtilsModule.ts +++ b/src/container/modules/utils/UtilsModule.ts @@ -19,19 +19,13 @@ import { SetUtils } from '../../../utils/SetUtils'; export const utilsModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { // array utils - bind(ServiceIdentifiers.IArrayUtils) - .to(ArrayUtils) - .inSingletonScope(); + bind(ServiceIdentifiers.IArrayUtils).to(ArrayUtils).inSingletonScope(); // random generator - bind(ServiceIdentifiers.IRandomGenerator) - .to(RandomGenerator) - .inSingletonScope(); + bind(ServiceIdentifiers.IRandomGenerator).to(RandomGenerator).inSingletonScope(); // crypt utils - bind(ServiceIdentifiers.ICryptUtils) - .to(CryptUtils) - .inSingletonScope(); + bind(ServiceIdentifiers.ICryptUtils).to(CryptUtils).inSingletonScope(); // crypt utils for string array bind(ServiceIdentifiers.ICryptUtilsStringArray) @@ -44,11 +38,8 @@ export const utilsModule: interfaces.ContainerModule = new ContainerModule((bind .inSingletonScope(); // levelled topological sorter - bind(ServiceIdentifiers.ILevelledTopologicalSorter) - .to(LevelledTopologicalSorter); + bind(ServiceIdentifiers.ILevelledTopologicalSorter).to(LevelledTopologicalSorter); // set utils - bind(ServiceIdentifiers.ISetUtils) - .to(SetUtils) - .inSingletonScope(); + bind(ServiceIdentifiers.ISetUtils).to(SetUtils).inSingletonScope(); }); diff --git a/src/custom-code-helpers/AbstractCustomCodeHelper.ts b/src/custom-code-helpers/AbstractCustomCodeHelper.ts index a6c550134..e9669f836 100644 --- a/src/custom-code-helpers/AbstractCustomCodeHelper.ts +++ b/src/custom-code-helpers/AbstractCustomCodeHelper.ts @@ -18,9 +18,9 @@ import { GlobalVariableNoEvalTemplate } from './common/templates/GlobalVariableN import { GlobalVariableServiceWorkerTemplate } from './common/templates/GlobalVariableServiceWorkerTemplate'; @injectable() -export abstract class AbstractCustomCodeHelper < - TInitialData extends unknown[] = unknown[] -> implements ICustomCodeHelper { +export abstract class AbstractCustomCodeHelper + implements ICustomCodeHelper +{ /** * @type {string[]} */ @@ -66,9 +66,9 @@ export abstract class AbstractCustomCodeHelper < * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -84,13 +84,11 @@ export abstract class AbstractCustomCodeHelper < /** * @returns {TStatement[]} */ - public getNode (): TStatement[] { + public getNode(): TStatement[] { if (!this.cachedNode) { const codeHelperTemplate: string = this.getCodeHelperTemplate(); - this.cachedNode = this.customCodeHelperFormatter.formatStructure( - this.getNodeStructure(codeHelperTemplate) - ); + this.cachedNode = this.customCodeHelperFormatter.formatStructure(this.getNodeStructure(codeHelperTemplate)); } return this.cachedNode; @@ -99,7 +97,7 @@ export abstract class AbstractCustomCodeHelper < /** * @returns {string} */ - protected getGlobalVariableTemplate (): string { + protected getGlobalVariableTemplate(): string { switch (this.options.target) { case ObfuscationTarget.BrowserNoEval: return GlobalVariableNoEvalTemplate(); @@ -115,17 +113,17 @@ export abstract class AbstractCustomCodeHelper < /** * @returns {string} */ - protected getCodeHelperTemplate (): string { + protected getCodeHelperTemplate(): string { return ''; } /** * @param {TInitialData} args */ - public abstract initialize (...args: TInitialData): void; + public abstract initialize(...args: TInitialData): void; /** * @returns {TStatement[]} */ - protected abstract getNodeStructure (codeHelperTemplate: string): TStatement[]; + protected abstract getNodeStructure(codeHelperTemplate: string): TStatement[]; } diff --git a/src/custom-code-helpers/AbstractCustomCodeHelperGroup.ts b/src/custom-code-helpers/AbstractCustomCodeHelperGroup.ts index 5b6e86824..267a09db2 100644 --- a/src/custom-code-helpers/AbstractCustomCodeHelperGroup.ts +++ b/src/custom-code-helpers/AbstractCustomCodeHelperGroup.ts @@ -31,16 +31,16 @@ export abstract class AbstractCustomCodeHelperGroup implements ICustomCodeHelper /** * @type {Map} */ - protected abstract customCodeHelpers: Map ; + protected abstract customCodeHelpers: Map; /** * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -52,7 +52,7 @@ export abstract class AbstractCustomCodeHelperGroup implements ICustomCodeHelper /** * @returns {Map} */ - public getCustomCodeHelpers (): Map { + public getCustomCodeHelpers(): Map { return this.customCodeHelpers; } @@ -60,7 +60,10 @@ export abstract class AbstractCustomCodeHelperGroup implements ICustomCodeHelper * @param {CustomCodeHelper} customCodeHelperName * @param {callback} callback */ - protected appendCustomNodeIfExist (customCodeHelperName: CustomCodeHelper, callback: (customCodeHelper: ICustomCodeHelper) => void): void { + protected appendCustomNodeIfExist( + customCodeHelperName: CustomCodeHelper, + callback: (customCodeHelper: ICustomCodeHelper) => void + ): void { const customCodeHelper: ICustomCodeHelper | undefined = this.customCodeHelpers.get(customCodeHelperName); if (!customCodeHelper) { @@ -75,9 +78,9 @@ export abstract class AbstractCustomCodeHelperGroup implements ICustomCodeHelper * @returns {number} */ - protected getRandomCallsGraphIndex (callsGraphLength: number): number { + protected getRandomCallsGraphIndex(callsGraphLength: number): number { return this.randomGenerator.getRandomInteger(0, Math.max(0, Math.round(callsGraphLength - 1))); } - public abstract initialize (): void; + public abstract initialize(): void; } diff --git a/src/custom-code-helpers/CustomCodeHelperFormatter.ts b/src/custom-code-helpers/CustomCodeHelperFormatter.ts index b24464a0e..a62be6b74 100644 --- a/src/custom-code-helpers/CustomCodeHelperFormatter.ts +++ b/src/custom-code-helpers/CustomCodeHelperFormatter.ts @@ -20,9 +20,9 @@ export class CustomCodeHelperFormatter implements ICustomCodeHelperFormatter { */ private readonly prevailingKindOfVariables: ESTree.VariableDeclaration['kind']; - public constructor ( + public constructor( @inject(ServiceIdentifiers.IPrevailingKindOfVariablesAnalyzer) - prevailingKindOfVariablesAnalyzer: IPrevailingKindOfVariablesAnalyzer + prevailingKindOfVariablesAnalyzer: IPrevailingKindOfVariablesAnalyzer ) { this.prevailingKindOfVariables = prevailingKindOfVariablesAnalyzer.getPrevailingKind(); } @@ -32,10 +32,7 @@ export class CustomCodeHelperFormatter implements ICustomCodeHelperFormatter { * @param {TMapping} mapping * @returns {string} */ - public formatTemplate ( - template: string, - mapping: TMapping - ): string { + public formatTemplate(template: string, mapping: TMapping): string { return format(template, mapping); } @@ -43,7 +40,7 @@ export class CustomCodeHelperFormatter implements ICustomCodeHelperFormatter { * @param {TStatement[]} statements * @returns {TStatement[]} */ - public formatStructure (statements: TStatement[]): TStatement[] { + public formatStructure(statements: TStatement[]): TStatement[] { for (const statement of statements) { estraverse.replace(statement, { enter: (node: ESTree.Node): ESTree.Node | void => { diff --git a/src/custom-code-helpers/CustomCodeHelperObfuscator.ts b/src/custom-code-helpers/CustomCodeHelperObfuscator.ts index f33bc251f..76cc9a36c 100644 --- a/src/custom-code-helpers/CustomCodeHelperObfuscator.ts +++ b/src/custom-code-helpers/CustomCodeHelperObfuscator.ts @@ -27,7 +27,7 @@ export class CustomCodeHelperObfuscator implements ICustomCodeHelperObfuscator { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -40,18 +40,15 @@ export class CustomCodeHelperObfuscator implements ICustomCodeHelperObfuscator { * @param {TInputOptions} additionalOptions * @returns {string} */ - public obfuscateTemplate (template: string, additionalOptions: TInputOptions = {}): string { - return JavaScriptObfuscator.obfuscate( - template, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: this.options.identifierNamesGenerator, - identifiersDictionary: this.options.identifiersDictionary, - numbersToExpressions: this.options.numbersToExpressions, - simplify: this.options.simplify, - seed: this.randomGenerator.getRawSeed(), - ...additionalOptions - } - ).getObfuscatedCode(); + public obfuscateTemplate(template: string, additionalOptions: TInputOptions = {}): string { + return JavaScriptObfuscator.obfuscate(template, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: this.options.identifierNamesGenerator, + identifiersDictionary: this.options.identifiersDictionary, + numbersToExpressions: this.options.numbersToExpressions, + simplify: this.options.simplify, + seed: this.randomGenerator.getRawSeed(), + ...additionalOptions + }).getObfuscatedCode(); } } diff --git a/src/custom-code-helpers/calls-controller/CallsControllerFunctionCodeHelper.ts b/src/custom-code-helpers/calls-controller/CallsControllerFunctionCodeHelper.ts index c9d211213..4f6758ef7 100644 --- a/src/custom-code-helpers/calls-controller/CallsControllerFunctionCodeHelper.ts +++ b/src/custom-code-helpers/calls-controller/CallsControllerFunctionCodeHelper.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -39,9 +39,9 @@ export class CallsControllerFunctionCodeHelper extends AbstractCustomCodeHelper * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -60,7 +60,7 @@ export class CallsControllerFunctionCodeHelper extends AbstractCustomCodeHelper * @param {NodeTransformationStage} nodeTransformationStage * @param {string} callsControllerFunctionName */ - public initialize (nodeTransformationStage: NodeTransformationStage, callsControllerFunctionName: string): void { + public initialize(nodeTransformationStage: NodeTransformationStage, callsControllerFunctionName: string): void { this.nodeTransformationStage = nodeTransformationStage; this.callsControllerFunctionName = callsControllerFunctionName; } @@ -69,14 +69,14 @@ export class CallsControllerFunctionCodeHelper extends AbstractCustomCodeHelper * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { + protected override getCodeHelperTemplate(): string { if (this.nodeTransformationStage === NodeTransformationStage.Finalizing) { return this.customCodeHelperObfuscator.obfuscateTemplate( this.customCodeHelperFormatter.formatTemplate(SingleCallControllerTemplate(), { diff --git a/src/custom-code-helpers/console-output/ConsoleOutputDisableCodeHelper.ts b/src/custom-code-helpers/console-output/ConsoleOutputDisableCodeHelper.ts index 8f34a5bc0..f342aedf2 100644 --- a/src/custom-code-helpers/console-output/ConsoleOutputDisableCodeHelper.ts +++ b/src/custom-code-helpers/console-output/ConsoleOutputDisableCodeHelper.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -9,7 +9,6 @@ import { ICustomCodeHelperObfuscator } from '../../interfaces/custom-code-helper import { IOptions } from '../../interfaces/options/IOptions'; import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; - import { ConsoleOutputDisableTemplate } from './templates/ConsoleOutputDisableTemplate'; import { initializable } from '../../decorators/Initializable'; @@ -38,9 +37,9 @@ export class ConsoleOutputDisableCodeHelper extends AbstractCustomCodeHelper { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -59,7 +58,7 @@ export class ConsoleOutputDisableCodeHelper extends AbstractCustomCodeHelper { * @param {string} callsControllerFunctionName * @param {StaticRange} consoleOutputDisableFunctionName */ - public initialize (callsControllerFunctionName: string, consoleOutputDisableFunctionName: string): void { + public initialize(callsControllerFunctionName: string, consoleOutputDisableFunctionName: string): void { this.callsControllerFunctionName = callsControllerFunctionName; this.consoleOutputDisableFunctionName = consoleOutputDisableFunctionName; } @@ -68,18 +67,18 @@ export class ConsoleOutputDisableCodeHelper extends AbstractCustomCodeHelper { * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { + protected override getCodeHelperTemplate(): string { return this.customCodeHelperFormatter.formatTemplate(ConsoleOutputDisableTemplate(), { callControllerFunctionName: this.callsControllerFunctionName, consoleLogDisableFunctionName: this.consoleOutputDisableFunctionName, - globalVariableTemplate: this.getGlobalVariableTemplate(), + globalVariableTemplate: this.getGlobalVariableTemplate() }); } } diff --git a/src/custom-code-helpers/console-output/group/ConsoleOutputCodeHelperGroup.ts b/src/custom-code-helpers/console-output/group/ConsoleOutputCodeHelperGroup.ts index 4ffae2bbe..75f584ea1 100644 --- a/src/custom-code-helpers/console-output/group/ConsoleOutputCodeHelperGroup.ts +++ b/src/custom-code-helpers/console-output/group/ConsoleOutputCodeHelperGroup.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { TCustomCodeHelperFactory } from '../../../types/container/custom-code-helpers/TCustomCodeHelperFactory'; @@ -29,7 +29,7 @@ export class ConsoleOutputCodeHelperGroup extends AbstractCustomCodeHelperGroup * @type {Map} */ @initializable() - protected customCodeHelpers!: Map ; + protected customCodeHelpers!: Map; /** * @type {TCustomCodeHelperFactory} @@ -42,10 +42,10 @@ export class ConsoleOutputCodeHelperGroup extends AbstractCustomCodeHelperGroup * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__ICustomCodeHelper) customCodeHelperFactory: TCustomCodeHelperFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -58,7 +58,7 @@ export class ConsoleOutputCodeHelperGroup extends AbstractCustomCodeHelperGroup * @param {TNodeWithStatements} nodeWithStatements * @param {ICallsGraphData[]} callsGraphData */ - public appendOnPreparingStage (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { + public appendOnPreparingStage(nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { if (!this.options.disableConsoleOutput) { return; } @@ -72,8 +72,8 @@ export class ConsoleOutputCodeHelperGroup extends AbstractCustomCodeHelperGroup ? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1) : nodeWithStatements; - const consoleOutputDisableLexicalScopeNode: TNodeWithLexicalScope | null = NodeLexicalScopeUtils - .getLexicalScope(consoleOutputDisableHostNode) ?? null; + const consoleOutputDisableLexicalScopeNode: TNodeWithLexicalScope | null = + NodeLexicalScopeUtils.getLexicalScope(consoleOutputDisableHostNode) ?? null; const consoleOutputDisableFunctionName: string = consoleOutputDisableLexicalScopeNode ? this.identifierNamesGenerator.generate(consoleOutputDisableLexicalScopeNode) @@ -103,15 +103,16 @@ export class ConsoleOutputCodeHelperGroup extends AbstractCustomCodeHelperGroup ); } - public initialize (): void { - this.customCodeHelpers = new Map (); + public initialize(): void { + this.customCodeHelpers = new Map(); if (!this.options.disableConsoleOutput) { return; } - const consoleOutputDisableExpressionCodeHelper: ICustomCodeHelper> = - this.customCodeHelperFactory(CustomCodeHelper.ConsoleOutputDisable); + const consoleOutputDisableExpressionCodeHelper: ICustomCodeHelper< + TInitialData + > = this.customCodeHelperFactory(CustomCodeHelper.ConsoleOutputDisable); const callsControllerFunctionCodeHelper: ICustomCodeHelper> = this.customCodeHelperFactory(CustomCodeHelper.CallsControllerFunction); diff --git a/src/custom-code-helpers/debug-protection/DebugProtectionFunctionCallCodeHelper.ts b/src/custom-code-helpers/debug-protection/DebugProtectionFunctionCallCodeHelper.ts index 48b170a6e..c00476ecd 100644 --- a/src/custom-code-helpers/debug-protection/DebugProtectionFunctionCallCodeHelper.ts +++ b/src/custom-code-helpers/debug-protection/DebugProtectionFunctionCallCodeHelper.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -37,9 +37,9 @@ export class DebugProtectionFunctionCallCodeHelper extends AbstractCustomCodeHel * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -58,7 +58,7 @@ export class DebugProtectionFunctionCallCodeHelper extends AbstractCustomCodeHel * @param {string} debugProtectionFunctionName * @param {string} callsControllerFunctionName */ - public initialize (debugProtectionFunctionName: string, callsControllerFunctionName: string): void { + public initialize(debugProtectionFunctionName: string, callsControllerFunctionName: string): void { this.debugProtectionFunctionName = debugProtectionFunctionName; this.callsControllerFunctionName = callsControllerFunctionName; } @@ -67,14 +67,14 @@ export class DebugProtectionFunctionCallCodeHelper extends AbstractCustomCodeHel * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { + protected override getCodeHelperTemplate(): string { return this.customCodeHelperFormatter.formatTemplate(DebugProtectionFunctionCallTemplate(), { debugProtectionFunctionName: this.debugProtectionFunctionName, callControllerFunctionName: this.callsControllerFunctionName diff --git a/src/custom-code-helpers/debug-protection/DebugProtectionFunctionCodeHelper.ts b/src/custom-code-helpers/debug-protection/DebugProtectionFunctionCodeHelper.ts index 13b5a1dec..381521de2 100644 --- a/src/custom-code-helpers/debug-protection/DebugProtectionFunctionCodeHelper.ts +++ b/src/custom-code-helpers/debug-protection/DebugProtectionFunctionCodeHelper.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -35,9 +35,9 @@ export class DebugProtectionFunctionCodeHelper extends AbstractCustomCodeHelper * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -55,7 +55,7 @@ export class DebugProtectionFunctionCodeHelper extends AbstractCustomCodeHelper /** * @param {string} debugProtectionFunctionName */ - public initialize (debugProtectionFunctionName: string): void { + public initialize(debugProtectionFunctionName: string): void { this.debugProtectionFunctionName = debugProtectionFunctionName; } @@ -63,17 +63,16 @@ export class DebugProtectionFunctionCodeHelper extends AbstractCustomCodeHelper * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { - const debuggerTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval - ? DebuggerTemplate() - : DebuggerTemplateNoEval(); + protected override getCodeHelperTemplate(): string { + const debuggerTemplate: string = + this.options.target !== ObfuscationTarget.BrowserNoEval ? DebuggerTemplate() : DebuggerTemplateNoEval(); return this.customCodeHelperFormatter.formatTemplate(DebugProtectionFunctionTemplate(), { debuggerTemplate, diff --git a/src/custom-code-helpers/debug-protection/DebugProtectionFunctionIntervalCodeHelper.ts b/src/custom-code-helpers/debug-protection/DebugProtectionFunctionIntervalCodeHelper.ts index 686d32e53..78e8dc187 100644 --- a/src/custom-code-helpers/debug-protection/DebugProtectionFunctionIntervalCodeHelper.ts +++ b/src/custom-code-helpers/debug-protection/DebugProtectionFunctionIntervalCodeHelper.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -40,9 +40,9 @@ export class DebugProtectionFunctionIntervalCodeHelper extends AbstractCustomCod * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -61,7 +61,7 @@ export class DebugProtectionFunctionIntervalCodeHelper extends AbstractCustomCod * @param {string} debugProtectionFunctionName * @param {number} debugProtectionInterval */ - public initialize (debugProtectionFunctionName: string, debugProtectionInterval: number): void { + public initialize(debugProtectionFunctionName: string, debugProtectionInterval: number): void { this.debugProtectionFunctionName = debugProtectionFunctionName; this.debugProtectionInterval = debugProtectionInterval; } @@ -70,17 +70,18 @@ export class DebugProtectionFunctionIntervalCodeHelper extends AbstractCustomCod * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { - const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval - ? this.getGlobalVariableTemplate() - : GlobalVariableNoEvalTemplate(); + protected override getCodeHelperTemplate(): string { + const globalVariableTemplate: string = + this.options.target !== ObfuscationTarget.BrowserNoEval + ? this.getGlobalVariableTemplate() + : GlobalVariableNoEvalTemplate(); return this.customCodeHelperFormatter.formatTemplate(DebugProtectionFunctionIntervalTemplate(), { debugProtectionFunctionName: this.debugProtectionFunctionName, diff --git a/src/custom-code-helpers/debug-protection/group/DebugProtectionCodeHelperGroup.ts b/src/custom-code-helpers/debug-protection/group/DebugProtectionCodeHelperGroup.ts index cfe5e9840..14ad7cfdb 100644 --- a/src/custom-code-helpers/debug-protection/group/DebugProtectionCodeHelperGroup.ts +++ b/src/custom-code-helpers/debug-protection/group/DebugProtectionCodeHelperGroup.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { TCustomCodeHelperFactory } from '../../../types/container/custom-code-helpers/TCustomCodeHelperFactory'; @@ -32,7 +32,7 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou * @type {Map} */ @initializable() - protected customCodeHelpers!: Map ; + protected customCodeHelpers!: Map; /** * @type {TCustomCodeHelperFactory} @@ -45,10 +45,10 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__ICustomCodeHelper) customCodeHelperFactory: TCustomCodeHelperFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -61,7 +61,7 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou * @param {TNodeWithStatements} nodeWithStatements * @param {ICallsGraphData[]} callsGraphData */ - public appendOnPreparingStage (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { + public appendOnPreparingStage(nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { if (!this.options.debugProtection) { return; } @@ -75,8 +75,8 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou ? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1) : nodeWithStatements; - const debugProtectionFunctionCallScopeNode: TNodeWithLexicalScope | null = NodeLexicalScopeUtils - .getLexicalScope(debugProtectionFunctionCallHostNode) ?? null; + const debugProtectionFunctionCallScopeNode: TNodeWithLexicalScope | null = + NodeLexicalScopeUtils.getLexicalScope(debugProtectionFunctionCallHostNode) ?? null; const debugProtectionFunctionName: string = debugProtectionFunctionCallScopeNode ? this.identifierNamesGenerator.generate(debugProtectionFunctionCallScopeNode) @@ -108,7 +108,7 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou // debugProtectionFunction helper nodes append this.appendCustomNodeIfExist( CustomCodeHelper.DebugProtectionFunction, - (customCodeHelper: ICustomCodeHelper>) => { + (customCodeHelper: ICustomCodeHelper>) => { customCodeHelper.initialize(debugProtectionFunctionName); NodeAppender.append(nodeWithStatements, customCodeHelper.getNode()); @@ -131,8 +131,8 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou ); } - public initialize (): void { - this.customCodeHelpers = new Map (); + public initialize(): void { + this.customCodeHelpers = new Map(); if (!this.options.debugProtection) { return; @@ -140,10 +140,12 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou const debugProtectionFunctionCodeHelper: ICustomCodeHelper> = this.customCodeHelperFactory(CustomCodeHelper.DebugProtectionFunction); - const debugProtectionFunctionCallCodeHelper: ICustomCodeHelper> = - this.customCodeHelperFactory(CustomCodeHelper.DebugProtectionFunctionCall); - const debugProtectionFunctionIntervalCodeHelper: ICustomCodeHelper> = - this.customCodeHelperFactory(CustomCodeHelper.DebugProtectionFunctionInterval); + const debugProtectionFunctionCallCodeHelper: ICustomCodeHelper< + TInitialData + > = this.customCodeHelperFactory(CustomCodeHelper.DebugProtectionFunctionCall); + const debugProtectionFunctionIntervalCodeHelper: ICustomCodeHelper< + TInitialData + > = this.customCodeHelperFactory(CustomCodeHelper.DebugProtectionFunctionInterval); const callsControllerFunctionCodeHelper: ICustomCodeHelper> = this.customCodeHelperFactory(CustomCodeHelper.CallsControllerFunction); @@ -151,7 +153,10 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou this.customCodeHelpers.set(CustomCodeHelper.DebugProtectionFunctionCall, debugProtectionFunctionCallCodeHelper); if (this.options.debugProtectionInterval) { - this.customCodeHelpers.set(CustomCodeHelper.DebugProtectionFunctionInterval, debugProtectionFunctionIntervalCodeHelper); + this.customCodeHelpers.set( + CustomCodeHelper.DebugProtectionFunctionInterval, + debugProtectionFunctionIntervalCodeHelper + ); } this.customCodeHelpers.set(CustomCodeHelper.CallsControllerFunction, callsControllerFunctionCodeHelper); diff --git a/src/custom-code-helpers/debug-protection/templates/debug-protection-function-call/DebugProtectionFunctionCallTemplate.ts b/src/custom-code-helpers/debug-protection/templates/debug-protection-function-call/DebugProtectionFunctionCallTemplate.ts index 2382da795..162b65d41 100644 --- a/src/custom-code-helpers/debug-protection/templates/debug-protection-function-call/DebugProtectionFunctionCallTemplate.ts +++ b/src/custom-code-helpers/debug-protection/templates/debug-protection-function-call/DebugProtectionFunctionCallTemplate.ts @@ -1,7 +1,7 @@ /** * @returns {string} */ -export function DebugProtectionFunctionCallTemplate (): string { +export function DebugProtectionFunctionCallTemplate(): string { return ` (function () { {callControllerFunctionName}( diff --git a/src/custom-code-helpers/debug-protection/templates/debug-protection-function-interval/DebugProtectionFunctionIntervalTemplate.ts b/src/custom-code-helpers/debug-protection/templates/debug-protection-function-interval/DebugProtectionFunctionIntervalTemplate.ts index fca700e54..3137f5e6a 100644 --- a/src/custom-code-helpers/debug-protection/templates/debug-protection-function-interval/DebugProtectionFunctionIntervalTemplate.ts +++ b/src/custom-code-helpers/debug-protection/templates/debug-protection-function-interval/DebugProtectionFunctionIntervalTemplate.ts @@ -1,7 +1,7 @@ /** * @returns {string} */ -export function DebugProtectionFunctionIntervalTemplate (): string { +export function DebugProtectionFunctionIntervalTemplate(): string { return ` (function () { {globalVariableTemplate} diff --git a/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebugProtectionFunctionTemplate.ts b/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebugProtectionFunctionTemplate.ts index ef61656ff..dae4007eb 100644 --- a/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebugProtectionFunctionTemplate.ts +++ b/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebugProtectionFunctionTemplate.ts @@ -1,7 +1,7 @@ /** * @returns {string} */ -export function DebugProtectionFunctionTemplate (): string { +export function DebugProtectionFunctionTemplate(): string { return ` function {debugProtectionFunctionName} (ret) { function debuggerProtection (counter) { diff --git a/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebuggerTemplate.ts b/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebuggerTemplate.ts index eeb93b38a..8740e592f 100644 --- a/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebuggerTemplate.ts +++ b/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebuggerTemplate.ts @@ -1,7 +1,7 @@ /** * @returns {string} */ -export function DebuggerTemplate (): string { +export function DebuggerTemplate(): string { return ` if (typeof counter === 'string') { return (function (arg) {}.constructor('while (true) {}').apply('counter')); diff --git a/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebuggerTemplateNoEval.ts b/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebuggerTemplateNoEval.ts index fe52b6ba3..62f841b06 100644 --- a/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebuggerTemplateNoEval.ts +++ b/src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebuggerTemplateNoEval.ts @@ -1,7 +1,7 @@ /** * @returns {string} */ -export function DebuggerTemplateNoEval (): string { +export function DebuggerTemplateNoEval(): string { return ` if (typeof counter === 'string') { const func = function () { diff --git a/src/custom-code-helpers/domain-lock/DomainLockCodeHelper.ts b/src/custom-code-helpers/domain-lock/DomainLockCodeHelper.ts index 9a92b15c8..eb683161a 100644 --- a/src/custom-code-helpers/domain-lock/DomainLockCodeHelper.ts +++ b/src/custom-code-helpers/domain-lock/DomainLockCodeHelper.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -47,9 +47,9 @@ export class DomainLockCodeHelper extends AbstractCustomCodeHelper { * @param {IOptions} options * @param {ICryptUtils} cryptUtils */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -71,7 +71,7 @@ export class DomainLockCodeHelper extends AbstractCustomCodeHelper { * @param {string} callsControllerFunctionName * @param {string} domainLockFunctionName */ - public initialize (callsControllerFunctionName: string, domainLockFunctionName: string): void { + public initialize(callsControllerFunctionName: string, domainLockFunctionName: string): void { this.callsControllerFunctionName = callsControllerFunctionName; this.domainLockFunctionName = domainLockFunctionName; } @@ -80,14 +80,14 @@ export class DomainLockCodeHelper extends AbstractCustomCodeHelper { * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { + protected override getCodeHelperTemplate(): string { const domainsString: string = this.options.domainLock.join(';'); const domainsLockRedirectUrl: string = this.options.domainLockRedirectUrl; const [hiddenDomainsString, domainsStringDiff]: string[] = this.cryptUtils.hideString( @@ -98,9 +98,10 @@ export class DomainLockCodeHelper extends AbstractCustomCodeHelper { domainsLockRedirectUrl, domainsLockRedirectUrl.length * 3 ); - const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval - ? this.getGlobalVariableTemplate() - : GlobalVariableNoEvalTemplate(); + const globalVariableTemplate: string = + this.options.target !== ObfuscationTarget.BrowserNoEval + ? this.getGlobalVariableTemplate() + : GlobalVariableNoEvalTemplate(); return this.customCodeHelperFormatter.formatTemplate(DomainLockTemplate(), { callControllerFunctionName: this.callsControllerFunctionName, diff --git a/src/custom-code-helpers/domain-lock/group/DomainLockCustomCodeHelperGroup.ts b/src/custom-code-helpers/domain-lock/group/DomainLockCustomCodeHelperGroup.ts index 48ed83266..e768d03fa 100644 --- a/src/custom-code-helpers/domain-lock/group/DomainLockCustomCodeHelperGroup.ts +++ b/src/custom-code-helpers/domain-lock/group/DomainLockCustomCodeHelperGroup.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { TCustomCodeHelperFactory } from '../../../types/container/custom-code-helpers/TCustomCodeHelperFactory'; @@ -29,7 +29,7 @@ export class DomainLockCustomCodeHelperGroup extends AbstractCustomCodeHelperGro * @type {Map} */ @initializable() - protected customCodeHelpers!: Map ; + protected customCodeHelpers!: Map; /** * @type {TCustomCodeHelperFactory} @@ -42,10 +42,10 @@ export class DomainLockCustomCodeHelperGroup extends AbstractCustomCodeHelperGro * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__ICustomCodeHelper) customCodeHelperFactory: TCustomCodeHelperFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -58,7 +58,7 @@ export class DomainLockCustomCodeHelperGroup extends AbstractCustomCodeHelperGro * @param {TNodeWithStatements} nodeWithStatements * @param {ICallsGraphData[]} callsGraphData */ - public appendOnPreparingStage (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { + public appendOnPreparingStage(nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { if (!this.options.domainLock.length) { return; } @@ -72,8 +72,8 @@ export class DomainLockCustomCodeHelperGroup extends AbstractCustomCodeHelperGro ? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1) : nodeWithStatements; - const domainLockFunctionLexicalScopeNode: TNodeWithLexicalScope | null = NodeLexicalScopeUtils - .getLexicalScope(domainLockFunctionHostNode) ?? null; + const domainLockFunctionLexicalScopeNode: TNodeWithLexicalScope | null = + NodeLexicalScopeUtils.getLexicalScope(domainLockFunctionHostNode) ?? null; const domainLockFunctionName: string = domainLockFunctionLexicalScopeNode ? this.identifierNamesGenerator.generate(domainLockFunctionLexicalScopeNode) @@ -103,8 +103,8 @@ export class DomainLockCustomCodeHelperGroup extends AbstractCustomCodeHelperGro ); } - public initialize (): void { - this.customCodeHelpers = new Map (); + public initialize(): void { + this.customCodeHelpers = new Map(); if (!this.options.domainLock.length) { return; diff --git a/src/custom-code-helpers/self-defending/SelfDefendingCodeHelper.ts b/src/custom-code-helpers/self-defending/SelfDefendingCodeHelper.ts index 86d02a2e2..b03a052c2 100644 --- a/src/custom-code-helpers/self-defending/SelfDefendingCodeHelper.ts +++ b/src/custom-code-helpers/self-defending/SelfDefendingCodeHelper.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -37,9 +37,9 @@ export class SelfDefendingCodeHelper extends AbstractCustomCodeHelper { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -58,7 +58,7 @@ export class SelfDefendingCodeHelper extends AbstractCustomCodeHelper { * @param {string} callsControllerFunctionName * @param {string} selfDefendingFunctionName */ - public initialize (callsControllerFunctionName: string, selfDefendingFunctionName: string): void { + public initialize(callsControllerFunctionName: string, selfDefendingFunctionName: string): void { this.callsControllerFunctionName = callsControllerFunctionName; this.selfDefendingFunctionName = selfDefendingFunctionName; } @@ -67,14 +67,14 @@ export class SelfDefendingCodeHelper extends AbstractCustomCodeHelper { * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { + protected override getCodeHelperTemplate(): string { return this.customCodeHelperFormatter.formatTemplate(SelfDefendingTemplate(), { callControllerFunctionName: this.callsControllerFunctionName, selfDefendingFunctionName: this.selfDefendingFunctionName diff --git a/src/custom-code-helpers/self-defending/group/SelfDefendingCodeHelperGroup.ts b/src/custom-code-helpers/self-defending/group/SelfDefendingCodeHelperGroup.ts index b747c682c..ebb46590c 100644 --- a/src/custom-code-helpers/self-defending/group/SelfDefendingCodeHelperGroup.ts +++ b/src/custom-code-helpers/self-defending/group/SelfDefendingCodeHelperGroup.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { TCustomCodeHelperFactory } from '../../../types/container/custom-code-helpers/TCustomCodeHelperFactory'; @@ -29,7 +29,7 @@ export class SelfDefendingCodeHelperGroup extends AbstractCustomCodeHelperGroup * @type {Map} */ @initializable() - protected customCodeHelpers!: Map ; + protected customCodeHelpers!: Map; /** * @type {TCustomCodeHelperFactory} @@ -42,10 +42,10 @@ export class SelfDefendingCodeHelperGroup extends AbstractCustomCodeHelperGroup * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__ICustomCodeHelper) customCodeHelperFactory: TCustomCodeHelperFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -58,7 +58,7 @@ export class SelfDefendingCodeHelperGroup extends AbstractCustomCodeHelperGroup * @param {TNodeWithStatements} nodeWithStatements * @param {ICallsGraphData[]} callsGraphData */ - public appendOnPreparingStage (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { + public appendOnPreparingStage(nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { if (!this.options.selfDefending) { return; } @@ -72,8 +72,8 @@ export class SelfDefendingCodeHelperGroup extends AbstractCustomCodeHelperGroup ? NodeAppender.getOptimalBlockScope(callsGraphData, randomCallsGraphIndex, 1) : nodeWithStatements; - const selfDefendingFunctionLexicalScopeNode: TNodeWithLexicalScope | null = NodeLexicalScopeUtils - .getLexicalScope(selfDefendingFunctionHostNode) ?? null; + const selfDefendingFunctionLexicalScopeNode: TNodeWithLexicalScope | null = + NodeLexicalScopeUtils.getLexicalScope(selfDefendingFunctionHostNode) ?? null; const selfDefendingFunctionName: string = selfDefendingFunctionLexicalScopeNode ? this.identifierNamesGenerator.generate(selfDefendingFunctionLexicalScopeNode) @@ -103,8 +103,8 @@ export class SelfDefendingCodeHelperGroup extends AbstractCustomCodeHelperGroup ); } - public initialize (): void { - this.customCodeHelpers = new Map (); + public initialize(): void { + this.customCodeHelpers = new Map(); if (!this.options.selfDefending) { return; diff --git a/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts index 43f60033d..61cf1113d 100644 --- a/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts @@ -1,4 +1,4 @@ -import { injectable, } from 'inversify'; +import { injectable } from 'inversify'; import { AtobTemplate } from './templates/string-array-calls-wrapper/AtobTemplate'; import { StringArrayBase64DecodeTemplate } from './templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate'; @@ -10,7 +10,7 @@ export class StringArrayCallsWrapperBase64CodeHelper extends StringArrayCallsWra /** * @returns {string} */ - protected override getDecodeStringArrayTemplate (): string { + protected override getDecodeStringArrayTemplate(): string { const atobFunctionName: string = this.randomGenerator.getRandomString(6); const atobPolyfill: string = this.customCodeHelperFormatter.formatTemplate( @@ -22,15 +22,12 @@ export class StringArrayCallsWrapperBase64CodeHelper extends StringArrayCallsWra const selfDefendingCode: string = this.getSelfDefendingTemplate(); - return this.customCodeHelperFormatter.formatTemplate( - StringArrayBase64DecodeTemplate(this.randomGenerator), - { - atobPolyfill, - atobFunctionName, - selfDefendingCode, - stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, - stringArrayFunctionName: this.stringArrayFunctionName - } - ); + return this.customCodeHelperFormatter.formatTemplate(StringArrayBase64DecodeTemplate(this.randomGenerator), { + atobPolyfill, + atobFunctionName, + selfDefendingCode, + stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, + stringArrayFunctionName: this.stringArrayFunctionName + }); } } diff --git a/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts index e599643dd..ac4e30051 100644 --- a/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -57,9 +57,9 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper * @param {IOptions} options * @param {IEscapeSequenceEncoder} escapeSequenceEncoder */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -82,7 +82,7 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper * @param {string} stringArrayCallsWrapperName * @param {number} indexShiftAmount */ - public initialize ( + public initialize( stringArrayFunctionName: string, stringArrayCallsWrapperName: string, indexShiftAmount: number @@ -98,14 +98,14 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { + protected override getCodeHelperTemplate(): string { const decodeCodeHelperTemplate: string = this.getDecodeStringArrayTemplate(); const preservedNames: string[] = [`^${this.stringArrayFunctionName}$`]; @@ -126,23 +126,20 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper /** * @returns {string} */ - protected getDecodeStringArrayTemplate (): string { + protected getDecodeStringArrayTemplate(): string { return ''; } /** * @returns {string} */ - protected getSelfDefendingTemplate (): string { + protected getSelfDefendingTemplate(): string { if (!this.options.selfDefending) { return ''; } return this.customCodeHelperFormatter.formatTemplate( - SelfDefendingTemplate( - this.randomGenerator, - this.escapeSequenceEncoder - ), + SelfDefendingTemplate(this.randomGenerator, this.escapeSequenceEncoder), { stringArrayCallsWrapperName: this.stringArrayCallsWrapperName } diff --git a/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts index 48074fc00..2f830cbda 100644 --- a/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts @@ -1,4 +1,4 @@ -import { injectable, } from 'inversify'; +import { injectable } from 'inversify'; import { AtobTemplate } from './templates/string-array-calls-wrapper/AtobTemplate'; import { Rc4Template } from './templates/string-array-calls-wrapper/Rc4Template'; @@ -11,7 +11,7 @@ export class StringArrayCallsWrapperRc4CodeHelper extends StringArrayCallsWrappe /** * @returns {string} */ - protected override getDecodeStringArrayTemplate (): string { + protected override getDecodeStringArrayTemplate(): string { const atobFunctionName: string = this.randomGenerator.getRandomString(6); const rc4FunctionName: string = this.randomGenerator.getRandomString(6); @@ -21,26 +21,20 @@ export class StringArrayCallsWrapperRc4CodeHelper extends StringArrayCallsWrappe atobFunctionName } ); - const rc4Polyfill: string = this.customCodeHelperFormatter.formatTemplate( - Rc4Template(), - { - atobFunctionName, - rc4FunctionName - } - ); + const rc4Polyfill: string = this.customCodeHelperFormatter.formatTemplate(Rc4Template(), { + atobFunctionName, + rc4FunctionName + }); const selfDefendingCode: string = this.getSelfDefendingTemplate(); - return this.customCodeHelperFormatter.formatTemplate( - StringArrayRC4DecodeTemplate(this.randomGenerator), - { - atobPolyfill, - rc4FunctionName, - rc4Polyfill, - selfDefendingCode, - stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, - stringArrayFunctionName: this.stringArrayFunctionName - } - ); + return this.customCodeHelperFormatter.formatTemplate(StringArrayRC4DecodeTemplate(this.randomGenerator), { + atobPolyfill, + rc4FunctionName, + rc4Polyfill, + selfDefendingCode, + stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, + stringArrayFunctionName: this.stringArrayFunctionName + }); } } diff --git a/src/custom-code-helpers/string-array/StringArrayCodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCodeHelper.ts index e1c97f755..47ce86139 100644 --- a/src/custom-code-helpers/string-array/StringArrayCodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCodeHelper.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -40,9 +40,9 @@ export class StringArrayCodeHelper extends AbstractCustomCodeHelper { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -61,10 +61,7 @@ export class StringArrayCodeHelper extends AbstractCustomCodeHelper { * @param {IStringArrayStorage} stringArrayStorage * @param {string} stringArrayFunctionName */ - public initialize ( - stringArrayStorage: IStringArrayStorage, - stringArrayFunctionName: string - ): void { + public initialize(stringArrayStorage: IStringArrayStorage, stringArrayFunctionName: string): void { this.stringArrayStorage = stringArrayStorage; this.stringArrayFunctionName = stringArrayFunctionName; } @@ -73,14 +70,14 @@ export class StringArrayCodeHelper extends AbstractCustomCodeHelper { * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { + protected override getCodeHelperTemplate(): string { const stringArrayName: string = this.identifierNamesGenerator.generateNext(); return this.customCodeHelperFormatter.formatTemplate(StringArrayTemplate(), { @@ -93,9 +90,8 @@ export class StringArrayCodeHelper extends AbstractCustomCodeHelper { /** * @returns {string} */ - private getEncodedStringArrayStorageItems (): string { - return Array - .from(this.stringArrayStorage.getStorage().values()) + private getEncodedStringArrayStorageItems(): string { + return Array.from(this.stringArrayStorage.getStorage().values()) .map((stringArrayStorageItemData: IStringArrayStorageItemData): string => { const escapedEncodedValue: string = StringUtils.escapeJsString(stringArrayStorageItemData.encodedValue); diff --git a/src/custom-code-helpers/string-array/StringArrayRotateFunctionCodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayRotateFunctionCodeHelper.ts index 776b26439..563c87495 100644 --- a/src/custom-code-helpers/string-array/StringArrayRotateFunctionCodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayRotateFunctionCodeHelper.ts @@ -1,5 +1,5 @@ import type { Expression } from 'estree'; -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -44,9 +44,9 @@ export class StringArrayRotateFunctionCodeHelper extends AbstractCustomCodeHelpe * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -66,7 +66,7 @@ export class StringArrayRotateFunctionCodeHelper extends AbstractCustomCodeHelpe * @param {number} comparisonValue * @param {Expression} comparisonExpressionNode */ - public initialize ( + public initialize( stringArrayFunctionName: string, comparisonValue: number, comparisonExpressionNode: Expression @@ -80,23 +80,20 @@ export class StringArrayRotateFunctionCodeHelper extends AbstractCustomCodeHelpe * @param {string} codeHelperTemplate * @returns {TStatement[]} */ - protected getNodeStructure (codeHelperTemplate: string): TStatement[] { + protected getNodeStructure(codeHelperTemplate: string): TStatement[] { return NodeUtils.convertCodeToStructure(codeHelperTemplate); } /** * @returns {string} */ - protected override getCodeHelperTemplate (): string { + protected override getCodeHelperTemplate(): string { const comparisonExpressionCode: string = NodeUtils.convertStructureToCode([this.comparisonExpressionNode]); - return this.customCodeHelperFormatter.formatTemplate( - StringArrayRotateFunctionTemplate(), - { - comparisonExpressionCode, - comparisonValue: this.comparisonValue, - stringArrayFunctionName: this.stringArrayFunctionName - } - ); + return this.customCodeHelperFormatter.formatTemplate(StringArrayRotateFunctionTemplate(), { + comparisonExpressionCode, + comparisonValue: this.comparisonValue, + stringArrayFunctionName: this.stringArrayFunctionName + }); } } diff --git a/src/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.ts b/src/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.ts index 90a667b40..242dd8e34 100644 --- a/src/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.ts +++ b/src/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { TCustomCodeHelperFactory } from '../../../types/container/custom-code-helpers/TCustomCodeHelperFactory'; @@ -29,17 +29,19 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup { /** * @type {Map} */ - private static readonly stringArrayCallsWrapperCodeHelperMap: Map = new Map([ - [StringArrayEncoding.None, CustomCodeHelper.StringArrayCallsWrapper], - [StringArrayEncoding.Base64, CustomCodeHelper.StringArrayCallsWrapperBase64], - [StringArrayEncoding.Rc4, CustomCodeHelper.StringArrayCallsWrapperRc4] - ]); + private static readonly stringArrayCallsWrapperCodeHelperMap: Map = new Map( + [ + [StringArrayEncoding.None, CustomCodeHelper.StringArrayCallsWrapper], + [StringArrayEncoding.Base64, CustomCodeHelper.StringArrayCallsWrapperBase64], + [StringArrayEncoding.Rc4, CustomCodeHelper.StringArrayCallsWrapperRc4] + ] + ); /** * @type {Map} */ @initializable() - protected customCodeHelpers!: Map ; + protected customCodeHelpers!: Map; /** * @type {TCustomCodeHelperFactory} @@ -58,11 +60,11 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__ICustomCodeHelper) customCodeHelperFactory: TCustomCodeHelperFactory, @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -76,7 +78,7 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup { * @param {TNodeWithStatements} nodeWithStatements * @param {ICallsGraphData[]} callsGraphData */ - public appendOnFinalizingStage (nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { + public appendOnFinalizingStage(nodeWithStatements: TNodeWithStatements, callsGraphData: ICallsGraphData[]): void { if (!this.stringArrayStorage.getLength()) { return; } @@ -97,7 +99,8 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup { // stringArrayCallsWrapper helper nodes append for (const stringArrayEncoding of this.options.stringArrayEncoding) { - const stringArrayCallsWrapperCodeHelperName: CustomCodeHelper = this.getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding); + const stringArrayCallsWrapperCodeHelperName: CustomCodeHelper = + this.getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding); this.appendCustomNodeIfExist( stringArrayCallsWrapperCodeHelperName, @@ -112,8 +115,8 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup { } } - public initialize (): void { - this.customCodeHelpers = new Map (); + public initialize(): void { + this.customCodeHelpers = new Map(); if (!this.options.stringArray) { return; @@ -125,18 +128,18 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup { const stringArrayCodeHelper: ICustomCodeHelper> = this.customCodeHelperFactory(CustomCodeHelper.StringArray); - stringArrayCodeHelper.initialize( - this.stringArrayStorage, - stringArrayFunctionName - ); + stringArrayCodeHelper.initialize(this.stringArrayStorage, stringArrayFunctionName); this.customCodeHelpers.set(CustomCodeHelper.StringArray, stringArrayCodeHelper); // stringArrayCallsWrapper helper initialize for (const stringArrayEncoding of this.options.stringArrayEncoding) { - const stringArrayCallsWrapperCodeHelperName: CustomCodeHelper = this.getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding); - const stringArrayCallsWrapperCodeHelper: ICustomCodeHelper> = - this.customCodeHelperFactory(stringArrayCallsWrapperCodeHelperName); - const stringArrayCallsWrapperName: string = this.stringArrayStorage.getStorageCallsWrapperName(stringArrayEncoding); + const stringArrayCallsWrapperCodeHelperName: CustomCodeHelper = + this.getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding); + const stringArrayCallsWrapperCodeHelper: ICustomCodeHelper< + TInitialData + > = this.customCodeHelperFactory(stringArrayCallsWrapperCodeHelperName); + const stringArrayCallsWrapperName: string = + this.stringArrayStorage.getStorageCallsWrapperName(stringArrayEncoding); stringArrayCallsWrapperCodeHelper.initialize( stringArrayFunctionName, @@ -152,20 +155,18 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup { * @param {TStringArrayEncoding} stringArrayEncoding * @returns {CustomCodeHelper} */ - private getStringArrayCallsWrapperCodeHelperName (stringArrayEncoding: TStringArrayEncoding): CustomCodeHelper { - return StringArrayCodeHelperGroup - .stringArrayCallsWrapperCodeHelperMap.get(stringArrayEncoding) - ?? CustomCodeHelper.StringArrayCallsWrapper; + private getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding: TStringArrayEncoding): CustomCodeHelper { + return ( + StringArrayCodeHelperGroup.stringArrayCallsWrapperCodeHelperMap.get(stringArrayEncoding) ?? + CustomCodeHelper.StringArrayCallsWrapper + ); } /** * @param {TStatement[]} scopeStatements * @returns {number} */ - private getScopeStatementRandomIndex (scopeStatements: TStatement[]): number { - return this.randomGenerator.getRandomInteger( - 0, - Math.max(0, scopeStatements.length) - ); + private getScopeStatementRandomIndex(scopeStatements: TStatement[]): number { + return this.randomGenerator.getRandomInteger(0, Math.max(0, scopeStatements.length)); } } diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/AtobTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/AtobTemplate.ts index bedeec5f3..340d7b42a 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/AtobTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/AtobTemplate.ts @@ -5,7 +5,7 @@ import { base64alphabetSwapped } from '../../../../constants/Base64AlphabetSwapp * * @returns {string} */ -export function AtobTemplate (selfDefending: boolean): string { +export function AtobTemplate(selfDefending: boolean): string { return ` var {atobFunctionName} = function (input) { const chars = '${base64alphabetSwapped}'; @@ -20,10 +20,8 @@ export function AtobTemplate (selfDefending: boolean): string { ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += ${((): string => { const basePart: string = 'String.fromCharCode(255 & bs >> (-2 * bc & 6))'; - - return selfDefending - ? `((func.charCodeAt(idx + 10) - 10 !== 0) ? ${basePart} : bc)` - : basePart; + + return selfDefending ? `((func.charCodeAt(idx + 10) - 10 !== 0) ? ${basePart} : bc)` : basePart; })()} : 0 ) { diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/Rc4Template.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/Rc4Template.ts index 15f72ad2a..cab18adba 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/Rc4Template.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/Rc4Template.ts @@ -1,7 +1,7 @@ /** * @returns {string} */ -export function Rc4Template (): string { +export function Rc4Template(): string { return ` const {rc4FunctionName} = function (str, key) { let s = [], j = 0, x, output = ''; diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/SelfDefendingTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/SelfDefendingTemplate.ts index bf08c200b..def5c29e9 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/SelfDefendingTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/SelfDefendingTemplate.ts @@ -7,7 +7,7 @@ import { IRandomGenerator } from '../../../../interfaces/utils/IRandomGenerator' * @returns {string} * @constructor */ -export function SelfDefendingTemplate ( +export function SelfDefendingTemplate( randomGenerator: IRandomGenerator, escapeSequenceEncoder: IEscapeSequenceEncoder ): string { @@ -21,18 +21,14 @@ export function SelfDefendingTemplate ( const runStateIdentifier: string = randomGenerator.getRandomString(identifierLength); const getStateIdentifier: string = randomGenerator.getRandomString(identifierLength); const stateResultIdentifier: string = randomGenerator.getRandomString(identifierLength); - + return ` const StatesClass = function (${rc4BytesIdentifier}) { this.${rc4BytesIdentifier} = ${rc4BytesIdentifier}; this.${statesIdentifier} = [1, 0, 0]; this.${newStateIdentifier} = function(){return 'newState';}; - this.${firstStateIdentifier} = '${ - escapeSequenceEncoder.encode('\\w+ *\\(\\) *{\\w+ *', true) - }'; - this.${secondStateIdentifier} = '${ - escapeSequenceEncoder.encode('[\'|"].+[\'|"];? *}', true) - }'; + this.${firstStateIdentifier} = '${escapeSequenceEncoder.encode('\\w+ *\\(\\) *{\\w+ *', true)}'; + this.${secondStateIdentifier} = '${escapeSequenceEncoder.encode('[\'|"].+[\'|"];? *}', true)}'; }; StatesClass.prototype.${checkStateIdentifier} = function () { diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts index b1b0a4f89..9bda4bf2e 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts @@ -5,9 +5,7 @@ import { IRandomGenerator } from '../../../../interfaces/utils/IRandomGenerator' * @returns {string} * @constructor */ -export function StringArrayBase64DecodeTemplate ( - randomGenerator: IRandomGenerator -): string { +export function StringArrayBase64DecodeTemplate(randomGenerator: IRandomGenerator): string { const identifierLength: number = 6; const initializedIdentifier: string = randomGenerator.getRandomString(identifierLength); const base64Identifier: string = randomGenerator.getRandomString(identifierLength); diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts index c7dcaca94..072b6b894 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts @@ -1,7 +1,7 @@ /** * @returns {string} */ -export function StringArrayCallsWrapperTemplate (): string { +export function StringArrayCallsWrapperTemplate(): string { return ` function {stringArrayCallsWrapperName} (index, key) { index = index - {indexShiftAmount}; diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts index 4a8bcbf68..69e4fc8b6 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts @@ -5,9 +5,7 @@ import { IRandomGenerator } from '../../../../interfaces/utils/IRandomGenerator' * @returns {string} * @constructor */ -export function StringArrayRC4DecodeTemplate ( - randomGenerator: IRandomGenerator -): string { +export function StringArrayRC4DecodeTemplate(randomGenerator: IRandomGenerator): string { const identifierLength: number = 6; const initializedIdentifier: string = randomGenerator.getRandomString(identifierLength); const rc4Identifier: string = randomGenerator.getRandomString(identifierLength); diff --git a/src/custom-code-helpers/string-array/templates/string-array-rotate-function/StringArrayRotateFunctionTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-rotate-function/StringArrayRotateFunctionTemplate.ts index 4a8e1203a..bc300c891 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-rotate-function/StringArrayRotateFunctionTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-rotate-function/StringArrayRotateFunctionTemplate.ts @@ -1,7 +1,7 @@ /** * @returns {string} */ -export function StringArrayRotateFunctionTemplate (): string { +export function StringArrayRotateFunctionTemplate(): string { return ` (function (stringArrayFunction, comparisonValue) { const stringArray = stringArrayFunction(); diff --git a/src/custom-code-helpers/string-array/templates/string-array/StringArrayTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array/StringArrayTemplate.ts index a9689e707..a0e05ca02 100644 --- a/src/custom-code-helpers/string-array/templates/string-array/StringArrayTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array/StringArrayTemplate.ts @@ -1,7 +1,7 @@ /** * @returns {string} */ -export function StringArrayTemplate (): string { +export function StringArrayTemplate(): string { return ` function {stringArrayFunctionName} () { const {stringArrayName} = [{stringArrayStorageItems}]; diff --git a/src/custom-nodes/AbstractCustomNode.ts b/src/custom-nodes/AbstractCustomNode.ts index 996227314..63584218f 100644 --- a/src/custom-nodes/AbstractCustomNode.ts +++ b/src/custom-nodes/AbstractCustomNode.ts @@ -11,9 +11,9 @@ import { IOptions } from '../interfaces/options/IOptions'; import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator'; @injectable() -export abstract class AbstractCustomNode < - TInitialData extends unknown[] = unknown[] -> implements ICustomNode { +export abstract class AbstractCustomNode + implements ICustomNode +{ /** * @type {TStatement[] | null} */ @@ -45,9 +45,9 @@ export abstract class AbstractCustomNode < * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions @@ -61,11 +61,9 @@ export abstract class AbstractCustomNode < /** * @returns {TStatement[]} */ - public getNode (): TStatement[] { + public getNode(): TStatement[] { if (!this.cachedNode) { - this.cachedNode = this.customCodeHelperFormatter.formatStructure( - this.getNodeStructure() - ); + this.cachedNode = this.customCodeHelperFormatter.formatStructure(this.getNodeStructure()); } return this.cachedNode; @@ -74,10 +72,10 @@ export abstract class AbstractCustomNode < /** * @param {TInitialData} args */ - public abstract initialize (...args: TInitialData): void; + public abstract initialize(...args: TInitialData): void; /** * @returns {TStatement[]} */ - protected abstract getNodeStructure (): TStatement[]; + protected abstract getNodeStructure(): TStatement[]; } diff --git a/src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts b/src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts index d74718f21..55c02da8a 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import type { BinaryOperator } from 'estree'; @@ -27,38 +27,30 @@ export class BinaryExpressionFunctionNode extends AbstractCustomNode { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** * @param {BinaryOperator} operator */ - public initialize (operator: BinaryOperator): void { + public initialize(operator: BinaryOperator): void { this.operator = operator; } /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const structure: TStatement = NodeFactory.expressionStatementNode( NodeFactory.functionExpressionNode( - [ - NodeFactory.identifierNode('x'), - NodeFactory.identifierNode('y') - ], + [NodeFactory.identifierNode('x'), NodeFactory.identifierNode('y')], NodeFactory.blockStatementNode([ NodeFactory.returnStatementNode( NodeFactory.binaryExpressionNode( diff --git a/src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts b/src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts index d774a9c63..84f64b935 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -45,19 +45,14 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** @@ -65,7 +60,7 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode * @param {number[]} shuffledKeys * @param {number[]} originalKeysIndexesInShuffledArray */ - public initialize ( + public initialize( blockStatementBody: ESTree.Statement[], shuffledKeys: number[], originalKeysIndexesInShuffledArray: number[] @@ -78,7 +73,7 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const controllerIdentifierName: string = this.randomGenerator.getRandomString(6); const indexIdentifierName: string = this.randomGenerator.getRandomString(6); @@ -94,9 +89,7 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode ), NodeFactory.identifierNode('split') ), - [ - NodeFactory.literalNode(StringSeparator.VerticalLine) - ] + [NodeFactory.literalNode(StringSeparator.VerticalLine)] ) ) ], @@ -117,10 +110,7 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode NodeFactory.switchStatementNode( NodeFactory.memberExpressionNode( NodeFactory.identifierNode(controllerIdentifierName), - NodeFactory.updateExpressionNode( - '++', - NodeFactory.identifierNode(indexIdentifierName) - ), + NodeFactory.updateExpressionNode('++', NodeFactory.identifierNode(indexIdentifierName)), true ), this.shuffledKeys.map((key: number, index: number) => { @@ -135,10 +125,7 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode consequent.push(NodeFactory.continueStatement()); } - return NodeFactory.switchCaseNode( - NodeFactory.literalNode(String(index)), - consequent - ); + return NodeFactory.switchCaseNode(NodeFactory.literalNode(String(index)), consequent); }) ), NodeFactory.breakStatement() diff --git a/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts b/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts index 88f34b03f..8202db775 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -38,26 +38,24 @@ export class CallExpressionFunctionNode extends AbstractCustomNode { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** * @param {(Expression | SpreadElement)[]} expressionArguments * @param {boolean} isChainExpressionParent */ - public initialize (expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[], isChainExpressionParent: boolean): void { + public initialize( + expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[], + isChainExpressionParent: boolean + ): void { this.expressionArguments = expressionArguments; this.isChainExpressionParent = isChainExpressionParent; } @@ -65,7 +63,7 @@ export class CallExpressionFunctionNode extends AbstractCustomNode { /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const calleeIdentifier: ESTree.Identifier = NodeFactory.identifierNode('callee'); const params: (ESTree.Identifier | ESTree.RestElement)[] = []; const callArguments: (ESTree.Identifier | ESTree.SpreadElement)[] = []; @@ -92,22 +90,19 @@ export class CallExpressionFunctionNode extends AbstractCustomNode { } const callExpression = NodeFactory.callExpressionNode( - calleeIdentifier, - callArguments, - this.isChainExpressionParent + calleeIdentifier, + callArguments, + this.isChainExpressionParent ); - + const structure: TStatement = NodeFactory.expressionStatementNode( NodeFactory.functionExpressionNode( - [ - calleeIdentifier, - ...params - ], + [calleeIdentifier, ...params], NodeFactory.blockStatementNode([ NodeFactory.returnStatementNode( this.isChainExpressionParent - ? NodeFactory.chainExpressionNode(callExpression) - : callExpression + ? NodeFactory.chainExpressionNode(callExpression) + : callExpression ) ]) ) diff --git a/src/custom-nodes/control-flow-flattening-nodes/LiteralNode.ts b/src/custom-nodes/control-flow-flattening-nodes/LiteralNode.ts index 1e418d112..29097ceb7 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/LiteralNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/LiteralNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import type * as ESTree from 'estree'; @@ -29,32 +29,27 @@ export class LiteralNode extends AbstractCustomNode { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** * @param {ESTree.Literal} literalNode */ - public initialize (literalNode: ESTree.Literal): void { + public initialize(literalNode: ESTree.Literal): void { this.literalNode = literalNode; } /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const structure: TStatement = NodeFactory.expressionStatementNode(this.literalNode); return [structure]; diff --git a/src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts b/src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts index a10f14258..65da3d95c 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import type { LogicalOperator } from 'estree'; @@ -27,38 +27,30 @@ export class LogicalExpressionFunctionNode extends AbstractCustomNode { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** * @param {LogicalOperator} operator */ - public initialize (operator: LogicalOperator): void { + public initialize(operator: LogicalOperator): void { this.operator = operator; } /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const structure: TStatement = NodeFactory.expressionStatementNode( NodeFactory.functionExpressionNode( - [ - NodeFactory.identifierNode('x'), - NodeFactory.identifierNode('y') - ], + [NodeFactory.identifierNode('x'), NodeFactory.identifierNode('y')], NodeFactory.blockStatementNode([ NodeFactory.returnStatementNode( NodeFactory.logicalExpressionNode( diff --git a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts index eba9f6acd..a024ec1a3 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import type * as ESTree from 'estree'; @@ -48,19 +48,14 @@ export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** @@ -69,7 +64,7 @@ export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode * @param {Expression} callee * @param {(Expression | SpreadElement)[]} expressionArguments */ - public initialize ( + public initialize( controlFlowStorageName: string, controlFlowStorageKey: string, callee: ESTree.Expression, @@ -84,17 +79,14 @@ export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const structure: TStatement = NodeFactory.expressionStatementNode( NodeFactory.callExpressionNode( NodeFactory.memberExpressionNode( NodeFactory.identifierNode(this.controlFlowStorageName), NodeFactory.identifierNode(this.controlFlowStorageKey) ), - [ - this.callee, - ...this.expressionArguments - ] + [this.callee, ...this.expressionArguments] ) ); diff --git a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts index 8db3102df..463f6a16e 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -32,32 +32,27 @@ export class ControlFlowStorageNode extends AbstractCustomNode { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** * @param {IControlFlowStorage} controlFlowStorage */ - public initialize (controlFlowStorage: IControlFlowStorage): void { + public initialize(controlFlowStorage: IControlFlowStorage): void { this.controlFlowStorage = controlFlowStorage; } /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const propertyNodes: ESTree.Property[] = []; const controlFlowStorageMap: Map = this.controlFlowStorage.getStorage(); @@ -65,15 +60,12 @@ export class ControlFlowStorageNode extends AbstractCustomNode { const node: ESTree.Node = value.getNode()[0]; if (!NodeGuards.isExpressionStatementNode(node)) { - throw new Error('Function node for control flow storage object should be passed inside the `ExpressionStatement` node!'); + throw new Error( + 'Function node for control flow storage object should be passed inside the `ExpressionStatement` node!' + ); } - propertyNodes.push( - NodeFactory.propertyNode( - NodeFactory.identifierNode(key), - node.expression - ) - ); + propertyNodes.push(NodeFactory.propertyNode(NodeFactory.identifierNode(key), node.expression)); } const structure: ESTree.Node = NodeFactory.variableDeclarationNode( diff --git a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts index f0ce12184..a5cc0eec5 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import type { Expression } from 'estree'; @@ -46,19 +46,14 @@ export class ExpressionWithOperatorControlFlowStorageCallNode extends AbstractCu * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** @@ -67,11 +62,11 @@ export class ExpressionWithOperatorControlFlowStorageCallNode extends AbstractCu * @param {Expression} leftValue * @param {Expression} rightValue */ - public initialize ( + public initialize( controlFlowStorageName: string, controlFlowStorageKey: string, leftValue: Expression, - rightValue: Expression, + rightValue: Expression ): void { this.controlFlowStorageName = controlFlowStorageName; this.controlFlowStorageKey = controlFlowStorageKey; @@ -82,17 +77,14 @@ export class ExpressionWithOperatorControlFlowStorageCallNode extends AbstractCu /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const structure: TStatement = NodeFactory.expressionStatementNode( NodeFactory.callExpressionNode( NodeFactory.memberExpressionNode( NodeFactory.identifierNode(this.controlFlowStorageName), NodeFactory.identifierNode(this.controlFlowStorageKey) ), - [ - this.leftValue, - this.rightValue - ] + [this.leftValue, this.rightValue] ) ); diff --git a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts index cb18049b9..a597e0161 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -34,29 +34,21 @@ export class StringLiteralControlFlowStorageCallNode extends AbstractCustomNode * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** * @param {string} controlFlowStorageName * @param {string} controlFlowStorageKey */ - public initialize ( - controlFlowStorageName: string, - controlFlowStorageKey: string - ): void { + public initialize(controlFlowStorageName: string, controlFlowStorageKey: string): void { this.controlFlowStorageName = controlFlowStorageName; this.controlFlowStorageKey = controlFlowStorageKey; } @@ -64,7 +56,7 @@ export class StringLiteralControlFlowStorageCallNode extends AbstractCustomNode /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const structure: TStatement = NodeFactory.expressionStatementNode( NodeFactory.memberExpressionNode( NodeFactory.identifierNode(this.controlFlowStorageName), diff --git a/src/custom-nodes/dead-code-injection-nodes/BlockStatementDeadCodeInjectionNode.ts b/src/custom-nodes/dead-code-injection-nodes/BlockStatementDeadCodeInjectionNode.ts index 9d66be341..c711d1525 100644 --- a/src/custom-nodes/dead-code-injection-nodes/BlockStatementDeadCodeInjectionNode.ts +++ b/src/custom-nodes/dead-code-injection-nodes/BlockStatementDeadCodeInjectionNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import type { BinaryOperator, BlockStatement } from 'estree'; @@ -32,29 +32,21 @@ export class BlockStatementDeadCodeInjectionNode extends AbstractCustomNode { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** * @param {BlockStatement} blockStatementNode * @param {BlockStatement} deadCodeInjectionRootAstHostNode */ - public initialize ( - blockStatementNode: BlockStatement, - deadCodeInjectionRootAstHostNode: BlockStatement - ): void { + public initialize(blockStatementNode: BlockStatement, deadCodeInjectionRootAstHostNode: BlockStatement): void { this.blockStatementNode = blockStatementNode; this.deadCodeInjectionRootAstHostNode = deadCodeInjectionRootAstHostNode; } @@ -64,14 +56,14 @@ export class BlockStatementDeadCodeInjectionNode extends AbstractCustomNode { * * @returns {TStatement[]} */ - public override getNode (): TStatement[] { + public override getNode(): TStatement[] { return this.getNodeStructure(); } /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const random1: boolean = this.randomGenerator.getMathRandom() > 0.5; const random2: boolean = this.randomGenerator.getMathRandom() > 0.5; @@ -79,9 +71,10 @@ export class BlockStatementDeadCodeInjectionNode extends AbstractCustomNode { const leftString: string = this.randomGenerator.getRandomString(5); const rightString: string = random2 ? leftString : this.randomGenerator.getRandomString(5); - const [consequent, alternate]: [BlockStatement, BlockStatement] = random1 === random2 - ? [this.blockStatementNode, this.deadCodeInjectionRootAstHostNode] - : [this.deadCodeInjectionRootAstHostNode, this.blockStatementNode]; + const [consequent, alternate]: [BlockStatement, BlockStatement] = + random1 === random2 + ? [this.blockStatementNode, this.deadCodeInjectionRootAstHostNode] + : [this.deadCodeInjectionRootAstHostNode, this.blockStatementNode]; const structure: BlockStatement = NodeFactory.blockStatementNode([ NodeFactory.ifStatementNode( diff --git a/src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts b/src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts index 2e9426159..3bb223c95 100644 --- a/src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts +++ b/src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -32,26 +32,24 @@ export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomN * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); } /** * @param {TNodeWithLexicalScope} lexicalScopeNode * @param {(ESTree.Property | ESTree.SpreadElement)[]} properties */ - public initialize (lexicalScopeNode: TNodeWithLexicalScope, properties: (ESTree.Property | ESTree.SpreadElement)[]): void { + public initialize( + lexicalScopeNode: TNodeWithLexicalScope, + properties: (ESTree.Property | ESTree.SpreadElement)[] + ): void { this.lexicalScopeNode = lexicalScopeNode; this.properties = properties; } @@ -59,7 +57,7 @@ export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomN /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const variableDeclarationName: string = NodeGuards.isProgramNode(this.lexicalScopeNode) ? this.identifierNamesGenerator.generateForGlobalScope() : this.identifierNamesGenerator.generateForLexicalScope(this.lexicalScopeNode); diff --git a/src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts b/src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts index a95833908..296d4f7ce 100644 --- a/src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts +++ b/src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -35,7 +35,10 @@ export abstract class AbstractStringArrayCallNode extends AbstractCustomNode { */ private static readonly stringArrayIndexNodesMap: Map = new Map([ [StringArrayIndexesType.HexadecimalNumber, StringArrayIndexNode.StringArrayHexadecimalNumberIndexNode], - [StringArrayIndexesType.HexadecimalNumericString, StringArrayIndexNode.StringArrayHexadecimalNumericStringIndexNode] + [ + StringArrayIndexesType.HexadecimalNumericString, + StringArrayIndexNode.StringArrayHexadecimalNumericStringIndexNode + ] ]); /** @@ -62,23 +65,18 @@ export abstract class AbstractStringArrayCallNode extends AbstractCustomNode { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.Factory__IStringArrayIndexNode) - stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory, + stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage, @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - identifierNamesGeneratorFactory, - customCodeHelperFormatter, - randomGenerator, - options - ); + super(identifierNamesGeneratorFactory, customCodeHelperFormatter, randomGenerator, options); this.stringArrayIndexNodeFactory = stringArrayIndexNodeFactory; this.stringArrayStorage = stringArrayStorage; @@ -89,33 +87,31 @@ export abstract class AbstractStringArrayCallNode extends AbstractCustomNode { * @param {number} index * @returns {Expression} */ - protected getStringArrayIndexNode (index: number): ESTree.Expression { + protected getStringArrayIndexNode(index: number): ESTree.Expression { const isPositive: boolean = index >= 0; const normalizedIndex: number = Math.abs(index); const stringArrayCallsIndexType: TStringArrayIndexesType = this.randomGenerator .getRandomGenerator() .pickone(this.options.stringArrayIndexesType); - const stringArrayIndexNodeName: StringArrayIndexNode | null = AbstractStringArrayCallNode.stringArrayIndexNodesMap.get(stringArrayCallsIndexType) ?? null; + const stringArrayIndexNodeName: StringArrayIndexNode | null = + AbstractStringArrayCallNode.stringArrayIndexNodesMap.get(stringArrayCallsIndexType) ?? null; if (!stringArrayIndexNodeName) { throw new Error('Invalid string array index node name'); } - const stringArrayCallIndexNode: ESTree.Expression = this.stringArrayIndexNodeFactory(stringArrayIndexNodeName) - .getNode(normalizedIndex); + const stringArrayCallIndexNode: ESTree.Expression = + this.stringArrayIndexNodeFactory(stringArrayIndexNodeName).getNode(normalizedIndex); NodeMetadata.set(stringArrayCallIndexNode, { stringArrayCallLiteralNode: true }); const hexadecimalNode: ESTree.Expression = isPositive ? stringArrayCallIndexNode - : NodeFactory.unaryExpressionNode( - '-', - stringArrayCallIndexNode - ); + : NodeFactory.unaryExpressionNode('-', stringArrayCallIndexNode); NodeUtils.parentizeAst(hexadecimalNode); - + return hexadecimalNode; } @@ -123,7 +119,7 @@ export abstract class AbstractStringArrayCallNode extends AbstractCustomNode { * @param {string} decodeKey * @returns {Literal} */ - protected getRc4KeyLiteralNode (decodeKey: string): ESTree.Literal { + protected getRc4KeyLiteralNode(decodeKey: string): ESTree.Literal { const rc4KeyLiteralNode: ESTree.Literal = NodeFactory.literalNode(decodeKey); NodeMetadata.set(rc4KeyLiteralNode, { stringArrayCallLiteralNode: true }); diff --git a/src/custom-nodes/string-array-nodes/StringArrayCallNode.ts b/src/custom-nodes/string-array-nodes/StringArrayCallNode.ts index 8f159ced7..d330eecd0 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayCallNode.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayCallNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -55,11 +55,11 @@ export class StringArrayCallNode extends AbstractStringArrayCallNode { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.Factory__IStringArrayIndexNode) - stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory, + stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage, @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils, @@ -83,7 +83,7 @@ export class StringArrayCallNode extends AbstractStringArrayCallNode { * @param {IStringArrayScopeCallsWrapperData} stringArrayCallsWrapperData * @param {string | null} decodeKey */ - public initialize ( + public initialize( index: number, indexShiftAmount: number, stringArrayCallsWrapperData: IStringArrayScopeCallsWrapperData, @@ -98,7 +98,7 @@ export class StringArrayCallNode extends AbstractStringArrayCallNode { /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const resultIndex: number = this.indexShiftAmount + this.stringArrayCallsWrapperData.index + this.index; const indexNode: ESTree.Expression = this.getStringArrayIndexNode(resultIndex); @@ -109,10 +109,10 @@ export class StringArrayCallNode extends AbstractStringArrayCallNode { // filling call expression arguments with a fake arguments first const callExpressionArgs: ESTree.Expression[] = this.arrayUtils.fillWithRange( !this.stringArrayCallsWrapperData.parameterIndexesData - // root string array calls wrapper - ? AbstractStringArrayCallNode.stringArrayRootCallsWrapperParametersCount - // scope string array calls wrapper - : this.options.stringArrayWrappersParametersMaxCount, + ? // root string array calls wrapper + AbstractStringArrayCallNode.stringArrayRootCallsWrapperParametersCount + : // scope string array calls wrapper + this.options.stringArrayWrappersParametersMaxCount, () => this.getFakeStringArrayIndexNode(resultIndex) ); @@ -152,7 +152,7 @@ export class StringArrayCallNode extends AbstractStringArrayCallNode { * @param {number} actualIndex * @returns {Expression} */ - private getFakeStringArrayIndexNode (actualIndex: number): ESTree.Expression { + private getFakeStringArrayIndexNode(actualIndex: number): ESTree.Expression { return this.getStringArrayIndexNode(this.getFakeStringArrayIndex(actualIndex)); } @@ -160,7 +160,7 @@ export class StringArrayCallNode extends AbstractStringArrayCallNode { * @param {number} actualIndex * @returns {number} */ - private getFakeStringArrayIndex (actualIndex: number): number { + private getFakeStringArrayIndex(actualIndex: number): number { const stringArrayStorageLength: number = this.stringArrayStorage.getLength(); const fakeIndexOffset: number = stringArrayStorageLength / 2; diff --git a/src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperFunctionNode.ts b/src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperFunctionNode.ts index 10d8cda62..7ebf4e707 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperFunctionNode.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperFunctionNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -43,11 +43,11 @@ export class StringArrayScopeCallsWrapperFunctionNode extends AbstractStringArra * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.Factory__IStringArrayIndexNode) - stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory, + stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage, @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils, @@ -69,9 +69,9 @@ export class StringArrayScopeCallsWrapperFunctionNode extends AbstractStringArra * @param {IStringArrayScopeCallsWrapperData} stringArrayScopeCallsWrapperData * @param {IStringArrayScopeCallsWrapperData} upperStringArrayCallsWrapperData */ - public initialize ( + public initialize( stringArrayScopeCallsWrapperData: IStringArrayScopeCallsWrapperData, - upperStringArrayCallsWrapperData: IStringArrayScopeCallsWrapperData, + upperStringArrayCallsWrapperData: IStringArrayScopeCallsWrapperData ): void { this.stringArrayScopeCallsWrapperData = stringArrayScopeCallsWrapperData; this.upperStringArrayCallsWrapperData = upperStringArrayCallsWrapperData; @@ -80,17 +80,20 @@ export class StringArrayScopeCallsWrapperFunctionNode extends AbstractStringArra /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { // identifiers of function expression parameters // as a temporary names use random strings - const stringArrayCallIdentifierNode: ESTree.Identifier = NodeFactory.identifierNode(this.randomGenerator.getRandomString(6)); - const decodeKeyIdentifierNode: ESTree.Identifier = NodeFactory.identifierNode(this.randomGenerator.getRandomString(6)); + const stringArrayCallIdentifierNode: ESTree.Identifier = NodeFactory.identifierNode( + this.randomGenerator.getRandomString(6) + ); + const decodeKeyIdentifierNode: ESTree.Identifier = NodeFactory.identifierNode( + this.randomGenerator.getRandomString(6) + ); const stringArrayCallNode: ESTree.Expression = this.getUpperStringArrayCallNode( stringArrayCallIdentifierNode, this.getStringArrayIndexNode( - this.stringArrayScopeCallsWrapperData.index - - this.upperStringArrayCallsWrapperData.index + this.stringArrayScopeCallsWrapperData.index - this.upperStringArrayCallsWrapperData.index ) ); @@ -98,10 +101,10 @@ export class StringArrayScopeCallsWrapperFunctionNode extends AbstractStringArra // filling all parameters with a fake parameters first const parameters: ESTree.Identifier[] = this.arrayUtils.fillWithRange( !this.stringArrayScopeCallsWrapperData.parameterIndexesData - // root string array calls wrapper - ? AbstractStringArrayCallNode.stringArrayRootCallsWrapperParametersCount - // scope string array calls wrapper - : this.options.stringArrayWrappersParametersMaxCount, + ? // root string array calls wrapper + AbstractStringArrayCallNode.stringArrayRootCallsWrapperParametersCount + : // scope string array calls wrapper + this.options.stringArrayWrappersParametersMaxCount, () => this.getFakeParameterNode() ); parameters.splice( @@ -119,14 +122,12 @@ export class StringArrayScopeCallsWrapperFunctionNode extends AbstractStringArra // filling all call expression arguments with a fake string array calls const callExpressionArgs: ESTree.Expression[] = this.arrayUtils.fillWithRange( !this.upperStringArrayCallsWrapperData.parameterIndexesData - // root string array calls wrapper - ? AbstractStringArrayCallNode.stringArrayRootCallsWrapperParametersCount - // scope string array calls wrapper - : this.options.stringArrayWrappersParametersMaxCount, - (index: number) => this.getUpperStringArrayCallNode( - parameters[index], - this.getFakeUpperStringArrayIndexNode() - ) + ? // root string array calls wrapper + AbstractStringArrayCallNode.stringArrayRootCallsWrapperParametersCount + : // scope string array calls wrapper + this.options.stringArrayWrappersParametersMaxCount, + (index: number) => + this.getUpperStringArrayCallNode(parameters[index], this.getFakeUpperStringArrayIndexNode()) ); callExpressionArgs.splice( @@ -141,7 +142,7 @@ export class StringArrayScopeCallsWrapperFunctionNode extends AbstractStringArra ); // stage 3: function declaration node - const functionDeclarationNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode( + const functionDeclarationNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode( this.stringArrayScopeCallsWrapperData.name, parameters, NodeFactory.blockStatementNode([ @@ -172,28 +173,24 @@ export class StringArrayScopeCallsWrapperFunctionNode extends AbstractStringArra * @param {Expression} indexShiftNode * @returns {Expression} */ - private getUpperStringArrayCallNode ( + private getUpperStringArrayCallNode( indexParameterIdentifierNode: ESTree.Identifier, indexShiftNode: ESTree.Expression ): ESTree.Expression { - return NodeFactory.binaryExpressionNode( - '-', - indexParameterIdentifierNode, - indexShiftNode - ); + return NodeFactory.binaryExpressionNode('-', indexParameterIdentifierNode, indexShiftNode); } /** * @returns {Identifier} */ - private getFakeParameterNode (): ESTree.Identifier { + private getFakeParameterNode(): ESTree.Identifier { return NodeFactory.identifierNode(this.randomGenerator.getRandomString(6)); } /** * @returns {Expression} */ - private getFakeUpperStringArrayIndexNode (): ESTree.Expression { + private getFakeUpperStringArrayIndexNode(): ESTree.Expression { return this.getStringArrayIndexNode(this.randomGenerator.getRandomInteger(0, 500)); } } diff --git a/src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperVariableNode.ts b/src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperVariableNode.ts index c9206c836..2a19f05be 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperVariableNode.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperVariableNode.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -32,7 +32,6 @@ export class StringArrayScopeCallsWrapperVariableNode extends AbstractStringArra @initializable() private stringArrayScopeCallsWrapperData!: IStringArrayScopeCallsWrapperData; - /** * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory * @param {TStringArrayIndexNodeFactory} stringArrayIndexNodeFactory @@ -42,16 +41,16 @@ export class StringArrayScopeCallsWrapperVariableNode extends AbstractStringArra * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.Factory__IStringArrayIndexNode) - stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory, + stringArrayIndexNodeFactory: TStringArrayIndexNodeFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage, @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, - @inject(ServiceIdentifiers.IOptions) options: IOptions, + @inject(ServiceIdentifiers.IOptions) options: IOptions ) { super( identifierNamesGeneratorFactory, @@ -68,7 +67,7 @@ export class StringArrayScopeCallsWrapperVariableNode extends AbstractStringArra * @param {IStringArrayScopeCallsWrapperData} stringArrayScopeCallsWrapperData * @param {IStringArrayScopeCallsWrapperData} stringArrayCallsWrapperData */ - public initialize ( + public initialize( stringArrayScopeCallsWrapperData: IStringArrayScopeCallsWrapperData, stringArrayCallsWrapperData: IStringArrayScopeCallsWrapperData ): void { @@ -79,7 +78,7 @@ export class StringArrayScopeCallsWrapperVariableNode extends AbstractStringArra /** * @returns {TStatement[]} */ - protected getNodeStructure (): TStatement[] { + protected getNodeStructure(): TStatement[] { const structure: TStatement = NodeFactory.variableDeclarationNode( [ NodeFactory.variableDeclaratorNode( @@ -87,7 +86,7 @@ export class StringArrayScopeCallsWrapperVariableNode extends AbstractStringArra NodeFactory.identifierNode(this.stringArrayCallsWrapperData.name) ) ], - 'const', + 'const' ); NodeUtils.parentizeAst(structure); diff --git a/src/custom-nodes/string-array-nodes/string-array-index-nodes/AbstractStringArrayIndexNode.ts b/src/custom-nodes/string-array-nodes/string-array-index-nodes/AbstractStringArrayIndexNode.ts index 29734769e..00e8366df 100644 --- a/src/custom-nodes/string-array-nodes/string-array-index-nodes/AbstractStringArrayIndexNode.ts +++ b/src/custom-nodes/string-array-nodes/string-array-index-nodes/AbstractStringArrayIndexNode.ts @@ -24,7 +24,7 @@ export abstract class AbstractStringArrayIndexNode implements IStringArrayIndexN * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -36,5 +36,5 @@ export abstract class AbstractStringArrayIndexNode implements IStringArrayIndexN * @param {number} index * @returns {Expression} */ - public abstract getNode (index: number): ESTree.Expression; + public abstract getNode(index: number): ESTree.Expression; } diff --git a/src/custom-nodes/string-array-nodes/string-array-index-nodes/StringArrayHexadecimalNumberIndexNode.ts b/src/custom-nodes/string-array-nodes/string-array-index-nodes/StringArrayHexadecimalNumberIndexNode.ts index 3889659ec..ed3fb3e38 100644 --- a/src/custom-nodes/string-array-nodes/string-array-index-nodes/StringArrayHexadecimalNumberIndexNode.ts +++ b/src/custom-nodes/string-array-nodes/string-array-index-nodes/StringArrayHexadecimalNumberIndexNode.ts @@ -17,7 +17,7 @@ export class StringArrayHexadecimalNumberIndexNode extends AbstractStringArrayIn * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -28,7 +28,7 @@ export class StringArrayHexadecimalNumberIndexNode extends AbstractStringArrayIn * @param {number} index * @returns {Expression} */ - public getNode (index: number): ESTree.Expression { + public getNode(index: number): ESTree.Expression { const hexadecimalIndex: string = NumberUtils.toHex(index); return NodeFactory.literalNode(index, hexadecimalIndex); diff --git a/src/custom-nodes/string-array-nodes/string-array-index-nodes/StringArrayHexadecimalNumericStringIndexNode.ts b/src/custom-nodes/string-array-nodes/string-array-index-nodes/StringArrayHexadecimalNumericStringIndexNode.ts index c014e1612..afaa3d2e3 100644 --- a/src/custom-nodes/string-array-nodes/string-array-index-nodes/StringArrayHexadecimalNumericStringIndexNode.ts +++ b/src/custom-nodes/string-array-nodes/string-array-index-nodes/StringArrayHexadecimalNumericStringIndexNode.ts @@ -17,7 +17,7 @@ export class StringArrayHexadecimalNumericStringIndexNode extends AbstractString * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -28,7 +28,7 @@ export class StringArrayHexadecimalNumericStringIndexNode extends AbstractString * @param {number} index * @returns {Expression} */ - public getNode (index: number): ESTree.Expression { + public getNode(index: number): ESTree.Expression { const hexadecimalIndex: string = NumberUtils.toHex(index); return NodeFactory.literalNode(hexadecimalIndex); diff --git a/src/declarations/ESTree.d.ts b/src/declarations/ESTree.d.ts index 2b4bed810..f598ecd81 100644 --- a/src/declarations/ESTree.d.ts +++ b/src/declarations/ESTree.d.ts @@ -18,12 +18,12 @@ declare module 'estree' { } export interface IdentifierNodeMetadata extends BaseNodeMetadata { - propertyKeyToRenameNode?: boolean + propertyKeyToRenameNode?: boolean; } export interface LiteralNodeMetadata extends BaseNodeMetadata { stringArrayCallLiteralNode?: boolean; - propertyKeyToRenameNode?: boolean + propertyKeyToRenameNode?: boolean; } /** @@ -57,17 +57,17 @@ declare module 'estree' { } interface BigIntLiteral extends BaseNode { - metadata?: LiteralNodeMetadata; + 'metadata'?: LiteralNodeMetadata; 'x-verbatim-property'?: escodegen.XVerbatimProperty; } interface RegExpLiteral extends BaseNode { - metadata?: LiteralNodeMetadata; + 'metadata'?: LiteralNodeMetadata; 'x-verbatim-property'?: escodegen.XVerbatimProperty; } interface SimpleLiteral extends BaseNode { - metadata?: LiteralNodeMetadata; + 'metadata'?: LiteralNodeMetadata; 'x-verbatim-property'?: escodegen.XVerbatimProperty; } } diff --git a/src/declarations/acorn-import-meta.d.ts b/src/declarations/acorn-import-meta.d.ts index dcdf0fc6a..5e2d804e2 100644 --- a/src/declarations/acorn-import-meta.d.ts +++ b/src/declarations/acorn-import-meta.d.ts @@ -1,7 +1,7 @@ declare module 'acorn-import-meta' { import * as acorn from 'acorn'; - function acornImportMeta (BaseParser: typeof acorn.Parser): typeof acorn.Parser; + function acornImportMeta(BaseParser: typeof acorn.Parser): typeof acorn.Parser; export = acornImportMeta; } diff --git a/src/declarations/environment.d.ts b/src/declarations/environment.d.ts index 15f603b8e..1e0025a5e 100644 --- a/src/declarations/environment.d.ts +++ b/src/declarations/environment.d.ts @@ -5,4 +5,4 @@ declare namespace NodeJS { VERSION?: string; BUILD_TIMESTAMP?: string; } -} \ No newline at end of file +} diff --git a/src/declarations/escodegen.d.ts b/src/declarations/escodegen.d.ts index 300b4590a..cc98a28b5 100644 --- a/src/declarations/escodegen.d.ts +++ b/src/declarations/escodegen.d.ts @@ -20,5 +20,5 @@ declare module '@javascript-obfuscator/escodegen' { * @param options * @returns IGeneratorOutput */ - export function generate (ast: ESTree.Node, options?: escodegen.GenerateOptions): IGeneratorOutput; + export function generate(ast: ESTree.Node, options?: escodegen.GenerateOptions): IGeneratorOutput; } diff --git a/src/decorators/Initializable.ts b/src/decorators/Initializable.ts index a968a5aa6..f445127a8 100644 --- a/src/decorators/Initializable.ts +++ b/src/decorators/Initializable.ts @@ -15,14 +15,16 @@ const initializeMethodName: 'initialize' = 'initialize'; * @param {string} initializeMethodName * @returns {(target: IInitializable, propertyKey: (string | symbol)) => any} */ -export function initializable (): (target: IInitializable, propertyKey: string | symbol) => any { +export function initializable(): (target: IInitializable, propertyKey: string | symbol) => any { return (target: IInitializable, propertyKey: string | symbol): PropertyDescriptor => { const initializeMethod: Function = target[initializeMethodName]; const isInvalidInitializeMethod = !initializeMethod || typeof initializeMethod !== 'function'; if (isInvalidInitializeMethod) { - throw new Error(`\`${initializeMethodName}\` method with initialization logic not ` + - `found. \`@${decoratorName}\` decorator requires \`${initializeMethodName}\` method`); + throw new Error( + `\`${initializeMethodName}\` method with initialization logic not ` + + `found. \`@${decoratorName}\` decorator requires \`${initializeMethodName}\` method` + ); } /** @@ -50,7 +52,7 @@ export function initializable (): (target: IInitializable, propertyKey: string | * @param metadataValue * @param {IInitializable} target */ -function initializeTargetMetadata (metadataKey: string, metadataValue: any, target: IInitializable): void { +function initializeTargetMetadata(metadataKey: string, metadataValue: any, target: IInitializable): void { const hasInitializedMetadata: boolean = Reflect.hasMetadata(metadataKey, target); if (!hasInitializedMetadata) { @@ -63,19 +65,21 @@ function initializeTargetMetadata (metadataKey: string, metadataValue: any, targ * * @param {IInitializable} target */ -function wrapTargetMethodsInInitializedCheck (target: IInitializable): void { +function wrapTargetMethodsInInitializedCheck(target: IInitializable): void { const ownPropertyNames: string[] = Object.getOwnPropertyNames(target); const prohibitedPropertyNames: Set = new Set([initializeMethodName, constructorMethodName]); ownPropertyNames.forEach((propertyName: string) => { - const initializablePropertiesSet: Set = Reflect - .getMetadata(initializablePropertiesSetMetadataKey, target); - const wrappedMethodsSet: Set = Reflect - .getMetadata(wrappedMethodsSetMetadataKey, target); + const initializablePropertiesSet: Set = Reflect.getMetadata( + initializablePropertiesSetMetadataKey, + target + ); + const wrappedMethodsSet: Set = Reflect.getMetadata(wrappedMethodsSetMetadataKey, target); - const isProhibitedPropertyName: boolean = prohibitedPropertyNames.has(propertyName) - || initializablePropertiesSet.has(propertyName) - || wrappedMethodsSet.has(propertyName); + const isProhibitedPropertyName: boolean = + prohibitedPropertyNames.has(propertyName) || + initializablePropertiesSet.has(propertyName) || + wrappedMethodsSet.has(propertyName); if (isProhibitedPropertyName) { return; @@ -87,13 +91,13 @@ function wrapTargetMethodsInInitializedCheck (target: IInitializable): void { return; } - const methodDescriptor: PropertyDescriptor = Object - .getOwnPropertyDescriptor(target, propertyName) ?? defaultDescriptor; + const methodDescriptor: PropertyDescriptor = + Object.getOwnPropertyDescriptor(target, propertyName) ?? defaultDescriptor; const originalMethod: Function = methodDescriptor.value; Object.defineProperty(target, propertyName, { ...methodDescriptor, - value (): void { + value(): void { if (!Reflect.getMetadata(initializedTargetMetadataKey, this)) { throw new Error(`Class should be initialized with \`${initializeMethodName}()\` method`); } @@ -112,12 +116,9 @@ function wrapTargetMethodsInInitializedCheck (target: IInitializable): void { * @param {IInitializable} target * @param {string | symbol} propertyKey */ -function wrapInitializeMethodInInitializeCheck ( - target: IInitializable, - propertyKey: string | symbol -): void { - const methodDescriptor: PropertyDescriptor = Object - .getOwnPropertyDescriptor(target, initializeMethodName) ?? defaultDescriptor; +function wrapInitializeMethodInInitializeCheck(target: IInitializable, propertyKey: string | symbol): void { + const methodDescriptor: PropertyDescriptor = + Object.getOwnPropertyDescriptor(target, initializeMethodName) ?? defaultDescriptor; const originalMethod: Function = methodDescriptor.value; Object.defineProperty(target, initializeMethodName, { @@ -131,7 +132,8 @@ function wrapInitializeMethodInInitializeCheck ( const result: typeof originalMethod = originalMethod.apply(this, arguments); - if (this[propertyKey]) {} + if (this[propertyKey]) { + } return result; } @@ -145,15 +147,17 @@ function wrapInitializeMethodInInitializeCheck ( * @param {string | symbol} propertyKey * @returns {PropertyDescriptor} */ -function wrapInitializableProperty (target: IInitializable, propertyKey: string | symbol): PropertyDescriptor { - const initializablePropertiesSet: Set = Reflect - .getMetadata(initializablePropertiesSetMetadataKey, target); +function wrapInitializableProperty(target: IInitializable, propertyKey: string | symbol): PropertyDescriptor { + const initializablePropertiesSet: Set = Reflect.getMetadata( + initializablePropertiesSetMetadataKey, + target + ); initializablePropertiesSet.add(propertyKey); const initializablePropertyMetadataKey: string = `_${propertyKey.toString()}`; - const propertyDescriptor: PropertyDescriptor = Object - .getOwnPropertyDescriptor(target, initializablePropertyMetadataKey) ?? defaultDescriptor; + const propertyDescriptor: PropertyDescriptor = + Object.getOwnPropertyDescriptor(target, initializablePropertyMetadataKey) ?? defaultDescriptor; Object.defineProperty(target, propertyKey, { ...propertyDescriptor, diff --git a/src/enums/ObfuscationTarget.ts b/src/enums/ObfuscationTarget.ts index 7fb67763c..55235dbfa 100644 --- a/src/enums/ObfuscationTarget.ts +++ b/src/enums/ObfuscationTarget.ts @@ -9,5 +9,5 @@ export const ObfuscationTarget: Readonly<{ Browser: 'browser', BrowserNoEval: 'browser-no-eval', Node: 'node', - ServiceWorker: 'service-worker', + ServiceWorker: 'service-worker' }); diff --git a/src/enums/analyzers/calls-graph-analyzer/CalleeDataExtractor.ts b/src/enums/analyzers/calls-graph-analyzer/CalleeDataExtractor.ts index 2652e4198..df3a3a742 100644 --- a/src/enums/analyzers/calls-graph-analyzer/CalleeDataExtractor.ts +++ b/src/enums/analyzers/calls-graph-analyzer/CalleeDataExtractor.ts @@ -1,5 +1,5 @@ export enum CalleeDataExtractor { FunctionDeclarationCalleeDataExtractor = 'FunctionDeclarationCalleeDataExtractor', FunctionExpressionCalleeDataExtractor = 'FunctionExpressionCalleeDataExtractor', - ObjectExpressionCalleeDataExtractor = 'ObjectExpressionCalleeDataExtractor', + ObjectExpressionCalleeDataExtractor = 'ObjectExpressionCalleeDataExtractor' } diff --git a/src/enums/code-transformers/CodeTransformationStage.ts b/src/enums/code-transformers/CodeTransformationStage.ts index 932612468..aea3a4d9c 100644 --- a/src/enums/code-transformers/CodeTransformationStage.ts +++ b/src/enums/code-transformers/CodeTransformationStage.ts @@ -1,4 +1,4 @@ export enum CodeTransformationStage { PreparingTransformers = 'PreparingTransformers', - FinalizingTransformers = 'FinalizingTransformers', + FinalizingTransformers = 'FinalizingTransformers' } diff --git a/src/enums/custom-nodes/ObjectExpressionKeysTransformerCustomNode.ts b/src/enums/custom-nodes/ObjectExpressionKeysTransformerCustomNode.ts index 98daa538e..40968aed8 100644 --- a/src/enums/custom-nodes/ObjectExpressionKeysTransformerCustomNode.ts +++ b/src/enums/custom-nodes/ObjectExpressionKeysTransformerCustomNode.ts @@ -1,4 +1,3 @@ export enum ObjectExpressionKeysTransformerCustomNode { - ObjectExpressionVariableDeclarationHostNode = - 'ObjectExpressionVariableDeclarationHostNode' + ObjectExpressionVariableDeclarationHostNode = 'ObjectExpressionVariableDeclarationHostNode' } diff --git a/src/enums/node-transformers/string-array-transformers/StringArrayWrappersType.ts b/src/enums/node-transformers/string-array-transformers/StringArrayWrappersType.ts index 8e49b5890..67c0542f6 100644 --- a/src/enums/node-transformers/string-array-transformers/StringArrayWrappersType.ts +++ b/src/enums/node-transformers/string-array-transformers/StringArrayWrappersType.ts @@ -5,5 +5,5 @@ export const StringArrayWrappersType: Readonly<{ Function: 'function'; }> = Utils.makeEnum({ Variable: 'variable', - Function: 'function', + Function: 'function' }); diff --git a/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts index f9ab69fe0..9779d6af7 100644 --- a/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts @@ -35,7 +35,7 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -48,7 +48,7 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam * @param {number} nameLength * @returns {string} */ - public generate (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string { + public generate(lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string { return NodeGuards.isProgramNode(lexicalScopeNode) ? this.generateForGlobalScope() : this.generateForLexicalScope(lexicalScopeNode); @@ -57,7 +57,7 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam /** * @param {string} name */ - public preserveName (name: string): void { + public preserveName(name: string): void { this.preservedNamesSet.add(name); } @@ -65,7 +65,7 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam * @param {string} name * @param {TNodeWithLexicalScope} lexicalScopeNode */ - public preserveNameForLexicalScope (name: string, lexicalScopeNode: TNodeWithLexicalScope): void { + public preserveNameForLexicalScope(name: string, lexicalScopeNode: TNodeWithLexicalScope): void { const preservedNamesForLexicalScopeSet: Set = this.lexicalScopesPreservedNamesMap.get(lexicalScopeNode) ?? new Set(); @@ -78,9 +78,8 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam * @param {string} name * @returns {boolean} */ - public isValidIdentifierName (name: string): boolean { - return !this.isReservedName(name) - && !this.preservedNamesSet.has(name); + public isValidIdentifierName(name: string): boolean { + return !this.isReservedName(name) && !this.preservedNamesSet.has(name); } /** @@ -88,7 +87,7 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam * @param {TNodeWithLexicalScope[]} lexicalScopeNodes * @returns {boolean} */ - public isValidIdentifierNameInLexicalScopes (name: string, lexicalScopeNodes: TNodeWithLexicalScope[]): boolean { + public isValidIdentifierNameInLexicalScopes(name: string, lexicalScopeNodes: TNodeWithLexicalScope[]): boolean { if (!this.isValidIdentifierName(name)) { return false; } @@ -113,38 +112,37 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam * @param {string} name * @returns {boolean} */ - private isReservedName (name: string): boolean { + private isReservedName(name: string): boolean { return this.options.reservedNames.length - ? this.options.reservedNames.some((reservedName: string) => - new RegExp(reservedName, 'g').exec(name) !== null - ) + ? this.options.reservedNames.some( + (reservedName: string) => new RegExp(reservedName, 'g').exec(name) !== null + ) : false; - } /** * @param {number} nameLength * @returns {string} */ - public abstract generateForGlobalScope (nameLength?: number): string; + public abstract generateForGlobalScope(nameLength?: number): string; /** * @param {TNodeWithLexicalScope} lexicalScopeNode * @param {number} nameLength * @returns {string} */ - public abstract generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string; + public abstract generateForLexicalScope(lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string; /** * @param {string} label * @param {number} nameLength * @returns {string} */ - public abstract generateForLabel (label: string, nameLength?: number): string; + public abstract generateForLabel(label: string, nameLength?: number): string; /** * @param {number} nameLength * @returns {string} */ - public abstract generateNext (nameLength?: number): string; + public abstract generateNext(nameLength?: number): string; } diff --git a/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts index 448a251b5..da6195a57 100644 --- a/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts @@ -20,7 +20,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG * @type {Set} */ private identifierNamesSet: Set; - + /** * @type {IterableIterator} */ @@ -31,10 +31,10 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG * @param {IOptions} options * @param {IArrayUtils} arrayUtils */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, - @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils, + @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils ) { super(randomGenerator, options); @@ -47,7 +47,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG * @param {string} identifierName * @returns {string | null} */ - private static incrementIdentifierName (identifierName: string): string | null { + private static incrementIdentifierName(identifierName: string): string | null { let newIdentifierName: string = ''; let isSuccess: boolean = false; @@ -69,7 +69,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG return null; } - public generateNext (): string { + public generateNext(): string { const identifierName: string = this.generateNewDictionaryName(); this.preserveName(identifierName); @@ -80,10 +80,8 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG /** * @returns {string} */ - public generateForGlobalScope (): string { - const prefix: string = this.options.identifiersPrefix ? - `${this.options.identifiersPrefix}` - : ''; + public generateForGlobalScope(): string { + const prefix: string = this.options.identifiersPrefix ? `${this.options.identifiersPrefix}` : ''; const identifierName: string = this.generateNewDictionaryName((newIdentifierName: string) => { const identifierNameWithPrefix: string = `${prefix}${newIdentifierName}`; @@ -101,7 +99,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG * @param {TNodeWithLexicalScope} lexicalScopeNode * @returns {string} */ - public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope): string { + public generateForLexicalScope(lexicalScopeNode: TNodeWithLexicalScope): string { const lexicalScopes: TNodeWithLexicalScope[] = [ lexicalScopeNode, ...NodeLexicalScopeUtils.getLexicalScopes(lexicalScopeNode) @@ -119,7 +117,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG * @param {string} label * @returns {string} */ - public generateForLabel (label: string): string { + public generateForLabel(label: string): string { return this.generateNewDictionaryName(); } @@ -127,7 +125,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG * @param {(newIdentifierName: string) => boolean} validationFunction * @returns {string} */ - private generateNewDictionaryName (validationFunction?: (newIdentifierName: string) => boolean): string { + private generateNewDictionaryName(validationFunction?: (newIdentifierName: string) => boolean): string { const generateNewDictionaryName = (): string => { if (!this.identifierNamesSet.size) { throw new Error('Too many identifiers in the code, add more words to identifiers dictionary'); @@ -138,8 +136,8 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG if (!iteratorResult.done) { const identifierName: string = iteratorResult.value; - const isValidIdentifierName = validationFunction?.(identifierName) - ?? this.isValidIdentifierName(identifierName); + const isValidIdentifierName = + validationFunction?.(identifierName) ?? this.isValidIdentifierName(identifierName); if (!isValidIdentifierName) { return generateNewDictionaryName(); @@ -161,7 +159,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG * @param {string[]} identifierNames * @returns {string[]} */ - private getInitialIdentifierNames (identifierNames: string[]): string[] { + private getInitialIdentifierNames(identifierNames: string[]): string[] { const formattedIdentifierNames: string[] = identifierNames .filter(Boolean) .map((identifierName: string) => identifierName.toLowerCase()); @@ -173,12 +171,12 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG * @param {string[]} identifierNames * @returns {string[]} */ - private getIncrementedIdentifierNames (identifierNames: string[]): string[] { + private getIncrementedIdentifierNames(identifierNames: string[]): string[] { const formattedIdentifierNames: string[] = []; for (const identifierName of identifierNames) { - const newIdentifierName: string | null = DictionaryIdentifierNamesGenerator - .incrementIdentifierName(identifierName); + const newIdentifierName: string | null = + DictionaryIdentifierNamesGenerator.incrementIdentifierName(identifierName); if (newIdentifierName) { formattedIdentifierNames.push(newIdentifierName); diff --git a/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts index c5f0e2c18..b47629013 100644 --- a/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts @@ -21,7 +21,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -32,14 +32,14 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames * @param {number} nameLength * @returns {string} */ - public generateNext (nameLength?: number): string { + public generateNext(nameLength?: number): string { const rangeMinInteger: number = 10000; const rangeMaxInteger: number = 99_999_999; const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger); const hexadecimalNumber: string = NumberUtils.toHex(randomInteger); const prefixLength: number = Utils.hexadecimalPrefix.length; - const baseNameLength: number = (nameLength ?? HexadecimalIdentifierNamesGenerator.baseIdentifierNameLength) - + prefixLength; + const baseNameLength: number = + (nameLength ?? HexadecimalIdentifierNamesGenerator.baseIdentifierNameLength) + prefixLength; const baseIdentifierName: string = hexadecimalNumber.slice(0, baseNameLength); const identifierName: string = `_${baseIdentifierName}`; @@ -56,7 +56,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames * @param {number} nameLength * @returns {string} */ - public generateForGlobalScope (nameLength?: number): string { + public generateForGlobalScope(nameLength?: number): string { const identifierName: string = this.generateNext(nameLength); return `${this.options.identifiersPrefix}${identifierName}`.replace('__', '_'); @@ -67,7 +67,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames * @param {number} nameLength * @returns {string} */ - public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string { + public generateForLexicalScope(lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string { return this.generateNext(nameLength); } @@ -76,7 +76,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames * @param {number} nameLength * @returns {string} */ - public generateForLabel (label: string, nameLength?: number): string { + public generateForLabel(label: string, nameLength?: number): string { return this.generateNext(nameLength); } } diff --git a/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts index 0528e895d..1c011bda3 100644 --- a/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts @@ -30,9 +30,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene /** * @type {string[]} */ - private static readonly nameSequence: string[] = [ - ...`${numbersString}${alphabetString}${alphabetStringUppercase}` - ]; + private static readonly nameSequence: string[] = [...`${numbersString}${alphabetString}${alphabetStringUppercase}`]; /** * Reserved JS words with length of 2-4 symbols that can be possible generated with this replacer @@ -50,12 +48,12 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene /** * @type {WeakMap} */ - private readonly lastMangledNameForScopeMap: WeakMap = new WeakMap(); + private readonly lastMangledNameForScopeMap: WeakMap = new WeakMap(); /** * @type {WeakMap} */ - private readonly lastMangledNameForLabelMap: Map = new Map(); + private readonly lastMangledNameForLabelMap: Map = new Map(); /** * @type {ISetUtils} @@ -67,10 +65,10 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {IOptions} options * @param {ISetUtils} setUtils */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, - @inject(ServiceIdentifiers.ISetUtils) setUtils: ISetUtils, + @inject(ServiceIdentifiers.ISetUtils) setUtils: ISetUtils ) { super(randomGenerator, options); @@ -84,7 +82,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {number} nameLength * @returns {string} */ - public generateNext (nameLength?: number): string { + public generateNext(nameLength?: number): string { const identifierName: string = this.generateNewMangledName(this.lastMangledName); this.updatePreviousMangledName(identifierName); @@ -97,10 +95,8 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {number} nameLength * @returns {string} */ - public generateForGlobalScope (nameLength?: number): string { - const prefix: string = this.options.identifiersPrefix ? - `${this.options.identifiersPrefix}` - : ''; + public generateForGlobalScope(nameLength?: number): string { + const prefix: string = this.options.identifiersPrefix ? `${this.options.identifiersPrefix}` : ''; const identifierName: string = this.generateNewMangledName( this.lastMangledName, @@ -123,7 +119,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {number} nameLength * @returns {string} */ - public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string { + public generateForLexicalScope(lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string { const lexicalScopes: TNodeWithLexicalScope[] = [ lexicalScopeNode, ...NodeLexicalScopeUtils.getLexicalScopes(lexicalScopeNode) @@ -132,8 +128,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene const lastMangledNameForScope: string = this.getLastMangledNameForScopes(lexicalScopes); const identifierName: string = this.generateNewMangledName( lastMangledNameForScope, - (newIdentifierName: string) => - this.isValidIdentifierNameInLexicalScopes(newIdentifierName, lexicalScopes) + (newIdentifierName: string) => this.isValidIdentifierNameInLexicalScopes(newIdentifierName, lexicalScopes) ); this.lastMangledNameForScopeMap.set(lexicalScopeNode, identifierName); @@ -149,7 +144,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {number} nameLength * @returns {string} */ - public generateForLabel (label: string, nameLength?: number): string { + public generateForLabel(label: string, nameLength?: number): string { const lastMangledNameForLabel: string = this.getLastMangledNameForLabel(label); const identifierName: string = this.generateNewMangledName(lastMangledNameForLabel); @@ -165,7 +160,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @returns {boolean} */ // eslint-disable-next-line complexity - public isIncrementedMangledName (nextName: string, prevName: string): boolean { + public isIncrementedMangledName(nextName: string, prevName: string): boolean { if (nextName === prevName) { return false; } @@ -200,22 +195,24 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {string} mangledName * @returns {boolean} */ - public override isValidIdentifierName (mangledName: string): boolean { - return super.isValidIdentifierName(mangledName) - && !MangledIdentifierNamesGenerator.reservedNamesSet.has(mangledName); + public override isValidIdentifierName(mangledName: string): boolean { + return ( + super.isValidIdentifierName(mangledName) && + !MangledIdentifierNamesGenerator.reservedNamesSet.has(mangledName) + ); } /** * @returns {string[]} */ - protected getNameSequence (): string[] { + protected getNameSequence(): string[] { return MangledIdentifierNamesGenerator.nameSequence; } /** * @param {string} name */ - protected updatePreviousMangledName (name: string): void { + protected updatePreviousMangledName(name: string): void { if (!this.isIncrementedMangledName(name, this.lastMangledName)) { return; } @@ -228,7 +225,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {string} label * @param {string} lastMangledNameForLabel */ - protected updatePreviousMangledNameForLabel (name: string, label: string, lastMangledNameForLabel: string): void { + protected updatePreviousMangledNameForLabel(name: string, label: string, lastMangledNameForLabel: string): void { if (!this.isIncrementedMangledName(name, lastMangledNameForLabel)) { return; } @@ -241,7 +238,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {(newIdentifierName: string) => boolean} validationFunction * @returns {string} */ - protected generateNewMangledName ( + protected generateNewMangledName( previousMangledName: string, validationFunction?: (newIdentifierName: string) => boolean ): string { @@ -296,8 +293,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene do { identifierName = generateNewMangledName(identifierName); - isValidIdentifierName = validationFunction?.(identifierName) - ?? this.isValidIdentifierName(identifierName); + isValidIdentifierName = validationFunction?.(identifierName) ?? this.isValidIdentifierName(identifierName); } while (!isValidIdentifierName); return identifierName; @@ -307,7 +303,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {TNodeWithLexicalScope[]} lexicalScopeNodes * @returns {string} */ - private getLastMangledNameForScopes (lexicalScopeNodes: TNodeWithLexicalScope[]): string { + private getLastMangledNameForScopes(lexicalScopeNodes: TNodeWithLexicalScope[]): string { for (const lexicalScope of lexicalScopeNodes) { const lastMangledName: string | null = this.lastMangledNameForScopeMap.get(lexicalScope) ?? null; @@ -325,7 +321,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @param {string} label * @returns {string} */ - private getLastMangledNameForLabel (label: string): string { + private getLastMangledNameForLabel(label: string): string { const lastMangledName: string | null = this.lastMangledNameForLabelMap.get(label) ?? null; return lastMangledName ?? MangledIdentifierNamesGenerator.initMangledNameCharacter; diff --git a/src/generators/identifier-names-generators/MangledShuffledIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/MangledShuffledIdentifierNamesGenerator.ts index aeeaf5928..e4705ae3b 100644 --- a/src/generators/identifier-names-generators/MangledShuffledIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/MangledShuffledIdentifierNamesGenerator.ts @@ -30,7 +30,7 @@ export class MangledShuffledIdentifierNamesGenerator extends MangledIdentifierNa * @param {IOptions} options * @param {ISetUtils} setUtils */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @@ -42,7 +42,7 @@ export class MangledShuffledIdentifierNamesGenerator extends MangledIdentifierNa } @postConstruct() - public initialize (): void { + public initialize(): void { this.initializeNameSequence([ ...`${numbersString}`, ...this.arrayUtils.shuffle([...`${alphabetString}${alphabetStringUppercase}`]) @@ -52,7 +52,7 @@ export class MangledShuffledIdentifierNamesGenerator extends MangledIdentifierNa /** * @param {string[]} nameSequence */ - protected initializeNameSequence (nameSequence: string[]): void { + protected initializeNameSequence(nameSequence: string[]): void { if (!this.getNameSequence()) { MangledShuffledIdentifierNamesGenerator.shuffledNameSequence = nameSequence; } @@ -61,7 +61,7 @@ export class MangledShuffledIdentifierNamesGenerator extends MangledIdentifierNa /** * @returns {string[]} */ - protected override getNameSequence (): string[] { + protected override getNameSequence(): string[] { return MangledShuffledIdentifierNamesGenerator.shuffledNameSequence; } } diff --git a/src/interfaces/IInitializable.ts b/src/interfaces/IInitializable.ts index df1746e67..21731f02c 100644 --- a/src/interfaces/IInitializable.ts +++ b/src/interfaces/IInitializable.ts @@ -1,8 +1,8 @@ -export interface IInitializable { +export interface IInitializable { [key: string]: any; /** * @param args */ - initialize (...args: T): void; + initialize(...args: T): void; } diff --git a/src/interfaces/IJavaScriptObfsucator.ts b/src/interfaces/IJavaScriptObfsucator.ts index bdb821227..31b3dc9a3 100644 --- a/src/interfaces/IJavaScriptObfsucator.ts +++ b/src/interfaces/IJavaScriptObfsucator.ts @@ -5,5 +5,5 @@ export interface IJavaScriptObfuscator { * @param sourceCode * @returns IObfuscationResult */ - obfuscate (sourceCode: string): IObfuscationResult; + obfuscate(sourceCode: string): IObfuscationResult; } diff --git a/src/interfaces/ITransformer.ts b/src/interfaces/ITransformer.ts index 118f57068..b63fb7682 100644 --- a/src/interfaces/ITransformer.ts +++ b/src/interfaces/ITransformer.ts @@ -1,4 +1,4 @@ -export interface ITransformer { +export interface ITransformer { /** * @type {TTransformerName[] | undefined} */ diff --git a/src/interfaces/analyzers/IAnalyzer.ts b/src/interfaces/analyzers/IAnalyzer.ts index f718e31ca..75ff6b154 100644 --- a/src/interfaces/analyzers/IAnalyzer.ts +++ b/src/interfaces/analyzers/IAnalyzer.ts @@ -1,7 +1,7 @@ -export interface IAnalyzer { +export interface IAnalyzer { /** * @param {TArgs} args * @returns {TData} */ - analyze (...args: TArgs): TData; + analyze(...args: TArgs): TData; } diff --git a/src/interfaces/analyzers/calls-graph-analyzer/ICalleeDataExtractor.ts b/src/interfaces/analyzers/calls-graph-analyzer/ICalleeDataExtractor.ts index 95324ba72..e4097ab0d 100644 --- a/src/interfaces/analyzers/calls-graph-analyzer/ICalleeDataExtractor.ts +++ b/src/interfaces/analyzers/calls-graph-analyzer/ICalleeDataExtractor.ts @@ -8,5 +8,5 @@ export interface ICalleeDataExtractor { * @param callee * @returns ICalleeData|null */ - extract (blockScopeBody: ESTree.Node[], callee: ESTree.Node): ICalleeData | null; + extract(blockScopeBody: ESTree.Node[], callee: ESTree.Node): ICalleeData | null; } diff --git a/src/interfaces/analyzers/calls-graph-analyzer/ICallsGraphAnalyzer.ts b/src/interfaces/analyzers/calls-graph-analyzer/ICallsGraphAnalyzer.ts index e768bf185..948d3deca 100644 --- a/src/interfaces/analyzers/calls-graph-analyzer/ICallsGraphAnalyzer.ts +++ b/src/interfaces/analyzers/calls-graph-analyzer/ICallsGraphAnalyzer.ts @@ -8,5 +8,5 @@ export interface ICallsGraphAnalyzer extends IAnalyzer<[ESTree.Program], ICallsG * @param {Program} astTree * @returns {ICallsGraphData[]} */ - analyze (astTree: ESTree.Program): ICallsGraphData[]; + analyze(astTree: ESTree.Program): ICallsGraphData[]; } diff --git a/src/interfaces/analyzers/calls-graph-analyzer/IPrevailingKindOfVariablesAnalyzer.ts b/src/interfaces/analyzers/calls-graph-analyzer/IPrevailingKindOfVariablesAnalyzer.ts index b6cfb1f8b..e4c974c6d 100644 --- a/src/interfaces/analyzers/calls-graph-analyzer/IPrevailingKindOfVariablesAnalyzer.ts +++ b/src/interfaces/analyzers/calls-graph-analyzer/IPrevailingKindOfVariablesAnalyzer.ts @@ -6,10 +6,10 @@ export interface IPrevailingKindOfVariablesAnalyzer extends IAnalyzer<[ESTree.Pr /** * @param {Program} astTree */ - analyze (astTree: ESTree.Program): void; + analyze(astTree: ESTree.Program): void; /** * @returns {ESTree.VariableDeclaration['kind']} */ - getPrevailingKind (): ESTree.VariableDeclaration['kind']; + getPrevailingKind(): ESTree.VariableDeclaration['kind']; } diff --git a/src/interfaces/analyzers/number-numerical-expression-analyzer/INumberNumericalExpressionAnalyzer.ts b/src/interfaces/analyzers/number-numerical-expression-analyzer/INumberNumericalExpressionAnalyzer.ts index aff822879..948dded3a 100644 --- a/src/interfaces/analyzers/number-numerical-expression-analyzer/INumberNumericalExpressionAnalyzer.ts +++ b/src/interfaces/analyzers/number-numerical-expression-analyzer/INumberNumericalExpressionAnalyzer.ts @@ -2,14 +2,12 @@ import { TNumberNumericalExpressionData } from '../../../types/analyzers/number- import { IAnalyzer } from '../IAnalyzer'; -export interface INumberNumericalExpressionAnalyzer extends IAnalyzer<[number, number], TNumberNumericalExpressionData> { +export interface INumberNumericalExpressionAnalyzer + extends IAnalyzer<[number, number], TNumberNumericalExpressionData> { /** * @param {number} number * @param {number} additionalPartsCount * @returns {TNumberNumericalExpressionData} */ - analyze ( - number: number, - additionalPartsCount: number - ): TNumberNumericalExpressionData; + analyze(number: number, additionalPartsCount: number): TNumberNumericalExpressionData; } diff --git a/src/interfaces/analyzers/scope-analyzer/IScopeAnalyzer.ts b/src/interfaces/analyzers/scope-analyzer/IScopeAnalyzer.ts index 6215a56f0..a4d80b071 100644 --- a/src/interfaces/analyzers/scope-analyzer/IScopeAnalyzer.ts +++ b/src/interfaces/analyzers/scope-analyzer/IScopeAnalyzer.ts @@ -7,11 +7,11 @@ export interface IScopeAnalyzer extends IAnalyzer<[ESTree.Node], void> { /** * @param {Program} astTree */ - analyze (astTree: ESTree.Node): void; + analyze(astTree: ESTree.Node): void; /** * @param {Node} node * @returns {Scope} */ - acquireScope (node: ESTree.Node): eslintScope.Scope; + acquireScope(node: ESTree.Node): eslintScope.Scope; } diff --git a/src/interfaces/analyzers/string-array-storage-analyzer/IStringArrayStorageAnalyzer.ts b/src/interfaces/analyzers/string-array-storage-analyzer/IStringArrayStorageAnalyzer.ts index b635b3553..cabb47254 100644 --- a/src/interfaces/analyzers/string-array-storage-analyzer/IStringArrayStorageAnalyzer.ts +++ b/src/interfaces/analyzers/string-array-storage-analyzer/IStringArrayStorageAnalyzer.ts @@ -9,22 +9,22 @@ export interface IStringArrayStorageAnalyzer extends IAnalyzer<[ESTree.Program], /** * @param {Program} astTree */ - analyze (astTree: ESTree.Program): void; + analyze(astTree: ESTree.Program): void; /** * @param {Literal} literalNode * @param {Node} parentNode */ - analyzeLiteralNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): void; + analyzeLiteralNode(literalNode: ESTree.Literal, parentNode: ESTree.Node): void; /** * @param {TStringLiteralNode} stringLiteralNode */ - addItemDataForLiteralNode (stringLiteralNode: TStringLiteralNode): void; + addItemDataForLiteralNode(stringLiteralNode: TStringLiteralNode): void; /** * @param {Literal} literalNode * @returns {IStringArrayStorageItemData | undefined} */ - getItemDataForLiteralNode (literalNode: ESTree.Literal): IStringArrayStorageItemData | undefined; + getItemDataForLiteralNode(literalNode: ESTree.Literal): IStringArrayStorageItemData | undefined; } diff --git a/src/interfaces/code-transformers/ICodeTransformer.ts b/src/interfaces/code-transformers/ICodeTransformer.ts index 7b399252d..276a09a9e 100644 --- a/src/interfaces/code-transformers/ICodeTransformer.ts +++ b/src/interfaces/code-transformers/ICodeTransformer.ts @@ -3,11 +3,11 @@ import { ITransformer } from '../ITransformer'; import { CodeTransformer } from '../../enums/code-transformers/CodeTransformer'; import { CodeTransformationStage } from '../../enums/code-transformers/CodeTransformationStage'; -export interface ICodeTransformer extends ITransformer { +export interface ICodeTransformer extends ITransformer { /** * @param {string} code * @param {CodeTransformationStage} codeTransformationStage * @returns {string} */ - transformCode (code: string, codeTransformationStage: CodeTransformationStage): string; + transformCode(code: string, codeTransformationStage: CodeTransformationStage): string; } diff --git a/src/interfaces/code-transformers/ICodeTransformersRunner.ts b/src/interfaces/code-transformers/ICodeTransformersRunner.ts index 0eab6f39c..cde212fc1 100644 --- a/src/interfaces/code-transformers/ICodeTransformersRunner.ts +++ b/src/interfaces/code-transformers/ICodeTransformersRunner.ts @@ -8,7 +8,7 @@ export interface ICodeTransformersRunner { * @param {CodeTransformationStage} codeTransformationStage * @returns {string} */ - transform ( + transform( code: string, codeTransformers: CodeTransformer[], codeTransformationStage: CodeTransformationStage diff --git a/src/interfaces/container/IInversifyContainerFacade.ts b/src/interfaces/container/IInversifyContainerFacade.ts index 3252ea833..ccd4bbe74 100644 --- a/src/interfaces/container/IInversifyContainerFacade.ts +++ b/src/interfaces/container/IInversifyContainerFacade.ts @@ -6,20 +6,20 @@ export interface IInversifyContainerFacade { /** * @param serviceIdentifier */ - get (serviceIdentifier: interfaces.ServiceIdentifier): T; + get(serviceIdentifier: interfaces.ServiceIdentifier): T; /** * @param serviceIdentifier * @param named */ - getNamed (serviceIdentifier: interfaces.ServiceIdentifier, named: string | number | symbol): T; + getNamed(serviceIdentifier: interfaces.ServiceIdentifier, named: string | number | symbol): T; /** * @param {string} sourceCode * @param {string} sourceMap * @param {TInputOptions} options */ - load (sourceCode: string, sourceMap: string, options: TInputOptions): void; + load(sourceCode: string, sourceMap: string, options: TInputOptions): void; - unload (): void; + unload(): void; } diff --git a/src/interfaces/custom-code-helpers/ICustomCodeHelper.ts b/src/interfaces/custom-code-helpers/ICustomCodeHelper.ts index e821b68fa..148b39534 100644 --- a/src/interfaces/custom-code-helpers/ICustomCodeHelper.ts +++ b/src/interfaces/custom-code-helpers/ICustomCodeHelper.ts @@ -2,11 +2,9 @@ import { TStatement } from '../../types/node/TStatement'; import { IInitializable } from '../IInitializable'; -export interface ICustomCodeHelper < - TInitialData extends unknown[] = unknown[] -> extends IInitializable { +export interface ICustomCodeHelper extends IInitializable { /** * @returns ESTree.Node[] */ - getNode (): TStatement[]; + getNode(): TStatement[]; } diff --git a/src/interfaces/custom-code-helpers/ICustomCodeHelperFormatter.ts b/src/interfaces/custom-code-helpers/ICustomCodeHelperFormatter.ts index e6266ed8d..d77a91b01 100644 --- a/src/interfaces/custom-code-helpers/ICustomCodeHelperFormatter.ts +++ b/src/interfaces/custom-code-helpers/ICustomCodeHelperFormatter.ts @@ -7,14 +7,11 @@ export interface ICustomCodeHelperFormatter { * @param {TMapping} mapping * @returns {string} */ - formatTemplate ( - template: string, - mapping: TMapping - ): string; + formatTemplate(template: string, mapping: TMapping): string; /** * @param {TStatement[]} structure * @returns {TStatement[]} */ - formatStructure (structure: TStatement[]): TStatement[]; + formatStructure(structure: TStatement[]): TStatement[]; } diff --git a/src/interfaces/custom-code-helpers/ICustomCodeHelperGroup.ts b/src/interfaces/custom-code-helpers/ICustomCodeHelperGroup.ts index 07df42661..cdae125d4 100644 --- a/src/interfaces/custom-code-helpers/ICustomCodeHelperGroup.ts +++ b/src/interfaces/custom-code-helpers/ICustomCodeHelperGroup.ts @@ -9,7 +9,7 @@ export interface ICustomCodeHelperGroup extends IInitializable, TCustomCodeHelpe /** * @type {Map } */ - getCustomCodeHelpers (): Map ; + getCustomCodeHelpers(): Map; - initialize (): void; + initialize(): void; } diff --git a/src/interfaces/custom-code-helpers/ICustomCodeHelperObfuscator.ts b/src/interfaces/custom-code-helpers/ICustomCodeHelperObfuscator.ts index 0d9abdfaf..9f209fd60 100644 --- a/src/interfaces/custom-code-helpers/ICustomCodeHelperObfuscator.ts +++ b/src/interfaces/custom-code-helpers/ICustomCodeHelperObfuscator.ts @@ -6,5 +6,5 @@ export interface ICustomCodeHelperObfuscator { * @param {TInputOptions} additionalOptions * @returns {string} */ - obfuscateTemplate (template: string, additionalOptions?: TInputOptions): string; + obfuscateTemplate(template: string, additionalOptions?: TInputOptions): string; } diff --git a/src/interfaces/custom-nodes/ICustomNode.ts b/src/interfaces/custom-nodes/ICustomNode.ts index 359db4be7..1869485a6 100644 --- a/src/interfaces/custom-nodes/ICustomNode.ts +++ b/src/interfaces/custom-nodes/ICustomNode.ts @@ -2,11 +2,9 @@ import { TStatement } from '../../types/node/TStatement'; import { IInitializable } from '../IInitializable'; -export interface ICustomNode < - TInitialData extends unknown[] = unknown[] -> extends IInitializable { +export interface ICustomNode extends IInitializable { /** * @returns ESTree.Node[] */ - getNode (): TStatement[]; + getNode(): TStatement[]; } diff --git a/src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts b/src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts index f0d2f8974..a5164d74a 100644 --- a/src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts +++ b/src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts @@ -6,55 +6,55 @@ export interface IIdentifierNamesGenerator { * @param {number} nameLength * @returns {string} */ - generate (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string; + generate(lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string; /** * @param {number} nameLength * @returns {string} */ - generateForGlobalScope (nameLength?: number): string; + generateForGlobalScope(nameLength?: number): string; /** * @param {TNodeWithLexicalScope} lexicalScopeNode * @param {number} nameLength * @returns {string} */ - generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string; + generateForLexicalScope(lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string; /** * @param {string} label * @param {number} nameLength * @returns {string} */ - generateForLabel (label: string, nameLength?: number): string; + generateForLabel(label: string, nameLength?: number): string; /** * @param {number} nameLength * @returns {string} */ - generateNext (nameLength?: number): string; + generateNext(nameLength?: number): string; /** * @param {string} identifierName * @returns {boolean} */ - isValidIdentifierName (identifierName: string): boolean; + isValidIdentifierName(identifierName: string): boolean; /** * @param {string} identifierName * @param {TNodeWithLexicalScope[]} lexicalScopeNodes * @returns {boolean} */ - isValidIdentifierNameInLexicalScopes (identifierName: string, lexicalScopeNodes: TNodeWithLexicalScope[]): boolean; + isValidIdentifierNameInLexicalScopes(identifierName: string, lexicalScopeNodes: TNodeWithLexicalScope[]): boolean; /** * @param {string} identifierName */ - preserveName (identifierName: string): void; + preserveName(identifierName: string): void; /** * @param {string} identifierName * @param {TNodeWithLexicalScope} lexicalScope */ - preserveNameForLexicalScope (identifierName: string, lexicalScope: TNodeWithLexicalScope): void; + preserveNameForLexicalScope(identifierName: string, lexicalScope: TNodeWithLexicalScope): void; } diff --git a/src/interfaces/logger/ILogger.ts b/src/interfaces/logger/ILogger.ts index f0b4a7044..f186f5029 100644 --- a/src/interfaces/logger/ILogger.ts +++ b/src/interfaces/logger/ILogger.ts @@ -5,17 +5,17 @@ export interface ILogger { * @param {LoggingMessage} loggingMessage * @param {string | number} value */ - info (loggingMessage: LoggingMessage, value?: string | number): void; + info(loggingMessage: LoggingMessage, value?: string | number): void; /** * @param {LoggingMessage} loggingMessage * @param {string | number} value */ - success (loggingMessage: LoggingMessage, value?: string | number): void; + success(loggingMessage: LoggingMessage, value?: string | number): void; /** * @param {LoggingMessage} loggingMessage * @param {string | number} value */ - warn (loggingMessage: LoggingMessage, value?: string | number): void; + warn(loggingMessage: LoggingMessage, value?: string | number): void; } diff --git a/src/interfaces/node-transformers/INodeTransformer.ts b/src/interfaces/node-transformers/INodeTransformer.ts index 3798edbe8..9d67274df 100644 --- a/src/interfaces/node-transformers/INodeTransformer.ts +++ b/src/interfaces/node-transformers/INodeTransformer.ts @@ -7,29 +7,29 @@ import { IVisitor } from './IVisitor'; import { NodeTransformer } from '../../enums/node-transformers/NodeTransformer'; import { NodeTransformationStage } from '../../enums/node-transformers/NodeTransformationStage'; -export interface INodeTransformer extends ITransformer { +export interface INodeTransformer extends ITransformer { /** * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null; + getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null; /** * @param {Node} node * @param {Node | null} parentNode */ - prepareNode ? (node: ESTree.Node, parentNode: ESTree.Node | null): void; + prepareNode?(node: ESTree.Node, parentNode: ESTree.Node | null): void; /** * @param {Node} node * @param {Node | null} parentNode */ - restoreNode ? (node: ESTree.Node, parentNode: ESTree.Node | null): void; + restoreNode?(node: ESTree.Node, parentNode: ESTree.Node | null): void; /** * @param {Node} node * @param {Node | null} parentNode * @returns {Node | VisitorOption} */ - transformNode (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | estraverse.VisitorOption; + transformNode(node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | estraverse.VisitorOption; } diff --git a/src/interfaces/node-transformers/INodeTransformersRunner.ts b/src/interfaces/node-transformers/INodeTransformersRunner.ts index 568cb3fc5..7369702c1 100644 --- a/src/interfaces/node-transformers/INodeTransformersRunner.ts +++ b/src/interfaces/node-transformers/INodeTransformersRunner.ts @@ -10,7 +10,7 @@ export interface INodeTransformersRunner { * @param {NodeTransformationStage} nodeTransformationStage * @returns {T} */ - transform ( + transform( astTree: T, nodeTransformers: NodeTransformer[], nodeTransformationStage: NodeTransformationStage diff --git a/src/interfaces/node-transformers/IVisitor.ts b/src/interfaces/node-transformers/IVisitor.ts index 993f31f0b..fc7db4015 100644 --- a/src/interfaces/node-transformers/IVisitor.ts +++ b/src/interfaces/node-transformers/IVisitor.ts @@ -1,7 +1,7 @@ import * as estraverse from '@javascript-obfuscator/estraverse'; import * as ESTree from 'estree'; -export interface IVisitor { - enter? (node: T, parentNode: ESTree.Node | null): ESTree.Node | estraverse.VisitorOption | void; - leave? (node: T, parentNode: ESTree.Node | null): ESTree.Node | estraverse.VisitorOption | void; +export interface IVisitor { + enter?(node: T, parentNode: ESTree.Node | null): ESTree.Node | estraverse.VisitorOption | void; + leave?(node: T, parentNode: ESTree.Node | null): ESTree.Node | estraverse.VisitorOption | void; } diff --git a/src/interfaces/node-transformers/control-flow-transformers/IControlFlowReplacer.ts b/src/interfaces/node-transformers/control-flow-transformers/IControlFlowReplacer.ts index 67c183f88..d2f912fb5 100644 --- a/src/interfaces/node-transformers/control-flow-transformers/IControlFlowReplacer.ts +++ b/src/interfaces/node-transformers/control-flow-transformers/IControlFlowReplacer.ts @@ -9,15 +9,11 @@ export interface IControlFlowReplacer { * @param {IControlFlowStorage} controlFlowStorage * @returns {Node} */ - replace ( - node: ESTree.Node, - parentNode: ESTree.Node, - controlFlowStorage: IControlFlowStorage - ): ESTree.Node; + replace(node: ESTree.Node, parentNode: ESTree.Node, controlFlowStorage: IControlFlowStorage): ESTree.Node; /** * @param {TControlFlowStorage} controlFlowStorage * @returns {string} */ - generateStorageKey (controlFlowStorage: IControlFlowStorage): string; + generateStorageKey(controlFlowStorage: IControlFlowStorage): string; } diff --git a/src/interfaces/node-transformers/converting-transformers/object-expression-extractors/IObjectExpressionExtractor.ts b/src/interfaces/node-transformers/converting-transformers/object-expression-extractors/IObjectExpressionExtractor.ts index fb811e29d..632129eca 100644 --- a/src/interfaces/node-transformers/converting-transformers/object-expression-extractors/IObjectExpressionExtractor.ts +++ b/src/interfaces/node-transformers/converting-transformers/object-expression-extractors/IObjectExpressionExtractor.ts @@ -8,7 +8,7 @@ export interface IObjectExpressionExtractor { * @param {Statement} hostStatement * @returns {IObjectExpressionExtractorResult} */ - extract ( + extract( objectExpressionNode: ESTree.ObjectExpression, hostStatement: ESTree.Statement ): IObjectExpressionExtractorResult; diff --git a/src/interfaces/node-transformers/rename-identifiers-transformers/replacer/IIdentifierReplacer.ts b/src/interfaces/node-transformers/rename-identifiers-transformers/replacer/IIdentifierReplacer.ts index b4c9e8088..5e64b4abd 100644 --- a/src/interfaces/node-transformers/rename-identifiers-transformers/replacer/IIdentifierReplacer.ts +++ b/src/interfaces/node-transformers/rename-identifiers-transformers/replacer/IIdentifierReplacer.ts @@ -7,13 +7,13 @@ export interface IIdentifierReplacer { * @param {Identifier} identifierNode * @param {TNodeWithLexicalScope} lexicalScopeNode */ - storeGlobalName (identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void; + storeGlobalName(identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void; /** * @param {Identifier} identifierNode * @param {TNodeWithLexicalScope} lexicalScopeNode */ - storeLocalName (identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void; + storeLocalName(identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void; /** * @param {Node} node @@ -21,20 +21,16 @@ export interface IIdentifierReplacer { * @param {number} nodeIdentifier * @returns {ESTree.Identifier} */ - replace ( - node: ESTree.Node, - lexicalScopeNode?: TNodeWithLexicalScope, - nodeIdentifier?: number - ): ESTree.Identifier; + replace(node: ESTree.Node, lexicalScopeNode?: TNodeWithLexicalScope, nodeIdentifier?: number): ESTree.Identifier; /** * @param {Identifier} identifierNode */ - preserveName (identifierNode: ESTree.Identifier): void; + preserveName(identifierNode: ESTree.Identifier): void; /** * @param {Identifier} identifierNode * @param {TNodeWithLexicalScope} lexicalScopeNode */ - preserveNameForLexicalScope (identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void; + preserveNameForLexicalScope(identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void; } diff --git a/src/interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer.ts b/src/interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer.ts index 802c16a44..84914a3ca 100644 --- a/src/interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer.ts +++ b/src/interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer.ts @@ -5,5 +5,5 @@ export interface IThroughIdentifierReplacer { * @param {Identifier} identifierNode * @returns {Identifier} */ - replace (identifierNode: ESTree.Identifier): ESTree.Identifier; + replace(identifierNode: ESTree.Identifier): ESTree.Identifier; } diff --git a/src/interfaces/node-transformers/rename-properties-transformers/replacer/IRenamePropertiesReplacer.ts b/src/interfaces/node-transformers/rename-properties-transformers/replacer/IRenamePropertiesReplacer.ts index ef9cbba61..18abe84cf 100644 --- a/src/interfaces/node-transformers/rename-properties-transformers/replacer/IRenamePropertiesReplacer.ts +++ b/src/interfaces/node-transformers/rename-properties-transformers/replacer/IRenamePropertiesReplacer.ts @@ -4,11 +4,11 @@ export interface IRenamePropertiesReplacer { /** * @param {string} propertyName */ - excludePropertyName (propertyName: string): void; + excludePropertyName(propertyName: string): void; /** * @param {ESTree.Identifier | ESTree.Literal} node * @returns {ESTree.Identifier | ESTree.Literal} */ - replace (node: ESTree.Identifier | ESTree.Literal): ESTree.Identifier | ESTree.Literal; + replace(node: ESTree.Identifier | ESTree.Literal): ESTree.Identifier | ESTree.Literal; } diff --git a/src/interfaces/node/IScopeIdentifiersTraverser.ts b/src/interfaces/node/IScopeIdentifiersTraverser.ts index 4f5570f5e..870b838e9 100644 --- a/src/interfaces/node/IScopeIdentifiersTraverser.ts +++ b/src/interfaces/node/IScopeIdentifiersTraverser.ts @@ -10,7 +10,7 @@ export interface IScopeIdentifiersTraverser { * @param {Node | null} parentNode * @param {TScopeIdentifiersTraverserCallback} callback */ - traverseScopeIdentifiers ( + traverseScopeIdentifiers( programNode: ESTree.Program, parentNode: ESTree.Node | null, callback: TScopeIdentifiersTraverserCallback @@ -21,10 +21,9 @@ export interface IScopeIdentifiersTraverser { * @param {Node | null} parentNode * @param {TScopeIdentifiersTraverserCallback} callback */ - traverseScopeThroughIdentifiers ( + traverseScopeThroughIdentifiers( node: ESTree.Node, parentNode: ESTree.Node | null, callback: TScopeIdentifiersTraverserCallback ): void; - } diff --git a/src/interfaces/options/IOptionsNormalizer.ts b/src/interfaces/options/IOptionsNormalizer.ts index fe7f39616..d44cb7493 100644 --- a/src/interfaces/options/IOptionsNormalizer.ts +++ b/src/interfaces/options/IOptionsNormalizer.ts @@ -5,5 +5,5 @@ export interface IOptionsNormalizer { * @param {IOptions} options * @returns {IOptions} */ - normalize (options: IOptions): IOptions; + normalize(options: IOptions): IOptions; } diff --git a/src/interfaces/source-code/IObfuscationResult.ts b/src/interfaces/source-code/IObfuscationResult.ts index 16c7301a9..00e07974d 100644 --- a/src/interfaces/source-code/IObfuscationResult.ts +++ b/src/interfaces/source-code/IObfuscationResult.ts @@ -3,24 +3,24 @@ import { TIdentifierNamesCache } from '../../types/TIdentifierNamesCache'; import { IInitializable } from '../IInitializable'; import { IOptions } from '../options/IOptions'; -export interface IObfuscationResult extends IInitializable <[string, string]> { +export interface IObfuscationResult extends IInitializable<[string, string]> { /** * @returns {TIdentifierNamesCache} */ - getIdentifierNamesCache (): TIdentifierNamesCache; + getIdentifierNamesCache(): TIdentifierNamesCache; /** * @return {string} */ - getObfuscatedCode (): string; + getObfuscatedCode(): string; /** * @return {IOptions} */ - getOptions (): IOptions; + getOptions(): IOptions; /** * @return {string} */ - getSourceMap (): string; + getSourceMap(): string; } diff --git a/src/interfaces/source-code/ISourceCode.ts b/src/interfaces/source-code/ISourceCode.ts index 5c9311b4c..61c2b2bf2 100644 --- a/src/interfaces/source-code/ISourceCode.ts +++ b/src/interfaces/source-code/ISourceCode.ts @@ -2,10 +2,10 @@ export interface ISourceCode { /** * @returns string */ - getSourceCode (): string; + getSourceCode(): string; /** * @returns string */ - getSourceMap (): string; + getSourceMap(): string; } diff --git a/src/interfaces/storages/IArrayStorage.ts b/src/interfaces/storages/IArrayStorage.ts index 771b21f89..47e917f97 100644 --- a/src/interfaces/storages/IArrayStorage.ts +++ b/src/interfaces/storages/IArrayStorage.ts @@ -1,59 +1,59 @@ import { IInitializable } from '../IInitializable'; -export interface IArrayStorage extends IInitializable { +export interface IArrayStorage extends IInitializable { /** * @param {number} key * @returns {V | undefined} */ - delete (key: number): V | undefined; + delete(key: number): V | undefined; /** * @param {number} key * @returns {V | undefined} */ - get (key: number): V | undefined; + get(key: number): V | undefined; /** * @param {number} key * @returns {V} */ - getOrThrow (key: number): V; + getOrThrow(key: number): V; /** * @param value * @returns number | null */ - getKeyOf (value: V): number | null; + getKeyOf(value: V): number | null; /** * @returns number */ - getLength (): number; + getLength(): number; /** * @returns {V[]} */ - getStorage (): V[]; + getStorage(): V[]; /** * @returns string */ - getStorageId (): string; + getStorageId(): string; /** * @param storage * @param mergeId */ - mergeWith (storage: this, mergeId: boolean): void; + mergeWith(storage: this, mergeId: boolean): void; /** * @param {number} key * @param {V} value */ - set (key: number, value: V): void; + set(key: number, value: V): void; /** * @returns string */ - toString (): string; + toString(): string; } diff --git a/src/interfaces/storages/IMapStorage.ts b/src/interfaces/storages/IMapStorage.ts index 50f004ca1..f217f9807 100644 --- a/src/interfaces/storages/IMapStorage.ts +++ b/src/interfaces/storages/IMapStorage.ts @@ -2,65 +2,65 @@ import { TDictionary } from '../../types/TDictionary'; import { IInitializable } from '../IInitializable'; -export interface IMapStorage extends IInitializable { +export interface IMapStorage extends IInitializable { /** * @param {K} key * @returns {V | undefined} */ - get (key: K): V | undefined; + get(key: K): V | undefined; /** * @param {K} key * @returns {V} */ - getOrThrow (key: K): V; + getOrThrow(key: K): V; /** * @param {V} value * @returns {K | null} */ - getKeyOf (value: V): K | null; + getKeyOf(value: V): K | null; /** * @returns number */ - getLength (): number; + getLength(): number; /** * @returns {Map} */ - getStorage (): Map ; + getStorage(): Map; /** * @returns {TDictionary} */ - getStorageAsDictionary (): TDictionary; + getStorageAsDictionary(): TDictionary; /** * @returns string */ - getStorageId (): string; + getStorageId(): string; /** * @param {K} key * @returns {boolean} */ - has (key: K): boolean; + has(key: K): boolean; /** * @param storage * @param mergeId */ - mergeWith (storage: this, mergeId: boolean): void; + mergeWith(storage: this, mergeId: boolean): void; /** * @param {K} key * @param {V} value */ - set (key: K, value: V): void; + set(key: K, value: V): void; /** * @returns string */ - toString (): string; + toString(): string; } diff --git a/src/interfaces/storages/IWeakMapStorage.ts b/src/interfaces/storages/IWeakMapStorage.ts index 82b91560a..40c064343 100644 --- a/src/interfaces/storages/IWeakMapStorage.ts +++ b/src/interfaces/storages/IWeakMapStorage.ts @@ -1,37 +1,37 @@ import { IInitializable } from '../IInitializable'; -export interface IWeakMapStorage extends IInitializable { +export interface IWeakMapStorage extends IInitializable { /** * @param {K} key * @returns {V | undefined} */ - get (key: K): V | undefined; + get(key: K): V | undefined; /** * @param {K} key * @returns {V} */ - getOrThrow (key: K): V; + getOrThrow(key: K): V; /** * @returns {WeakMap} */ - getStorage (): WeakMap ; + getStorage(): WeakMap; /** * @returns string */ - getStorageId (): string; + getStorageId(): string; /** * @param {K} key * @returns {boolean} */ - has (key: K): boolean; + has(key: K): boolean; /** * @param {K} key * @param {V} value */ - set (key: K, value: V): void; + set(key: K, value: V): void; } diff --git a/src/interfaces/storages/control-flow-transformers/IControlFlowStorage.ts b/src/interfaces/storages/control-flow-transformers/IControlFlowStorage.ts index 7c59d6df7..19171fc7d 100644 --- a/src/interfaces/storages/control-flow-transformers/IControlFlowStorage.ts +++ b/src/interfaces/storages/control-flow-transformers/IControlFlowStorage.ts @@ -2,4 +2,4 @@ import { IMapStorage } from '../IMapStorage'; import { ICustomNode } from '../../custom-nodes/ICustomNode'; // eslint-disable-next-line -export interface IControlFlowStorage extends IMapStorage {} +export interface IControlFlowStorage extends IMapStorage {} diff --git a/src/interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage.ts b/src/interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage.ts index c1aa13bec..dfdc47182 100644 --- a/src/interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage.ts +++ b/src/interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage.ts @@ -1,4 +1,4 @@ import { IMapStorage } from '../IMapStorage'; // eslint-disable-next-line -export interface IGlobalIdentifierNamesCacheStorage extends IMapStorage {} +export interface IGlobalIdentifierNamesCacheStorage extends IMapStorage {} diff --git a/src/interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage.ts b/src/interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage.ts index b4a6e1579..5003d6c69 100644 --- a/src/interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage.ts +++ b/src/interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage.ts @@ -1,4 +1,4 @@ import { IMapStorage } from '../IMapStorage'; // eslint-disable-next-line -export interface IPropertyIdentifierNamesCacheStorage extends IMapStorage {} +export interface IPropertyIdentifierNamesCacheStorage extends IMapStorage {} diff --git a/src/interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage.ts b/src/interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage.ts index 149e0cc1c..4c505cb25 100644 --- a/src/interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage.ts +++ b/src/interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage.ts @@ -3,24 +3,18 @@ import * as ESTree from 'estree'; import { IMapStorage } from '../IMapStorage'; import { IStringArrayStorageItemData } from './IStringArrayStorageItem'; -export interface ILiteralNodesCacheStorage extends IMapStorage { +export interface ILiteralNodesCacheStorage extends IMapStorage { /** * @param {string} literalValue * @param {IStringArrayStorageItemData | undefined} stringArrayStorageItemData * @returns {string} */ - buildKey ( - literalValue: string, - stringArrayStorageItemData: IStringArrayStorageItemData | undefined, - ): string; + buildKey(literalValue: string, stringArrayStorageItemData: IStringArrayStorageItemData | undefined): string; /** * @param {string} key * @param {IStringArrayStorageItemData | undefined} stringArrayStorageItemData * @returns {boolean} */ - shouldUseCachedValue ( - key: string, - stringArrayStorageItemData: IStringArrayStorageItemData | undefined - ): boolean; + shouldUseCachedValue(key: string, stringArrayStorageItemData: IStringArrayStorageItemData | undefined): boolean; } diff --git a/src/interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrappersDataStorage.ts b/src/interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrappersDataStorage.ts index ed9e71341..f88a899af 100644 --- a/src/interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrappersDataStorage.ts +++ b/src/interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrappersDataStorage.ts @@ -4,7 +4,5 @@ import { TStringArrayScopeCallsWrappersDataByEncoding } from '../../../types/nod import { IWeakMapStorage } from '../IWeakMapStorage'; // eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface IStringArrayScopeCallsWrappersDataStorage extends IWeakMapStorage< - TNodeWithLexicalScopeStatements, - TStringArrayScopeCallsWrappersDataByEncoding -> {} +export interface IStringArrayScopeCallsWrappersDataStorage + extends IWeakMapStorage {} diff --git a/src/interfaces/storages/string-array-transformers/IStringArrayStorage.ts b/src/interfaces/storages/string-array-transformers/IStringArrayStorage.ts index a80d3d965..0e1cf6b44 100644 --- a/src/interfaces/storages/string-array-transformers/IStringArrayStorage.ts +++ b/src/interfaces/storages/string-array-transformers/IStringArrayStorage.ts @@ -3,29 +3,29 @@ import { TStringArrayEncoding } from '../../../types/options/TStringArrayEncodin import { IMapStorage } from '../IMapStorage'; import { IStringArrayStorageItemData } from './IStringArrayStorageItem'; -export interface IStringArrayStorage extends IMapStorage { +export interface IStringArrayStorage extends IMapStorage { /** * @returns {number} */ - getIndexShiftAmount (): number; + getIndexShiftAmount(): number; /** * @returns {number} */ - getRotationAmount (): number; + getRotationAmount(): number; /** * @returns {string} */ - getStorageName (): string; + getStorageName(): string; /** * @param {TStringArrayEncoding | null} stringArrayEncoding * @returns {string} */ - getStorageCallsWrapperName (stringArrayEncoding: TStringArrayEncoding | null): string; + getStorageCallsWrapperName(stringArrayEncoding: TStringArrayEncoding | null): string; - rotateStorage (): void; + rotateStorage(): void; - shuffleStorage (): void; + shuffleStorage(): void; } diff --git a/src/interfaces/storages/string-array-transformers/IVisitedLexicalScopeNodesStackStorage.ts b/src/interfaces/storages/string-array-transformers/IVisitedLexicalScopeNodesStackStorage.ts index 8d41654ed..76f01e56d 100644 --- a/src/interfaces/storages/string-array-transformers/IVisitedLexicalScopeNodesStackStorage.ts +++ b/src/interfaces/storages/string-array-transformers/IVisitedLexicalScopeNodesStackStorage.ts @@ -6,20 +6,20 @@ export interface IVisitedLexicalScopeNodesStackStorage extends IArrayStorage TValue} valueFunction * @returns {TValue[]} */ - fillWithRange (length: number, valueFunction: (index: number) => TValue): TValue[]; + fillWithRange(length: number, valueFunction: (index: number) => TValue): TValue[]; /** * @param {T[]} array * @returns {T | null} */ - findMostOccurringElement (array: T[]): T | null; + findMostOccurringElement(array: T[]): T | null; /** * @param {T[]} array * @returns {T | undefined} */ - getLastElement (array: T[]): T | undefined; + getLastElement(array: T[]): T | undefined; /** * @param {T[]} array * @param {number} index * @returns {T | undefined} */ - getLastElementByIndex (array: T[], index: number): T | undefined; + getLastElementByIndex(array: T[], index: number): T | undefined; /** * @param array * @param times * @returns {T[]} */ - rotate (array: T[], times: number): T[]; + rotate(array: T[], times: number): T[]; /** * @param array * @return {T[]} */ - shuffle (array: T[]): T[]; + shuffle(array: T[]): T[]; } diff --git a/src/interfaces/utils/ICryptUtils.ts b/src/interfaces/utils/ICryptUtils.ts index 49dae1a0d..ea8b90471 100644 --- a/src/interfaces/utils/ICryptUtils.ts +++ b/src/interfaces/utils/ICryptUtils.ts @@ -3,19 +3,19 @@ export interface ICryptUtils { * @param {string} string * @returns {string} */ - btoa (string: string): string; + btoa(string: string): string; /** * @param str * @param length * @returns {[string, string]} */ - hideString (str: string, length: number): [string, string]; + hideString(str: string, length: number): [string, string]; /** * @param key * @param string * @returns {string} */ - rc4 (string: string, key: string): string; + rc4(string: string, key: string): string; } diff --git a/src/interfaces/utils/IEscapeSequenceEncoder.ts b/src/interfaces/utils/IEscapeSequenceEncoder.ts index 2394170cf..e8cc0aec7 100644 --- a/src/interfaces/utils/IEscapeSequenceEncoder.ts +++ b/src/interfaces/utils/IEscapeSequenceEncoder.ts @@ -4,5 +4,5 @@ export interface IEscapeSequenceEncoder { * @param {boolean} encodeAllSymbols * @returns {string} */ - encode (string: string, encodeAllSymbols: boolean): string; + encode(string: string, encodeAllSymbols: boolean): string; } diff --git a/src/interfaces/utils/ILevelledTopologicalSorter.ts b/src/interfaces/utils/ILevelledTopologicalSorter.ts index 137cfc29a..6c97b4a87 100644 --- a/src/interfaces/utils/ILevelledTopologicalSorter.ts +++ b/src/interfaces/utils/ILevelledTopologicalSorter.ts @@ -1,21 +1,18 @@ -export interface ILevelledTopologicalSorter { +export interface ILevelledTopologicalSorter { /** * @param {TValue} precedent * @param {TValue | null} consequent * @returns {this} */ - add ( - precedent: TValue, - consequent?: TValue | null - ): this; + add(precedent: TValue, consequent?: TValue | null): this; /** * @returns {TValue[]} */ - sort (): TValue[]; + sort(): TValue[]; /** * @returns {TValue[][]} */ - sortByGroups (): TValue[][]; + sortByGroups(): TValue[][]; } diff --git a/src/interfaces/utils/IRandomGenerator.ts b/src/interfaces/utils/IRandomGenerator.ts index 65c5f4d24..d3091f482 100644 --- a/src/interfaces/utils/IRandomGenerator.ts +++ b/src/interfaces/utils/IRandomGenerator.ts @@ -6,19 +6,19 @@ export interface IRandomGenerator { /** * @returns {number} */ - getMathRandom (): number; + getMathRandom(): number; /** * @returns {Chance.Chance} */ - getRandomGenerator (): Chance.Chance; + getRandomGenerator(): Chance.Chance; /** * @param min * @param max * @returns {number} */ - getRandomInteger (min: number, max: number): number; + getRandomInteger(min: number, max: number): number; /** * @param {number} min @@ -26,22 +26,22 @@ export interface IRandomGenerator { * @param {number[]} valuesToExclude * @returns {number} */ - getRandomIntegerExcluding (min: number, max: number, valuesToExclude: number[]): number; + getRandomIntegerExcluding(min: number, max: number, valuesToExclude: number[]): number; /** * @param length * @param pool * @returns {string} */ - getRandomString (length: number, pool?: string): string; + getRandomString(length: number, pool?: string): string; /** * @returns {string} */ - getInputSeed (): string; + getInputSeed(): string; /** * @returns {string} */ - getRawSeed (): string; + getRawSeed(): string; } diff --git a/src/interfaces/utils/ISetUtils.ts b/src/interfaces/utils/ISetUtils.ts index 7a81941e1..5b5c5c47b 100644 --- a/src/interfaces/utils/ISetUtils.ts +++ b/src/interfaces/utils/ISetUtils.ts @@ -3,5 +3,5 @@ export interface ISetUtils { * @param {Set} set * @returns {T | undefined} */ - getLastElement (set: Set): T | undefined; + getLastElement(set: Set): T | undefined; } diff --git a/src/interfaces/utils/ITransformerNamesGroupsBuilder.ts b/src/interfaces/utils/ITransformerNamesGroupsBuilder.ts index 99f813c6d..0dd4875ca 100644 --- a/src/interfaces/utils/ITransformerNamesGroupsBuilder.ts +++ b/src/interfaces/utils/ITransformerNamesGroupsBuilder.ts @@ -1,12 +1,9 @@ import { TDictionary } from '../../types/TDictionary'; -export interface ITransformerNamesGroupsBuilder < - TTransformerName extends string, - TTransformer -> { +export interface ITransformerNamesGroupsBuilder { /** * @param {TDictionary} normalizedTransformers * @returns {TTransformerName[][]} */ - build (normalizedTransformers: TDictionary): TTransformerName[][]; + build(normalizedTransformers: TDictionary): TTransformerName[][]; } diff --git a/src/logger/Logger.ts b/src/logger/Logger.ts index 7a93c6c57..5b706cb16 100644 --- a/src/logger/Logger.ts +++ b/src/logger/Logger.ts @@ -34,9 +34,7 @@ export class Logger implements ILogger { /** * @param {IOptions} options */ - public constructor ( - @inject(ServiceIdentifiers.IOptions) options: IOptions - ) { + public constructor(@inject(ServiceIdentifiers.IOptions) options: IOptions) { this.options = options; } @@ -46,11 +44,11 @@ export class Logger implements ILogger { * @param {string} loggingMessage * @param {string | number} value */ - public static log ( + public static log( loggingLevelColor: Chalk, loggingPrefix: LoggingPrefix, loggingMessage: string, - value?: string | number, + value?: string | number ): void { const processedMessage: string = loggingLevelColor(`\n${loggingPrefix} ${loggingMessage}`); @@ -61,7 +59,7 @@ export class Logger implements ILogger { * @param {LoggingMessage} loggingMessage * @param {string | number} value */ - public info (loggingMessage: LoggingMessage, value?: string | number): void { + public info(loggingMessage: LoggingMessage, value?: string | number): void { if (!this.options.log) { return; } @@ -73,7 +71,7 @@ export class Logger implements ILogger { * @param {LoggingMessage} loggingMessage * @param {string | number} value */ - public success (loggingMessage: LoggingMessage, value?: string | number): void { + public success(loggingMessage: LoggingMessage, value?: string | number): void { if (!this.options.log) { return; } @@ -85,7 +83,7 @@ export class Logger implements ILogger { * @param {LoggingMessage} loggingMessage * @param {string | number} value */ - public warn (loggingMessage: LoggingMessage, value?: string | number): void { + public warn(loggingMessage: LoggingMessage, value?: string | number): void { if (!this.options.log) { return; } diff --git a/src/node-transformers/AbstractNodeTransformer.ts b/src/node-transformers/AbstractNodeTransformer.ts index 44232a2f7..ebaa85e4c 100644 --- a/src/node-transformers/AbstractNodeTransformer.ts +++ b/src/node-transformers/AbstractNodeTransformer.ts @@ -33,7 +33,7 @@ export abstract class AbstractNodeTransformer implements INodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -45,12 +45,12 @@ export abstract class AbstractNodeTransformer implements INodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public abstract getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null; + public abstract getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null; /** * @param {Node} node * @param {Node} parentNode * @returns {Node | VisitorOption} */ - public abstract transformNode (node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node | estraverse.VisitorOption; + public abstract transformNode(node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node | estraverse.VisitorOption; } diff --git a/src/node-transformers/NodeTransformersRunner.ts b/src/node-transformers/NodeTransformersRunner.ts index 8e423bae3..360566caf 100644 --- a/src/node-transformers/NodeTransformersRunner.ts +++ b/src/node-transformers/NodeTransformersRunner.ts @@ -42,14 +42,11 @@ export class NodeTransformersRunner implements INodeTransformersRunner { * @param {TNodeTransformerFactory} nodeTransformerFactory * @param {ITransformerNamesGroupsBuilder} nodeTransformerNamesGroupsBuilder */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__INodeTransformer) - nodeTransformerFactory: TNodeTransformerFactory, + nodeTransformerFactory: TNodeTransformerFactory, @inject(ServiceIdentifiers.INodeTransformerNamesGroupsBuilder) - nodeTransformerNamesGroupsBuilder: ITransformerNamesGroupsBuilder< - NodeTransformer, - INodeTransformer - >, + nodeTransformerNamesGroupsBuilder: ITransformerNamesGroupsBuilder ) { this.nodeTransformerFactory = nodeTransformerFactory; this.nodeTransformerNamesGroupsBuilder = nodeTransformerNamesGroupsBuilder; @@ -61,7 +58,7 @@ export class NodeTransformersRunner implements INodeTransformersRunner { * @param {NodeTransformationStage} nodeTransformationStage * @returns {T} */ - public transform ( + public transform( astTree: T, nodeTransformerNames: NodeTransformer[], nodeTransformationStage: NodeTransformationStage @@ -70,8 +67,10 @@ export class NodeTransformersRunner implements INodeTransformersRunner { return astTree; } - const normalizedNodeTransformers: TDictionary = - this.buildNormalizedNodeTransformers(nodeTransformerNames, nodeTransformationStage); + const normalizedNodeTransformers: TDictionary = this.buildNormalizedNodeTransformers( + nodeTransformerNames, + nodeTransformationStage + ); const nodeTransformerNamesGroups: NodeTransformer[][] = this.nodeTransformerNamesGroupsBuilder.build(normalizedNodeTransformers); @@ -114,26 +113,25 @@ export class NodeTransformersRunner implements INodeTransformersRunner { * @param {NodeTransformationStage} nodeTransformationStage * @returns {TDictionary} */ - private buildNormalizedNodeTransformers ( + private buildNormalizedNodeTransformers( nodeTransformerNames: NodeTransformer[], nodeTransformationStage: NodeTransformationStage ): TDictionary { - return nodeTransformerNames - .reduce>( - (acc: TDictionary, nodeTransformerName: NodeTransformer) => { - const nodeTransformer: INodeTransformer = this.nodeTransformerFactory(nodeTransformerName); - - if (!nodeTransformer.getVisitor(nodeTransformationStage)) { - return acc; - } - - return >{ - ...acc, - [nodeTransformerName]: nodeTransformer - }; - }, - {} - ); + return nodeTransformerNames.reduce>( + (acc: TDictionary, nodeTransformerName: NodeTransformer) => { + const nodeTransformer: INodeTransformer = this.nodeTransformerFactory(nodeTransformerName); + + if (!nodeTransformer.getVisitor(nodeTransformationStage)) { + return acc; + } + + return >{ + ...acc, + [nodeTransformerName]: nodeTransformer + }; + }, + {} + ); } /** @@ -141,7 +139,7 @@ export class NodeTransformersRunner implements INodeTransformersRunner { * @param {TVisitorDirection} direction * @returns {TVisitorFunction} */ - private mergeVisitorsForDirection (visitors: IVisitor[], direction: TVisitorDirection): TVisitorFunction { + private mergeVisitorsForDirection(visitors: IVisitor[], direction: TVisitorDirection): TVisitorFunction { const visitorsLength: number = visitors.length; if (!visitorsLength) { diff --git a/src/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.ts b/src/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.ts index 62ff4b8bf..54a9356cd 100644 --- a/src/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.ts +++ b/src/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -40,9 +40,9 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions @@ -57,24 +57,26 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme * @param {Node} node * @returns {boolean} */ - private static isProhibitedStatementNode (node: ESTree.Node): boolean { - const isBreakOrContinueStatement: boolean = NodeGuards.isBreakStatementNode(node) - || NodeGuards.isContinueStatementNode(node); - const isVariableDeclarationWithLetOrConstKind: boolean = NodeGuards.isVariableDeclarationNode(node) - && (node.kind === 'const' || node.kind === 'let'); + private static isProhibitedStatementNode(node: ESTree.Node): boolean { + const isBreakOrContinueStatement: boolean = + NodeGuards.isBreakStatementNode(node) || NodeGuards.isContinueStatementNode(node); + const isVariableDeclarationWithLetOrConstKind: boolean = + NodeGuards.isVariableDeclarationNode(node) && (node.kind === 'const' || node.kind === 'let'); const isClassDeclaration: boolean = NodeGuards.isClassDeclarationNode(node); - return NodeGuards.isFunctionDeclarationNode(node) - || isBreakOrContinueStatement - || isVariableDeclarationWithLetOrConstKind - || isClassDeclaration; + return ( + NodeGuards.isFunctionDeclarationNode(node) || + isBreakOrContinueStatement || + isVariableDeclarationWithLetOrConstKind || + isClassDeclaration + ); } /** * @param {BlockStatement} blockStatementNode * @returns {boolean} */ - private static canTransformBlockStatementNode (blockStatementNode: ESTree.BlockStatement): boolean { + private static canTransformBlockStatementNode(blockStatementNode: ESTree.BlockStatement): boolean { let canTransform: boolean = true; estraverse.traverse(blockStatementNode, { @@ -100,7 +102,7 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { if (!this.options.controlFlowFlattening) { return null; } @@ -125,7 +127,7 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (blockStatementNode: ESTree.BlockStatement, parentNode: ESTree.Node): ESTree.Node { + public transformNode(blockStatementNode: ESTree.BlockStatement, parentNode: ESTree.Node): ESTree.Node { if ( this.randomGenerator.getMathRandom() > this.options.controlFlowFlatteningThreshold || !BlockStatementControlFlowTransformer.canTransformBlockStatementNode(blockStatementNode) @@ -136,9 +138,12 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme const blockStatementBody: ESTree.Statement[] = blockStatementNode.body; const originalKeys: number[] = this.arrayUtils.createWithRange(blockStatementBody.length); const shuffledKeys: number[] = this.arrayUtils.shuffle(originalKeys); - const originalKeysIndexesInShuffledArray: number[] = originalKeys.map((key: number) => shuffledKeys.indexOf(key)); - const blockStatementControlFlowFlatteningCustomNode: ICustomNode> = - this.controlFlowCustomNodeFactory(ControlFlowCustomNode.BlockStatementControlFlowFlatteningNode); + const originalKeysIndexesInShuffledArray: number[] = originalKeys.map((key: number) => + shuffledKeys.indexOf(key) + ); + const blockStatementControlFlowFlatteningCustomNode: ICustomNode< + TInitialData + > = this.controlFlowCustomNodeFactory(ControlFlowCustomNode.BlockStatementControlFlowFlatteningNode); blockStatementControlFlowFlatteningCustomNode.initialize( blockStatementBody, diff --git a/src/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.ts b/src/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.ts index 1e656219b..362317f03 100644 --- a/src/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.ts +++ b/src/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -7,9 +7,7 @@ import * as ESTree from 'estree'; import { TControlFlowCustomNodeFactory } from '../../types/container/custom-nodes/TControlFlowCustomNodeFactory'; import { TControlFlowReplacerFactory } from '../../types/container/node-transformers/TControlFlowReplacerFactory'; import { TControlFlowStorageFactory } from '../../types/container/node-transformers/TControlFlowStorageFactory'; -import { - TControlFlowStorageFactoryCreator -} from '../../types/container/node-transformers/TControlFlowStorageFactoryCreator'; +import { TControlFlowStorageFactoryCreator } from '../../types/container/node-transformers/TControlFlowStorageFactoryCreator'; import { TInitialData } from '../../types/TInitialData'; import { TNodeWithStatements } from '../../types/node/TNodeWithStatements'; @@ -20,17 +18,13 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; import { IVisitor } from '../../interfaces/node-transformers/IVisitor'; import { ControlFlowCustomNode } from '../../enums/custom-nodes/ControlFlowCustomNode'; -import { - ControlFlowReplacer -} from '../../enums/node-transformers/control-flow-transformers/control-flow-replacers/ControlFlowReplacer'; +import { ControlFlowReplacer } from '../../enums/node-transformers/control-flow-transformers/control-flow-replacers/ControlFlowReplacer'; import { ControlFlowStorage } from '../../enums/storages/ControlFlowStorage'; import { NodeType } from '../../enums/node/NodeType'; import { NodeTransformationStage } from '../../enums/node-transformers/NodeTransformationStage'; import { AbstractNodeTransformer } from '../AbstractNodeTransformer'; -import { - ControlFlowStorageNode -} from '../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode'; +import { ControlFlowStorageNode } from '../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode'; import { NodeAppender } from '../../node/NodeAppender'; import { NodeGuards } from '../../node/NodeGuards'; import { NodeMetadata } from '../../node/NodeMetadata'; @@ -52,7 +46,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { /** * @type {Map } */ - protected readonly controlFlowReplacersMap: Map = new Map([ + protected readonly controlFlowReplacersMap: Map = new Map([ [NodeType.BinaryExpression, ControlFlowReplacer.BinaryExpressionControlFlowReplacer], [NodeType.CallExpression, ControlFlowReplacer.CallExpressionControlFlowReplacer], [NodeType.LogicalExpression, ControlFlowReplacer.LogicalExpressionControlFlowReplacer], @@ -62,12 +56,13 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { /** * @type {WeakMap} */ - protected readonly controlFlowData: WeakMap = new WeakMap(); + protected readonly controlFlowData: WeakMap = new WeakMap(); /** * @type {WeakMap} */ - protected readonly hostNodesWithControlFlowNode: WeakMap = new WeakMap(); + protected readonly hostNodesWithControlFlowNode: WeakMap = + new WeakMap(); /** * @type {TControlFlowReplacerFactory} @@ -96,19 +91,21 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__TControlFlowStorage) - controlFlowStorageFactoryCreator: TControlFlowStorageFactoryCreator, + controlFlowStorageFactoryCreator: TControlFlowStorageFactoryCreator, @inject(ServiceIdentifiers.Factory__IControlFlowReplacer) - controlFlowReplacerFactory: TControlFlowReplacerFactory, + controlFlowReplacerFactory: TControlFlowReplacerFactory, @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { super(randomGenerator, options); - this.controlFlowStorageFactory = controlFlowStorageFactoryCreator(ControlFlowStorage.FunctionControlFlowStorage); + this.controlFlowStorageFactory = controlFlowStorageFactoryCreator( + ControlFlowStorage.FunctionControlFlowStorage + ); this.controlFlowReplacerFactory = controlFlowReplacerFactory; this.controlFlowCustomNodeFactory = controlFlowCustomNodeFactory; } @@ -117,7 +114,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { if (!this.options.controlFlowFlattening) { return null; } @@ -145,7 +142,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {Function} */ - public transformNode (functionNode: ESTree.Function, parentNode: ESTree.Node): ESTree.Function { + public transformNode(functionNode: ESTree.Function, parentNode: ESTree.Node): ESTree.Function { this.visitedFunctionNodes.add(functionNode); if (!NodeGuards.isBlockStatementNode(functionNode.body)) { @@ -172,7 +169,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {BlockStatement} functionNode * @param {IControlFlowStorage} controlFlowStorage */ - protected transformFunctionBody (functionNode: ESTree.Function, controlFlowStorage: IControlFlowStorage): void { + protected transformFunctionBody(functionNode: ESTree.Function, controlFlowStorage: IControlFlowStorage): void { estraverse.replace(functionNode.body, { enter: (node: ESTree.Node, parentNode: ESTree.Node | null): estraverse.VisitorOption | ESTree.Node => this.transformFunctionBodyNode(node, parentNode, functionNode, controlFlowStorage) @@ -186,22 +183,19 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {IControlFlowStorage} controlFlowStorage * @returns {ESTraverse.VisitorOption | Node} */ - protected transformFunctionBodyNode ( + protected transformFunctionBodyNode( node: ESTree.Node, parentNode: ESTree.Node | null, functionNode: ESTree.Function, controlFlowStorage: IControlFlowStorage ): estraverse.VisitorOption | ESTree.Node { - const shouldSkipTraverse = !parentNode - || NodeMetadata.isIgnoredNode(node) - || this.isVisitedFunctionNode(node); + const shouldSkipTraverse = !parentNode || NodeMetadata.isIgnoredNode(node) || this.isVisitedFunctionNode(node); if (shouldSkipTraverse) { return estraverse.VisitorOption.Skip; } - const controlFlowReplacerName: ControlFlowReplacer | null = this.controlFlowReplacersMap.get(node.type) - ?? null; + const controlFlowReplacerName: ControlFlowReplacer | null = this.controlFlowReplacersMap.get(node.type) ?? null; if (!controlFlowReplacerName) { return node; @@ -211,12 +205,11 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { return node; } - const replacedNode: ESTree.Node = this.controlFlowReplacerFactory(controlFlowReplacerName) - .replace( - node, - parentNode, - controlFlowStorage - ); + const replacedNode: ESTree.Node = this.controlFlowReplacerFactory(controlFlowReplacerName).replace( + node, + parentNode, + controlFlowStorage + ); NodeUtils.parentizeNode(replacedNode, parentNode); @@ -227,8 +220,9 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {BlockStatement} functionNodeBody * @returns {TNodeWithStatements} */ - protected getHostNode (functionNodeBody: ESTree.BlockStatement): TNodeWithStatements { - const blockScopesOfNode: TNodeWithStatements[] = NodeStatementUtils.getParentNodesWithStatements(functionNodeBody); + protected getHostNode(functionNodeBody: ESTree.BlockStatement): TNodeWithStatements { + const blockScopesOfNode: TNodeWithStatements[] = + NodeStatementUtils.getParentNodesWithStatements(functionNodeBody); if (blockScopesOfNode.length === 1) { return functionNodeBody; @@ -251,7 +245,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {TNodeWithStatements} hostNode * @returns {TControlFlowStorage} */ - protected getControlFlowStorage (hostNode: TNodeWithStatements): IControlFlowStorage { + protected getControlFlowStorage(hostNode: TNodeWithStatements): IControlFlowStorage { let controlFlowStorage: IControlFlowStorage; const hostControlFlowStorage: IControlFlowStorage | null = this.controlFlowData.get(hostNode) ?? null; @@ -278,7 +272,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {IControlFlowStorage} controlFlowStorage * @returns {VariableDeclaration} */ - protected getControlFlowStorageNode (controlFlowStorage: IControlFlowStorage): ESTree.VariableDeclaration { + protected getControlFlowStorageNode(controlFlowStorage: IControlFlowStorage): ESTree.VariableDeclaration { const controlFlowStorageCustomNode: ICustomNode> = this.controlFlowCustomNodeFactory(ControlFlowCustomNode.ControlFlowStorageNode); @@ -287,7 +281,9 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { const controlFlowStorageNode: ESTree.Node = controlFlowStorageCustomNode.getNode()[0]; if (!NodeGuards.isVariableDeclarationNode(controlFlowStorageNode)) { - throw new Error('`controlFlowStorageNode` should contain `VariableDeclaration` node with control flow storage object'); + throw new Error( + '`controlFlowStorageNode` should contain `VariableDeclaration` node with control flow storage object' + ); } return controlFlowStorageNode; @@ -297,7 +293,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {TNodeWithStatements} hostNode * @param {VariableDeclaration} controlFlowStorageNode */ - protected appendControlFlowStorageNode ( + protected appendControlFlowStorageNode( hostNode: TNodeWithStatements, controlFlowStorageNode: ESTree.VariableDeclaration ): void { @@ -311,14 +307,14 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { * @param {NodeGuards} node * @returns {boolean} */ - protected isVisitedFunctionNode (node: ESTree.Node): boolean { + protected isVisitedFunctionNode(node: ESTree.Node): boolean { return NodeGuards.isFunctionNode(node) && this.visitedFunctionNodes.has(node); } /** * @returns {boolean} */ - protected isAllowedTransformationByThreshold (): boolean { + protected isAllowedTransformationByThreshold(): boolean { return this.randomGenerator.getMathRandom() <= this.options.controlFlowFlatteningThreshold; } } diff --git a/src/node-transformers/control-flow-transformers/StringArrayControlFlowTransformer.ts b/src/node-transformers/control-flow-transformers/StringArrayControlFlowTransformer.ts index ab9cd7b38..0de2115a9 100644 --- a/src/node-transformers/control-flow-transformers/StringArrayControlFlowTransformer.ts +++ b/src/node-transformers/control-flow-transformers/StringArrayControlFlowTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -6,9 +6,7 @@ import * as ESTree from 'estree'; import { TControlFlowCustomNodeFactory } from '../../types/container/custom-nodes/TControlFlowCustomNodeFactory'; import { TControlFlowReplacerFactory } from '../../types/container/node-transformers/TControlFlowReplacerFactory'; -import { - TControlFlowStorageFactoryCreator -} from '../../types/container/node-transformers/TControlFlowStorageFactoryCreator'; +import { TControlFlowStorageFactoryCreator } from '../../types/container/node-transformers/TControlFlowStorageFactoryCreator'; import { TNodeWithStatements } from '../../types/node/TNodeWithStatements'; import { IControlFlowStorage } from '../../interfaces/storages/control-flow-transformers/IControlFlowStorage'; @@ -39,7 +37,7 @@ export class StringArrayControlFlowTransformer extends FunctionControlFlowTransf /** * @type {Map } */ - protected override readonly controlFlowReplacersMap: Map = new Map([ + protected override readonly controlFlowReplacersMap: Map = new Map([ [NodeType.Literal, ControlFlowReplacer.StringArrayCallControlFlowReplacer] ]); @@ -55,13 +53,13 @@ export class StringArrayControlFlowTransformer extends FunctionControlFlowTransf * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__TControlFlowStorage) - controlFlowStorageFactoryCreator: TControlFlowStorageFactoryCreator, + controlFlowStorageFactoryCreator: TControlFlowStorageFactoryCreator, @inject(ServiceIdentifiers.Factory__IControlFlowReplacer) - controlFlowReplacerFactory: TControlFlowReplacerFactory, + controlFlowReplacerFactory: TControlFlowReplacerFactory, @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -80,7 +78,7 @@ export class StringArrayControlFlowTransformer extends FunctionControlFlowTransf * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public override getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public override getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { if (!this.options.stringArrayCallsTransform) { return null; } @@ -110,14 +108,14 @@ export class StringArrayControlFlowTransformer extends FunctionControlFlowTransf * @param {IControlFlowStorage} controlFlowStorage * @returns {ESTraverse.VisitorOption | Node} */ - protected override transformFunctionBodyNode ( + protected override transformFunctionBodyNode( node: ESTree.Node, parentNode: ESTree.Node | null, functionNode: ESTree.Function, controlFlowStorage: IControlFlowStorage ): estraverse.VisitorOption | ESTree.Node { - const isControlFlowStorageNode = NodeGuards.isVariableDeclarationNode(node) - && this.controlFlowStorageNodes.has(node); + const isControlFlowStorageNode = + NodeGuards.isVariableDeclarationNode(node) && this.controlFlowStorageNodes.has(node); if (isControlFlowStorageNode) { return estraverse.VisitorOption.Skip; @@ -130,7 +128,7 @@ export class StringArrayControlFlowTransformer extends FunctionControlFlowTransf * @param {TNodeWithStatements} hostNode * @returns {TControlFlowStorage} */ - protected override getControlFlowStorage (hostNode: TNodeWithStatements): IControlFlowStorage { + protected override getControlFlowStorage(hostNode: TNodeWithStatements): IControlFlowStorage { return this.controlFlowStorageFactory(); } @@ -138,7 +136,7 @@ export class StringArrayControlFlowTransformer extends FunctionControlFlowTransf * @param {TNodeWithStatements} hostNode * @param {VariableDeclaration} controlFlowStorageNode */ - protected override appendControlFlowStorageNode ( + protected override appendControlFlowStorageNode( hostNode: TNodeWithStatements, controlFlowStorageNode: ESTree.VariableDeclaration ): void { @@ -150,7 +148,7 @@ export class StringArrayControlFlowTransformer extends FunctionControlFlowTransf /** * @returns {boolean} */ - protected override isAllowedTransformationByThreshold (): boolean { + protected override isAllowedTransformationByThreshold(): boolean { return this.randomGenerator.getMathRandom() <= this.options.stringArrayCallsTransformThreshold; } } diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts index fde1f972e..e26e2fee1 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -38,7 +38,7 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace /** * @type {Map>} */ - protected readonly replacerDataByControlFlowStorageId: Map > = new Map(); + protected readonly replacerDataByControlFlowStorageId: Map> = new Map(); /** * @param {TControlFlowCustomNodeFactory} controlFlowCustomNodeFactory @@ -46,11 +46,11 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -67,7 +67,7 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace * @param {IControlFlowStorage} controlFlowStorage * @returns {string} */ - public generateStorageKey (controlFlowStorage: IControlFlowStorage): string { + public generateStorageKey(controlFlowStorage: IControlFlowStorage): string { const key: string = this.randomGenerator.getRandomString(5); if (controlFlowStorage.has(key)) { @@ -84,19 +84,19 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace * @param {number} usingExistingIdentifierChance * @returns {string} */ - protected insertCustomNodeToControlFlowStorage ( + protected insertCustomNodeToControlFlowStorage( customNode: ICustomNode, controlFlowStorage: IControlFlowStorage, replacerId: string | number, usingExistingIdentifierChance: number ): string { const controlFlowStorageId: string = controlFlowStorage.getStorageId(); - const storageKeysById: Map = this.replacerDataByControlFlowStorageId.get(controlFlowStorageId) - ?? new Map (); + const storageKeysById: Map = + this.replacerDataByControlFlowStorageId.get(controlFlowStorageId) ?? new Map(); const storageKeysForCurrentId: string[] = storageKeysById.get(replacerId) ?? []; - const shouldPickFromStorageKeysById = this.randomGenerator.getMathRandom() < usingExistingIdentifierChance - && storageKeysForCurrentId.length; + const shouldPickFromStorageKeysById = + this.randomGenerator.getMathRandom() < usingExistingIdentifierChance && storageKeysForCurrentId.length; if (shouldPickFromStorageKeysById) { return this.randomGenerator.getRandomGenerator().pickone(storageKeysForCurrentId); @@ -119,7 +119,7 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace * @param {IControlFlowStorage} controlFlowStorage * @returns {Node} */ - public abstract replace ( + public abstract replace( node: ESTree.Node, parentNode: ESTree.Node, controlFlowStorage: IControlFlowStorage diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.ts index d92e2a53f..af926ae08 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -30,20 +30,15 @@ export class BinaryExpressionControlFlowReplacer extends ExpressionWithOperatorC * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - controlFlowCustomNodeFactory, - identifierNamesGeneratorFactory, - randomGenerator, - options - ); + super(controlFlowCustomNodeFactory, identifierNamesGeneratorFactory, randomGenerator, options); } /** @@ -53,7 +48,7 @@ export class BinaryExpressionControlFlowReplacer extends ExpressionWithOperatorC * @param {IControlFlowStorage} controlFlowStorage * @returns {Node} */ - public replace ( + public replace( binaryExpressionNode: ESTree.BinaryExpression, parentNode: ESTree.Node, controlFlowStorage: IControlFlowStorage diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.ts index 17e2bf4d0..e6362c81e 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -33,20 +33,15 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - controlFlowCustomNodeFactory, - identifierNamesGeneratorFactory, - randomGenerator, - options - ); + super(controlFlowCustomNodeFactory, identifierNamesGeneratorFactory, randomGenerator, options); } /** @@ -55,7 +50,7 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac * @param {IControlFlowStorage} controlFlowStorage * @returns {Node} */ - public replace ( + public replace( callExpressionNode: ESTree.CallExpression, parentNode: ESTree.Node, controlFlowStorage: IControlFlowStorage @@ -86,7 +81,7 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac controlFlowStorage.getStorageId(), storageKey, callee, - expressionArguments, + expressionArguments ); } @@ -97,7 +92,7 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac * @param {(Expression | SpreadElement)[]} expressionArguments * @returns {NodeGuards} */ - protected getControlFlowStorageCallNode ( + protected getControlFlowStorageCallNode( controlFlowStorageId: string, storageKey: string, callee: ESTree.Expression, @@ -111,7 +106,9 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac const statementNode: TStatement = controlFlowStorageCallCustomNode.getNode()[0]; if (!statementNode || !NodeGuards.isExpressionStatementNode(statementNode)) { - throw new Error('`controlFlowStorageCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node'); + throw new Error( + '`controlFlowStorageCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node' + ); } return statementNode.expression; diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/ExpressionWithOperatorControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/ExpressionWithOperatorControlFlowReplacer.ts index 88e5129f6..be9604ff8 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/ExpressionWithOperatorControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/ExpressionWithOperatorControlFlowReplacer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -26,20 +26,15 @@ export abstract class ExpressionWithOperatorControlFlowReplacer extends Abstract * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - controlFlowCustomNodeFactory, - identifierNamesGeneratorFactory, - randomGenerator, - options - ); + super(controlFlowCustomNodeFactory, identifierNamesGeneratorFactory, randomGenerator, options); } /** @@ -49,21 +44,24 @@ export abstract class ExpressionWithOperatorControlFlowReplacer extends Abstract * @param {Expression} rightExpression * @returns {NodeGuards} */ - protected getControlFlowStorageCallNode ( + protected getControlFlowStorageCallNode( controlFlowStorageId: string, storageKey: string, leftExpression: ESTree.Expression, rightExpression: ESTree.Expression ): ESTree.Node { - const controlFlowStorageCallCustomNode: ICustomNode> = - this.controlFlowCustomNodeFactory(ControlFlowCustomNode.ExpressionWithOperatorControlFlowStorageCallNode); + const controlFlowStorageCallCustomNode: ICustomNode< + TInitialData + > = this.controlFlowCustomNodeFactory(ControlFlowCustomNode.ExpressionWithOperatorControlFlowStorageCallNode); controlFlowStorageCallCustomNode.initialize(controlFlowStorageId, storageKey, leftExpression, rightExpression); const statementNode: TStatement = controlFlowStorageCallCustomNode.getNode()[0]; if (!statementNode || !NodeGuards.isExpressionStatementNode(statementNode)) { - throw new Error('`controlFlowStorageCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node'); + throw new Error( + '`controlFlowStorageCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node' + ); } return statementNode.expression; diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.ts index ef24c3a69..d77f1c60d 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -32,20 +32,15 @@ export class LogicalExpressionControlFlowReplacer extends ExpressionWithOperator * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - controlFlowCustomNodeFactory, - identifierNamesGeneratorFactory, - randomGenerator, - options - ); + super(controlFlowCustomNodeFactory, identifierNamesGeneratorFactory, randomGenerator, options); } /** @@ -54,7 +49,7 @@ export class LogicalExpressionControlFlowReplacer extends ExpressionWithOperator * @param {IControlFlowStorage} controlFlowStorage * @returns {Node} */ - public replace ( + public replace( logicalExpressionNode: ESTree.LogicalExpression, parentNode: ESTree.Node, controlFlowStorage: IControlFlowStorage @@ -89,7 +84,10 @@ export class LogicalExpressionControlFlowReplacer extends ExpressionWithOperator * @param {Expression} rightExpression * @returns {boolean} */ - private checkForProhibitedExpressions (leftExpression: ESTree.Expression, rightExpression: ESTree.Expression): boolean { + private checkForProhibitedExpressions( + leftExpression: ESTree.Expression, + rightExpression: ESTree.Expression + ): boolean { return [leftExpression, rightExpression].some((expressionNode: ESTree.Node | ESTree.Expression): boolean => { let nodeForCheck: ESTree.Node | ESTree.Expression; @@ -99,10 +97,12 @@ export class LogicalExpressionControlFlowReplacer extends ExpressionWithOperator nodeForCheck = NodeUtils.getUnaryExpressionArgumentNode(expressionNode); } - return !NodeGuards.isLiteralNode(nodeForCheck) && + return ( + !NodeGuards.isLiteralNode(nodeForCheck) && !NodeGuards.isIdentifierNode(nodeForCheck) && !NodeGuards.isObjectExpressionNode(nodeForCheck) && - !NodeGuards.isExpressionStatementNode(nodeForCheck); + !NodeGuards.isExpressionStatementNode(nodeForCheck) + ); }); } } diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/StringArrayCallControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/StringArrayCallControlFlowReplacer.ts index 0c90ec330..ea5340056 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/StringArrayCallControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/StringArrayCallControlFlowReplacer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -19,9 +19,7 @@ import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer'; import { NodeGuards } from '../../../node/NodeGuards'; import { NodeLiteralUtils } from '../../../node/NodeLiteralUtils'; import { NodeMetadata } from '../../../node/NodeMetadata'; -import { - StringLiteralControlFlowStorageCallNode -} from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode'; +import { StringLiteralControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode'; import { LiteralNode } from '../../../custom-nodes/control-flow-flattening-nodes/LiteralNode'; @injectable() @@ -37,20 +35,15 @@ export class StringArrayCallControlFlowReplacer extends AbstractControlFlowRepla * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - controlFlowCustomNodeFactory, - identifierNamesGeneratorFactory, - randomGenerator, - options - ); + super(controlFlowCustomNodeFactory, identifierNamesGeneratorFactory, randomGenerator, options); } /** @@ -59,24 +52,23 @@ export class StringArrayCallControlFlowReplacer extends AbstractControlFlowRepla * @param {IControlFlowStorage} controlFlowStorage * @returns {Node} */ - public override replace ( + public override replace( literalNode: ESTree.Literal, parentNode: ESTree.Node, controlFlowStorage: IControlFlowStorage ): ESTree.Node { - const isStringArrayCallLiteralNode = NodeMetadata.isStringArrayCallLiteralNode(literalNode) - && ( - NodeLiteralUtils.isNumberLiteralNode(literalNode) - || NodeLiteralUtils.isStringLiteralNode(literalNode) - ); + const isStringArrayCallLiteralNode = + NodeMetadata.isStringArrayCallLiteralNode(literalNode) && + (NodeLiteralUtils.isNumberLiteralNode(literalNode) || NodeLiteralUtils.isStringLiteralNode(literalNode)); if (!isStringArrayCallLiteralNode) { return literalNode; } const replacerId: string | number = literalNode.value; - const literalCustomNode: ICustomNode> = - this.controlFlowCustomNodeFactory(ControlFlowCustomNode.LiteralNode); + const literalCustomNode: ICustomNode> = this.controlFlowCustomNodeFactory( + ControlFlowCustomNode.LiteralNode + ); literalCustomNode.initialize(literalNode); @@ -96,9 +88,8 @@ export class StringArrayCallControlFlowReplacer extends AbstractControlFlowRepla * @param {IControlFlowStorage} controlFlowStorage * @returns {string} */ - public override generateStorageKey (controlFlowStorage: IControlFlowStorage): string { - const key: string = this.identifierNamesGenerator - .generateForLabel(controlFlowStorage.getStorageId()); + public override generateStorageKey(controlFlowStorage: IControlFlowStorage): string { + const key: string = this.identifierNamesGenerator.generateForLabel(controlFlowStorage.getStorageId()); if (controlFlowStorage.has(key)) { return this.generateStorageKey(controlFlowStorage); @@ -112,10 +103,7 @@ export class StringArrayCallControlFlowReplacer extends AbstractControlFlowRepla * @param {string} storageKey * @returns {NodeGuards} */ - protected getControlFlowStorageCallNode ( - controlFlowStorageId: string, - storageKey: string - ): ESTree.Node { + protected getControlFlowStorageCallNode(controlFlowStorageId: string, storageKey: string): ESTree.Node { const controlFlowStorageCallCustomNode: ICustomNode> = this.controlFlowCustomNodeFactory(ControlFlowCustomNode.StringLiteralControlFlowStorageCallNode); @@ -124,7 +112,9 @@ export class StringArrayCallControlFlowReplacer extends AbstractControlFlowRepla const statementNode: TStatement = controlFlowStorageCallCustomNode.getNode()[0]; if (!statementNode || !NodeGuards.isExpressionStatementNode(statementNode)) { - throw new Error('`controlFlowStorageCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node'); + throw new Error( + '`controlFlowStorageCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node' + ); } return statementNode.expression; diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/StringLiteralControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/StringLiteralControlFlowReplacer.ts index 9ed65afac..f4de203ee 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/StringLiteralControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/StringLiteralControlFlowReplacer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -34,20 +34,15 @@ export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplace * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IControlFlowCustomNode) - controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, + controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super( - controlFlowCustomNodeFactory, - identifierNamesGeneratorFactory, - randomGenerator, - options - ); + super(controlFlowCustomNodeFactory, identifierNamesGeneratorFactory, randomGenerator, options); } /** @@ -56,7 +51,7 @@ export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplace * @param {IControlFlowStorage} controlFlowStorage * @returns {Node} */ - public replace ( + public replace( literalNode: ESTree.Literal, parentNode: ESTree.Node, controlFlowStorage: IControlFlowStorage @@ -70,8 +65,9 @@ export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplace } const replacerId: string = literalNode.value; - const literalCustomNode: ICustomNode> = - this.controlFlowCustomNodeFactory(ControlFlowCustomNode.LiteralNode); + const literalCustomNode: ICustomNode> = this.controlFlowCustomNodeFactory( + ControlFlowCustomNode.LiteralNode + ); literalCustomNode.initialize(literalNode); @@ -90,10 +86,7 @@ export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplace * @param {string} storageKey * @returns {NodeGuards} */ - protected getControlFlowStorageCallNode ( - controlFlowStorageId: string, - storageKey: string - ): ESTree.Node { + protected getControlFlowStorageCallNode(controlFlowStorageId: string, storageKey: string): ESTree.Node { const controlFlowStorageCallCustomNode: ICustomNode> = this.controlFlowCustomNodeFactory(ControlFlowCustomNode.StringLiteralControlFlowStorageCallNode); @@ -102,7 +95,9 @@ export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplace const statementNode: TStatement = controlFlowStorageCallCustomNode.getNode()[0]; if (!statementNode || !NodeGuards.isExpressionStatementNode(statementNode)) { - throw new Error('`controlFlowStorageCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node'); + throw new Error( + '`controlFlowStorageCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node' + ); } return statementNode.expression; diff --git a/src/node-transformers/converting-transformers/BooleanLiteralTransformer.ts b/src/node-transformers/converting-transformers/BooleanLiteralTransformer.ts index ba09a60e9..f1bc652bc 100644 --- a/src/node-transformers/converting-transformers/BooleanLiteralTransformer.ts +++ b/src/node-transformers/converting-transformers/BooleanLiteralTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -20,7 +20,7 @@ export class BooleanLiteralTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -31,7 +31,7 @@ export class BooleanLiteralTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Converting: return { @@ -60,7 +60,7 @@ export class BooleanLiteralTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { + public transformNode(literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { if (typeof literalNode.value !== 'boolean') { return literalNode; } @@ -79,20 +79,14 @@ export class BooleanLiteralTransformer extends AbstractNodeTransformer { /** * @return {ESTree.UnaryExpression} */ - private getTrueUnaryExpressionNode (): ESTree.UnaryExpression { - return NodeFactory.unaryExpressionNode( - '!', - this.getFalseUnaryExpressionNode() - ); + private getTrueUnaryExpressionNode(): ESTree.UnaryExpression { + return NodeFactory.unaryExpressionNode('!', this.getFalseUnaryExpressionNode()); } /** * @return {ESTree.UnaryExpression} */ - private getFalseUnaryExpressionNode (): ESTree.UnaryExpression { - return NodeFactory.unaryExpressionNode( - '!', - NodeFactory.arrayExpressionNode() - ); + private getFalseUnaryExpressionNode(): ESTree.UnaryExpression { + return NodeFactory.unaryExpressionNode('!', NodeFactory.arrayExpressionNode()); } } diff --git a/src/node-transformers/converting-transformers/ClassFieldTransformer.ts b/src/node-transformers/converting-transformers/ClassFieldTransformer.ts index dba2ad1e5..a8ef3ac58 100644 --- a/src/node-transformers/converting-transformers/ClassFieldTransformer.ts +++ b/src/node-transformers/converting-transformers/ClassFieldTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -39,7 +39,7 @@ export class ClassFieldTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -50,17 +50,14 @@ export class ClassFieldTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Converting: return { enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => { if ( - parentNode - && ( - NodeGuards.isMethodDefinitionNode(node) - || NodeGuards.isPropertyDefinitionNode(node) - ) + parentNode && + (NodeGuards.isMethodDefinitionNode(node) || NodeGuards.isPropertyDefinitionNode(node)) ) { return this.transformNode(node, parentNode); } @@ -77,7 +74,7 @@ export class ClassFieldTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode ( + public transformNode( classFieldNode: ESTree.MethodDefinition | ESTree.PropertyDefinition, parentNode: ESTree.Node ): ESTree.Node { @@ -97,14 +94,11 @@ export class ClassFieldTransformer extends AbstractNodeTransformer { * @param {Identifier} keyNode * @returns {MethodDefinition | PropertyDefinition} */ - private replaceIdentifierKey ( + private replaceIdentifierKey( classFieldNode: ESTree.MethodDefinition | ESTree.PropertyDefinition, keyNode: ESTree.Identifier ): ESTree.MethodDefinition | ESTree.PropertyDefinition { - if ( - !ClassFieldTransformer.ignoredNames.includes(keyNode.name) - && !classFieldNode.computed - ) { + if (!ClassFieldTransformer.ignoredNames.includes(keyNode.name) && !classFieldNode.computed) { classFieldNode.computed = true; classFieldNode.key = NodeFactory.literalNode(keyNode.name); } @@ -117,14 +111,14 @@ export class ClassFieldTransformer extends AbstractNodeTransformer { * @param {Literal} keyNode * @returns {MethodDefinition | PropertyDefinition} */ - private replaceLiteralKey ( + private replaceLiteralKey( classFieldNode: ESTree.MethodDefinition | ESTree.PropertyDefinition, keyNode: ESTree.Literal ): ESTree.MethodDefinition | ESTree.PropertyDefinition { if ( - typeof keyNode.value === 'string' - && !ClassFieldTransformer.ignoredNames.includes(keyNode.value) - && !classFieldNode.computed + typeof keyNode.value === 'string' && + !ClassFieldTransformer.ignoredNames.includes(keyNode.value) && + !classFieldNode.computed ) { classFieldNode.computed = true; } diff --git a/src/node-transformers/converting-transformers/ExportSpecifierTransformer.ts b/src/node-transformers/converting-transformers/ExportSpecifierTransformer.ts index 16a85332b..fd49aad2c 100644 --- a/src/node-transformers/converting-transformers/ExportSpecifierTransformer.ts +++ b/src/node-transformers/converting-transformers/ExportSpecifierTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -19,7 +19,7 @@ export class ExportSpecifierTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -30,7 +30,7 @@ export class ExportSpecifierTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Converting: return { @@ -57,7 +57,7 @@ export class ExportSpecifierTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {Node} */ - public transformNode (exportSpecifierNode: ESTree.ExportSpecifier, parentNode: ESTree.Node): ESTree.Node { + public transformNode(exportSpecifierNode: ESTree.ExportSpecifier, parentNode: ESTree.Node): ESTree.Node { if (exportSpecifierNode.local.name === exportSpecifierNode.exported.name) { exportSpecifierNode.exported = NodeUtils.clone(exportSpecifierNode.local); } diff --git a/src/node-transformers/converting-transformers/MemberExpressionTransformer.ts b/src/node-transformers/converting-transformers/MemberExpressionTransformer.ts index 731244995..bf1e9cd6f 100644 --- a/src/node-transformers/converting-transformers/MemberExpressionTransformer.ts +++ b/src/node-transformers/converting-transformers/MemberExpressionTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -20,7 +20,7 @@ export class MemberExpressionTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -31,7 +31,7 @@ export class MemberExpressionTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Converting: return { @@ -63,8 +63,11 @@ export class MemberExpressionTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (memberExpressionNode: ESTree.MemberExpression, parentNode: ESTree.Node): ESTree.Node { - if (NodeMetadata.isIgnoredNode(memberExpressionNode.object) || NodeMetadata.isIgnoredNode(memberExpressionNode.property)) { + public transformNode(memberExpressionNode: ESTree.MemberExpression, parentNode: ESTree.Node): ESTree.Node { + if ( + NodeMetadata.isIgnoredNode(memberExpressionNode.object) || + NodeMetadata.isIgnoredNode(memberExpressionNode.property) + ) { return memberExpressionNode; } diff --git a/src/node-transformers/converting-transformers/NumberLiteralTransformer.ts b/src/node-transformers/converting-transformers/NumberLiteralTransformer.ts index edf7e4ba2..cc84588c5 100644 --- a/src/node-transformers/converting-transformers/NumberLiteralTransformer.ts +++ b/src/node-transformers/converting-transformers/NumberLiteralTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -22,23 +22,19 @@ export class NumberLiteralTransformer extends AbstractNodeTransformer { * * @type {NodeTransformer[]} */ - public override readonly runAfter: NodeTransformer[] = [ - NodeTransformer.NumberToNumericalExpressionTransformer - ]; + public override readonly runAfter: NodeTransformer[] = [NodeTransformer.NumberToNumericalExpressionTransformer]; /** * @type {Map} */ - private readonly numberLiteralCache: Map < - ESTree.SimpleLiteral['value'] | ESTree.BigIntLiteral['value'], - string - > = new Map(); + private readonly numberLiteralCache: Map = + new Map(); /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -49,7 +45,7 @@ export class NumberLiteralTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Converting: return { @@ -76,7 +72,7 @@ export class NumberLiteralTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { + public transformNode(literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { if (typeof literalNode.value !== 'number' && typeof literalNode.value !== 'bigint') { return literalNode; } diff --git a/src/node-transformers/converting-transformers/NumberToNumericalExpressionTransformer.ts b/src/node-transformers/converting-transformers/NumberToNumericalExpressionTransformer.ts index 117f78fcf..8ceaa0bda 100644 --- a/src/node-transformers/converting-transformers/NumberToNumericalExpressionTransformer.ts +++ b/src/node-transformers/converting-transformers/NumberToNumericalExpressionTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -38,9 +38,9 @@ export class NumberToNumericalExpressionTransformer extends AbstractNodeTransfor * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.INumberNumericalExpressionAnalyzer) - numberNumericalExpressionAnalyzer: INumberNumericalExpressionAnalyzer, + numberNumericalExpressionAnalyzer: INumberNumericalExpressionAnalyzer, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -53,7 +53,7 @@ export class NumberToNumericalExpressionTransformer extends AbstractNodeTransfor * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { if (!this.options.numbersToExpressions) { return null; } @@ -78,7 +78,7 @@ export class NumberToNumericalExpressionTransformer extends AbstractNodeTransfor * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { + public transformNode(literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { if (typeof literalNode.value !== 'number') { return literalNode; } @@ -89,8 +89,8 @@ export class NumberToNumericalExpressionTransformer extends AbstractNodeTransfor const baseNumber: number = literalNode.value; const [integerPart, decimalPart] = NumberUtils.extractIntegerAndDecimalParts(baseNumber); - const integerNumberNumericalExpressionData: TNumberNumericalExpressionData = this.numberNumericalExpressionAnalyzer - .analyze( + const integerNumberNumericalExpressionData: TNumberNumericalExpressionData = + this.numberNumericalExpressionAnalyzer.analyze( integerPart, NumberNumericalExpressionAnalyzer.defaultAdditionalPartsCount ); @@ -114,14 +114,9 @@ export class NumberToNumericalExpressionTransformer extends AbstractNodeTransfor * @param {boolean} isPositiveNumber * @returns {Expression} */ - private getNumberNumericalExpressionLiteralNode (number: number, isPositiveNumber: boolean): ESTree.Expression { + private getNumberNumericalExpressionLiteralNode(number: number, isPositiveNumber: boolean): ESTree.Expression { const numberLiteralNode: ESTree.Literal = NodeFactory.literalNode(number); - return isPositiveNumber - ? numberLiteralNode - : NodeFactory.unaryExpressionNode( - '-', - numberLiteralNode - ); + return isPositiveNumber ? numberLiteralNode : NodeFactory.unaryExpressionNode('-', numberLiteralNode); } } diff --git a/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts b/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts index 20efc1d37..15ac0ae2b 100644 --- a/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts +++ b/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts @@ -42,9 +42,9 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IObjectExpressionExtractor) - objectExpressionExtractorFactory: TObjectExpressionExtractorFactory, + objectExpressionExtractorFactory: TObjectExpressionExtractorFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -59,33 +59,33 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { * @param {Statement} objectExpressionHostStatement * @returns {boolean} */ - private static isProhibitedObjectExpressionNode ( + private static isProhibitedObjectExpressionNode( objectExpressionNode: ESTree.ObjectExpression, objectExpressionParentNode: ESTree.Node, objectExpressionHostStatement: ESTree.Statement ): boolean { - return ObjectExpressionKeysTransformer.isReferencedIdentifierName( + return ( + ObjectExpressionKeysTransformer.isReferencedIdentifierName( objectExpressionNode, objectExpressionHostStatement - ) - || ObjectExpressionKeysTransformer.isProhibitedArrowFunctionExpression( + ) || + ObjectExpressionKeysTransformer.isProhibitedArrowFunctionExpression( objectExpressionNode, objectExpressionParentNode - ) - || ObjectExpressionKeysTransformer.isObjectExpressionWithCallExpression( - objectExpressionNode, - ) - || ObjectExpressionKeysTransformer.isProhibitedSequenceExpression( + ) || + ObjectExpressionKeysTransformer.isObjectExpressionWithCallExpression(objectExpressionNode) || + ObjectExpressionKeysTransformer.isProhibitedSequenceExpression( objectExpressionNode, objectExpressionHostStatement - ); + ) + ); } /** * @param {Identifier | ThisExpression} node * @returns {string} */ - private static getReferencedIdentifierName (node: ESTree.Identifier | ESTree.ThisExpression): string { + private static getReferencedIdentifierName(node: ESTree.Identifier | ESTree.ThisExpression): string { if (NodeGuards.isIdentifierNode(node)) { return node.name; } else { @@ -98,9 +98,9 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { * @param {Node} objectExpressionHostNode * @returns {boolean} */ - private static isReferencedIdentifierName ( + private static isReferencedIdentifierName( objectExpressionNode: ESTree.ObjectExpression, - objectExpressionHostNode: ESTree.Node, + objectExpressionHostNode: ESTree.Node ): boolean { const identifierNamesSet: Set = new Set(); @@ -151,25 +151,27 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { * @param {Node} objectExpressionNodeParentNode * @returns {boolean} */ - private static isProhibitedArrowFunctionExpression ( + private static isProhibitedArrowFunctionExpression( objectExpressionNode: ESTree.ObjectExpression, objectExpressionNodeParentNode: ESTree.Node ): boolean { - return NodeGuards.isArrowFunctionExpressionNode(objectExpressionNodeParentNode) - && objectExpressionNodeParentNode.body === objectExpressionNode; + return ( + NodeGuards.isArrowFunctionExpressionNode(objectExpressionNodeParentNode) && + objectExpressionNodeParentNode.body === objectExpressionNode + ); } /** * @param {ObjectExpression} objectExpressionNode * @returns {boolean} */ - private static isObjectExpressionWithCallExpression (objectExpressionNode: ESTree.ObjectExpression): boolean { + private static isObjectExpressionWithCallExpression(objectExpressionNode: ESTree.ObjectExpression): boolean { let isCallExpressionLikeNodeFound: boolean = false; estraverse.traverse(objectExpressionNode, { enter: (node: ESTree.Node): void | estraverse.VisitorOption => { - const isCallExpressionLikeNode = NodeGuards.isCallExpressionNode(node) - || NodeGuards.isNewExpressionNode(node); + const isCallExpressionLikeNode = + NodeGuards.isCallExpressionNode(node) || NodeGuards.isNewExpressionNode(node); if (!isCallExpressionLikeNode) { return; @@ -189,23 +191,25 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { * @param {Node} objectExpressionHostNode * @returns {boolean} */ - private static isProhibitedSequenceExpression ( + private static isProhibitedSequenceExpression( objectExpressionNode: ESTree.ObjectExpression, - objectExpressionHostNode: ESTree.Node, + objectExpressionHostNode: ESTree.Node ): boolean { - return NodeGuards.isExpressionStatementNode(objectExpressionHostNode) - && NodeGuards.isSequenceExpressionNode(objectExpressionHostNode.expression) - && objectExpressionHostNode.expression.expressions.some((expressionNode: ESTree.Expression) => - NodeGuards.isCallExpressionNode(expressionNode) - && NodeGuards.isSuperNode(expressionNode.callee) - ); + return ( + NodeGuards.isExpressionStatementNode(objectExpressionHostNode) && + NodeGuards.isSequenceExpressionNode(objectExpressionHostNode.expression) && + objectExpressionHostNode.expression.expressions.some( + (expressionNode: ESTree.Expression) => + NodeGuards.isCallExpressionNode(expressionNode) && NodeGuards.isSuperNode(expressionNode.callee) + ) + ); } /** * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { if (!this.options.transformObjectKeys) { return null; } @@ -214,10 +218,7 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { case NodeTransformationStage.Converting: return { leave: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => { - if ( - parentNode - && NodeGuards.isObjectExpressionNode(node) - ) { + if (parentNode && NodeGuards.isObjectExpressionNode(node)) { return this.transformNode(node, parentNode); } } @@ -245,18 +246,20 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {NodeGuards} */ - public transformNode (objectExpressionNode: ESTree.ObjectExpression, parentNode: ESTree.Node): ESTree.Node { + public transformNode(objectExpressionNode: ESTree.ObjectExpression, parentNode: ESTree.Node): ESTree.Node { if (!objectExpressionNode.properties.length) { return objectExpressionNode; } const hostStatement: ESTree.Statement = NodeStatementUtils.getRootStatementOfNode(objectExpressionNode); - if (ObjectExpressionKeysTransformer.isProhibitedObjectExpressionNode( - objectExpressionNode, - parentNode, - hostStatement - )) { + if ( + ObjectExpressionKeysTransformer.isProhibitedObjectExpressionNode( + objectExpressionNode, + parentNode, + hostStatement + ) + ) { return objectExpressionNode; } @@ -273,7 +276,7 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { * @param {Statement} hostStatement * @returns {Node} */ - private applyObjectExpressionKeysExtractorsRecursive ( + private applyObjectExpressionKeysExtractorsRecursive( objectExpressionExtractorNames: ObjectExpressionExtractor[], objectExpressionNode: ESTree.ObjectExpression, hostStatement: ESTree.Statement @@ -290,8 +293,10 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { nodeToReplace, objectExpressionHostStatement: newObjectExpressionHostStatement, objectExpressionNode: newObjectExpressionNode - } = this.objectExpressionExtractorFactory(objectExpressionExtractor) - .extract(objectExpressionNode, hostStatement); + } = this.objectExpressionExtractorFactory(objectExpressionExtractor).extract( + objectExpressionNode, + hostStatement + ); this.applyObjectExpressionKeysExtractorsRecursive( newObjectExpressionExtractorNames, diff --git a/src/node-transformers/converting-transformers/ObjectExpressionTransformer.ts b/src/node-transformers/converting-transformers/ObjectExpressionTransformer.ts index b6981d077..828c60dd9 100644 --- a/src/node-transformers/converting-transformers/ObjectExpressionTransformer.ts +++ b/src/node-transformers/converting-transformers/ObjectExpressionTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -26,7 +26,7 @@ export class ObjectExpressionTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -37,7 +37,7 @@ export class ObjectExpressionTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Converting: return { @@ -58,23 +58,22 @@ export class ObjectExpressionTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (objectExpressionNode: ESTree.ObjectExpression, parentNode: ESTree.Node): ESTree.Node { - objectExpressionNode.properties - .forEach((property: ESTree.Property | ESTree.SpreadElement) => { - if (!NodeGuards.isPropertyNode(property)) { - return; - } - - if (!property.key) { - return; - } - - if (property.computed) { - this.transformComputedProperty(property); - } else { - this.transformBaseProperty(property); - } - }); + public transformNode(objectExpressionNode: ESTree.ObjectExpression, parentNode: ESTree.Node): ESTree.Node { + objectExpressionNode.properties.forEach((property: ESTree.Property | ESTree.SpreadElement) => { + if (!NodeGuards.isPropertyNode(property)) { + return; + } + + if (!property.key) { + return; + } + + if (property.computed) { + this.transformComputedProperty(property); + } else { + this.transformBaseProperty(property); + } + }); return objectExpressionNode; } @@ -82,7 +81,7 @@ export class ObjectExpressionTransformer extends AbstractNodeTransformer { /** * @param {Property} property */ - private transformComputedProperty (property: ESTree.Property): void { + private transformComputedProperty(property: ESTree.Property): void { if (!NodeGuards.isLiteralNode(property.key) || !(typeof property.key.value === 'string')) { return; } @@ -93,7 +92,7 @@ export class ObjectExpressionTransformer extends AbstractNodeTransformer { /** * @param {Property} property */ - private transformBaseProperty (property: ESTree.Property): void { + private transformBaseProperty(property: ESTree.Property): void { if (property.shorthand) { property.shorthand = false; } diff --git a/src/node-transformers/converting-transformers/ObjectPatternPropertiesTransformer.ts b/src/node-transformers/converting-transformers/ObjectPatternPropertiesTransformer.ts index 690da5cea..d4a80e39e 100644 --- a/src/node-transformers/converting-transformers/ObjectPatternPropertiesTransformer.ts +++ b/src/node-transformers/converting-transformers/ObjectPatternPropertiesTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -22,7 +22,7 @@ export class ObjectPatternPropertiesTransformer extends AbstractNodeTransformer * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -33,7 +33,7 @@ export class ObjectPatternPropertiesTransformer extends AbstractNodeTransformer * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Converting: return { @@ -60,14 +60,15 @@ export class ObjectPatternPropertiesTransformer extends AbstractNodeTransformer * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (propertyNode: ESTree.Property, parentNode: ESTree.Node): ESTree.Node { + public transformNode(propertyNode: ESTree.Property, parentNode: ESTree.Node): ESTree.Node { if (!NodeGuards.isObjectPatternNode(parentNode) || !propertyNode.shorthand) { return propertyNode; } if (!this.options.renameGlobals) { const lexicalScope: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(propertyNode); - const shouldNotTransformGlobalPropertyNode: boolean = !!lexicalScope && NodeGuards.isProgramNode(lexicalScope); + const shouldNotTransformGlobalPropertyNode: boolean = + !!lexicalScope && NodeGuards.isProgramNode(lexicalScope); if (shouldNotTransformGlobalPropertyNode) { return propertyNode; diff --git a/src/node-transformers/converting-transformers/SplitStringTransformer.ts b/src/node-transformers/converting-transformers/SplitStringTransformer.ts index 8bf62e68e..2481cd35f 100644 --- a/src/node-transformers/converting-transformers/SplitStringTransformer.ts +++ b/src/node-transformers/converting-transformers/SplitStringTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -40,7 +40,7 @@ export class SplitStringTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -53,21 +53,13 @@ export class SplitStringTransformer extends AbstractNodeTransformer { * @param {number} chunkSize * @returns {string[]} */ - private static chunkString ( - string: string, - stringLength: number, - chunkSize: number - ): string[] { + private static chunkString(string: string, stringLength: number, chunkSize: number): string[] { const chunksCount: number = Math.ceil(stringLength / chunkSize); const chunks: string[] = []; let nextChunkStartIndex: number = 0; - for ( - let chunkIndex: number = 0; - chunkIndex < chunksCount; - ++chunkIndex, nextChunkStartIndex += chunkSize - ) { + for (let chunkIndex: number = 0; chunkIndex < chunksCount; ++chunkIndex, nextChunkStartIndex += chunkSize) { // eslint-disable-next-line unicorn/prefer-string-slice chunks[chunkIndex] = stringz.substr(string, nextChunkStartIndex, chunkSize); } @@ -79,7 +71,7 @@ export class SplitStringTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { if (!this.options.splitStrings) { return null; } @@ -107,7 +99,7 @@ export class SplitStringTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {Node} */ - public transformNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { + public transformNode(literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { if (NodeLiteralUtils.isProhibitedLiteralNode(literalNode, parentNode)) { return literalNode; } @@ -123,10 +115,7 @@ export class SplitStringTransformer extends AbstractNodeTransformer { // eslint-disable-next-line @typescript-eslint/no-shadow enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => { if (NodeGuards.isLiteralNode(node)) { - return this.transformLiteralNodeByChunkLength( - node, - this.options.splitStringsChunkLength - ); + return this.transformLiteralNodeByChunkLength(node, this.options.splitStringsChunkLength); } } }); @@ -142,10 +131,7 @@ export class SplitStringTransformer extends AbstractNodeTransformer { * @param {number} chunkLength * @returns {Node} */ - private transformLiteralNodeByChunkLength ( - literalNode: ESTree.Literal, - chunkLength: number - ): ESTree.Node { + private transformLiteralNodeByChunkLength(literalNode: ESTree.Literal, chunkLength: number): ESTree.Node { if (!NodeLiteralUtils.isStringLiteralNode(literalNode)) { return literalNode; } @@ -156,11 +142,7 @@ export class SplitStringTransformer extends AbstractNodeTransformer { return literalNode; } - const stringChunks: string[] = SplitStringTransformer.chunkString( - literalNode.value, - valueLength, - chunkLength - ); + const stringChunks: string[] = SplitStringTransformer.chunkString(literalNode.value, valueLength, chunkLength); return this.transformStringChunksToBinaryExpressionNode(stringChunks); } @@ -169,7 +151,7 @@ export class SplitStringTransformer extends AbstractNodeTransformer { * @param {string[]} chunks * @returns {BinaryExpression} */ - private transformStringChunksToBinaryExpressionNode (chunks: string[]): ESTree.BinaryExpression { + private transformStringChunksToBinaryExpressionNode(chunks: string[]): ESTree.BinaryExpression { const firstChunk: string | undefined = chunks.shift(); const secondChunk: string | undefined = chunks.shift(); @@ -187,11 +169,7 @@ export class SplitStringTransformer extends AbstractNodeTransformer { (binaryExpressionNode: ESTree.BinaryExpression, chunk: string) => { const chunkLiteralNode: ESTree.Literal = NodeFactory.literalNode(chunk); - return NodeFactory.binaryExpressionNode( - '+', - binaryExpressionNode, - chunkLiteralNode - ); + return NodeFactory.binaryExpressionNode('+', binaryExpressionNode, chunkLiteralNode); }, initialBinaryExpressionNode ); diff --git a/src/node-transformers/converting-transformers/TemplateLiteralTransformer.ts b/src/node-transformers/converting-transformers/TemplateLiteralTransformer.ts index a6637463b..ae684a594 100644 --- a/src/node-transformers/converting-transformers/TemplateLiteralTransformer.ts +++ b/src/node-transformers/converting-transformers/TemplateLiteralTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -24,7 +24,7 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -35,7 +35,7 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer { * @param {NodeGuards} node * @returns {boolean} */ - private static isLiteralNodeWithStringValue (node: ESTree.Node | undefined): boolean { + private static isLiteralNodeWithStringValue(node: ESTree.Node | undefined): boolean { return !!node && NodeGuards.isLiteralNode(node) && typeof node.value === 'string'; } @@ -43,7 +43,7 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Converting: return { @@ -64,7 +64,7 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer { * @param {ESTree.Node} parentNode * @returns {ESTree.Node} */ - public transformNode (templateLiteralNode: ESTree.TemplateLiteral, parentNode: ESTree.Node): ESTree.Node { + public transformNode(templateLiteralNode: ESTree.TemplateLiteral, parentNode: ESTree.Node): ESTree.Node { if (NodeGuards.isTaggedTemplateExpressionNode(parentNode)) { return templateLiteralNode; } @@ -77,7 +77,10 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer { * @param {ESTree.Node} parentNode * @returns {ESTree.Expression} */ - private transformTemplateLiteralNode (templateLiteralNode: ESTree.TemplateLiteral, parentNode: ESTree.Node): ESTree.Expression { + private transformTemplateLiteralNode( + templateLiteralNode: ESTree.TemplateLiteral, + parentNode: ESTree.Node + ): ESTree.Expression { const templateLiteralExpressions: ESTree.Expression[] = templateLiteralNode.expressions; let nodes: ESTree.Expression[] = []; diff --git a/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts b/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts index ee45587a2..4eea6ae2e 100644 --- a/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts +++ b/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts @@ -19,15 +19,12 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { * @param {Property} propertyNode * @returns {string | null} */ - private static getPropertyNodeKeyName (propertyNode: ESTree.Property): string | null { + private static getPropertyNodeKeyName(propertyNode: ESTree.Property): string | null { const propertyKeyNode: ESTree.Expression | ESTree.PrivateIdentifier = propertyNode.key; if ( - NodeGuards.isLiteralNode(propertyKeyNode) - && ( - typeof propertyKeyNode.value === 'string' - || typeof propertyKeyNode.value === 'number' - ) + NodeGuards.isLiteralNode(propertyKeyNode) && + (typeof propertyKeyNode.value === 'string' || typeof propertyKeyNode.value === 'number') ) { return propertyKeyNode.value.toString(); } @@ -43,7 +40,7 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { * @param {Property} node * @returns {boolean} */ - private static isProhibitedPropertyNode (node: ESTree.Property): boolean { + private static isProhibitedPropertyNode(node: ESTree.Property): boolean { return node.kind !== 'init'; } @@ -51,21 +48,22 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { * @param {Node} node * @returns {propertyValueNode is Pattern} */ - private static isProhibitedPattern (node: ESTree.Node): node is ESTree.Pattern { - return !node - || NodeGuards.isObjectPatternNode(node) - || NodeGuards.isArrayPatternNode(node) - || NodeGuards.isAssignmentPatternNode(node) - || NodeGuards.isRestElementNode(node); + private static isProhibitedPattern(node: ESTree.Node): node is ESTree.Pattern { + return ( + !node || + NodeGuards.isObjectPatternNode(node) || + NodeGuards.isArrayPatternNode(node) || + NodeGuards.isAssignmentPatternNode(node) || + NodeGuards.isRestElementNode(node) + ); } /** * @param {Property} property * @returns {boolean} */ - private static shouldCreateLiteralNode (property: ESTree.Property): boolean { - return !property.computed - || (property.computed && !!property.key && NodeGuards.isLiteralNode(property.key)); + private static shouldCreateLiteralNode(property: ESTree.Property): boolean { + return !property.computed || (property.computed && !!property.key && NodeGuards.isLiteralNode(property.key)); } /** @@ -84,17 +82,13 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { * @param {Statement} hostStatement * @returns {IObjectExpressionExtractorResult} */ - public extract ( + public extract( objectExpressionNode: ESTree.ObjectExpression, hostStatement: ESTree.Statement ): IObjectExpressionExtractorResult { const hostNode: ESTree.Node | undefined = objectExpressionNode.parentNode; - if ( - hostNode - && NodeGuards.isVariableDeclaratorNode(hostNode) - && NodeGuards.isIdentifierNode(hostNode.id) - ) { + if (hostNode && NodeGuards.isVariableDeclaratorNode(hostNode) && NodeGuards.isIdentifierNode(hostNode.id)) { return this.transformObjectExpressionNode(objectExpressionNode, hostStatement, hostNode.id); } @@ -111,18 +105,14 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { * @param {Expression} memberExpressionHostNode * @returns {IObjectExpressionExtractorResult} */ - private transformObjectExpressionNode ( + private transformObjectExpressionNode( objectExpressionNode: ESTree.ObjectExpression, hostStatement: ESTree.Statement, memberExpressionHostNode: ESTree.Expression ): IObjectExpressionExtractorResult { const properties: (ESTree.Property | ESTree.SpreadElement)[] = objectExpressionNode.properties; - const [expressionStatements, removablePropertyIds]: [ESTree.ExpressionStatement[], number[]] = this - .extractPropertiesToExpressionStatements( - properties, - hostStatement, - memberExpressionHostNode - ); + const [expressionStatements, removablePropertyIds]: [ESTree.ExpressionStatement[], number[]] = + this.extractPropertiesToExpressionStatements(properties, hostStatement, memberExpressionHostNode); const hostNodeWithStatements: TNodeWithStatements = NodeStatementUtils.getScopeOfNode(hostStatement); @@ -147,7 +137,7 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { * @param {Expression} memberExpressionHostNode * @returns {[ExpressionStatement[], number[]]} */ - private extractPropertiesToExpressionStatements ( + private extractPropertiesToExpressionStatements( properties: (ESTree.Property | ESTree.SpreadElement)[], hostStatement: ESTree.Statement, memberExpressionHostNode: ESTree.Expression @@ -158,7 +148,7 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { // have to iterate in the reversed order to fast check spread elements and break iteration on them for (let i: number = propertiesLength - 1; i >= 0; i--) { - const property: (ESTree.Property | ESTree.SpreadElement) = properties[i]; + const property: ESTree.Property | ESTree.SpreadElement = properties[i]; // spread element if (NodeGuards.isSpreadElementNode(property)) { @@ -192,8 +182,11 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { const memberExpressionProperty: ESTree.Expression = shouldCreateLiteralNode ? NodeFactory.literalNode(propertyKeyName) : NodeFactory.identifierNode(propertyKeyName); - const memberExpressionNode: ESTree.MemberExpression = NodeFactory - .memberExpressionNode(memberExpressionHostNode, memberExpressionProperty, true); + const memberExpressionNode: ESTree.MemberExpression = NodeFactory.memberExpressionNode( + memberExpressionHostNode, + memberExpressionProperty, + true + ); const expressionStatementNode: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode( NodeFactory.assignmentExpressionNode('=', memberExpressionNode, propertyValue) ); @@ -219,13 +212,12 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { * @param {ObjectExpression} objectExpressionNode * @param {number[]} removablePropertyIds */ - private filterExtractedObjectExpressionProperties ( + private filterExtractedObjectExpressionProperties( objectExpressionNode: ESTree.ObjectExpression, removablePropertyIds: number[] ): void { - objectExpressionNode.properties = objectExpressionNode.properties - .filter((property: ESTree.Property | ESTree.SpreadElement, index: number) => - !removablePropertyIds.includes(index) - ); + objectExpressionNode.properties = objectExpressionNode.properties.filter( + (property: ESTree.Property | ESTree.SpreadElement, index: number) => !removablePropertyIds.includes(index) + ); } } diff --git a/src/node-transformers/converting-transformers/object-expression-extractors/ObjectExpressionToVariableDeclarationExtractor.ts b/src/node-transformers/converting-transformers/object-expression-extractors/ObjectExpressionToVariableDeclarationExtractor.ts index 2ec99f9cc..941589354 100644 --- a/src/node-transformers/converting-transformers/object-expression-extractors/ObjectExpressionToVariableDeclarationExtractor.ts +++ b/src/node-transformers/converting-transformers/object-expression-extractors/ObjectExpressionToVariableDeclarationExtractor.ts @@ -32,9 +32,9 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx /** * @param {TObjectExpressionKeysTransformerCustomNodeFactory} objectExpressionKeysTransformerCustomNodeFactory */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IObjectExpressionKeysTransformerCustomNode) - objectExpressionKeysTransformerCustomNodeFactory: TObjectExpressionKeysTransformerCustomNodeFactory, + objectExpressionKeysTransformerCustomNodeFactory: TObjectExpressionKeysTransformerCustomNodeFactory ) { this.objectExpressionKeysTransformerCustomNodeFactory = objectExpressionKeysTransformerCustomNodeFactory; } @@ -57,14 +57,11 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx * @param {Statement} hostStatement * @returns {IObjectExpressionExtractorResult} */ - public extract ( + public extract( objectExpressionNode: ESTree.ObjectExpression, hostStatement: ESTree.Statement ): IObjectExpressionExtractorResult { - return this.transformObjectExpressionToVariableDeclaration( - objectExpressionNode, - hostStatement - ); + return this.transformObjectExpressionToVariableDeclaration(objectExpressionNode, hostStatement); } /** @@ -72,14 +69,14 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx * @param {Statement} hostStatement * @returns {Node} */ - private transformObjectExpressionToVariableDeclaration ( + private transformObjectExpressionToVariableDeclaration( objectExpressionNode: ESTree.ObjectExpression, hostStatement: ESTree.Statement ): IObjectExpressionExtractorResult { const hostNodeWithStatements: TNodeWithStatements = NodeStatementUtils.getScopeOfNode(hostStatement); const lexicalScopeNode: TNodeWithLexicalScope | null = NodeGuards.isNodeWithLexicalScope(hostNodeWithStatements) ? hostNodeWithStatements - : NodeLexicalScopeUtils.getLexicalScope(hostNodeWithStatements) ?? null; + : (NodeLexicalScopeUtils.getLexicalScope(hostNodeWithStatements) ?? null); if (!lexicalScopeNode) { throw new Error('Cannot find lexical scope node for the host statement node'); @@ -97,8 +94,12 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx NodeUtils.parentizeAst(newObjectExpressionHostStatement); NodeUtils.parentizeNode(newObjectExpressionHostStatement, hostNodeWithStatements); - const newObjectExpressionIdentifier: ESTree.Identifier = this.getObjectExpressionIdentifierNode(newObjectExpressionHostStatement); - const newObjectExpressionNode: ESTree.ObjectExpression = this.getObjectExpressionNode(newObjectExpressionHostStatement); + const newObjectExpressionIdentifier: ESTree.Identifier = this.getObjectExpressionIdentifierNode( + newObjectExpressionHostStatement + ); + const newObjectExpressionNode: ESTree.ObjectExpression = this.getObjectExpressionNode( + newObjectExpressionHostStatement + ); return { nodeToReplace: newObjectExpressionIdentifier, @@ -112,24 +113,24 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx * @param {(Property | SpreadElement)[]} properties * @returns {VariableDeclaration} */ - private getObjectExpressionHostNode ( + private getObjectExpressionHostNode( lexicalScopeNode: TNodeWithLexicalScope, properties: (ESTree.Property | ESTree.SpreadElement)[] ): ESTree.VariableDeclaration { - const variableDeclarationHostNodeCustomNode: ICustomNode> = - this.objectExpressionKeysTransformerCustomNodeFactory( - ObjectExpressionKeysTransformerCustomNode.ObjectExpressionVariableDeclarationHostNode - ); + const variableDeclarationHostNodeCustomNode: ICustomNode< + TInitialData + > = this.objectExpressionKeysTransformerCustomNodeFactory( + ObjectExpressionKeysTransformerCustomNode.ObjectExpressionVariableDeclarationHostNode + ); variableDeclarationHostNodeCustomNode.initialize(lexicalScopeNode, properties); const statementNode: TStatement = variableDeclarationHostNodeCustomNode.getNode()[0]; - if ( - !statementNode - || !NodeGuards.isVariableDeclarationNode(statementNode) - ) { - throw new Error('`objectExpressionHostCustomNode.getNode()[0]` should returns array with `VariableDeclaration` node'); + if (!statementNode || !NodeGuards.isVariableDeclarationNode(statementNode)) { + throw new Error( + '`objectExpressionHostCustomNode.getNode()[0]` should returns array with `VariableDeclaration` node' + ); } return statementNode; @@ -139,11 +140,13 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx * @param {VariableDeclaration} objectExpressionHostNode * @returns {Identifier} */ - private getObjectExpressionIdentifierNode (objectExpressionHostNode: ESTree.VariableDeclaration): ESTree.Identifier { + private getObjectExpressionIdentifierNode(objectExpressionHostNode: ESTree.VariableDeclaration): ESTree.Identifier { const newObjectExpressionIdentifierNode: ESTree.Pattern = objectExpressionHostNode.declarations[0].id; if (!NodeGuards.isIdentifierNode(newObjectExpressionIdentifierNode)) { - throw new Error('`objectExpressionHostNode` should contain `VariableDeclarator` node with `Identifier` id property'); + throw new Error( + '`objectExpressionHostNode` should contain `VariableDeclarator` node with `Identifier` id property' + ); } return newObjectExpressionIdentifierNode; @@ -153,11 +156,13 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx * @param {VariableDeclaration} objectExpressionHostNode * @returns {Identifier} */ - private getObjectExpressionNode (objectExpressionHostNode: ESTree.VariableDeclaration): ESTree.ObjectExpression { + private getObjectExpressionNode(objectExpressionHostNode: ESTree.VariableDeclaration): ESTree.ObjectExpression { const newObjectExpressionNode: ESTree.Expression | null = objectExpressionHostNode.declarations[0].init ?? null; if (!newObjectExpressionNode || !NodeGuards.isObjectExpressionNode(newObjectExpressionNode)) { - throw new Error('`objectExpressionHostNode` should contain `VariableDeclarator` node with `ObjectExpression` init property'); + throw new Error( + '`objectExpressionHostNode` should contain `VariableDeclarator` node with `ObjectExpression` init property' + ); } return newObjectExpressionNode; diff --git a/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionIdentifiersTransformer.ts b/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionIdentifiersTransformer.ts index 8a1d99d08..04044b2ae 100644 --- a/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionIdentifiersTransformer.ts +++ b/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionIdentifiersTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as eslintScope from 'eslint-scope'; @@ -39,7 +39,7 @@ export class DeadCodeInjectionIdentifiersTransformer extends AbstractNodeTransfo * @param {IOptions} options * @param {IScopeIdentifiersTraverser} scopeIdentifiersTraverser */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IIdentifierReplacer) identifierReplacer: IIdentifierReplacer, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @@ -55,7 +55,7 @@ export class DeadCodeInjectionIdentifiersTransformer extends AbstractNodeTransfo * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.RenameIdentifiers: return { @@ -76,15 +76,12 @@ export class DeadCodeInjectionIdentifiersTransformer extends AbstractNodeTransfo * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node { + public transformNode(programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node { this.scopeIdentifiersTraverser.traverseScopeThroughIdentifiers( programNode, parentNode, (data: IScopeThroughIdentifiersTraverserCallbackData) => { - const { - reference, - variableLexicalScopeNode - } = data; + const { reference, variableLexicalScopeNode } = data; this.transformScopeThroughIdentifiers(reference, variableLexicalScopeNode); } @@ -97,9 +94,9 @@ export class DeadCodeInjectionIdentifiersTransformer extends AbstractNodeTransfo * @param {Reference} reference * @param {TNodeWithLexicalScope} lexicalScopeNode */ - private transformScopeThroughIdentifiers ( + private transformScopeThroughIdentifiers( reference: eslintScope.Reference, - lexicalScopeNode: TNodeWithLexicalScope, + lexicalScopeNode: TNodeWithLexicalScope ): void { if (reference.resolved) { return; @@ -115,10 +112,7 @@ export class DeadCodeInjectionIdentifiersTransformer extends AbstractNodeTransfo * @param {Identifier} identifierNode * @param {TNodeWithLexicalScope} lexicalScopeNode */ - private storeIdentifierName ( - identifierNode: ESTree.Identifier, - lexicalScopeNode: TNodeWithLexicalScope - ): void { + private storeIdentifierName(identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void { this.identifierReplacer.storeLocalName(identifierNode, lexicalScopeNode); } @@ -127,13 +121,12 @@ export class DeadCodeInjectionIdentifiersTransformer extends AbstractNodeTransfo * @param {TNodeWithLexicalScope} lexicalScopeNode * @param {Variable} reference */ - private replaceIdentifierName ( + private replaceIdentifierName( identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope, reference: eslintScope.Reference ): void { - const newIdentifier: ESTree.Identifier = this.identifierReplacer - .replace(identifierNode, lexicalScopeNode); + const newIdentifier: ESTree.Identifier = this.identifierReplacer.replace(identifierNode, lexicalScopeNode); // rename of identifier reference.identifier.name = newIdentifier.name; diff --git a/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts b/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts index d1fd7bb15..d9508e327 100644 --- a/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts +++ b/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -56,7 +56,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { /** * @type {WeakSet } */ - private readonly deadCodeInjectionRootAstHostNodeSet: WeakSet = new WeakSet(); + private readonly deadCodeInjectionRootAstHostNodeSet: WeakSet = new WeakSet(); /** * @type {ESTree.BlockStatement[]} @@ -84,9 +84,9 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IDeadCodeInjectionCustomNode) - deadCodeInjectionCustomNodeFactory: TDeadNodeInjectionCustomNodeFactory, + deadCodeInjectionCustomNodeFactory: TDeadNodeInjectionCustomNodeFactory, @inject(ServiceIdentifiers.INodeTransformersRunner) transformersRunner: INodeTransformersRunner, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions @@ -101,22 +101,24 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {Node} targetNode * @returns {boolean} */ - private static isProhibitedNodeInsideCollectedBlockStatement (targetNode: ESTree.Node): boolean { - return NodeGuards.isFunctionDeclarationNode(targetNode) // can break code on strict mode - || NodeGuards.isBreakStatementNode(targetNode) - || NodeGuards.isContinueStatementNode(targetNode) - || NodeGuards.isAwaitExpressionNode(targetNode) - || NodeGuards.isYieldExpressionNode(targetNode) - || NodeGuards.isSuperNode(targetNode) - || (NodeGuards.isForOfStatementNode(targetNode) && targetNode.await) - || NodeGuards.isPrivateIdentifierNode(targetNode); + private static isProhibitedNodeInsideCollectedBlockStatement(targetNode: ESTree.Node): boolean { + return ( + NodeGuards.isFunctionDeclarationNode(targetNode) || // can break code on strict mode + NodeGuards.isBreakStatementNode(targetNode) || + NodeGuards.isContinueStatementNode(targetNode) || + NodeGuards.isAwaitExpressionNode(targetNode) || + NodeGuards.isYieldExpressionNode(targetNode) || + NodeGuards.isSuperNode(targetNode) || + (NodeGuards.isForOfStatementNode(targetNode) && targetNode.await) || + NodeGuards.isPrivateIdentifierNode(targetNode) + ); } /** * @param {Node} targetNode * @returns {boolean} */ - private static isScopeHoistingFunctionDeclaration (targetNode: ESTree.Node): boolean { + private static isScopeHoistingFunctionDeclaration(targetNode: ESTree.Node): boolean { if (!NodeGuards.isFunctionDeclarationNode(targetNode)) { return false; } @@ -154,7 +156,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {BlockStatement} blockStatementNode * @returns {boolean} */ - private static isValidCollectedBlockStatementNode (blockStatementNode: ESTree.BlockStatement): boolean { + private static isValidCollectedBlockStatementNode(blockStatementNode: ESTree.BlockStatement): boolean { if (!blockStatementNode.body.length) { return false; } @@ -169,9 +171,9 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { } if ( - nestedBlockStatementsCount > DeadCodeInjectionTransformer.maxNestedBlockStatementsCount - || DeadCodeInjectionTransformer.isProhibitedNodeInsideCollectedBlockStatement(node) - || DeadCodeInjectionTransformer.isScopeHoistingFunctionDeclaration(node) + nestedBlockStatementsCount > DeadCodeInjectionTransformer.maxNestedBlockStatementsCount || + DeadCodeInjectionTransformer.isProhibitedNodeInsideCollectedBlockStatement(node) || + DeadCodeInjectionTransformer.isScopeHoistingFunctionDeclaration(node) ) { isValidBlockStatementNode = false; @@ -188,7 +190,10 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {boolean} */ - private static isValidWrappedBlockStatementNode (blockStatementNode: ESTree.BlockStatement, parentNode: ESTree.Node): boolean { + private static isValidWrappedBlockStatementNode( + blockStatementNode: ESTree.BlockStatement, + parentNode: ESTree.Node + ): boolean { /** * Special case for ignoring all EvalHost nodes that are added by EvalCallExpressionTransformer * So, all content of eval expressions should not be affected by dead code injection @@ -217,8 +222,8 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { return false; } - const parentNodeWithStatements: TNodeWithStatements = NodeStatementUtils - .getParentNodeWithStatements(blockStatementNode); + const parentNodeWithStatements: TNodeWithStatements = + NodeStatementUtils.getParentNodeWithStatements(blockStatementNode); return parentNodeWithStatements.type !== NodeType.Program; } @@ -227,7 +232,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.DeadCodeInjection: return { @@ -253,7 +258,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { enter: ( node: ESTree.Node, parentNode: ESTree.Node | null - ): ESTree.Node | estraverse.VisitorOption |undefined => { + ): ESTree.Node | estraverse.VisitorOption | undefined => { if (parentNode && this.isDeadCodeInjectionRootAstHostNode(node)) { return this.restoreNode(node, parentNode); } @@ -269,7 +274,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {NodeGuards} programNode * @param {NodeGuards} parentNode */ - public prepareNode (programNode: ESTree.Node, parentNode: ESTree.Node): void { + public prepareNode(programNode: ESTree.Node, parentNode: ESTree.Node): void { estraverse.traverse(programNode, { enter: (node: ESTree.Node): void => { if (!NodeGuards.isBlockStatementNode(node)) { @@ -300,20 +305,21 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards | VisitorOption} */ - public transformNode ( + public transformNode( blockStatementNode: ESTree.BlockStatement, parentNode: ESTree.Node ): ESTree.Node | estraverse.VisitorOption { - const canBreakTraverse: boolean = !this.collectedBlockStatements.length - || this.collectedBlockStatementsTotalLength < DeadCodeInjectionTransformer.minCollectedBlockStatementsCount; + const canBreakTraverse: boolean = + !this.collectedBlockStatements.length || + this.collectedBlockStatementsTotalLength < DeadCodeInjectionTransformer.minCollectedBlockStatementsCount; if (canBreakTraverse) { return estraverse.VisitorOption.Break; } if ( - this.randomGenerator.getMathRandom() > this.options.deadCodeInjectionThreshold - || !DeadCodeInjectionTransformer.isValidWrappedBlockStatementNode(blockStatementNode, parentNode) + this.randomGenerator.getMathRandom() > this.options.deadCodeInjectionThreshold || + !DeadCodeInjectionTransformer.isValidWrappedBlockStatementNode(blockStatementNode, parentNode) ) { return blockStatementNode; } @@ -336,11 +342,13 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {Node} */ - public restoreNode (deadCodeInjectionRootAstHostNode: ESTree.BlockStatement, parentNode: ESTree.Node): ESTree.Node { + public restoreNode(deadCodeInjectionRootAstHostNode: ESTree.BlockStatement, parentNode: ESTree.Node): ESTree.Node { const hostNodeFirstStatement: ESTree.Statement = deadCodeInjectionRootAstHostNode.body[0]; if (!NodeGuards.isFunctionDeclarationNode(hostNodeFirstStatement)) { - throw new Error('Wrong dead code injection root AST host node. Host node should contain `FunctionDeclaration` node'); + throw new Error( + 'Wrong dead code injection root AST host node. Host node should contain `FunctionDeclaration` node' + ); } return hostNodeFirstStatement.body; @@ -350,8 +358,9 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {Node} node * @returns {boolean} */ - private isDeadCodeInjectionRootAstHostNode (node: ESTree.Node): node is ESTree.BlockStatement { - const isDeadCodeInjectionRootAstHostNode = NodeGuards.isBlockStatementNode(node) && this.deadCodeInjectionRootAstHostNodeSet.has(node); + private isDeadCodeInjectionRootAstHostNode(node: ESTree.Node): node is ESTree.BlockStatement { + const isDeadCodeInjectionRootAstHostNode = + NodeGuards.isBlockStatementNode(node) && this.deadCodeInjectionRootAstHostNodeSet.has(node); if (isDeadCodeInjectionRootAstHostNode) { this.deadCodeInjectionRootAstHostNodeSet.delete(node); @@ -366,12 +375,10 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {BlockStatement} clonedBlockStatementNode * @returns {BlockStatement} */ - private makeClonedBlockStatementNodeUnique (clonedBlockStatementNode: ESTree.BlockStatement): ESTree.BlockStatement { + private makeClonedBlockStatementNodeUnique(clonedBlockStatementNode: ESTree.BlockStatement): ESTree.BlockStatement { // should wrap cloned block statement node into function node for correct scope encapsulation const hostNode: ESTree.Program = NodeFactory.programNode([ - NodeFactory.expressionStatementNode( - NodeFactory.functionExpressionNode([], clonedBlockStatementNode) - ) + NodeFactory.expressionStatementNode(NodeFactory.functionExpressionNode([], clonedBlockStatementNode)) ]); NodeUtils.parentizeAst(hostNode); @@ -392,7 +399,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {BlockStatement} */ - private replaceBlockStatementNode ( + private replaceBlockStatementNode( blockStatementNode: ESTree.BlockStatement, randomBlockStatementNode: ESTree.BlockStatement, parentNode: ESTree.Node @@ -415,12 +422,15 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { */ this.deadCodeInjectionRootAstHostNodeSet.add(deadCodeInjectionRootAstHostNode); - const blockStatementDeadCodeInjectionCustomNode: ICustomNode> = - this.deadCodeInjectionCustomNodeFactory(DeadCodeInjectionCustomNode.BlockStatementDeadCodeInjectionNode); + const blockStatementDeadCodeInjectionCustomNode: ICustomNode< + TInitialData + > = this.deadCodeInjectionCustomNodeFactory(DeadCodeInjectionCustomNode.BlockStatementDeadCodeInjectionNode); blockStatementDeadCodeInjectionCustomNode.initialize(blockStatementNode, deadCodeInjectionRootAstHostNode); - const newBlockStatementNode: ESTree.BlockStatement = blockStatementDeadCodeInjectionCustomNode.getNode()[0]; + const newBlockStatementNode: ESTree.BlockStatement = ( + blockStatementDeadCodeInjectionCustomNode.getNode()[0] + ); NodeUtils.parentizeNode(newBlockStatementNode, parentNode); diff --git a/src/node-transformers/finalizing-transformers/DirectivePlacementTransformer.ts b/src/node-transformers/finalizing-transformers/DirectivePlacementTransformer.ts index 5da2ffb5c..63f414774 100644 --- a/src/node-transformers/finalizing-transformers/DirectivePlacementTransformer.ts +++ b/src/node-transformers/finalizing-transformers/DirectivePlacementTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -28,25 +28,23 @@ export class DirectivePlacementTransformer extends AbstractNodeTransformer { /** * @type {NodeTransformer[]} */ - public override readonly runAfter: NodeTransformer[] = [ - NodeTransformer.CustomCodeHelpersTransformer - ]; + public override readonly runAfter: NodeTransformer[] = [NodeTransformer.CustomCodeHelpersTransformer]; /** * @type {WeakMap} */ - private readonly lexicalScopeDirectives: WeakMap< + private readonly lexicalScopeDirectives: WeakMap = new WeakMap< TNodeWithLexicalScope, ESTree.Directive - > = new WeakMap(); + >(); /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, - @inject(ServiceIdentifiers.IOptions) options: IOptions, + @inject(ServiceIdentifiers.IOptions) options: IOptions ) { super(randomGenerator, options); } @@ -55,7 +53,7 @@ export class DirectivePlacementTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Preparing: return { @@ -91,7 +89,7 @@ export class DirectivePlacementTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {TNodeWithLexicalScopeStatements} */ - public analyzeNode ( + public analyzeNode( nodeWithLexicalScopeStatements: TNodeWithLexicalScopeStatements, parentNode: ESTree.Node ): TNodeWithLexicalScopeStatements { @@ -113,7 +111,7 @@ export class DirectivePlacementTransformer extends AbstractNodeTransformer { * @param {Node | null} parentNode * @returns {TNodeWithLexicalScope} */ - public transformNode ( + public transformNode( nodeWithLexicalScopeStatements: TNodeWithLexicalScopeStatements, parentNode: ESTree.Node ): TNodeWithLexicalScopeStatements { diff --git a/src/node-transformers/finalizing-transformers/EscapeSequenceTransformer.ts b/src/node-transformers/finalizing-transformers/EscapeSequenceTransformer.ts index ee59d17c9..19dde7dfc 100644 --- a/src/node-transformers/finalizing-transformers/EscapeSequenceTransformer.ts +++ b/src/node-transformers/finalizing-transformers/EscapeSequenceTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -22,9 +22,7 @@ export class EscapeSequenceTransformer extends AbstractNodeTransformer { /** * @type {NodeTransformer[]} */ - public override readonly runAfter: NodeTransformer[] = [ - NodeTransformer.CustomCodeHelpersTransformer - ]; + public override readonly runAfter: NodeTransformer[] = [NodeTransformer.CustomCodeHelpersTransformer]; /** * @type {IEscapeSequenceEncoder} @@ -36,7 +34,7 @@ export class EscapeSequenceTransformer extends AbstractNodeTransformer { * @param {IOptions} options * @param {IEscapeSequenceEncoder} escapeSequenceEncoder */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder @@ -50,7 +48,7 @@ export class EscapeSequenceTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Finalizing: return { @@ -71,7 +69,7 @@ export class EscapeSequenceTransformer extends AbstractNodeTransformer { * @param {Node | null} parentNode * @returns {Literal} */ - public transformNode (literalNode: ESTree.Literal, parentNode: ESTree.Node | null): ESTree.Literal { + public transformNode(literalNode: ESTree.Literal, parentNode: ESTree.Node | null): ESTree.Literal { if (!NodeLiteralUtils.isStringLiteralNode(literalNode)) { return literalNode; } diff --git a/src/node-transformers/initializing-transformers/CommentsTransformer.ts b/src/node-transformers/initializing-transformers/CommentsTransformer.ts index f3f861e6d..d3877052e 100644 --- a/src/node-transformers/initializing-transformers/CommentsTransformer.ts +++ b/src/node-transformers/initializing-transformers/CommentsTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -19,16 +19,13 @@ export class CommentsTransformer extends AbstractNodeTransformer { /** * @type {string[]} */ - private static readonly preservedWords: string[] = [ - '@license', - '@preserve' - ]; + private static readonly preservedWords: string[] = ['@license', '@preserve']; /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -39,7 +36,7 @@ export class CommentsTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Initializing: return { @@ -67,7 +64,7 @@ export class CommentsTransformer extends AbstractNodeTransformer { /** * Moves comments to their nodes */ - public transformNode (rootNode: ESTree.Program): ESTree.Node { + public transformNode(rootNode: ESTree.Program): ESTree.Node { rootNode = this.filterCommentsOnPrimaryTraverse(rootNode); if (!rootNode.comments?.length) { @@ -94,13 +91,14 @@ export class CommentsTransformer extends AbstractNodeTransformer { return; } - const commentIdx: number = comments.findIndex((comment: ESTree.Comment) => - comment.range && node.range && comment.range[0] < node.range[0] + const commentIdx: number = comments.findIndex( + (comment: ESTree.Comment) => comment.range && node.range && comment.range[0] < node.range[0] ); if (commentIdx >= 0) { - (isFirstNode ? rootNode : node).leadingComments = - comments.splice(commentIdx, comments.length - commentIdx).reverse(); + (isFirstNode ? rootNode : node).leadingComments = comments + .splice(commentIdx, comments.length - commentIdx) + .reverse(); } isFirstNode = false; @@ -121,10 +119,8 @@ export class CommentsTransformer extends AbstractNodeTransformer { * @param {ESTree.Program} rootNode * @returns {ESTree.Program} */ - private filterCommentsOnPrimaryTraverse (rootNode: ESTree.Program): ESTree.Program { - rootNode.comments = rootNode.comments?.filter((comment: ESTree.Comment) => - this.filterComment(comment, true) - ); + private filterCommentsOnPrimaryTraverse(rootNode: ESTree.Program): ESTree.Program { + rootNode.comments = rootNode.comments?.filter((comment: ESTree.Comment) => this.filterComment(comment, true)); return rootNode; } @@ -135,7 +131,7 @@ export class CommentsTransformer extends AbstractNodeTransformer { * @param {ESTree.Program} rootNode * @returns {ESTree.Program} */ - private filterCommentsOnFinalizingTraverse (rootNode: ESTree.Program): ESTree.Program { + private filterCommentsOnFinalizingTraverse(rootNode: ESTree.Program): ESTree.Program { estraverse.replace(rootNode, { enter: (node: ESTree.Node): ESTree.Node => { if (node.leadingComments) { @@ -162,12 +158,13 @@ export class CommentsTransformer extends AbstractNodeTransformer { * @param {boolean} keepConditionalComment * @returns {boolean} */ - private filterComment (comment: ESTree.Comment, keepConditionalComment: boolean): boolean { + private filterComment(comment: ESTree.Comment, keepConditionalComment: boolean): boolean { if (keepConditionalComment && ConditionalCommentObfuscatingGuard.isConditionalComment(comment)) { return true; } - return CommentsTransformer.preservedWords - .some((preservedWord: string) => comment.value.includes(preservedWord)); + return CommentsTransformer.preservedWords.some((preservedWord: string) => + comment.value.includes(preservedWord) + ); } } diff --git a/src/node-transformers/preparing-transformers/CustomCodeHelpersTransformer.ts b/src/node-transformers/preparing-transformers/CustomCodeHelpersTransformer.ts index e3deb6fbc..b8cc19c42 100644 --- a/src/node-transformers/preparing-transformers/CustomCodeHelpersTransformer.ts +++ b/src/node-transformers/preparing-transformers/CustomCodeHelpersTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -60,10 +60,10 @@ export class CustomCodeHelpersTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.ICallsGraphAnalyzer) callsGraphAnalyzer: ICallsGraphAnalyzer, @inject(ServiceIdentifiers.IPrevailingKindOfVariablesAnalyzer) - prevailingKindOfVariablesAnalyzer: IPrevailingKindOfVariablesAnalyzer, + prevailingKindOfVariablesAnalyzer: IPrevailingKindOfVariablesAnalyzer, @inject(ServiceIdentifiers.TCustomNodeGroupStorage) customCodeHelperGroupStorage: TCustomCodeHelperGroupStorage, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions @@ -79,7 +79,7 @@ export class CustomCodeHelpersTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Preparing: return { @@ -110,7 +110,7 @@ export class CustomCodeHelpersTransformer extends AbstractNodeTransformer { * @param {Program} node * @param {Node | null} parentNode */ - public prepareNode (node: ESTree.Program, parentNode: ESTree.Node | null): void { + public prepareNode(node: ESTree.Program, parentNode: ESTree.Node | null): void { this.callsGraphData = this.callsGraphAnalyzer.analyze(node); this.prevailingKindOfVariablesAnalyzer.analyze(node); } @@ -120,7 +120,7 @@ export class CustomCodeHelpersTransformer extends AbstractNodeTransformer { * @param {Node | null} parentNode * @returns {Node} */ - public transformNode (node: ESTree.Program, parentNode: ESTree.Node | null): ESTree.Node { + public transformNode(node: ESTree.Program, parentNode: ESTree.Node | null): ESTree.Node { return node; } @@ -128,13 +128,11 @@ export class CustomCodeHelpersTransformer extends AbstractNodeTransformer { * @param {Program} node * @param {Node | null} parentNode */ - private appendCustomNodesForPreparingStage (node: ESTree.Program, parentNode: ESTree.Node | null): void { - this.customCodeHelperGroupStorage - .getStorage() - .forEach((customCodeHelperGroup: ICustomCodeHelperGroup) => { - customCodeHelperGroup.initialize(); - customCodeHelperGroup.appendOnPreparingStage?.(node, this.callsGraphData); - }); + private appendCustomNodesForPreparingStage(node: ESTree.Program, parentNode: ESTree.Node | null): void { + this.customCodeHelperGroupStorage.getStorage().forEach((customCodeHelperGroup: ICustomCodeHelperGroup) => { + customCodeHelperGroup.initialize(); + customCodeHelperGroup.appendOnPreparingStage?.(node, this.callsGraphData); + }); } /** @@ -142,17 +140,15 @@ export class CustomCodeHelpersTransformer extends AbstractNodeTransformer { * @param {Program} node * @param {Node | null} parentNode */ - private appendCustomNodesForStage ( + private appendCustomNodesForStage( nodeTransformationStage: NodeTransformationStage, node: ESTree.Program, parentNode: ESTree.Node | null ): void { - this.customCodeHelperGroupStorage - .getStorage() - .forEach((customCodeHelperGroup: ICustomCodeHelperGroup) => { - const methodName: TCustomCodeHelpersGroupAppendMethodName = `appendOn${nodeTransformationStage}Stage`; + this.customCodeHelperGroupStorage.getStorage().forEach((customCodeHelperGroup: ICustomCodeHelperGroup) => { + const methodName: TCustomCodeHelpersGroupAppendMethodName = `appendOn${nodeTransformationStage}Stage`; - customCodeHelperGroup[methodName]?.(node, this.callsGraphData); - }); + customCodeHelperGroup[methodName]?.(node, this.callsGraphData); + }); } } diff --git a/src/node-transformers/preparing-transformers/EvalCallExpressionTransformer.ts b/src/node-transformers/preparing-transformers/EvalCallExpressionTransformer.ts index f762fe446..137a4557c 100644 --- a/src/node-transformers/preparing-transformers/EvalCallExpressionTransformer.ts +++ b/src/node-transformers/preparing-transformers/EvalCallExpressionTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -32,7 +32,7 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -43,15 +43,15 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { * @param {Expression | SpreadElement} node * @returns {string | null} */ - private static extractEvalStringFromCallExpressionArgument (node: ESTree.Expression | ESTree.SpreadElement): string | null { + private static extractEvalStringFromCallExpressionArgument( + node: ESTree.Expression | ESTree.SpreadElement + ): string | null { if (NodeGuards.isLiteralNode(node)) { - return EvalCallExpressionTransformer - .extractEvalStringFromLiteralNode(node); + return EvalCallExpressionTransformer.extractEvalStringFromLiteralNode(node); } if (NodeGuards.isTemplateLiteralNode(node)) { - return EvalCallExpressionTransformer - .extractEvalStringFromTemplateLiteralNode(node); + return EvalCallExpressionTransformer.extractEvalStringFromTemplateLiteralNode(node); } return null; @@ -61,7 +61,7 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { * @param {Literal} node * @returns {string | null} */ - private static extractEvalStringFromLiteralNode (node: ESTree.Literal): string | null { + private static extractEvalStringFromLiteralNode(node: ESTree.Literal): string | null { return typeof node.value === 'string' ? node.value : null; } @@ -69,7 +69,7 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { * @param {TemplateLiteral} node * @returns {string | null} */ - private static extractEvalStringFromTemplateLiteralNode (node: ESTree.TemplateLiteral): string | null { + private static extractEvalStringFromTemplateLiteralNode(node: ESTree.TemplateLiteral): string | null { const quasis: ESTree.TemplateElement[] = node.quasis; const allowedQuasisLength: number = 1; @@ -84,7 +84,7 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Preparing: return { @@ -114,11 +114,12 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {Node} */ - public transformNode (node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node { - const isEvalCallExpressionNode = parentNode - && NodeGuards.isCallExpressionNode(node) - && NodeGuards.isIdentifierNode(node.callee) - && node.callee.name === 'eval'; + public transformNode(node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node { + const isEvalCallExpressionNode = + parentNode && + NodeGuards.isCallExpressionNode(node) && + NodeGuards.isIdentifierNode(node.callee) && + node.callee.name === 'eval'; if (!isEvalCallExpressionNode) { return node; @@ -130,8 +131,9 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { return node; } - const evalString: string | null = EvalCallExpressionTransformer - .extractEvalStringFromCallExpressionArgument(evalCallExpressionFirstArgument); + const evalString: string | null = EvalCallExpressionTransformer.extractEvalStringFromCallExpressionArgument( + evalCallExpressionFirstArgument + ); if (!evalString) { return node; @@ -150,8 +152,10 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { * we should wrap AST-tree into the parent function expression node (ast root host node). * This function expression node will help to correctly transform AST-tree. */ - const evalRootAstHostNode: ESTree.FunctionExpression = NodeFactory - .functionExpressionNode([], NodeFactory.blockStatementNode(ast)); + const evalRootAstHostNode: ESTree.FunctionExpression = NodeFactory.functionExpressionNode( + [], + NodeFactory.blockStatementNode(ast) + ); NodeMetadata.set(evalRootAstHostNode, { evalHostNode: true }); @@ -166,7 +170,7 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {Node} */ - public restoreNode (node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node { + public restoreNode(node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node { if (!this.isEvalRootAstHostNode(node)) { return node; } @@ -174,19 +178,16 @@ export class EvalCallExpressionTransformer extends AbstractNodeTransformer { const targetAst: ESTree.Statement[] = node.body.body; const obfuscatedCode: string = NodeUtils.convertStructureToCode(targetAst); - return NodeFactory.callExpressionNode( - NodeFactory.identifierNode('eval'), - [ - NodeFactory.literalNode(StringUtils.escapeJsString(obfuscatedCode)) - ] - ); + return NodeFactory.callExpressionNode(NodeFactory.identifierNode('eval'), [ + NodeFactory.literalNode(StringUtils.escapeJsString(obfuscatedCode)) + ]); } /** * @param {Node} node * @returns {boolean} */ - private isEvalRootAstHostNode (node: ESTree.Node): node is ESTree.FunctionExpression { + private isEvalRootAstHostNode(node: ESTree.Node): node is ESTree.FunctionExpression { return NodeMetadata.isEvalHostNode(node); } } diff --git a/src/node-transformers/preparing-transformers/MetadataTransformer.ts b/src/node-transformers/preparing-transformers/MetadataTransformer.ts index 0df45dafd..dd916c8b2 100644 --- a/src/node-transformers/preparing-transformers/MetadataTransformer.ts +++ b/src/node-transformers/preparing-transformers/MetadataTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -31,7 +31,7 @@ export class MetadataTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -42,7 +42,7 @@ export class MetadataTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Preparing: return { @@ -61,7 +61,7 @@ export class MetadataTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {Node} */ - public transformNode (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node { + public transformNode(node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node { NodeMetadata.set(node, { ignoredNode: false }); if (NodeGuards.isLiteralNode(node)) { diff --git a/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts b/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts index dad6fc5dc..c05f019b2 100644 --- a/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts +++ b/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -54,7 +54,7 @@ export class ObfuscatingGuardsTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__INodeGuard) obfuscatingGuardFactory: TObfuscatingGuardFactory, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions @@ -68,7 +68,7 @@ export class ObfuscatingGuardsTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Preparing: return { @@ -87,9 +87,10 @@ export class ObfuscatingGuardsTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {Node} */ - public transformNode (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node { - const obfuscatingGuardResults: ObfuscatingGuardResult[] = this.obfuscatingGuards - .map((obfuscatingGuard: IObfuscatingGuard) => obfuscatingGuard.check(node)); + public transformNode(node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node { + const obfuscatingGuardResults: ObfuscatingGuardResult[] = this.obfuscatingGuards.map( + (obfuscatingGuard: IObfuscatingGuard) => obfuscatingGuard.check(node) + ); this.setNodeMetadata(node, obfuscatingGuardResults); @@ -100,18 +101,18 @@ export class ObfuscatingGuardsTransformer extends AbstractNodeTransformer { * @param {Node} node * @param {ObfuscatingGuardResult[]} obfuscatingGuardResults */ - private setNodeMetadata (node: ESTree.Node, obfuscatingGuardResults: ObfuscatingGuardResult[]): void { - const isTransformNode: boolean = obfuscatingGuardResults - .every((obfuscatingGuardResult: ObfuscatingGuardResult) => obfuscatingGuardResult === ObfuscatingGuardResult.Transform); + private setNodeMetadata(node: ESTree.Node, obfuscatingGuardResults: ObfuscatingGuardResult[]): void { + const isTransformNode: boolean = obfuscatingGuardResults.every( + (obfuscatingGuardResult: ObfuscatingGuardResult) => + obfuscatingGuardResult === ObfuscatingGuardResult.Transform + ); let isForceTransformNode: boolean = false; let isIgnoredNode: boolean = false; if (!isTransformNode) { - isForceTransformNode = obfuscatingGuardResults - .includes(ObfuscatingGuardResult.ForceTransform); - isIgnoredNode = !isForceTransformNode && obfuscatingGuardResults - .includes(ObfuscatingGuardResult.Ignore); + isForceTransformNode = obfuscatingGuardResults.includes(ObfuscatingGuardResult.ForceTransform); + isIgnoredNode = !isForceTransformNode && obfuscatingGuardResults.includes(ObfuscatingGuardResult.Ignore); } NodeMetadata.set(node, { diff --git a/src/node-transformers/preparing-transformers/ParentificationTransformer.ts b/src/node-transformers/preparing-transformers/ParentificationTransformer.ts index 21ffd8dfd..4e2f27608 100644 --- a/src/node-transformers/preparing-transformers/ParentificationTransformer.ts +++ b/src/node-transformers/preparing-transformers/ParentificationTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -21,7 +21,7 @@ export class ParentificationTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -32,7 +32,7 @@ export class ParentificationTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Preparing: return { @@ -51,7 +51,7 @@ export class ParentificationTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {Node} */ - public transformNode (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node { + public transformNode(node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node { return NodeUtils.parentizeNode(node, parentNode); } } diff --git a/src/node-transformers/preparing-transformers/VariablePreserveTransformer.ts b/src/node-transformers/preparing-transformers/VariablePreserveTransformer.ts index 68232d50a..dc9326100 100644 --- a/src/node-transformers/preparing-transformers/VariablePreserveTransformer.ts +++ b/src/node-transformers/preparing-transformers/VariablePreserveTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import * as ESTree from 'estree'; import * as eslintScope from 'eslint-scope'; @@ -26,9 +26,7 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer { /** * @type {NodeTransformer.ParentificationTransformer[]} */ - public override readonly runAfter: NodeTransformer[] = [ - NodeTransformer.ParentificationTransformer - ]; + public override readonly runAfter: NodeTransformer[] = [NodeTransformer.ParentificationTransformer]; /** * @type {IIdentifierReplacer} @@ -46,7 +44,7 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer { * @param {IOptions} options * @param {IScopeIdentifiersTraverser} scopeIdentifiersTraverser */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IIdentifierReplacer) identifierReplacer: IIdentifierReplacer, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @@ -64,7 +62,7 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Preparing: case NodeTransformationStage.Converting: @@ -87,7 +85,7 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node { + public transformNode(programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node { this.scopeIdentifiersTraverser.traverseScopeIdentifiers( programNode, parentNode, @@ -100,13 +98,8 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer { /** * @param {IScopeIdentifiersTraverserCallbackData} data */ - private preserveScopeVariableIdentifiers (data: IScopeIdentifiersTraverserCallbackData): void { - const { - isGlobalDeclaration, - isBubblingDeclaration, - variable, - variableScope - } = data; + private preserveScopeVariableIdentifiers(data: IScopeIdentifiersTraverserCallbackData): void { + const { isGlobalDeclaration, isBubblingDeclaration, variable, variableScope } = data; for (const identifier of variable.identifiers) { if (isGlobalDeclaration || isBubblingDeclaration) { @@ -120,7 +113,7 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer { /** * @param {Identifier} identifierNode */ - private preserveIdentifierNameForRootLexicalScope (identifierNode: ESTree.Identifier): void { + private preserveIdentifierNameForRootLexicalScope(identifierNode: ESTree.Identifier): void { this.identifierReplacer.preserveName(identifierNode); } @@ -128,7 +121,7 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer { * @param {Identifier} identifierNode * @param {Scope} variableScope */ - private preserveIdentifierNameForLexicalScope ( + private preserveIdentifierNameForLexicalScope( identifierNode: ESTree.Identifier, variableScope: eslintScope.Scope ): void { diff --git a/src/node-transformers/preparing-transformers/obfuscating-guards/BlackListObfuscatingGuard.ts b/src/node-transformers/preparing-transformers/obfuscating-guards/BlackListObfuscatingGuard.ts index 2f0b7e3ef..eb82e905e 100644 --- a/src/node-transformers/preparing-transformers/obfuscating-guards/BlackListObfuscatingGuard.ts +++ b/src/node-transformers/preparing-transformers/obfuscating-guards/BlackListObfuscatingGuard.ts @@ -13,16 +13,14 @@ export class BlackListObfuscatingGuard implements IObfuscatingGuard { /** * @type {((node: Node) => boolean)[]} */ - private static readonly blackListGuards: ((node: ESTree.Node) => boolean)[] = [ - NodeGuards.isDirectiveNode - ]; + private static readonly blackListGuards: ((node: ESTree.Node) => boolean)[] = [NodeGuards.isDirectiveNode]; /** * @type {number} */ private readonly blackListGuardsLength: number; - public constructor () { + public constructor() { this.blackListGuardsLength = BlackListObfuscatingGuard.blackListGuards.length; } @@ -30,7 +28,7 @@ export class BlackListObfuscatingGuard implements IObfuscatingGuard { * @param {Node} node * @returns {ObfuscatingGuardResult} */ - public check (node: ESTree.Node): ObfuscatingGuardResult { + public check(node: ESTree.Node): ObfuscatingGuardResult { for (let i: number = 0; i < this.blackListGuardsLength; i++) { if (BlackListObfuscatingGuard.blackListGuards[i](node)) { return ObfuscatingGuardResult.Ignore; diff --git a/src/node-transformers/preparing-transformers/obfuscating-guards/ConditionalCommentObfuscatingGuard.ts b/src/node-transformers/preparing-transformers/obfuscating-guards/ConditionalCommentObfuscatingGuard.ts index e001b3712..cc934a2b9 100644 --- a/src/node-transformers/preparing-transformers/obfuscating-guards/ConditionalCommentObfuscatingGuard.ts +++ b/src/node-transformers/preparing-transformers/obfuscating-guards/ConditionalCommentObfuscatingGuard.ts @@ -29,16 +29,18 @@ export class ConditionalCommentObfuscatingGuard implements IObfuscatingGuard { * @param {Comment} comment * @returns {boolean} */ - public static isConditionalComment (comment: ESTree.Comment): boolean { - return ConditionalCommentObfuscatingGuard.obfuscationEnableCommentRegExp.test(comment.value) || - ConditionalCommentObfuscatingGuard.obfuscationDisableCommentRegExp.test(comment.value); + public static isConditionalComment(comment: ESTree.Comment): boolean { + return ( + ConditionalCommentObfuscatingGuard.obfuscationEnableCommentRegExp.test(comment.value) || + ConditionalCommentObfuscatingGuard.obfuscationDisableCommentRegExp.test(comment.value) + ); } /** * @param {Node} node * @returns {ObfuscatingGuardResult} */ - public check (node: ESTree.Node): ObfuscatingGuardResult { + public check(node: ESTree.Node): ObfuscatingGuardResult { if (NodeGuards.isNodeWithComments(node)) { const leadingComments: ESTree.Comment[] | undefined = node.leadingComments; @@ -47,16 +49,14 @@ export class ConditionalCommentObfuscatingGuard implements IObfuscatingGuard { } } - return this.obfuscationAllowed - ? ObfuscatingGuardResult.Transform - : ObfuscatingGuardResult.Ignore; + return this.obfuscationAllowed ? ObfuscatingGuardResult.Transform : ObfuscatingGuardResult.Ignore; } /** * @param {Comment[]} comments * @returns {boolean} */ - private checkComments (comments: ESTree.Comment[]): boolean { + private checkComments(comments: ESTree.Comment[]): boolean { const commentsLength: number = comments.length; let obfuscationAllowed: boolean = this.obfuscationAllowed; diff --git a/src/node-transformers/preparing-transformers/obfuscating-guards/ForceTransformStringObfuscatingGuard.ts b/src/node-transformers/preparing-transformers/obfuscating-guards/ForceTransformStringObfuscatingGuard.ts index d4a066add..b3f70a26c 100644 --- a/src/node-transformers/preparing-transformers/obfuscating-guards/ForceTransformStringObfuscatingGuard.ts +++ b/src/node-transformers/preparing-transformers/obfuscating-guards/ForceTransformStringObfuscatingGuard.ts @@ -21,9 +21,7 @@ export class ForceTransformStringObfuscatingGuard implements IObfuscatingGuard { /** * @param {IOptions} options */ - public constructor ( - @inject(ServiceIdentifiers.IOptions) options: IOptions - ) { + public constructor(@inject(ServiceIdentifiers.IOptions) options: IOptions) { this.options = options; } @@ -31,11 +29,11 @@ export class ForceTransformStringObfuscatingGuard implements IObfuscatingGuard { * @param {Node} node * @returns {ObfuscatingGuardResult} */ - public check (node: ESTree.Node): ObfuscatingGuardResult { + public check(node: ESTree.Node): ObfuscatingGuardResult { if ( - this.options.forceTransformStrings.length - && NodeGuards.isLiteralNode(node) - && typeof node.value === 'string' + this.options.forceTransformStrings.length && + NodeGuards.isLiteralNode(node) && + typeof node.value === 'string' ) { return !this.isForceTransformString(node.value) ? ObfuscatingGuardResult.Transform @@ -49,10 +47,9 @@ export class ForceTransformStringObfuscatingGuard implements IObfuscatingGuard { * @param {string} value * @returns {boolean} */ - private isForceTransformString (value: string): boolean { - return this.options.forceTransformStrings - .some((forceTransformString: string) => { - return new RegExp(forceTransformString, 'g').exec(value) !== null; - }); + private isForceTransformString(value: string): boolean { + return this.options.forceTransformStrings.some((forceTransformString: string) => { + return new RegExp(forceTransformString, 'g').exec(value) !== null; + }); } } diff --git a/src/node-transformers/preparing-transformers/obfuscating-guards/IgnoredImportObfuscatingGuard.ts b/src/node-transformers/preparing-transformers/obfuscating-guards/IgnoredImportObfuscatingGuard.ts index ff27b178b..d80a62d2c 100644 --- a/src/node-transformers/preparing-transformers/obfuscating-guards/IgnoredImportObfuscatingGuard.ts +++ b/src/node-transformers/preparing-transformers/obfuscating-guards/IgnoredImportObfuscatingGuard.ts @@ -21,9 +21,7 @@ export class IgnoredImportObfuscatingGuard implements IObfuscatingGuard { /** * @param {IOptions} options */ - public constructor ( - @inject(ServiceIdentifiers.IOptions) options: IOptions - ) { + public constructor(@inject(ServiceIdentifiers.IOptions) options: IOptions) { this.options = options; } @@ -31,7 +29,7 @@ export class IgnoredImportObfuscatingGuard implements IObfuscatingGuard { * @param {Node} node * @returns {boolean} */ - private static isDynamicImport (node: ESTree.Node): boolean { + private static isDynamicImport(node: ESTree.Node): boolean { return NodeGuards.isImportExpressionNode(node); } @@ -39,20 +37,23 @@ export class IgnoredImportObfuscatingGuard implements IObfuscatingGuard { * @param {Node} node * @returns {boolean} */ - private static isRequireImport (node: ESTree.Node): boolean { - return NodeGuards.isCallExpressionNode(node) - && NodeGuards.isIdentifierNode(node.callee) - && node.callee.name === 'require'; + private static isRequireImport(node: ESTree.Node): boolean { + return ( + NodeGuards.isCallExpressionNode(node) && + NodeGuards.isIdentifierNode(node.callee) && + node.callee.name === 'require' + ); } /** * @param {Node} node * @returns {ObfuscatingGuardResult} */ - public check (node: ESTree.Node): ObfuscatingGuardResult { + public check(node: ESTree.Node): ObfuscatingGuardResult { if (this.options.ignoreImports) { - const isIgnoredImport = IgnoredImportObfuscatingGuard.isDynamicImport(node) - || IgnoredImportObfuscatingGuard.isRequireImport(node); + const isIgnoredImport = + IgnoredImportObfuscatingGuard.isDynamicImport(node) || + IgnoredImportObfuscatingGuard.isRequireImport(node); if (isIgnoredImport) { return ObfuscatingGuardResult.Ignore; diff --git a/src/node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard.ts b/src/node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard.ts index 32ebd4b89..34bdc5307 100644 --- a/src/node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard.ts +++ b/src/node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard.ts @@ -14,10 +14,12 @@ export class ImportMetaObfuscationGuard implements IObfuscatingGuard { * @param {Node} node * @returns {ObfuscatingGuardResult} */ - public check (node: ESTree.Node): ObfuscatingGuardResult { + public check(node: ESTree.Node): ObfuscatingGuardResult { const isMetaProperty = NodeGuards.isMetaPropertyNode(node); const isMetaPropertyParent = !!node?.parentNode && NodeGuards.isMetaPropertyNode(node.parentNode); - return isMetaProperty || isMetaPropertyParent ? ObfuscatingGuardResult.Ignore : ObfuscatingGuardResult.Transform; + return isMetaProperty || isMetaPropertyParent + ? ObfuscatingGuardResult.Ignore + : ObfuscatingGuardResult.Transform; } } diff --git a/src/node-transformers/preparing-transformers/obfuscating-guards/ReservedStringObfuscatingGuard.ts b/src/node-transformers/preparing-transformers/obfuscating-guards/ReservedStringObfuscatingGuard.ts index 21005fd88..d6769cec8 100644 --- a/src/node-transformers/preparing-transformers/obfuscating-guards/ReservedStringObfuscatingGuard.ts +++ b/src/node-transformers/preparing-transformers/obfuscating-guards/ReservedStringObfuscatingGuard.ts @@ -21,9 +21,7 @@ export class ReservedStringObfuscatingGuard implements IObfuscatingGuard { /** * @param {IOptions} options */ - public constructor ( - @inject(ServiceIdentifiers.IOptions) options: IOptions - ) { + public constructor(@inject(ServiceIdentifiers.IOptions) options: IOptions) { this.options = options; } @@ -31,12 +29,8 @@ export class ReservedStringObfuscatingGuard implements IObfuscatingGuard { * @param {Node} node * @returns {ObfuscatingGuardResult} */ - public check (node: ESTree.Node): ObfuscatingGuardResult { - if ( - this.options.reservedStrings.length - && NodeGuards.isLiteralNode(node) - && typeof node.value === 'string' - ) { + public check(node: ESTree.Node): ObfuscatingGuardResult { + if (this.options.reservedStrings.length && NodeGuards.isLiteralNode(node) && typeof node.value === 'string') { return !this.isReservedString(node.value) ? ObfuscatingGuardResult.Transform : ObfuscatingGuardResult.Ignore; @@ -49,10 +43,9 @@ export class ReservedStringObfuscatingGuard implements IObfuscatingGuard { * @param {string} value * @returns {boolean} */ - private isReservedString (value: string): boolean { - return this.options.reservedStrings - .some((reservedString: string) => { - return new RegExp(reservedString, 'g').exec(value) !== null; - }); + private isReservedString(value: string): boolean { + return this.options.reservedStrings.some((reservedString: string) => { + return new RegExp(reservedString, 'g').exec(value) !== null; + }); } } diff --git a/src/node-transformers/rename-identifiers-transformers/LabeledStatementTransformer.ts b/src/node-transformers/rename-identifiers-transformers/LabeledStatementTransformer.ts index 3c12a6d5b..b56ddbea3 100644 --- a/src/node-transformers/rename-identifiers-transformers/LabeledStatementTransformer.ts +++ b/src/node-transformers/rename-identifiers-transformers/LabeledStatementTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -45,7 +45,7 @@ export class LabeledStatementTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IIdentifierReplacer) identifierReplacer: IIdentifierReplacer, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions @@ -59,7 +59,7 @@ export class LabeledStatementTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.RenameIdentifiers: return { @@ -80,8 +80,9 @@ export class LabeledStatementTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (labeledStatementNode: ESTree.LabeledStatement, parentNode: ESTree.Node): ESTree.Node { - const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(labeledStatementNode); + public transformNode(labeledStatementNode: ESTree.LabeledStatement, parentNode: ESTree.Node): ESTree.Node { + const lexicalScopeNode: TNodeWithLexicalScope | undefined = + NodeLexicalScopeUtils.getLexicalScope(labeledStatementNode); if (!lexicalScopeNode) { return labeledStatementNode; @@ -97,7 +98,7 @@ export class LabeledStatementTransformer extends AbstractNodeTransformer { * @param {LabeledStatement} labeledStatementNode * @param {TNodeWithLexicalScope} lexicalScopeNode */ - private storeLabeledStatementName ( + private storeLabeledStatementName( labeledStatementNode: ESTree.LabeledStatement, lexicalScopeNode: TNodeWithLexicalScope ): void { @@ -108,15 +109,14 @@ export class LabeledStatementTransformer extends AbstractNodeTransformer { * @param {LabeledStatement} labeledStatementNode * @param {TNodeWithLexicalScope} lexicalScopeNode */ - private replaceLabeledStatementName ( + private replaceLabeledStatementName( labeledStatementNode: ESTree.LabeledStatement, lexicalScopeNode: TNodeWithLexicalScope ): void { estraverse.replace(labeledStatementNode, { enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => { if (parentNode && NodeGuards.isLabelIdentifierNode(node, parentNode)) { - const newIdentifier: ESTree.Identifier = this.identifierReplacer - .replace(node, lexicalScopeNode); + const newIdentifier: ESTree.Identifier = this.identifierReplacer.replace(node, lexicalScopeNode); node.name = newIdentifier.name; } diff --git a/src/node-transformers/rename-identifiers-transformers/ScopeIdentifiersTransformer.ts b/src/node-transformers/rename-identifiers-transformers/ScopeIdentifiersTransformer.ts index 6eef3e984..028a51350 100644 --- a/src/node-transformers/rename-identifiers-transformers/ScopeIdentifiersTransformer.ts +++ b/src/node-transformers/rename-identifiers-transformers/ScopeIdentifiersTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as eslintScope from 'eslint-scope'; @@ -33,7 +33,8 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { /** * @type {WeakMap} */ - private readonly lexicalScopesWithObjectPatternWithoutDeclarationMap: WeakMap = new WeakMap(); + private readonly lexicalScopesWithObjectPatternWithoutDeclarationMap: WeakMap = + new WeakMap(); /** * @type {IScopeIdentifiersTraverser} @@ -46,7 +47,7 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {IOptions} options * @param {IScopeIdentifiersTraverser} scopeIdentifiersTraverser */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IIdentifierReplacer) identifierReplacer: IIdentifierReplacer, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @@ -62,7 +63,7 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.RenameIdentifiers: return { @@ -83,23 +84,18 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node { + public transformNode(programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node { this.scopeIdentifiersTraverser.traverseScopeIdentifiers( programNode, parentNode, (data: IScopeIdentifiersTraverserCallbackData) => { - const { - isGlobalDeclaration, - variable, - variableLexicalScopeNode - } = data; + const { isGlobalDeclaration, variable, variableLexicalScopeNode } = data; if (!this.options.renameGlobals && isGlobalDeclaration) { - const isImportBindingOrCatchClauseIdentifier: boolean = variable.defs - .every((definition: eslintScope.Definition) => - definition.type === 'ImportBinding' - || definition.type === 'CatchClause' - ); + const isImportBindingOrCatchClauseIdentifier: boolean = variable.defs.every( + (definition: eslintScope.Definition) => + definition.type === 'ImportBinding' || definition.type === 'CatchClause' + ); // skip all global identifiers except import statement and catch clause parameter identifiers if (!isImportBindingOrCatchClauseIdentifier) { @@ -107,11 +103,7 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { } } - this.transformScopeVariableIdentifiers( - variable, - variableLexicalScopeNode, - isGlobalDeclaration - ); + this.transformScopeVariableIdentifiers(variable, variableLexicalScopeNode, isGlobalDeclaration); } ); @@ -123,7 +115,7 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {TNodeWithLexicalScope} lexicalScopeNode * @param {boolean} isGlobalDeclaration */ - private transformScopeVariableIdentifiers ( + private transformScopeVariableIdentifiers( variable: eslintScope.Variable, lexicalScopeNode: TNodeWithLexicalScope, isGlobalDeclaration: boolean @@ -147,7 +139,7 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {TNodeWithLexicalScope} lexicalScopeNode * @param {boolean} isGlobalDeclaration */ - private storeIdentifierName ( + private storeIdentifierName( identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope, isGlobalDeclaration: boolean @@ -164,13 +156,12 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {TNodeWithLexicalScope} lexicalScopeNode * @param {Variable} variable */ - private replaceIdentifierName ( + private replaceIdentifierName( identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope, variable: eslintScope.Variable ): void { - const newIdentifier: ESTree.Identifier = this.identifierReplacer - .replace(identifierNode, lexicalScopeNode); + const newIdentifier: ESTree.Identifier = this.identifierReplacer.replace(identifierNode, lexicalScopeNode); // rename of identifiers variable.identifiers.forEach((identifier: ESTree.Identifier) => { @@ -190,24 +181,26 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @returns {boolean} */ // eslint-disable-next-line complexity - private isReplaceableIdentifierNode ( + private isReplaceableIdentifierNode( identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope, variable: eslintScope.Variable ): identifierNode is ESTree.Identifier & { parentNode: ESTree.Node } { const parentNode: ESTree.Node | undefined = identifierNode.parentNode; - return !!parentNode - && !NodeMetadata.isIgnoredNode(identifierNode) - && !this.isProhibitedPropertyIdentifierNode(identifierNode, parentNode) - && !this.isProhibitedPropertyAssignmentPatternIdentifierNode(identifierNode, parentNode) - && !this.isProhibitedClassDeclarationNameIdentifierNode(variable, identifierNode, parentNode) - && !this.isProhibitedExportNamedClassDeclarationIdentifierNode(identifierNode, parentNode) - && !this.isProhibitedExportNamedFunctionDeclarationIdentifierNode(identifierNode, parentNode) - && !this.isProhibitedExportNamedVariableDeclarationIdentifierNode(identifierNode, parentNode) - && !this.isProhibitedImportSpecifierNode(identifierNode, parentNode) - && !this.isProhibitedVariableNameUsedInObjectPatternNode(variable, identifierNode, lexicalScopeNode) - && !NodeGuards.isLabelIdentifierNode(identifierNode, parentNode); + return ( + !!parentNode && + !NodeMetadata.isIgnoredNode(identifierNode) && + !this.isProhibitedPropertyIdentifierNode(identifierNode, parentNode) && + !this.isProhibitedPropertyAssignmentPatternIdentifierNode(identifierNode, parentNode) && + !this.isProhibitedClassDeclarationNameIdentifierNode(variable, identifierNode, parentNode) && + !this.isProhibitedExportNamedClassDeclarationIdentifierNode(identifierNode, parentNode) && + !this.isProhibitedExportNamedFunctionDeclarationIdentifierNode(identifierNode, parentNode) && + !this.isProhibitedExportNamedVariableDeclarationIdentifierNode(identifierNode, parentNode) && + !this.isProhibitedImportSpecifierNode(identifierNode, parentNode) && + !this.isProhibitedVariableNameUsedInObjectPatternNode(variable, identifierNode, lexicalScopeNode) && + !NodeGuards.isLabelIdentifierNode(identifierNode, parentNode) + ); } /** @@ -216,14 +209,16 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {identifierNode is Identifier} */ - private isProhibitedClassDeclarationNameIdentifierNode ( + private isProhibitedClassDeclarationNameIdentifierNode( variable: eslintScope.Variable, identifierNode: ESTree.Identifier, parentNode: ESTree.Node ): identifierNode is ESTree.Identifier { - return NodeGuards.isClassDeclarationNode(variable.scope.block) - && NodeGuards.isClassDeclarationNode(parentNode) - && parentNode.id === identifierNode; + return ( + NodeGuards.isClassDeclarationNode(variable.scope.block) && + NodeGuards.isClassDeclarationNode(parentNode) && + parentNode.id === identifierNode + ); } /** @@ -231,14 +226,16 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {identifierNode is Identifier} */ - private isProhibitedExportNamedClassDeclarationIdentifierNode ( + private isProhibitedExportNamedClassDeclarationIdentifierNode( identifierNode: ESTree.Identifier, parentNode: ESTree.Node ): identifierNode is ESTree.Identifier { - return NodeGuards.isClassDeclarationNode(parentNode) - && parentNode.id === identifierNode - && !!parentNode.parentNode - && NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode); + return ( + NodeGuards.isClassDeclarationNode(parentNode) && + parentNode.id === identifierNode && + !!parentNode.parentNode && + NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode) + ); } /** @@ -246,14 +243,16 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {identifierNode is Identifier} */ - private isProhibitedExportNamedFunctionDeclarationIdentifierNode ( + private isProhibitedExportNamedFunctionDeclarationIdentifierNode( identifierNode: ESTree.Identifier, parentNode: ESTree.Node ): identifierNode is ESTree.Identifier { - return NodeGuards.isFunctionDeclarationNode(parentNode) - && parentNode.id === identifierNode - && !!parentNode.parentNode - && NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode); + return ( + NodeGuards.isFunctionDeclarationNode(parentNode) && + parentNode.id === identifierNode && + !!parentNode.parentNode && + NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode) + ); } /** @@ -261,16 +260,18 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {identifierNode is Identifier} */ - private isProhibitedExportNamedVariableDeclarationIdentifierNode ( + private isProhibitedExportNamedVariableDeclarationIdentifierNode( identifierNode: ESTree.Identifier, parentNode: ESTree.Node ): identifierNode is ESTree.Identifier { - return NodeGuards.isVariableDeclaratorNode(parentNode) - && parentNode.id === identifierNode - && !!parentNode.parentNode - && NodeGuards.isVariableDeclarationNode(parentNode.parentNode) - && !!parentNode.parentNode.parentNode - && NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode.parentNode); + return ( + NodeGuards.isVariableDeclaratorNode(parentNode) && + parentNode.id === identifierNode && + !!parentNode.parentNode && + NodeGuards.isVariableDeclarationNode(parentNode.parentNode) && + !!parentNode.parentNode.parentNode && + NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode.parentNode) + ); } /** @@ -278,9 +279,8 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {boolean} */ - private isProhibitedImportSpecifierNode (identifierNode: ESTree.Identifier, parentNode: ESTree.Node): boolean { - return NodeGuards.isImportSpecifierNode(parentNode) - && parentNode.imported.name === parentNode.local.name; + private isProhibitedImportSpecifierNode(identifierNode: ESTree.Identifier, parentNode: ESTree.Node): boolean { + return NodeGuards.isImportSpecifierNode(parentNode) && parentNode.imported.name === parentNode.local.name; } /** @@ -288,16 +288,15 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {boolean} */ - private isProhibitedPropertyIdentifierNode ( - node: ESTree.Node, - parentNode: ESTree.Node - ): node is ESTree.Identifier { - return NodeGuards.isPropertyNode(parentNode) - && !parentNode.computed - && NodeGuards.isIdentifierNode(parentNode.key) - && NodeGuards.isIdentifierNode(node) - && parentNode.shorthand - && parentNode.key.name === node.name; + private isProhibitedPropertyIdentifierNode(node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier { + return ( + NodeGuards.isPropertyNode(parentNode) && + !parentNode.computed && + NodeGuards.isIdentifierNode(parentNode.key) && + NodeGuards.isIdentifierNode(node) && + parentNode.shorthand && + parentNode.key.name === node.name + ); } /** @@ -305,17 +304,19 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {Node} parentNode * @returns {boolean} */ - private isProhibitedPropertyAssignmentPatternIdentifierNode ( + private isProhibitedPropertyAssignmentPatternIdentifierNode( node: ESTree.Node, parentNode: ESTree.Node ): node is ESTree.Identifier { - return NodeGuards.isAssignmentPatternNode(parentNode) - && parentNode.left === node - && !!parentNode.parentNode - && NodeGuards.isPropertyNode(parentNode.parentNode) - && NodeGuards.isIdentifierNode(parentNode.left) - && NodeGuards.isIdentifierNode(parentNode.parentNode.key) - && parentNode.left.name === parentNode.parentNode.key.name; + return ( + NodeGuards.isAssignmentPatternNode(parentNode) && + parentNode.left === node && + !!parentNode.parentNode && + NodeGuards.isPropertyNode(parentNode.parentNode) && + NodeGuards.isIdentifierNode(parentNode.left) && + NodeGuards.isIdentifierNode(parentNode.parentNode.key) && + parentNode.left.name === parentNode.parentNode.key.name + ); } /** @@ -329,7 +330,7 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { * @param {TNodeWithLexicalScope} lexicalScopeNode * @returns {boolean} */ - private isProhibitedVariableNameUsedInObjectPatternNode ( + private isProhibitedVariableNameUsedInObjectPatternNode( variable: eslintScope.Variable, identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope @@ -342,7 +343,9 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { return false; } - const hasVarDefinitions: boolean = variable.defs.some((definition: eslintScope.Definition) => (definition).kind === 'var'); + const hasVarDefinitions: boolean = variable.defs.some( + (definition: eslintScope.Definition) => (definition).kind === 'var' + ); if (!hasVarDefinitions) { return false; @@ -353,20 +356,21 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer { estraverse.traverse(lexicalScopeNode, { enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void | estraverse.VisitorOption => { if ( - NodeGuards.isObjectPatternNode(node) - && parentNode - && NodeGuards.isAssignmentExpressionNode(parentNode) + NodeGuards.isObjectPatternNode(node) && + parentNode && + NodeGuards.isAssignmentExpressionNode(parentNode) ) { isLexicalScopeHasObjectPatternWithoutDeclaration = true; const properties: (ESTree.Property | ESTree.RestElement)[] = node.properties; for (const property of properties) { - isProhibitedVariableDeclaration = NodeGuards.isPropertyNode(property) - && !property.computed - && property.shorthand - && NodeGuards.isIdentifierNode(property.key) - && identifierNode.name === property.key.name; + isProhibitedVariableDeclaration = + NodeGuards.isPropertyNode(property) && + !property.computed && + property.shorthand && + NodeGuards.isIdentifierNode(property.key) && + identifierNode.name === property.key.name; if (!isProhibitedVariableDeclaration) { continue; diff --git a/src/node-transformers/rename-identifiers-transformers/ScopeThroughIdentifiersTransformer.ts b/src/node-transformers/rename-identifiers-transformers/ScopeThroughIdentifiersTransformer.ts index e1775d48b..242bcecdb 100644 --- a/src/node-transformers/rename-identifiers-transformers/ScopeThroughIdentifiersTransformer.ts +++ b/src/node-transformers/rename-identifiers-transformers/ScopeThroughIdentifiersTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as eslintScope from 'eslint-scope'; @@ -39,7 +39,7 @@ export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IThroughIdentifierReplacer) throughIdentifierReplacer: IThroughIdentifierReplacer, @inject(ServiceIdentifiers.IScopeIdentifiersTraverser) scopeIdentifiersTraverser: IScopeIdentifiersTraverser, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @@ -55,7 +55,7 @@ export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.RenameIdentifiers: return { @@ -76,20 +76,14 @@ export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node { + public transformNode(programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node { this.scopeIdentifiersTraverser.traverseScopeThroughIdentifiers( programNode, parentNode, (data: IScopeThroughIdentifiersTraverserCallbackData) => { - const { - reference, - variableLexicalScopeNode - } = data; - - this.transformScopeThroughIdentifiers( - reference, - variableLexicalScopeNode - ); + const { reference, variableLexicalScopeNode } = data; + + this.transformScopeThroughIdentifiers(reference, variableLexicalScopeNode); } ); @@ -100,7 +94,7 @@ export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer * @param {Reference} reference * @param {TNodeWithLexicalScope} lexicalScopeNode */ - protected transformScopeThroughIdentifiers ( + protected transformScopeThroughIdentifiers( reference: eslintScope.Reference, lexicalScopeNode: TNodeWithLexicalScope ): void { @@ -114,7 +108,7 @@ export class ScopeThroughIdentifiersTransformer extends AbstractNodeTransformer /** * @param {Variable} reference */ - protected replaceIdentifierName (reference: eslintScope.Reference): void { + protected replaceIdentifierName(reference: eslintScope.Reference): void { const identifier: ESTree.Identifier = reference.identifier; const newIdentifier: ESTree.Identifier = this.throughIdentifierReplacer.replace(identifier); diff --git a/src/node-transformers/rename-identifiers-transformers/replacer/IdentifierReplacer.ts b/src/node-transformers/rename-identifiers-transformers/replacer/IdentifierReplacer.ts index 9fbd0c636..8a7d70846 100644 --- a/src/node-transformers/rename-identifiers-transformers/replacer/IdentifierReplacer.ts +++ b/src/node-transformers/rename-identifiers-transformers/replacer/IdentifierReplacer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -40,11 +40,11 @@ export class IdentifierReplacer implements IIdentifierReplacer { * @param {IGlobalIdentifierNamesCacheStorage} identifierNamesCacheStorage * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage) - identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage, + identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { this.options = options; @@ -59,7 +59,7 @@ export class IdentifierReplacer implements IIdentifierReplacer { * @param {Node} identifierNode * @param {TNodeWithLexicalScope} lexicalScopeNode */ - public storeGlobalName (identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void { + public storeGlobalName(identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void { const identifierName: string = identifierNode.name; if (this.isReservedName(identifierName)) { @@ -86,7 +86,7 @@ export class IdentifierReplacer implements IIdentifierReplacer { * @param {Identifier} identifierNode * @param {TNodeWithLexicalScope} lexicalScopeNode */ - public storeLocalName (identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void { + public storeLocalName(identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void { const identifierName: string = identifierNode.name; if (this.isReservedName(identifierName)) { @@ -105,7 +105,7 @@ export class IdentifierReplacer implements IIdentifierReplacer { * @param {TNodeWithLexicalScope} lexicalScopeNode * @returns {Identifier} */ - public replace (identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): ESTree.Identifier { + public replace(identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): ESTree.Identifier { const namesMap: Map | null = this.blockScopesMap.get(lexicalScopeNode) ?? null; if (!namesMap) { @@ -126,7 +126,7 @@ export class IdentifierReplacer implements IIdentifierReplacer { * * @param {Identifier} identifierNode */ - public preserveName (identifierNode: ESTree.Identifier): void { + public preserveName(identifierNode: ESTree.Identifier): void { this.identifierNamesGenerator.preserveName(identifierNode.name); } @@ -136,7 +136,10 @@ export class IdentifierReplacer implements IIdentifierReplacer { * @param {Identifier} identifierNode * @param {TNodeWithLexicalScope} lexicalScopeNode */ - public preserveNameForLexicalScope (identifierNode: ESTree.Identifier, lexicalScopeNode: TNodeWithLexicalScope): void { + public preserveNameForLexicalScope( + identifierNode: ESTree.Identifier, + lexicalScopeNode: TNodeWithLexicalScope + ): void { this.identifierNamesGenerator.preserveNameForLexicalScope(identifierNode.name, lexicalScopeNode); } @@ -144,14 +147,13 @@ export class IdentifierReplacer implements IIdentifierReplacer { * @param {string} name * @returns {boolean} */ - private isReservedName (name: string): boolean { + private isReservedName(name: string): boolean { if (!this.options.reservedNames.length) { return false; } - return this.options.reservedNames - .some((reservedName: string) => { - return new RegExp(reservedName, 'g').exec(name) !== null; - }); + return this.options.reservedNames.some((reservedName: string) => { + return new RegExp(reservedName, 'g').exec(name) !== null; + }); } } diff --git a/src/node-transformers/rename-identifiers-transformers/through-replacer/ThroughIdentifierReplacer.ts b/src/node-transformers/rename-identifiers-transformers/through-replacer/ThroughIdentifierReplacer.ts index c12da4bd2..9bd4f5137 100644 --- a/src/node-transformers/rename-identifiers-transformers/through-replacer/ThroughIdentifierReplacer.ts +++ b/src/node-transformers/rename-identifiers-transformers/through-replacer/ThroughIdentifierReplacer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -25,9 +25,9 @@ export class ThroughIdentifierReplacer implements IThroughIdentifierReplacer { * @param {IGlobalIdentifierNamesCacheStorage} identifierNamesCacheStorage * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage) - identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage, + identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { this.identifierNamesCacheStorage = identifierNamesCacheStorage; @@ -38,11 +38,12 @@ export class ThroughIdentifierReplacer implements IThroughIdentifierReplacer { * @param {Identifier} identifierNode * @returns {Identifier} */ - public replace (identifierNode: ESTree.Identifier): ESTree.Identifier { + public replace(identifierNode: ESTree.Identifier): ESTree.Identifier { const identifierName: string = identifierNode.name; - const newIdentifierName: string = this.options.identifierNamesCache && !this.isReservedName(identifierName) - ? this.identifierNamesCacheStorage.get(identifierName) ?? identifierName - : identifierName; + const newIdentifierName: string = + this.options.identifierNamesCache && !this.isReservedName(identifierName) + ? (this.identifierNamesCacheStorage.get(identifierName) ?? identifierName) + : identifierName; return NodeFactory.identifierNode(newIdentifierName); } @@ -51,14 +52,13 @@ export class ThroughIdentifierReplacer implements IThroughIdentifierReplacer { * @param {string} name * @returns {boolean} */ - private isReservedName (name: string): boolean { + private isReservedName(name: string): boolean { if (!this.options.reservedNames.length) { return false; } - return this.options.reservedNames - .some((reservedName: string) => { - return new RegExp(reservedName, 'g').exec(name) !== null; - }); + return this.options.reservedNames.some((reservedName: string) => { + return new RegExp(reservedName, 'g').exec(name) !== null; + }); } } diff --git a/src/node-transformers/rename-properties-transformers/RenamePropertiesTransformer.ts b/src/node-transformers/rename-properties-transformers/RenamePropertiesTransformer.ts index 55a321a13..685b6d0d4 100644 --- a/src/node-transformers/rename-properties-transformers/RenamePropertiesTransformer.ts +++ b/src/node-transformers/rename-properties-transformers/RenamePropertiesTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable} from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -28,7 +28,7 @@ export class RenamePropertiesTransformer extends AbstractNodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRenamePropertiesReplacer) renamePropertiesReplacer: IRenamePropertiesReplacer, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions @@ -44,11 +44,8 @@ export class RenamePropertiesTransformer extends AbstractNodeTransformer { * @returns {boolean} */ private static isValidPropertyNode< - TNode extends ESTree.Property - | ESTree.PropertyDefinition - | ESTree.MemberExpression - | ESTree.MethodDefinition - > ( + TNode extends ESTree.Property | ESTree.PropertyDefinition | ESTree.MemberExpression | ESTree.MethodDefinition + >( propertyNode: TNode, propertyKeyNode: ESTree.Expression | ESTree.PrivateIdentifier ): propertyKeyNode is ESTree.Identifier | ESTree.Literal { @@ -63,7 +60,7 @@ export class RenamePropertiesTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Preparing: return { @@ -92,15 +89,14 @@ export class RenamePropertiesTransformer extends AbstractNodeTransformer { * @param {Node} node * @param {Node} parentNode */ - public prepareNode ( - node: ESTree.Node, - parentNode: ESTree.Node - ): void { - if ((NodeGuards.isPropertyNode(parentNode) && parentNode.key === node) - || NodeGuards.isMemberExpressionNode(parentNode) && parentNode.property === node - || NodeGuards.isMethodDefinitionNode(parentNode) && parentNode.key === node - || NodeGuards.isPropertyDefinitionNode(parentNode) && parentNode.key === node) { - NodeMetadata.set(node, {propertyKeyToRenameNode: true}); + public prepareNode(node: ESTree.Node, parentNode: ESTree.Node): void { + if ( + (NodeGuards.isPropertyNode(parentNode) && parentNode.key === node) || + (NodeGuards.isMemberExpressionNode(parentNode) && parentNode.property === node) || + (NodeGuards.isMethodDefinitionNode(parentNode) && parentNode.key === node) || + (NodeGuards.isPropertyDefinitionNode(parentNode) && parentNode.key === node) + ) { + NodeMetadata.set(node, { propertyKeyToRenameNode: true }); return; } @@ -115,7 +111,7 @@ export class RenamePropertiesTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {Node} */ - public transformNode (node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node { + public transformNode(node: ESTree.Node, parentNode: ESTree.Node): ESTree.Node { if (!NodeGuards.isIdentifierNode(node) && !NodeGuards.isLiteralNode(node)) { return node; } @@ -125,10 +121,11 @@ export class RenamePropertiesTransformer extends AbstractNodeTransformer { } const isPropertyNode = NodeGuards.isPropertyNode(parentNode); - const isPropertyLikeNode = isPropertyNode - || NodeGuards.isPropertyDefinitionNode(parentNode) - || NodeGuards.isMemberExpressionNode(parentNode) - || NodeGuards.isMethodDefinitionNode(parentNode); + const isPropertyLikeNode = + isPropertyNode || + NodeGuards.isPropertyDefinitionNode(parentNode) || + NodeGuards.isMemberExpressionNode(parentNode) || + NodeGuards.isMethodDefinitionNode(parentNode); if (isPropertyLikeNode && !RenamePropertiesTransformer.isValidPropertyNode(parentNode, node)) { return node; @@ -145,10 +142,7 @@ export class RenamePropertiesTransformer extends AbstractNodeTransformer { * @param {Node} node * @param {Node} parentNode */ - private analyzeAutoExcludedPropertyNames ( - node: ESTree.Node, - parentNode: ESTree.Node - ): void { + private analyzeAutoExcludedPropertyNames(node: ESTree.Node, parentNode: ESTree.Node): void { if (!NodeGuards.isLiteralNode(node) || !NodeLiteralUtils.isStringLiteralNode(node)) { return; } diff --git a/src/node-transformers/rename-properties-transformers/replacer/RenamePropertiesReplacer.ts b/src/node-transformers/rename-properties-transformers/replacer/RenamePropertiesReplacer.ts index 95cbd95dd..707a49251 100644 --- a/src/node-transformers/rename-properties-transformers/replacer/RenamePropertiesReplacer.ts +++ b/src/node-transformers/rename-properties-transformers/replacer/RenamePropertiesReplacer.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -60,11 +60,11 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer { * @param {IPropertyIdentifierNamesCacheStorage} propertyIdentifierNamesCacheStorage * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IPropertyIdentifierNamesCacheStorage) - propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage, + propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { this.identifierNamesGenerator = identifierNamesGeneratorFactory(options); @@ -75,25 +75,21 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer { /** * @param {string} propertyName */ - public excludePropertyName (propertyName: string): void { - this.excludedPropertyNames.add(propertyName); + public excludePropertyName(propertyName: string): void { + this.excludedPropertyNames.add(propertyName); } /** * @param {ESTree.Identifier | ESTree.Literal} node * @returns {ESTree.Identifier | ESTree.Literal} */ - public replace (node: ESTree.Identifier | ESTree.Literal): ESTree.Identifier | ESTree.Literal { + public replace(node: ESTree.Identifier | ESTree.Literal): ESTree.Identifier | ESTree.Literal { if (NodeGuards.isIdentifierNode(node)) { - return NodeFactory.identifierNode( - this.replacePropertyName(node.name) - ); + return NodeFactory.identifierNode(this.replacePropertyName(node.name)); } if (NodeGuards.isLiteralNode(node) && typeof node.value === 'string') { - return NodeFactory.literalNode( - this.replacePropertyName(node.value) - ); + return NodeFactory.literalNode(this.replacePropertyName(node.value)); } return node; @@ -104,7 +100,7 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer { * @returns {string} * @private */ - private replacePropertyName (propertyName: string): string { + private replacePropertyName(propertyName: string): string { if (this.isReservedName(propertyName)) { this.identifierNamesGenerator.preserveName(propertyName); @@ -112,12 +108,10 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer { } let renamedPropertyName: string | null = this.options.identifierNamesCache - ? this.propertyIdentifierNamesCacheStorage.get(propertyName) ?? null + ? (this.propertyIdentifierNamesCacheStorage.get(propertyName) ?? null) : null; - renamedPropertyName = renamedPropertyName - ?? this.propertyNamesMap.get(propertyName) - ?? null; + renamedPropertyName = renamedPropertyName ?? this.propertyNamesMap.get(propertyName) ?? null; if (renamedPropertyName !== null) { return renamedPropertyName; @@ -137,17 +131,15 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer { * @param {string} name * @returns {boolean} */ - private isReservedName (name: string): boolean { - return this.isExcludedName(name) - || this.isReservedOptionName(name) - || this.isReservedDomPropertyName(name); + private isReservedName(name: string): boolean { + return this.isExcludedName(name) || this.isReservedOptionName(name) || this.isReservedDomPropertyName(name); } /** * @param {string} name * @returns {boolean} */ - private isExcludedName (name: string): boolean { + private isExcludedName(name: string): boolean { return this.excludedPropertyNames.has(name); } @@ -155,22 +147,21 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer { * @param {string} name * @returns {boolean} */ - private isReservedOptionName (name: string): boolean { + private isReservedOptionName(name: string): boolean { if (!this.options.reservedNames.length) { return false; } - return this.options.reservedNames - .some((reservedName: string) => { - return new RegExp(reservedName, 'g').exec(name) !== null; - }); + return this.options.reservedNames.some((reservedName: string) => { + return new RegExp(reservedName, 'g').exec(name) !== null; + }); } /** * @param {string} name * @returns {boolean} */ - private isReservedDomPropertyName (name: string): boolean { + private isReservedDomPropertyName(name: string): boolean { return RenamePropertiesReplacer.reservedDomPropertiesList.has(name); } } diff --git a/src/node-transformers/simplifying-transformers/AbstractStatementSimplifyTransformer.ts b/src/node-transformers/simplifying-transformers/AbstractStatementSimplifyTransformer.ts index 24d926618..9014aa3a5 100644 --- a/src/node-transformers/simplifying-transformers/AbstractStatementSimplifyTransformer.ts +++ b/src/node-transformers/simplifying-transformers/AbstractStatementSimplifyTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -31,7 +31,7 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -44,7 +44,7 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT * @param {ESTree.Statement | null | undefined} statementNode * @returns {IStatementSimplifyData | null} */ - protected getStatementSimplifyData ( + protected getStatementSimplifyData( statementNode: ESTree.Statement | null | undefined ): IStatementSimplifyData | null { if (!statementNode) { @@ -60,12 +60,8 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT }; } - const { - startIndex, - unwrappedExpressions, - hasReturnStatement, - hasStatementsAfterReturnStatement - } = this.collectIteratedStatementsSimplifyData(statementNode); + const { startIndex, unwrappedExpressions, hasReturnStatement, hasStatementsAfterReturnStatement } = + this.collectIteratedStatementsSimplifyData(statementNode); if (hasStatementsAfterReturnStatement) { return { @@ -114,7 +110,7 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT * @param {ESTree.Statement | null | undefined} statementNode * @returns {IIteratedStatementsSimplifyData} */ - protected collectIteratedStatementsSimplifyData ( + protected collectIteratedStatementsSimplifyData( statementNode: ESTree.BlockStatement ): IIteratedStatementsSimplifyData { const statementNodeBodyLength: number = statementNode.body.length; @@ -138,10 +134,7 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT continue; } - if ( - NodeGuards.isReturnStatementNode(statementBodyStatementNode) - && statementBodyStatementNode.argument - ) { + if (NodeGuards.isReturnStatementNode(statementBodyStatementNode) && statementBodyStatementNode.argument) { unwrappedExpressions.unshift(statementBodyStatementNode.argument); hasReturnStatement = true; hasStatementsAfterReturnStatement = i !== statementNodeBodyLength - 1; @@ -167,24 +160,27 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT * @param {number | null} startIndex * @returns {ESTree.Statement[]} */ - protected getLeadingStatements (statementNode: ESTree.BlockStatement, startIndex: number | null): ESTree.Statement[] { + protected getLeadingStatements( + statementNode: ESTree.BlockStatement, + startIndex: number | null + ): ESTree.Statement[] { // variant #1: no valid statements inside `BlockStatement` are found if (startIndex === null) { return statementNode.body; } return startIndex === 0 - // variant #2: all statements inside `BlockStatement` branch are valid - ? [] - // variant #3: only last N statements inside `BlockStatement` branch are valid - : statementNode.body.slice(0, startIndex); + ? // variant #2: all statements inside `BlockStatement` branch are valid + [] + : // variant #3: only last N statements inside `BlockStatement` branch are valid + statementNode.body.slice(0, startIndex); } /** * @param {IStatementSimplifyData} statementSimplifyData * @returns {ESTree.Statement} */ - protected getPartialStatement (statementSimplifyData: IStatementSimplifyData): ESTree.Statement { + protected getPartialStatement(statementSimplifyData: IStatementSimplifyData): ESTree.Statement { // variant #1: all statements inside `BlockStatement` branch are valid if (!statementSimplifyData.leadingStatements.length && statementSimplifyData.trailingStatement) { return statementSimplifyData.trailingStatement.statement; @@ -192,8 +188,8 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT // variant #2: only last N statements inside `BlockStatement` branch are valid return NodeFactory.blockStatementNode([ - ...statementSimplifyData.leadingStatements.length ? statementSimplifyData.leadingStatements : [], - ...statementSimplifyData.trailingStatement ? [statementSimplifyData.trailingStatement.statement] : [] + ...(statementSimplifyData.leadingStatements.length ? statementSimplifyData.leadingStatements : []), + ...(statementSimplifyData.trailingStatement ? [statementSimplifyData.trailingStatement.statement] : []) ]); } @@ -202,8 +198,5 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT * @param {ESTree.Node} parentNode * @returns {ESTree.Node} */ - public abstract override transformNode ( - statementNode: ESTree.Statement, - parentNode: ESTree.Node - ): ESTree.Node; + public abstract override transformNode(statementNode: ESTree.Statement, parentNode: ESTree.Node): ESTree.Node; } diff --git a/src/node-transformers/simplifying-transformers/BlockStatementSimplifyTransformer.ts b/src/node-transformers/simplifying-transformers/BlockStatementSimplifyTransformer.ts index 89d60ad48..010f9b5c9 100644 --- a/src/node-transformers/simplifying-transformers/BlockStatementSimplifyTransformer.ts +++ b/src/node-transformers/simplifying-transformers/BlockStatementSimplifyTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -24,15 +24,13 @@ export class BlockStatementSimplifyTransformer extends AbstractStatementSimplify /** * @type {NodeTransformer[]} */ - public override readonly runAfter: NodeTransformer[] = [ - NodeTransformer.VariableDeclarationsMergeTransformer - ]; + public override readonly runAfter: NodeTransformer[] = [NodeTransformer.VariableDeclarationsMergeTransformer]; /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -43,14 +41,11 @@ export class BlockStatementSimplifyTransformer extends AbstractStatementSimplify * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Simplifying: return { - leave: ( - node: ESTree.Node, - parentNode: ESTree.Node | null - ): ESTree.Node | undefined => { + leave: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => { if (parentNode && NodeGuards.isBlockStatementNode(node)) { return this.transformNode(node, parentNode); } @@ -67,10 +62,7 @@ export class BlockStatementSimplifyTransformer extends AbstractStatementSimplify * @param {ESTree.Node} parentNode * @returns {ESTree.Node} */ - public transformNode ( - statementNode: ESTree.Statement, - parentNode: ESTree.Node - ): ESTree.Node { + public transformNode(statementNode: ESTree.Statement, parentNode: ESTree.Node): ESTree.Node { const simplifyData: IStatementSimplifyData | null = this.getStatementSimplifyData(statementNode); if (!simplifyData) { diff --git a/src/node-transformers/simplifying-transformers/ExpressionStatementsMergeTransformer.ts b/src/node-transformers/simplifying-transformers/ExpressionStatementsMergeTransformer.ts index fd942f35a..ef2dcf818 100644 --- a/src/node-transformers/simplifying-transformers/ExpressionStatementsMergeTransformer.ts +++ b/src/node-transformers/simplifying-transformers/ExpressionStatementsMergeTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -32,7 +32,7 @@ export class ExpressionStatementsMergeTransformer extends AbstractNodeTransforme * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -43,7 +43,7 @@ export class ExpressionStatementsMergeTransformer extends AbstractNodeTransforme * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Simplifying: return { @@ -67,7 +67,7 @@ export class ExpressionStatementsMergeTransformer extends AbstractNodeTransforme * @param {ESTree.Node} parentNode * @returns {ESTree.ExpressionStatement | estraverse.VisitorOption} */ - public transformNode ( + public transformNode( expressionStatementNode: ESTree.ExpressionStatement, parentNode: ESTree.Node ): ESTree.ExpressionStatement | estraverse.VisitorOption { @@ -75,7 +75,8 @@ export class ExpressionStatementsMergeTransformer extends AbstractNodeTransforme return expressionStatementNode; } - const prevStatement: TStatement | null = NodeStatementUtils.getPreviousSiblingStatement(expressionStatementNode); + const prevStatement: TStatement | null = + NodeStatementUtils.getPreviousSiblingStatement(expressionStatementNode); if (!prevStatement || !NodeGuards.isExpressionStatementNode(prevStatement)) { return expressionStatementNode; diff --git a/src/node-transformers/simplifying-transformers/IfStatementSimplifyTransformer.ts b/src/node-transformers/simplifying-transformers/IfStatementSimplifyTransformer.ts index cdb548453..7ff89e296 100644 --- a/src/node-transformers/simplifying-transformers/IfStatementSimplifyTransformer.ts +++ b/src/node-transformers/simplifying-transformers/IfStatementSimplifyTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -24,7 +24,7 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -35,14 +35,11 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Simplifying: return { - leave: ( - node: ESTree.Node, - parentNode: ESTree.Node | null - ): ESTree.Node | undefined => { + leave: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => { if (parentNode && NodeGuards.isIfStatementNode(node)) { return this.transformNode(node, parentNode); } @@ -59,11 +56,10 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * @param {ESTree.Node} parentNode * @returns {ESTree.IfStatement} */ - public transformNode ( - ifStatementNode: ESTree.IfStatement, - parentNode: ESTree.Node - ): ESTree.Node { - const consequentSimplifyData: IStatementSimplifyData | null = this.getStatementSimplifyData(ifStatementNode.consequent); + public transformNode(ifStatementNode: ESTree.IfStatement, parentNode: ESTree.Node): ESTree.Node { + const consequentSimplifyData: IStatementSimplifyData | null = this.getStatementSimplifyData( + ifStatementNode.consequent + ); // Variant #1: no valid consequent expression data if (!consequentSimplifyData) { @@ -76,14 +72,20 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra // Variant #2: valid data for consequent expression only transformedNode = this.getConsequentNode(ifStatementNode, consequentSimplifyData); } else { - const alternateSimplifyData: IStatementSimplifyData | null = this.getStatementSimplifyData(ifStatementNode.alternate); + const alternateSimplifyData: IStatementSimplifyData | null = this.getStatementSimplifyData( + ifStatementNode.alternate + ); if (!alternateSimplifyData) { return ifStatementNode; } // Variant #3: valid data for consequent and alternate expressions - transformedNode = this.getConsequentAndAlternateNode(ifStatementNode, consequentSimplifyData, alternateSimplifyData); + transformedNode = this.getConsequentAndAlternateNode( + ifStatementNode, + consequentSimplifyData, + alternateSimplifyData + ); } return NodeUtils.parentizeNode(transformedNode, parentNode); @@ -94,7 +96,7 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * @param {IStatementSimplifyData} consequentSimplifyData * @returns {ESTree.Node} */ - protected getConsequentNode ( + protected getConsequentNode( ifStatementNode: ESTree.IfStatement, consequentSimplifyData: IStatementSimplifyData ): ESTree.Node { @@ -112,14 +114,8 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * return console.log(1), 1; * } */ - if ( - consequentSimplifyData.leadingStatements.length - || !consequentSimplifyData.trailingStatement - ) { - return NodeFactory.ifStatementNode( - ifStatementNode.test, - this.getPartialStatement(consequentSimplifyData) - ); + if (consequentSimplifyData.leadingStatements.length || !consequentSimplifyData.trailingStatement) { + return NodeFactory.ifStatementNode(ifStatementNode.test, this.getPartialStatement(consequentSimplifyData)); } /** @@ -163,7 +159,7 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * @param {IStatementSimplifyData} alternateSimplifyData * @returns {ESTree.Node} */ - protected getConsequentAndAlternateNode ( + protected getConsequentAndAlternateNode( ifStatementNode: ESTree.IfStatement, consequentSimplifyData: IStatementSimplifyData, alternateSimplifyData: IStatementSimplifyData @@ -183,10 +179,10 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * } */ if ( - consequentSimplifyData.leadingStatements.length - || alternateSimplifyData.leadingStatements.length - || !consequentSimplifyData.trailingStatement - || !alternateSimplifyData.trailingStatement + consequentSimplifyData.leadingStatements.length || + alternateSimplifyData.leadingStatements.length || + !consequentSimplifyData.trailingStatement || + !alternateSimplifyData.trailingStatement ) { return NodeFactory.ifStatementNode( ifStatementNode.test, @@ -262,29 +258,29 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * @param {IStatementSimplifyData} statementSimplifyData * @returns {ESTree.Statement} */ - protected override getPartialStatement (statementSimplifyData: IStatementSimplifyData): ESTree.Statement { + protected override getPartialStatement(statementSimplifyData: IStatementSimplifyData): ESTree.Statement { const partialStatement: ESTree.Statement = super.getPartialStatement(statementSimplifyData); if (!NodeGuards.isBlockStatementNode(partialStatement)) { return partialStatement; } - return partialStatement.body.length === 1 - && !this.isProhibitedSingleStatementForIfStatementBranch(partialStatement.body[0]) + return partialStatement.body.length === 1 && + !this.isProhibitedSingleStatementForIfStatementBranch(partialStatement.body[0]) ? partialStatement.body[0] : partialStatement; - } /** * @param {ESTree.Statement} statement * @returns {boolean} */ - protected isProhibitedSingleStatementForIfStatementBranch (statement: ESTree.Statement): boolean { + protected isProhibitedSingleStatementForIfStatementBranch(statement: ESTree.Statement): boolean { /** * Function declaration is not allowed outside of block in `strict` mode */ - return NodeGuards.isFunctionDeclarationNode(statement) + return ( + NodeGuards.isFunctionDeclarationNode(statement) || /** * Have to ignore all `IfStatement` nodes * Also have to ignore any nodes with a single statement as a `body` @@ -307,9 +303,8 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * * See issue: https://github.com/javascript-obfuscator/javascript-obfuscator/issues/860 */ - || NodeGuards.isIfStatementNode(statement) - || NodeGuards.isNodeWithSingleStatementBody(statement) - + NodeGuards.isIfStatementNode(statement) || + NodeGuards.isNodeWithSingleStatementBody(statement) || /** * `let` and `const` variable declarations are not allowed outside of `IfStatement` block statement * Input: @@ -321,6 +316,7 @@ export class IfStatementSimplifyTransformer extends AbstractStatementSimplifyTra * if (condition1) * const foo = 1; */ - || (NodeGuards.isVariableDeclarationNode(statement) && statement.kind !== 'var'); + (NodeGuards.isVariableDeclarationNode(statement) && statement.kind !== 'var') + ); } } diff --git a/src/node-transformers/simplifying-transformers/VariableDeclarationsMergeTransformer.ts b/src/node-transformers/simplifying-transformers/VariableDeclarationsMergeTransformer.ts index 613f96277..d89c5c03a 100644 --- a/src/node-transformers/simplifying-transformers/VariableDeclarationsMergeTransformer.ts +++ b/src/node-transformers/simplifying-transformers/VariableDeclarationsMergeTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -31,7 +31,7 @@ export class VariableDeclarationsMergeTransformer extends AbstractNodeTransforme * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -42,7 +42,7 @@ export class VariableDeclarationsMergeTransformer extends AbstractNodeTransforme * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.Simplifying: return { @@ -66,7 +66,7 @@ export class VariableDeclarationsMergeTransformer extends AbstractNodeTransforme * @param {ESTree.Node} parentNode * @returns {ESTree.VariableDeclaration | estraverse.VisitorOption} */ - public transformNode ( + public transformNode( variableDeclarationNode: ESTree.VariableDeclaration, parentNode: ESTree.Node ): ESTree.VariableDeclaration | estraverse.VisitorOption { @@ -74,7 +74,8 @@ export class VariableDeclarationsMergeTransformer extends AbstractNodeTransforme return variableDeclarationNode; } - const prevStatement: TStatement | null = NodeStatementUtils.getPreviousSiblingStatement(variableDeclarationNode); + const prevStatement: TStatement | null = + NodeStatementUtils.getPreviousSiblingStatement(variableDeclarationNode); if (!prevStatement || !NodeGuards.isVariableDeclarationNode(prevStatement)) { return variableDeclarationNode; diff --git a/src/node-transformers/string-array-transformers/StringArrayRotateFunctionTransformer.ts b/src/node-transformers/string-array-transformers/StringArrayRotateFunctionTransformer.ts index eac0bcba8..4788a9434 100644 --- a/src/node-transformers/string-array-transformers/StringArrayRotateFunctionTransformer.ts +++ b/src/node-transformers/string-array-transformers/StringArrayRotateFunctionTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from '@javascript-obfuscator/estraverse'; @@ -86,7 +86,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme * @param {TCustomCodeHelperFactory} customCodeHelperFactory * @param {INumberNumericalExpressionAnalyzer} numberNumericalExpressionAnalyzer */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @inject(ServiceIdentifiers.INodeTransformersRunner) transformersRunner: INodeTransformersRunner, @@ -94,7 +94,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme @inject(ServiceIdentifiers.IStringArrayStorageAnalyzer) stringArrayStorageAnalyzer: IStringArrayStorageAnalyzer, @inject(ServiceIdentifiers.Factory__ICustomCodeHelper) customCodeHelperFactory: TCustomCodeHelperFactory, @inject(ServiceIdentifiers.INumberNumericalExpressionAnalyzer) - numberNumericalExpressionAnalyzer: INumberNumericalExpressionAnalyzer + numberNumericalExpressionAnalyzer: INumberNumericalExpressionAnalyzer ) { super(randomGenerator, options); @@ -112,15 +112,12 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme * @param {Program} programNode * @returns {boolean} */ - private static isProgramNodeHasStringLiterals (programNode: ESTree.Program): boolean { + private static isProgramNodeHasStringLiterals(programNode: ESTree.Program): boolean { let hasStringLiterals: boolean = false; estraverse.traverse(programNode, { enter: (node: ESTree.Node): estraverse.VisitorOption | void => { - if ( - NodeGuards.isLiteralNode(node) - && NodeLiteralUtils.isStringLiteralNode(node) - ) { + if (NodeGuards.isLiteralNode(node) && NodeLiteralUtils.isStringLiteralNode(node)) { hasStringLiterals = true; return estraverse.VisitorOption.Break; @@ -135,7 +132,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { if (!this.options.stringArrayRotate) { return null; } @@ -165,7 +162,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme * @param {Program} programNode * @returns {Node} */ - public transformNode (programNode: ESTree.Program): ESTree.Node { + public transformNode(programNode: ESTree.Program): ESTree.Node { const stringArrayRotateFunctionNode: TStatement = this.getStringArrayRotateFunctionNode(); const wrappedStringArrayRotateFunctionNode: ESTree.Program = NodeFactory.programNode([ stringArrayRotateFunctionNode @@ -193,10 +190,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme // as ignored to prevent additional transformation of these nodes estraverse.traverse(wrappedStringArrayRotateFunctionNode, { enter: (node: ESTree.Node): void => { - if ( - !NodeGuards.isLiteralNode(node) - || !NodeLiteralUtils.isStringLiteralNode(node) - ) { + if (!NodeGuards.isLiteralNode(node) || !NodeLiteralUtils.isStringLiteralNode(node)) { return; } @@ -205,7 +199,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme if (this.isComparisonExpressionStringLiteralNode(node)) { this.stringArrayStorageAnalyzer.addItemDataForLiteralNode(node); } else { - NodeMetadata.set(node, {ignoredNode: true}); + NodeMetadata.set(node, { ignoredNode: true }); } } }); @@ -218,7 +212,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme /** * @returns {TStatement} */ - private getStringArrayRotateFunctionNode (): TStatement { + private getStringArrayRotateFunctionNode(): TStatement { const comparisonValue: number = this.getComparisonValue(); const comparisonExpressionNumberNumericalExpressionData: TNumberNumericalExpressionData = this.numberNumericalExpressionAnalyzer.analyze( @@ -227,37 +221,36 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme ); let index: number = 1; - const comparisonExpressionNode: ESTree.Expression = NumericalExpressionDataToNodeConverter.convertIntegerNumberData( - comparisonExpressionNumberNumericalExpressionData, - ((number: number, isPositiveNumber) => { - const multipliedNumber: number = number * index; - const literalNode: ESTree.Literal = NodeFactory.literalNode( - `${multipliedNumber}${this.randomGenerator.getRandomString(6)}` - ); - const parseIntCallExpression: ESTree.CallExpression = NodeFactory.callExpressionNode( - NodeFactory.identifierNode('parseInt'), - [literalNode] - ); - - const binaryExpressionNode: ESTree.BinaryExpression = NodeFactory.binaryExpressionNode( - '/', - isPositiveNumber - ? parseIntCallExpression - : NodeFactory.unaryExpressionNode( - '-', - parseIntCallExpression - ), - NodeFactory.literalNode(index, index.toString()) - ); - - index++; - - return binaryExpressionNode; - }) - ); + const comparisonExpressionNode: ESTree.Expression = + NumericalExpressionDataToNodeConverter.convertIntegerNumberData( + comparisonExpressionNumberNumericalExpressionData, + (number: number, isPositiveNumber) => { + const multipliedNumber: number = number * index; + const literalNode: ESTree.Literal = NodeFactory.literalNode( + `${multipliedNumber}${this.randomGenerator.getRandomString(6)}` + ); + const parseIntCallExpression: ESTree.CallExpression = NodeFactory.callExpressionNode( + NodeFactory.identifierNode('parseInt'), + [literalNode] + ); + + const binaryExpressionNode: ESTree.BinaryExpression = NodeFactory.binaryExpressionNode( + '/', + isPositiveNumber + ? parseIntCallExpression + : NodeFactory.unaryExpressionNode('-', parseIntCallExpression), + NodeFactory.literalNode(index, index.toString()) + ); + + index++; + + return binaryExpressionNode; + } + ); - const stringArrayRotateFunctionCodeHelper: ICustomCodeHelper> = - this.customCodeHelperFactory(CustomCodeHelper.StringArrayRotateFunction); + const stringArrayRotateFunctionCodeHelper: ICustomCodeHelper< + TInitialData + > = this.customCodeHelperFactory(CustomCodeHelper.StringArrayRotateFunction); stringArrayRotateFunctionCodeHelper.initialize( this.stringArrayStorage.getStorageName(), @@ -272,7 +265,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme * @param {TStringLiteralNode} stringLiteralNode * @returns {boolean} */ - private isComparisonExpressionStringLiteralNode (stringLiteralNode: TStringLiteralNode): boolean { + private isComparisonExpressionStringLiteralNode(stringLiteralNode: TStringLiteralNode): boolean { return /\d/.test(stringLiteralNode.value); } @@ -281,7 +274,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme * * @returns {number} */ - private getComparisonValue (): number { + private getComparisonValue(): number { return this.randomGenerator.getRandomInteger(100000, 1_000_000); } } diff --git a/src/node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer.ts b/src/node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer.ts index 9f8c32e01..68a7eb3ec 100644 --- a/src/node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer.ts +++ b/src/node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -35,9 +35,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo /** * @type {NodeTransformer[]} */ - public override readonly runAfter: NodeTransformer[] = [ - NodeTransformer.StringArrayRotateFunctionTransformer - ]; + public override readonly runAfter: NodeTransformer[] = [NodeTransformer.StringArrayRotateFunctionTransformer]; /** * @type {IStringArrayStorage} @@ -67,14 +65,16 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo * @param {IStringArrayScopeCallsWrappersDataStorage} stringArrayScopeCallsWrappersDataStorage * @param {TStringArrayCustomNodeFactory} stringArrayTransformerCustomNodeFactory */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, - @inject(ServiceIdentifiers.IVisitedLexicalScopeNodesStackStorage) visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage, + @inject(ServiceIdentifiers.IVisitedLexicalScopeNodesStackStorage) + visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage, @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage, - @inject(ServiceIdentifiers.IStringArrayScopeCallsWrappersDataStorage) stringArrayScopeCallsWrappersDataStorage: IStringArrayScopeCallsWrappersDataStorage, + @inject(ServiceIdentifiers.IStringArrayScopeCallsWrappersDataStorage) + stringArrayScopeCallsWrappersDataStorage: IStringArrayScopeCallsWrappersDataStorage, @inject(ServiceIdentifiers.Factory__IStringArrayCustomNode) - stringArrayTransformerCustomNodeFactory: TStringArrayCustomNodeFactory + stringArrayTransformerCustomNodeFactory: TStringArrayCustomNodeFactory ) { super(randomGenerator, options); @@ -88,7 +88,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { if (!this.options.stringArrayWrappersCount) { return null; } @@ -119,9 +119,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo * @param {TNodeWithLexicalScopeStatements} lexicalScopeBodyNode * @returns {TNodeWithLexicalScopeStatements} */ - public transformNode ( - lexicalScopeBodyNode: TNodeWithLexicalScopeStatements - ): TNodeWithLexicalScopeStatements { + public transformNode(lexicalScopeBodyNode: TNodeWithLexicalScopeStatements): TNodeWithLexicalScopeStatements { const stringArrayScopeCallsWrappersDataByEncoding: TStringArrayScopeCallsWrappersDataByEncoding | null = this.stringArrayScopeCallsWrappersDataStorage.get(lexicalScopeBodyNode) ?? null; @@ -129,8 +127,9 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo return lexicalScopeBodyNode; } - const stringArrayScopeCallsWrappersDataList: (IStringArrayScopeCallsWrappersData | undefined)[] = - Object.values(stringArrayScopeCallsWrappersDataByEncoding); + const stringArrayScopeCallsWrappersDataList: (IStringArrayScopeCallsWrappersData | undefined)[] = Object.values( + stringArrayScopeCallsWrappersDataByEncoding + ); // iterates over data for each encoding type for (const stringArrayScopeCallsWrappersData of stringArrayScopeCallsWrappersDataList) { @@ -138,7 +137,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo continue; } - const {scopeCallsWrappersData} = stringArrayScopeCallsWrappersData; + const { scopeCallsWrappersData } = stringArrayScopeCallsWrappersData; const scopeCallsWrappersDataLength: number = scopeCallsWrappersData.length; /** @@ -147,8 +146,9 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo */ for (let i = scopeCallsWrappersDataLength - 1; i >= 0; i--) { const stringArrayScopeCallsWrapperData = scopeCallsWrappersData[i]; - const upperStringArrayCallsWrapperData = - this.getUpperStringArrayCallsWrapperData(stringArrayScopeCallsWrappersData); + const upperStringArrayCallsWrapperData = this.getUpperStringArrayCallsWrapperData( + stringArrayScopeCallsWrappersData + ); this.getAndAppendStringArrayScopeCallsWrapperNode( lexicalScopeBodyNode, @@ -165,10 +165,10 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo * @param {IStringArrayScopeCallsWrappersData} stringArrayScopeCallsWrappersData * @returns {IStringArrayScopeCallsWrapperData} */ - private getRootStringArrayCallsWrapperData ( - stringArrayScopeCallsWrappersData: IStringArrayScopeCallsWrappersData, + private getRootStringArrayCallsWrapperData( + stringArrayScopeCallsWrappersData: IStringArrayScopeCallsWrappersData ): IStringArrayScopeCallsWrapperData { - const {encoding} = stringArrayScopeCallsWrappersData; + const { encoding } = stringArrayScopeCallsWrappersData; return { name: this.stringArrayStorage.getStorageCallsWrapperName(encoding), @@ -181,29 +181,28 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo * @param {IStringArrayScopeCallsWrappersData} stringArrayScopeCallsWrappersData * @returns {IStringArrayScopeCallsWrapperData} */ - private getUpperStringArrayCallsWrapperData ( - stringArrayScopeCallsWrappersData: IStringArrayScopeCallsWrappersData, + private getUpperStringArrayCallsWrapperData( + stringArrayScopeCallsWrappersData: IStringArrayScopeCallsWrappersData ): IStringArrayScopeCallsWrapperData { - const {encoding} = stringArrayScopeCallsWrappersData; + const { encoding } = stringArrayScopeCallsWrappersData; - const rootStringArrayCallsWrapperData = - this.getRootStringArrayCallsWrapperData(stringArrayScopeCallsWrappersData); + const rootStringArrayCallsWrapperData = this.getRootStringArrayCallsWrapperData( + stringArrayScopeCallsWrappersData + ); if (!this.options.stringArrayWrappersChainedCalls) { return rootStringArrayCallsWrapperData; } const parentLexicalScopeBodyNode: TNodeWithLexicalScopeStatements | null = - this.visitedLexicalScopeNodesStackStorage.getLastElement() - ?? null; + this.visitedLexicalScopeNodesStackStorage.getLastElement() ?? null; if (!parentLexicalScopeBodyNode) { return rootStringArrayCallsWrapperData; } const parentLexicalScopeCallsWrappersDataByEncoding: TStringArrayScopeCallsWrappersDataByEncoding | null = - this.stringArrayScopeCallsWrappersDataStorage - .get(parentLexicalScopeBodyNode) ?? null; + this.stringArrayScopeCallsWrappersDataStorage.get(parentLexicalScopeBodyNode) ?? null; const parentScopeCallsWrappersData: IStringArrayScopeCallsWrapperData[] | null = parentLexicalScopeCallsWrappersDataByEncoding?.[encoding]?.scopeCallsWrappersData ?? null; @@ -211,9 +210,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo return rootStringArrayCallsWrapperData; } - return this.randomGenerator - .getRandomGenerator() - .pickone(parentScopeCallsWrappersData); + return this.randomGenerator.getRandomGenerator().pickone(parentScopeCallsWrappersData); } /** @@ -221,10 +218,10 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo * @param {IStringArrayScopeCallsWrapperData} stringArrayScopeCallsWrapperData * @param {IStringArrayScopeCallsWrapperData} upperStringArrayCallsWrapperData */ - private getAndAppendStringArrayScopeCallsWrapperNode ( + private getAndAppendStringArrayScopeCallsWrapperNode( lexicalScopeBodyNode: TNodeWithLexicalScopeStatements, stringArrayScopeCallsWrapperData: IStringArrayScopeCallsWrapperData, - upperStringArrayCallsWrapperData: IStringArrayScopeCallsWrapperData, + upperStringArrayCallsWrapperData: IStringArrayScopeCallsWrapperData ): void { let stringArrayScopeCallsWrapperNode: TStatement[]; @@ -237,14 +234,10 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo stringArrayScopeCallsWrapperNode = this.getStringArrayScopeCallsWrapperFunctionNode( stringArrayScopeCallsWrapperData, - upperStringArrayCallsWrapperData, + upperStringArrayCallsWrapperData ); - NodeAppender.insertAtIndex( - lexicalScopeBodyNode, - stringArrayScopeCallsWrapperNode, - randomIndex - ); + NodeAppender.insertAtIndex(lexicalScopeBodyNode, stringArrayScopeCallsWrapperNode, randomIndex); break; } @@ -256,10 +249,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo upperStringArrayCallsWrapperData ); - NodeAppender.prepend( - lexicalScopeBodyNode, - stringArrayScopeCallsWrapperNode - ); + NodeAppender.prepend(lexicalScopeBodyNode, stringArrayScopeCallsWrapperNode); } } } @@ -269,14 +259,15 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo * @param {IStringArrayScopeCallsWrapperData} upperStringArrayCallsWrapperData * @returns {TStatement[]} */ - private getStringArrayScopeCallsWrapperVariableNode ( + private getStringArrayScopeCallsWrapperVariableNode( stringArrayScopeCallsWrapperData: IStringArrayScopeCallsWrapperData, upperStringArrayCallsWrapperData: IStringArrayScopeCallsWrapperData ): TStatement[] { - const stringArrayScopeCallsWrapperVariableNode: ICustomNode> = - this.stringArrayTransformerCustomNodeFactory( - StringArrayCustomNode.StringArrayScopeCallsWrapperVariableNode - ); + const stringArrayScopeCallsWrapperVariableNode: ICustomNode< + TInitialData + > = this.stringArrayTransformerCustomNodeFactory( + StringArrayCustomNode.StringArrayScopeCallsWrapperVariableNode + ); stringArrayScopeCallsWrapperVariableNode.initialize( stringArrayScopeCallsWrapperData, @@ -291,14 +282,15 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo * @param {IStringArrayScopeCallsWrapperData} upperStringArrayCallsWrapperData * @returns {TStatement[]} */ - private getStringArrayScopeCallsWrapperFunctionNode ( + private getStringArrayScopeCallsWrapperFunctionNode( stringArrayScopeCallsWrapperData: IStringArrayScopeCallsWrapperData, - upperStringArrayCallsWrapperData: IStringArrayScopeCallsWrapperData, + upperStringArrayCallsWrapperData: IStringArrayScopeCallsWrapperData ): TStatement[] { - const stringArrayScopeCallsWrapperFunctionNode: ICustomNode> = - this.stringArrayTransformerCustomNodeFactory( - StringArrayCustomNode.StringArrayScopeCallsWrapperFunctionNode - ); + const stringArrayScopeCallsWrapperFunctionNode: ICustomNode< + TInitialData + > = this.stringArrayTransformerCustomNodeFactory( + StringArrayCustomNode.StringArrayScopeCallsWrapperFunctionNode + ); stringArrayScopeCallsWrapperFunctionNode.initialize( stringArrayScopeCallsWrapperData, @@ -311,11 +303,11 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo /** * @param {TNodeWithLexicalScopeStatements} lexicalScopeBodyNode */ - private onLexicalScopeNodeEnter (lexicalScopeBodyNode: TNodeWithLexicalScopeStatements): void { + private onLexicalScopeNodeEnter(lexicalScopeBodyNode: TNodeWithLexicalScopeStatements): void { this.visitedLexicalScopeNodesStackStorage.push(lexicalScopeBodyNode); } - private onLexicalScopeNodeLeave (): void { + private onLexicalScopeNodeLeave(): void { this.visitedLexicalScopeNodesStackStorage.pop(); } } diff --git a/src/node-transformers/string-array-transformers/StringArrayTransformer.ts b/src/node-transformers/string-array-transformers/StringArrayTransformer.ts index 5bd33e10e..6c80f5733 100644 --- a/src/node-transformers/string-array-transformers/StringArrayTransformer.ts +++ b/src/node-transformers/string-array-transformers/StringArrayTransformer.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; @@ -51,9 +51,7 @@ export class StringArrayTransformer extends AbstractNodeTransformer { /** * @type {NodeTransformer[]} */ - public override readonly runAfter: NodeTransformer[] = [ - NodeTransformer.StringArrayRotateFunctionTransformer - ]; + public override readonly runAfter: NodeTransformer[] = [NodeTransformer.StringArrayRotateFunctionTransformer]; /** * @type {IIdentifierNamesGenerator} @@ -101,19 +99,20 @@ export class StringArrayTransformer extends AbstractNodeTransformer { * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory * @param {TStringArrayCustomNodeFactory} stringArrayTransformerCustomNodeFactory */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @inject(ServiceIdentifiers.ILiteralNodesCacheStorage) literalNodesCacheStorage: ILiteralNodesCacheStorage, - @inject(ServiceIdentifiers.IVisitedLexicalScopeNodesStackStorage) visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage, + @inject(ServiceIdentifiers.IVisitedLexicalScopeNodesStackStorage) + visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage, @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage, @inject(ServiceIdentifiers.IStringArrayScopeCallsWrappersDataStorage) - stringArrayScopeCallsWrappersDataStorage: IStringArrayScopeCallsWrappersDataStorage, + stringArrayScopeCallsWrappersDataStorage: IStringArrayScopeCallsWrappersDataStorage, @inject(ServiceIdentifiers.IStringArrayStorageAnalyzer) stringArrayStorageAnalyzer: IStringArrayStorageAnalyzer, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.Factory__IStringArrayCustomNode) - stringArrayTransformerCustomNodeFactory: TStringArrayCustomNodeFactory + stringArrayTransformerCustomNodeFactory: TStringArrayCustomNodeFactory ) { super(randomGenerator, options); @@ -130,7 +129,7 @@ export class StringArrayTransformer extends AbstractNodeTransformer { * @param {NodeTransformationStage} nodeTransformationStage * @returns {IVisitor | null} */ - public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null { + public getVisitor(nodeTransformationStage: NodeTransformationStage): IVisitor | null { switch (nodeTransformationStage) { case NodeTransformationStage.StringArray: return { @@ -140,9 +139,9 @@ export class StringArrayTransformer extends AbstractNodeTransformer { } if ( - parentNode - && NodeGuards.isLiteralNode(node) - && !NodeMetadata.isStringArrayCallLiteralNode(node) + parentNode && + NodeGuards.isLiteralNode(node) && + !NodeMetadata.isStringArrayCallLiteralNode(node) ) { return this.transformNode(node, parentNode); } @@ -157,7 +156,7 @@ export class StringArrayTransformer extends AbstractNodeTransformer { /** * @param {Program} programNode */ - public prepareNode (programNode: ESTree.Program): void { + public prepareNode(programNode: ESTree.Program): void { if (this.options.stringArray) { this.stringArrayStorageAnalyzer.analyze(programNode); } @@ -176,10 +175,10 @@ export class StringArrayTransformer extends AbstractNodeTransformer { * @param {NodeGuards} parentNode * @returns {NodeGuards} */ - public transformNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { + public transformNode(literalNode: ESTree.Literal, parentNode: ESTree.Node): ESTree.Node { if ( - !NodeLiteralUtils.isStringLiteralNode(literalNode) - || NodeLiteralUtils.isProhibitedLiteralNode(literalNode, parentNode) + !NodeLiteralUtils.isStringLiteralNode(literalNode) || + NodeLiteralUtils.isProhibitedLiteralNode(literalNode, parentNode) ) { return literalNode; } @@ -189,7 +188,10 @@ export class StringArrayTransformer extends AbstractNodeTransformer { const stringArrayStorageItemData: IStringArrayStorageItemData | undefined = this.stringArrayStorageAnalyzer.getItemDataForLiteralNode(literalNode); const cacheKey: string = this.literalNodesCacheStorage.buildKey(literalValue, stringArrayStorageItemData); - const useCachedValue: boolean = this.literalNodesCacheStorage.shouldUseCachedValue(cacheKey, stringArrayStorageItemData); + const useCachedValue: boolean = this.literalNodesCacheStorage.shouldUseCachedValue( + cacheKey, + stringArrayStorageItemData + ); let resultNode: ESTree.Node; @@ -213,10 +215,10 @@ export class StringArrayTransformer extends AbstractNodeTransformer { * @param {IStringArrayStorageItemData} stringArrayStorageItemData * @returns {Expression} */ - private getStringArrayCallNode (stringArrayStorageItemData: IStringArrayStorageItemData): ESTree.Expression { + private getStringArrayCallNode(stringArrayStorageItemData: IStringArrayStorageItemData): ESTree.Expression { const stringArrayScopeCallsWrapperData: IStringArrayScopeCallsWrapperData = this.getStringArrayScopeCallsWrapperData(stringArrayStorageItemData); - const {decodeKey, index} = stringArrayStorageItemData; + const { decodeKey, index } = stringArrayStorageItemData; const stringArrayCallCustomNode: ICustomNode> = this.stringArrayTransformerCustomNodeFactory(StringArrayCustomNode.StringArrayCallNode); @@ -231,7 +233,9 @@ export class StringArrayTransformer extends AbstractNodeTransformer { const statementNode: TStatement = stringArrayCallCustomNode.getNode()[0]; if (!NodeGuards.isExpressionStatementNode(statementNode)) { - throw new Error('`stringArrayCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node'); + throw new Error( + '`stringArrayCallCustomNode.getNode()[0]` should returns array with `ExpressionStatement` node' + ); } return statementNode.expression; @@ -241,7 +245,7 @@ export class StringArrayTransformer extends AbstractNodeTransformer { * @param {IStringArrayStorageItemData} stringArrayStorageItemData * @returns {IStringArrayScopeCallsWrapperData} */ - private getStringArrayScopeCallsWrapperData ( + private getStringArrayScopeCallsWrapperData( stringArrayStorageItemData: IStringArrayStorageItemData ): IStringArrayScopeCallsWrapperData { return !this.options.stringArrayWrappersCount @@ -253,10 +257,10 @@ export class StringArrayTransformer extends AbstractNodeTransformer { * @param {IStringArrayStorageItemData} stringArrayStorageItemData * @returns {IStringArrayScopeCallsWrapperData} */ - private getRootStringArrayScopeCallsWrapperData ( + private getRootStringArrayScopeCallsWrapperData( stringArrayStorageItemData: IStringArrayStorageItemData ): IStringArrayScopeCallsWrapperData { - const {encoding} = stringArrayStorageItemData; + const { encoding } = stringArrayStorageItemData; const rootStringArrayCallsWrapperName: string = this.stringArrayStorage.getStorageCallsWrapperName(encoding); @@ -271,10 +275,10 @@ export class StringArrayTransformer extends AbstractNodeTransformer { * @param {IStringArrayStorageItemData} stringArrayStorageItemData * @returns {IStringArrayScopeCallsWrapperData} */ - private getUpperStringArrayScopeCallsWrapperData ( + private getUpperStringArrayScopeCallsWrapperData( stringArrayStorageItemData: IStringArrayStorageItemData ): IStringArrayScopeCallsWrapperData { - const {encoding} = stringArrayStorageItemData; + const { encoding } = stringArrayStorageItemData; const currentLexicalScopeBodyNode: TNodeWithLexicalScopeStatements | null = this.visitedLexicalScopeNodesStackStorage.getLastElement() ?? null; @@ -291,9 +295,7 @@ export class StringArrayTransformer extends AbstractNodeTransformer { const stringArrayScopeCallsWrappersData: IStringArrayScopeCallsWrapperData[] = stringArrayScopeCallsWrappersDataByEncoding[encoding]?.scopeCallsWrappersData ?? []; - return this.randomGenerator - .getRandomGenerator() - .pickone(stringArrayScopeCallsWrappersData); + return this.randomGenerator.getRandomGenerator().pickone(stringArrayScopeCallsWrappersData); } /** @@ -301,14 +303,13 @@ export class StringArrayTransformer extends AbstractNodeTransformer { * @param {IStringArrayStorageItemData} stringArrayStorageItemData * @returns {TStringArrayScopeCallsWrappersDataByEncoding} */ - private getAndUpdateStringArrayScopeCallsWrappersDataByEncoding ( + private getAndUpdateStringArrayScopeCallsWrappersDataByEncoding( currentLexicalScopeBodyNode: TNodeWithLexicalScopeStatements, - stringArrayStorageItemData: IStringArrayStorageItemData, + stringArrayStorageItemData: IStringArrayStorageItemData ): TStringArrayScopeCallsWrappersDataByEncoding { - const {encoding} = stringArrayStorageItemData; + const { encoding } = stringArrayStorageItemData; const stringArrayScopeCallsWrappersDataByEncoding: TStringArrayScopeCallsWrappersDataByEncoding = - this.stringArrayScopeCallsWrappersDataStorage.get(currentLexicalScopeBodyNode) - ?? {}; + this.stringArrayScopeCallsWrappersDataStorage.get(currentLexicalScopeBodyNode) ?? {}; const stringArrayScopeCallsWrappersData: IStringArrayScopeCallsWrapperData[] = stringArrayScopeCallsWrappersDataByEncoding[encoding]?.scopeCallsWrappersData ?? []; @@ -323,8 +324,7 @@ export class StringArrayTransformer extends AbstractNodeTransformer { const nextScopeCallsWrapperName: string = NodeGuards.isProgramNode(currentLexicalScopeBodyNode) ? this.identifierNamesGenerator.generateForGlobalScope() : this.identifierNamesGenerator.generateNext(); - const nextScopeCallsWrapperShiftedIndex: number = - this.getStringArrayCallsWrapperShiftedIndex(); + const nextScopeCallsWrapperShiftedIndex: number = this.getStringArrayCallsWrapperShiftedIndex(); const nextScopeCallsWrapperParameterIndexesData: IStringArrayScopeCallsWrapperParameterIndexesData | null = this.getStringArrayCallsWrapperParameterIndexesData(); @@ -351,19 +351,19 @@ export class StringArrayTransformer extends AbstractNodeTransformer { /** * @returns {number} */ - private getStringArrayCallsWrapperShiftedIndex (): number { + private getStringArrayCallsWrapperShiftedIndex(): number { return this.options.stringArrayWrappersType === StringArrayWrappersType.Function ? this.randomGenerator.getRandomInteger( - StringArrayTransformer.minShiftedIndexValue, - StringArrayTransformer.maxShiftedIndexValue - ) + StringArrayTransformer.minShiftedIndexValue, + StringArrayTransformer.maxShiftedIndexValue + ) : 0; } /** * @returns {IStringArrayScopeCallsWrapperParameterIndexesData | null} */ - private getStringArrayCallsWrapperParameterIndexesData (): IStringArrayScopeCallsWrapperParameterIndexesData | null { + private getStringArrayCallsWrapperParameterIndexesData(): IStringArrayScopeCallsWrapperParameterIndexesData | null { if (this.options.stringArrayWrappersType !== StringArrayWrappersType.Function) { return null; } @@ -371,10 +371,12 @@ export class StringArrayTransformer extends AbstractNodeTransformer { const minIndexValue: number = 0; const maxIndexValue: number = this.options.stringArrayWrappersParametersMaxCount - 1; - const valueIndexParameterIndex: number = this.randomGenerator - .getRandomInteger(minIndexValue, maxIndexValue); - const decodeKeyParameterIndex: number = this.randomGenerator - .getRandomIntegerExcluding(minIndexValue, maxIndexValue, [valueIndexParameterIndex]); + const valueIndexParameterIndex: number = this.randomGenerator.getRandomInteger(minIndexValue, maxIndexValue); + const decodeKeyParameterIndex: number = this.randomGenerator.getRandomIntegerExcluding( + minIndexValue, + maxIndexValue, + [valueIndexParameterIndex] + ); return { valueIndexParameterIndex, diff --git a/src/node/NodeAppender.ts b/src/node/NodeAppender.ts index 6600644db..461ec5889 100644 --- a/src/node/NodeAppender.ts +++ b/src/node/NodeAppender.ts @@ -12,7 +12,7 @@ export class NodeAppender { * @param {TNodeWithStatements} nodeWithStatements * @param {TStatement[]} statements */ - public static append (nodeWithStatements: TNodeWithStatements, statements: TStatement[]): void { + public static append(nodeWithStatements: TNodeWithStatements, statements: TStatement[]): void { statements = NodeAppender.parentizeScopeStatementsBeforeAppend(nodeWithStatements, statements); const updatedStatements: TStatement[] = NodeAppender.getScopeStatements(nodeWithStatements).concat(statements); @@ -42,7 +42,7 @@ export class NodeAppender { * @param {TStatement[]} bodyStatements * @param {number} index */ - public static appendToOptimalBlockScope ( + public static appendToOptimalBlockScope( callsGraphData: ICallsGraphData[], nodeWithStatements: TNodeWithStatements, bodyStatements: TStatement[], @@ -63,7 +63,7 @@ export class NodeAppender { * @param {number} deep * @returns {BlockStatement} */ - public static getOptimalBlockScope ( + public static getOptimalBlockScope( callsGraphData: ICallsGraphData[], index: number, deep: number = Infinity @@ -85,7 +85,7 @@ export class NodeAppender { * @param {TNodeWithStatements} nodeWithStatements * @returns {TStatement[]} */ - public static getScopeStatements (nodeWithStatements: TNodeWithStatements): TStatement[] { + public static getScopeStatements(nodeWithStatements: TNodeWithStatements): TStatement[] { if (NodeGuards.isSwitchCaseNode(nodeWithStatements)) { return nodeWithStatements.consequent; } @@ -98,14 +98,12 @@ export class NodeAppender { * @param {TStatement[]} statements * @param {Node} target */ - public static insertBefore ( + public static insertBefore( nodeWithStatements: TNodeWithStatements, statements: TStatement[], target: ESTree.Statement ): void { - const indexInScopeStatement: number = NodeAppender - .getScopeStatements(nodeWithStatements) - .indexOf(target); + const indexInScopeStatement: number = NodeAppender.getScopeStatements(nodeWithStatements).indexOf(target); NodeAppender.insertAtIndex(nodeWithStatements, statements, indexInScopeStatement); } @@ -115,14 +113,12 @@ export class NodeAppender { * @param {TStatement[]} statements * @param {Node} target */ - public static insertAfter ( + public static insertAfter( nodeWithStatements: TNodeWithStatements, statements: TStatement[], target: ESTree.Statement ): void { - const indexInScopeStatement: number = NodeAppender - .getScopeStatements(nodeWithStatements) - .indexOf(target); + const indexInScopeStatement: number = NodeAppender.getScopeStatements(nodeWithStatements).indexOf(target); NodeAppender.insertAtIndex(nodeWithStatements, statements, indexInScopeStatement + 1); } @@ -132,7 +128,7 @@ export class NodeAppender { * @param {TStatement[]} statements * @param {number} index */ - public static insertAtIndex ( + public static insertAtIndex( nodeWithStatements: TNodeWithStatements, statements: TStatement[], index: number @@ -150,7 +146,7 @@ export class NodeAppender { * @param {TNodeWithStatements} nodeWithStatements * @param {TStatement[]} statements */ - public static prepend (nodeWithStatements: TNodeWithStatements, statements: TStatement[]): void { + public static prepend(nodeWithStatements: TNodeWithStatements, statements: TStatement[]): void { statements = NodeAppender.parentizeScopeStatementsBeforeAppend(nodeWithStatements, statements); const updatedStatements: TStatement[] = statements.concat(NodeAppender.getScopeStatements(nodeWithStatements)); @@ -162,7 +158,7 @@ export class NodeAppender { * @param {TNodeWithStatements} nodeWithStatements * @param {Statement} statement */ - public static remove (nodeWithStatements: TNodeWithStatements, statement: ESTree.Statement): void { + public static remove(nodeWithStatements: TNodeWithStatements, statement: ESTree.Statement): void { const scopeStatements: TStatement[] = NodeAppender.getScopeStatements(nodeWithStatements); const indexInScopeStatement: number = scopeStatements.indexOf(statement); @@ -181,7 +177,7 @@ export class NodeAppender { * @param {TStatement[]} statements * @returns {TStatement[]} */ - private static parentizeScopeStatementsBeforeAppend ( + private static parentizeScopeStatementsBeforeAppend( nodeWithStatements: TNodeWithStatements, statements: TStatement[] ): TStatement[] { @@ -196,7 +192,7 @@ export class NodeAppender { * @param {TNodeWithStatements} nodeWithStatements * @param {TStatement[]} statements */ - private static setScopeStatements (nodeWithStatements: TNodeWithStatements, statements: TStatement[]): void { + private static setScopeStatements(nodeWithStatements: TNodeWithStatements, statements: TStatement[]): void { if (NodeGuards.isSwitchCaseNode(nodeWithStatements)) { nodeWithStatements.consequent = statements; diff --git a/src/node/NodeFactory.ts b/src/node/NodeFactory.ts index 3449f2ef3..6057ea1ca 100644 --- a/src/node/NodeFactory.ts +++ b/src/node/NodeFactory.ts @@ -11,7 +11,7 @@ export class NodeFactory { * @param {TStatement[]} body * @returns {Program} */ - public static programNode (body: TStatement[] = []): ESTree.Program { + public static programNode(body: TStatement[] = []): ESTree.Program { return { type: NodeType.Program, body, @@ -24,7 +24,7 @@ export class NodeFactory { * @param {(Expression | SpreadElement)[]} elements * @returns {ArrayExpression} */ - public static arrayExpressionNode ( + public static arrayExpressionNode( elements: (ESTree.Expression | ESTree.SpreadElement)[] = [] ): ESTree.ArrayExpression { return { @@ -40,7 +40,7 @@ export class NodeFactory { * @param {Expression} right * @returns {AssignmentExpression} */ - public static assignmentExpressionNode ( + public static assignmentExpressionNode( operator: ESTree.AssignmentOperator, left: ESTree.Pattern | ESTree.MemberExpression, right: ESTree.Expression @@ -60,7 +60,7 @@ export class NodeFactory { * @param {Expression} right * @returns {BinaryExpression} */ - public static binaryExpressionNode ( + public static binaryExpressionNode( operator: ESTree.BinaryOperator, left: ESTree.Expression, right: ESTree.Expression @@ -78,7 +78,7 @@ export class NodeFactory { * @param {Statement[]} body * @returns {BlockStatement} */ - public static blockStatementNode (body: ESTree.Statement[] = []): ESTree.BlockStatement { + public static blockStatementNode(body: ESTree.Statement[] = []): ESTree.BlockStatement { return { type: NodeType.BlockStatement, body, @@ -90,7 +90,7 @@ export class NodeFactory { * @param {Identifier} label * @returns {BreakStatement} */ - public static breakStatement (label?: ESTree.Identifier): ESTree.BreakStatement { + public static breakStatement(label?: ESTree.Identifier): ESTree.BreakStatement { return { type: NodeType.BreakStatement, label, @@ -104,10 +104,10 @@ export class NodeFactory { * @param {boolean} optional * @returns {CallExpression} */ - public static callExpressionNode ( + public static callExpressionNode( callee: ESTree.Expression, args: (ESTree.Expression | ESTree.SpreadElement)[] = [], - optional: boolean = false, + optional: boolean = false ): ESTree.CallExpression { return { type: NodeType.CallExpression, @@ -122,9 +122,7 @@ export class NodeFactory { * @param {ChainElement} expression * @return {ChainExpression} */ - public static chainExpressionNode ( - expression: ESTree.ChainElement, - ): ESTree.ChainExpression { + public static chainExpressionNode(expression: ESTree.ChainElement): ESTree.ChainExpression { return { type: NodeType.ChainExpression, expression, @@ -138,7 +136,7 @@ export class NodeFactory { * @param {ESTree.Expression} alternate * @returns {ESTree.ConditionalExpression} */ - public static conditionalExpressionNode ( + public static conditionalExpressionNode( test: ESTree.Expression, consequent: ESTree.Expression, alternate: ESTree.Expression @@ -156,7 +154,7 @@ export class NodeFactory { * @param {Identifier} label * @returns {ContinueStatement} */ - public static continueStatement (label?: ESTree.Identifier): ESTree.ContinueStatement { + public static continueStatement(label?: ESTree.Identifier): ESTree.ContinueStatement { return { type: NodeType.ContinueStatement, label, @@ -169,10 +167,7 @@ export class NodeFactory { * @param {string} directive * @returns {Directive} */ - public static directiveNode ( - expression: ESTree.Literal, - directive: string - ): ESTree.Directive { + public static directiveNode(expression: ESTree.Literal, directive: string): ESTree.Directive { return { type: NodeType.ExpressionStatement, expression, @@ -186,7 +181,7 @@ export class NodeFactory { * @param {Expression} test * @returns {DoWhileStatement} */ - public static doWhileStatementNode (body: ESTree.Statement, test: ESTree.Expression): ESTree.DoWhileStatement { + public static doWhileStatementNode(body: ESTree.Statement, test: ESTree.Expression): ESTree.DoWhileStatement { return { type: NodeType.DoWhileStatement, body, @@ -200,7 +195,7 @@ export class NodeFactory { * @param {Identifier | null} exported * @returns {ExportAllDeclaration} */ - public static exportAllDeclarationNode ( + public static exportAllDeclarationNode( source: ESTree.Literal, exported: ESTree.Identifier | null ): ESTree.ExportAllDeclaration { @@ -217,7 +212,7 @@ export class NodeFactory { * @param {Literal} source * @returns {ExportNamedDeclaration} */ - public static exportNamedDeclarationNode ( + public static exportNamedDeclarationNode( specifiers: ESTree.ExportSpecifier[], source: ESTree.Literal ): ESTree.ExportNamedDeclaration { @@ -233,7 +228,7 @@ export class NodeFactory { * @param {Expression} expression * @returns {ExpressionStatement} */ - public static expressionStatementNode (expression: ESTree.Expression): ESTree.ExpressionStatement { + public static expressionStatementNode(expression: ESTree.Expression): ESTree.ExpressionStatement { return { type: NodeType.ExpressionStatement, expression, @@ -248,7 +243,7 @@ export class NodeFactory { * @param {Statement} body * @returns {ForStatement} */ - public static forStatementNode ( + public static forStatementNode( init: ESTree.VariableDeclaration | ESTree.Expression | null, test: ESTree.Expression | null, update: ESTree.Expression | null, @@ -270,7 +265,7 @@ export class NodeFactory { * @param {Statement} body * @returns {ForInStatement} */ - public static forInStatementNode ( + public static forInStatementNode( left: ESTree.VariableDeclaration | ESTree.Pattern, right: ESTree.Expression, body: ESTree.Statement @@ -291,7 +286,7 @@ export class NodeFactory { * @param {Statement} body * @returns {ForOfStatement} */ - public static forOfStatementNode ( + public static forOfStatementNode( asAwait: boolean, left: ESTree.VariableDeclaration | ESTree.Pattern, right: ESTree.Expression, @@ -313,7 +308,7 @@ export class NodeFactory { * @param {BlockStatement} body * @returns {FunctionDeclaration} */ - public static functionDeclarationNode ( + public static functionDeclarationNode( functionName: string, params: ESTree.Identifier[], body: ESTree.BlockStatement @@ -333,7 +328,7 @@ export class NodeFactory { * @param {BlockStatement} body * @returns {FunctionExpression} */ - public static functionExpressionNode ( + public static functionExpressionNode( params: ESTree.Pattern[], body: ESTree.BlockStatement ): ESTree.FunctionExpression { @@ -352,7 +347,7 @@ export class NodeFactory { * @param {ESTree.Statement | null} alternate * @returns {ESTree.IfStatement} */ - public static ifStatementNode ( + public static ifStatementNode( test: ESTree.Expression, consequent: ESTree.Statement, alternate?: ESTree.Statement | null @@ -361,7 +356,7 @@ export class NodeFactory { type: NodeType.IfStatement, test, consequent, - ...alternate && { alternate }, + ...(alternate && { alternate }), metadata: { ignoredNode: false } }; } @@ -370,7 +365,7 @@ export class NodeFactory { * @param {string} name * @returns {Identifier} */ - public static identifierNode (name: string): ESTree.Identifier { + public static identifierNode(name: string): ESTree.Identifier { return { type: NodeType.Identifier, name, @@ -383,7 +378,7 @@ export class NodeFactory { * @param {Literal} source * @returns {ImportDeclaration} */ - public static importDeclarationNode ( + public static importDeclarationNode( specifiers: (ESTree.ImportSpecifier | ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier)[], source: ESTree.Literal ): ESTree.ImportDeclaration { @@ -400,10 +395,7 @@ export class NodeFactory { * @param {Statement} body * @returns {LabeledStatement} */ - public static labeledStatementNode ( - label: ESTree.Identifier, - body: ESTree.Statement - ): ESTree.LabeledStatement { + public static labeledStatementNode(label: ESTree.Identifier, body: ESTree.Statement): ESTree.LabeledStatement { return { type: NodeType.LabeledStatement, label, @@ -417,7 +409,7 @@ export class NodeFactory { * @param {string} raw * @returns {Literal} */ - public static literalNode (value: boolean | number | string, raw?: string): ESTree.Literal { + public static literalNode(value: boolean | number | string, raw?: string): ESTree.Literal { raw = raw ?? `'${value}'`; return { @@ -439,10 +431,10 @@ export class NodeFactory { * @param {Expression} right * @returns {LogicalExpression} */ - public static logicalExpressionNode ( + public static logicalExpressionNode( operator: ESTree.LogicalOperator, left: ESTree.Expression, - right: ESTree.Expression, + right: ESTree.Expression ): ESTree.LogicalExpression { return { type: NodeType.LogicalExpression, @@ -460,11 +452,11 @@ export class NodeFactory { * @param {boolean} optional * @returns {MemberExpression} */ - public static memberExpressionNode ( + public static memberExpressionNode( object: ESTree.Expression | ESTree.Super, property: ESTree.Expression, computed: boolean = false, - optional: boolean = false, + optional: boolean = false ): ESTree.MemberExpression { return { type: NodeType.MemberExpression, @@ -480,7 +472,9 @@ export class NodeFactory { * @param {(ESTree.Property | ESTree.SpreadElement)[]} properties * @returns {ESTree.ObjectExpression} */ - public static objectExpressionNode (properties: (ESTree.Property | ESTree.SpreadElement)[]): ESTree.ObjectExpression { + public static objectExpressionNode( + properties: (ESTree.Property | ESTree.SpreadElement)[] + ): ESTree.ObjectExpression { return { type: NodeType.ObjectExpression, properties, @@ -494,7 +488,7 @@ export class NodeFactory { * @param {boolean} computed * @returns {Property} */ - public static propertyNode ( + public static propertyNode( key: ESTree.Expression, value: ESTree.Expression | ESTree.Pattern, computed: boolean = false @@ -515,7 +509,7 @@ export class NodeFactory { * @param {Pattern} argument * @returns {SpreadElement} */ - public static restElementNode (argument: ESTree.Pattern): ESTree.RestElement { + public static restElementNode(argument: ESTree.Pattern): ESTree.RestElement { return { type: NodeType.RestElement, argument, @@ -527,7 +521,7 @@ export class NodeFactory { * @param {Expression} argument * @returns {ReturnStatement} */ - public static returnStatementNode (argument: ESTree.Expression): ESTree.ReturnStatement { + public static returnStatementNode(argument: ESTree.Expression): ESTree.ReturnStatement { return { type: NodeType.ReturnStatement, argument, @@ -539,7 +533,7 @@ export class NodeFactory { * @param {ESTree.Expression[]} expressions * @returns {ESTree.SequenceExpression} */ - public static sequenceExpressionNode (expressions: ESTree.Expression[]): ESTree.SequenceExpression { + public static sequenceExpressionNode(expressions: ESTree.Expression[]): ESTree.SequenceExpression { return { type: NodeType.SequenceExpression, expressions, @@ -551,7 +545,7 @@ export class NodeFactory { * @param {Expression} argument * @returns {SpreadElement} */ - public static spreadElementNode (argument: ESTree.Expression): ESTree.SpreadElement { + public static spreadElementNode(argument: ESTree.Expression): ESTree.SpreadElement { return { type: NodeType.SpreadElement, argument, @@ -563,7 +557,7 @@ export class NodeFactory { * @param {Statement[]} body * @returns {StaticBlock} */ - public static staticBlockNode (body: ESTree.Statement[] = []): ESTree.StaticBlock { + public static staticBlockNode(body: ESTree.Statement[] = []): ESTree.StaticBlock { return { type: NodeType.StaticBlock, body, @@ -576,7 +570,7 @@ export class NodeFactory { * @param {SwitchCase[]} cases * @returns {SwitchStatement} */ - public static switchStatementNode ( + public static switchStatementNode( discriminant: ESTree.Expression, cases: ESTree.SwitchCase[] ): ESTree.SwitchStatement { @@ -593,7 +587,7 @@ export class NodeFactory { * @param {Statement[]} consequent * @returns {SwitchCase} */ - public static switchCaseNode (test: ESTree.Expression, consequent: ESTree.Statement[]): ESTree.SwitchCase { + public static switchCaseNode(test: ESTree.Expression, consequent: ESTree.Statement[]): ESTree.SwitchCase { return { type: NodeType.SwitchCase, test, @@ -608,7 +602,7 @@ export class NodeFactory { * @param {true} prefix * @returns {UnaryExpression} */ - public static unaryExpressionNode ( + public static unaryExpressionNode( operator: ESTree.UnaryOperator, argument: ESTree.Expression, prefix: true = true @@ -627,7 +621,10 @@ export class NodeFactory { * @param {Expression} argumentExpr * @returns {UpdateExpression} */ - public static updateExpressionNode (operator: ESTree.UpdateOperator, argumentExpr: ESTree.Expression): ESTree.UpdateExpression { + public static updateExpressionNode( + operator: ESTree.UpdateOperator, + argumentExpr: ESTree.Expression + ): ESTree.UpdateExpression { return { type: NodeType.UpdateExpression, operator, @@ -642,7 +639,7 @@ export class NodeFactory { * @param {string} kind * @returns {VariableDeclaration} */ - public static variableDeclarationNode ( + public static variableDeclarationNode( declarations: ESTree.VariableDeclarator[] = [], kind: 'var' | 'let' | 'const' = 'var' ): ESTree.VariableDeclaration { @@ -659,7 +656,10 @@ export class NodeFactory { * @param {Expression | null} init * @returns {VariableDeclarator} */ - public static variableDeclaratorNode (id: ESTree.Identifier, init: ESTree.Expression | null): ESTree.VariableDeclarator { + public static variableDeclaratorNode( + id: ESTree.Identifier, + init: ESTree.Expression | null + ): ESTree.VariableDeclarator { return { type: NodeType.VariableDeclarator, id, @@ -673,7 +673,7 @@ export class NodeFactory { * @param {Statement} body * @returns {WhileStatement} */ - public static whileStatementNode (test: ESTree.Expression, body: ESTree.Statement): ESTree.WhileStatement { + public static whileStatementNode(test: ESTree.Expression, body: ESTree.Statement): ESTree.WhileStatement { return { type: NodeType.WhileStatement, test, diff --git a/src/node/NodeGuards.ts b/src/node/NodeGuards.ts index ee6d3568a..b34962a39 100644 --- a/src/node/NodeGuards.ts +++ b/src/node/NodeGuards.ts @@ -16,14 +16,14 @@ export class NodeGuards { NodeType.ArrowFunctionExpression, NodeType.FunctionDeclaration, NodeType.FunctionExpression, - NodeType.MethodDefinition, + NodeType.MethodDefinition ]; /** * @param {Node} node * @returns {boolean} */ - public static isArrayPatternNode (node: ESTree.Node): node is ESTree.ArrayPattern { + public static isArrayPatternNode(node: ESTree.Node): node is ESTree.ArrayPattern { return node.type === NodeType.ArrayPattern; } @@ -31,7 +31,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isArrowFunctionExpressionNode (node: ESTree.Node): node is ESTree.ArrowFunctionExpression { + public static isArrowFunctionExpressionNode(node: ESTree.Node): node is ESTree.ArrowFunctionExpression { return node.type === NodeType.ArrowFunctionExpression; } @@ -39,7 +39,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isAssignmentExpressionNode (node: ESTree.Node): node is ESTree.AssignmentExpression { + public static isAssignmentExpressionNode(node: ESTree.Node): node is ESTree.AssignmentExpression { return node.type === NodeType.AssignmentExpression; } @@ -47,7 +47,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isAssignmentPatternNode (node: ESTree.Node): node is ESTree.AssignmentPattern { + public static isAssignmentPatternNode(node: ESTree.Node): node is ESTree.AssignmentPattern { return node.type === NodeType.AssignmentPattern; } @@ -55,7 +55,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isAwaitExpressionNode (node: ESTree.Node): node is ESTree.AwaitExpression { + public static isAwaitExpressionNode(node: ESTree.Node): node is ESTree.AwaitExpression { return node.type === NodeType.AwaitExpression; } @@ -63,7 +63,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isBigIntLiteralNode (node: ESTree.Node): node is ESTree.BigIntLiteral { + public static isBigIntLiteralNode(node: ESTree.Node): node is ESTree.BigIntLiteral { return NodeGuards.isLiteralNode(node) && !!(node).bigint; } @@ -71,7 +71,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isBlockStatementNode (node: ESTree.Node): node is ESTree.BlockStatement { + public static isBlockStatementNode(node: ESTree.Node): node is ESTree.BlockStatement { return node.type === NodeType.BlockStatement; } @@ -79,7 +79,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isBreakStatementNode (node: ESTree.Node): node is ESTree.BreakStatement { + public static isBreakStatementNode(node: ESTree.Node): node is ESTree.BreakStatement { return node.type === NodeType.BreakStatement; } @@ -87,25 +87,23 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isCallExpressionNode (node: ESTree.Node): node is ESTree.CallExpression { + public static isCallExpressionNode(node: ESTree.Node): node is ESTree.CallExpression { return node.type === NodeType.CallExpression; } - /** - * @param {Node} node - * @returns {boolean} - */ - public static isChainExpressionNode (node: ESTree.Node): node is ESTree.ChainExpression { - return node.type === NodeType.ChainExpression; - } + /** + * @param {Node} node + * @returns {boolean} + */ + public static isChainExpressionNode(node: ESTree.Node): node is ESTree.ChainExpression { + return node.type === NodeType.ChainExpression; + } /** * @param {Node} node * @returns {boolean} */ - public static isClassBodyNode ( - node: ESTree.Node - ): node is ESTree.ClassBody { + public static isClassBodyNode(node: ESTree.Node): node is ESTree.ClassBody { return node.type === NodeType.ClassBody; } @@ -113,7 +111,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isClassDeclarationNode ( + public static isClassDeclarationNode( node: ESTree.Node ): node is ESTree.ClassDeclaration & { id: ESTree.Identifier } { return node.type === NodeType.ClassDeclaration && node.id !== null; @@ -123,7 +121,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isConditionalExpressionNode (node: ESTree.Node): node is ESTree.ConditionalExpression { + public static isConditionalExpressionNode(node: ESTree.Node): node is ESTree.ConditionalExpression { return node.type === NodeType.ConditionalExpression; } @@ -131,7 +129,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isContinueStatementNode (node: ESTree.Node): node is ESTree.ContinueStatement { + public static isContinueStatementNode(node: ESTree.Node): node is ESTree.ContinueStatement { return node.type === NodeType.ContinueStatement; } @@ -139,16 +137,15 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isDirectiveNode (node: ESTree.Node): node is ESTree.Directive { - return node.type === NodeType.ExpressionStatement - && 'directive' in node; + public static isDirectiveNode(node: ESTree.Node): node is ESTree.Directive { + return node.type === NodeType.ExpressionStatement && 'directive' in node; } /** * @param {Node} node * @returns {boolean} */ - public static isDoWhileStatementNode (node: ESTree.Node): node is ESTree.DoWhileStatement { + public static isDoWhileStatementNode(node: ESTree.Node): node is ESTree.DoWhileStatement { return node.type === NodeType.DoWhileStatement; } @@ -156,7 +153,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isExportAllDeclarationNode (node: ESTree.Node): node is ESTree.ExportAllDeclaration { + public static isExportAllDeclarationNode(node: ESTree.Node): node is ESTree.ExportAllDeclaration { return node.type === NodeType.ExportAllDeclaration; } @@ -164,7 +161,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isExportNamedDeclarationNode (node: ESTree.Node): node is ESTree.ExportNamedDeclaration { + public static isExportNamedDeclarationNode(node: ESTree.Node): node is ESTree.ExportNamedDeclaration { return node.type === NodeType.ExportNamedDeclaration; } @@ -172,7 +169,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isExportSpecifierNode (node: ESTree.Node): node is ESTree.ExportSpecifier { + public static isExportSpecifierNode(node: ESTree.Node): node is ESTree.ExportSpecifier { return node.type === NodeType.ExportSpecifier; } @@ -180,16 +177,15 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isExpressionStatementNode (node: ESTree.Node): node is ESTree.ExpressionStatement { - return node.type === NodeType.ExpressionStatement - && !('directive' in node); + public static isExpressionStatementNode(node: ESTree.Node): node is ESTree.ExpressionStatement { + return node.type === NodeType.ExpressionStatement && !('directive' in node); } /** * @param {Node} node * @returns {boolean} */ - public static isForStatementNode (node: ESTree.Node): node is ESTree.ForStatement { + public static isForStatementNode(node: ESTree.Node): node is ESTree.ForStatement { return node.type === NodeType.ForStatement; } @@ -197,7 +193,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isForInStatementNode (node: ESTree.Node): node is ESTree.ForInStatement { + public static isForInStatementNode(node: ESTree.Node): node is ESTree.ForInStatement { return node.type === NodeType.ForInStatement; } @@ -205,7 +201,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isForOfStatementNode (node: ESTree.Node): node is ESTree.ForOfStatement { + public static isForOfStatementNode(node: ESTree.Node): node is ESTree.ForOfStatement { return node.type === NodeType.ForOfStatement; } @@ -213,17 +209,19 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isFunctionNode (node: ESTree.Node): node is ESTree.Function { - return NodeGuards.isFunctionDeclarationNode(node) || + public static isFunctionNode(node: ESTree.Node): node is ESTree.Function { + return ( + NodeGuards.isFunctionDeclarationNode(node) || NodeGuards.isFunctionExpressionNode(node) || - NodeGuards.isArrowFunctionExpressionNode(node); + NodeGuards.isArrowFunctionExpressionNode(node) + ); } /** * @param {Node} node * @returns {boolean} */ - public static isFunctionDeclarationNode ( + public static isFunctionDeclarationNode( node: ESTree.Node ): node is ESTree.FunctionDeclaration & { id: ESTree.Identifier } { return node.type === NodeType.FunctionDeclaration && node.id !== null; @@ -233,7 +231,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isFunctionExpressionNode (node: ESTree.Node): node is ESTree.FunctionExpression { + public static isFunctionExpressionNode(node: ESTree.Node): node is ESTree.FunctionExpression { return node.type === NodeType.FunctionExpression; } @@ -241,7 +239,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isIdentifierNode (node: ESTree.Node): node is ESTree.Identifier { + public static isIdentifierNode(node: ESTree.Node): node is ESTree.Identifier { return node.type === NodeType.Identifier; } @@ -249,7 +247,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isIfStatementNode (node: ESTree.Node): node is ESTree.IfStatement { + public static isIfStatementNode(node: ESTree.Node): node is ESTree.IfStatement { return node.type === NodeType.IfStatement; } @@ -257,20 +255,22 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isIfStatementNodeWithSingleStatementBody (node: ESTree.Node): node is ESTree.IfStatement { + public static isIfStatementNodeWithSingleStatementBody(node: ESTree.Node): node is ESTree.IfStatement { if (!NodeGuards.isIfStatementNode(node)) { - return false; + return false; } - return !NodeGuards.isBlockStatementNode(node.consequent) - || (!!node.alternate && !NodeGuards.isBlockStatementNode(node.alternate)); + return ( + !NodeGuards.isBlockStatementNode(node.consequent) || + (!!node.alternate && !NodeGuards.isBlockStatementNode(node.alternate)) + ); } /** * @param {Node} node * @returns {boolean} */ - public static isImportDeclarationNode (node: ESTree.Node): node is ESTree.ImportDeclaration { + public static isImportDeclarationNode(node: ESTree.Node): node is ESTree.ImportDeclaration { return node.type === NodeType.ImportDeclaration; } @@ -278,7 +278,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isImportExpressionNode (node: ESTree.Node): node is ESTree.ImportExpression { + public static isImportExpressionNode(node: ESTree.Node): node is ESTree.ImportExpression { return node.type === NodeType.ImportExpression; } @@ -286,7 +286,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isImportSpecifierNode (node: ESTree.Node): node is ESTree.ImportSpecifier { + public static isImportSpecifierNode(node: ESTree.Node): node is ESTree.ImportSpecifier { return node.type === NodeType.ImportSpecifier; } @@ -295,10 +295,13 @@ export class NodeGuards { * @param {Node} parentNode * @returns {boolean} */ - public static isLabelIdentifierNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier { - const parentNodeIsLabeledStatementNode: boolean = NodeGuards.isLabeledStatementNode(parentNode) && parentNode.label === node; - const parentNodeIsContinueStatementNode: boolean = NodeGuards.isContinueStatementNode(parentNode) && parentNode.label === node; - const parentNodeIsBreakStatementNode: boolean = NodeGuards.isBreakStatementNode(parentNode) && parentNode.label === node; + public static isLabelIdentifierNode(node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier { + const parentNodeIsLabeledStatementNode: boolean = + NodeGuards.isLabeledStatementNode(parentNode) && parentNode.label === node; + const parentNodeIsContinueStatementNode: boolean = + NodeGuards.isContinueStatementNode(parentNode) && parentNode.label === node; + const parentNodeIsBreakStatementNode: boolean = + NodeGuards.isBreakStatementNode(parentNode) && parentNode.label === node; return parentNodeIsLabeledStatementNode || parentNodeIsContinueStatementNode || parentNodeIsBreakStatementNode; } @@ -307,7 +310,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isLabeledStatementNode (node: ESTree.Node): node is ESTree.LabeledStatement { + public static isLabeledStatementNode(node: ESTree.Node): node is ESTree.LabeledStatement { return node.type === NodeType.LabeledStatement; } @@ -315,7 +318,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isLiteralNode (node: ESTree.Node): node is ESTree.Literal { + public static isLiteralNode(node: ESTree.Node): node is ESTree.Literal { return node.type === NodeType.Literal; } @@ -323,7 +326,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isLogicalExpressionNode (node: ESTree.Node): node is ESTree.LogicalExpression { + public static isLogicalExpressionNode(node: ESTree.Node): node is ESTree.LogicalExpression { return node.type === NodeType.LogicalExpression; } @@ -331,7 +334,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isMemberExpressionNode (node: ESTree.Node): node is ESTree.MemberExpression { + public static isMemberExpressionNode(node: ESTree.Node): node is ESTree.MemberExpression { return node.type === NodeType.MemberExpression; } @@ -339,7 +342,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isMetaPropertyNode (node: ESTree.Node): node is ESTree.MetaProperty { + public static isMetaPropertyNode(node: ESTree.Node): node is ESTree.MetaProperty { return node.type === NodeType.MetaProperty; } @@ -347,7 +350,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isMethodDefinitionNode (node: ESTree.Node): node is ESTree.MethodDefinition { + public static isMethodDefinitionNode(node: ESTree.Node): node is ESTree.MethodDefinition { return node.type === NodeType.MethodDefinition; } @@ -355,7 +358,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isNewExpressionNode (node: ESTree.Node): node is ESTree.NewExpression { + public static isNewExpressionNode(node: ESTree.Node): node is ESTree.NewExpression { return node.type === NodeType.NewExpression; } @@ -364,7 +367,7 @@ export class NodeGuards { * @returns {boolean} */ // eslint-disable-next-line @typescript-eslint/ban-types - public static isNode (object: Object & { type?: string }): object is ESTree.Node { + public static isNode(object: Object & { type?: string }): object is ESTree.Node { return object && !object.type !== undefined; } @@ -372,7 +375,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isNodeWithLexicalScope (node: ESTree.Node): node is TNodeWithLexicalScope { + public static isNodeWithLexicalScope(node: ESTree.Node): node is TNodeWithLexicalScope { return NodeGuards.isProgramNode(node) || NodeGuards.isFunctionNode(node); } @@ -380,10 +383,12 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isNodeWithBlockLexicalScope (node: ESTree.Node): node is TNodeWithLexicalScope { - return NodeGuards.isNodeWithLexicalScope(node) - || NodeGuards.isBlockStatementNode(node) - || NodeGuards.isStaticBlockNode(node); + public static isNodeWithBlockLexicalScope(node: ESTree.Node): node is TNodeWithLexicalScope { + return ( + NodeGuards.isNodeWithLexicalScope(node) || + NodeGuards.isBlockStatementNode(node) || + NodeGuards.isStaticBlockNode(node) + ); } /** @@ -397,7 +402,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isNodeWithSingleStatementBody (node: ESTree.Node): node is TNodeWithSingleStatementBody { + public static isNodeWithSingleStatementBody(node: ESTree.Node): node is TNodeWithSingleStatementBody { // Different approach for `IfStatement` node because this node hasn't `body` property if (NodeGuards.isIfStatementNode(node)) { return NodeGuards.isIfStatementNodeWithSingleStatementBody(node); @@ -405,14 +410,15 @@ export class NodeGuards { // All other nodes with `Statement` node as `body` property return ( - NodeGuards.isForStatementNode(node) - || NodeGuards.isForOfStatementNode(node) - || NodeGuards.isForInStatementNode(node) - || NodeGuards.isWhileStatementNode(node) - || NodeGuards.isDoWhileStatementNode(node) - || NodeGuards.isWithStatementNode(node) - || NodeGuards.isLabeledStatementNode(node) - ) && !NodeGuards.isBlockStatementNode(node.body); + (NodeGuards.isForStatementNode(node) || + NodeGuards.isForOfStatementNode(node) || + NodeGuards.isForInStatementNode(node) || + NodeGuards.isWhileStatementNode(node) || + NodeGuards.isDoWhileStatementNode(node) || + NodeGuards.isWithStatementNode(node) || + NodeGuards.isLabeledStatementNode(node)) && + !NodeGuards.isBlockStatementNode(node.body) + ); } /** @@ -420,30 +426,34 @@ export class NodeGuards { * @param {Node} parentNode * @returns {boolean} */ - public static isNodeWithLexicalScopeStatements ( + public static isNodeWithLexicalScopeStatements( node: ESTree.Node, parentNode: ESTree.Node ): node is TNodeWithLexicalScopeStatements { - return NodeGuards.isProgramNode(node) - || (NodeGuards.isBlockStatementNode(node) && NodeGuards.nodesWithLexicalStatements.includes(parentNode.type)); + return ( + NodeGuards.isProgramNode(node) || + (NodeGuards.isBlockStatementNode(node) && NodeGuards.nodesWithLexicalStatements.includes(parentNode.type)) + ); } /** * @param {Node} node * @returns {boolean} */ - public static isNodeWithStatements (node: ESTree.Node): node is TNodeWithStatements { - return NodeGuards.isProgramNode(node) - || NodeGuards.isBlockStatementNode(node) - || NodeGuards.isStaticBlockNode(node) - || NodeGuards.isSwitchCaseNode(node); + public static isNodeWithStatements(node: ESTree.Node): node is TNodeWithStatements { + return ( + NodeGuards.isProgramNode(node) || + NodeGuards.isBlockStatementNode(node) || + NodeGuards.isStaticBlockNode(node) || + NodeGuards.isSwitchCaseNode(node) + ); } /** * @param {Node} node * @returns {boolean} */ - public static isNodeWithComments (node: ESTree.Node): node is ESTree.Node { + public static isNodeWithComments(node: ESTree.Node): node is ESTree.Node { return Boolean(node.leadingComments) || Boolean(node.trailingComments); } @@ -451,7 +461,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isObjectPatternNode (node: ESTree.Node): node is ESTree.ObjectPattern { + public static isObjectPatternNode(node: ESTree.Node): node is ESTree.ObjectPattern { return node.type === NodeType.ObjectPattern; } @@ -459,7 +469,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isObjectExpressionNode (node: ESTree.Node): node is ESTree.ObjectExpression { + public static isObjectExpressionNode(node: ESTree.Node): node is ESTree.ObjectExpression { return node.type === NodeType.ObjectExpression; } @@ -467,7 +477,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isPrivateIdentifierNode (node: ESTree.Node): node is ESTree.PrivateIdentifier { + public static isPrivateIdentifierNode(node: ESTree.Node): node is ESTree.PrivateIdentifier { return node.type === NodeType.PrivateIdentifier; } @@ -475,7 +485,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isProgramNode (node: ESTree.Node): node is ESTree.Program { + public static isProgramNode(node: ESTree.Node): node is ESTree.Program { return node.type === NodeType.Program; } @@ -483,7 +493,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isPropertyNode (node: ESTree.Node): node is ESTree.Property { + public static isPropertyNode(node: ESTree.Node): node is ESTree.Property { return node.type === NodeType.Property; } @@ -491,7 +501,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isPropertyDefinitionNode (node: ESTree.Node): node is ESTree.PropertyDefinition { + public static isPropertyDefinitionNode(node: ESTree.Node): node is ESTree.PropertyDefinition { return node.type === NodeType.PropertyDefinition; } @@ -499,7 +509,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isRestElementNode (node: ESTree.Node): node is ESTree.RestElement { + public static isRestElementNode(node: ESTree.Node): node is ESTree.RestElement { return node.type === NodeType.RestElement; } @@ -507,7 +517,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isReturnStatementNode (node: ESTree.Node): node is ESTree.ReturnStatement { + public static isReturnStatementNode(node: ESTree.Node): node is ESTree.ReturnStatement { return node.type === NodeType.ReturnStatement; } @@ -515,7 +525,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isSequenceExpressionNode (node: ESTree.Node): node is ESTree.SequenceExpression { + public static isSequenceExpressionNode(node: ESTree.Node): node is ESTree.SequenceExpression { return node.type === NodeType.SequenceExpression; } @@ -523,7 +533,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isSpreadElementNode (node: ESTree.Node): node is ESTree.SpreadElement { + public static isSpreadElementNode(node: ESTree.Node): node is ESTree.SpreadElement { return node.type === NodeType.SpreadElement; } @@ -531,7 +541,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isStaticBlockNode (node: ESTree.Node): node is ESTree.StaticBlock { + public static isStaticBlockNode(node: ESTree.Node): node is ESTree.StaticBlock { return node.type === NodeType.StaticBlock; } @@ -539,7 +549,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isSuperNode (node: ESTree.Node): node is ESTree.Super { + public static isSuperNode(node: ESTree.Node): node is ESTree.Super { return node.type === NodeType.Super; } @@ -547,7 +557,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isSwitchCaseNode (node: ESTree.Node): node is ESTree.SwitchCase { + public static isSwitchCaseNode(node: ESTree.Node): node is ESTree.SwitchCase { return node.type === NodeType.SwitchCase; } @@ -555,7 +565,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isTaggedTemplateExpressionNode (node: ESTree.Node): node is ESTree.TaggedTemplateExpression { + public static isTaggedTemplateExpressionNode(node: ESTree.Node): node is ESTree.TaggedTemplateExpression { return node.type === NodeType.TaggedTemplateExpression; } @@ -563,7 +573,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isTemplateLiteralNode (node: ESTree.Node): node is ESTree.TemplateLiteral { + public static isTemplateLiteralNode(node: ESTree.Node): node is ESTree.TemplateLiteral { return node.type === NodeType.TemplateLiteral; } @@ -571,7 +581,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isThisExpressionNode (node: ESTree.Node): node is ESTree.ThisExpression { + public static isThisExpressionNode(node: ESTree.Node): node is ESTree.ThisExpression { return node.type === NodeType.ThisExpression; } @@ -579,7 +589,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isUnaryExpressionNode (node: ESTree.Node): node is ESTree.UnaryExpression { + public static isUnaryExpressionNode(node: ESTree.Node): node is ESTree.UnaryExpression { return node.type === NodeType.UnaryExpression; } @@ -587,7 +597,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isVariableDeclarationNode (node: ESTree.Node): node is ESTree.VariableDeclaration { + public static isVariableDeclarationNode(node: ESTree.Node): node is ESTree.VariableDeclaration { return node.type === NodeType.VariableDeclaration; } @@ -595,7 +605,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isVariableDeclaratorNode (node: ESTree.Node): node is ESTree.VariableDeclarator { + public static isVariableDeclaratorNode(node: ESTree.Node): node is ESTree.VariableDeclarator { return node.type === NodeType.VariableDeclarator; } @@ -603,7 +613,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isWithStatementNode (node: ESTree.Node): node is ESTree.WithStatement { + public static isWithStatementNode(node: ESTree.Node): node is ESTree.WithStatement { return node.type === NodeType.WithStatement; } @@ -611,7 +621,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isWhileStatementNode (node: ESTree.Node): node is ESTree.WhileStatement { + public static isWhileStatementNode(node: ESTree.Node): node is ESTree.WhileStatement { return node.type === NodeType.WhileStatement; } @@ -619,7 +629,7 @@ export class NodeGuards { * @param {Node} node * @returns {boolean} */ - public static isYieldExpressionNode (node: ESTree.Node): node is ESTree.YieldExpression { + public static isYieldExpressionNode(node: ESTree.Node): node is ESTree.YieldExpression { return node.type === NodeType.YieldExpression; } } diff --git a/src/node/NodeLexicalScopeUtils.ts b/src/node/NodeLexicalScopeUtils.ts index eefdbfc1c..119502612 100644 --- a/src/node/NodeLexicalScopeUtils.ts +++ b/src/node/NodeLexicalScopeUtils.ts @@ -9,7 +9,7 @@ export class NodeLexicalScopeUtils { * @param {Node} node * @returns {TNodeWithLexicalScope} */ - public static getLexicalScope (node: ESTree.Node): TNodeWithLexicalScope | undefined { + public static getLexicalScope(node: ESTree.Node): TNodeWithLexicalScope | undefined { return NodeLexicalScopeUtils.getLexicalScopesRecursive(node, 1)[0]; } @@ -17,7 +17,7 @@ export class NodeLexicalScopeUtils { * @param {Node} node * @returns {TNodeWithLexicalScope[]} */ - public static getLexicalScopes (node: ESTree.Node): TNodeWithLexicalScope[] { + public static getLexicalScopes(node: ESTree.Node): TNodeWithLexicalScope[] { return NodeLexicalScopeUtils.getLexicalScopesRecursive(node); } @@ -28,7 +28,7 @@ export class NodeLexicalScopeUtils { * @param {number} depth * @returns {TNodeWithLexicalScope[]} */ - private static getLexicalScopesRecursive ( + private static getLexicalScopesRecursive( node: ESTree.Node, maxSize: number = Infinity, nodesWithLexicalScope: TNodeWithLexicalScope[] = [], diff --git a/src/node/NodeLiteralUtils.ts b/src/node/NodeLiteralUtils.ts index 037b207ad..db45d690d 100644 --- a/src/node/NodeLiteralUtils.ts +++ b/src/node/NodeLiteralUtils.ts @@ -10,7 +10,7 @@ export class NodeLiteralUtils { * @param {Literal} literalNode * @returns {literalNode is TNumberLiteralNode} */ - public static isNumberLiteralNode (literalNode: ESTree.Literal): literalNode is TNumberLiteralNode { + public static isNumberLiteralNode(literalNode: ESTree.Literal): literalNode is TNumberLiteralNode { return typeof literalNode.value === 'number'; } @@ -18,7 +18,7 @@ export class NodeLiteralUtils { * @param {Literal} literalNode * @returns {literalNode is TStringLiteralNode} */ - public static isStringLiteralNode (literalNode: ESTree.Literal): literalNode is TStringLiteralNode { + public static isStringLiteralNode(literalNode: ESTree.Literal): literalNode is TStringLiteralNode { return typeof literalNode.value === 'string'; } @@ -27,7 +27,7 @@ export class NodeLiteralUtils { * @param {Node} parentNode * @returns {boolean} */ - public static isProhibitedLiteralNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): boolean { + public static isProhibitedLiteralNode(literalNode: ESTree.Literal, parentNode: ESTree.Node): boolean { if (NodeGuards.isPropertyNode(parentNode) && !parentNode.computed && parentNode.key === literalNode) { return true; } diff --git a/src/node/NodeMetadata.ts b/src/node/NodeMetadata.ts index aa93c85c4..30fc98d8e 100644 --- a/src/node/NodeMetadata.ts +++ b/src/node/NodeMetadata.ts @@ -5,7 +5,7 @@ export class NodeMetadata { * @param {T} node * @param {Partial} metadata */ - public static set (node: T, metadata: Partial): void { + public static set(node: T, metadata: Partial): void { node.metadata = Object.assign(node.metadata ?? {}, metadata); } @@ -14,20 +14,18 @@ export class NodeMetadata { * @param {keyof T} metadataKey * @returns {T[keyof T] | undefined} */ - public static get < - T extends ESTree.BaseNodeMetadata, - TMetadataKey extends keyof T - > (node: ESTree.Node, metadataKey: TMetadataKey): T[TMetadataKey] | undefined { - return node.metadata !== undefined - ? (node.metadata)[metadataKey] - : undefined; + public static get( + node: ESTree.Node, + metadataKey: TMetadataKey + ): T[TMetadataKey] | undefined { + return node.metadata !== undefined ? (node.metadata)[metadataKey] : undefined; } /** * @param {Node} node * @returns {boolean} */ - public static isEvalHostNode (node: ESTree.Node): boolean { + public static isEvalHostNode(node: ESTree.Node): boolean { return NodeMetadata.get(node, 'evalHostNode') === true; } @@ -35,7 +33,7 @@ export class NodeMetadata { * @param {Node} node * @returns {boolean} */ - public static isForceTransformNode (node: ESTree.Node): boolean { + public static isForceTransformNode(node: ESTree.Node): boolean { return NodeMetadata.get(node, 'forceTransformNode') === true; } @@ -43,7 +41,7 @@ export class NodeMetadata { * @param {Node} node * @returns {boolean} */ - public static isIgnoredNode (node: ESTree.Node): boolean { + public static isIgnoredNode(node: ESTree.Node): boolean { return NodeMetadata.get(node, 'ignoredNode') === true; } @@ -51,21 +49,25 @@ export class NodeMetadata { * @param {Identifier | Literal} node * @returns {boolean} */ - public static isPropertyKeyToRenameNode (node: ESTree.Identifier | ESTree.Literal): boolean { - return NodeMetadata.get( - node, - 'propertyKeyToRenameNode' - ) === true; + public static isPropertyKeyToRenameNode(node: ESTree.Identifier | ESTree.Literal): boolean { + return ( + NodeMetadata.get( + node, + 'propertyKeyToRenameNode' + ) === true + ); } /** * @param {Node} literalNode * @returns {boolean} */ - public static isStringArrayCallLiteralNode (literalNode: ESTree.Literal): boolean { - return NodeMetadata.get< - ESTree.LiteralNodeMetadata, - 'stringArrayCallLiteralNode' - >(literalNode, 'stringArrayCallLiteralNode') === true; + public static isStringArrayCallLiteralNode(literalNode: ESTree.Literal): boolean { + return ( + NodeMetadata.get( + literalNode, + 'stringArrayCallLiteralNode' + ) === true + ); } } diff --git a/src/node/NodeStatementUtils.ts b/src/node/NodeStatementUtils.ts index 0d31aa9f0..6679a2fbe 100644 --- a/src/node/NodeStatementUtils.ts +++ b/src/node/NodeStatementUtils.ts @@ -10,7 +10,7 @@ export class NodeStatementUtils { * @param {Node} node * @returns {TNodeWithStatements} */ - public static getParentNodeWithStatements (node: ESTree.Node): TNodeWithStatements { + public static getParentNodeWithStatements(node: ESTree.Node): TNodeWithStatements { return NodeStatementUtils.getParentNodesWithStatementsRecursive(node, 1)[0]; } @@ -18,7 +18,7 @@ export class NodeStatementUtils { * @param {Node} node * @returns {TNodeWithStatements[]} */ - public static getParentNodesWithStatements (node: ESTree.Node): TNodeWithStatements[] { + public static getParentNodesWithStatements(node: ESTree.Node): TNodeWithStatements[] { return NodeStatementUtils.getParentNodesWithStatementsRecursive(node); } @@ -26,7 +26,7 @@ export class NodeStatementUtils { * @param {Statement} statement * @returns {TStatement | null} */ - public static getNextSiblingStatement (statement: ESTree.Statement): TStatement | null { + public static getNextSiblingStatement(statement: ESTree.Statement): TStatement | null { return NodeStatementUtils.getSiblingStatementByOffset(statement, 1); } @@ -34,7 +34,7 @@ export class NodeStatementUtils { * @param {Statement} statement * @returns {TStatement | null} */ - public static getPreviousSiblingStatement (statement: ESTree.Statement): TStatement | null { + public static getPreviousSiblingStatement(statement: ESTree.Statement): TStatement | null { return NodeStatementUtils.getSiblingStatementByOffset(statement, -1); } @@ -42,7 +42,7 @@ export class NodeStatementUtils { * @param {Node} node * @returns {Statement} */ - public static getRootStatementOfNode (node: ESTree.Node): ESTree.Statement { + public static getRootStatementOfNode(node: ESTree.Node): ESTree.Statement { if (NodeGuards.isProgramNode(node)) { throw new Error('Unable to find root statement for `Program` node'); } @@ -64,7 +64,7 @@ export class NodeStatementUtils { * @param {NodeGuards} node * @returns {TNodeWithStatements} */ - public static getScopeOfNode (node: ESTree.Node): TNodeWithStatements { + public static getScopeOfNode(node: ESTree.Node): TNodeWithStatements { const parentNode: ESTree.Node | undefined = node.parentNode; if (!parentNode) { @@ -85,7 +85,7 @@ export class NodeStatementUtils { * @param {number} depth * @returns {TNodeWithStatements[]} */ - private static getParentNodesWithStatementsRecursive ( + private static getParentNodesWithStatementsRecursive( node: ESTree.Node, maxSize: number = Infinity, nodesWithStatements: TNodeWithStatements[] = [], @@ -112,7 +112,12 @@ export class NodeStatementUtils { } if (node !== parentNode) { - return NodeStatementUtils.getParentNodesWithStatementsRecursive(parentNode, maxSize, nodesWithStatements, ++depth); + return NodeStatementUtils.getParentNodesWithStatementsRecursive( + parentNode, + maxSize, + nodesWithStatements, + ++depth + ); } return nodesWithStatements; @@ -123,11 +128,9 @@ export class NodeStatementUtils { * @param {number} offset * @returns {TStatement | null} */ - private static getSiblingStatementByOffset (statement: ESTree.Statement, offset: number): TStatement | null { + private static getSiblingStatementByOffset(statement: ESTree.Statement, offset: number): TStatement | null { const scopeNode: TNodeWithStatements = NodeStatementUtils.getScopeOfNode(statement); - const scopeBody: TStatement[] = !NodeGuards.isSwitchCaseNode(scopeNode) - ? scopeNode.body - : scopeNode.consequent; + const scopeBody: TStatement[] = !NodeGuards.isSwitchCaseNode(scopeNode) ? scopeNode.body : scopeNode.consequent; const indexInScope: number = scopeBody.indexOf(statement); return scopeBody[indexInScope + offset] || null; diff --git a/src/node/NodeUtils.ts b/src/node/NodeUtils.ts index 22f23ed4b..2834fb661 100644 --- a/src/node/NodeUtils.ts +++ b/src/node/NodeUtils.ts @@ -13,7 +13,7 @@ export class NodeUtils { * @param {ESTree.Literal} literalNode * @returns {ESTree.Literal} */ - public static addXVerbatimPropertyTo (literalNode: ESTree.Literal): ESTree.Literal { + public static addXVerbatimPropertyTo(literalNode: ESTree.Literal): ESTree.Literal { literalNode['x-verbatim-property'] = { content: literalNode.raw, precedence: escodegen.Precedence.Primary @@ -26,7 +26,7 @@ export class NodeUtils { * @param {T} astTree * @returns {T} */ - public static clone (astTree: T): T { + public static clone(astTree: T): T { return NodeUtils.parentizeAst(NodeUtils.cloneRecursive(astTree)); } @@ -34,14 +34,11 @@ export class NodeUtils { * @param {string} code * @returns {ESTree.Statement[]} */ - public static convertCodeToStructure (code: string): ESTree.Statement[] { - const structure: ESTree.Program = ASTParserFacade.parse( - code, - { - ecmaVersion, - sourceType: 'script' - } - ); + public static convertCodeToStructure(code: string): ESTree.Statement[] { + const structure: ESTree.Program = ASTParserFacade.parse(code, { + ecmaVersion, + sourceType: 'script' + }); estraverse.replace(structure, { enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node => { @@ -64,11 +61,14 @@ export class NodeUtils { * @param {NodeGuards[]} structure * @returns {string} */ - public static convertStructureToCode (structure: ESTree.Node[]): string { + public static convertStructureToCode(structure: ESTree.Node[]): string { return structure.reduce((code: string, node: ESTree.Node) => { - return code + escodegen.generate(node, { - sourceMapWithCode: true - }).code; + return ( + code + + escodegen.generate(node, { + sourceMapWithCode: true + }).code + ); }, ''); } @@ -76,7 +76,7 @@ export class NodeUtils { * @param {UnaryExpression} unaryExpressionNode * @returns {NodeGuards} */ - public static getUnaryExpressionArgumentNode (unaryExpressionNode: ESTree.UnaryExpression): ESTree.Node { + public static getUnaryExpressionArgumentNode(unaryExpressionNode: ESTree.UnaryExpression): ESTree.Node { if (NodeGuards.isUnaryExpressionNode(unaryExpressionNode.argument)) { return NodeUtils.getUnaryExpressionArgumentNode(unaryExpressionNode.argument); } @@ -88,7 +88,7 @@ export class NodeUtils { * @param {T} astTree * @returns {T} */ - public static parentizeAst (astTree: T): T { + public static parentizeAst(astTree: T): T { const parentNode: ESTree.Node | null = astTree.parentNode ?? null; estraverse.replace(astTree, { @@ -107,7 +107,7 @@ export class NodeUtils { * @param {Node} parentNode * @returns {T} */ - public static parentizeNode (node: T, parentNode: ESTree.Node | null): T { + public static parentizeNode(node: T, parentNode: ESTree.Node | null): T { node.parentNode = parentNode ?? node; return node; @@ -117,7 +117,7 @@ export class NodeUtils { * @param {T} node * @returns {T} */ - private static cloneRecursive (node: NonNullable): T { + private static cloneRecursive(node: NonNullable): T { if (node === null) { return node; } @@ -125,28 +125,27 @@ export class NodeUtils { const copy: Partial = {}; const nodeKeys: (keyof T)[] = <(keyof T)[]>Object.keys(node); - nodeKeys - .forEach((property: keyof T) => { - if (property === 'parentNode') { - return; - } + nodeKeys.forEach((property: keyof T) => { + if (property === 'parentNode') { + return; + } - const value: T[keyof T] | T[keyof T][] | null = node[property] ?? null; + const value: T[keyof T] | T[keyof T][] | null = node[property] ?? null; - let clonedValue: T[keyof T] | T[keyof T][] | null; + let clonedValue: T[keyof T] | T[keyof T][] | null; - if (value === null || value instanceof RegExp) { - clonedValue = value; - } else if (value instanceof Array) { - clonedValue = value.map(NodeUtils.cloneRecursive); - } else if (typeof value === 'object') { - clonedValue = NodeUtils.cloneRecursive(value); - } else { - clonedValue = value; - } + if (value === null || value instanceof RegExp) { + clonedValue = value; + } else if (value instanceof Array) { + clonedValue = value.map(NodeUtils.cloneRecursive); + } else if (typeof value === 'object') { + clonedValue = NodeUtils.cloneRecursive(value); + } else { + clonedValue = value; + } - copy[property] = clonedValue; - }); + copy[property] = clonedValue; + }); return copy; } diff --git a/src/node/NumericalExpressionDataToNodeConverter.ts b/src/node/NumericalExpressionDataToNodeConverter.ts index 8c1253f49..d217d7834 100644 --- a/src/node/NumericalExpressionDataToNodeConverter.ts +++ b/src/node/NumericalExpressionDataToNodeConverter.ts @@ -15,14 +15,14 @@ export class NumericalExpressionDataToNodeConverter { * @param {TNumericalExpressionDataToNodeConverterLiteralNodeGetter} literalNodeGetter * @returns {Expression} */ - public static convertIntegerNumberData ( + public static convertIntegerNumberData( numberNumericalExpressionData: TNumberNumericalExpressionData, literalNodeGetter: TNumericalExpressionDataToNodeConverterLiteralNodeGetter ): ESTree.Expression { - return NumericalExpressionDataToNodeConverter.convertNumericalExpressionDataToNode( - numberNumericalExpressionData, - literalNodeGetter - ); + return NumericalExpressionDataToNodeConverter.convertNumericalExpressionDataToNode( + numberNumericalExpressionData, + literalNodeGetter + ); } /** @@ -31,13 +31,13 @@ export class NumericalExpressionDataToNodeConverter { * @param {TNumericalExpressionDataToNodeConverterLiteralNodeGetter} literalNodeGetter * @returns {Expression} */ - public static convertFloatNumberData ( + public static convertFloatNumberData( integerNumberNumericalExpressionData: TNumberNumericalExpressionData, decimalPart: number, literalNodeGetter: TNumericalExpressionDataToNodeConverterLiteralNodeGetter ): ESTree.Expression { - const integerNumberNumericalExpressionNode: ESTree.Expression = NumericalExpressionDataToNodeConverter - .convertNumericalExpressionDataToNode( + const integerNumberNumericalExpressionNode: ESTree.Expression = + NumericalExpressionDataToNodeConverter.convertNumericalExpressionDataToNode( integerNumberNumericalExpressionData, literalNodeGetter ); @@ -55,24 +55,28 @@ export class NumericalExpressionDataToNodeConverter { * @param {BinaryOperator} operator * @returns {Expression} */ - private static convertNumericalExpressionDataToNode ( + private static convertNumericalExpressionDataToNode( numberNumericalExpressionData: TNumberNumericalExpressionData, literalNodeGetter: TNumericalExpressionDataToNodeConverterLiteralNodeGetter, operator: ESTree.BinaryOperator = '+' ): ESTree.Expression { const numberNumericalExpressionDataLength: number = numberNumericalExpressionData.length; - const leftParts: TNumberNumericalExpressionData = numberNumericalExpressionDataLength > 1 - ? numberNumericalExpressionData.slice(0, numberNumericalExpressionDataLength - 1) - : [numberNumericalExpressionData[0]]; - const rightParts: TNumberNumericalExpressionData = numberNumericalExpressionDataLength > 1 - ? numberNumericalExpressionData.slice(-1) - : []; + const leftParts: TNumberNumericalExpressionData = + numberNumericalExpressionDataLength > 1 + ? numberNumericalExpressionData.slice(0, numberNumericalExpressionDataLength - 1) + : [numberNumericalExpressionData[0]]; + const rightParts: TNumberNumericalExpressionData = + numberNumericalExpressionDataLength > 1 ? numberNumericalExpressionData.slice(-1) : []; // trailing iterations if (rightParts.length) { - return NumericalExpressionDataToNodeConverter - .convertPartsToBinaryExpression(operator, leftParts, rightParts, literalNodeGetter); + return NumericalExpressionDataToNodeConverter.convertPartsToBinaryExpression( + operator, + leftParts, + rightParts, + literalNodeGetter + ); } const firstLeftPartOrNumber: number | number[] | null = leftParts[0] ?? null; @@ -80,14 +84,14 @@ export class NumericalExpressionDataToNodeConverter { // last iteration when only single left part is left return Array.isArray(firstLeftPartOrNumber) ? NumericalExpressionDataToNodeConverter.convertNumericalExpressionDataToNode( - firstLeftPartOrNumber, - literalNodeGetter, - '*' - ) + firstLeftPartOrNumber, + literalNodeGetter, + '*' + ) : NumericalExpressionDataToNodeConverter.convertPartOrNumberToLiteralNode( - firstLeftPartOrNumber, - literalNodeGetter - ); + firstLeftPartOrNumber, + literalNodeGetter + ); } /** @@ -97,7 +101,7 @@ export class NumericalExpressionDataToNodeConverter { * @param {TNumericalExpressionDataToNodeConverterLiteralNodeGetter} literalNodeGetter * @returns {BinaryExpression} */ - private static convertPartsToBinaryExpression ( + private static convertPartsToBinaryExpression( operator: ESTree.BinaryOperator, leftParts: TNumberNumericalExpressionData, rightParts: TNumberNumericalExpressionData, @@ -127,10 +131,7 @@ export class NumericalExpressionDataToNodeConverter { leftParts, literalNodeGetter ), - this.convertPartOrNumberToLiteralNode( - rightPartOrNumber, - literalNodeGetter - ) + this.convertPartOrNumberToLiteralNode(rightPartOrNumber, literalNodeGetter) ); } } @@ -140,13 +141,11 @@ export class NumericalExpressionDataToNodeConverter { * @param {TNumericalExpressionDataToNodeConverterLiteralNodeGetter} literalNodeGetter * @returns {Expression} */ - private static convertPartOrNumberToLiteralNode ( + private static convertPartOrNumberToLiteralNode( partOrNumber: number | number[], literalNodeGetter: TNumericalExpressionDataToNodeConverterLiteralNodeGetter ): ESTree.Expression { - const number: number = Array.isArray(partOrNumber) - ? partOrNumber[0] - : partOrNumber; + const number: number = Array.isArray(partOrNumber) ? partOrNumber[0] : partOrNumber; const isPositiveNumber: boolean = NumberUtils.isPositive(number); const absoluteNumber: number = Math.abs(number); diff --git a/src/node/ScopeIdentifiersTraverser.ts b/src/node/ScopeIdentifiersTraverser.ts index cb50e4842..7261bfa91 100644 --- a/src/node/ScopeIdentifiersTraverser.ts +++ b/src/node/ScopeIdentifiersTraverser.ts @@ -1,4 +1,4 @@ -import { inject, injectable, } from 'inversify'; +import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../container/ServiceIdentifiers'; import * as eslintScope from 'eslint-scope'; @@ -27,10 +27,7 @@ export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser { /** * @type {string[]} */ - private static readonly globalScopeNames: string[] = [ - 'global', - 'module' - ]; + private static readonly globalScopeNames: string[] = ['global', 'module']; /** * @type {IScopeAnalyzer} @@ -40,9 +37,7 @@ export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser { /** * @param {IScopeAnalyzer} scopeAnalyzer */ - public constructor ( - @inject(ServiceIdentifiers.IScopeAnalyzer) scopeAnalyzer: IScopeAnalyzer - ) { + public constructor(@inject(ServiceIdentifiers.IScopeAnalyzer) scopeAnalyzer: IScopeAnalyzer) { this.scopeAnalyzer = scopeAnalyzer; } @@ -51,7 +46,7 @@ export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser { * @param {Node | null} parentNode * @param {TScopeIdentifiersTraverserCallback} callback */ - public traverseScopeIdentifiers ( + public traverseScopeIdentifiers( programNode: ESTree.Program, parentNode: ESTree.Node | null, callback: TScopeIdentifiersTraverserCallback @@ -68,7 +63,7 @@ export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser { * @param {Node | null} parentNode * @param {TScopeIdentifiersTraverserCallback} callback */ - public traverseScopeThroughIdentifiers ( + public traverseScopeThroughIdentifiers( programNode: ESTree.Program, parentNode: ESTree.Node | null, callback: TScopeIdentifiersTraverserCallback @@ -85,13 +80,15 @@ export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser { * @param {Scope} currentScope * @param {TScopeIdentifiersTraverserCallback} callback */ - private traverseScopeIdentifiersRecursive ( + private traverseScopeIdentifiersRecursive( rootScope: eslintScope.Scope, currentScope: eslintScope.Scope, callback: TScopeIdentifiersTraverserCallback ): void { const variableScope: eslintScope.Scope = currentScope.variableScope; - const variableLexicalScopeNode: TNodeWithLexicalScope | null = NodeGuards.isNodeWithBlockLexicalScope(variableScope.block) + const variableLexicalScopeNode: TNodeWithLexicalScope | null = NodeGuards.isNodeWithBlockLexicalScope( + variableScope.block + ) ? variableScope.block : null; const isGlobalDeclaration: boolean = ScopeIdentifiersTraverser.globalScopeNames.includes(variableScope.type); @@ -105,13 +102,12 @@ export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser { continue; } - const isBubblingDeclaration: boolean = variable - .identifiers - .some((identifier: ESTree.Node) => - identifier.parentNode - && NodeGuards.isPropertyNode(identifier.parentNode) - && identifier.parentNode.shorthand - ); + const isBubblingDeclaration: boolean = variable.identifiers.some( + (identifier: ESTree.Node) => + identifier.parentNode && + NodeGuards.isPropertyNode(identifier.parentNode) && + identifier.parentNode.shorthand + ); callback({ isGlobalDeclaration, @@ -133,13 +129,15 @@ export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser { * @param {Scope} currentScope * @param {TScopeIdentifiersTraverserCallback} callback */ - private traverseScopeThroughIdentifiersRecursive ( + private traverseScopeThroughIdentifiersRecursive( rootScope: eslintScope.Scope, currentScope: eslintScope.Scope, callback: TScopeIdentifiersTraverserCallback ): void { const variableScope: eslintScope.Scope = currentScope.variableScope; - const variableLexicalScopeNode: TNodeWithLexicalScope | null = NodeGuards.isNodeWithBlockLexicalScope(variableScope.block) + const variableLexicalScopeNode: TNodeWithLexicalScope | null = NodeGuards.isNodeWithBlockLexicalScope( + variableScope.block + ) ? variableScope.block : null; const isGlobalDeclaration: boolean = ScopeIdentifiersTraverser.globalScopeNames.includes(variableScope.type); diff --git a/src/options/Options.ts b/src/options/Options.ts index c47f091d9..fc1d92d55 100644 --- a/src/options/Options.ts +++ b/src/options/Options.ts @@ -132,10 +132,7 @@ export class Options implements IOptions { @IsString({ each: true }) - @IsAllowedForObfuscationTargets([ - ObfuscationTarget.Browser, - ObfuscationTarget.BrowserNoEval, - ]) + @IsAllowedForObfuscationTargets([ObfuscationTarget.Browser, ObfuscationTarget.BrowserNoEval]) public readonly domainLock!: string[]; /** @@ -182,8 +179,9 @@ export class Options implements IOptions { @IsString({ each: true }) - @ValidateIf((options: IOptions) => - options.identifierNamesGenerator === IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator + @ValidateIf( + (options: IOptions) => + options.identifierNamesGenerator === IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator ) @ArrayNotEmpty() public readonly identifiersDictionary!: string[]; @@ -415,7 +413,12 @@ export class Options implements IOptions { /** * @type {ObfuscationTarget} */ - @IsIn([ObfuscationTarget.Browser, ObfuscationTarget.BrowserNoEval, ObfuscationTarget.Node, ObfuscationTarget.ServiceWorker]) + @IsIn([ + ObfuscationTarget.Browser, + ObfuscationTarget.BrowserNoEval, + ObfuscationTarget.Node, + ObfuscationTarget.ServiceWorker + ]) public readonly target!: TTypeFromEnum; /** @@ -439,7 +442,7 @@ export class Options implements IOptions { * @param {TInputOptions} inputOptions * @param {IOptionsNormalizer} optionsNormalizer */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.TInputOptions) inputOptions: TInputOptions, @inject(ServiceIdentifiers.IOptionsNormalizer) optionsNormalizer: IOptionsNormalizer ) { @@ -462,7 +465,7 @@ export class Options implements IOptions { * @param {TOptionsPreset} optionsPreset * @returns {TInputOptions} */ - public static getOptionsByPreset (optionsPreset: TOptionsPreset): TInputOptions { + public static getOptionsByPreset(optionsPreset: TOptionsPreset): TInputOptions { const options: TInputOptions | null = Options.optionPresetsMap.get(optionsPreset) ?? null; if (!options) { diff --git a/src/options/OptionsNormalizer.ts b/src/options/OptionsNormalizer.ts index e5f54e9ad..613a3a6e5 100644 --- a/src/options/OptionsNormalizer.ts +++ b/src/options/OptionsNormalizer.ts @@ -43,14 +43,14 @@ export class OptionsNormalizer implements IOptionsNormalizer { StringArrayRule, StringArrayCallsTransformThresholdRule, StringArrayEncodingRule, - StringArrayWrappersChainedCallsRule, + StringArrayWrappersChainedCallsRule ]; /** * @param {IOptions} options * @returns {IOptions} */ - public normalize (options: IOptions): IOptions { + public normalize(options: IOptions): IOptions { let normalizedOptions: IOptions = { ...options }; diff --git a/src/options/ValidationErrorsFormatter.ts b/src/options/ValidationErrorsFormatter.ts index 21c117b15..0e596c0f4 100644 --- a/src/options/ValidationErrorsFormatter.ts +++ b/src/options/ValidationErrorsFormatter.ts @@ -7,7 +7,7 @@ export class ValidationErrorsFormatter { * @param {ValidationError[]} errors * @returns {string} */ - public static format (errors: ValidationError[]): string { + public static format(errors: ValidationError[]): string { return errors .reduce( (errorMessages: string[], error: ValidationError) => [ @@ -23,7 +23,7 @@ export class ValidationErrorsFormatter { * @param {ValidationError} error * @returns {string} */ - private static formatWithNestedConstraints (error: ValidationError): string { + private static formatWithNestedConstraints(error: ValidationError): string { const constraints: TDictionary | undefined = error.constraints; if (!constraints) { @@ -31,8 +31,7 @@ export class ValidationErrorsFormatter { } const rootError: string = `\`${error.property}\` errors:\n`; - const nestedErrors: string = Object - .keys(constraints) + const nestedErrors: string = Object.keys(constraints) .map((constraint: string) => ` - ${constraints[constraint]}\n`) .join(); diff --git a/src/options/normalizer-rules/InputFileNameRule.ts b/src/options/normalizer-rules/InputFileNameRule.ts index 0afc06120..753cc17fe 100644 --- a/src/options/normalizer-rules/InputFileNameRule.ts +++ b/src/options/normalizer-rules/InputFileNameRule.ts @@ -12,11 +12,9 @@ export const InputFileNameRule: TOptionsNormalizerRule = (options: IOptions): IO let { inputFileName } = options; if (inputFileName) { - inputFileName = inputFileName - .replace(/^\/+/, '') - .split(StringSeparator.Dot) - .slice(0, -1) - .join(StringSeparator.Dot) || inputFileName; + inputFileName = + inputFileName.replace(/^\/+/, '').split(StringSeparator.Dot).slice(0, -1).join(StringSeparator.Dot) || + inputFileName; options = { ...options, diff --git a/src/options/normalizer-rules/SourceMapFileNameRule.ts b/src/options/normalizer-rules/SourceMapFileNameRule.ts index e2fa07461..ac5bf6004 100644 --- a/src/options/normalizer-rules/SourceMapFileNameRule.ts +++ b/src/options/normalizer-rules/SourceMapFileNameRule.ts @@ -12,9 +12,7 @@ export const SourceMapFileNameRule: TOptionsNormalizerRule = (options: IOptions) let { sourceMapFileName }: { sourceMapFileName: string } = options; if (sourceMapFileName) { - sourceMapFileName = sourceMapFileName - .replace(/^\/+/, '') - .replace(/(?:\.js)?(?:\.map)?$/, ''); + sourceMapFileName = sourceMapFileName.replace(/^\/+/, '').replace(/(?:\.js)?(?:\.map)?$/, ''); let sourceMapFileNameParts: string[] = sourceMapFileName.split(StringSeparator.Dot); const sourceMapFileNamePartsCount: number = sourceMapFileNameParts.length; diff --git a/src/options/normalizer-rules/StringArrayEncodingRule.ts b/src/options/normalizer-rules/StringArrayEncodingRule.ts index 7782fba5c..03399f43a 100644 --- a/src/options/normalizer-rules/StringArrayEncodingRule.ts +++ b/src/options/normalizer-rules/StringArrayEncodingRule.ts @@ -12,11 +12,9 @@ export const StringArrayEncodingRule: TOptionsNormalizerRule = (options: IOption if (!options.stringArrayEncoding.length) { options = { ...options, - stringArrayEncoding: [ - StringArrayEncoding.None - ] + stringArrayEncoding: [StringArrayEncoding.None] }; } - + return options; }; diff --git a/src/options/normalizer-rules/StringArrayRule.ts b/src/options/normalizer-rules/StringArrayRule.ts index b766ae8bb..c527b8f5b 100644 --- a/src/options/normalizer-rules/StringArrayRule.ts +++ b/src/options/normalizer-rules/StringArrayRule.ts @@ -15,9 +15,7 @@ export const StringArrayRule: TOptionsNormalizerRule = (options: IOptions): IOpt stringArray: false, stringArrayCallsTransform: false, stringArrayCallsTransformThreshold: 0, - stringArrayEncoding: [ - StringArrayEncoding.None - ], + stringArrayEncoding: [StringArrayEncoding.None], stringArrayIndexShift: false, stringArrayRotate: false, stringArrayShuffle: false, diff --git a/src/options/presets/Default.ts b/src/options/presets/Default.ts index b8e059f3d..7881bd14e 100644 --- a/src/options/presets/Default.ts +++ b/src/options/presets/Default.ts @@ -53,12 +53,8 @@ export const DEFAULT_PRESET: TInputOptions = Object.freeze({ stringArray: true, stringArrayCallsTransform: false, stringArrayCallsTransformThreshold: 0.5, - stringArrayEncoding: [ - StringArrayEncoding.None - ], - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumber - ], + stringArrayEncoding: [StringArrayEncoding.None], + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumber], stringArrayIndexShift: true, stringArrayWrappersChainedCalls: true, stringArrayWrappersCount: 1, diff --git a/src/options/presets/HighObfuscation.ts b/src/options/presets/HighObfuscation.ts index 7dedef176..3044e404b 100644 --- a/src/options/presets/HighObfuscation.ts +++ b/src/options/presets/HighObfuscation.ts @@ -14,9 +14,7 @@ export const HIGH_OBFUSCATION_PRESET: TInputOptions = Object.freeze({ optionsPreset: OptionsPreset.HighObfuscation, splitStringsChunkLength: 5, stringArrayCallsTransformThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.Rc4 - ], + stringArrayEncoding: [StringArrayEncoding.Rc4], stringArrayWrappersCount: 5, stringArrayWrappersParametersMaxCount: 5, stringArrayThreshold: 1 diff --git a/src/options/presets/MediumObfuscation.ts b/src/options/presets/MediumObfuscation.ts index 721a1cfe9..24f8ae45d 100644 --- a/src/options/presets/MediumObfuscation.ts +++ b/src/options/presets/MediumObfuscation.ts @@ -15,9 +15,7 @@ export const MEDIUM_OBFUSCATION_PRESET: TInputOptions = Object.freeze({ splitStrings: true, splitStringsChunkLength: 10, stringArrayCallsTransformThreshold: 0.75, - stringArrayEncoding: [ - StringArrayEncoding.Base64 - ], + stringArrayEncoding: [StringArrayEncoding.Base64], stringArrayWrappersCount: 2, stringArrayWrappersParametersMaxCount: 4, stringArrayWrappersType: StringArrayWrappersType.Function, diff --git a/src/options/presets/NoCustomNodes.ts b/src/options/presets/NoCustomNodes.ts index eb80d021b..517f83a3c 100644 --- a/src/options/presets/NoCustomNodes.ts +++ b/src/options/presets/NoCustomNodes.ts @@ -49,12 +49,8 @@ export const NO_ADDITIONAL_NODES_PRESET: TInputOptions = Object.freeze({ stringArray: false, stringArrayCallsTransform: false, stringArrayCallsTransformThreshold: 0, - stringArrayEncoding: [ - StringArrayEncoding.None - ], - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumber - ], + stringArrayEncoding: [StringArrayEncoding.None], + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumber], stringArrayIndexShift: false, stringArrayWrappersChainedCalls: false, stringArrayWrappersCount: 0, diff --git a/src/options/validators/IsAllowedForObfuscationTargets.ts b/src/options/validators/IsAllowedForObfuscationTargets.ts index 435cd44dc..38f457c76 100644 --- a/src/options/validators/IsAllowedForObfuscationTargets.ts +++ b/src/options/validators/IsAllowedForObfuscationTargets.ts @@ -15,7 +15,7 @@ import { DEFAULT_PRESET } from '../presets/Default'; * @param {ValidationOptions} validationOptions * @returns {(options: IOptions, propertyName: keyof IOptions) => void} */ -export function IsAllowedForObfuscationTargets ( +export function IsAllowedForObfuscationTargets( obfuscationTargets: TTypeFromEnum[], validationOptions?: ValidationOptions ): (options: IOptions, propertyName: keyof IOptions) => void { @@ -32,7 +32,7 @@ export function IsAllowedForObfuscationTargets ( * @param {ValidationArguments} validationArguments * @returns {boolean} */ - validate (value: IOptions[keyof IOptions], validationArguments: ValidationArguments): boolean { + validate(value: IOptions[keyof IOptions], validationArguments: ValidationArguments): boolean { const options: IOptions = validationArguments.object; const defaultValue: IOptions[keyof IOptions] | undefined = DEFAULT_PRESET[propertyName]; const isDefaultValue: boolean = equal(value, defaultValue); @@ -44,8 +44,10 @@ export function IsAllowedForObfuscationTargets ( * @param {ValidationArguments} validationArguments * @returns {string} */ - defaultMessage (validationArguments: ValidationArguments): string { - const requiredObfuscationTargetsString: string = obfuscationTargets.join(`${StringSeparator.Comma} `); + defaultMessage(validationArguments: ValidationArguments): string { + const requiredObfuscationTargetsString: string = obfuscationTargets.join( + `${StringSeparator.Comma} ` + ); return `This option allowed only for obfuscation targets: ${requiredObfuscationTargetsString}`; } diff --git a/src/options/validators/IsDomainLockRedirectUrl.ts b/src/options/validators/IsDomainLockRedirectUrl.ts index 0fc0fe0e9..fe2b42b36 100644 --- a/src/options/validators/IsDomainLockRedirectUrl.ts +++ b/src/options/validators/IsDomainLockRedirectUrl.ts @@ -15,16 +15,16 @@ import { IsAllowedForObfuscationTargets } from './IsAllowedForObfuscationTargets */ export const IsDomainLockRedirectUrl = (): PropertyDecorator => { return (target: any, key: string | symbol): void => { - ValidateIf(({domainLockRedirectUrl}: TInputOptions) => { + ValidateIf(({ domainLockRedirectUrl }: TInputOptions) => { return domainLockRedirectUrl !== DEFAULT_PRESET.domainLockRedirectUrl; })(target, key); IsUrl({ require_protocol: false, require_host: false })(target, key); - IsAllowedForObfuscationTargets([ - ObfuscationTarget.Browser, - ObfuscationTarget.BrowserNoEval, - ])(target, key); + IsAllowedForObfuscationTargets([ObfuscationTarget.Browser, ObfuscationTarget.BrowserNoEval])( + target, + key + ); }; }; diff --git a/src/options/validators/IsIdentifierNamesCache.ts b/src/options/validators/IsIdentifierNamesCache.ts index 4ccf441ad..0bf762ede 100644 --- a/src/options/validators/IsIdentifierNamesCache.ts +++ b/src/options/validators/IsIdentifierNamesCache.ts @@ -40,7 +40,7 @@ const validateDictionary = (value: unknown | TIdentifierNamesCacheDictionary): b * @param {ValidationOptions} validationOptions * @returns {(options: IOptions, propertyName: keyof IOptions) => void} */ -export function IsIdentifierNamesCache ( +export function IsIdentifierNamesCache( validationOptions?: ValidationOptions ): (options: IOptions, propertyName: keyof IOptions) => void { return (optionsObject: IOptions, propertyName: keyof IOptions): void => { @@ -56,7 +56,7 @@ export function IsIdentifierNamesCache ( * @param {ValidationArguments} validationArguments * @returns {boolean} */ - validate (value: unknown, validationArguments: ValidationArguments): boolean { + validate(value: unknown, validationArguments: ValidationArguments): boolean { const defaultValue: IOptions[keyof IOptions] | undefined = DEFAULT_PRESET[propertyName]; const isDefaultValue: boolean = equal(value, defaultValue); @@ -78,7 +78,7 @@ export function IsIdentifierNamesCache ( /** * @returns {string} */ - defaultMessage (): string { + defaultMessage(): string { return 'Passed value must be an identifier names cache object or `null` value'; } } diff --git a/src/options/validators/IsInputFileName.ts b/src/options/validators/IsInputFileName.ts index 92b615be2..5661d49d6 100644 --- a/src/options/validators/IsInputFileName.ts +++ b/src/options/validators/IsInputFileName.ts @@ -10,7 +10,7 @@ import { SourceMapSourcesMode } from '../../enums/source-map/SourceMapSourcesMod export const IsInputFileName = (): PropertyDecorator => { return (target: any, key: string | symbol): void => { IsString()(target, key); - ValidateIf(({sourceMapSourcesMode}: TInputOptions) => { + ValidateIf(({ sourceMapSourcesMode }: TInputOptions) => { return sourceMapSourcesMode === SourceMapSourcesMode.Sources; })(target, key); IsNotEmpty()(target, key); diff --git a/src/source-code/ObfuscationResult.ts b/src/source-code/ObfuscationResult.ts index f9e6f9539..30d10f584 100644 --- a/src/source-code/ObfuscationResult.ts +++ b/src/source-code/ObfuscationResult.ts @@ -52,12 +52,12 @@ export class ObfuscationResult implements IObfuscationResult { * @param {IPropertyIdentifierNamesCacheStorage} propertyIdentifierNamesCacheStorage * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.ICryptUtils) cryptUtils: ICryptUtils, @inject(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage) - globalIdentifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage, + globalIdentifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage, @inject(ServiceIdentifiers.IPropertyIdentifierNamesCacheStorage) - propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage, + propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { this.cryptUtils = cryptUtils; @@ -70,7 +70,7 @@ export class ObfuscationResult implements IObfuscationResult { * @param {string} obfuscatedCode * @param {string} sourceMap */ - public initialize (obfuscatedCode: string, sourceMap: string): void { + public initialize(obfuscatedCode: string, sourceMap: string): void { this.obfuscatedCode = obfuscatedCode; this.sourceMap = sourceMap; } @@ -78,7 +78,7 @@ export class ObfuscationResult implements IObfuscationResult { /** * @returns {string} */ - public getIdentifierNamesCache (): TIdentifierNamesCache { + public getIdentifierNamesCache(): TIdentifierNamesCache { if (!this.options.identifierNamesCache) { return null; } @@ -92,35 +92,35 @@ export class ObfuscationResult implements IObfuscationResult { /** * @returns {string} */ - public getObfuscatedCode (): string { + public getObfuscatedCode(): string { return this.correctObfuscatedCode(); } /** * @returns {IOptions} */ - public getOptions (): IOptions { + public getOptions(): IOptions { return this.options; } /** * @returns {string} */ - public getSourceMap (): string { + public getSourceMap(): string { return this.sourceMap; } /** * @returns {string} */ - public toString (): string { + public toString(): string { return this.obfuscatedCode; } /** * @returns {string} */ - private correctObfuscatedCode (): string { + private correctObfuscatedCode(): string { if (!this.sourceMap) { return this.obfuscatedCode; } diff --git a/src/source-code/SourceCode.ts b/src/source-code/SourceCode.ts index ece6606b1..7db97a294 100644 --- a/src/source-code/SourceCode.ts +++ b/src/source-code/SourceCode.ts @@ -15,7 +15,7 @@ export class SourceCode implements ISourceCode { * @param {string} sourceCode * @param {string} sourceMap */ - public constructor (sourceCode: string, sourceMap: string) { + public constructor(sourceCode: string, sourceMap: string) { this.sourceCode = sourceCode; this.sourceMap = sourceMap; } @@ -23,21 +23,21 @@ export class SourceCode implements ISourceCode { /** * @returns {string} */ - public getSourceCode (): string { + public getSourceCode(): string { return this.sourceCode; } /** * @returns {string} */ - public getSourceMap (): string { + public getSourceMap(): string { return this.sourceMap; } /** * @returns {string} */ - public toString (): string { + public toString(): string { return this.sourceCode; } } diff --git a/src/storages/ArrayStorage.ts b/src/storages/ArrayStorage.ts index a29d32c84..cb1fa91c2 100644 --- a/src/storages/ArrayStorage.ts +++ b/src/storages/ArrayStorage.ts @@ -8,7 +8,7 @@ import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator'; import { initializable } from '../decorators/Initializable'; @injectable() -export abstract class ArrayStorage implements IArrayStorage { +export abstract class ArrayStorage implements IArrayStorage { /** * @type {V[]} */ @@ -40,7 +40,7 @@ export abstract class ArrayStorage implements IArrayStorage { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -49,7 +49,7 @@ export abstract class ArrayStorage implements IArrayStorage { } @postConstruct() - public initialize (): void { + public initialize(): void { this.storage = []; this.storageId = this.randomGenerator.getRandomString(6); } @@ -58,7 +58,7 @@ export abstract class ArrayStorage implements IArrayStorage { * @param {number} key * @returns {V | undefined} */ - public delete (key: number): V | undefined { + public delete(key: number): V | undefined { const deletedElement: V | undefined = this.storage.splice(key, 1)[0] ?? undefined; if (deletedElement) { @@ -72,7 +72,7 @@ export abstract class ArrayStorage implements IArrayStorage { * @param {number} key * @returns {V | undefined} */ - public get (key: number): V | undefined { + public get(key: number): V | undefined { return this.storage[key]; } @@ -80,7 +80,7 @@ export abstract class ArrayStorage implements IArrayStorage { * @param {number} key * @returns {V} */ - public getOrThrow (key: number): V { + public getOrThrow(key: number): V { const value: V | undefined = this.get(key); if (!value) { @@ -94,7 +94,7 @@ export abstract class ArrayStorage implements IArrayStorage { * @param {V} value * @returns {number} */ - public getKeyOf (value: V): number | null { + public getKeyOf(value: V): number | null { const key: number = this.storage.indexOf(value); return key >= 0 ? key : null; @@ -103,21 +103,21 @@ export abstract class ArrayStorage implements IArrayStorage { /** * @returns {number} */ - public getLength (): number { + public getLength(): number { return this.storageLength; } /** * @returns {V[]} */ - public getStorage (): V[] { + public getStorage(): V[] { return this.storage; } /** * @returns {string} */ - public getStorageId (): string { + public getStorageId(): string { return this.storageId; } @@ -125,7 +125,7 @@ export abstract class ArrayStorage implements IArrayStorage { * @param {this} storage * @param {boolean} mergeId */ - public mergeWith (storage: this, mergeId: boolean = false): void { + public mergeWith(storage: this, mergeId: boolean = false): void { this.storage = [...this.storage, ...storage.getStorage()]; if (mergeId) { @@ -137,7 +137,7 @@ export abstract class ArrayStorage implements IArrayStorage { * @param {number} key * @param {V} value */ - public set (key: number, value: V): void { + public set(key: number, value: V): void { if (key === this.storageLength) { this.storage.push(value); } else { diff --git a/src/storages/MapStorage.ts b/src/storages/MapStorage.ts index cc9b88423..4935099ff 100644 --- a/src/storages/MapStorage.ts +++ b/src/storages/MapStorage.ts @@ -9,7 +9,7 @@ import { initializable } from '../decorators/Initializable'; import { TDictionary } from '../types/TDictionary'; @injectable() -export abstract class MapStorage implements IMapStorage { +export abstract class MapStorage implements IMapStorage { /** * @type {string} */ @@ -20,7 +20,7 @@ export abstract class MapStorage implements IMapStorage { * @type {Map } */ @initializable() - protected storage!: Map ; + protected storage!: Map; /** * @type {IOptions} @@ -36,7 +36,7 @@ export abstract class MapStorage implements IMapStorage { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -45,8 +45,8 @@ export abstract class MapStorage implements IMapStorage { } @postConstruct() - public initialize (): void { - this.storage = new Map (); + public initialize(): void { + this.storage = new Map(); this.storageId = this.randomGenerator.getRandomString(6); } @@ -54,7 +54,7 @@ export abstract class MapStorage implements IMapStorage { * @param {K} key * @returns {V | undefined} */ - public get (key: K): V | undefined { + public get(key: K): V | undefined { return this.storage.get(key); } @@ -62,7 +62,7 @@ export abstract class MapStorage implements IMapStorage { * @param {K} key * @returns {V} */ - public getOrThrow (key: K): V { + public getOrThrow(key: K): V { const value: V | undefined = this.get(key); if (!value) { @@ -76,7 +76,7 @@ export abstract class MapStorage implements IMapStorage { * @param {V} value * @returns {K | null} */ - public getKeyOf (value: V): K | null { + public getKeyOf(value: V): K | null { for (const [key, storageValue] of this.storage) { if (value === storageValue) { return key; @@ -89,28 +89,28 @@ export abstract class MapStorage implements IMapStorage { /** * @returns {number} */ - public getLength (): number { + public getLength(): number { return this.storage.size; } /** * @returns {Map} */ - public getStorage (): Map { + public getStorage(): Map { return this.storage; } /** * @returns {TDictionary} */ - public getStorageAsDictionary (): TDictionary { + public getStorageAsDictionary(): TDictionary { return Object.fromEntries(this.storage); } /** * @returns {string} */ - public getStorageId (): string { + public getStorageId(): string { return this.storageId; } @@ -118,7 +118,7 @@ export abstract class MapStorage implements IMapStorage { * @param {K} key * @returns {boolean} */ - public has (key: K): boolean { + public has(key: K): boolean { return this.storage.has(key); } @@ -126,8 +126,8 @@ export abstract class MapStorage implements IMapStorage { * @param {this} storage * @param {boolean} mergeId */ - public mergeWith (storage: this, mergeId: boolean = false): void { - this.storage = new Map ([...this.storage, ...storage.getStorage()]); + public mergeWith(storage: this, mergeId: boolean = false): void { + this.storage = new Map([...this.storage, ...storage.getStorage()]); if (mergeId) { this.storageId = storage.getStorageId(); @@ -138,7 +138,7 @@ export abstract class MapStorage implements IMapStorage { * @param {K} key * @param {V} value */ - public set (key: K, value: V): void { + public set(key: K, value: V): void { this.storage.set(key, value); } } diff --git a/src/storages/WeakMapStorage.ts b/src/storages/WeakMapStorage.ts index bfe2f7bc9..9184940ce 100644 --- a/src/storages/WeakMapStorage.ts +++ b/src/storages/WeakMapStorage.ts @@ -8,7 +8,7 @@ import { IWeakMapStorage } from '../interfaces/storages/IWeakMapStorage'; import { initializable } from '../decorators/Initializable'; @injectable() -export abstract class WeakMapStorage implements IWeakMapStorage { +export abstract class WeakMapStorage implements IWeakMapStorage { /** * @type {string} */ @@ -19,7 +19,7 @@ export abstract class WeakMapStorage implements IWeakMapSt * @type {WeakMap } */ @initializable() - protected storage!: WeakMap ; + protected storage!: WeakMap; /** * @type {IOptions} @@ -35,7 +35,7 @@ export abstract class WeakMapStorage implements IWeakMapSt * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -44,8 +44,8 @@ export abstract class WeakMapStorage implements IWeakMapSt } @postConstruct() - public initialize (): void { - this.storage = new Map (); + public initialize(): void { + this.storage = new Map(); this.storageId = this.randomGenerator.getRandomString(6); } @@ -53,7 +53,7 @@ export abstract class WeakMapStorage implements IWeakMapSt * @param {K} key * @returns {V | undefined} */ - public get (key: K): V | undefined { + public get(key: K): V | undefined { return this.storage.get(key); } @@ -61,7 +61,7 @@ export abstract class WeakMapStorage implements IWeakMapSt * @param {K} key * @returns {V} */ - public getOrThrow (key: K): V { + public getOrThrow(key: K): V { const value: V | undefined = this.get(key); if (!value) { @@ -74,14 +74,14 @@ export abstract class WeakMapStorage implements IWeakMapSt /** * @returns {WeakMap} */ - public getStorage (): WeakMap { + public getStorage(): WeakMap { return this.storage; } /** * @returns {string} */ - public getStorageId (): string { + public getStorageId(): string { return this.storageId; } @@ -89,7 +89,7 @@ export abstract class WeakMapStorage implements IWeakMapSt * @param {K} key * @returns {boolean} */ - public has (key: K): boolean { + public has(key: K): boolean { return this.storage.has(key); } @@ -97,7 +97,7 @@ export abstract class WeakMapStorage implements IWeakMapSt * @param {K} key * @param {V} value */ - public set (key: K, value: V): void { + public set(key: K, value: V): void { this.storage.set(key, value); } } diff --git a/src/storages/control-flow-transformers/FunctionControlFlowStorage.ts b/src/storages/control-flow-transformers/FunctionControlFlowStorage.ts index 655f23e11..30b4b9c0e 100644 --- a/src/storages/control-flow-transformers/FunctionControlFlowStorage.ts +++ b/src/storages/control-flow-transformers/FunctionControlFlowStorage.ts @@ -5,16 +5,14 @@ import { TIdentifierNamesGeneratorFactory } from '../../types/container/generato import { IControlFlowStorage } from '../../interfaces/storages/control-flow-transformers/IControlFlowStorage'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { - IIdentifierNamesGenerator -} from '../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator'; +import { IIdentifierNamesGenerator } from '../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator'; import { IOptions } from '../../interfaces/options/IOptions'; import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; import { MapStorage } from '../MapStorage'; @injectable() -export class FunctionControlFlowStorage extends MapStorage implements IControlFlowStorage { +export class FunctionControlFlowStorage extends MapStorage implements IControlFlowStorage { /** * @type {IIdentifierNamesGenerator} */ @@ -25,11 +23,11 @@ export class FunctionControlFlowStorage extends MapStorage * @param {IOptions} options * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory ) { super(randomGenerator, options); diff --git a/src/storages/control-flow-transformers/StringControlFlowStorage.ts b/src/storages/control-flow-transformers/StringControlFlowStorage.ts index 5ff22c7d2..7288e7b22 100644 --- a/src/storages/control-flow-transformers/StringControlFlowStorage.ts +++ b/src/storages/control-flow-transformers/StringControlFlowStorage.ts @@ -15,17 +15,16 @@ export class StringControlFlowStorage extends FunctionControlFlowStorage { * @param {IOptions} options * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory */ - public constructor ( - + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory ) { super(randomGenerator, options, identifierNamesGeneratorFactory); } - public override initialize (): void { + public override initialize(): void { super.initialize(); this.storageId = this.identifierNamesGenerator.generateForGlobalScope(); diff --git a/src/storages/custom-code-helpers/CustomCodeHelperGroupStorage.ts b/src/storages/custom-code-helpers/CustomCodeHelperGroupStorage.ts index 11cafa37e..d43fa5aff 100644 --- a/src/storages/custom-code-helpers/CustomCodeHelperGroupStorage.ts +++ b/src/storages/custom-code-helpers/CustomCodeHelperGroupStorage.ts @@ -12,7 +12,7 @@ import { CustomCodeHelperGroup } from '../../enums/custom-code-helpers/CustomCod import { MapStorage } from '../MapStorage'; @injectable() -export class CustomCodeHelperGroupStorage extends MapStorage { +export class CustomCodeHelperGroupStorage extends MapStorage { /** * @type {CustomCodeHelperGroup[]} */ @@ -34,8 +34,9 @@ export class CustomCodeHelperGroupStorage extends MapStorage { - const customCodeHelperGroup: ICustomCodeHelperGroup = this.customCodeHelperGroupFactory(customCodeHelperGroupName); + CustomCodeHelperGroupStorage.customCodeHelperGroupsList.forEach( + (customCodeHelperGroupName: CustomCodeHelperGroup) => { + const customCodeHelperGroup: ICustomCodeHelperGroup = + this.customCodeHelperGroupFactory(customCodeHelperGroupName); - this.storage.set(customCodeHelperGroupName, customCodeHelperGroup); - }); + this.storage.set(customCodeHelperGroupName, customCodeHelperGroup); + } + ); } } diff --git a/src/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.ts b/src/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.ts index 1453d0aff..04fc83a13 100644 --- a/src/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.ts +++ b/src/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.ts @@ -8,12 +8,15 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; import { MapStorage } from '../MapStorage'; @injectable() -export class GlobalIdentifierNamesCacheStorage extends MapStorage implements IGlobalIdentifierNamesCacheStorage { - /** +export class GlobalIdentifierNamesCacheStorage + extends MapStorage + implements IGlobalIdentifierNamesCacheStorage +{ + /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -21,8 +24,8 @@ export class GlobalIdentifierNamesCacheStorage extends MapStorage implements IPropertyIdentifierNamesCacheStorage { - /** +export class PropertyIdentifierNamesCacheStorage + extends MapStorage + implements IPropertyIdentifierNamesCacheStorage +{ + /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -21,8 +24,8 @@ export class PropertyIdentifierNamesCacheStorage extends MapStorage implements ILiteralNodesCacheStorage { +export class LiteralNodesCacheStorage extends MapStorage implements ILiteralNodesCacheStorage { /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -30,10 +30,7 @@ export class LiteralNodesCacheStorage extends MapStorage i * @param {IStringArrayStorageItemData | undefined} stringArrayStorageItemData * @returns {string} */ - public buildKey ( - literalValue: string, - stringArrayStorageItemData: IStringArrayStorageItemData | undefined, - ): string { + public buildKey(literalValue: string, stringArrayStorageItemData: IStringArrayStorageItemData | undefined): string { return `${literalValue}-${Boolean(stringArrayStorageItemData)}`; } @@ -42,14 +39,16 @@ export class LiteralNodesCacheStorage extends MapStorage i * @param {IStringArrayStorageItemData | undefined} stringArrayStorageItemData * @returns {boolean} */ - public shouldUseCachedValue ( + public shouldUseCachedValue( key: string, stringArrayStorageItemData: IStringArrayStorageItemData | undefined ): boolean { // for each function scope different nodes will be created, so cache have no sense - return !this.options.stringArrayWrappersCount + return ( + !this.options.stringArrayWrappersCount && // different nodes will be created with different rc4 keys, so cache have no sense - && stringArrayStorageItemData?.encoding !== StringArrayEncoding.Rc4 - && this.storage.has(key); + stringArrayStorageItemData?.encoding !== StringArrayEncoding.Rc4 && + this.storage.has(key) + ); } } diff --git a/src/storages/string-array-transformers/StringArrayScopeCallsWrappersDataStorage.ts b/src/storages/string-array-transformers/StringArrayScopeCallsWrappersDataStorage.ts index 153b0abf6..11d15a671 100644 --- a/src/storages/string-array-transformers/StringArrayScopeCallsWrappersDataStorage.ts +++ b/src/storages/string-array-transformers/StringArrayScopeCallsWrappersDataStorage.ts @@ -11,15 +11,15 @@ import { IStringArrayScopeCallsWrappersDataStorage } from '../../interfaces/stor import { WeakMapStorage } from '../WeakMapStorage'; @injectable() -export class StringArrayScopeCallsWrappersDataStorage extends WeakMapStorage < - TNodeWithLexicalScopeStatements, - TStringArrayScopeCallsWrappersDataByEncoding -> implements IStringArrayScopeCallsWrappersDataStorage { +export class StringArrayScopeCallsWrappersDataStorage + extends WeakMapStorage + implements IStringArrayScopeCallsWrappersDataStorage +{ /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { diff --git a/src/storages/string-array-transformers/StringArrayStorage.ts b/src/storages/string-array-transformers/StringArrayStorage.ts index 7d91579b6..ebdd04075 100644 --- a/src/storages/string-array-transformers/StringArrayStorage.ts +++ b/src/storages/string-array-transformers/StringArrayStorage.ts @@ -18,7 +18,10 @@ import { StringArrayEncoding } from '../../enums/node-transformers/string-array- import { MapStorage } from '../MapStorage'; @injectable() -export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEncoding}`, IStringArrayStorageItemData> implements IStringArrayStorage { +export class StringArrayStorage + extends MapStorage<`${string}-${TStringArrayEncoding}`, IStringArrayStorageItemData> + implements IStringArrayStorage +{ /** * @type {number} */ @@ -106,9 +109,9 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc * @param {IOptions} options * @param {ICryptUtilsStringArray} cryptUtilsStringArray */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, + identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils, @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions, @@ -120,68 +123,69 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc this.arrayUtils = arrayUtils; this.cryptUtilsStringArray = cryptUtilsStringArray; - this.rc4Keys = this.randomGenerator.getRandomGenerator() - .n( - () => this.randomGenerator.getRandomGenerator().string({ + this.rc4Keys = this.randomGenerator.getRandomGenerator().n( + () => + this.randomGenerator.getRandomGenerator().string({ length: StringArrayStorage.rc4KeyLength }), - StringArrayStorage.rc4KeysCount - ); + StringArrayStorage.rc4KeysCount + ); } @postConstruct() - public override initialize (): void { + public override initialize(): void { super.initialize(); this.indexShiftAmount = this.options.stringArrayIndexShift ? this.randomGenerator.getRandomInteger( - StringArrayStorage.minimumIndexShiftAmount, - StringArrayStorage.maximumIndexShiftAmount - ) + StringArrayStorage.minimumIndexShiftAmount, + StringArrayStorage.maximumIndexShiftAmount + ) : 0; this.rotationAmount = this.options.stringArrayRotate ? this.randomGenerator.getRandomInteger( - StringArrayStorage.minimumRotationAmount, - StringArrayStorage.maximumRotationAmount - ) + StringArrayStorage.minimumRotationAmount, + StringArrayStorage.maximumRotationAmount + ) : 0; } /** * @param {string} value */ - public override get (value: string): IStringArrayStorageItemData { + public override get(value: string): IStringArrayStorageItemData { return this.getOrSetIfDoesNotExist(value); } /** * @returns {number} */ - public getIndexShiftAmount (): number { + public getIndexShiftAmount(): number { return this.indexShiftAmount; } /** * @returns {number} */ - public getRotationAmount (): number { + public getRotationAmount(): number { return this.rotationAmount; } /** * @returns {string} */ - public getStorageName (): string { + public getStorageName(): string { return this.getStorageId(); } /** * @returns {string} */ - public override getStorageId (): string { + public override getStorageId(): string { if (!this.stringArrayStorageName) { - this.stringArrayStorageName = this.identifierNamesGenerator - .generateForGlobalScope(StringArrayStorage.stringArrayFunctionNameLength); + this.stringArrayStorageName = this.identifierNamesGenerator.generateForGlobalScope( + StringArrayStorage.stringArrayFunctionNameLength + ); } return this.stringArrayStorageName; @@ -191,56 +195,48 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc * @param {TStringArrayEncoding | null} stringArrayEncoding * @returns {IStringArrayCallsWrapperNames} */ - public getStorageCallsWrapperName (stringArrayEncoding: TStringArrayEncoding | null): string { - const storageCallsWrapperName: string | null = this.stringArrayStorageCallsWrapperNamesMap - .get(stringArrayEncoding) ?? null; + public getStorageCallsWrapperName(stringArrayEncoding: TStringArrayEncoding | null): string { + const storageCallsWrapperName: string | null = + this.stringArrayStorageCallsWrapperNamesMap.get(stringArrayEncoding) ?? null; if (storageCallsWrapperName) { return storageCallsWrapperName; } - const newStorageCallsWrapperName: string = this.identifierNamesGenerator - .generateForGlobalScope(StringArrayStorage.stringArrayFunctionNameLength); - - this.stringArrayStorageCallsWrapperNamesMap.set( - stringArrayEncoding, - newStorageCallsWrapperName + const newStorageCallsWrapperName: string = this.identifierNamesGenerator.generateForGlobalScope( + StringArrayStorage.stringArrayFunctionNameLength ); + this.stringArrayStorageCallsWrapperNamesMap.set(stringArrayEncoding, newStorageCallsWrapperName); + return newStorageCallsWrapperName; } - public rotateStorage (): void { + public rotateStorage(): void { if (!this.getLength()) { return; } - this.storage = new Map( - this.arrayUtils.rotate( - Array.from(this.storage.entries()), - this.rotationAmount - ) - ); + this.storage = new Map(this.arrayUtils.rotate(Array.from(this.storage.entries()), this.rotationAmount)); } - public shuffleStorage (): void { + public shuffleStorage(): void { this.storage = new Map( this.arrayUtils .shuffle(Array.from(this.storage.entries())) .map<[`${string}-${TStringArrayEncoding}`, IStringArrayStorageItemData]>( - ( - [value, stringArrayStorageItemData], - index: number - ) => { + ([value, stringArrayStorageItemData], index: number) => { stringArrayStorageItemData.index = index; return [value, stringArrayStorageItemData]; } ) - .sort(( - [, stringArrayStorageItemDataA]: [string, IStringArrayStorageItemData], - [, stringArrayStorageItemDataB]: [string, IStringArrayStorageItemData] - ) => stringArrayStorageItemDataA.index - stringArrayStorageItemDataB.index) + .sort( + ( + [, stringArrayStorageItemDataA]: [string, IStringArrayStorageItemData], + [, stringArrayStorageItemDataB]: [string, IStringArrayStorageItemData] + ) => stringArrayStorageItemDataA.index - stringArrayStorageItemDataB.index + ) ); } @@ -248,7 +244,7 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc * @param {string} value * @returns {IStringArrayStorageItemData} */ - private getOrSetIfDoesNotExist (value: string): IStringArrayStorageItemData { + private getOrSetIfDoesNotExist(value: string): IStringArrayStorageItemData { const { encodedValue, encoding, decodeKey }: IEncodedValue = this.getEncodedValue(value); const cacheKey: `${string}-${TStringArrayEncoding}` = `${encodedValue}-${encoding}`; @@ -275,11 +271,9 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc * @param {string} value * @returns {IEncodedValue} */ - private getEncodedValue (value: string): IEncodedValue { + private getEncodedValue(value: string): IEncodedValue { const encoding: TStringArrayEncoding | null = this.options.stringArrayEncoding.length - ? this.randomGenerator - .getRandomGenerator() - .pickone(this.options.stringArrayEncoding) + ? this.randomGenerator.getRandomGenerator().pickone(this.options.stringArrayEncoding) : null; if (!encoding) { @@ -303,12 +297,15 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc */ case StringArrayEncoding.Rc4: { const decodeKey: string = this.randomGenerator.getRandomGenerator().pickone(this.rc4Keys); - const encodedValue: string = this.cryptUtilsStringArray.btoa(this.cryptUtilsStringArray.rc4(value, decodeKey)); + const encodedValue: string = this.cryptUtilsStringArray.btoa( + this.cryptUtilsStringArray.rc4(value, decodeKey) + ); const encodedValueSources: string[] = this.rc4EncodedValuesSourcesCache.get(encodedValue) ?? []; let encodedValueSourcesLength: number = encodedValueSources.length; - const shouldAddValueToSourcesCache: boolean = !encodedValueSourcesLength || !encodedValueSources.includes(value); + const shouldAddValueToSourcesCache: boolean = + !encodedValueSourcesLength || !encodedValueSources.includes(value); if (shouldAddValueToSourcesCache) { encodedValueSources.push(value); diff --git a/src/storages/string-array-transformers/VisitedLexicalScopeNodesStackStorage.ts b/src/storages/string-array-transformers/VisitedLexicalScopeNodesStackStorage.ts index 80a5883e7..cbc72fd3e 100644 --- a/src/storages/string-array-transformers/VisitedLexicalScopeNodesStackStorage.ts +++ b/src/storages/string-array-transformers/VisitedLexicalScopeNodesStackStorage.ts @@ -11,7 +11,10 @@ import { IVisitedLexicalScopeNodesStackStorage } from '../../interfaces/storages import { ArrayStorage } from '../ArrayStorage'; @injectable() -export class VisitedLexicalScopeNodesStackStorage extends ArrayStorage implements IVisitedLexicalScopeNodesStackStorage { +export class VisitedLexicalScopeNodesStackStorage + extends ArrayStorage + implements IVisitedLexicalScopeNodesStackStorage +{ /** * @type {IArrayUtils} */ @@ -22,10 +25,10 @@ export class VisitedLexicalScopeNodesStackStorage extends ArrayStorage = {[key: string]: T}; +export type TDictionary = { [key: string]: T }; diff --git a/src/types/TIdentifierNamesCache.ts b/src/types/TIdentifierNamesCache.ts index 76c7ccee5..de7006017 100644 --- a/src/types/TIdentifierNamesCache.ts +++ b/src/types/TIdentifierNamesCache.ts @@ -4,4 +4,3 @@ export type TIdentifierNamesCache = { globalIdentifiers?: TIdentifierNamesCacheDictionary; propertyIdentifiers?: TIdentifierNamesCacheDictionary; } | null; - diff --git a/src/types/TInitialData.ts b/src/types/TInitialData.ts index bdc90063e..044baa7fc 100644 --- a/src/types/TInitialData.ts +++ b/src/types/TInitialData.ts @@ -1,3 +1,3 @@ import { IInitializable } from '../interfaces/IInitializable'; -export type TInitialData = Parameters; +export type TInitialData = Parameters; diff --git a/src/types/TObfuscationResultsObject.ts b/src/types/TObfuscationResultsObject.ts index 6c4be60a3..55a3cb80e 100644 --- a/src/types/TObfuscationResultsObject.ts +++ b/src/types/TObfuscationResultsObject.ts @@ -1,3 +1,3 @@ import { IObfuscationResult } from '../interfaces/source-code/IObfuscationResult'; -export type TObfuscationResultsObject = {[key in keyof TSourceCodesObject]: IObfuscationResult}; +export type TObfuscationResultsObject = { [key in keyof TSourceCodesObject]: IObfuscationResult }; diff --git a/src/types/cli/TCLISanitizer.ts b/src/types/cli/TCLISanitizer.ts index e1058160d..ea12582cd 100644 --- a/src/types/cli/TCLISanitizer.ts +++ b/src/types/cli/TCLISanitizer.ts @@ -1 +1 @@ -export type TCLISanitizer = (value: string) => T; +export type TCLISanitizer = (value: string) => T; diff --git a/src/types/container/custom-code-helpers/TCustomCodeHelperFactory.ts b/src/types/container/custom-code-helpers/TCustomCodeHelperFactory.ts index 01feb86fc..b506406ff 100644 --- a/src/types/container/custom-code-helpers/TCustomCodeHelperFactory.ts +++ b/src/types/container/custom-code-helpers/TCustomCodeHelperFactory.ts @@ -2,6 +2,6 @@ import { ICustomCodeHelper } from '../../../interfaces/custom-code-helpers/ICust import { CustomCodeHelper } from '../../../enums/custom-code-helpers/CustomCodeHelper'; -export type TCustomCodeHelperFactory = < - TInitialData extends unknown[] = unknown[] -> (customCodeHelperName: CustomCodeHelper) => ICustomCodeHelper; +export type TCustomCodeHelperFactory = ( + customCodeHelperName: CustomCodeHelper +) => ICustomCodeHelper; diff --git a/src/types/container/custom-code-helpers/TCustomCodeHelperGroupFactory.ts b/src/types/container/custom-code-helpers/TCustomCodeHelperGroupFactory.ts index eb22c680f..c53553b2b 100644 --- a/src/types/container/custom-code-helpers/TCustomCodeHelperGroupFactory.ts +++ b/src/types/container/custom-code-helpers/TCustomCodeHelperGroupFactory.ts @@ -2,4 +2,6 @@ import { ICustomCodeHelperGroup } from '../../../interfaces/custom-code-helpers/ import { CustomCodeHelperGroup } from '../../../enums/custom-code-helpers/CustomCodeHelperGroup'; -export type TCustomCodeHelperGroupFactory = (customCodeHelperGroupName: CustomCodeHelperGroup) => ICustomCodeHelperGroup; +export type TCustomCodeHelperGroupFactory = ( + customCodeHelperGroupName: CustomCodeHelperGroup +) => ICustomCodeHelperGroup; diff --git a/src/types/container/custom-nodes/TControlFlowCustomNodeFactory.ts b/src/types/container/custom-nodes/TControlFlowCustomNodeFactory.ts index b917b71b8..5935b4f51 100644 --- a/src/types/container/custom-nodes/TControlFlowCustomNodeFactory.ts +++ b/src/types/container/custom-nodes/TControlFlowCustomNodeFactory.ts @@ -2,6 +2,6 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCustomNode'; -export type TControlFlowCustomNodeFactory = < - TInitialData extends unknown[] = unknown[] -> (controlFlowCustomNodeName: ControlFlowCustomNode) => ICustomNode; +export type TControlFlowCustomNodeFactory = ( + controlFlowCustomNodeName: ControlFlowCustomNode +) => ICustomNode; diff --git a/src/types/container/custom-nodes/TDeadNodeInjectionCustomNodeFactory.ts b/src/types/container/custom-nodes/TDeadNodeInjectionCustomNodeFactory.ts index e10858f57..4efc15724 100644 --- a/src/types/container/custom-nodes/TDeadNodeInjectionCustomNodeFactory.ts +++ b/src/types/container/custom-nodes/TDeadNodeInjectionCustomNodeFactory.ts @@ -2,6 +2,6 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; import { DeadCodeInjectionCustomNode } from '../../../enums/custom-nodes/DeadCodeInjectionCustomNode'; -export type TDeadNodeInjectionCustomNodeFactory = < - TInitialData extends unknown[] = unknown[] -> (deadCodeInjectionCustomNodeName: DeadCodeInjectionCustomNode) => ICustomNode ; +export type TDeadNodeInjectionCustomNodeFactory = ( + deadCodeInjectionCustomNodeName: DeadCodeInjectionCustomNode +) => ICustomNode; diff --git a/src/types/container/custom-nodes/TObjectExpressionKeysTransformerCustomNodeFactory.ts b/src/types/container/custom-nodes/TObjectExpressionKeysTransformerCustomNodeFactory.ts index 8cc94f03d..92dbd03f5 100644 --- a/src/types/container/custom-nodes/TObjectExpressionKeysTransformerCustomNodeFactory.ts +++ b/src/types/container/custom-nodes/TObjectExpressionKeysTransformerCustomNodeFactory.ts @@ -2,6 +2,6 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; import { ObjectExpressionKeysTransformerCustomNode } from '../../../enums/custom-nodes/ObjectExpressionKeysTransformerCustomNode'; -export type TObjectExpressionKeysTransformerCustomNodeFactory = < - TInitialData extends unknown[] = unknown[] -> (objectExpressionKeysTransformerNodeName: ObjectExpressionKeysTransformerCustomNode) => ICustomNode ; +export type TObjectExpressionKeysTransformerCustomNodeFactory = ( + objectExpressionKeysTransformerNodeName: ObjectExpressionKeysTransformerCustomNode +) => ICustomNode; diff --git a/src/types/container/custom-nodes/TStringArrayCustomNodeFactory.ts b/src/types/container/custom-nodes/TStringArrayCustomNodeFactory.ts index b118f2e3c..1de9aa261 100644 --- a/src/types/container/custom-nodes/TStringArrayCustomNodeFactory.ts +++ b/src/types/container/custom-nodes/TStringArrayCustomNodeFactory.ts @@ -2,6 +2,6 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; import { StringArrayCustomNode } from '../../../enums/custom-nodes/StringArrayCustomNode'; -export type TStringArrayCustomNodeFactory = < - TInitialData extends unknown[] = unknown[] -> (stringArrayCustomNodeName: StringArrayCustomNode) => ICustomNode ; +export type TStringArrayCustomNodeFactory = ( + stringArrayCustomNodeName: StringArrayCustomNode +) => ICustomNode; diff --git a/src/types/container/node-transformers/TControlFlowStorageFactoryCreator.ts b/src/types/container/node-transformers/TControlFlowStorageFactoryCreator.ts index 3a2a1ecbc..de5968775 100644 --- a/src/types/container/node-transformers/TControlFlowStorageFactoryCreator.ts +++ b/src/types/container/node-transformers/TControlFlowStorageFactoryCreator.ts @@ -2,4 +2,6 @@ import { TControlFlowStorageFactory } from './TControlFlowStorageFactory'; import { ControlFlowStorage } from '../../../enums/storages/ControlFlowStorage'; -export type TControlFlowStorageFactoryCreator = (controlFlowStorageName: ControlFlowStorage) => TControlFlowStorageFactory; +export type TControlFlowStorageFactoryCreator = ( + controlFlowStorageName: ControlFlowStorage +) => TControlFlowStorageFactory; diff --git a/src/types/container/node-transformers/TObjectExpressionExtractorFactory.ts b/src/types/container/node-transformers/TObjectExpressionExtractorFactory.ts index 59e16175f..75334c48b 100644 --- a/src/types/container/node-transformers/TObjectExpressionExtractorFactory.ts +++ b/src/types/container/node-transformers/TObjectExpressionExtractorFactory.ts @@ -2,5 +2,6 @@ import { IObjectExpressionExtractor } from '../../../interfaces/node-transformer import { ObjectExpressionExtractor } from '../../../enums/node-transformers/converting-transformers/properties-extractors/ObjectExpressionExtractor'; -export type TObjectExpressionExtractorFactory = - (objectExpressionExtractorName: ObjectExpressionExtractor) => IObjectExpressionExtractor; +export type TObjectExpressionExtractorFactory = ( + objectExpressionExtractorName: ObjectExpressionExtractor +) => IObjectExpressionExtractor; diff --git a/src/types/node/TNodeWithSingleStatementBody.ts b/src/types/node/TNodeWithSingleStatementBody.ts index d2a4e5f40..d0e387080 100644 --- a/src/types/node/TNodeWithSingleStatementBody.ts +++ b/src/types/node/TNodeWithSingleStatementBody.ts @@ -1,21 +1,18 @@ import * as ESTree from 'estree'; -export type TNodeWithSingleStatementBody = ( - ESTree.LabeledStatement - | ESTree.WithStatement - | ESTree.WhileStatement - | ESTree.DoWhileStatement - | ESTree.ForStatement - | ESTree.ForInStatement - | ESTree.ForOfStatement - & { - body: Exclude; - } -) -| ( - ESTree.IfStatement - & { - consequent: Exclude; - alternate?: Exclude | null; - } -); +export type TNodeWithSingleStatementBody = + | ( + | ESTree.LabeledStatement + | ESTree.WithStatement + | ESTree.WhileStatement + | ESTree.DoWhileStatement + | ESTree.ForStatement + | ESTree.ForInStatement + | (ESTree.ForOfStatement & { + body: Exclude; + }) + ) + | (ESTree.IfStatement & { + consequent: Exclude; + alternate?: Exclude | null; + }); diff --git a/src/types/node/TNumberLiteralNode.ts b/src/types/node/TNumberLiteralNode.ts index 11ed90ee1..c4db9545b 100644 --- a/src/types/node/TNumberLiteralNode.ts +++ b/src/types/node/TNumberLiteralNode.ts @@ -1,3 +1,3 @@ import * as ESTree from 'estree'; -export type TNumberLiteralNode = ESTree.Literal & {value: number}; +export type TNumberLiteralNode = ESTree.Literal & { value: number }; diff --git a/src/types/node/TScopeIdentifiersTraverserCallback.ts b/src/types/node/TScopeIdentifiersTraverserCallback.ts index 1f79ea2a9..aab195083 100644 --- a/src/types/node/TScopeIdentifiersTraverserCallback.ts +++ b/src/types/node/TScopeIdentifiersTraverserCallback.ts @@ -1 +1 @@ -export type TScopeIdentifiersTraverserCallback = (data: TData) => void; +export type TScopeIdentifiersTraverserCallback = (data: TData) => void; diff --git a/src/types/node/TStringLiteralNode.ts b/src/types/node/TStringLiteralNode.ts index 051c03f99..c23c0b956 100644 --- a/src/types/node/TStringLiteralNode.ts +++ b/src/types/node/TStringLiteralNode.ts @@ -1,3 +1,3 @@ import * as ESTree from 'estree'; -export type TStringLiteralNode = ESTree.Literal & {value: string}; +export type TStringLiteralNode = ESTree.Literal & { value: string }; diff --git a/src/types/storages/TCustomCodeHelperGroupStorage.ts b/src/types/storages/TCustomCodeHelperGroupStorage.ts index be1aeb0aa..a0a3d5c2c 100644 --- a/src/types/storages/TCustomCodeHelperGroupStorage.ts +++ b/src/types/storages/TCustomCodeHelperGroupStorage.ts @@ -1,4 +1,4 @@ import { ICustomCodeHelperGroup } from '../../interfaces/custom-code-helpers/ICustomCodeHelperGroup'; import { IMapStorage } from '../../interfaces/storages/IMapStorage'; -export type TCustomCodeHelperGroupStorage = IMapStorage ; +export type TCustomCodeHelperGroupStorage = IMapStorage; diff --git a/src/types/utils/TTransformersRelationEdge.ts b/src/types/utils/TTransformersRelationEdge.ts index 87681dfb4..316867ba2 100644 --- a/src/types/utils/TTransformersRelationEdge.ts +++ b/src/types/utils/TTransformersRelationEdge.ts @@ -1,4 +1,4 @@ -export type TTransformersRelationEdge = [ +export type TTransformersRelationEdge = [ transformerNameA: TTransformerName, transformerNameB: TTransformerName | null ]; diff --git a/src/types/utils/TTypeFromEnum.ts b/src/types/utils/TTypeFromEnum.ts index 9dd551e2f..4ed6749b5 100644 --- a/src/types/utils/TTypeFromEnum.ts +++ b/src/types/utils/TTypeFromEnum.ts @@ -1 +1 @@ -export type TTypeFromEnum = (T)[keyof T]; +export type TTypeFromEnum = T[keyof T]; diff --git a/src/utils/AbstractTransformerNamesGroupsBuilder.ts b/src/utils/AbstractTransformerNamesGroupsBuilder.ts index 4a9a38a21..08fdff6fd 100644 --- a/src/utils/AbstractTransformerNamesGroupsBuilder.ts +++ b/src/utils/AbstractTransformerNamesGroupsBuilder.ts @@ -9,21 +9,19 @@ import { ITransformer } from '../interfaces/ITransformer'; import { ITransformerNamesGroupsBuilder } from '../interfaces/utils/ITransformerNamesGroupsBuilder'; @injectable() -export abstract class AbstractTransformerNamesGroupsBuilder < +export abstract class AbstractTransformerNamesGroupsBuilder< TTransformerName extends string, TTransformer extends ITransformer -> implements ITransformerNamesGroupsBuilder < - TTransformerName, - TTransformer -> { +> implements ITransformerNamesGroupsBuilder +{ /** * @type {ILevelledTopologicalSorter} */ private readonly levelledTopologicalSorter: ILevelledTopologicalSorter; - public constructor ( + public constructor( @inject(ServiceIdentifiers.ILevelledTopologicalSorter) - levelledTopologicalSorter: ILevelledTopologicalSorter + levelledTopologicalSorter: ILevelledTopologicalSorter ) { this.levelledTopologicalSorter = levelledTopologicalSorter; } @@ -51,7 +49,7 @@ export abstract class AbstractTransformerNamesGroupsBuilder < * @param {TDictionary} normalizedTransformers * @returns {TTransformerName[][]} */ - public build (normalizedTransformers: TDictionary): TTransformerName[][] { + public build(normalizedTransformers: TDictionary): TTransformerName[][] { const transformerNames: TTransformerName[] = Object.keys(normalizedTransformers); const relationEdges: TTransformersRelationEdge[] = this.buildTransformersRelationEdges( transformerNames, @@ -70,7 +68,7 @@ export abstract class AbstractTransformerNamesGroupsBuilder < * @param {TDictionary} normalizedTransformers * @returns {TTransformersRelationEdge[]} */ - private buildTransformersRelationEdges ( + private buildTransformersRelationEdges( transformerNames: TTransformerName[], normalizedTransformers: TDictionary ): TTransformersRelationEdge[] { diff --git a/src/utils/ArrayUtils.ts b/src/utils/ArrayUtils.ts index ad2151586..718ee2298 100644 --- a/src/utils/ArrayUtils.ts +++ b/src/utils/ArrayUtils.ts @@ -14,9 +14,7 @@ export class ArrayUtils implements IArrayUtils { /** * @param {IRandomGenerator} randomGenerator */ - public constructor ( - @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator - ) { + public constructor(@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator) { this.randomGenerator = randomGenerator; } @@ -24,7 +22,7 @@ export class ArrayUtils implements IArrayUtils { * @param {number} length * @returns {number[]} */ - public createWithRange (length: number): number[] { + public createWithRange(length: number): number[] { const range: number[] = []; for (let i: number = 0; i < length; i++) { @@ -39,7 +37,7 @@ export class ArrayUtils implements IArrayUtils { * @param {(index: number) => TValue} valueFunction * @returns {TValue[]} */ - public fillWithRange (length: number, valueFunction: (index: number) => TValue): TValue[] { + public fillWithRange(length: number, valueFunction: (index: number) => TValue): TValue[] { const range: TValue[] = []; for (let i: number = 0; i < length; i++) { @@ -53,14 +51,14 @@ export class ArrayUtils implements IArrayUtils { * @param {T[]} array * @returns {T | null} */ - public findMostOccurringElement (array: T[]): T | null { + public findMostOccurringElement(array: T[]): T | null { const arrayLength: number = array.length; if (!arrayLength) { return null; } - const elementsMap: Partial<{[key in T]: number}> = {}; + const elementsMap: Partial<{ [key in T]: number }> = {}; let mostOccurringElement: T = array[0]; let mostOccurringElementCount: number = 1; @@ -84,7 +82,7 @@ export class ArrayUtils implements IArrayUtils { * @param {T[]} array * @returns {T | undefined} */ - public getLastElement (array: T[]): T | undefined { + public getLastElement(array: T[]): T | undefined { return this.getLastElementByIndex(array, 0); } @@ -93,7 +91,7 @@ export class ArrayUtils implements IArrayUtils { * @param {number} index * @returns {T | undefined} */ - public getLastElementByIndex (array: T[], index: number): T | undefined { + public getLastElementByIndex(array: T[], index: number): T | undefined { const arrayLength: number = array.length; return array[arrayLength - 1 - index] ?? undefined; @@ -104,7 +102,7 @@ export class ArrayUtils implements IArrayUtils { * @param {number} times * @returns {T[]} */ - public rotate (array: T[], times: number): T[] { + public rotate(array: T[], times: number): T[] { if (!array.length) { throw new ReferenceError('Cannot rotate empty array.'); } @@ -132,7 +130,7 @@ export class ArrayUtils implements IArrayUtils { * @param {T[]} array * @returns {T[]} */ - public shuffle (array: T[]): T[] { + public shuffle(array: T[]): T[] { const shuffledArray: T[] = [...array]; for (let i: number = shuffledArray.length; i; i--) { diff --git a/src/utils/CryptUtils.ts b/src/utils/CryptUtils.ts index 84712efaa..344ed4c2c 100644 --- a/src/utils/CryptUtils.ts +++ b/src/utils/CryptUtils.ts @@ -24,9 +24,7 @@ export class CryptUtils implements ICryptUtils { /** * @param {IRandomGenerator} randomGenerator */ - public constructor ( - @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator - ) { + public constructor(@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator) { this.randomGenerator = randomGenerator; } @@ -34,7 +32,7 @@ export class CryptUtils implements ICryptUtils { * @param {string} string * @returns {string} */ - public btoa (string: string): string { + public btoa(string: string): string { const chars: string = this.base64Alphabet; let output: string = ''; @@ -45,16 +43,18 @@ export class CryptUtils implements ICryptUtils { for ( let block: number | undefined, charCode: number, idx: number = 0, map: string = chars; - string.charAt(idx | 0) || (map = '=', idx % 1); - output += map.charAt(63 & block >> 8 - idx % 1 * 8) + string.charAt(idx | 0) || ((map = '='), idx % 1); + output += map.charAt(63 & (block >> (8 - (idx % 1) * 8))) ) { - charCode = string.charCodeAt(idx += 3/4); + charCode = string.charCodeAt((idx += 3 / 4)); - if (charCode > 0xFF) { - throw new Error('\'btoa\' failed: The string to be encoded contains characters outside of the Latin1 range.'); + if (charCode > 0xff) { + throw new Error( + '\'btoa\' failed: The string to be encoded contains characters outside of the Latin1 range.' + ); } - block = block << 8 | charCode; + block = ((block) << 8) | charCode; } return output; @@ -67,9 +67,8 @@ export class CryptUtils implements ICryptUtils { * @param {number} length * @returns {[string , string]} */ - public hideString (str: string, length: number): [string, string] { - const escapeRegExp: (s: string) => string = (s: string) => - s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + public hideString(str: string, length: number): [string, string] { + const escapeRegExp: (s: string) => string = (s: string) => s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); const randomMerge: (s1: string, s2: string) => string = (s1: string, s2: string): string => { let i1: number = -1; @@ -92,10 +91,7 @@ export class CryptUtils implements ICryptUtils { pool: RandomGenerator.randomGeneratorPool }); - let randomStringDiff: string = randomString.replace( - new RegExp(`[${escapeRegExp(str)}]`, 'g'), - '' - ); + let randomStringDiff: string = randomString.replace(new RegExp(`[${escapeRegExp(str)}]`, 'g'), ''); const randomStringDiffArray: string[] = randomStringDiff.split(''); @@ -113,7 +109,7 @@ export class CryptUtils implements ICryptUtils { * @param {string} key * @returns {string} */ - public rc4 (string: string, key: string): string { + public rc4(string: string, key: string): string { const s: number[] = []; let j: number = 0; diff --git a/src/utils/CryptUtilsStringArray.ts b/src/utils/CryptUtilsStringArray.ts index 18132298c..b51049274 100644 --- a/src/utils/CryptUtilsStringArray.ts +++ b/src/utils/CryptUtilsStringArray.ts @@ -18,9 +18,7 @@ export class CryptUtilsStringArray extends CryptUtils implements ICryptUtilsStri /** * @param {IRandomGenerator} randomGenerator */ - public constructor ( - @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator - ) { + public constructor(@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator) { super(randomGenerator); } @@ -30,7 +28,7 @@ export class CryptUtilsStringArray extends CryptUtils implements ICryptUtilsStri * @param {string} string * @returns {string} */ - public override btoa (string: string): string { + public override btoa(string: string): string { const output = super.btoa(string); return output.replace(/=+$/, ''); diff --git a/src/utils/EscapeSequenceEncoder.ts b/src/utils/EscapeSequenceEncoder.ts index 0600778a1..6db012ab3 100644 --- a/src/utils/EscapeSequenceEncoder.ts +++ b/src/utils/EscapeSequenceEncoder.ts @@ -22,14 +22,14 @@ export class EscapeSequenceEncoder implements IEscapeSequenceEncoder { /** * @type {Map} */ - private readonly stringsCache: Map = new Map(); + private readonly stringsCache: Map = new Map(); /** * @param {string} string * @param {boolean} encodeAllSymbols * @returns {string} */ - public encode (string: string, encodeAllSymbols: boolean): string { + public encode(string: string, encodeAllSymbols: boolean): string { const cacheKey: string = `${string}-${String(encodeAllSymbols)}`; if (this.stringsCache.has(cacheKey)) { @@ -43,8 +43,8 @@ export class EscapeSequenceEncoder implements IEscapeSequenceEncoder { let template: string; const result: string = string.replace(replaceRegExp, (character: string): string => { - const shouldEncodeCharacter: boolean = encodeAllSymbols - || EscapeSequenceEncoder.forceEscapeCharactersRegExp.test(character); + const shouldEncodeCharacter: boolean = + encodeAllSymbols || EscapeSequenceEncoder.forceEscapeCharactersRegExp.test(character); if (!shouldEncodeCharacter) { return character; diff --git a/src/utils/LevelledTopologicalSorter.ts b/src/utils/LevelledTopologicalSorter.ts index a38b1b0f9..faccb3416 100644 --- a/src/utils/LevelledTopologicalSorter.ts +++ b/src/utils/LevelledTopologicalSorter.ts @@ -4,7 +4,7 @@ import { ILevelledTopologicalSorter } from '../interfaces/utils/ILevelledTopolog type TVisitMark = 'ok' | 'visiting'; -interface IVisitMarks { +interface IVisitMarks { [key: string]: TVisitMark; } @@ -12,7 +12,7 @@ interface IVisitMarks { * Port and rework of https://github.com/loveencounterflow/ltsort */ @injectable() -export class LevelledTopologicalSorter implements ILevelledTopologicalSorter { +export class LevelledTopologicalSorter implements ILevelledTopologicalSorter { /** * @type {Map implemen * @param {TValue | null} consequent * @returns {this} */ - public add ( - precedent: TValue, - consequent: TValue | null = null - ): this { + public add(precedent: TValue, consequent: TValue | null = null): this { if (consequent !== null) { return this.link(precedent, consequent); } @@ -39,7 +36,7 @@ export class LevelledTopologicalSorter implemen * * @returns {TValue[]} */ - public sort (): TValue[] { + public sort(): TValue[] { const consequents: TValue[] = Array.from(this.graph.keys()); const results: TValue[] = []; @@ -59,7 +56,7 @@ export class LevelledTopologicalSorter implemen /** * @returns {TValue[][]} */ - public sortByGroups (): TValue[][] { + public sortByGroups(): TValue[][] { this.sort(); const resultItemsGroups: TValue[][] = []; @@ -80,7 +77,7 @@ export class LevelledTopologicalSorter implemen /** * @param {TValue} consequent */ - private delete (consequent: TValue): void { + private delete(consequent: TValue): void { const precedents: TValue[] = this.getPrecedents(consequent); if (precedents.length) { @@ -107,7 +104,7 @@ export class LevelledTopologicalSorter implemen /** * @returns {TValue[]} */ - private findRootNodes (): TValue[] { + private findRootNodes(): TValue[] { const consequents: TValue[] = Array.from(this.graph.keys()); const rootNodes: TValue[] = []; @@ -124,7 +121,7 @@ export class LevelledTopologicalSorter implemen * @param {TValue} consequent * @returns {TValue[]} */ - private getPrecedents (consequent: TValue): TValue[] { + private getPrecedents(consequent: TValue): TValue[] { const precedents: TValue[] | undefined = this.graph.get(consequent); if (!precedents) { @@ -137,7 +134,7 @@ export class LevelledTopologicalSorter implemen /** * @returns {boolean} */ - private hasNodes (): boolean { + private hasNodes(): boolean { return this.graph.size > 0; } @@ -145,7 +142,7 @@ export class LevelledTopologicalSorter implemen * @param {TValue} consequent * @returns {boolean} */ - private hasPrecedents (consequent: TValue): boolean { + private hasPrecedents(consequent: TValue): boolean { return this.getPrecedents(consequent).length > 0; } @@ -154,7 +151,7 @@ export class LevelledTopologicalSorter implemen * @param {TValue} consequent * @returns {this} */ - private link (precedent: TValue, consequent: TValue): this { + private link(precedent: TValue, consequent: TValue): this { this.register(precedent); this.register(consequent); @@ -171,7 +168,7 @@ export class LevelledTopologicalSorter implemen * @param {TValue} name * @returns {this} */ - private register (name: TValue): this { + private register(name: TValue): this { if (!this.graph.has(name)) { this.graph.set(name, []); } @@ -185,11 +182,7 @@ export class LevelledTopologicalSorter implemen * @param {TValue} name * @returns {null} */ - private visit ( - results: TValue[], - marks: IVisitMarks, - name: TValue - ): void { + private visit(results: TValue[], marks: IVisitMarks, name: TValue): void { const mark: TVisitMark = marks[name]; if (mark === 'visiting') { diff --git a/src/utils/NumberUtils.ts b/src/utils/NumberUtils.ts index 949229ef5..c7f76705f 100644 --- a/src/utils/NumberUtils.ts +++ b/src/utils/NumberUtils.ts @@ -5,12 +5,10 @@ export class NumberUtils { * @param {number} number * @returns {string} */ - public static toHex (number: number | bigint): string { + public static toHex(number: number | bigint): string { const radix: number = 16; - const basePart: string = typeof number === 'number' - ? number.toString(radix) - : `${number.toString(radix)}n`; + const basePart: string = typeof number === 'number' ? number.toString(radix) : `${number.toString(radix)}n`; return `${Utils.hexadecimalPrefix}${basePart}`; } @@ -19,11 +17,9 @@ export class NumberUtils { * @param {number} number * @returns {[number, (number | null)]} */ - public static extractIntegerAndDecimalParts (number: number): [number, number | null] { + public static extractIntegerAndDecimalParts(number: number): [number, number | null] { const integerPart: number = Math.trunc(number); - const decimalPart: number | null = number !== integerPart - ? number % 1 - : null; + const decimalPart: number | null = number !== integerPart ? number % 1 : null; return [integerPart, decimalPart]; } @@ -32,17 +28,15 @@ export class NumberUtils { * @param {number} number * @returns {boolean} */ - public static isCeil (number: number | bigint): boolean { - return typeof number === 'number' - ? number % 1 === 0 - : true; + public static isCeil(number: number | bigint): boolean { + return typeof number === 'number' ? number % 1 === 0 : true; } /** * @param {number} number * @returns {boolean} */ - public static isPositive (number: number): boolean { + public static isPositive(number: number): boolean { if (isNaN(number)) { throw new Error('Given value is NaN'); } @@ -66,7 +60,7 @@ export class NumberUtils { * @param {number} number * @returns {boolean} */ - public static isUnsafeNumber (number: number): boolean { + public static isUnsafeNumber(number: number): boolean { if (isNaN(number)) { throw new Error('Given value is NaN'); } @@ -81,7 +75,7 @@ export class NumberUtils { * @param {number} number * @returns {number[]} */ - public static getFactors (number: number): number[] { + public static getFactors(number: number): number[] { if (number === 0) { throw new Error('Invalid number. Allowed only non-zero number'); } @@ -99,13 +93,9 @@ export class NumberUtils { const isEven: boolean = number % 2 === 0; const incrementValue: number = isEven ? 1 : 2; - for ( - let currentFactor = 1; - currentFactor <= root; - currentFactor += incrementValue - ) { + for (let currentFactor = 1; currentFactor <= root; currentFactor += incrementValue) { const compliment: number = number / currentFactor; - const check = (number - Math.floor(compliment) * currentFactor) !== 0; + const check = number - Math.floor(compliment) * currentFactor !== 0; if (check) { continue; diff --git a/src/utils/RandomGenerator.ts b/src/utils/RandomGenerator.ts index a27daf4ce..9381a6c05 100644 --- a/src/utils/RandomGenerator.ts +++ b/src/utils/RandomGenerator.ts @@ -41,7 +41,7 @@ export class RandomGenerator implements IRandomGenerator, IInitializable { * @param {ISourceCode} sourceCode * @param {IOptions} options */ - public constructor ( + public constructor( @inject(ServiceIdentifiers.ISourceCode) sourceCode: ISourceCode, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { @@ -50,21 +50,21 @@ export class RandomGenerator implements IRandomGenerator, IInitializable { } @postConstruct() - public initialize (): void { + public initialize(): void { this.randomGenerator = new Chance(this.getRawSeed()); } /** * @returns {number} */ - public getMathRandom (): number { + public getMathRandom(): number { return this.getRandomInteger(0, 99999) / 100000; } /** * @returns {Chance.Chance} */ - public getRandomGenerator (): Chance.Chance { + public getRandomGenerator(): Chance.Chance { return this.randomGenerator; } @@ -73,7 +73,7 @@ export class RandomGenerator implements IRandomGenerator, IInitializable { * @param {number} max * @returns {number} */ - public getRandomInteger (min: number, max: number): number { + public getRandomInteger(min: number, max: number): number { return this.getRandomGenerator().integer({ min: min, max: max @@ -86,7 +86,7 @@ export class RandomGenerator implements IRandomGenerator, IInitializable { * @param {number[]} valuesToExclude * @returns {number} */ - public getRandomIntegerExcluding (min: number, max: number, valuesToExclude: number[]): number { + public getRandomIntegerExcluding(min: number, max: number, valuesToExclude: number[]): number { const valuesToPickArray: number[] = []; for (let value: number = min; value <= max; value++) { @@ -105,14 +105,14 @@ export class RandomGenerator implements IRandomGenerator, IInitializable { * @param {string} pool * @returns {string} */ - public getRandomString (length: number, pool: string = RandomGenerator.randomGeneratorPool): string { + public getRandomString(length: number, pool: string = RandomGenerator.randomGeneratorPool): string { return this.getRandomGenerator().string({ length, pool }); } /** * @returns {string} */ - public getInputSeed (): string { + public getInputSeed(): string { return this.options.seed.toString(); } @@ -122,7 +122,7 @@ export class RandomGenerator implements IRandomGenerator, IInitializable { * * @returns {number} */ - public getRawSeed (): string { + public getRawSeed(): string { const inputSeed: string = this.getInputSeed(); const inputSeedParts: string[] = `${inputSeed}`.split('|'); diff --git a/src/utils/SetUtils.ts b/src/utils/SetUtils.ts index e19ef24b0..1be1749f5 100644 --- a/src/utils/SetUtils.ts +++ b/src/utils/SetUtils.ts @@ -14,9 +14,7 @@ export class SetUtils implements ISetUtils { /** * @param {IArrayUtils} arrayUtils */ - public constructor ( - @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils - ) { + public constructor(@inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils) { this.arrayUtils = arrayUtils; } @@ -24,7 +22,7 @@ export class SetUtils implements ISetUtils { * @param {Set} set * @returns {T | undefined} */ - public getLastElement (set: Set): T | undefined { + public getLastElement(set: Set): T | undefined { const array = [...set]; return this.arrayUtils.getLastElement(array); diff --git a/src/utils/StringUtils.ts b/src/utils/StringUtils.ts index 56c01d15c..51b182495 100644 --- a/src/utils/StringUtils.ts +++ b/src/utils/StringUtils.ts @@ -5,7 +5,7 @@ export class StringUtils { * @param {string} string * @returns {string} */ - public static escapeJsString (string: string): string { + public static escapeJsString(string: string): string { return jsStringEscape(string); } } diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 31b0a06bb..fc44fa209 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -14,7 +14,7 @@ export class Utils { * @param {string} buildTimestamp * @returns {string} */ - public static buildVersionMessage (version?: string, buildTimestamp?: string): string { + public static buildVersionMessage(version?: string, buildTimestamp?: string): string { const isUnknownVersion = !version || !buildTimestamp; if (isUnknownVersion) { @@ -30,7 +30,7 @@ export class Utils { * @param {string} url * @returns {string} */ - public static extractDomainFrom (url: string): string { + public static extractDomainFrom(url: string): string { let domain: string; if (url.includes('://') || url.indexOf('//') === 0) { @@ -49,7 +49,7 @@ export class Utils { * @param {number} sourceCodeIndex * @returns {string} */ - public static getIdentifiersPrefixForMultipleSources ( + public static getIdentifiersPrefixForMultipleSources( identifiersPrefix: string | undefined, sourceCodeIndex: number ): string { @@ -64,10 +64,9 @@ export class Utils { * @param {TObject} enumLikeObject * @returns {Readonly} */ - public static makeEnum< - TObject extends {[index: string]: TValue}, - TValue extends string - > (enumLikeObject: TObject): Readonly { - return Object.freeze({...enumLikeObject}); + public static makeEnum( + enumLikeObject: TObject + ): Readonly { + return Object.freeze({ ...enumLikeObject }); } } diff --git a/test/declarations/index.d.ts b/test/declarations/index.d.ts index f0adad508..c86cc6420 100644 --- a/test/declarations/index.d.ts +++ b/test/declarations/index.d.ts @@ -1,3 +1,3 @@ /// /// -/// \ No newline at end of file +/// diff --git a/test/declarations/source-map-resolve.d.ts b/test/declarations/source-map-resolve.d.ts index e36b6e300..3f5cfa6ff 100644 --- a/test/declarations/source-map-resolve.d.ts +++ b/test/declarations/source-map-resolve.d.ts @@ -14,6 +14,6 @@ declare module 'source-map-resolve' { map: ExistingRawSourceMap, mapUrl: string, read: (path: string, callback: (error: Error | null, data: Buffer | string) => void) => void, - callback: (error: Error | null, result: ResolvedSources) => void, + callback: (error: Error | null, result: ResolvedSources) => void ): void; -} \ No newline at end of file +} diff --git a/test/dev/dev-compile-performance.ts b/test/dev/dev-compile-performance.ts index 3116dc5db..adb28ac63 100644 --- a/test/dev/dev-compile-performance.ts +++ b/test/dev/dev-compile-performance.ts @@ -7,9 +7,7 @@ import * as fs from 'fs'; let start: any = new Date(); - JavaScriptObfuscator.obfuscate( - fs.readFileSync('test/fixtures/compile-performance.js', 'utf8') - ).getObfuscatedCode(); + JavaScriptObfuscator.obfuscate(fs.readFileSync('test/fixtures/compile-performance.js', 'utf8')).getObfuscatedCode(); console.log(`Total time: ${new Date() - start}`); })(); diff --git a/test/dev/dev-runtime-performance.ts b/test/dev/dev-runtime-performance.ts index 0a0841cf4..16d99c7ca 100644 --- a/test/dev/dev-runtime-performance.ts +++ b/test/dev/dev-runtime-performance.ts @@ -3,7 +3,8 @@ (function () { const JavaScriptObfuscator: any = require('../../index'); - let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(` + let obfuscatedCode: string = JavaScriptObfuscator.obfuscate( + ` var start = new Date(); var log = console.log; console.log = function () {}; @@ -73,7 +74,7 @@ console.log(new Date() - start); `, { - disableConsoleOutput: false, + disableConsoleOutput: false } ).getObfuscatedCode(); diff --git a/test/dev/dev.ts b/test/dev/dev.ts index 7190cd665..e0067263c 100644 --- a/test/dev/dev.ts +++ b/test/dev/dev.ts @@ -10,29 +10,29 @@ } `, { - "compact": false, - "controlFlowFlattening": true, - "controlFlowFlatteningThreshold": 1, - "disableConsoleOutput": false, - "identifierNamesGenerator": "mangled", - "log": true, - "numbersToExpressions": true, - "renameProperties": true, - "renamePropertiesMode": "safe", - "simplify": false, - "stringArray": true, - "stringArrayCallsTransform": true, - "stringArrayIndexShift": true, - "stringArrayRotate": false, - "stringArrayShuffle": false, - "stringArrayWrappersCount": 5, - "stringArrayWrappersChainedCalls": true, - "stringArrayWrappersParametersMaxCount": 5, - "stringArrayWrappersType": "function", - "stringArrayThreshold": 0, - "transformObjectKeys": true, - "unicodeEscapeSequence": false, - "ignoreImports": false + compact: false, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + disableConsoleOutput: false, + identifierNamesGenerator: 'mangled', + log: true, + numbersToExpressions: true, + renameProperties: true, + renamePropertiesMode: 'safe', + simplify: false, + stringArray: true, + stringArrayCallsTransform: true, + stringArrayIndexShift: true, + stringArrayRotate: false, + stringArrayShuffle: false, + stringArrayWrappersCount: 5, + stringArrayWrappersChainedCalls: true, + stringArrayWrappersParametersMaxCount: 5, + stringArrayWrappersType: 'function', + stringArrayThreshold: 0, + transformObjectKeys: true, + unicodeEscapeSequence: false, + ignoreImports: false } ).getObfuscatedCode(); diff --git a/test/fixtures/directory-obfuscation/baz.ts b/test/fixtures/directory-obfuscation/baz.ts index 034c08dcf..d16605964 100644 --- a/test/fixtures/directory-obfuscation/baz.ts +++ b/test/fixtures/directory-obfuscation/baz.ts @@ -1 +1 @@ -var baz = 3; \ No newline at end of file +var baz = 3; diff --git a/test/functional-tests/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.spec.ts b/test/functional-tests/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.spec.ts index 0f6008d08..b91bd5656 100644 --- a/test/functional-tests/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.spec.ts +++ b/test/functional-tests/analyzers/calls-graph-analyzer/CallsGraphAnalyzer.spec.ts @@ -25,8 +25,8 @@ import { NodeUtils } from '../../../../src/node/NodeUtils'; * @param name * @returns {ESTree.FunctionDeclaration|null} */ -function getFunctionDeclarationByName (astTree: ESTree.Node, name: string): ESTree.FunctionDeclaration|null { - let functionDeclarationNode: ESTree.FunctionDeclaration|null = null; +function getFunctionDeclarationByName(astTree: ESTree.Node, name: string): ESTree.FunctionDeclaration | null { + let functionDeclarationNode: ESTree.FunctionDeclaration | null = null; estraverse.traverse(astTree, { enter: (node: ESTree.Node): any => { @@ -50,8 +50,8 @@ function getFunctionDeclarationByName (astTree: ESTree.Node, name: string): ESTr * @param name * @returns {ESTree.FunctionExpression|null} */ -function getFunctionExpressionByName (astTree: ESTree.Node, name: string): ESTree.FunctionExpression|null { - let functionExpressionNode: ESTree.FunctionExpression|null = null; +function getFunctionExpressionByName(astTree: ESTree.Node, name: string): ESTree.FunctionExpression | null { + let functionExpressionNode: ESTree.FunctionExpression | null = null; estraverse.traverse(astTree, { enter: (node: ESTree.Node): any => { @@ -77,8 +77,8 @@ function getFunctionExpressionByName (astTree: ESTree.Node, name: string): ESTre * @param id * @returns {ESTree.FunctionExpression|null} */ -function getFunctionExpressionById (astTree: ESTree.Node, id: string): ESTree.FunctionExpression|null { - let functionExpressionNode: ESTree.FunctionExpression|null = null; +function getFunctionExpressionById(astTree: ESTree.Node, id: string): ESTree.FunctionExpression | null { + let functionExpressionNode: ESTree.FunctionExpression | null = null; estraverse.traverse(astTree, { enter: (node: ESTree.Node): any => { @@ -104,9 +104,13 @@ function getFunctionExpressionById (astTree: ESTree.Node, id: string): ESTree.Fu * @param name * @returns {ESTree.FunctionExpression|null} */ -function getObjectFunctionExpressionByName (astTree: ESTree.Node, objectName: string, name: string|number): ESTree.FunctionExpression|null { - let functionExpressionNode: ESTree.FunctionExpression|null = null, - targetObjectExpressionNode: ESTree.ObjectExpression|null = null; +function getObjectFunctionExpressionByName( + astTree: ESTree.Node, + objectName: string, + name: string | number +): ESTree.FunctionExpression | null { + let functionExpressionNode: ESTree.FunctionExpression | null = null, + targetObjectExpressionNode: ESTree.ObjectExpression | null = null; estraverse.traverse(astTree, { enter: (node: ESTree.Node): any => { @@ -133,10 +137,8 @@ function getObjectFunctionExpressionByName (astTree: ESTree.Node, objectName: st if ( NodeGuards.isPropertyNode(node) && NodeGuards.isFunctionExpressionNode(node.value) && - ( - (NodeGuards.isIdentifierNode(node.key) && node.key.name === name) || - (NodeGuards.isLiteralNode(node.key) && node.key.value === name) - ) + ((NodeGuards.isIdentifierNode(node.key) && node.key.name === name) || + (NodeGuards.isLiteralNode(node.key) && node.key.value === name)) ) { functionExpressionNode = node.value; @@ -158,16 +160,15 @@ describe('CallsGraphAnalyzer', () => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - callsGraphAnalyzer = inversifyContainerFacade - .get(ServiceIdentifiers.ICallsGraphAnalyzer); + callsGraphAnalyzer = inversifyContainerFacade.get( + ServiceIdentifiers.ICallsGraphAnalyzer + ); }); describe('Variant #1: basic-1', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/basic-1.js'); - const astTree: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = [ { @@ -186,20 +187,24 @@ describe('CallsGraphAnalyzer', () => { callsGraph: [ { name: 'inner2', - callee: (getFunctionDeclarationByName(astTree, 'inner2')).body, + callee: (getFunctionDeclarationByName(astTree, 'inner2')) + .body, callsGraph: [ { name: 'inner3', - callee: (getFunctionExpressionByName(astTree, 'inner3')).body, + callee: (( + getFunctionExpressionByName(astTree, 'inner3') + )).body, callsGraph: [] - }, + } ] }, { name: 'inner1', - callee: (getFunctionDeclarationByName(astTree, 'inner1')).body, + callee: (getFunctionDeclarationByName(astTree, 'inner1')) + .body, callsGraph: [] - }, + } ] } ]; @@ -215,9 +220,7 @@ describe('CallsGraphAnalyzer', () => { describe('Variant #2: basic-2', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/basic-2.js'); - const astTree: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = [ { @@ -231,9 +234,10 @@ describe('CallsGraphAnalyzer', () => { callsGraph: [ { name: 'inner1', - callee: (getFunctionDeclarationByName(astTree, 'inner1')).body, + callee: (getFunctionDeclarationByName(astTree, 'inner1')) + .body, callsGraph: [] - }, + } ] }, { @@ -254,9 +258,7 @@ describe('CallsGraphAnalyzer', () => { describe('Variant #3: deep conditions nesting', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/deep-conditions-nesting.js'); - const astTree: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = [ { @@ -270,9 +272,10 @@ describe('CallsGraphAnalyzer', () => { callsGraph: [ { name: 'inner1', - callee: (getFunctionDeclarationByName(astTree, 'inner1')).body, + callee: (getFunctionDeclarationByName(astTree, 'inner1')) + .body, callsGraph: [] - }, + } ] }, { @@ -293,9 +296,7 @@ describe('CallsGraphAnalyzer', () => { describe('Variant #4: call before declaration', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/call-before-declaration.js'); - const astTree: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = [ { @@ -316,50 +317,55 @@ describe('CallsGraphAnalyzer', () => { 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: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = [ { name: 'baz', - callee: (getObjectFunctionExpressionByName(astTree, 'object1', 'baz')).body, + callee: (( + getObjectFunctionExpressionByName(astTree, 'object1', 'baz') + )).body, callsGraph: [] }, { name: 'baz', - callee: (getObjectFunctionExpressionByName(astTree, 'object1', 'baz')).body, + callee: (( + getObjectFunctionExpressionByName(astTree, 'object1', 'baz') + )).body, callsGraph: [] }, { name: 'func', - callee: (getObjectFunctionExpressionByName(astTree, 'object1', 'func')).body, + callee: (( + getObjectFunctionExpressionByName(astTree, 'object1', 'func') + )).body, callsGraph: [] }, { name: 'bar', - callee: (getObjectFunctionExpressionByName(astTree, 'object1', 'bar')).body, + callee: (( + getObjectFunctionExpressionByName(astTree, 'object1', 'bar') + )).body, callsGraph: [ { name: 'inner1', - callee: (getFunctionDeclarationByName(astTree, 'inner1')).body, - callsGraph: [ - - ] - }, + callee: (getFunctionDeclarationByName(astTree, 'inner1')) + .body, + callsGraph: [] + } ] }, { name: 'bar', - callee: (getObjectFunctionExpressionByName(astTree, 'object', 'bar')).body, + callee: (getObjectFunctionExpressionByName(astTree, 'object', 'bar')) + .body, callsGraph: [ { name: 'inner', - callee: (getFunctionDeclarationByName(astTree, 'inner')).body, - callsGraph: [ - - ] - }, + callee: (getFunctionDeclarationByName(astTree, 'inner')) + .body, + callsGraph: [] + } ] } ]; @@ -375,21 +381,21 @@ describe('CallsGraphAnalyzer', () => { 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: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = [ { name: 'baz', - callee: (getObjectFunctionExpressionByName(astTree, 'object', 'baz')).body, + callee: (getObjectFunctionExpressionByName(astTree, 'object', 'baz')) + .body, callsGraph: [] }, { name: 1, - callee: (getObjectFunctionExpressionByName(astTree, 'object1', 1)).body, + callee: (getObjectFunctionExpressionByName(astTree, 'object1', 1)) + .body, callsGraph: [] - }, + } ]; callsGraphData = callsGraphAnalyzer.analyze(astTree); @@ -403,9 +409,7 @@ describe('CallsGraphAnalyzer', () => { describe('Variant #6: no call expressions', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/no-call-expressions.js'); - const astTree: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = []; @@ -420,9 +424,7 @@ describe('CallsGraphAnalyzer', () => { describe('Variant #7: only call expression', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/only-call-expression.js'); - const astTree: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = []; @@ -437,27 +439,34 @@ describe('CallsGraphAnalyzer', () => { describe('Variant #8: self-invoking functions', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/self-invoking-functions.js'); - const astTree: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = [ { name: null, callee: (getFunctionExpressionById(astTree, 'foo')).body, - callsGraph: [{ - name: null, - callee: (getFunctionExpressionById(astTree, 'bar')).body, - callsGraph: [{ + callsGraph: [ + { name: null, - callee: (getFunctionExpressionById(astTree, 'baz')).body, - callsGraph: [{ - name: 'inner', - callee: (getFunctionDeclarationByName(astTree, 'inner')).body, - callsGraph: [] - }] - }] - }] + callee: (getFunctionExpressionById(astTree, 'bar')).body, + callsGraph: [ + { + name: null, + callee: (getFunctionExpressionById(astTree, 'baz')) + .body, + callsGraph: [ + { + name: 'inner', + callee: (( + getFunctionDeclarationByName(astTree, 'inner') + )).body, + callsGraph: [] + } + ] + } + ] + } + ] } ]; @@ -472,9 +481,7 @@ describe('CallsGraphAnalyzer', () => { describe('Variant #9: no recursion', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/no-recursion.js'); - const astTree: TNodeWithStatements = NodeFactory.programNode( - NodeUtils.convertCodeToStructure(code) - ); + const astTree: TNodeWithStatements = NodeFactory.programNode(NodeUtils.convertCodeToStructure(code)); expectedCallsGraphData = [ { diff --git a/test/functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts b/test/functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts index 9adebc7e3..b0f82d724 100644 --- a/test/functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts +++ b/test/functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts @@ -11,7 +11,7 @@ describe('ScopeAnalyzer', () => { /** * https://github.com/javascript-obfuscator/javascript-obfuscator/issues/804 */ - describe('Variant #1: should attach a valid missing ranges', function() { + describe('Variant #1: should attach a valid missing ranges', function () { this.timeout(120000); const samplesCount: number = 1000; @@ -21,21 +21,18 @@ describe('ScopeAnalyzer', () => { const code: string = readFileAsString(__dirname + '/fixtures/attach-missing-ranges.js'); for (let i = 0; i < samplesCount; i++) { - let obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - stringArray: false, - selfDefending: true, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 0.1, - splitStrings: false, - seed: i - } - ).getObfuscatedCode(); + let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + stringArray: false, + selfDefending: true, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 0.1, + splitStrings: false, + seed: i + }).getObfuscatedCode(); try { eval(obfuscatedCode); - } catch ({message}) { + } catch ({ message }) { error = message; break; } diff --git a/test/functional-tests/cli/JavaScriptObfuscatorCLI.spec.ts b/test/functional-tests/cli/JavaScriptObfuscatorCLI.spec.ts index 0757aa810..9a15e89ea 100644 --- a/test/functional-tests/cli/JavaScriptObfuscatorCLI.spec.ts +++ b/test/functional-tests/cli/JavaScriptObfuscatorCLI.spec.ts @@ -29,7 +29,6 @@ describe('JavaScriptObfuscatorCLI', function (): void { const configFileName: string = 'config.js'; const configFilePath: string = path.join(configDirName, configFileName); - describe('run', () => { before(() => { mkdirp.sync(outputDirName); @@ -94,19 +93,14 @@ describe('JavaScriptObfuscatorCLI', function (): void { }); }); - describe('`--output` option isn\'t set', () => { + describe("`--output` option isn't set", () => { describe('Variant #1: default behaviour', () => { - let outputFixturesFilePath: string, - isFileExist: boolean; + let outputFixturesFilePath: string, isFileExist: boolean; before(() => { outputFixturesFilePath = path.join(fixturesDirName, outputFileName); - JavaScriptObfuscatorCLI.obfuscate([ - 'node', - 'javascript-obfuscator', - fixtureFilePath - ]); + JavaScriptObfuscatorCLI.obfuscate(['node', 'javascript-obfuscator', fixtureFilePath]); isFileExist = fs.existsSync(outputFixturesFilePath); }); @@ -124,11 +118,12 @@ describe('JavaScriptObfuscatorCLI', function (): void { let testFunc: () => void; before(() => { - testFunc = () => JavaScriptObfuscatorCLI.obfuscate([ - 'node', - 'javascript-obfuscator', - path.join('wrong', 'file', 'path') - ]); + testFunc = () => + JavaScriptObfuscatorCLI.obfuscate([ + 'node', + 'javascript-obfuscator', + path.join('wrong', 'file', 'path') + ]); }); it(`should throw an error`, () => { @@ -136,7 +131,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { }); }); - describe('Variant #3: input file extension isn\'t `.js`', () => { + describe("Variant #3: input file extension isn't `.js`", () => { const expectedError: RegExp = /Given input path must be a valid/; const outputFileName: string = 'sample-obfuscated.ts'; const outputFilePath: string = path.join(outputDirName, outputFileName); @@ -146,11 +141,8 @@ describe('JavaScriptObfuscatorCLI', function (): void { before(() => { fs.writeFileSync(outputFilePath, 'data'); - testFunc = () => JavaScriptObfuscatorCLI.obfuscate([ - 'node', - 'javascript-obfuscator', - outputFilePath - ]); + testFunc = () => + JavaScriptObfuscatorCLI.obfuscate(['node', 'javascript-obfuscator', outputFilePath]); }); it(`should throw an error`, () => { @@ -190,15 +182,16 @@ describe('JavaScriptObfuscatorCLI', function (): void { let testFunc: () => void; before(() => { - testFunc = () => JavaScriptObfuscatorCLI.obfuscate([ - 'node', - 'javascript-obfuscator', - fixtureFilePath, - '--output', - outputFilePath, - '--exclude', - path.join('**', 'sample.js') - ]); + testFunc = () => + JavaScriptObfuscatorCLI.obfuscate([ + 'node', + 'javascript-obfuscator', + fixtureFilePath, + '--output', + outputFilePath, + '--exclude', + path.join('**', 'sample.js') + ]); }); it('should throw an error', () => { @@ -372,7 +365,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { it( `should create file \`${outputFileName1}\` with obfuscated code in ` + - `\`${path.join(fixturesDirName, outputDirectoryName)}\` directory`, + `\`${path.join(fixturesDirName, outputDirectoryName)}\` directory`, () => { assert.equal(isFileExist1, true); } @@ -380,7 +373,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { it( `should create file \`${outputFileName2}\` with obfuscated code in ` + - `\`${path.join(fixturesDirName, outputDirectoryName)}\` directory`, + `\`${path.join(fixturesDirName, outputDirectoryName)}\` directory`, () => { assert.equal(isFileExist2, true); } @@ -388,7 +381,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { it( `shouldn't create file \`${outputFileName3}\` in ` + - `\`${path.join(fixturesDirName, outputDirectoryName)}\` directory`, + `\`${path.join(fixturesDirName, outputDirectoryName)}\` directory`, () => { assert.equal(isFileExist3, false); } @@ -562,9 +555,8 @@ describe('JavaScriptObfuscatorCLI', function (): void { sourceMapObject = JSON.parse(sourceMapContent); resolveSources(sourceMapObject, fixtureFilePath, fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = + typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); } catch (e) { @@ -625,9 +617,8 @@ describe('JavaScriptObfuscatorCLI', function (): void { sourceMapObject = JSON.parse(sourceMapContent); resolveSources(sourceMapObject, fixtureFilePath, fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = + typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); } catch (e) { @@ -686,15 +677,16 @@ describe('JavaScriptObfuscatorCLI', function (): void { try { sourceCodeContent = fs.readFileSync(fixtureFilePath, { encoding: 'utf8' }); - const sourceMapContent: string = fs.readFileSync(outputSourceMapFilePath, { encoding: 'utf8' }); + const sourceMapContent: string = fs.readFileSync(outputSourceMapFilePath, { + encoding: 'utf8' + }); isFileExist = true; sourceMapObject = JSON.parse(sourceMapContent); resolveSources(sourceMapObject, fixtureFilePath, fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = + typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); } catch (e) { @@ -752,15 +744,16 @@ describe('JavaScriptObfuscatorCLI', function (): void { try { sourceCodeContent = fs.readFileSync(fixtureFilePath, { encoding: 'utf8' }); - const sourceMapContent: string = fs.readFileSync(outputSourceMapPath, { encoding: 'utf8' }); + const sourceMapContent: string = fs.readFileSync(outputSourceMapPath, { + encoding: 'utf8' + }); isFileExist = true; sourceMapObject = JSON.parse(sourceMapContent); resolveSources(sourceMapObject, fixtureFilePath, fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = + typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); } catch (e) { @@ -825,15 +818,16 @@ describe('JavaScriptObfuscatorCLI', function (): void { try { sourceCodeContent = fs.readFileSync(fixtureFilePath, { encoding: 'utf8' }); - const sourceMapContent: string = fs.readFileSync(outputSourceMapPath, { encoding: 'utf8' }); + const sourceMapContent: string = fs.readFileSync(outputSourceMapPath, { + encoding: 'utf8' + }); isFileExist = true; sourceMapObject = JSON.parse(sourceMapContent); resolveSources(sourceMapObject, fixtureFilePath, fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = + typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); } catch (e) { @@ -901,14 +895,13 @@ describe('JavaScriptObfuscatorCLI', function (): void { sourceMapObject = parseSourceMapFromObfuscatedCode(obfuscatedCodeContent); resolveSources(sourceMapObject, fixtureFilePath, fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = + typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); }); - it('shouldn\'t create file with source map', () => { + it("shouldn't create file with source map", () => { assert.equal(isFileExist, false); }); @@ -956,14 +949,13 @@ describe('JavaScriptObfuscatorCLI', function (): void { sourceMapObject = parseSourceMapFromObfuscatedCode(obfuscatedCodeContent); resolveSources(sourceMapObject, fixtureFilePath, fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = + typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); }); - it('shouldn\'t create file with source map', () => { + it("shouldn't create file with source map", () => { assert.equal(isFileExist, false); }); @@ -1026,14 +1018,13 @@ describe('JavaScriptObfuscatorCLI', function (): void { sourceMapObject = parseSourceMapFromObfuscatedCode(obfuscatedCodeContent); resolveSources(sourceMapObject, fixtureFilePath, fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = + typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); }); - it('shouldn\'t create file with source map', () => { + it("shouldn't create file with source map", () => { assert.equal(isFileExist, false); }); @@ -1062,9 +1053,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { }); describe('help output', () => { - let callback: sinon.SinonSpy, - stdoutWriteMock: StdoutWriteMock, - stubExit: sinon.SinonStub; + let callback: sinon.SinonSpy, stdoutWriteMock: StdoutWriteMock, stubExit: sinon.SinonStub; beforeEach(() => { stubExit = sinon.stub(process, 'exit'); @@ -1078,11 +1067,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { beforeEach(() => { stdoutWriteMock.mute(); - JavaScriptObfuscatorCLI.obfuscate([ - 'node', - 'javascript-obfuscator', - '--help' - ]); + JavaScriptObfuscatorCLI.obfuscate(['node', 'javascript-obfuscator', '--help']); stdoutWriteMock.restore(); isConsoleLogCalled = callback.called; @@ -1099,12 +1084,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { beforeEach(() => { stdoutWriteMock.mute(); - JavaScriptObfuscatorCLI.obfuscate([ - 'node', - 'javascript-obfuscator', - '--help', - fixtureFilePath - ]); + JavaScriptObfuscatorCLI.obfuscate(['node', 'javascript-obfuscator', '--help', fixtureFilePath]); stdoutWriteMock.restore(); isConsoleLogCalled = callback.called; @@ -1121,12 +1101,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { beforeEach(() => { stdoutWriteMock.mute(); - JavaScriptObfuscatorCLI.obfuscate([ - 'node', - 'javascript-obfuscator', - fixtureFilePath, - '--help' - ]); + JavaScriptObfuscatorCLI.obfuscate(['node', 'javascript-obfuscator', fixtureFilePath, '--help']); stdoutWriteMock.restore(); isConsoleLogCalled = callback.called; @@ -1143,10 +1118,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { beforeEach(() => { stdoutWriteMock.mute(); - JavaScriptObfuscatorCLI.obfuscate([ - 'node', - 'javascript-obfuscator' - ]); + JavaScriptObfuscatorCLI.obfuscate(['node', 'javascript-obfuscator']); stdoutWriteMock.restore(); isConsoleLogCalled = callback.called; @@ -1167,8 +1139,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { describe('Base options', () => { const outputSourceMapPath: string = `${outputFilePath}.map`; - let isFileExist: boolean, - sourceMapObject: any; + let isFileExist: boolean, sourceMapObject: any; before(() => { JavaScriptObfuscatorCLI.obfuscate([ @@ -1182,7 +1153,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { ]); try { - const content: string = fs.readFileSync(outputSourceMapPath, {encoding: 'utf8'}); + const content: string = fs.readFileSync(outputSourceMapPath, { encoding: 'utf8' }); isFileExist = true; sourceMapObject = JSON.parse(content); @@ -1269,11 +1240,11 @@ describe('JavaScriptObfuscatorCLI', function (): void { '--config', configFilePath, '--source-map', - 'false', + 'false' ]); try { - fs.readFileSync(outputSourceMapPath, {encoding: 'utf8'}); + fs.readFileSync(outputSourceMapPath, { encoding: 'utf8' }); isFileExist = true; } catch (e) { @@ -1349,8 +1320,7 @@ describe('JavaScriptObfuscatorCLI', function (): void { const expectedLoggingMessage1: string = `[javascript-obfuscator-cli] Error in file: ${inputFilePath}...`; - let consoleLogSpy: sinon.SinonSpy, - loggingMessageResult: string + let consoleLogSpy: sinon.SinonSpy, loggingMessageResult: string; before(() => { consoleLogSpy = sinon.spy(console, 'log'); diff --git a/test/functional-tests/code-transformers/preparing-transformers/hashbang-operator-transformer/HashbangOperatorTransformer.spec.ts b/test/functional-tests/code-transformers/preparing-transformers/hashbang-operator-transformer/HashbangOperatorTransformer.spec.ts index eb77332a4..ab221ed93 100644 --- a/test/functional-tests/code-transformers/preparing-transformers/hashbang-operator-transformer/HashbangOperatorTransformer.spec.ts +++ b/test/functional-tests/code-transformers/preparing-transformers/hashbang-operator-transformer/HashbangOperatorTransformer.spec.ts @@ -11,22 +11,16 @@ describe('HashbangOperatorTransformer', () => { const lineSeparator: string = '\r?\n'; describe('Variant #1: simple', () => { - const regExp: RegExp = new RegExp( - `^#!\/usr\/bin\/env node${lineSeparator}` + - `var foo *= *'abc';` - ); + const regExp: RegExp = new RegExp(`^#!\/usr\/bin\/env node${lineSeparator}` + `var foo *= *'abc';`); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should remove hashbang operator before ast transformation and append it after', () => { @@ -35,22 +29,16 @@ describe('HashbangOperatorTransformer', () => { }); describe('Variant #2: multiple new lines', () => { - const regExp: RegExp = new RegExp( - `^#!\/usr\/bin\/env node${lineSeparator.repeat(4)}` + - `var foo *= *'abc';` - ); + const regExp: RegExp = new RegExp(`^#!\/usr\/bin\/env node${lineSeparator.repeat(4)}` + `var foo *= *'abc';`); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/multiple-new-lines.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should remove hashbang operator before ast transformation and append it after', () => { @@ -60,8 +48,7 @@ describe('HashbangOperatorTransformer', () => { describe('Variant #3: `stringArray` option enabled', () => { const regExp: RegExp = new RegExp( - `^#!\/usr\/bin\/env node${lineSeparator}.*` + - `${getStringArrayRegExp(['abc']).source}` + `^#!\/usr\/bin\/env node${lineSeparator}.*` + `${getStringArrayRegExp(['abc']).source}` ); let obfuscatedCode: string; @@ -69,14 +56,11 @@ describe('HashbangOperatorTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should remove hashbang operator before ast transformation and append it after', () => { @@ -85,21 +69,16 @@ describe('HashbangOperatorTransformer', () => { }); describe('Variant #4: invalid hashbang indent', () => { - const regExp: RegExp = new RegExp( - `^var foo *= *'abc';` - ); + const regExp: RegExp = new RegExp(`^var foo *= *'abc';`); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/hashbang-indent.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should remove invalid hashbang operator', () => { @@ -108,21 +87,16 @@ describe('HashbangOperatorTransformer', () => { }); describe('Variant #5: hashbang as a string value', () => { - const regExp: RegExp = new RegExp( - `^var foo *= *'#!/usr/bin/env\\\\x20node';$` - ); + const regExp: RegExp = new RegExp(`^var foo *= *'#!/usr/bin/env\\\\x20node';$`); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/hashbang-as-string-value.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should keep hashbang operator as a string value', () => { diff --git a/test/functional-tests/custom-code-helpers/console-output/ConsoleOutputDisableExpressionCodeHelper.spec.ts b/test/functional-tests/custom-code-helpers/console-output/ConsoleOutputDisableExpressionCodeHelper.spec.ts index 230860965..6ab766a89 100644 --- a/test/functional-tests/custom-code-helpers/console-output/ConsoleOutputDisableExpressionCodeHelper.spec.ts +++ b/test/functional-tests/custom-code-helpers/console-output/ConsoleOutputDisableExpressionCodeHelper.spec.ts @@ -7,7 +7,8 @@ import { readFileAsString } from '../../../helpers/readFileAsString'; import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade'; describe('ConsoleOutputDisableExpressionCodeHelper', () => { - const consoleGetterRegExp: RegExp = /var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\['console'] *= *_0x([a-f0-9]){4,6}\['console'] *\|| *{};/; + const consoleGetterRegExp: RegExp = + /var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\['console'] *= *_0x([a-f0-9]){4,6}\['console'] *\|| *{};/; describe('`disableConsoleOutput` option is set', () => { let obfuscatedCode: string; @@ -15,13 +16,10 @@ describe('ConsoleOutputDisableExpressionCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - disableConsoleOutput: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + disableConsoleOutput: true + }).getObfuscatedCode(); }); it('match #1: should correctly append code helper into the obfuscated code', () => { @@ -29,22 +27,19 @@ describe('ConsoleOutputDisableExpressionCodeHelper', () => { }); }); - describe('`disableConsoleOutput` option isn\'t set', () => { + describe("`disableConsoleOutput` option isn't set", () => { let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - disableConsoleOutput: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + disableConsoleOutput: false + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t append code helper into the obfuscated code', () => { + it("match #1: shouldn't append code helper into the obfuscated code", () => { assert.notMatch(obfuscatedCode, consoleGetterRegExp); }); }); diff --git a/test/functional-tests/custom-code-helpers/console-output/templates/ConsoleOutputDisableTemplate.spec.ts b/test/functional-tests/custom-code-helpers/console-output/templates/ConsoleOutputDisableTemplate.spec.ts index 6ae248668..3b9840af0 100644 --- a/test/functional-tests/custom-code-helpers/console-output/templates/ConsoleOutputDisableTemplate.spec.ts +++ b/test/functional-tests/custom-code-helpers/console-output/templates/ConsoleOutputDisableTemplate.spec.ts @@ -48,7 +48,7 @@ const getPartialConsoleObjectGlobalVariableTemplate: () => string = () => ` * @param {string} additionalCode * @returns {Function} */ -function getFunctionFromTemplate ( +function getFunctionFromTemplate( templateData: any, callsControllerFunctionName: string, consoleMethod: keyof Console, @@ -102,7 +102,7 @@ describe('ConsoleOutputDisableTemplate', () => { { consoleLogDisableFunctionName, callControllerFunctionName, - globalVariableTemplate: GlobalVariableTemplate1(), + globalVariableTemplate: GlobalVariableTemplate1() }, callControllerFunctionName, consoleMethodName @@ -126,7 +126,7 @@ describe('ConsoleOutputDisableTemplate', () => { { consoleLogDisableFunctionName, callControllerFunctionName, - globalVariableTemplate: getPartialConsoleObjectGlobalVariableTemplate(), + globalVariableTemplate: getPartialConsoleObjectGlobalVariableTemplate() }, callControllerFunctionName, consoleMethodName @@ -150,7 +150,7 @@ describe('ConsoleOutputDisableTemplate', () => { { consoleLogDisableFunctionName, callControllerFunctionName, - globalVariableTemplate: getUndefinedConsoleObjectGlobalVariableTemplate(), + globalVariableTemplate: getUndefinedConsoleObjectGlobalVariableTemplate() }, callControllerFunctionName, consoleMethodName @@ -174,7 +174,7 @@ describe('ConsoleOutputDisableTemplate', () => { { consoleLogDisableFunctionName, callControllerFunctionName, - globalVariableTemplate: getWrongGlobalVariableTemplate(), + globalVariableTemplate: getWrongGlobalVariableTemplate() }, callControllerFunctionName, consoleMethodName @@ -196,16 +196,17 @@ describe('ConsoleOutputDisableTemplate', () => { let testFunc: () => void; beforeEach(() => { - testFunc = () => getFunctionFromTemplate( - { - consoleLogDisableFunctionName, + testFunc = () => + getFunctionFromTemplate( + { + consoleLogDisableFunctionName, + callControllerFunctionName, + globalVariableTemplate: GlobalVariableTemplate1() + }, callControllerFunctionName, - globalVariableTemplate: GlobalVariableTemplate1(), - }, - callControllerFunctionName, - consoleMethodName, - `console.${consoleMethodName}.bind();` - )(); + consoleMethodName, + `console.${consoleMethodName}.bind();` + )(); }); it(`should does not throw error during \`console.${consoleMethodName}.bind\` call`, () => { diff --git a/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-call-template/DebugProtectionFunctionCallTemplate.spec.ts b/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-call-template/DebugProtectionFunctionCallTemplate.spec.ts index 5a6173647..ca3dba89c 100644 --- a/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-call-template/DebugProtectionFunctionCallTemplate.spec.ts +++ b/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-call-template/DebugProtectionFunctionCallTemplate.spec.ts @@ -25,23 +25,19 @@ describe('DebugProtectionFunctionCallTemplate', function () { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true, - identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true, + identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator + }).getObfuscatedCode(); + + return evaluateInWorker(obfuscatedCode, evaluationTimeout).then((result: string | null) => { + if (!result) { + return; } - ).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, evaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } - - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should correctly evaluate code with enabled debug protection', () => { @@ -58,23 +54,19 @@ describe('DebugProtectionFunctionCallTemplate', function () { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, evaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, evaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should correctly evaluate code with enabled debug protection', () => { @@ -91,24 +83,20 @@ describe('DebugProtectionFunctionCallTemplate', function () { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true, - identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, - identifiersDictionary: ['foo', 'bar', 'baz', 'bark', 'hawk', 'eagle'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true, + identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, + identifiersDictionary: ['foo', 'bar', 'baz', 'bark', 'hawk', 'eagle'] + }).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, evaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, evaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should correctly evaluate code with enabled debug protection', () => { @@ -125,23 +113,19 @@ describe('DebugProtectionFunctionCallTemplate', function () { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true, - target: ObfuscationTarget.BrowserNoEval - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true, + target: ObfuscationTarget.BrowserNoEval + }).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, evaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, evaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should correctly evaluate code with enabled debug protection', () => { @@ -158,23 +142,19 @@ describe('DebugProtectionFunctionCallTemplate', function () { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true, - target: ObfuscationTarget.ServiceWorker - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true, + target: ObfuscationTarget.ServiceWorker + }).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, evaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, evaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should correctly evaluate code with enabled debug protection', () => { @@ -191,23 +171,19 @@ describe('DebugProtectionFunctionCallTemplate', function () { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true + }).getObfuscatedCode(); obfuscatedCode = obfuscatedCode.replace(/\+\+ *_0x([a-f0-9]){4,6}/, ''); - return evaluateInWorker(obfuscatedCode, evaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, evaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should enter code in infinity loop', () => { @@ -224,22 +200,18 @@ describe('DebugProtectionFunctionCallTemplate', function () { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/single-call.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true + }).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, evaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, evaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should correctly evaluate code with enabled debug protection', () => { diff --git a/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-interval-template/DebugProtectionFunctionIntervalTemplate.spec.ts b/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-interval-template/DebugProtectionFunctionIntervalTemplate.spec.ts index 8f6a061f5..52db40fdf 100644 --- a/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-interval-template/DebugProtectionFunctionIntervalTemplate.spec.ts +++ b/test/functional-tests/custom-code-helpers/debug-protection/templates/debug-protection-function-interval-template/DebugProtectionFunctionIntervalTemplate.spec.ts @@ -12,24 +12,18 @@ describe('DebugProtectionFunctionIntervalTemplate', function () { describe('Variant #1 - `high-obfuscation` preset interval', () => { const debugProtectionIntervalRegExp: RegExp = new RegExp( - `${variableMatch}\\['setInterval'\\]\\( *` + - `${variableMatch}, *` + - '0xfa0 *' + - `\\);` + `${variableMatch}\\['setInterval'\\]\\( *` + `${variableMatch}, *` + '0xfa0 *' + `\\);` ); let obfuscatedCode: string; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true, - debugProtectionInterval: HIGH_OBFUSCATION_PRESET.debugProtectionInterval - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true, + debugProtectionInterval: HIGH_OBFUSCATION_PRESET.debugProtectionInterval + }).getObfuscatedCode(); console.log(obfuscatedCode); }); @@ -41,24 +35,18 @@ describe('DebugProtectionFunctionIntervalTemplate', function () { describe('Variant #2 - custom interval', () => { const debugProtectionIntervalRegExp: RegExp = new RegExp( - `${variableMatch}\\['setInterval'\\]\\( *` + - `${variableMatch}, *` + - '0x64 *' + - `\\);` + `${variableMatch}\\['setInterval'\\]\\( *` + `${variableMatch}, *` + '0x64 *' + `\\);` ); let obfuscatedCode: string; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true, - debugProtectionInterval: 100 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true, + debugProtectionInterval: 100 + }).getObfuscatedCode(); }); it('Should add debug protection interval code with default interval value', () => { @@ -67,20 +55,17 @@ describe('DebugProtectionFunctionIntervalTemplate', function () { }); describe('Variant #3 - no interval', () => { - const debugProtectionIntervalRegExp: RegExp = /setInterval/ + const debugProtectionIntervalRegExp: RegExp = /setInterval/; let obfuscatedCode: string; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - debugProtection: true, - debugProtectionInterval: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + debugProtection: true, + debugProtectionInterval: 0 + }).getObfuscatedCode(); }); it('Should not add debug protection interval code', () => { diff --git a/test/functional-tests/custom-code-helpers/domain-lock/DomainLockCodeHelper.spec.ts b/test/functional-tests/custom-code-helpers/domain-lock/DomainLockCodeHelper.spec.ts index fe187499e..bcf0af633 100644 --- a/test/functional-tests/custom-code-helpers/domain-lock/DomainLockCodeHelper.spec.ts +++ b/test/functional-tests/custom-code-helpers/domain-lock/DomainLockCodeHelper.spec.ts @@ -18,13 +18,10 @@ describe('DomainLockCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - domainLock: ['.example.com'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + domainLock: ['.example.com'] + }).getObfuscatedCode(); }); it('should correctly append code helper into the obfuscated code', () => { @@ -39,15 +36,12 @@ describe('DomainLockCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - domainLock: ['.example.com'], - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'foo' - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + domainLock: ['.example.com'], + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'foo' + }).getObfuscatedCode(); }); it('should add prefix to the helper identifiers inside global scope', () => { @@ -62,15 +56,12 @@ describe('DomainLockCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/append-inside-function-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - domainLock: ['.example.com'], - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'foo' - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + domainLock: ['.example.com'], + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'foo' + }).getObfuscatedCode(); }); it('should not add prefix to the helper identifiers inside global scope', () => { @@ -79,7 +70,7 @@ describe('DomainLockCodeHelper', () => { }); }); - describe('`domainLock` option isn\'t set', () => { + describe("`domainLock` option isn't set", () => { const regExp: RegExp = /var _0x([a-f0-9]){4,6} *= *new RegExp/; let obfuscatedCode: string; @@ -87,16 +78,13 @@ describe('DomainLockCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - domainLock: [] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + domainLock: [] + }).getObfuscatedCode(); }); - it('shouldn\'t append code helper into the obfuscated code', () => { + it("shouldn't append code helper into the obfuscated code", () => { assert.notMatch(obfuscatedCode, regExp); }); }); diff --git a/test/functional-tests/custom-code-helpers/domain-lock/templates/DomainLockNodeTemplate.spec.ts b/test/functional-tests/custom-code-helpers/domain-lock/templates/DomainLockNodeTemplate.spec.ts index 9e6dd434b..6f30afa6e 100644 --- a/test/functional-tests/custom-code-helpers/domain-lock/templates/DomainLockNodeTemplate.spec.ts +++ b/test/functional-tests/custom-code-helpers/domain-lock/templates/DomainLockNodeTemplate.spec.ts @@ -24,7 +24,7 @@ import { readFileAsString } from '../../../../helpers/readFileAsString'; * @param {string} documentTemplate * @returns {Function} */ -function getFunctionFromTemplate ( +function getFunctionFromTemplate( templateData: any, callsControllerFunctionName: string, documentTemplate: string @@ -68,21 +68,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -115,21 +115,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -162,21 +162,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -210,21 +210,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -257,21 +257,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -304,21 +304,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -351,21 +351,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -399,21 +399,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -437,7 +437,7 @@ describe('DomainLockTemplate', () => { }); }); - describe('Variant #6: current domain doesn\'t match with `domainsString`', () => { + describe("Variant #6: current domain doesn't match with `domainsString`", () => { describe('Variant #1', () => { const domainsString: string = ['www.example.com'].join(';'); const domainLockRedirectUrl: string = 'about:blank'; @@ -447,21 +447,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -494,24 +494,25 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; - testFunc = getFunctionFromTemplate({ + testFunc = getFunctionFromTemplate( + { domainLockFunctionName: 'domainLockFunction', domainsStringDiff, domains: hiddenDomainsString, @@ -540,21 +541,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -587,21 +588,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -634,21 +635,21 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentDomain, - location: undefined, - }, + location: undefined + } }; testFunc = getFunctionFromTemplate( @@ -683,22 +684,22 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { location: { - hostname: currentHostName, - }, - }, + hostname: currentHostName + } + } }; testFunc = getFunctionFromTemplate( @@ -722,7 +723,7 @@ describe('DomainLockTemplate', () => { }); }); - describe('Variant #2: current location.hostname doesn\'t match with `domainsString`', () => { + describe("Variant #2: current location.hostname doesn't match with `domainsString`", () => { const domainsString: string = ['www.example.com'].join(';'); const domainLockRedirectUrl: string = 'about:blank'; const currentHostName: string = 'www.test.com'; @@ -731,22 +732,22 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { location: { - hostname: currentHostName, - }, - }, + hostname: currentHostName + } + } }; testFunc = getFunctionFromTemplate( @@ -781,23 +782,23 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentHostName, location: { - hostname: currentHostName, - }, - }, + hostname: currentHostName + } + } }; testFunc = getFunctionFromTemplate( @@ -821,7 +822,7 @@ describe('DomainLockTemplate', () => { }); }); - describe('Variant #2: current domain doesn\'t match with `domainsString`', () => { + describe("Variant #2: current domain doesn't match with `domainsString`", () => { const domainsString: string = ['www.example.com'].join(';'); const domainLockRedirectUrl: string = 'about:blank'; const currentHostName: string = 'www.test.com'; @@ -830,23 +831,23 @@ describe('DomainLockTemplate', () => { let root: any; before(() => { - const [ - hiddenDomainsString, - domainsStringDiff - ] = cryptUtils.hideString(domainsString, domainsString.length * 3); + const [hiddenDomainsString, domainsStringDiff] = cryptUtils.hideString( + domainsString, + domainsString.length * 3 + ); - const [ - hiddenDomainLockRedirectUrl, - domainLockRedirectUrlDiff - ] = cryptUtils.hideString(domainLockRedirectUrl, domainLockRedirectUrl.length * 3); + const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff] = cryptUtils.hideString( + domainLockRedirectUrl, + domainLockRedirectUrl.length * 3 + ); root = { document: { domain: currentHostName, location: { - hostname: currentHostName, - }, - }, + hostname: currentHostName + } + } }; testFunc = getFunctionFromTemplate( @@ -885,15 +886,12 @@ describe('DomainLockTemplate', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - domainLock: ['obfuscator.io'], - stringArray: true, - stringArrayThreshold: 1 - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + domainLock: ['obfuscator.io'], + stringArray: true, + stringArrayThreshold: 1 + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -913,15 +911,12 @@ describe('DomainLockTemplate', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - domainLock: ['obfuscator.io'], - stringArray: true, - stringArrayThreshold: 1 - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + domainLock: ['obfuscator.io'], + stringArray: true, + stringArrayThreshold: 1 + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -941,15 +936,12 @@ describe('DomainLockTemplate', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - domainLock: ['obfuscator.io'], - stringArray: true, - stringArrayThreshold: 1 - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + domainLock: ['obfuscator.io'], + stringArray: true, + stringArrayThreshold: 1 + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); diff --git a/test/functional-tests/custom-code-helpers/self-defending/SelfDefendingCodeHelper.spec.ts b/test/functional-tests/custom-code-helpers/self-defending/SelfDefendingCodeHelper.spec.ts index 61533dff1..2da4fe284 100644 --- a/test/functional-tests/custom-code-helpers/self-defending/SelfDefendingCodeHelper.spec.ts +++ b/test/functional-tests/custom-code-helpers/self-defending/SelfDefendingCodeHelper.spec.ts @@ -17,15 +17,12 @@ describe('SelfDefendingCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'foo', - selfDefending: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'foo', + selfDefending: true + }).getObfuscatedCode(); }); it('should add prefix to the helper identifiers inside global scope', () => { @@ -40,15 +37,12 @@ describe('SelfDefendingCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/append-inside-function-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'foo', - selfDefending: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'foo', + selfDefending: true + }).getObfuscatedCode(); }); it('should not add prefix to the helper identifiers inside global scope', () => { diff --git a/test/functional-tests/custom-code-helpers/self-defending/templates/SelfDefendingTemplate.spec.ts b/test/functional-tests/custom-code-helpers/self-defending/templates/SelfDefendingTemplate.spec.ts index 20fafd2df..f9633af01 100644 --- a/test/functional-tests/custom-code-helpers/self-defending/templates/SelfDefendingTemplate.spec.ts +++ b/test/functional-tests/custom-code-helpers/self-defending/templates/SelfDefendingTemplate.spec.ts @@ -30,23 +30,19 @@ describe('SelfDefendingTemplate', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...baseOptions, - selfDefending: true, - identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...baseOptions, + selfDefending: true, + identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator + }).getObfuscatedCode(); + + return evaluateInWorker(obfuscatedCode, correctEvaluationTimeout).then((result: string | null) => { + if (!result) { + return; } - ).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, correctEvaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } - - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should correctly evaluate code with enabled self defending', () => { @@ -63,23 +59,19 @@ describe('SelfDefendingTemplate', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - baseOptions, - selfDefending: true, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + baseOptions, + selfDefending: true, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, correctEvaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, correctEvaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should correctly evaluate code with enabled self defending', () => { @@ -96,24 +88,20 @@ describe('SelfDefendingTemplate', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - baseOptions, - selfDefending: true, - identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, - identifiersDictionary: ['foo', 'bar', 'baz', 'bark', 'hawk', 'eagle'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + baseOptions, + selfDefending: true, + identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, + identifiersDictionary: ['foo', 'bar', 'baz', 'bark', 'hawk', 'eagle'] + }).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, correctEvaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, correctEvaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should correctly evaluate code with enabled self defending', () => { @@ -131,23 +119,19 @@ describe('SelfDefendingTemplate', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...baseOptions, - selfDefending: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...baseOptions, + selfDefending: true + }).getObfuscatedCode(); obfuscatedCode = beautifyCode(obfuscatedCode, 'space'); - return evaluateInWorker(obfuscatedCode, redosEvaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, redosEvaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should enter code in infinity loop', () => { @@ -164,23 +148,19 @@ describe('SelfDefendingTemplate', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...baseOptions, - selfDefending: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...baseOptions, + selfDefending: true + }).getObfuscatedCode(); obfuscatedCode = beautifyCode(obfuscatedCode, 'tab'); - return evaluateInWorker(obfuscatedCode, redosEvaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, redosEvaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = parseInt(result, 10); - }); + evaluationResult = parseInt(result, 10); + }); }); it('should enter code in infinity loop', () => { @@ -211,14 +191,13 @@ describe('SelfDefendingTemplate', function () { } ).getObfuscatedCode(); - return evaluateInWorker(obfuscatedCode, evaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, evaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = result; - }); + evaluationResult = result; + }); }); it('should correctly evaluate code with enabled self defending', () => { @@ -247,14 +226,13 @@ describe('SelfDefendingTemplate', function () { ).getObfuscatedCode(); obfuscatedCode = beautifyCode(obfuscatedCode, 'space'); - return evaluateInWorker(obfuscatedCode, redosEvaluationTimeout) - .then((result: string | null) => { - if (!result) { - return; - } + return evaluateInWorker(obfuscatedCode, redosEvaluationTimeout).then((result: string | null) => { + if (!result) { + return; + } - evaluationResult = result; - }); + evaluationResult = result; + }); }); it('should enter code in infinity loop', () => { diff --git a/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts b/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts index b5efc053c..6f2aff93e 100644 --- a/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts +++ b/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts @@ -25,14 +25,11 @@ describe('StringArrayCallsWrapperCodeHelper', () => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); if (obfuscatedCode.match(stringArrayCallsWrapperAtFirstPositionRegExp)) { stringArrayCallsWrapperAtFirstPositionMatchesCount++; @@ -59,14 +56,11 @@ describe('StringArrayCallsWrapperCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should correctly append code helper into the obfuscated code', () => { @@ -74,49 +68,45 @@ describe('StringArrayCallsWrapperCodeHelper', () => { }); }); - describe('`stringArray` option isn\'t set', () => { + describe("`stringArray` option isn't set", () => { let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: false + }).getObfuscatedCode(); }); - it('shouldn\'t append code helper into the obfuscated code', () => { + it("shouldn't append code helper into the obfuscated code", () => { assert.notMatch(obfuscatedCode, stringCallsWrapperRegExp); }); }); describe('Preserve string array name', () => { - const callsWrapperRegExp: RegExp = new RegExp(`` + - `function *b *\\(c, *d\\) *{ *` + - `c *= *c *- *0x0; *` + - `var e *= *a *\\(\\);` + - `var f *= *e\\[c]; *` + - ``); + const callsWrapperRegExp: RegExp = new RegExp( + `` + + `function *b *\\(c, *d\\) *{ *` + + `c *= *c *- *0x0; *` + + `var e *= *a *\\(\\);` + + `var f *= *e\\[c]; *` + + `` + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [StringArrayEncoding.Base64] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.Base64] + }).getObfuscatedCode(); }); it('should preserve string array name', () => { diff --git a/test/functional-tests/custom-code-helpers/string-array/StringArrayCodeHelper.spec.ts b/test/functional-tests/custom-code-helpers/string-array/StringArrayCodeHelper.spec.ts index 3b4fa9704..324c8873f 100644 --- a/test/functional-tests/custom-code-helpers/string-array/StringArrayCodeHelper.spec.ts +++ b/test/functional-tests/custom-code-helpers/string-array/StringArrayCodeHelper.spec.ts @@ -23,14 +23,11 @@ describe('StringArrayCodeHelper', () => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); if (obfuscatedCode.match(stringArrayAtFirstPositionRegExp)) { stringArrayAtFirstPositionMatchesCount++; @@ -51,22 +48,19 @@ describe('StringArrayCodeHelper', () => { }); }); - describe('`stringArray` option isn\'t set', () => { + describe("`stringArray` option isn't set", () => { let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: false + }).getObfuscatedCode(); }); - it('shouldn\'t append code helper into the obfuscated code', () => { + it("shouldn't append code helper into the obfuscated code", () => { assert.notMatch(obfuscatedCode, stringArrayRegExp); }); }); diff --git a/test/functional-tests/custom-code-helpers/string-array/StringArrayRotateFunctionCodeHelper.spec.ts b/test/functional-tests/custom-code-helpers/string-array/StringArrayRotateFunctionCodeHelper.spec.ts index 7c4443ed1..8913566ad 100644 --- a/test/functional-tests/custom-code-helpers/string-array/StringArrayRotateFunctionCodeHelper.spec.ts +++ b/test/functional-tests/custom-code-helpers/string-array/StringArrayRotateFunctionCodeHelper.spec.ts @@ -18,15 +18,12 @@ describe('StringArrayRotateFunctionCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should correctly append code helper into the obfuscated code', () => { @@ -34,24 +31,21 @@ describe('StringArrayRotateFunctionCodeHelper', () => { }); }); - describe('`stringArray` option isn\'t set', () => { + describe("`stringArray` option isn't set", () => { let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: false, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: false, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t append code helper into the obfuscated code', () => { + it("shouldn't append code helper into the obfuscated code", () => { assert.notMatch(obfuscatedCode, regExp); }); }); @@ -59,22 +53,20 @@ describe('StringArrayRotateFunctionCodeHelper', () => { describe('Comparison expression', () => { describe('Should add comparison expression to the code helper', () => { - const comparisonExpressionRegExp: RegExp = /var _0x([a-f0-9]){4,6} *= *-?parseInt\(_0x([a-f0-9]){4,6}\(0x.\)\)/; + const comparisonExpressionRegExp: RegExp = + /var _0x([a-f0-9]){4,6} *= *-?parseInt\(_0x([a-f0-9]){4,6}\(0x.\)\)/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add comparison expression to the code', () => { @@ -92,16 +84,13 @@ describe('StringArrayRotateFunctionCodeHelper', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArrayRotate: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArrayRotate: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should preserve string array name', () => { diff --git a/test/functional-tests/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.spec.ts b/test/functional-tests/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.spec.ts index 10c350ca0..dba52ab19 100644 --- a/test/functional-tests/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.spec.ts +++ b/test/functional-tests/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.spec.ts @@ -13,12 +13,10 @@ import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFac describe('StringArrayCodeHelperGroup', () => { const regExp: RegExp = new RegExp( 'function *\\w *\\(\\w, *\\w\\) *{.*return \\w;}.*' + - 'function *\\w *\\(\\w, *\\w\\) *{.*return \\w;}.*' + - 'function *\\w *\\(\\w, *\\w\\) *{.*return \\w;}' - ); - const stringArrayCallsWrapperRegExp: RegExp = new RegExp( - `function *(\\w) *\\(\\w, *\\w\\) *{.*return \\w;}.*` + 'function *\\w *\\(\\w, *\\w\\) *{.*return \\w;}.*' + + 'function *\\w *\\(\\w, *\\w\\) *{.*return \\w;}' ); + const stringArrayCallsWrapperRegExp: RegExp = new RegExp(`function *(\\w) *\\(\\w, *\\w\\) *{.*return \\w;}.*`); describe('StringArrayCallsWrapper code helper names', function () { this.timeout(10000); @@ -33,20 +31,13 @@ describe('StringArrayCodeHelperGroup', () => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Base64, - StringArrayEncoding.Rc4 - ] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Base64, StringArrayEncoding.Rc4] + }).getObfuscatedCode(); const callsWrapperName: string = getRegExpMatch(obfuscatedCode, stringArrayCallsWrapperRegExp); diff --git a/test/functional-tests/custom-code-helpers/string-array/templates/string-array-calls-wrapper-node-template/StringArrayCallsWrapperTemplate.spec.ts b/test/functional-tests/custom-code-helpers/string-array/templates/string-array-calls-wrapper-node-template/StringArrayCallsWrapperTemplate.spec.ts index 31f74032b..68a393509 100644 --- a/test/functional-tests/custom-code-helpers/string-array/templates/string-array-calls-wrapper-node-template/StringArrayCallsWrapperTemplate.spec.ts +++ b/test/functional-tests/custom-code-helpers/string-array/templates/string-array-calls-wrapper-node-template/StringArrayCallsWrapperTemplate.spec.ts @@ -34,17 +34,16 @@ describe('StringArrayCallsWrapperTemplate', () => { const atobFunctionName: string = 'atob'; const rc4FunctionName: string = 'rc4'; - let cryptUtilsSwappedAlphabet: ICryptUtilsStringArray, - randomGenerator: IRandomGenerator; + let cryptUtilsSwappedAlphabet: ICryptUtilsStringArray, randomGenerator: IRandomGenerator; before(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - cryptUtilsSwappedAlphabet = inversifyContainerFacade - .get(ServiceIdentifiers.ICryptUtilsStringArray); - randomGenerator = inversifyContainerFacade - .get(ServiceIdentifiers.IRandomGenerator); + cryptUtilsSwappedAlphabet = inversifyContainerFacade.get( + ServiceIdentifiers.ICryptUtilsStringArray + ); + randomGenerator = inversifyContainerFacade.get(ServiceIdentifiers.IRandomGenerator); }); describe('Variant #1: `base64` encoding', () => { @@ -69,16 +68,13 @@ describe('StringArrayCallsWrapperTemplate', () => { const atobPolyfill = format(AtobTemplate(selfDefendingEnabled), { atobFunctionName }); - const atobDecodeTemplate: string = format( - StringArrayBase64DecodeTemplate(randomGenerator), - { - atobPolyfill, - atobFunctionName, - selfDefendingCode: '', - stringArrayCacheName, - stringArrayCallsWrapperName - } - ); + const atobDecodeTemplate: string = format(StringArrayBase64DecodeTemplate(randomGenerator), { + atobPolyfill, + atobFunctionName, + selfDefendingCode: '', + stringArrayCacheName, + stringArrayCallsWrapperName + }); const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate: atobDecodeTemplate, indexShiftAmount, @@ -119,16 +115,13 @@ describe('StringArrayCallsWrapperTemplate', () => { const atobPolyfill = format(AtobTemplate(selfDefendingEnabled), { atobFunctionName }); - const atobDecodeTemplate: string = format( - StringArrayBase64DecodeTemplate(randomGenerator), - { - atobPolyfill, - atobFunctionName, - selfDefendingCode: '', - stringArrayCacheName, - stringArrayCallsWrapperName - } - ); + const atobDecodeTemplate: string = format(StringArrayBase64DecodeTemplate(randomGenerator), { + atobPolyfill, + atobFunctionName, + selfDefendingCode: '', + stringArrayCacheName, + stringArrayCallsWrapperName + }); const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate: atobDecodeTemplate, indexShiftAmount, @@ -167,16 +160,13 @@ describe('StringArrayCallsWrapperTemplate', () => { const atobPolyfill = format(AtobTemplate(selfDefendingEnabled), { atobFunctionName }); - const atobDecodeTemplate: string = format( - StringArrayBase64DecodeTemplate(randomGenerator), - { - atobPolyfill, - atobFunctionName, - selfDefendingCode: '', - stringArrayCacheName, - stringArrayCallsWrapperName - } - ); + const atobDecodeTemplate: string = format(StringArrayBase64DecodeTemplate(randomGenerator), { + atobPolyfill, + atobFunctionName, + selfDefendingCode: '', + stringArrayCacheName, + stringArrayCallsWrapperName + }); const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate: atobDecodeTemplate, indexShiftAmount, @@ -216,7 +206,7 @@ describe('StringArrayCallsWrapperTemplate', () => { let decodedValue: string; - before(async() => { + before(async () => { const stringArrayTemplate = format(StringArrayTemplate(), { stringArrayName, stringArrayFunctionName, @@ -225,16 +215,13 @@ describe('StringArrayCallsWrapperTemplate', () => { const atobPolyfill = format(AtobTemplate(selfDefendingEnabled), { atobFunctionName }); - const atobDecodeTemplate: string = format( - StringArrayBase64DecodeTemplate(randomGenerator), - { - atobPolyfill, - atobFunctionName, - selfDefendingCode: '', - stringArrayCacheName, - stringArrayCallsWrapperName - } - ); + const atobDecodeTemplate: string = format(StringArrayBase64DecodeTemplate(randomGenerator), { + atobPolyfill, + atobFunctionName, + selfDefendingCode: '', + stringArrayCacheName, + stringArrayCallsWrapperName + }); const stringArrayCallsWrapperTemplate: string = await minimizeCode( format(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate: atobDecodeTemplate, @@ -268,7 +255,7 @@ describe('StringArrayCallsWrapperTemplate', () => { let decodedValue: string; - before(async() => { + before(async () => { const stringArrayTemplate = format(StringArrayTemplate(), { stringArrayName, stringArrayFunctionName, @@ -277,16 +264,13 @@ describe('StringArrayCallsWrapperTemplate', () => { const atobPolyfill = format(AtobTemplate(selfDefendingEnabled), { atobFunctionName }); - const atobDecodeTemplate: string = format( - StringArrayBase64DecodeTemplate(randomGenerator), - { - atobPolyfill, - atobFunctionName, - selfDefendingCode: '', - stringArrayCacheName, - stringArrayCallsWrapperName - } - ); + const atobDecodeTemplate: string = format(StringArrayBase64DecodeTemplate(randomGenerator), { + atobPolyfill, + atobFunctionName, + selfDefendingCode: '', + stringArrayCacheName, + stringArrayCallsWrapperName + }); const stringArrayCallsWrapperTemplate: string = await minimizeCode( format(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate: atobDecodeTemplate, @@ -331,16 +315,13 @@ describe('StringArrayCallsWrapperTemplate', () => { const atobPolyfill = format(AtobTemplate(selfDefendingEnabled), { atobFunctionName }); - const atobDecodeTemplate: string = format( - StringArrayBase64DecodeTemplate(randomGenerator), - { - atobPolyfill, - atobFunctionName, - selfDefendingCode: '', - stringArrayCacheName, - stringArrayCallsWrapperName - } - ); + const atobDecodeTemplate: string = format(StringArrayBase64DecodeTemplate(randomGenerator), { + atobPolyfill, + atobFunctionName, + selfDefendingCode: '', + stringArrayCacheName, + stringArrayCallsWrapperName + }); const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate: atobDecodeTemplate, indexShiftAmount, @@ -381,16 +362,13 @@ describe('StringArrayCallsWrapperTemplate', () => { const atobPolyfill = format(AtobTemplate(selfDefendingEnabled), { atobFunctionName }); - const atobDecodeTemplate: string = format( - StringArrayBase64DecodeTemplate(randomGenerator), - { - atobPolyfill, - atobFunctionName, - selfDefendingCode: '', - stringArrayCacheName, - stringArrayCallsWrapperName - } - ); + const atobDecodeTemplate: string = format(StringArrayBase64DecodeTemplate(randomGenerator), { + atobPolyfill, + atobFunctionName, + selfDefendingCode: '', + stringArrayCacheName, + stringArrayCallsWrapperName + }); const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate: atobDecodeTemplate, indexShiftAmount, @@ -443,17 +421,14 @@ describe('StringArrayCallsWrapperTemplate', () => { atobFunctionName, rc4FunctionName }); - const rc4decodeCodeHelperTemplate: string = format( - StringArrayRC4DecodeTemplate(randomGenerator), - { - atobPolyfill, - rc4Polyfill, - rc4FunctionName, - selfDefendingCode: '', - stringArrayCacheName, - stringArrayCallsWrapperName - } - ); + const rc4decodeCodeHelperTemplate: string = format(StringArrayRC4DecodeTemplate(randomGenerator), { + atobPolyfill, + rc4Polyfill, + rc4FunctionName, + selfDefendingCode: '', + stringArrayCacheName, + stringArrayCallsWrapperName + }); const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate: rc4decodeCodeHelperTemplate, indexShiftAmount, @@ -499,17 +474,14 @@ describe('StringArrayCallsWrapperTemplate', () => { atobFunctionName, rc4FunctionName }); - const rc4decodeCodeHelperTemplate: string = format( - StringArrayRC4DecodeTemplate(randomGenerator), - { - atobPolyfill, - rc4Polyfill, - rc4FunctionName, - selfDefendingCode: '', - stringArrayCacheName, - stringArrayCallsWrapperName - } - ); + const rc4decodeCodeHelperTemplate: string = format(StringArrayRC4DecodeTemplate(randomGenerator), { + atobPolyfill, + rc4Polyfill, + rc4FunctionName, + selfDefendingCode: '', + stringArrayCacheName, + stringArrayCallsWrapperName + }); const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate: rc4decodeCodeHelperTemplate, indexShiftAmount, @@ -547,7 +519,7 @@ describe('StringArrayCallsWrapperTemplate', () => { let decodedValue: string; - before(async() => { + before(async () => { const stringArrayTemplate = format(StringArrayTemplate(), { stringArrayName, stringArrayFunctionName, @@ -661,18 +633,16 @@ describe('StringArrayCallsWrapperTemplate', () => { describe('Prevailing kind of variables', () => { describe('`var` kind', () => { let obfuscatedCode: string, - stringArrayCallsWrapperVariableRegExp: RegExp = /var (_0x(\w){4,6}) *= *(_0x(\w){4,6})\[(_0x(\w){4,6})];/; + stringArrayCallsWrapperVariableRegExp: RegExp = + /var (_0x(\w){4,6}) *= *(_0x(\w){4,6})\[(_0x(\w){4,6})];/; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -688,18 +658,16 @@ describe('StringArrayCallsWrapperTemplate', () => { describe('`const` kind', () => { let obfuscatedCode: string, - stringArrayCallsWrapperVariableRegExp: RegExp = /let (_0x(\w){4,6}) *= *(_0x(\w){4,6})\[(_0x(\w){4,6})];/; + stringArrayCallsWrapperVariableRegExp: RegExp = + /let (_0x(\w){4,6}) *= *(_0x(\w){4,6})\[(_0x(\w){4,6})];/; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -715,18 +683,16 @@ describe('StringArrayCallsWrapperTemplate', () => { describe('`let` kind', () => { let obfuscatedCode: string, - stringArrayCallsWrapperVariableRegExp: RegExp = /let (_0x(\w){4,6}) *= *(_0x(\w){4,6})\[(_0x(\w){4,6})];/; + stringArrayCallsWrapperVariableRegExp: RegExp = + /let (_0x(\w){4,6}) *= *(_0x(\w){4,6})\[(_0x(\w){4,6})];/; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); diff --git a/test/functional-tests/custom-code-helpers/string-array/templates/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts b/test/functional-tests/custom-code-helpers/string-array/templates/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts index 7e1c59f7d..ee54ef2fc 100644 --- a/test/functional-tests/custom-code-helpers/string-array/templates/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts +++ b/test/functional-tests/custom-code-helpers/string-array/templates/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts @@ -19,15 +19,12 @@ describe('StringArrayRotateFunctionTemplate', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayRotate: true - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayRotate: true + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -49,15 +46,12 @@ describe('StringArrayRotateFunctionTemplate', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayRotate: true - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayRotate: true + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -79,15 +73,12 @@ describe('StringArrayRotateFunctionTemplate', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayRotate: true - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayRotate: true + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -107,15 +98,12 @@ describe('StringArrayRotateFunctionTemplate', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayRotate: true - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayRotate: true + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -135,15 +123,12 @@ describe('StringArrayRotateFunctionTemplate', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayRotate: true - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayRotate: true + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); diff --git a/test/functional-tests/custom-code-helpers/string-array/templates/string-array-template/StringArrayTemplate.spec.ts b/test/functional-tests/custom-code-helpers/string-array/templates/string-array-template/StringArrayTemplate.spec.ts index 3742c78e2..bd6c2d251 100644 --- a/test/functional-tests/custom-code-helpers/string-array/templates/string-array-template/StringArrayTemplate.spec.ts +++ b/test/functional-tests/custom-code-helpers/string-array/templates/string-array-template/StringArrayTemplate.spec.ts @@ -14,18 +14,15 @@ describe('StringArrayTemplate', () => { describe('Prevailing kind of variables', () => { describe('`var` kind', () => { let obfuscatedCode: string, - stringArrayRegExp: RegExp = getStringArrayRegExp(['foo'], {kind: 'var'}); + stringArrayRegExp: RegExp = getStringArrayRegExp(['foo'], { kind: 'var' }); beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -41,18 +38,15 @@ describe('StringArrayTemplate', () => { describe('`const` kind', () => { let obfuscatedCode: string, - stringArrayRegExp: RegExp = getStringArrayRegExp(['foo'], {kind: 'const'}); + stringArrayRegExp: RegExp = getStringArrayRegExp(['foo'], { kind: 'const' }); beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); @@ -68,18 +62,15 @@ describe('StringArrayTemplate', () => { describe('`let` kind', () => { let obfuscatedCode: string, - stringArrayRegExp: RegExp = getStringArrayRegExp(['foo'], {kind: 'const'}); + stringArrayRegExp: RegExp = getStringArrayRegExp(['foo'], { kind: 'const' }); beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); }); diff --git a/test/functional-tests/generators/identifier-names-generators/dictionary-identifier-names-generator/DictionaryIdentifierNamesGenerator.spec.ts b/test/functional-tests/generators/identifier-names-generators/dictionary-identifier-names-generator/DictionaryIdentifierNamesGenerator.spec.ts index 8d2520d28..28132ffb8 100644 --- a/test/functional-tests/generators/identifier-names-generators/dictionary-identifier-names-generator/DictionaryIdentifierNamesGenerator.spec.ts +++ b/test/functional-tests/generators/identifier-names-generators/dictionary-identifier-names-generator/DictionaryIdentifierNamesGenerator.spec.ts @@ -14,13 +14,10 @@ describe('DictionaryIdentifierNamesGenerator', () => { describe('generateWithPrefix', () => { describe('Variant #1: should not generate same name for string array as existing name in code', () => { describe('Variant #1: `renameGlobals` option is disabled', () => { - const stringArrayStorageRegExp: RegExp = getStringArrayRegExp( - ['_aa', '_ab'], - { - name: '\\w*', - kind: 'const' - } - ); + const stringArrayStorageRegExp: RegExp = getStringArrayRegExp(['_aa', '_ab'], { + name: '\\w*', + kind: 'const' + }); const variableDeclarationIdentifierNameRegExp1: RegExp = /const (\w*) *= *\w*\(0x0\);/; const variableDeclarationIdentifierNameRegExp2: RegExp = /const (\w*) *= *\w*\(0x1\);/; @@ -30,21 +27,20 @@ describe('DictionaryIdentifierNamesGenerator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-name-conflict-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, - identifiersDictionary: ['a', 'b', 'c'], - identifiersPrefix: 'a', - transformObjectKeys: true, - stringArray: true, - stringArrayThreshold: 1, - seed: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, + identifiersDictionary: ['a', 'b', 'c'], + identifiersPrefix: 'a', + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1, + seed: 1 + }).getObfuscatedCode(); stringArrayName = getRegExpMatch(obfuscatedCode, stringArrayStorageRegExp); variableDeclarationIdentifierName1 = getRegExpMatch( @@ -71,13 +67,10 @@ describe('DictionaryIdentifierNamesGenerator', () => { }); describe('Variant #2: `renameGlobals` option is enabled', () => { - const stringArrayStorageRegExp: RegExp = getStringArrayRegExp( - ['_aa', '_ab'], - { - name: '\\w*', - kind: 'const' - } - ); + const stringArrayStorageRegExp: RegExp = getStringArrayRegExp(['_aa', '_ab'], { + name: '\\w*', + kind: 'const' + }); const variableDeclarationIdentifierNameRegExp1: RegExp = /const (\w*) *= *\w*\(0x0\);/; const variableDeclarationIdentifierNameRegExp2: RegExp = /const (\w*) *= *\w*\(0x1\);/; @@ -87,21 +80,20 @@ describe('DictionaryIdentifierNamesGenerator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-name-conflict-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, - identifiersDictionary: ['a', 'b', 'c', 'd'], - identifiersPrefix: 'a', - renameGlobals: true, - transformObjectKeys: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, + identifiersDictionary: ['a', 'b', 'c', 'd'], + identifiersPrefix: 'a', + renameGlobals: true, + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); stringArrayName = getRegExpMatch(obfuscatedCode, stringArrayStorageRegExp); variableDeclarationIdentifierName1 = getRegExpMatch( @@ -134,36 +126,35 @@ describe('DictionaryIdentifierNamesGenerator', () => { const samplesCount: number = 30; describe('Variant #1: `renameGlobals` option is disabled', () => { - const stringArrayStorageRegExp: RegExp = getStringArrayRegExp( - ['first', 'abc'], - { - name: '\\w*', - kind: 'const' - } - ); + const stringArrayStorageRegExp: RegExp = getStringArrayRegExp(['first', 'abc'], { + name: '\\w*', + kind: 'const' + }); const variableDeclarationIdentifierNameRegExp: RegExp = /const (\w*) *= *\w*\(0x0\);/; let isIdentifiersAreConflicted: boolean = false; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-name-conflict-2.js' + ); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, - identifiersDictionary: ['a', 'b', 'aa'], - identifiersPrefix: 'a', - transformObjectKeys: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, + identifiersDictionary: ['a', 'b', 'aa'], + identifiersPrefix: 'a', + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const stringArrayStorageName: string = getRegExpMatch(obfuscatedCode, stringArrayStorageRegExp); - const variableDeclarationIdentifierName: string = getRegExpMatch(obfuscatedCode, variableDeclarationIdentifierNameRegExp); + const variableDeclarationIdentifierName: string = getRegExpMatch( + obfuscatedCode, + variableDeclarationIdentifierNameRegExp + ); if (stringArrayStorageName === variableDeclarationIdentifierName) { isIdentifiersAreConflicted = true; @@ -179,37 +170,36 @@ describe('DictionaryIdentifierNamesGenerator', () => { }); describe('Variant #2: `renameGlobals` option is enabled', () => { - const stringArrayStorageRegExp: RegExp = getStringArrayRegExp( - ['first', 'abc'], - { - name: '\\w*', - kind: 'const' - } - ); + const stringArrayStorageRegExp: RegExp = getStringArrayRegExp(['first', 'abc'], { + name: '\\w*', + kind: 'const' + }); const variableDeclarationIdentifierNameRegExp: RegExp = /const (\w*) *= *\w*\(0x0\);/; let isIdentifiersAreConflicted: boolean = false; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-name-conflict-2.js' + ); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, - identifiersDictionary: ['a', 'b', 'aa'], - identifiersPrefix: 'a', - renameGlobals: true, - transformObjectKeys: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, + identifiersDictionary: ['a', 'b', 'aa'], + identifiersPrefix: 'a', + renameGlobals: true, + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const stringArrayStorageName: string = getRegExpMatch(obfuscatedCode, stringArrayStorageRegExp); - const variableDeclarationIdentifierName: string = getRegExpMatch(obfuscatedCode, variableDeclarationIdentifierNameRegExp); + const variableDeclarationIdentifierName: string = getRegExpMatch( + obfuscatedCode, + variableDeclarationIdentifierNameRegExp + ); if (stringArrayStorageName === variableDeclarationIdentifierName) { isIdentifiersAreConflicted = true; diff --git a/test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/MangledIdentifierNamesGenerator.spec.ts b/test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/MangledIdentifierNamesGenerator.spec.ts index 62d8800ac..1dc01f542 100644 --- a/test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/MangledIdentifierNamesGenerator.spec.ts +++ b/test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/MangledIdentifierNamesGenerator.spec.ts @@ -22,19 +22,18 @@ describe('MangledIdentifierNamesGenerator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-name-conflict-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'a', - transformObjectKeys: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'a', + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('Match #1: should generate correct identifier for string array', () => { @@ -56,20 +55,19 @@ describe('MangledIdentifierNamesGenerator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'a', - renameGlobals: true, - transformObjectKeys: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-name-conflict-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'a', + renameGlobals: true, + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('Match #1: should generate correct identifier for string array', () => { @@ -94,19 +92,18 @@ describe('MangledIdentifierNamesGenerator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-name-conflict-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'a', - transformObjectKeys: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'a', + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('Match #1: should generate correct identifier name for string array', () => { @@ -133,20 +130,19 @@ describe('MangledIdentifierNamesGenerator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-2.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'a', - renameGlobals: true, - transformObjectKeys: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-name-conflict-2.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'a', + renameGlobals: true, + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('Match #1: should generate correct identifier name for string array', () => { @@ -176,13 +172,10 @@ describe('MangledIdentifierNamesGenerator', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Match #1: should keep identifier name for variable declaration', () => { @@ -208,14 +201,11 @@ describe('MangledIdentifierNamesGenerator', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + renameGlobals: true + }).getObfuscatedCode(); }); it('Match #1: should generate valid identifier name for variable declaration', () => { @@ -247,15 +237,12 @@ describe('MangledIdentifierNamesGenerator', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('Match #1: should generate valid identifier names for string array', () => { @@ -289,16 +276,13 @@ describe('MangledIdentifierNamesGenerator', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - renameGlobals: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + renameGlobals: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('Match #1: should generate valid identifier names for string array', () => { @@ -321,30 +305,29 @@ describe('MangledIdentifierNamesGenerator', () => { describe('Variant #3: Should generate different names set for different lexical scopes: nested functions', () => { describe('Variant #1: `renameGlobals` option is disabled', () => { - const regExp: RegExp = new RegExp(`` + - `var foo *= *'abc'; *` + - `function bar *\\(a, *b\\) *{` + + const regExp: RegExp = new RegExp( + `` + + `var foo *= *'abc'; *` + + `function bar *\\(a, *b\\) *{` + `function c *\\(e, *f\\) *{ *} *` + `function d *\\(e, *f\\) *{ *} *` + - `} *` + - `function baz *\\(a, *b\\) *{` + + `} *` + + `function baz *\\(a, *b\\) *{` + `function c *\\(e, *f\\) *{ *} *` + `function d *\\(e, *f\\) *{ *} *` + - `}` + - ``); + `}` + + `` + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Match #1: should generate valid identifier names', () => { @@ -353,31 +336,30 @@ describe('MangledIdentifierNamesGenerator', () => { }); describe('Variant #2: `renameGlobals` option is enabled', () => { - const regExp: RegExp = new RegExp(`` + - `var a *= *'abc'; *` + - `function b *\\(d, *e\\) *{` + + const regExp: RegExp = new RegExp( + `` + + `var a *= *'abc'; *` + + `function b *\\(d, *e\\) *{` + `function f *\\(h, *i\\) *{ *} *` + `function g *\\(h, *i\\) *{ *} *` + - `} *` + - `function c *\\(d, *e\\) *{` + + `} *` + + `function c *\\(d, *e\\) *{` + `function f *\\(h, *i\\) *{ *} *` + `function g *\\(h, *i\\) *{ *} *` + - `}` + - ``); + `}` + + `` + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + renameGlobals: true + }).getObfuscatedCode(); }); it('Match #1: should generate valid identifier names', () => { diff --git a/test/functional-tests/generators/identifier-names-generators/mangled-shuffled-identifier-names-generator/MangledShuffledIdentifierNamesGenerator.spec.ts b/test/functional-tests/generators/identifier-names-generators/mangled-shuffled-identifier-names-generator/MangledShuffledIdentifierNamesGenerator.spec.ts index 4c41473f7..b17f62db4 100644 --- a/test/functional-tests/generators/identifier-names-generators/mangled-shuffled-identifier-names-generator/MangledShuffledIdentifierNamesGenerator.spec.ts +++ b/test/functional-tests/generators/identifier-names-generators/mangled-shuffled-identifier-names-generator/MangledShuffledIdentifierNamesGenerator.spec.ts @@ -12,9 +12,9 @@ describe('MangledShuffledIdentifierNamesGenerator', () => { describe('Variant #1: prevent name sequence mutation of base `mangled` generator', () => { const functionsRegExp: RegExp = new RegExp( 'function foo *\\(a, *b\\) *{} *' + - 'function foo *\\(a, *b\\) *{} *' + - 'function foo *\\(a, *b\\) *{} *' + - 'function foo *\\(a, *b\\) *{}' + 'function foo *\\(a, *b\\) *{} *' + + 'function foo *\\(a, *b\\) *{} *' + + 'function foo *\\(a, *b\\) *{}' ); let obfuscatedCode: string = ''; @@ -23,17 +23,15 @@ describe('MangledShuffledIdentifierNamesGenerator', () => { const code: string = readFileAsString(__dirname + '/fixtures/prevent-name-sequence-mutation.js'); for (let i = 0; i < 4; i++) { - const identifierNamesGenerator = i % 2 === 0 - ? IdentifierNamesGenerator.MangledIdentifierNamesGenerator - : IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator; - - obfuscatedCode += JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator - } - ).getObfuscatedCode(); + const identifierNamesGenerator = + i % 2 === 0 + ? IdentifierNamesGenerator.MangledIdentifierNamesGenerator + : IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator; + + obfuscatedCode += JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator + }).getObfuscatedCode(); } }); diff --git a/test/functional-tests/issues/issue321.spec.ts b/test/functional-tests/issues/issue321.spec.ts index a5fe68e52..313189455 100644 --- a/test/functional-tests/issues/issue321.spec.ts +++ b/test/functional-tests/issues/issue321.spec.ts @@ -13,14 +13,10 @@ describe('Issue #321', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/issue321.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: false, - } - ).getObfuscatedCode(); - + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: false + }).getObfuscatedCode(); }); it('does not break on run', () => { diff --git a/test/functional-tests/issues/issue355.spec.ts b/test/functional-tests/issues/issue355.spec.ts index d16d716ed..eb4738a76 100644 --- a/test/functional-tests/issues/issue355.spec.ts +++ b/test/functional-tests/issues/issue355.spec.ts @@ -2,7 +2,7 @@ import { assert } from 'chai'; import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; import { readFileAsString } from '../../helpers/readFileAsString'; import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; -import { IdentifierNamesGenerator } from "../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator"; +import { IdentifierNamesGenerator } from '../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator'; // // https://github.com/javascript-obfuscator/javascript-obfuscator/issues/355 @@ -14,15 +14,11 @@ describe('Issue #355', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/issue355.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: false, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); - + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: false, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('does not break on run', () => { diff --git a/test/functional-tests/issues/issue419.spec.ts b/test/functional-tests/issues/issue419.spec.ts index 2afb52954..2222603a4 100644 --- a/test/functional-tests/issues/issue419.spec.ts +++ b/test/functional-tests/issues/issue419.spec.ts @@ -15,13 +15,10 @@ describe('Issue #419', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/issue419.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - compact: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + compact: true + }).getObfuscatedCode(); }); it('does not break on obfuscating', () => { diff --git a/test/functional-tests/issues/issue424.spec.ts b/test/functional-tests/issues/issue424.spec.ts index 1cba1f4b9..7f0a51a1f 100644 --- a/test/functional-tests/issues/issue424.spec.ts +++ b/test/functional-tests/issues/issue424.spec.ts @@ -13,14 +13,10 @@ describe('Issue #424', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/issue424.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: false - } - ).getObfuscatedCode(); - + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: false + }).getObfuscatedCode(); }); it('does not break on run', () => { diff --git a/test/functional-tests/issues/issue437.spec.ts b/test/functional-tests/issues/issue437.spec.ts index b6144608c..04503496d 100644 --- a/test/functional-tests/issues/issue437.spec.ts +++ b/test/functional-tests/issues/issue437.spec.ts @@ -13,13 +13,11 @@ describe('Issue #437', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/issue437.js'); - testFunc = () => JavaScriptObfuscator.obfuscate( - code, - { + testFunc = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, transformObjectKeys: true - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('does not break on obfuscating', () => { diff --git a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts index 07761c9f3..6a12c7ab2 100644 --- a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts +++ b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts @@ -33,17 +33,13 @@ import { readFileAsString } from '../../helpers/readFileAsString'; describe('JavaScriptObfuscator', () => { describe('obfuscate', () => { describe('correct source code', () => { - let obfuscatedCode: string, - sourceMap: string; + let obfuscatedCode: string, sourceMap: string; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input-1.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); sourceMap = obfuscationResult.getSourceMap(); @@ -65,9 +61,7 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/empty-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code).getObfuscatedCode(); }); it('should return an empty obfuscated code', () => { @@ -81,13 +75,10 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/comments-only.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - controlFlowFlattening: true, - deadCodeInjection: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + controlFlowFlattening: true, + deadCodeInjection: true + }).getObfuscatedCode(); }); it('should return an empty obfuscated code', () => { @@ -99,9 +90,7 @@ describe('JavaScriptObfuscator', () => { let obfuscatedCode: string; beforeEach(() => { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - 1 as unknown as string - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(1 as unknown as string).getObfuscatedCode(); }); it('should return an empty obfuscated code', () => { @@ -112,27 +101,19 @@ describe('JavaScriptObfuscator', () => { describe('`sourceMap` option is `true`', () => { describe('`sourceMapMode` is `separate`', () => { - let code: string, - obfuscatedCode: string, - sourceMap: ISourceMap, - resolvedSources: string; + let code: string, obfuscatedCode: string, sourceMap: ISourceMap, resolvedSources: string; beforeEach((done) => { code = readFileAsString(__dirname + '/fixtures/simple-input-1.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - sourceMap: true - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + sourceMap: true + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); sourceMap = JSON.parse(obfuscationResult.getSourceMap()); resolveSources(sourceMap, '/', fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); }); @@ -161,28 +142,20 @@ describe('JavaScriptObfuscator', () => { describe('`sourceMapMode` is `inline`', () => { const regExp: RegExp = /sourceMappingURL=data:application\/json;base64/; - let code: string, - obfuscatedCode: string, - sourceMap: ISourceMap, - resolvedSources: string; + let code: string, obfuscatedCode: string, sourceMap: ISourceMap, resolvedSources: string; beforeEach((done) => { code = readFileAsString(__dirname + '/fixtures/simple-input-1.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - sourceMap: true, - sourceMapMode: SourceMapMode.Inline - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + sourceMap: true, + sourceMapMode: SourceMapMode.Inline + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); sourceMap = JSON.parse(obfuscationResult.getSourceMap()); resolveSources(sourceMap, '/', fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); }); @@ -221,12 +194,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/empty-input.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - sourceMap: true - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + sourceMap: true + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); @@ -256,28 +226,21 @@ describe('JavaScriptObfuscator', () => { describe('`sourceMapSourceMode` is set', () => { describe('`sourcesContent` value', () => { - let code: string, - obfuscatedCode: string, - sourceMap: ISourceMap, - resolvedSources: string; + let code: string, obfuscatedCode: string, sourceMap: ISourceMap, resolvedSources: string; beforeEach((done) => { code = readFileAsString(__dirname + '/fixtures/simple-input-1.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - sourceMap: true, - sourceMapSourcesMode: SourceMapSourcesMode.SourcesContent - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + sourceMap: true, + sourceMapSourcesMode: SourceMapSourcesMode.SourcesContent + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); sourceMap = JSON.parse(obfuscationResult.getSourceMap()); resolveSources(sourceMap, '/', fs.readFile, (error, result) => { - resolvedSources = typeof result.sourcesContent[0] === 'string' - ? result.sourcesContent[0] - : ''; + resolvedSources = + typeof result.sourcesContent[0] === 'string' ? result.sourcesContent[0] : ''; done(); }); }); @@ -313,21 +276,16 @@ describe('JavaScriptObfuscator', () => { describe('`sources` value', () => { describe('`inputFileName` option is set', () => { - let code: string, - obfuscatedCode: string, - sourceMap: ISourceMap; + let code: string, obfuscatedCode: string, sourceMap: ISourceMap; beforeEach(() => { code = readFileAsString(__dirname + '/fixtures/simple-input-1.js'); - const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - inputFileName: 'someFile.js', - sourceMap: true, - sourceMapSourcesMode: SourceMapSourcesMode.Sources - } - ); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + inputFileName: 'someFile.js', + sourceMap: true, + sourceMapSourcesMode: SourceMapSourcesMode.Sources + }); obfuscatedCode = obfuscationResult.getObfuscatedCode(); sourceMap = JSON.parse(obfuscationResult.getSourceMap()); @@ -352,21 +310,19 @@ describe('JavaScriptObfuscator', () => { it('should define placeholder `sources` field for source map', () => { assert.deepEqual(sourceMap.sources, ['someFile.js']); }); - }) + }); describe('`inputFileName` option is not set', () => { let testFunc: () => IObfuscationResult; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input-1.js'); - testFunc = () => JavaScriptObfuscator.obfuscate( - code, - { + testFunc = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, sourceMap: true, sourceMapSourcesMode: SourceMapSourcesMode.Sources - } - ); + }); }); it('should throw an error', () => { @@ -386,12 +342,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should return correct obfuscated code', () => { @@ -407,13 +360,10 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('should return correct obfuscated code', () => { @@ -429,14 +379,11 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifiersPrefix: 'foo' - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifiersPrefix: 'foo' + }).getObfuscatedCode(); }); it('should return correct obfuscated code', () => { @@ -447,9 +394,9 @@ describe('JavaScriptObfuscator', () => { describe('Variant #4: with `stringArray`, `renameGlobals` and `identifiersPrefix` options', () => { const stringArrayRegExp: RegExp = new RegExp( 'function foo_0x([a-f0-9]){4} *\\(\\) *{' + - 'var _0x([a-f0-9]){4,6} *= *\\[\'abc\'];.*' + + "var _0x([a-f0-9]){4,6} *= *\\['abc'];.*" + 'return foo_0x([a-f0-9]){4}\\(\\); *' + - '}' + '}' ); const stringArrayCallRegExp: RegExp = /var foo_0x(\w){4,6} *= *foo_0x(\w){4}\(0x0\);/; @@ -458,16 +405,13 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifiersPrefix: 'foo', - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifiersPrefix: 'foo', + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should return correct obfuscated code', () => { @@ -488,12 +432,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/block-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should return correct obfuscated code', () => { @@ -513,14 +454,11 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifiers-prefix.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifiersPrefix: 'foo' - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifiersPrefix: 'foo' + }).getObfuscatedCode(); }); it('match #1: should return correct obfuscated code', () => { @@ -550,14 +488,11 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should return correct obfuscated code', () => { @@ -572,9 +507,9 @@ describe('JavaScriptObfuscator', () => { describe('cyrillic literal variable value', () => { const stringArrayCyrillicRegExp: RegExp = new RegExp( 'function _0x(\\w){4} *\\(\\) *{' + - 'var _0x([a-f0-9]){4,6} *= *\\[\'абц\'];.*' + + "var _0x([a-f0-9]){4,6} *= *\\['абц'];.*" + 'return _0x(\\w){4}\\(\\); *' + - '}' + '}' ); const stringArrayCallRegExp: RegExp = /var test *= *_0x(\w){4}\(0x0\);/; @@ -583,14 +518,11 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input-cyrillic.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should return correct obfuscated code', () => { @@ -620,18 +552,12 @@ describe('JavaScriptObfuscator', () => { seed++; } - obfuscatedCode1 = JavaScriptObfuscator.obfuscate( - code, - { - seed: seed - } - ).getObfuscatedCode(); - obfuscatedCode2 = JavaScriptObfuscator.obfuscate( - code, - { - seed: seed - } - ).getObfuscatedCode(); + obfuscatedCode1 = JavaScriptObfuscator.obfuscate(code, { + seed: seed + }).getObfuscatedCode(); + obfuscatedCode2 = JavaScriptObfuscator.obfuscate(code, { + seed: seed + }).getObfuscatedCode(); if (obfuscatedCode1 === obfuscatedCode2) { equalsCount++; @@ -647,22 +573,15 @@ describe('JavaScriptObfuscator', () => { describe('Variant #1: different seed on each run', () => { const code: string = readFileAsString('./test/fixtures/sample.js'); - let obfuscatedCode1: string, - obfuscatedCode2: string; + let obfuscatedCode1: string, obfuscatedCode2: string; beforeEach(() => { - obfuscatedCode1 = JavaScriptObfuscator.obfuscate( - code, - { - seed: 12345 - } - ).getObfuscatedCode(); - obfuscatedCode2 = JavaScriptObfuscator.obfuscate( - code, - { - seed: 12346 - } - ).getObfuscatedCode(); + obfuscatedCode1 = JavaScriptObfuscator.obfuscate(code, { + seed: 12345 + }).getObfuscatedCode(); + obfuscatedCode2 = JavaScriptObfuscator.obfuscate(code, { + seed: 12346 + }).getObfuscatedCode(); }); it('should return different obfuscated code with different `seed` option value', () => { @@ -673,22 +592,15 @@ describe('JavaScriptObfuscator', () => { describe('Variant #2: different seed on each run', () => { const code: string = readFileAsString('./test/fixtures/sample.js'); - let obfuscatedCode1: string, - obfuscatedCode2: string; + let obfuscatedCode1: string, obfuscatedCode2: string; beforeEach(() => { - obfuscatedCode1 = JavaScriptObfuscator.obfuscate( - code, - { - seed: 0 - } - ).getObfuscatedCode(); - obfuscatedCode2 = JavaScriptObfuscator.obfuscate( - code, - { - seed: 0 - } - ).getObfuscatedCode(); + obfuscatedCode1 = JavaScriptObfuscator.obfuscate(code, { + seed: 0 + }).getObfuscatedCode(); + obfuscatedCode2 = JavaScriptObfuscator.obfuscate(code, { + seed: 0 + }).getObfuscatedCode(); }); it('should return different obfuscated code with different `seed` option value', () => { @@ -702,29 +614,22 @@ describe('JavaScriptObfuscator', () => { const regExp: RegExp = new RegExp( 'function _0x(\\w){4} *\\(\\) *{' + - 'var _0x([a-f0-9]){4,6} *= *\\[\'.*\'];.*' + + "var _0x([a-f0-9]){4,6} *= *\\['.*'];.*" + 'return _0x(\\w){4}\\(\\); *' + - '}' + '}' ); - let match1: string, - match2: string; + let match1: string, match2: string; beforeEach(() => { - const obfuscatedCode1: string = JavaScriptObfuscator.obfuscate( - code1, - { - seed: 123, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); - const obfuscatedCode2: string = JavaScriptObfuscator.obfuscate( - code2, - { - seed: 123, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode1: string = JavaScriptObfuscator.obfuscate(code1, { + seed: 123, + stringArrayThreshold: 1 + }).getObfuscatedCode(); + const obfuscatedCode2: string = JavaScriptObfuscator.obfuscate(code2, { + seed: 123, + stringArrayThreshold: 1 + }).getObfuscatedCode(); match1 = getRegExpMatch(obfuscatedCode1, regExp); match2 = getRegExpMatch(obfuscatedCode2, regExp); @@ -747,12 +652,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-single-rest-element.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should not break on `ObjectPattern` with single `RestElement`', () => { @@ -769,14 +671,13 @@ describe('JavaScriptObfuscator', () => { let obfuscatedCode: string; beforeEach(() => { - const code: string = readFileAsString(__dirname + '/fixtures/precedence-of-sequence-expression-in-computed-property.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/precedence-of-sequence-expression-in-computed-property.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should generate a valid js code', () => { @@ -792,12 +693,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/new-target.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should keep new.target MetaProperty', () => { @@ -813,12 +711,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/import-meta.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should support `import.meta`', () => { @@ -837,12 +732,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/export-all-named-support.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should support `export * as` syntax', () => { @@ -861,12 +753,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/exponentiation-operator-precedence.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should support exponentiation operator', () => { @@ -882,12 +771,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/bigint-support.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should support BigInt', () => { @@ -898,9 +784,9 @@ describe('JavaScriptObfuscator', () => { describe('Optional chaining support', () => { const regExp: RegExp = new RegExp( 'const _0x(\\w){4,6} *= *{ *' + - '\'bar\': *\\(\\) *=> *{} *' + - '}; *' + - '_0x(\\w){4,6}\\?\\.\\[\'bar\']\\?\\.\\(\\);' + "'bar': *\\(\\) *=> *{} *" + + '}; *' + + "_0x(\\w){4,6}\\?\\.\\['bar']\\?\\.\\(\\);" ); let obfuscatedCode: string; @@ -908,12 +794,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/optional-chaining-support.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should support optional chaining', () => { @@ -929,12 +812,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/nullish-coalescing-support.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should support nullish coalescing operator', () => { @@ -950,12 +830,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/numeric-separators-support.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should support numeric separators', () => { @@ -971,12 +848,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/top-level-await-support.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should support top-level await', () => { @@ -987,15 +861,15 @@ describe('JavaScriptObfuscator', () => { describe('Class static block support', () => { const regExp: RegExp = new RegExp( 'let _0x(\\w){4,6} *= *0x1; *' + - 'class _0x(\\w){4,6} *{ *' + - 'static *\\[\'_0x(\\w){4,6}\']; *' + + 'class _0x(\\w){4,6} *{ *' + + "static *\\['_0x(\\w){4,6}']; *" + 'static *{ *' + - 'let _0x(\\w){4,6} *= *0x2; *' + - '_0x(\\w){4,6}\\[\'_0x(\\w){4,6}\'] *= *0x3; *' + - '_0x(\\w){4,6} *= *0x4; *' + - '_0x(\\w){4,6} *= *0x5; *' + + 'let _0x(\\w){4,6} *= *0x2; *' + + "_0x(\\w){4,6}\\['_0x(\\w){4,6}'] *= *0x3; *" + + '_0x(\\w){4,6} *= *0x4; *' + + '_0x(\\w){4,6} *= *0x5; *' + '} *' + - '}' + '}' ); let obfuscatedCode: string; @@ -1003,14 +877,11 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/class-static-block-support-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - renameProperties: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + renameProperties: true + }).getObfuscatedCode(); console.log(obfuscatedCode); }); @@ -1022,12 +893,7 @@ describe('JavaScriptObfuscator', () => { describe('Private identifiers support', () => { const regExp: RegExp = new RegExp( - 'class Foo *{ *' + - '#bar *= *0x1; *' + - '\\[\'method\'] *\\(\\) *{ *' + - 'this\.#bar *= *0x2;' + - '} *' + - '}' + 'class Foo *{ *' + '#bar *= *0x1; *' + "\\['method'] *\\(\\) *{ *" + 'this\.#bar *= *0x2;' + '} *' + '}' ); let obfuscatedCode: string; @@ -1035,13 +901,10 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/private-identifier.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true + }).getObfuscatedCode(); }); it('should support private identifiers', () => { @@ -1058,18 +921,15 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/call-expression-class-expression.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should not throw', () => { assert.match(obfuscatedCode, regExp); }); - }); + }); describe('mangled identifier names generator', () => { const regExp: RegExp = /var c *= *0x1/; @@ -1079,15 +939,12 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/mangle.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should mangle obfuscated code', () => { @@ -1103,12 +960,9 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/mangle.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - identifierNamesGenerator: IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + identifierNamesGenerator: IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('should mangle obfuscated code', () => { @@ -1125,14 +979,11 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/dictionary-identifiers.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, - identifiersDictionary: ['a', 'b', 'c'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, + identifiersDictionary: ['a', 'b', 'c'] + }).getObfuscatedCode(); }); it('Match #1: should generate identifier based on the dictionary', () => { @@ -1199,20 +1050,17 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-names-cache-1.js'); - identifierNamesCache = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - baz: 'baz_value_from_cache' - }, - propertyIdentifiers: {} + identifierNamesCache = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + baz: 'baz_value_from_cache' }, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getIdentifierNamesCache(); + propertyIdentifiers: {} + }, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getIdentifierNamesCache(); }); it('Match #1: should correctly generate identifier names cache', () => { @@ -1234,18 +1082,15 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-names-cache-1.js'); - identifierNamesCache = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: {}, - propertyIdentifiers: {} - }, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getIdentifierNamesCache(); + identifierNamesCache = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: {}, + propertyIdentifiers: {} + }, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getIdentifierNamesCache(); }); it('Match #1: should correctly generate identifier names cache', () => { @@ -1264,18 +1109,15 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-names-cache-2.js'); - identifierNamesCache = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: {}, - propertyIdentifiers: {} - }, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getIdentifierNamesCache(); + identifierNamesCache = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: {}, + propertyIdentifiers: {} + }, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getIdentifierNamesCache(); }); it('Match #1: should correctly generate identifier names cache', () => { @@ -1291,15 +1133,12 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-names-cache-1.js'); - identifierNamesCache = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: null, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getIdentifierNamesCache(); + identifierNamesCache = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: null, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getIdentifierNamesCache(); }); it('Match #1: should correctly generate identifier names cache', () => { @@ -1318,40 +1157,34 @@ describe('JavaScriptObfuscator', () => { beforeEach(() => { const code: string = buildLargeCode(expectedValue); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - compact: true, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - disableConsoleOutput: false, - numbersToExpressions: true, - simplify: true, - renameProperties: true, - stringArrayRotate: true, - stringArray: true, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.Base64, - StringArrayEncoding.Rc4 - ], - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumber, - StringArrayIndexesType.HexadecimalNumericString - ], - stringArrayIndexShift: true, - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 10, - stringArrayWrappersParametersMaxCount: 5, - stringArrayWrappersType: StringArrayWrappersType.Function, - stringArrayThreshold: 1, - transformObjectKeys: true, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + compact: true, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + disableConsoleOutput: false, + numbersToExpressions: true, + simplify: true, + renameProperties: true, + stringArrayRotate: true, + stringArray: true, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.Base64, StringArrayEncoding.Rc4], + stringArrayIndexesType: [ + StringArrayIndexesType.HexadecimalNumber, + StringArrayIndexesType.HexadecimalNumericString + ], + stringArrayIndexShift: true, + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 10, + stringArrayWrappersParametersMaxCount: 5, + stringArrayWrappersType: StringArrayWrappersType.Function, + stringArrayThreshold: 1, + transformObjectKeys: true, + unicodeEscapeSequence: false + }).getObfuscatedCode(); result = eval(obfuscatedCode); }); @@ -1372,26 +1205,23 @@ describe('JavaScriptObfuscator', () => { const code: string = readFileAsString(__dirname + '/fixtures/eval-hello-world.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - compact: false, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - disableConsoleOutput: true, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - renameProperties: true, - simplify: false, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 1, - stringArrayWrappersType: StringArrayWrappersType.Variable - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + compact: false, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + disableConsoleOutput: true, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + renameProperties: true, + simplify: false, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 1, + stringArrayWrappersType: StringArrayWrappersType.Variable + }).getObfuscatedCode(); const evaluationResult: string = eval(obfuscatedCode); @@ -1413,25 +1243,25 @@ describe('JavaScriptObfuscator', () => { const samplesCount: number = 30; let collisionError: string | null = null; - let obfuscateFunc: (identifierNamesGenerator: TTypeFromEnum) => IObfuscationResult; + let obfuscateFunc: ( + identifierNamesGenerator: TTypeFromEnum + ) => IObfuscationResult; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/custom-nodes-identifier-names-collision.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/custom-nodes-identifier-names-collision.js' + ); obfuscateFunc = (identifierNamesGenerator: TTypeFromEnum) => { - return JavaScriptObfuscator.obfuscate( - code, - { - identifierNamesGenerator, - compact: false, - renameGlobals: true, - identifiersDictionary: ['foo', 'bar', 'baz', 'bark', 'hawk', 'foozmos', 'cow', 'chikago'], - stringArray: true - } - ); + return JavaScriptObfuscator.obfuscate(code, { + identifierNamesGenerator, + compact: false, + renameGlobals: true, + identifiersDictionary: ['foo', 'bar', 'baz', 'bark', 'hawk', 'foozmos', 'cow', 'chikago'], + stringArray: true + }); }; - [ IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator, IdentifierNamesGenerator.MangledIdentifierNamesGenerator @@ -1480,14 +1310,11 @@ describe('JavaScriptObfuscator', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - ...baseParams, - stringArrayEncoding: [StringArrayEncoding.Rc4] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + ...baseParams, + stringArrayEncoding: [StringArrayEncoding.Rc4] + }).getObfuscatedCode(); }); it('does not break on run', () => { @@ -1500,17 +1327,15 @@ describe('JavaScriptObfuscator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - ...baseParams, - stringArrayEncoding: [StringArrayEncoding.Rc4] - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/prevailing-kind-of-variables-const.js' + ); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + ...baseParams, + stringArrayEncoding: [StringArrayEncoding.Rc4] + }).getObfuscatedCode(); }); it('does not break on run', () => { @@ -1522,16 +1347,15 @@ describe('JavaScriptObfuscator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/prevailing-kind-of-variables-const.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - ...baseParams, - stringArrayEncoding: [StringArrayEncoding.Rc4] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + ...baseParams, + stringArrayEncoding: [StringArrayEncoding.Rc4] + }).getObfuscatedCode(); }); it('does not break on run', () => { @@ -1545,17 +1369,15 @@ describe('JavaScriptObfuscator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - ...baseParams, - stringArrayEncoding: [StringArrayEncoding.Rc4] - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/prevailing-kind-of-variables-let.js' + ); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + ...baseParams, + stringArrayEncoding: [StringArrayEncoding.Rc4] + }).getObfuscatedCode(); }); it('does not break on run', () => { @@ -1567,17 +1389,15 @@ describe('JavaScriptObfuscator', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - ...baseParams, - stringArrayEncoding: [StringArrayEncoding.Base64] - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/prevailing-kind-of-variables-let.js' + ); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + ...baseParams, + stringArrayEncoding: [StringArrayEncoding.Base64] + }).getObfuscatedCode(); }); it('does not break on run', () => { @@ -1627,13 +1447,11 @@ describe('JavaScriptObfuscator', () => { let testFunc: () => TDictionary; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscateMultiple( - 'foo' as any, - { + testFunc = () => + JavaScriptObfuscator.obfuscateMultiple('foo' as any, { ...NO_ADDITIONAL_NODES_PRESET, renameGlobals: true - } - ); + }); }); it('Should throw an error if source codes object is not a plain object', () => { diff --git a/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts index 5eea8be82..de0fb56a1 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts @@ -25,17 +25,14 @@ describe('BlockStatementControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - describe('`console.log` statements', ()=> { + describe('`console.log` statements', () => { const statementRegExp1: RegExp = getStatementRegExp('0x1'); const statementRegExp2: RegExp = getStatementRegExp('0x2'); const statementRegExp3: RegExp = getStatementRegExp('0x3'); @@ -84,7 +81,8 @@ describe('BlockStatementControlFlowTransformer', function () { }); describe('switch-case map', () => { - const switchCaseMapVariableRegExp: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\)/; + const switchCaseMapVariableRegExp: RegExp = + /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\)/; const switchCaseMapIndexVariableRegExp: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *0x0;/; const switchCaseMapStringRegExp: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *\{'.*' *: *'(.*)'\};/; const expectedSwitchCasesSequence: string[] = ['0', '1', '2', '3', '4']; @@ -117,18 +115,15 @@ describe('BlockStatementControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + unicodeEscapeSequence: false + }).getObfuscatedCode(); }); - describe('`console.log` statements', ()=> { + describe('`console.log` statements', () => { const statementRegExp1: RegExp = getStatementRegExp('0x1'); const statementRegExp2: RegExp = getStatementRegExp('0x2'); const statementRegExp3: RegExp = getStatementRegExp('0x3'); @@ -177,7 +172,8 @@ describe('BlockStatementControlFlowTransformer', function () { }); describe('switch-case map', () => { - const switchCaseMapVariableRegExp: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\)/; + const switchCaseMapVariableRegExp: RegExp = + /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\)/; const switchCaseMapStringRegExp: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *\{'.*' *: *'(.*)'\};/; const expectedSwitchCasesSequence: string[] = ['0', '1', '2', '3', '4']; @@ -207,132 +203,119 @@ describe('BlockStatementControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/one-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); describe('Variant #4: block statement contain variable declaration with `const` kind', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *\{ *const _0x([a-f0-9]){4,6} *= *0x1; *console\['log'\]\(0x1\);/; + const statementRegExp: RegExp = + /^\(function *\( *\) *\{ *const _0x([a-f0-9]){4,6} *= *0x1; *console\['log'\]\(0x1\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/const-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); describe('Variant #5: block statement contain variable declaration with `let` kind', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *\{ *let _0x([a-f0-9]){4,6} *= *0x1; *console\['log'\]\(0x1\);/; + const statementRegExp: RegExp = + /^\(function *\( *\) *\{ *let _0x([a-f0-9]){4,6} *= *0x1; *console\['log'\]\(0x1\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/let-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); describe('Variant #6: block statement contain break statement #1', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *break; *console\['log'\]\(0x1\);/; + const statementRegExp: RegExp = + /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *break; *console\['log'\]\(0x1\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/break-statement-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); describe('Variant #7: block statement contain break statement #2', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *if *\(!!\[\]\) *\{ *break; *\} *console\['log'\]\(0x1\);/; + const statementRegExp: RegExp = + /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *if *\(!!\[\]\) *\{ *break; *\} *console\['log'\]\(0x1\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/break-statement-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); describe('Variant #8: block statement contain break statement #3', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *if *\(!!\[\]\) *break; *console\['log'\]\(0x1\);/; + const statementRegExp: RegExp = + /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *if *\(!!\[\]\) *break; *console\['log'\]\(0x1\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/break-statement-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); @@ -342,20 +325,18 @@ describe('BlockStatementControlFlowTransformer', function () { const switchCaseLengthRegExp: RegExp = /case *'[0-5]': *console\['log'\]\(0x[0-6]\);/g; const expectedSwitchCaseLength: number = 5; - let obfuscatedCode: string, - switchCaseLength: number; + let obfuscatedCode: string, switchCaseLength: number; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/break-statement-inside-while-statement-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/break-statement-inside-while-statement-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); switchCaseLength = obfuscatedCode.match(switchCaseLengthRegExp)!.length; }); @@ -373,20 +354,18 @@ describe('BlockStatementControlFlowTransformer', function () { const switchCaseLengthRegExp: RegExp = /case *'[0-5]': *console\['log'\]\(0x[0-6]\);/g; const expectedSwitchCaseLength: number = 5; - let obfuscatedCode: string, - switchCaseLength: number; + let obfuscatedCode: string, switchCaseLength: number; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/break-statement-inside-while-statement-2.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/break-statement-inside-while-statement-2.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); switchCaseLength = obfuscatedCode.match(switchCaseLengthRegExp)!.length; }); @@ -400,70 +379,64 @@ describe('BlockStatementControlFlowTransformer', function () { }); describe('Variant #11: block statement contain continue statement #1', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *continue; *console\['log'\]\(0x1\);/; + const statementRegExp: RegExp = + /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *continue; *console\['log'\]\(0x1\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/continue-statement-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); describe('Variant #12: block statement contain continue statement #2', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *if *\(!!\[\]\) *\{ *continue; *\} *console\['log'\]\(0x1\);/; + const statementRegExp: RegExp = + /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *if *\(!!\[\]\) *\{ *continue; *\} *console\['log'\]\(0x1\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/continue-statement-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); describe('Variant #13: block statement contain continue statement #3', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *if *\(!!\[\]\) *continue; *console\['log'\]\(0x1\);/; + const statementRegExp: RegExp = + /^\(function *\( *\) *\{ *while *\(!!\[\]\) *\{ *if *\(!!\[\]\) *continue; *console\['log'\]\(0x1\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/continue-statement-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); @@ -473,20 +446,18 @@ describe('BlockStatementControlFlowTransformer', function () { const switchCaseLengthRegExp: RegExp = /case *'[0-5]': *console\['log'\]\(0x[0-6]\);/g; const expectedSwitchCaseLength: number = 5; - let obfuscatedCode: string, - switchCaseLength: number; + let obfuscatedCode: string, switchCaseLength: number; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/continue-statement-inside-while-statement-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/continue-statement-inside-while-statement-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); switchCaseLength = obfuscatedCode.match(switchCaseLengthRegExp)!.length; }); @@ -504,20 +475,18 @@ describe('BlockStatementControlFlowTransformer', function () { const switchCaseLengthRegExp: RegExp = /case *'[0-5]': *console\['log'\]\(0x[0-6]\);/g; const expectedSwitchCaseLength: number = 5; - let obfuscatedCode: string, - switchCaseLength: number; + let obfuscatedCode: string, switchCaseLength: number; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/continue-statement-inside-while-statement-2.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/continue-statement-inside-while-statement-2.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); switchCaseLength = obfuscatedCode.match(switchCaseLengthRegExp)!.length; }); @@ -531,47 +500,43 @@ describe('BlockStatementControlFlowTransformer', function () { }); describe('Variant #16: block statement contain function declaration', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *\{ *function *_0x([a-f0-9]){4,6} *\( *\) *\{ *\} *console\['log'\]\(0x1\);/ + const statementRegExp: RegExp = + /^\(function *\( *\) *\{ *function *_0x([a-f0-9]){4,6} *\( *\) *\{ *\} *console\['log'\]\(0x1\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); describe('Variant #17: block statement contain class declaration', () => { - const statementRegExp: RegExp = /^\(function *\( *\) *{ * *class *_0x([a-f0-9]){4,6} *{.*?} *}.*class *_0x([a-f0-9]){4,6} *{.*?} *}.*class *_0x([a-f0-9]){4,6} *{.*?} *}/; + const statementRegExp: RegExp = + /^\(function *\( *\) *{ * *class *_0x([a-f0-9]){4,6} *{.*?} *}.*class *_0x([a-f0-9]){4,6} *{.*?} *}.*class *_0x([a-f0-9]){4,6} *{.*?} *}/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/class-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t transform block statement', () => { + it("shouldn't transform block statement", () => { assert.match(obfuscatedCode, statementRegExp); }); }); @@ -585,27 +550,19 @@ describe('BlockStatementControlFlowTransformer', function () { const regExp1: RegExp = /switch *\(_0x([a-f0-9]){4,6}\[_0x([a-f0-9]){4,6}\+\+\]\) *\{/g; const regExp2: RegExp = /\(function *\( *\) *\{ *console\['log'\]\(0x1\);/g; - let transformedStatementPercentage: number, - untouchedStatementPercentage: number; + let transformedStatementPercentage: number, untouchedStatementPercentage: number; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code.repeat(samples), - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: controlFlowFlatteningThreshold, - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code.repeat(samples), { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: controlFlowFlatteningThreshold + }).getObfuscatedCode(); - const transformedStatementMatchesLength: number = obfuscatedCode - .match(regExp1)! - .length; - const untouchedStatementMatchesLength: number = obfuscatedCode - .match(regExp2)! - .length; + const transformedStatementMatchesLength: number = obfuscatedCode.match(regExp1)!.length; + const untouchedStatementMatchesLength: number = obfuscatedCode.match(regExp2)!.length; transformedStatementPercentage = transformedStatementMatchesLength / samples; untouchedStatementPercentage = untouchedStatementMatchesLength / samples; @@ -626,20 +583,16 @@ describe('BlockStatementControlFlowTransformer', function () { const returnStatementRegExp: RegExp = /case *'[0-5]': *return; *(case|})/; const expectedSwitchCaseLength: number = 5; - let obfuscatedCode: string, - switchCaseLength: number; + let obfuscatedCode: string, switchCaseLength: number; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/no-unreachable-code-warning.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); switchCaseLength = obfuscatedCode.match(switchCaseLengthRegExp)!.length; }); @@ -663,18 +616,16 @@ describe('BlockStatementControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); describe('switch-case map', () => { - const switchCaseMapVariableRegExp: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\);/; + const switchCaseMapVariableRegExp: RegExp = + /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\);/; const switchCaseMapIndexVariableRegExp: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *0x0;/; const switchCaseMapStringRegExp: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *\{'.*' *: *'(.*)'\};/; const expectedSwitchCasesSequence: string[] = ['0', '1', '2', '3', '4']; @@ -705,20 +656,20 @@ describe('BlockStatementControlFlowTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/prevailing-kind-of-variables-const.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); describe('switch-case map', () => { - const switchCaseMapVariableRegExp: RegExp = /const _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\);/; + const switchCaseMapVariableRegExp: RegExp = + /const _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\);/; const switchCaseMapIndexVariableRegExp: RegExp = /let _0x(?:[a-f0-9]){4,6} *= *0x0;/; const switchCaseMapStringRegExp: RegExp = /const _0x(?:[a-f0-9]){4,6} *= *\{'.*' *: *'(.*)'\};/; const expectedSwitchCasesSequence: string[] = ['0', '1', '2', '3', '4']; @@ -751,18 +702,16 @@ describe('BlockStatementControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); describe('switch-case map', () => { - const switchCaseMapVariableRegExp: RegExp = /const _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\)/; + const switchCaseMapVariableRegExp: RegExp = + /const _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\)/; const switchCaseMapIndexVariableRegExp: RegExp = /let _0x(?:[a-f0-9]){4,6} *= *0x0;/; const switchCaseMapStringRegExp: RegExp = /const _0x(?:[a-f0-9]){4,6} *= *\{'.*' *: *'(.*)'\};/; const expectedSwitchCasesSequence: string[] = ['0', '1', '2', '3', '4']; diff --git a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/BinaryExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/BinaryExpressionControlFlowReplacer.spec.ts index 1886150dd..b66753674 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/BinaryExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/BinaryExpressionControlFlowReplacer.spec.ts @@ -22,14 +22,11 @@ describe('BinaryExpressionControlFlowReplacer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should replace binary expression node with call to control flow storage node', () => { @@ -65,14 +62,11 @@ describe('BinaryExpressionControlFlowReplacer', function () { equalsValue: number = 0; for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); firstMatchArray = obfuscatedCode.match(controlFlowStorageCallRegExp1); secondMatchArray = obfuscatedCode.match(controlFlowStorageCallRegExp2); diff --git a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts index a1d0699d7..ea3b91a2f 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts @@ -22,14 +22,11 @@ describe('CallExpressionControlFlowReplacer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should replace call expression node with call to control flow storage node', () => { @@ -65,14 +62,11 @@ describe('CallExpressionControlFlowReplacer', function () { equalsValue: number = 0; for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); firstMatchArray = obfuscatedCode.match(controlFlowStorageCallRegExp1); secondMatchArray = obfuscatedCode.match(controlFlowStorageCallRegExp2); @@ -104,26 +98,21 @@ describe('CallExpressionControlFlowReplacer', function () { }); describe('Variant #3 - call expression callee is member expression node', () => { - const regExp: RegExp = new RegExp( - `var ${variableMatch} *= *${variableMatch}\\['sum'\\]\\(0x1, *0x2\\);` - ); + const regExp: RegExp = new RegExp(`var ${variableMatch} *= *${variableMatch}\\['sum'\\]\\(0x1, *0x2\\);`); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t replace call expression node with call to control flow storage node', () => { + it("shouldn't replace call expression node with call to control flow storage node", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -132,25 +121,24 @@ describe('CallExpressionControlFlowReplacer', function () { const controlFlowStorageCallRegExp: RegExp = new RegExp( `${variableMatch}\\['\\w{5}']\\(${variableMatch}, *\\.\\.\\.${variableMatch}, *${variableMatch}\\);` ); - const controlFlowStorageNodeRegExp: RegExp = new RegExp(`` + - `'\\w{5}' *: *function *\\(${variableMatch}, *\.\.\.${variableMatch}\\) *\\{` + + const controlFlowStorageNodeRegExp: RegExp = new RegExp( + `` + + `'\\w{5}' *: *function *\\(${variableMatch}, *\.\.\.${variableMatch}\\) *\\{` + `return *${variableMatch}\\(\.\.\.${variableMatch}\\);` + - `\\}` + - ``); + `\\}` + + `` + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/rest-as-start-call-argument.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should replace call expression node with call to control flow storage node', () => { @@ -166,25 +154,24 @@ describe('CallExpressionControlFlowReplacer', function () { const controlFlowStorageCallRegExp: RegExp = new RegExp( `${variableMatch}\\['\\w{5}']\\(${variableMatch}, *${variableMatch}, *\\.\\.\\.${variableMatch}, *${variableMatch}\\);` ); - const controlFlowStorageNodeRegExp: RegExp = new RegExp(`` + - `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}, *\.\.\.${variableMatch}\\) *\\{` + + const controlFlowStorageNodeRegExp: RegExp = new RegExp( + `` + + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}, *\.\.\.${variableMatch}\\) *\\{` + `return *${variableMatch}\\(${variableMatch}, *\.\.\.${variableMatch}\\);` + - `\\}` + - ``); + `\\}` + + `` + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/rest-as-middle-call-argument.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should replace call expression node with call to control flow storage node', () => { @@ -200,25 +187,24 @@ describe('CallExpressionControlFlowReplacer', function () { const controlFlowStorageCallRegExp: RegExp = new RegExp( `${variableMatch}\\['\\w{5}']\\(${variableMatch}, *${variableMatch}, *\\.\\.\\.${variableMatch}\\);` ); - const controlFlowStorageNodeRegExp: RegExp = new RegExp(`` + - `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}, *\.\.\.${variableMatch}\\) *\\{` + - `return *${variableMatch}\\(${variableMatch}, *\.\.\.${variableMatch}\\);` + - `\\}` + - ``); + const controlFlowStorageNodeRegExp: RegExp = new RegExp( + `` + + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}, *\.\.\.${variableMatch}\\) *\\{` + + `return *${variableMatch}\\(${variableMatch}, *\.\.\.${variableMatch}\\);` + + `\\}` + + `` + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/rest-as-last-call-argument.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should replace call expression node with call to control flow storage node', () => { @@ -232,36 +218,35 @@ describe('CallExpressionControlFlowReplacer', function () { describe('Variant #7 - keep optional chaining operator', () => { const controlFlowStorageCallRegExp: RegExp = new RegExp( - `${variableMatch}\\['\\w{5}']\\(${variableMatch}, *0x1, *0x2\\);` + `${variableMatch}\\['\\w{5}']\\(${variableMatch}, *0x1, *0x2\\);` ); - const controlFlowStorageNodeRegExp: RegExp = new RegExp(`` + - `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}, *${variableMatch}\\) *\\{` + + const controlFlowStorageNodeRegExp: RegExp = new RegExp( + `` + + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}, *${variableMatch}\\) *\\{` + `return *${variableMatch}\\?\\.\\(${variableMatch}, *${variableMatch}\\);` + - `\\}` + - ``); + `\\}` + + `` + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/optional-chaining-call.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should replace call expression node with call to control flow storage node', () => { - assert.match(obfuscatedCode, controlFlowStorageCallRegExp); + assert.match(obfuscatedCode, controlFlowStorageCallRegExp); }); it('should wrap call expression into chain expression', () => { - assert.match(obfuscatedCode, controlFlowStorageNodeRegExp); + assert.match(obfuscatedCode, controlFlowStorageNodeRegExp); }); }); - }); + }); }); diff --git a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/LogicalExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/LogicalExpressionControlFlowReplacer.spec.ts index 4ad5ccd5f..915891121 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/LogicalExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/LogicalExpressionControlFlowReplacer.spec.ts @@ -22,14 +22,11 @@ describe('LogicalExpressionControlFlowReplacer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should replace logical expression node with call to control flow storage node', () => { @@ -65,14 +62,11 @@ describe('LogicalExpressionControlFlowReplacer', function () { equalsValue: number = 0; for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); firstMatchArray = obfuscatedCode.match(controlFlowStorageCallRegExp1); secondMatchArray = obfuscatedCode.match(controlFlowStorageCallRegExp2); @@ -113,14 +107,11 @@ describe('LogicalExpressionControlFlowReplacer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should replace logical unary expression with call to control flow storage node', () => { @@ -138,17 +129,14 @@ describe('LogicalExpressionControlFlowReplacer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prohibited-nodes.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: .1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 0.1 + }).getObfuscatedCode(); }); - it('shouldn\'t replace prohibited expression nodes', () => { + it("shouldn't replace prohibited expression nodes", () => { assert.match(obfuscatedCode, regExp); }); }); diff --git a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/string-litertal-control-flow-replacer/StringLiteralControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/string-litertal-control-flow-replacer/StringLiteralControlFlowReplacer.spec.ts index 4ea956aa0..6a7aa4e56 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/string-litertal-control-flow-replacer/StringLiteralControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/string-litertal-control-flow-replacer/StringLiteralControlFlowReplacer.spec.ts @@ -12,7 +12,6 @@ describe('StringLiteralControlFlowReplacer', () => { const variableMatch: string = '_0x([a-f0-9]){4,6}'; describe('Variant #1 - base behavior', () => { - const controlFlowStorageStringLiteralRegExp: RegExp = new RegExp( `var ${variableMatch} *= *\\{'\\w{5}' *: *'test'\\};` ); @@ -25,14 +24,11 @@ describe('StringLiteralControlFlowReplacer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should add string literal node as property of control flow storage node', () => { @@ -51,20 +47,19 @@ describe('StringLiteralControlFlowReplacer', () => { let storageCallsMatchesCount: number; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/same-storage-key-for-same-string-values.js'); - - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - compact: false, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/same-storage-key-for-same-string-values.js' + ); + + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + compact: false, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); const storageKeyMatch = getRegExpMatch(obfuscatedCode, storageKeyRegExp); - const storageCallsRegExp = new RegExp(`${variableMatch}\\[\'${storageKeyMatch}\']`, 'g') + const storageCallsRegExp = new RegExp(`${variableMatch}\\[\'${storageKeyMatch}\']`, 'g'); storageCallsMatchesCount = obfuscatedCode.match(storageCallsRegExp)?.length ?? 0; }); diff --git a/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts index 55dc0b45b..539e9a397 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts @@ -10,20 +10,22 @@ describe('FunctionControlFlowTransformer', function () { this.timeout(100000); const variableMatch: string = '_0x([a-f0-9]){4,6}'; - const rootControlFlowStorageNodeMatch: string = `` + + const rootControlFlowStorageNodeMatch: string = + `` + `var ${variableMatch} *= *\\{` + - `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}\\) *\\{` + - `return *${variableMatch} *\\+ *${variableMatch};` + - `\\}` + + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `return *${variableMatch} *\\+ *${variableMatch};` + + `\\}` + `\\};` + - ``; - const innerControlFlowStorageNodeMatch: string = `` + + ``; + const innerControlFlowStorageNodeMatch: string = + `` + `var ${variableMatch} *= *\\{` + - `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}\\) *\\{` + - `return *${variableMatch}\\['\\w{5}'\\]\\(${variableMatch}, *${variableMatch}\\);` + - `\\}` + + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `return *${variableMatch}\\['\\w{5}'\\]\\(${variableMatch}, *${variableMatch}\\);` + + `\\}` + `\\};` + - ``; + ``; describe('transformNode', () => { describe('Variant #1 - single `control flow storage` node with single item', () => { @@ -34,14 +36,11 @@ describe('FunctionControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should add `control flow storage` node to the obfuscated code', () => { @@ -55,10 +54,7 @@ describe('FunctionControlFlowTransformer', function () { const samplesCount: number = 1000; const delta: number = 0.1; - const regExp1: RegExp = new RegExp( - `\\(function\\(\\) *\\{ *${rootControlFlowStorageNodeMatch}`, - 'g' - ); + const regExp1: RegExp = new RegExp(`\\(function\\(\\) *\\{ *${rootControlFlowStorageNodeMatch}`, 'g'); const regExp2: RegExp = new RegExp( `function *${variableMatch} *\\(\\) *\\{ *${innerControlFlowStorageNodeMatch}`, 'g' @@ -73,14 +69,11 @@ describe('FunctionControlFlowTransformer', function () { totalValue: number = 0; for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); if (regExp1.test(obfuscatedCode)) { totalValue += obfuscatedCode.match(regExp1)!.length; @@ -103,12 +96,12 @@ describe('FunctionControlFlowTransformer', function () { const regexp: RegExp = new RegExp( `var ${variableMatch} *= *\\{` + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}\\) *\\{` + - `return *${variableMatch} *\\+ *${variableMatch};` + + `return *${variableMatch} *\\+ *${variableMatch};` + `\\}, *` + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}\\) *\\{` + - `return *${variableMatch} *- *${variableMatch};` + + `return *${variableMatch} *- *${variableMatch};` + `\\}` + - `\\};` + `\\};` ); let obfuscatedCode: string; @@ -116,14 +109,11 @@ describe('FunctionControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/multiple-items.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should add `control flow storage` node with multiple items to the obfuscated code', () => { @@ -139,17 +129,14 @@ describe('FunctionControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/root-block-scope-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('should\'t add control flow storage node', () => { + it("should't add control flow storage node", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -161,9 +148,9 @@ describe('FunctionControlFlowTransformer', function () { const regExp: RegExp = new RegExp( `var [a-zA-Z]{6} *= *\\{` + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}\\) *\\{` + - `return *${variableMatch} *\\+ *${variableMatch};` + + `return *${variableMatch} *\\+ *${variableMatch};` + `\\}` + - `\\};` + `\\};` ); const code: string = readFileAsString(__dirname + '/fixtures/root-block-scope-2.js'); @@ -172,15 +159,11 @@ describe('FunctionControlFlowTransformer', function () { before(() => { for (let i = 0; i < samplesCount; i++) { - - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); if (regExp.test(obfuscatedCode)) { totalValue++; @@ -188,7 +171,7 @@ describe('FunctionControlFlowTransformer', function () { } }); - it('should\'t add control flow storage node to the root block scope', () => { + it("should't add control flow storage node to the root block scope", () => { assert.equal(totalValue, expectedValue); }); }); @@ -202,21 +185,18 @@ describe('FunctionControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/zero-threshold.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 0 + }).getObfuscatedCode(); }); - it('shouldn\'t add call to control flow storage node to the obfuscated code', () => { + it("shouldn't add call to control flow storage node to the obfuscated code", () => { assert.match(obfuscatedCode, regexp); }); - it('shouldn\'t add `control flow storage` node to the obfuscated code', () => { + it("shouldn't add `control flow storage` node to the obfuscated code", () => { assert.notMatch(obfuscatedCode, controlFlowStorageRegExp); }); }); @@ -228,16 +208,15 @@ describe('FunctionControlFlowTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/arrow-function-expression-with-body.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/arrow-function-expression-with-body.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should add `control flow storage` node to the obfuscated code', () => { @@ -251,19 +230,18 @@ describe('FunctionControlFlowTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/arrow-function-expression-without-body.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/arrow-function-expression-without-body.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t add `control flow storage` node to the obfuscated code', () => { + it("shouldn't add `control flow storage` node to the obfuscated code", () => { assert.match(obfuscatedCode, regexp); }); }); @@ -278,14 +256,11 @@ describe('FunctionControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should use correct kind of variables for `control flow storage`', () => { @@ -299,16 +274,15 @@ describe('FunctionControlFlowTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/prevailing-kind-of-variables-const.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should use correct kind of variables for `control flow storage`', () => { @@ -324,14 +298,11 @@ describe('FunctionControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should use correct kind of variables for `control flow storage`', () => { diff --git a/test/functional-tests/node-transformers/control-flow-transformers/string-array-control-flow-transformer/StringArrayControlFlowTransformer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/string-array-control-flow-transformer/StringArrayControlFlowTransformer.spec.ts index 4e65fa2ea..c0b801bd8 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/string-array-control-flow-transformer/StringArrayControlFlowTransformer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/string-array-control-flow-transformer/StringArrayControlFlowTransformer.spec.ts @@ -1,11 +1,7 @@ import { assert } from 'chai'; -import { - IdentifierNamesGenerator -} from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator'; -import { - StringArrayIndexesType -} from '../../../../../src/enums/node-transformers/string-array-transformers/StringArrayIndexesType'; +import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator'; +import { StringArrayIndexesType } from '../../../../../src/enums/node-transformers/string-array-transformers/StringArrayIndexesType'; import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; @@ -22,10 +18,11 @@ describe('StringArrayControlFlowTransformer', function () { describe('Variant #1 - hexadecimal number generator', () => { const stringArrayVariableMatch: string = '_0x([a-f0-9]){4}'; - const controlFlowStorageMatch: string = `var ${hexadecimalVariableMatch} *= *\\{` + + const controlFlowStorageMatch: string = + `var ${hexadecimalVariableMatch} *= *\\{` + `${hexadecimalVariableMatch} *: *0x0, *` + `${hexadecimalVariableMatch} *: *0x1 *` + - `\\};`; + `\\};`; const controlFlowStorageCallMatch: string = `${stringArrayVariableMatch}\\(${hexadecimalVariableMatch}.${hexadecimalVariableMatch}\\)`; describe('Variant #1 - positive cases', () => { @@ -41,17 +38,14 @@ describe('StringArrayControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumber], - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumber], + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); }); it('should add `control flow storage` node to the obfuscated code', () => { @@ -68,7 +62,7 @@ describe('StringArrayControlFlowTransformer', function () { `var ${hexadecimalVariableMatch} *= *\\{` + `${hexadecimalVariableMatch} *: *'0x0', *` + `${hexadecimalVariableMatch} *: *'0x1' *` + - `\\};` + `\\};` ); const controlFlowStorageCallRegExp: RegExp = new RegExp( @@ -80,17 +74,14 @@ describe('StringArrayControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumericString], - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumericString], + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); }); it('should add `control flow storage` node to the obfuscated code', () => { @@ -108,11 +99,9 @@ describe('StringArrayControlFlowTransformer', function () { const samplesCount: number = 1000; const delta: number = 0.1; - const regExp1: RegExp = new RegExp( - `\\(function\\(\\) *\\{ *${controlFlowStorageMatch}`, - ); + const regExp1: RegExp = new RegExp(`\\(function\\(\\) *\\{ *${controlFlowStorageMatch}`); const regExp2: RegExp = new RegExp( - `function *${hexadecimalVariableMatch} *\\(${hexadecimalVariableMatch}\\) *\\{ *${controlFlowStorageMatch}`, + `function *${hexadecimalVariableMatch} *\\(${hexadecimalVariableMatch}\\) *\\{ *${controlFlowStorageMatch}` ); let appendToScopeThreshold1: number = 0; @@ -126,16 +115,13 @@ describe('StringArrayControlFlowTransformer', function () { totalValue2: number = 0; for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); if (!regExp1.test(obfuscatedCode) && !regExp2.test(obfuscatedCode)) { console.log(obfuscatedCode); @@ -167,7 +153,7 @@ describe('StringArrayControlFlowTransformer', function () { `${hexadecimalVariableMatch} *: *0x1, *` + `${hexadecimalVariableMatch} *: *0x2, *` + `${hexadecimalVariableMatch} *: *0x3 *` + - `\\};` + `\\};` ); let obfuscatedCode: string; @@ -175,16 +161,13 @@ describe('StringArrayControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/multiple-items.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); }); it('should add `control flow storage` node with multiple items to the obfuscated code', () => { @@ -197,12 +180,11 @@ describe('StringArrayControlFlowTransformer', function () { `var ${hexadecimalVariableMatch} *= *\\{` + `${hexadecimalVariableMatch} *: *0x0, *` + `${hexadecimalVariableMatch} *: *0x1 *` + - `\\}; *` + - `var ${hexadecimalVariableMatch} *= *\\{` + - + `\\}; *` + + `var ${hexadecimalVariableMatch} *= *\\{` + `${hexadecimalVariableMatch} *: *0x2, *` + `${hexadecimalVariableMatch} *: *0x3 *` + - `\\};` + `\\};` ); let obfuscatedCode: string; @@ -210,16 +192,13 @@ describe('StringArrayControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/multiple-storages-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); console.log(obfuscatedCode); }); @@ -242,20 +221,17 @@ describe('StringArrayControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/root-block-scope-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); console.log(obfuscatedCode); }); - it('shouldn\'t add control flow storage node', () => { + it("shouldn't add control flow storage node", () => { assert.notMatch(obfuscatedCode, controlFlowStorageRegExp); assert.match(obfuscatedCode, stringArrayCallsRegExp); }); @@ -272,21 +248,18 @@ describe('StringArrayControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 0 + }).getObfuscatedCode(); console.log(obfuscatedCode); }); - it('shouldn\'t add control flow storage node', () => { + it("shouldn't add control flow storage node", () => { assert.notMatch(obfuscatedCode, controlFlowStorageRegExp); assert.match(obfuscatedCode, stringArrayCallsRegExp); }); @@ -297,31 +270,23 @@ describe('StringArrayControlFlowTransformer', function () { describe('Variant #2 - mangled number generator', () => { describe('Variant #1 - single control flow storage', () => { const controlFlowStorageRegExp: RegExp = new RegExp( - `var d *= *\\{` + - `c *: *0x0, *` + - `e *: *0x1 *` + - `\\};` - ); - const controlFlowStorageCallRegExp: RegExp = new RegExp( - `var c *= *b\\(d.c\\) *\\+ *b\\(d.e\\);` + `var d *= *\\{` + `c *: *0x0, *` + `e *: *0x1 *` + `\\};` ); + const controlFlowStorageCallRegExp: RegExp = new RegExp(`var c *= *b\\(d.c\\) *\\+ *b\\(d.e\\);`); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); }); it('should add `control flow storage` node to the obfuscated code', () => { @@ -335,41 +300,28 @@ describe('StringArrayControlFlowTransformer', function () { describe('Variant #2 - multiple control flow storages', () => { const controlFlowStorageRegExp1: RegExp = new RegExp( - `var d *= *\\{` + - `c *: *0x0, *` + - `e *: *0x1 *` + - `\\};` - ); - const controlFlowStorageCallRegExp1: RegExp = new RegExp( - `var c *= *b\\(d.c\\) *\\+ *b\\(d.e\\);` + `var d *= *\\{` + `c *: *0x0, *` + `e *: *0x1 *` + `\\};` ); + const controlFlowStorageCallRegExp1: RegExp = new RegExp(`var c *= *b\\(d.c\\) *\\+ *b\\(d.e\\);`); const controlFlowStorageRegExp2: RegExp = new RegExp( - `var e *= *\\{` + - `c *: *0x0, *` + - `f *: *0x1 *` + - `\\};` - ); - const controlFlowStorageCallRegExp2: RegExp = new RegExp( - `var c *= *b\\(e.c\\) *\\+ *b\\(e.f\\);` + `var e *= *\\{` + `c *: *0x0, *` + `f *: *0x1 *` + `\\};` ); + const controlFlowStorageCallRegExp2: RegExp = new RegExp(`var c *= *b\\(e.c\\) *\\+ *b\\(e.f\\);`); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/multiple-storages-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); }); it('Match #1: should add `control flow storage` №1 and its calls to the obfuscated code', () => { @@ -393,16 +345,13 @@ describe('StringArrayControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); }); it('should use correct kind of variables for `control flow storage`', () => { @@ -416,18 +365,17 @@ describe('StringArrayControlFlowTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/prevailing-kind-of-variables-const.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); }); it('should use correct kind of variables for `control flow storage`', () => { @@ -443,16 +391,13 @@ describe('StringArrayControlFlowTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1 + }).getObfuscatedCode(); }); it('should use correct kind of variables for `control flow storage`', () => { diff --git a/test/functional-tests/node-transformers/converting-transformers/boolean-literal-transformer/BooleanLiteralTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/boolean-literal-transformer/BooleanLiteralTransformer.spec.ts index dfaf962b9..de8f025bf 100644 --- a/test/functional-tests/node-transformers/converting-transformers/boolean-literal-transformer/BooleanLiteralTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/boolean-literal-transformer/BooleanLiteralTransformer.spec.ts @@ -15,14 +15,11 @@ describe('BooleanLiteralTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/true-value.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should transform boolean literal node', () => { @@ -38,14 +35,11 @@ describe('BooleanLiteralTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/false-value.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should transform boolean literal node', () => { diff --git a/test/functional-tests/node-transformers/converting-transformers/class-field-transformer/ClassFieldTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/class-field-transformer/ClassFieldTransformer.spec.ts index d39281cd7..7dae5624e 100644 --- a/test/functional-tests/node-transformers/converting-transformers/class-field-transformer/ClassFieldTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/class-field-transformer/ClassFieldTransformer.spec.ts @@ -18,12 +18,9 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should replace method definition node `key` property with square brackets literal', () => { @@ -40,22 +37,19 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add method definition node `key` property to string array', () => { - assert.match(obfuscatedCode, stringArrayRegExp); + assert.match(obfuscatedCode, stringArrayRegExp); }); it('should replace method definition node `key` property with call to string array', () => { - assert.match(obfuscatedCode, stringArrayCallRegExp); + assert.match(obfuscatedCode, stringArrayCallRegExp); }); }); @@ -67,15 +61,12 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('shouldn\'t transform method definition node with `constructor` key', () => { + it("shouldn't transform method definition node with `constructor` key", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -90,12 +81,9 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/literal-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should replace method definition node `key` property with square brackets literal', () => { @@ -112,22 +100,19 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/literal-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add method definition node `key` property to string array', () => { - assert.match(obfuscatedCode, stringArrayRegExp); + assert.match(obfuscatedCode, stringArrayRegExp); }); it('should replace method definition node `key` property with call to string array', () => { - assert.match(obfuscatedCode, stringArrayCallRegExp); + assert.match(obfuscatedCode, stringArrayCallRegExp); }); }); @@ -139,15 +124,12 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/literal-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('shouldn\'t transform method definition node with `constructor` key', () => { + it("shouldn't transform method definition node with `constructor` key", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -162,12 +144,9 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/async-get-method.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should rename class declaration name', () => { @@ -190,12 +169,9 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should replace property definition node `key` property with square brackets literal', () => { @@ -212,22 +188,19 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add property definition node `key` property to string array', () => { - assert.match(obfuscatedCode, stringArrayRegExp); + assert.match(obfuscatedCode, stringArrayRegExp); }); it('should replace property definition node `key` property with call to string array', () => { - assert.match(obfuscatedCode, stringArrayCallRegExp); + assert.match(obfuscatedCode, stringArrayCallRegExp); }); }); }); @@ -241,12 +214,9 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/literal-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should replace property definition node `key` property with square brackets literal', () => { @@ -263,22 +233,19 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/literal-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add property definition node `key` property to string array', () => { - assert.match(obfuscatedCode, stringArrayRegExp); + assert.match(obfuscatedCode, stringArrayRegExp); }); it('should replace property definition node `key` property with call to string array', () => { - assert.match(obfuscatedCode, stringArrayCallRegExp); + assert.match(obfuscatedCode, stringArrayCallRegExp); }); }); }); @@ -292,12 +259,9 @@ describe('ClassFieldTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/async-get-method.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should rename class declaration name', () => { diff --git a/test/functional-tests/node-transformers/converting-transformers/export-specifier-transformer/ExportSpecifierTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/export-specifier-transformer/ExportSpecifierTransformer.spec.ts index 6fd1abb14..dce42a8d2 100644 --- a/test/functional-tests/node-transformers/converting-transformers/export-specifier-transformer/ExportSpecifierTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/export-specifier-transformer/ExportSpecifierTransformer.spec.ts @@ -10,8 +10,7 @@ describe('ExportSpecifierTransformer', () => { describe('Variant #1: exported constant', () => { describe('Variant #1:`renameGlobals` option is enabled', () => { const regExp: RegExp = new RegExp( - 'const _0x([a-f0-9]){4,6} *= *0x1; *' + - 'export *{_0x([a-f0-9]){4,6} as foo};' + 'const _0x([a-f0-9]){4,6} *= *0x1; *' + 'export *{_0x([a-f0-9]){4,6} as foo};' ); let obfuscatedCode: string; @@ -19,13 +18,10 @@ describe('ExportSpecifierTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/exported-constant.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('should transform export specifier node', () => { @@ -34,23 +30,17 @@ describe('ExportSpecifierTransformer', () => { }); describe('Variant #2: `renameGlobals` option is disabled', () => { - const regExp: RegExp = new RegExp( - 'const foo *= *0x1; *' + - 'export *{foo};' - ); + const regExp: RegExp = new RegExp('const foo *= *0x1; *' + 'export *{foo};'); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/exported-constant.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: false + }).getObfuscatedCode(); }); it('should not transform export specifier node', () => { @@ -62,8 +52,7 @@ describe('ExportSpecifierTransformer', () => { describe('Variant #2: exported import', () => { describe('Variant #1:`renameGlobals` option is enabled', () => { const regExp: RegExp = new RegExp( - 'import _0x([a-f0-9]){4,6} from *\'./bar\'; *' + - 'export *{_0x([a-f0-9]){4,6} as foo};' + "import _0x([a-f0-9]){4,6} from *'./bar'; *" + 'export *{_0x([a-f0-9]){4,6} as foo};' ); let obfuscatedCode: string; @@ -71,13 +60,10 @@ describe('ExportSpecifierTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/exported-import.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('should transform export specifier node', () => { @@ -87,8 +73,7 @@ describe('ExportSpecifierTransformer', () => { describe('Variant #2: `renameGlobals` option is disabled', () => { const regExp: RegExp = new RegExp( - 'import _0x([a-f0-9]){4,6} from *\'./bar\'; *' + - 'export *{_0x([a-f0-9]){4,6} as foo};' + "import _0x([a-f0-9]){4,6} from *'./bar'; *" + 'export *{_0x([a-f0-9]){4,6} as foo};' ); let obfuscatedCode: string; @@ -96,13 +81,10 @@ describe('ExportSpecifierTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/exported-import.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: false + }).getObfuscatedCode(); }); it('should transform export specifier node', () => { diff --git a/test/functional-tests/node-transformers/converting-transformers/member-expression-transformer/MemberExpressionTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/member-expression-transformer/MemberExpressionTransformer.spec.ts index 48b752b51..bfae1d6ce 100644 --- a/test/functional-tests/node-transformers/converting-transformers/member-expression-transformer/MemberExpressionTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/member-expression-transformer/MemberExpressionTransformer.spec.ts @@ -17,16 +17,13 @@ describe('MemberExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/dot-notation-call.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should replace member expression dot notation call with literal value', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); @@ -39,14 +36,11 @@ describe('MemberExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/dot-notation-call.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add member expression identifier to string array', () => { @@ -69,14 +63,11 @@ describe('MemberExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/square-brackets-call.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add member expression square brackets literal to string array', () => { @@ -96,12 +87,9 @@ describe('MemberExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/square-brackets-with-identifier-call.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should ignore square brackets call with identifier value', () => { diff --git a/test/functional-tests/node-transformers/converting-transformers/number-literal-transformer/NumberLiteralTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/number-literal-transformer/NumberLiteralTransformer.spec.ts index 9835d584a..9dfec6a7e 100644 --- a/test/functional-tests/node-transformers/converting-transformers/number-literal-transformer/NumberLiteralTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/number-literal-transformer/NumberLiteralTransformer.spec.ts @@ -15,14 +15,11 @@ describe('NumberLiteralTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/number-value.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should transform literal node', () => { @@ -38,14 +35,11 @@ describe('NumberLiteralTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/bigint-value.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should transform literal node', () => { diff --git a/test/functional-tests/node-transformers/converting-transformers/numbers-to-numerical-expressions-transformer/NumbersToNumericalExpressionsTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/numbers-to-numerical-expressions-transformer/NumbersToNumericalExpressionsTransformer.spec.ts index c5d1f426b..0a53304cd 100644 --- a/test/functional-tests/node-transformers/converting-transformers/numbers-to-numerical-expressions-transformer/NumbersToNumericalExpressionsTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/numbers-to-numerical-expressions-transformer/NumbersToNumericalExpressionsTransformer.spec.ts @@ -17,13 +17,10 @@ describe('NumbersToNumericalExpressionsTransformer', function () { before(() => { for (let i = initialNumber; i < lastNumber; i++) { const number: number = i; - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - `${number};`, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(`${number};`, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); const result: number = eval(obfuscatedCode); @@ -48,13 +45,10 @@ describe('NumbersToNumericalExpressionsTransformer', function () { before(() => { for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - `${number};`, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(`${number};`, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); const result: number = eval(obfuscatedCode); @@ -78,13 +72,10 @@ describe('NumbersToNumericalExpressionsTransformer', function () { before(() => { for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - `${number};`, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(`${number};`, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); const result: number = eval(obfuscatedCode); @@ -108,13 +99,10 @@ describe('NumbersToNumericalExpressionsTransformer', function () { before(() => { for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - `${number};`, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(`${number};`, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); const result: number = eval(obfuscatedCode); @@ -140,13 +128,10 @@ describe('NumbersToNumericalExpressionsTransformer', function () { before(() => { for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - `${number};`, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(`${number};`, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); const result: number = eval(obfuscatedCode); @@ -169,13 +154,10 @@ describe('NumbersToNumericalExpressionsTransformer', function () { let obfuscatedCode: string; before(() => { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - `${number};`, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(`${number};`, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); }); it('should not transform unsafe integer to expressions', () => { @@ -191,13 +173,10 @@ describe('NumbersToNumericalExpressionsTransformer', function () { before(() => { for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - `${number};`, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(`${number};`, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); const result: number = eval(obfuscatedCode); @@ -220,13 +199,10 @@ describe('NumbersToNumericalExpressionsTransformer', function () { let obfuscatedCode: string; before(() => { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - `${number};`, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(`${number};`, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); }); it('should not transform unsafe integer to expressions', () => { @@ -243,17 +219,14 @@ describe('NumbersToNumericalExpressionsTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/non-computed-object-key.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); }); it('should not replace non-computed object property literal with expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); @@ -265,17 +238,14 @@ describe('NumbersToNumericalExpressionsTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/member-expression.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - numbersToExpressions: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + numbersToExpressions: true + }).getObfuscatedCode(); }); it('should replace member expression with literal object with expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); diff --git a/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts index 5085de466..d261014a1 100644 --- a/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts @@ -13,11 +13,12 @@ describe('ObjectExpressionKeysTransformer', () => { describe('transformation of object keys', () => { describe('Variant #1: simple', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -25,56 +26,54 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: variable declaration without initialization', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + `${variableMatch} *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declaration-without-initialization.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declaration-without-initialization.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: return statement', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + `return *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -82,78 +81,76 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/return-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #4: object expression inside array expression', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + `var ${variableMatch} *= *\\[${variableMatch}];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/object-expression-inside-array-expression.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/object-expression-inside-array-expression.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #5: object expression inside call expression', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + `console\\['log']\\(${variableMatch}\\);` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/object-expression-inside-call-expression.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/object-expression-inside-call-expression.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #6: nested objects #1', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['baz'] *= *'bark';` + `var ${variableMatch} *= *{};` + @@ -162,7 +159,7 @@ describe('ObjectExpressionKeysTransformer', () => { `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['inner'] *= *${variableMatch};` + `var object *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -170,22 +167,20 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/nested-objects-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #7: nested objects #2', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['hawk'] *= *'geek';` + `var ${variableMatch} *= *{};` + @@ -197,7 +192,7 @@ describe('ObjectExpressionKeysTransformer', () => { `${variableMatch}\\['inner'] *= *${variableMatch};` + `${variableMatch}\\['ball'] *= *'door';` + `var object *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -205,22 +200,20 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/nested-objects-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #8: nested objects #3', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['hawk'] *= *'geek';` + `var ${variableMatch} *= *{};` + @@ -232,7 +225,7 @@ describe('ObjectExpressionKeysTransformer', () => { `${variableMatch}\\['inner'] *= *${variableMatch};` + `${variableMatch}\\['ball'] *= *'door';` + `return ${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -240,57 +233,55 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/nested-objects-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #9: correct integration with control flow flattening object #1', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['\\w{5}'] *= *function *\\(${variableMatch}, *${variableMatch}\\) *{` + - `return *${variableMatch} *\\+ *${variableMatch};` + + `return *${variableMatch} *\\+ *${variableMatch};` + `};` + `var ${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-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/integration-with-control-flow-flattening-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #10: correct integration with control flow flattening object #2', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['\\w{5}'] *= *function *\\(${variableMatch}, *${variableMatch}\\) *{` + - `return *${variableMatch} *\\+ *${variableMatch};` + + `return *${variableMatch} *\\+ *${variableMatch};` + `};` + `var ${variableMatch} *= *${variableMatch};` + `var ${variableMatch} *= *{};` + @@ -298,148 +289,146 @@ describe('ObjectExpressionKeysTransformer', () => { `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *0x2;` + `var ${variableMatch} *= *${variableMatch}\\['\\w{5}']\\(${variableMatch}\\['foo'], *${variableMatch}\\['bar']\\);` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/integration-with-control-flow-flattening-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/integration-with-control-flow-flattening-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #11: variable declarator object call inside other variable declarator', () => { describe('Variant #1', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'foo';` + `var ${variableMatch} *= *${variableMatch}, *` + `${variableMatch} *= *${variableMatch}\\['foo'];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-4.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarator-with-object-call-4.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'foo';` + `var ${variableMatch} *= *${variableMatch}, *` + `${variableMatch} *= *\\[${variableMatch}\\['foo']];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-5.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarator-with-object-call-5.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3', () => { - const match: string = `` + - `var ${variableMatch} *= *0x1, *${variableMatch} *= *{'foo' *: *${variableMatch}};` + - ``; + const match: string = + `` + `var ${variableMatch} *= *0x1, *${variableMatch} *= *{'foo' *: *${variableMatch}};` + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-6.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarator-with-object-call-6.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #12: assignment expression and member expression', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch}; *` + `var ${variableMatch} *= *{}; *` + `${variableMatch}\\['foo'] *= *'bar';` + `\\(${variableMatch} *= *${variableMatch}\\)\\['baz'] *= *${variableMatch}\\['foo'];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/assignment-expression-and-member-expression.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/assignment-expression-and-member-expression.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #13: should keep numeric object keys', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['0'] *= *'foo';` + `${variableMatch}\\['bar'] *= *'bar';` + `${variableMatch}\\['2'] *= *'baz';` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -447,27 +436,25 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/numeric-keys.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #14: template literal', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + `var foo *= *'' *\\+ *_0x[a-f0-9]{4,6};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -475,24 +462,22 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/template-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #15: function default values', () => { // issue https://github.com/javascript-obfuscator/javascript-obfuscator/issues/516 describe('Variant #1: base', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['value'] *= *0x1;` + `function test *\\(${variableMatch} *= *0x1, *${variableMatch} *= *${variableMatch}\\) *{ *}` + @@ -504,55 +489,45 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-default-values.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore default parameter object if it references other parameter', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: mangled name of object host node', () => { - const match1: string = `` + - `var a *= *{};` + - `a\\['bar'] *= *0x1;` + - `function foo *\\(c *= *a\\) *{ *}` + - ``; - const match2: string = `` + - `var b *= *{};` + - `b\\['bark'] *= *0x1;` + - `function baz *\\(c *= *b\\) *{ *}` + - ``; + const match1: string = + `` + `var a *= *{};` + `a\\['bar'] *= *0x1;` + `function foo *\\(c *= *a\\) *{ *}` + ``; + const match2: string = + `` + `var b *= *{};` + `b\\['bark'] *= *0x1;` + `function baz *\\(c *= *b\\) *{ *}` + ``; const regExp1: RegExp = new RegExp(match1); const regExp2: RegExp = new RegExp(match2); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/function-default-values-mangled-name.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/function-default-values-mangled-name.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('Match #1: shouldn generate correct name for object host node', () => { - assert.match(obfuscatedCode, regExp1); + assert.match(obfuscatedCode, regExp1); }); it('Match #2: shouldn generate correct name for object host node', () => { - assert.match(obfuscatedCode, regExp2); + assert.match(obfuscatedCode, regExp2); }); }); }); @@ -561,124 +536,125 @@ describe('ObjectExpressionKeysTransformer', () => { describe('Variant #16: object expression inside variable declaration', () => { describe('Without reference on other property', () => { describe('Variant #1: Single variable declarator and object expression parent node is expression node', () => { - const match: string = `` + + const match: string = + `` + `var passthrough *= *${variableMatch} *=> *${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *0x1;` + `var foo *= *passthrough *\\(${variableMatch}\\);` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/object-expression-inside-variable-declaration-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/object-expression-inside-variable-declaration-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform object expression keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: Multiple variable declarators and object expression parent node is variable declarator node', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *0x1;` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *0x2;` + `var foo *= *${variableMatch}, *bar *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/object-expression-inside-variable-declaration-2.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/object-expression-inside-variable-declaration-2.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform object expressions keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('With reference on other property', () => { describe('Variant #1: Object expression parent node is variable declarator node', () => { - const match: string = `` + + const match: string = + `` + `var passthrough *= *${variableMatch} *=> *${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *0x1;` + `var foo *= *${variableMatch}, *bar *= *{'bar': *foo\\['foo']};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/object-expression-inside-variable-declaration-3.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/object-expression-inside-variable-declaration-3.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform first object expression keys and ignore second object expression keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: Object expression parent node is any expression node', () => { - const match: string = `` + + const match: string = + `` + `var passthrough *= *${variableMatch} *=> *${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *0x1;` + `var foo *= *${variableMatch}, *bar *= *passthrough *\\({ *'bar' *: *foo\\['foo'] *}\\);` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/object-expression-inside-variable-declaration-4.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/object-expression-inside-variable-declaration-4.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform first object expression keys and ignore second object expression keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); }); describe('Variant #17: sequence expression object expressions', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + @@ -687,30 +663,30 @@ describe('ObjectExpressionKeysTransformer', () => { `${variableMatch}\\['bar'] *= *0x2;` + `${variableMatch} *= *${variableMatch}, *` + `${variableMatch} *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/sequence-expression-object-expressions.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/sequence-expression-object-expressions.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn transform sequence expression object expressions keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #18: return statement sequence expression object expressions', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + @@ -720,31 +696,31 @@ describe('ObjectExpressionKeysTransformer', () => { `return ${variableMatch} *= *${variableMatch}, *` + `${variableMatch} *= *${variableMatch}, *` + `${variableMatch}\\['bar'];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/return-statement-sequence-expression-object-expressions.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/return-statement-sequence-expression-object-expressions.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn transform sequence expression object expressions keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #19: object spread as member', () => { describe('Variant #1: object spread as first member', () => { - const match: string = `` + + const match: string = + `` + `const ${variableMatch} *= *{};` + `${variableMatch}\\['baz'] *= *0x1;` + `const foo *= *${variableMatch};` + @@ -752,7 +728,7 @@ describe('ObjectExpressionKeysTransformer', () => { `${variableMatch}\\['baz'] *= *0x2;` + `${variableMatch}\\['bark'] *= *0x3;` + `const bar *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -760,32 +736,30 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-spread-as-first-member.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn transform object expressions keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: object spread as middle member', () => { - const match: string = `` + + const match: string = + `` + `const ${variableMatch} *= *{};` + `${variableMatch}\\['baz'] *= *0x1;` + `const foo *= *${variableMatch};` + `const ${variableMatch} *= *{ *` + - `'baz': *0x2, *` + - `\.\.\.foo *` + + `'baz': *0x2, *` + + `\.\.\.foo *` + `};` + `${variableMatch}\\['bark'] *= *0x3;` + `const bar *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -793,17 +767,14 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-spread-as-middle-member.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn transform object expressions keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); @@ -811,12 +782,13 @@ describe('ObjectExpressionKeysTransformer', () => { describe('Variant #20: `this` expression', () => { describe('Variant #1: base', () => { describe('Variant #1: `this` expression as object expression', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + `this\\['object'] *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -824,26 +796,24 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/this-expression-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: `this` expression as property value without `this` reference', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *this\\['foo'];` + `var ${variableMatch} *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -851,27 +821,25 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/this-expression-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: `this` expression as property value with `this` reference after object expression', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *this\\['foo'];` + `var ${variableMatch} *= *${variableMatch};` + `this\\['bar'] *= *'bar';` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -879,28 +847,26 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/this-expression-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #4: `this` expression as property value with `this` reference before and after object expression', () => { - const match: string = `` + + const match: string = + `` + `this\\['foo'] *= *'foo';` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *this\\['foo'];` + `var ${variableMatch} *= *${variableMatch};` + `this\\['bar'] *= *'bar';` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -908,47 +874,44 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/this-expression-4.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #2: Sequence expression', () => { describe('Variant #1: sequence expression, `this` reference after object expression', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'foo';` + `this\\['foo'] *= *${variableMatch},` + `this\\['foo'] *= *'foo';` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/sequence-expression-this-reference-after.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/sequence-expression-this-reference-after.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); @@ -957,12 +920,13 @@ describe('ObjectExpressionKeysTransformer', () => { describe('member expression as host of object expression', () => { describe('Variant #1: simple', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + `this\\['state'] *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -970,27 +934,25 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/member-expression-host-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: long members chain', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + `this\\['state']\\['foo'] *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -998,17 +960,14 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/member-expression-host-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); @@ -1016,13 +975,14 @@ describe('ObjectExpressionKeysTransformer', () => { describe('correct placement of expression statements', () => { describe('Variant #1: if statement', () => { describe('Variant #1: with block statement', () => { - const match: string = `` + + const match: string = + `` + `if *\\(!!\\[]\\) *{` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['foo'] *= *'bar';` + - `var ${variableMatch} *= *${variableMatch};` + + `var ${variableMatch} *= *{};` + + `${variableMatch}\\['foo'] *= *'bar';` + + `var ${variableMatch} *= *${variableMatch};` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1030,91 +990,89 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-if-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: without block statement', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *'bar';` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['baz'] *= *'baz';` + `if *\\(!!\\[]\\)` + - `${variableMatch} *= *${variableMatch};` + + `${variableMatch} *= *${variableMatch};` + `else *` + - `${variableMatch} *= *${variableMatch};` + - ``; + `${variableMatch} *= *${variableMatch};` + + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-if-statement-without-block-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/placement-inside-if-statement-without-block-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: inside condition', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *'bar';` + `if *\\(${variableMatch} *= *${variableMatch}\\) *{}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-if-statement-condition.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/placement-inside-if-statement-condition.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #2: for statement', () => { describe('Variant #1: with block statement', () => { - const match: string = `` + + const match: string = + `` + `for *\\(var ${variableMatch} *= *0x0; *${variableMatch} *< *0xa; *${variableMatch}\\+\\+\\) *{` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['foo'] *= *'bar';` + - `var ${variableMatch} *= *${variableMatch};` + + `var ${variableMatch} *= *{};` + + `${variableMatch}\\['foo'] *= *'bar';` + + `var ${variableMatch} *= *${variableMatch};` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1122,60 +1080,58 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-for-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: without block statement', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *'bar';` + `for *\\(var ${variableMatch} *= *0x0; *${variableMatch} *< *0xa; *${variableMatch}\\+\\+\\) *` + - `${variableMatch} *= *${variableMatch};` + - ``; + `${variableMatch} *= *${variableMatch};` + + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-for-statement-without-block-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/placement-inside-for-statement-without-block-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #3: for in statement', () => { describe('Variant #1: with block statement', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `for *\\(var ${variableMatch} in *${variableMatch}\\) *{` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['bar'] *= *'bar';` + - `${variableMatch} *= *${variableMatch};` + + `var ${variableMatch} *= *{};` + + `${variableMatch}\\['bar'] *= *'bar';` + + `${variableMatch} *= *${variableMatch};` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1183,60 +1139,58 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-for-in-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: without block statement', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *'bar';` + `for *\\(var ${variableMatch} in *${variableMatch}\\) *` + - `${variableMatch} *= *${variableMatch};` + - ``; + `${variableMatch} *= *${variableMatch};` + + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-for-in-statement-without-block-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/placement-inside-for-in-statement-without-block-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #4: for of statement', () => { describe('Variant #1: with block statement', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *\\[];` + `for *\\(var ${variableMatch} of *${variableMatch}\\) *{` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['bar'] *= *'bar';` + - `${variableMatch} *= *${variableMatch};` + + `var ${variableMatch} *= *{};` + + `${variableMatch}\\['bar'] *= *'bar';` + + `${variableMatch} *= *${variableMatch};` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1244,59 +1198,57 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-for-of-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: without block statement', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *\\[];` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *'bar';` + `for *\\(var ${variableMatch} of *${variableMatch}\\) *` + - `${variableMatch} *= *${variableMatch};` + + `${variableMatch} *= *${variableMatch};` + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-for-of-statement-without-block-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/placement-inside-for-of-statement-without-block-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #5: while statement', () => { describe('Variant #1: with block statement', () => { - const match: string = `` + + const match: string = + `` + `while *\\(!!\\[]\\) *{` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['foo'] *= *'bar';` + - `var ${variableMatch} *= *${variableMatch};` + + `var ${variableMatch} *= *{};` + + `${variableMatch}\\['foo'] *= *'bar';` + + `var ${variableMatch} *= *${variableMatch};` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1304,87 +1256,85 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-while-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: without block statement', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *'bar';` + `while *\\(!!\\[]\\)` + - `${variableMatch} *= *${variableMatch};` + - ``; + `${variableMatch} *= *${variableMatch};` + + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-while-statement-without-block-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/placement-inside-while-statement-without-block-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: inside condition', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *'bar';` + `while *\\(${variableMatch} *= *${variableMatch}\\) *{}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-while-statement-condition.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/placement-inside-while-statement-condition.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #6: try statement', () => { - const match: string = `` + + const match: string = + `` + `try *{` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['foo'] *= *'bar';` + - `var ${variableMatch} *= *${variableMatch};` + + `var ${variableMatch} *= *{};` + + `${variableMatch}\\['foo'] *= *'bar';` + + `var ${variableMatch} *= *${variableMatch};` + `} *catch *\\(${variableMatch}\\) *{` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1392,29 +1342,27 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-try-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #7: catch clause statement', () => { - const match: string = `` + + const match: string = + `` + `try *{` + `} *catch *\\(${variableMatch}\\) *{` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['foo'] *= *'bar';` + - `var ${variableMatch} *= *${variableMatch};` + + `var ${variableMatch} *= *{};` + + `${variableMatch}\\['foo'] *= *'bar';` + + `var ${variableMatch} *= *${variableMatch};` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1422,29 +1370,27 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-catch-clause.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #8: switch catch statement', () => { - const match: string = `` + + const match: string = + `` + `switch *\\(!!\\[]\\) *{` + - `case *!!\\[]:` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['foo'] *= *'bar';` + - `var ${variableMatch} *= *${variableMatch};` + + `case *!!\\[]:` + + `var ${variableMatch} *= *{};` + + `${variableMatch}\\['foo'] *= *'bar';` + + `var ${variableMatch} *= *${variableMatch};` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1452,107 +1398,104 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/placement-inside-switch-case.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #9: variable declarator with object call', () => { describe('Variant #1', () => { - const match: string = `` + + const match: string = + `` + `const ${variableMatch} *= *{}; *` + `${variableMatch}\\['foo'] *= *'foo'; *` + `const ${variableMatch} *= *${variableMatch};` + `const ${variableMatch} *= *${variableMatch}\\['foo'];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarator-with-object-call-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2', () => { - const match: string = `` + + const match: string = + `` + `const ${variableMatch} *= *{}; *` + `${variableMatch}\\['foo'] *= *'foo'; *` + `const ${variableMatch} *= *0x1, *` + - `${variableMatch} *= *${variableMatch}; *` + + `${variableMatch} *= *${variableMatch}; *` + `const ${variableMatch} *= *${variableMatch}\\['foo'];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarator-with-object-call-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform object keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: two objects', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'foo';` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *'bar';` + `var ${variableMatch} *= *${variableMatch}, *` + - `${variableMatch} *= *${variableMatch}, *` + - `${variableMatch} *= *${variableMatch}\\['bar']; *` + + `${variableMatch} *= *${variableMatch}, *` + + `${variableMatch} *= *${variableMatch}\\['bar']; *` + `console\\['log']\\(${variableMatch}\\);` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-3.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarator-with-object-call-3.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly transform objects keys', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); @@ -1560,11 +1503,12 @@ describe('ObjectExpressionKeysTransformer', () => { describe('prevailing kind of variables', () => { describe('Variant #1: `var` kind`', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1572,26 +1516,24 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should use correct kind of variables', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: `const` kind`', () => { - const match: string = `` + + const match: string = + `` + `const ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1599,26 +1541,24 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should use correct kind of variables', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: `let` kind`', () => { - const match: string = `` + + const match: string = + `` + `const ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1626,29 +1566,21 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should use correct kind of variables', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Ignore transformation', () => { describe('Variant #1: disabled option', () => { - const match: string = `` + - `var ${variableMatch} *= *{` + - `'foo': *'bar',` + - `'baz': *'bark'` + - `}` + - ``; + const match: string = `` + `var ${variableMatch} *= *{` + `'foo': *'bar',` + `'baz': *'bark'` + `}` + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1656,16 +1588,13 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('shouldn\'t transform object keys', () => { - assert.match(obfuscatedCode, regExp); + it("shouldn't transform object keys", () => { + assert.match(obfuscatedCode, regExp); }); }); @@ -1678,23 +1607,21 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/empty-object-expression.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('shouldn\'t transform object keys', () => { - assert.match(obfuscatedCode, regExp); + it("shouldn't transform object keys", () => { + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: function default value reference', () => { - const match: string = `` + + const match: string = + `` + `function test *\\(${variableMatch} *= *0x1, *${variableMatch} *= *{'value' *: *${variableMatch}}\\) *{ *}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1702,29 +1629,27 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-default-value-reference.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore default parameter object if it references other parameter', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #4: member expression node as property key', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'test';` + `var foo *= *${variableMatch};` + `var ${variableMatch} *= *{\\[foo\\['foo']] *: *'1'};` + `${variableMatch}\\['bar'] *= *'2';` + `var bar *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -1732,53 +1657,51 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/computed-key-member-expression.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore extraction of property with member expression key', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #5: sequence expression identifier reference', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *0x1;` + `${variableMatch} *= *${variableMatch}, *` + `${variableMatch} *= *{'bar' *: *${variableMatch}\\['foo']};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/sequence-expression-identifier-reference.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/sequence-expression-identifier-reference.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore sequence expression object expression if it references other sequence expression identifier', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #6: return statement sequence expression identifier reference', () => { describe('Variant #1: reference on other sequence expression identifier', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + @@ -1786,232 +1709,228 @@ describe('ObjectExpressionKeysTransformer', () => { `return ${variableMatch} *= *${variableMatch}, *` + `${variableMatch} *= *{'bar' *: *${variableMatch}\\['foo']}, *` + `${variableMatch}\\['bar'];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/return-statement-sequence-expression-identifier-reference-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/return-statement-sequence-expression-identifier-reference-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore sequence expression object expression if it references other sequence expression identifier', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: reference on same sequence expression identifier', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['props'] *= *0x1;` + `return *\\(${variableMatch} *= *${variableMatch}\\)\\['state'] *= *{'expanded' *: *${variableMatch}\\['props']}, *` + `${variableMatch}\\['state']\\['expanded'];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/return-statement-sequence-expression-identifier-reference-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/return-statement-sequence-expression-identifier-reference-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore sequence expression object expression if it references other sequence expression identifier', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #7: conditional expression identifier reference', () => { describe('Variant #1: conditional expression identifier reference', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *0x1;` + `${variableMatch} *\\? *{'bar' *: *${variableMatch}\\['foo']} *: *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/conditional-expression-identifier-reference.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/conditional-expression-identifier-reference.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore conditional expression object expression if it references other conditional expression identifier', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: return statement conditional expression identifier reference', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *0x1;` + `return ${variableMatch} *\\? *{'bar' *: *${variableMatch}\\['foo']} *: *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/return-statement-conditional-expression-identifier-reference.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/return-statement-conditional-expression-identifier-reference.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore conditional expression object expression if it references other conditional expression identifier', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: assignment expression conditional expression identifier reference', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *0x1;` + `${variableMatch} *= *${variableMatch} *\\? *{'bar' *: *${variableMatch}\\['foo']} *: *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/assignment-expression-conditional-expression-identifier-reference.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/assignment-expression-conditional-expression-identifier-reference.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore conditional expression object expression if it references other conditional expression identifier', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #4: variable declarator conditional expression identifier reference', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch};` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *0x1;` + `var ${variableMatch} *= *${variableMatch} *\\? *{'bar' *: *${variableMatch}\\['foo']} *: *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-conditional-expression-identifier-reference.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarator-conditional-expression-identifier-reference.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore conditional expression object expression if it references other conditional expression identifier', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #8: variable declarator identifier reference', () => { - const match: string = `` + + const match: string = + `` + `var passthrough *= *${variableMatch} *=> *${variableMatch};` + `var foo *= *0x1, *bar *= *{'baz' *: *passthrough\\(foo\\)};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-identifier-reference.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarator-identifier-reference.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore variable declarator object expression if it references other variable declarator identifier', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #9: sequence expression super call expression', () => { - const match: string = `` + - `super\\(\\), *` + - `this\\['state'] *= *{ *'foo': *0x1 *};` + - ``; + const match: string = `` + `super\\(\\), *` + `this\\['state'] *= *{ *'foo': *0x1 *};` + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/sequence-expression-super-call-expression.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/sequence-expression-super-call-expression.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); - it('shouldn\'t ignore sequence expression object expression if this sequence expression contains super call expression', () => { - assert.match(obfuscatedCode, regExp); + it("shouldn't ignore sequence expression object expression if this sequence expression contains super call expression", () => { + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #10: computed property key name', () => { - const match: string = `` + + const match: string = + `` + `const ${variableMatch} *= *'foo';` + `const ${variableMatch} *= *{};` + `${variableMatch}\\[${variableMatch}] *= *'bar';` + `const ${variableMatch} *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2019,28 +1938,26 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/computed-key-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly generate name for the computed key identifier', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #11: `get` and `set` property kinds', () => { - const match: string = `` + + const match: string = + `` + `const ${variableMatch} *= *{ *` + - `get \'baz\' *\\(\\) *{ *return 0x2; *}, *` + - `set \'bark\' *\\(${variableMatch}\\) *{ *this\\[\'bark\'] *= *${variableMatch}; *} *` + + `get \'baz\' *\\(\\) *{ *return 0x2; *}, *` + + `set \'bark\' *\\(${variableMatch}\\) *{ *this\\[\'bark\'] *= *${variableMatch}; *} *` + `}; *` + `${variableMatch}\\[\'bar\'] *= *0x1;` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2048,32 +1965,30 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/get-set-property-kind.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should keep property nodes with `get` and `set` kind in the object', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #12: object spread as last member', () => { - const match: string = `` + + const match: string = + `` + `const ${variableMatch} *= *{};` + `${variableMatch}\\['baz'] *= *0x1;` + `const foo *= *${variableMatch};` + `const ${variableMatch} *= *{ *` + - `'baz': *0x2 *,` + - `'bark': *0x3 *,` + - `\.\.\.foo *` + + `'baz': *0x2 *,` + + `'bark': *0x3 *,` + + `\.\.\.foo *` + `};` + `const bar *= *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2081,52 +1996,41 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-spread-as-last-member.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expressions keys transformation', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #13: object expression as body of arrow function expression', () => { - const match: string = `` + - `const test *= *\\(\\) *=> *\\({`+ - `'foo' *: *'bar'` + - `}\\);` + - ``; + const match: string = `` + `const test *= *\\(\\) *=> *\\({` + `'foo' *: *'bar'` + `}\\);` + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/object-expression-as-body-of-arrow-function-expression.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/object-expression-as-body-of-arrow-function-expression.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expressions keys transformation', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #14: sequence expression `this` reference', () => { - const match: string = `` + - `this\\['foo'] *= *0x1, *` + - `this\\['bar'] *= *{'bar' *: *this\\['foo']};` + - ``; + const match: string = `` + `this\\['foo'] *= *0x1, *` + `this\\['bar'] *= *{'bar' *: *this\\['foo']};` + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2134,162 +2038,157 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/sequence-expression-this-reference.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore sequence expression object expression if it references other sequence expression `this` expression`', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #15: return statement sequence expression `this` reference', () => { describe('Variant #1: reference on other sequence expression `this` expression`', () => { - const match: string = `` + - `return this\\['foo'] *= *0x1, *` + - `this\\['bar'] *= *{'bar' *: *this\\['foo']};` + - ``; + const match: string = + `` + `return this\\['foo'] *= *0x1, *` + `this\\['bar'] *= *{'bar' *: *this\\['foo']};` + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/return-statement-sequence-expression-this-reference-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/return-statement-sequence-expression-this-reference-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore sequence expression object expression if it references other sequence expression `this` expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: reference on same sequence expression `this` expression', () => { - const match: string = `` + + const match: string = + `` + `return *\\(this\\['foo'] *= *${variableMatch}\\)\\['state'] *= *{'expanded' *: *this\\['foo']\\['props']}, *` + `this\\['foo']\\['state']\\['expanded'];` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/return-statement-sequence-expression-this-reference-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/return-statement-sequence-expression-this-reference-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore sequence expression object expression if it references other sequence expression `this` expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #16: conditional expression `this` reference', () => { describe('Variant #1: conditional expression identifier reference', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *0x1;` + `this\\['foo'] *\\? *{'bar' *: *this\\['foo']} *: *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/conditional-expression-this-reference.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/conditional-expression-this-reference.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore conditional expression object expression if it references other conditional expression `this` expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: return statement conditional expression `this` reference', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *0x1;` + `return this\\['foo'] *\\? *{'bar' *: *this\\['foo']} *: *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/return-statement-conditional-expression-this-reference.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/return-statement-conditional-expression-this-reference.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore conditional expression object expression if it references other conditional expression `this` expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: assignment expression conditional expression `this` reference', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{};` + `${variableMatch}\\['bar'] *= *0x1;` + `this\\['bar'] *= *this\\['foo'] *\\? *{'bar' *: *this\\['foo']} *: *${variableMatch};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/assignment-expression-conditional-expression-this-reference.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/assignment-expression-conditional-expression-this-reference.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore conditional expression object expression if it references other conditional expression `this` expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #17: variable declarator `this` reference', () => { - const match: string = `` + + const match: string = + `` + `var passthrough *= *${variableMatch} *=> *${variableMatch};` + `var foo *= *this\\['foo'], *bar *= *{'baz' *: *passthrough\\(this\\['foo']\\)};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2297,28 +2196,21 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-this-reference.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore variable declarator object expression if it references other variable declarator `this` expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #18: call expression as property value', () => { describe('Variant #1: call expression as a direct property value', () => { - const match: string = `` + - `var ${variableMatch} *= *{` + - `'foo': *'bar',` + - `'baz': *${variableMatch}\\(\\)` + - `}` + - ``; + const match: string = + `` + `var ${variableMatch} *= *{` + `'foo': *'bar',` + `'baz': *${variableMatch}\\(\\)` + `}` + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2326,27 +2218,25 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/call-expression-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expression if it contains a call expression as a direct property value', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: call expression as an indirect property value', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{` + - `'foo': *'bar',` + - `'baz': *'call' *\\+ *${variableMatch}\\(\\)` + + `'foo': *'bar',` + + `'baz': *'call' *\\+ *${variableMatch}\\(\\)` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2354,29 +2244,27 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/call-expression-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expression if it contains a call expression as an indirect property value', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: call expression as a nested object expression as property value', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{` + - `'foo': *'bar',` + - `'baz': *{` + - `'bark': *${variableMatch}\\(\\)` + - `}` + + `'foo': *'bar',` + + `'baz': *{` + + `'bark': *${variableMatch}\\(\\)` + `}` + - ``; + `}` + + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2384,28 +2272,26 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/call-expression-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expression if it contains a call expression as a nested object expression as property value', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #4: call expression as a a property value after object expression property', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{` + - `'foo': *'bar',` + - `'baz': *${variableMatch},` + - `'eagle': *${variableMatch}\\(\\)` + + `'foo': *'bar',` + + `'baz': *${variableMatch},` + + `'eagle': *${variableMatch}\\(\\)` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2413,29 +2299,27 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/call-expression-4.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expression if it contains a call expression and the previous property value is object expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); describe('Variant #19: new expression as property value', () => { describe('Variant #1: new expression as a direct property value', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{` + - `'foo': *'bar',` + - `'baz': *new ${variableMatch}\\(\\)` + + `'foo': *'bar',` + + `'baz': *new ${variableMatch}\\(\\)` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2443,27 +2327,25 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/new-expression-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expression if it contains a new expression as a direct property value', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #2: new expression as an indirect property value', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{` + - `'foo': *'bar',` + - `'baz': *'call' *\\+ *new ${variableMatch}\\(\\)` + + `'foo': *'bar',` + + `'baz': *'call' *\\+ *new ${variableMatch}\\(\\)` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2471,29 +2353,27 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/new-expression-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expression if it contains a new expression as an indirect property value', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #3: new expression as a nested object expression as property value', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{` + - `'foo': *'bar',` + - `'baz': *{` + - `'bark': *new ${variableMatch}\\(\\)` + - `}` + + `'foo': *'bar',` + + `'baz': *{` + + `'bark': *new ${variableMatch}\\(\\)` + `}` + - ``; + `}` + + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2501,28 +2381,26 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/new-expression-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expression if it contains a new expression as a nested object expression as property value', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); describe('Variant #4: new expression as a a property value after object expression property', () => { - const match: string = `` + + const match: string = + `` + `var ${variableMatch} *= *{` + - `'foo': *'bar',` + - `'baz': *${variableMatch},` + - `'eagle': *new ${variableMatch}\\(\\)` + + `'foo': *'bar',` + + `'baz': *${variableMatch},` + + `'eagle': *new ${variableMatch}\\(\\)` + `}` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -2530,17 +2408,14 @@ describe('ObjectExpressionKeysTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/new-expression-4.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('shouldn ignore object expression if it contains a new expression and the previous property value is object expression', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); diff --git a/test/functional-tests/node-transformers/converting-transformers/object-expression-transformer/ObjectExpressionTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/object-expression-transformer/ObjectExpressionTransformer.spec.ts index a5d61a449..3cde0c229 100644 --- a/test/functional-tests/node-transformers/converting-transformers/object-expression-transformer/ObjectExpressionTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/object-expression-transformer/ObjectExpressionTransformer.spec.ts @@ -10,7 +10,7 @@ import { ObjectPatternPropertiesTransformer } from '../../../../../src/node-tran describe('ObjectExpressionTransformer', () => { describe('default behaviour', () => { - describe('Variant #1: `unicodeEscapeSequence` option is disabled\'', () => { + describe("Variant #1: `unicodeEscapeSequence` option is disabled'", () => { const regExp: RegExp = /var test *= *\{'foo':0x0\};/; let obfuscatedCode: string; @@ -18,13 +18,10 @@ describe('ObjectExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/property-with-identifier-value.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); }); it('should replace object expression node `key` property with identifier value by property with literal value', () => { @@ -40,13 +37,10 @@ describe('ObjectExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/property-with-identifier-value.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: true + }).getObfuscatedCode(); }); it('should replace object expression node `key` property with identifier value by property with encoded literal value', () => { @@ -63,12 +57,9 @@ describe('ObjectExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/shorthand-object-expression.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should correct convert shorthand ES6 object expression to non-shorthand object expression', () => { @@ -85,12 +76,9 @@ describe('ObjectExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/computed-property-name-identifier.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should ignore computed property identifier', () => { @@ -107,13 +95,10 @@ describe('ObjectExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/computed-property-name-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); }); it('should ignore computed property literal value', () => { @@ -129,13 +114,10 @@ describe('ObjectExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/computed-property-name-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: true + }).getObfuscatedCode(); }); it('should encode computed property literal value', () => { @@ -156,12 +138,9 @@ describe('ObjectExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-rest.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should transform object name', () => { @@ -176,19 +155,17 @@ describe('ObjectExpressionTransformer', () => { describe('object spread', () => { const object1RegExp: RegExp = /var _0x[a-f0-9]{4,6} *= *\{'foo': *0x1\};/; const object2RegExp: RegExp = /var _0x[a-f0-9]{4,6} *= *\{'bar': *0x2\};/; - const objectSpreadRegExp: RegExp = /var _0x[a-f0-9]{4,6} *= *\{\.\.\._0x[a-f0-9]{4,6}, *\.\.\._0x[a-f0-9]{4,6}\};/; + const objectSpreadRegExp: RegExp = + /var _0x[a-f0-9]{4,6} *= *\{\.\.\._0x[a-f0-9]{4,6}, *\.\.\._0x[a-f0-9]{4,6}\};/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-spread.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should transform object name', () => { @@ -216,14 +193,11 @@ describe('ObjectExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-spread-unicode-escape-sequence.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true, - unicodeEscapeSequence: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true, + unicodeEscapeSequence: true + }).getObfuscatedCode(); }); it('Match #1: should transform object declaration', () => { diff --git a/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/ObjectPatternPropertiesTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/ObjectPatternPropertiesTransformer.spec.ts index 3c5da4b1f..69a870363 100644 --- a/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/ObjectPatternPropertiesTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/ObjectPatternPropertiesTransformer.spec.ts @@ -14,8 +14,8 @@ describe('ObjectPatternPropertiesTransformer', () => { 'foo: *_0x([a-f0-9]){4,6}, *' + 'bar: *_0x([a-f0-9]){4,6}, *' + '..._0x([a-f0-9]){4,6}' + - '} *= *{}; *' + - 'console\\[\'log\']\\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\\);' + '} *= *{}; *' + + "console\\['log']\\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\\);" ); let obfuscatedCode: string; @@ -23,13 +23,10 @@ describe('ObjectPatternPropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: false + }).getObfuscatedCode(); }); it('should transform object properties', () => { @@ -43,8 +40,8 @@ describe('ObjectPatternPropertiesTransformer', () => { 'foo: *_0x([a-f0-9]){4,6}, *' + 'bar: *_0x([a-f0-9]){4,6}, *' + '..._0x([a-f0-9]){4,6}' + - '} *= *{}; *' + - 'console\\[\'log\']\\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\\);' + '} *= *{}; *' + + "console\\['log']\\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\\);" ); let obfuscatedCode: string; @@ -52,13 +49,10 @@ describe('ObjectPatternPropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('should transform object properties', () => { @@ -71,10 +65,10 @@ describe('ObjectPatternPropertiesTransformer', () => { 'const { *' + 'foo: *_0x([a-f0-9]){4,6}, *' + 'bar: *_0x([a-f0-9]){4,6} *' + - '} *= *{}; *' + - 'const _0x([a-f0-9]){4,6} *= *{};' + - '_0x([a-f0-9]){4,6}\\[\'prop\'] *= *0x1;' + - 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6};' + '} *= *{}; *' + + 'const _0x([a-f0-9]){4,6} *= *{};' + + "_0x([a-f0-9]){4,6}\\['prop'] *= *0x1;" + + 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6};' ); let obfuscatedCode: string; @@ -82,14 +76,11 @@ describe('ObjectPatternPropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-scope-wrong-parentize.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: false, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: false, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should transform object properties', () => { @@ -105,8 +96,8 @@ describe('ObjectPatternPropertiesTransformer', () => { 'foo, *' + 'bar, *' + '...rest' + - '} *= *{}; *' + - 'console\\[\'log\']\\(foo, *bar, *rest\\);' + '} *= *{}; *' + + "console\\['log']\\(foo, *bar, *rest\\);" ); let obfuscatedCode: string; @@ -114,13 +105,10 @@ describe('ObjectPatternPropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/global-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: false + }).getObfuscatedCode(); }); it('should transform object properties', () => { @@ -134,8 +122,8 @@ describe('ObjectPatternPropertiesTransformer', () => { 'foo: *_0x([a-f0-9]){4,6}, *' + 'bar: *_0x([a-f0-9]){4,6}, *' + '..._0x([a-f0-9]){4,6}' + - '} *= *{}; *' + - 'console\\[\'log\']\\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\\);' + '} *= *{}; *' + + "console\\['log']\\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\\);" ); let obfuscatedCode: string; @@ -143,13 +131,10 @@ describe('ObjectPatternPropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/global-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('should transform object properties', () => { diff --git a/test/functional-tests/node-transformers/converting-transformers/split-string-transformer/SplitStringTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/split-string-transformer/SplitStringTransformer.spec.ts index 45a01dc00..a5c8f9516 100644 --- a/test/functional-tests/node-transformers/converting-transformers/split-string-transformer/SplitStringTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/split-string-transformer/SplitStringTransformer.spec.ts @@ -10,21 +10,18 @@ import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFac describe('SplitStringTransformer', () => { let obfuscatedCode: string; - + describe('Variant #1: simple string literal', () => { it('should transform string literal to binary expression', () => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'ab' *\+ *'cd' *\+ *'ef' *\+ *'g';$/); + assert.match(obfuscatedCode, /^var test *= *'ab' *\+ *'cd' *\+ *'ef' *\+ *'g';$/); }); }); @@ -32,16 +29,13 @@ describe('SplitStringTransformer', () => { it('should keep original string literal', () => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: false, - splitStringsChunkLength: 10 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: false, + splitStringsChunkLength: 10 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'abcdefg';$/); + assert.match(obfuscatedCode, /^var test *= *'abcdefg';$/); }); }); @@ -49,16 +43,13 @@ describe('SplitStringTransformer', () => { it('should keep original string literal', () => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 10 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 10 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'abcdefg';$/); + assert.match(obfuscatedCode, /^var test *= *'abcdefg';$/); }); }); @@ -66,14 +57,12 @@ describe('SplitStringTransformer', () => { it('should throw an validation error ', () => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - const testFunc = () => JavaScriptObfuscator.obfuscate( - code, - { + const testFunc = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, splitStrings: true, splitStringsChunkLength: 0 - } - ); + }); assert.throws(testFunc, /validation failed/i); }); @@ -83,16 +72,13 @@ describe('SplitStringTransformer', () => { it('should transform string literals to binary expressions', () => { const code: string = readFileAsString(__dirname + '/fixtures/strings-concatenation.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'ab' *\+ *'cd' *\+ *\( *'ef' *\+ *'g' *\);$/); + assert.match(obfuscatedCode, /^var test *= *'ab' *\+ *'cd' *\+ *\( *'ef' *\+ *'g' *\);$/); }); }); @@ -100,17 +86,17 @@ describe('SplitStringTransformer', () => { it('should convert strings to unicode escape sequence view', () => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2, - unicodeEscapeSequence: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2, + unicodeEscapeSequence: true + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'\\x61\\x62' *\+ *'\\x63\\x64' *\+ *'\\x65\\x66' *\+ *'\\x67';$/); + assert.match( + obfuscatedCode, + /^var test *= *'\\x61\\x62' *\+ *'\\x63\\x64' *\+ *'\\x65\\x66' *\+ *'\\x67';$/ + ); }); }); @@ -118,16 +104,13 @@ describe('SplitStringTransformer', () => { it('should apply string splitting on template literal strings', () => { const code: string = readFileAsString(__dirname + '/fixtures/template-literal-string.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'ab' *\+ *'cd' *\+ *'ef' *\+ *'g';$/); + assert.match(obfuscatedCode, /^var test *= *'ab' *\+ *'cd' *\+ *'ef' *\+ *'g';$/); }); }); @@ -135,16 +118,13 @@ describe('SplitStringTransformer', () => { it('should keep original key string literal and transform value string literal', () => { const code: string = readFileAsString(__dirname + '/fixtures/object-string-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *{'abcdefg' *: *'ab' *\+ *'cd' *\+ *'ef' *\+ *'g'};$/); + assert.match(obfuscatedCode, /^var test *= *{'abcdefg' *: *'ab' *\+ *'cd' *\+ *'ef' *\+ *'g'};$/); }); }); @@ -152,16 +132,13 @@ describe('SplitStringTransformer', () => { it('should transform string literal to binary expression', () => { const code: string = readFileAsString(__dirname + '/fixtures/object-computed-key-string-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *{\['ab' *\+ *'cd' *\+ *'ef' *\+ *'g'] *: *0x1};$/); + assert.match(obfuscatedCode, /^var test *= *{\['ab' *\+ *'cd' *\+ *'ef' *\+ *'g'] *: *0x1};$/); }); }); @@ -172,16 +149,13 @@ describe('SplitStringTransformer', () => { const code: string = readFileAsString(__dirname + '/fixtures/string-with-emoji-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 1 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); it('should correctly evaluate splitted string with emoji', () => { @@ -189,14 +163,11 @@ describe('SplitStringTransformer', () => { const code: string = readFileAsString(__dirname + '/fixtures/string-with-emoji-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 1 + }).getObfuscatedCode(); const resultString: string = eval(obfuscatedCode); @@ -210,16 +181,13 @@ describe('SplitStringTransformer', () => { const code: string = readFileAsString(__dirname + '/fixtures/string-with-emoji-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 1 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); it('should correctly evaluate splitted string with emoji', () => { @@ -227,14 +195,11 @@ describe('SplitStringTransformer', () => { const code: string = readFileAsString(__dirname + '/fixtures/string-with-emoji-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 1 + }).getObfuscatedCode(); const resultString: string = eval(obfuscatedCode); @@ -248,16 +213,13 @@ describe('SplitStringTransformer', () => { const code: string = readFileAsString(__dirname + '/fixtures/string-with-emoji-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 3 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 3 + }).getObfuscatedCode(); - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); it('should correctly evaluate splitted string with emoji', () => { @@ -265,14 +227,11 @@ describe('SplitStringTransformer', () => { const code: string = readFileAsString(__dirname + '/fixtures/string-with-emoji-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 3 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 3 + }).getObfuscatedCode(); const resultString: string = eval(obfuscatedCode); @@ -290,19 +249,14 @@ describe('SplitStringTransformer', () => { const code: string = readFileAsString(__dirname + '/fixtures/string-with-emoji-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 3, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.Base64 - ] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 3, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.Base64] + }).getObfuscatedCode(); const resultString: string = eval(obfuscatedCode); @@ -315,27 +269,23 @@ describe('SplitStringTransformer', () => { describe('Variant #12: Integration with `transformObjectKeys` option', () => { it('should correctly transform string when `transformObjectKeys` option is enabled', () => { - const regExp: RegExp = new RegExp(`` + - `var _0x[a-f0-9]{4,6} *= *{};` + - `*_0x[a-f0-9]{4,6}\\['ab' *\\+ *'cd' *\\+ *'ef' *\\+ *'g'] *= *'ab' *\\+ *'cd' *\\+ *'ef' *\\+ *'g';` + - `var test *= *_0x[a-f0-9]{4,6};` + - ``); + const regExp: RegExp = new RegExp( + `` + + `var _0x[a-f0-9]{4,6} *= *{};` + + `*_0x[a-f0-9]{4,6}\\['ab' *\\+ *'cd' *\\+ *'ef' *\\+ *'g'] *= *'ab' *\\+ *'cd' *\\+ *'ef' *\\+ *'g';` + + `var test *= *_0x[a-f0-9]{4,6};` + + `` + ); const code: string = readFileAsString(__dirname + '/fixtures/object-string-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2, + transformObjectKeys: true + }).getObfuscatedCode(); - assert.match( - obfuscatedCode, - regExp - ); + assert.match(obfuscatedCode, regExp); }); }); @@ -343,15 +293,12 @@ describe('SplitStringTransformer', () => { it('should correctly ignore strings from `reservedStrings` option', () => { const code: string = readFileAsString(__dirname + '/fixtures/ignore-reserved-strings.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 3, - reservedStrings: ['bar'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 3, + reservedStrings: ['bar'] + }).getObfuscatedCode(); assert.match( obfuscatedCode, @@ -364,19 +311,14 @@ describe('SplitStringTransformer', () => { it('Should does not throw `Maximum call stack size exceeded` error on a large string', () => { const code: string = `var foo = '${'a'.repeat(10000)}';`; - const testFunc = () => JavaScriptObfuscator.obfuscate( - code, - { + const testFunc = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, splitStrings: true, splitStringsChunkLength: 2 - } - ); + }); - assert.doesNotThrow( - testFunc, - Error - ); + assert.doesNotThrow(testFunc, Error); }); }); @@ -388,14 +330,11 @@ describe('SplitStringTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/import-declaration-source.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2 + }).getObfuscatedCode(); }); it('Should not split `ImportDeclaration` source literal', () => { @@ -411,14 +350,11 @@ describe('SplitStringTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/export-all-declaration-source.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2 + }).getObfuscatedCode(); }); it('Should not split `ExportAllDeclaration` source literal', () => { @@ -434,14 +370,11 @@ describe('SplitStringTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/export-named-declaration-source.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - splitStrings: true, - splitStringsChunkLength: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + splitStrings: true, + splitStringsChunkLength: 2 + }).getObfuscatedCode(); }); it('Should not split `ExportNamedDeclaration` source literal', () => { diff --git a/test/functional-tests/node-transformers/converting-transformers/template-literal-transformer/TemplateLiteralTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/template-literal-transformer/TemplateLiteralTransformer.spec.ts index e07b8b7da..7bd07ae70 100644 --- a/test/functional-tests/node-transformers/converting-transformers/template-literal-transformer/TemplateLiteralTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/template-literal-transformer/TemplateLiteralTransformer.spec.ts @@ -8,20 +8,17 @@ import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFac describe('TemplateLiteralTransformer', () => { let obfuscatedCode: string; - + describe('Variant #1: simple template literal', () => { it('should transform es6 template literal to es5', () => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'abc\\x20' *\+ *foo;$/); + assert.match(obfuscatedCode, /^var test *= *'abc\\x20' *\+ *foo;$/); }); }); @@ -29,71 +26,64 @@ describe('TemplateLiteralTransformer', () => { it('Variant #1: should transform es6 multiline template literal to es5', () => { const code: string = readFileAsString(__dirname + '/fixtures/multiline-template-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'foo\\x0abar';$/); + assert.match(obfuscatedCode, /^var test *= *'foo\\x0abar';$/); }); it('Variant #2: should transform es6 multiline template literal inside return statement', () => { - const code: string = readFileAsString(__dirname + '/fixtures/multiline-template-literal-return-statement-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/multiline-template-literal-return-statement-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /{ *return *'foo\\x0abar'; *}$/); + assert.match(obfuscatedCode, /{ *return *'foo\\x0abar'; *}$/); }); it('Variant #3: should transform es6 multiline template literal inside return statement', () => { - const code: string = readFileAsString(__dirname + '/fixtures/multiline-template-literal-return-statement-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/multiline-template-literal-return-statement-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /case *!!\[] *: *return *'foo\\x0abar'; *} *}$/); + assert.match(obfuscatedCode, /case *!!\[] *: *return *'foo\\x0abar'; *} *}$/); }); it('Variant #4: should transform es6 multiline template literal inside binary expression inside return statement', () => { - const code: string = readFileAsString(__dirname + '/fixtures/multiline-template-literal-binary-expression-return-statement-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/multiline-template-literal-binary-expression-return-statement-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /{ *return *'foo\\x0abar' *\+ *0x1; *}$/); + assert.match(obfuscatedCode, /{ *return *'foo\\x0abar' *\+ *0x1; *}$/); }); it('Variant #5: should transform es6 multiline template literal inside binary expression inside return statement', () => { - const code: string = readFileAsString(__dirname + '/fixtures/multiline-template-literal-binary-expression-return-statement-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/multiline-template-literal-binary-expression-return-statement-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /case *!!\[] *: *return *'foo\\x0abar' *\+ *0x1; *} *}$/); + assert.match(obfuscatedCode, /case *!!\[] *: *return *'foo\\x0abar' *\+ *0x1; *} *}$/); }); }); @@ -101,15 +91,12 @@ describe('TemplateLiteralTransformer', () => { it('should transform es6 template literal to es5 and add empty literal node before expression node', () => { const code: string = readFileAsString(__dirname + '/fixtures/expression-only.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'' *\+ *foo;$/); + assert.match(obfuscatedCode, /^var test *= *'' *\+ *foo;$/); }); }); @@ -117,15 +104,12 @@ describe('TemplateLiteralTransformer', () => { it('should transform es6 template literal to es5', () => { const code: string = readFileAsString(__dirname + '/fixtures/literal-inside-expression.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^var test *= *'abc';$/); + assert.match(obfuscatedCode, /^var test *= *'abc';$/); }); }); @@ -133,37 +117,25 @@ describe('TemplateLiteralTransformer', () => { it('should transform es6 template literal to es5', () => { const code: string = readFileAsString(__dirname + '/fixtures/multiple-expressions.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); - - assert.match( - obfuscatedCode, - /^var test *= *0x1 *\+ *0x1 *\+ *'\\x20abc\\x20' *\+ *\(0x1 *\+ *0x1\);$/ - ); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); + + assert.match(obfuscatedCode, /^var test *= *0x1 *\+ *0x1 *\+ *'\\x20abc\\x20' *\+ *\(0x1 *\+ *0x1\);$/); }); }); describe('Variant #6: tagged template literal', () => { - it('shouldn\'t transform es6 tagged template literal to es5', () => { + it("shouldn't transform es6 tagged template literal to es5", () => { const code: string = readFileAsString(__dirname + '/fixtures/tagged-template-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); - - assert.match( - obfuscatedCode, - /tag`foo *\${0x1 *\+ *0x1} *bar`;/ - ); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); + + assert.match(obfuscatedCode, /tag`foo *\${0x1 *\+ *0x1} *bar`;/); }); }); @@ -171,24 +143,22 @@ describe('TemplateLiteralTransformer', () => { it('should parentize transformed template literal node', () => { const code: string = readFileAsString(__dirname + '/fixtures/template-literal-parentize.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: false + }).getObfuscatedCode(); - assert.match(obfuscatedCode, /^\[]\['map']\(\(\) *=> *'foo'\);$/); + assert.match(obfuscatedCode, /^\[]\['map']\(\(\) *=> *'foo'\);$/); }); }); describe('Variant #8: parentize node', () => { - const match: string = `` + + const match: string = + `` + `var _0x[a-f0-9]{4,6} *= *{};` + `_0x[a-f0-9]{4,6}\\['foo'] *= *'bar';` + `var foo *= *'' *\\+ *_0x[a-f0-9]{4,6};` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; @@ -196,17 +166,14 @@ describe('TemplateLiteralTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/parentize-node.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should correctly obfuscate code without maximum call stack error', () => { - assert.match(obfuscatedCode, regExp); + assert.match(obfuscatedCode, regExp); }); }); }); diff --git a/test/functional-tests/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.spec.ts b/test/functional-tests/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.spec.ts index 8024e4b13..386ac44a6 100644 --- a/test/functional-tests/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.spec.ts +++ b/test/functional-tests/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.spec.ts @@ -19,11 +19,11 @@ describe('DeadCodeInjectionTransformer', () => { describe('Variant #1 - 5 simple block statements', () => { const regExp: RegExp = new RegExp( - `if *\\(${variableMatch}\\(${hexMatch}\\) *[=|!]== *${variableMatch}\\(${hexMatch}\\)\\) *\\{`+ + `if *\\(${variableMatch}\\(${hexMatch}\\) *[=|!]== *${variableMatch}\\(${hexMatch}\\)\\) *\\{` + `(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\} *else *\\{`+ + `\\} *else *\\{` + `(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\}`, + `\\}`, 'g' ); const expectedMatchesLength: number = 5; @@ -33,16 +33,13 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const matches: RegExpMatchArray = obfuscatedCode.match(regExp); if (matches) { @@ -59,7 +56,7 @@ describe('DeadCodeInjectionTransformer', () => { const regexp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, + `\\};`, 'g' ); const expectedMatchesLength: number = 4; @@ -69,16 +66,13 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/block-statements-min-count.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const matches: RegExpMatchArray = obfuscatedCode.match(regexp); if (matches) { @@ -86,7 +80,7 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('shouldn\'t add dead code', () => { + it("shouldn't add dead code", () => { assert.equal(matchesLength, expectedMatchesLength); }); }); @@ -95,7 +89,7 @@ describe('DeadCodeInjectionTransformer', () => { const regexp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, + `\\};`, 'g' ); const expectedMatchesLength: number = 5; @@ -105,16 +99,13 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 0, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 0, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const matches: RegExpMatchArray = obfuscatedCode.match(regexp); if (matches) { @@ -122,7 +113,7 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('shouldn\'t add dead code', () => { + it("shouldn't add dead code", () => { assert.equal(matchesLength, expectedMatchesLength); }); }); @@ -132,7 +123,7 @@ describe('DeadCodeInjectionTransformer', () => { const functionRegExp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, + `\\};`, 'g' ); const functionDeclarationRegExp: RegExp = new RegExp( @@ -146,20 +137,21 @@ describe('DeadCodeInjectionTransformer', () => { functionDeclarationMatchesLength: number = 0; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/function-declaration-inside-block-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/function-declaration-inside-block-statement.js' + ); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const functionMatches: RegExpMatchArray = obfuscatedCode.match(functionRegExp); - const loopMatches: RegExpMatchArray = obfuscatedCode.match(functionDeclarationRegExp); + const loopMatches: RegExpMatchArray = ( + obfuscatedCode.match(functionDeclarationRegExp) + ); if (functionMatches) { functionMatchesLength = functionMatches.length; @@ -170,11 +162,11 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('match #1: shouldn\'t add dead code', () => { + it("match #1: shouldn't add dead code", () => { assert.equal(functionMatchesLength, expectedFunctionMatchesLength); }); - it('match #2: shouldn\'t add dead code', () => { + it("match #2: shouldn't add dead code", () => { assert.equal(functionDeclarationMatchesLength, expectedFunctionDeclarationMatchesLength); }); }); @@ -184,13 +176,13 @@ describe('DeadCodeInjectionTransformer', () => { const functionRegExp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, + `\\};`, 'g' ); const loopRegExp: RegExp = new RegExp( `for *\\(var ${variableMatch} *= *${hexMatch}; *${variableMatch} *< *${hexMatch}; *${variableMatch}\\+\\+\\) *\\{` + - `(?:continue|break);` + - `\\}`, + `(?:continue|break);` + + `\\}`, 'g' ); const expectedFunctionMatchesLength: number = 4; @@ -202,17 +194,16 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/break-continue-statement-1.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); - const functionMatches: RegExpMatchArray = obfuscatedCode.match(functionRegExp); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); + const functionMatches: RegExpMatchArray = ( + obfuscatedCode.match(functionRegExp) + ); const loopMatches: RegExpMatchArray = obfuscatedCode.match(loopRegExp); if (functionMatches) { @@ -224,11 +215,11 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('match #1: shouldn\'t add dead code', () => { + it("match #1: shouldn't add dead code", () => { assert.equal(functionMatchesLength, expectedFunctionMatchesLength); }); - it('match #2: shouldn\'t add dead code', () => { + it("match #2: shouldn't add dead code", () => { assert.equal(loopMatchesLength, expectedLoopMatchesLength); }); }); @@ -237,7 +228,7 @@ describe('DeadCodeInjectionTransformer', () => { const functionRegExp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, + `\\};`, 'g' ); const loopRegExp: RegExp = new RegExp( @@ -254,17 +245,16 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/break-continue-statement-2.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); - const functionMatches: RegExpMatchArray = obfuscatedCode.match(functionRegExp); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); + const functionMatches: RegExpMatchArray = ( + obfuscatedCode.match(functionRegExp) + ); const loopMatches: RegExpMatchArray = obfuscatedCode.match(loopRegExp); if (functionMatches) { @@ -276,11 +266,11 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('match #1: shouldn\'t add dead code', () => { + it("match #1: shouldn't add dead code", () => { assert.equal(functionMatchesLength, expectedFunctionMatchesLength); }); - it('match #2: shouldn\'t add dead code', () => { + it("match #2: shouldn't add dead code", () => { assert.equal(loopMatchesLength, expectedLoopMatchesLength); }); }); @@ -290,13 +280,10 @@ describe('DeadCodeInjectionTransformer', () => { const functionRegExp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, - 'g' - ); - const awaitExpressionRegExp: RegExp = new RegExp( - `await *${variableMatch}\\(\\)`, + `\\};`, 'g' ); + const awaitExpressionRegExp: RegExp = new RegExp(`await *${variableMatch}\\(\\)`, 'g'); const expectedFunctionMatchesLength: number = 4; const expectedAwaitExpressionMatchesLength: number = 1; @@ -306,18 +293,17 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/await-expression.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const functionMatches: RegExpMatchArray = obfuscatedCode.match(functionRegExp); - const awaitExpressionMatches: RegExpMatchArray = obfuscatedCode.match(awaitExpressionRegExp); + const awaitExpressionMatches: RegExpMatchArray = ( + obfuscatedCode.match(awaitExpressionRegExp) + ); if (functionMatches) { functionMatchesLength = functionMatches.length; @@ -328,11 +314,11 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('match #1: shouldn\'t add dead code', () => { + it("match #1: shouldn't add dead code", () => { assert.equal(functionMatchesLength, expectedFunctionMatchesLength); }); - it('match #2: shouldn\'t add dead code', () => { + it("match #2: shouldn't add dead code", () => { assert.equal(awaitExpressionMatchesLength, expectedAwaitExpressionMatchesLength); }); }); @@ -341,13 +327,10 @@ describe('DeadCodeInjectionTransformer', () => { const functionRegExp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, - 'g' - ); - const yieldExpressionRegExp: RegExp = new RegExp( - `yield *${variableMatch}\\(\\)`, + `\\};`, 'g' ); + const yieldExpressionRegExp: RegExp = new RegExp(`yield *${variableMatch}\\(\\)`, 'g'); const expectedFunctionMatchesLength: number = 4; const expectedAwaitExpressionMatchesLength: number = 1; @@ -357,18 +340,17 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/yield-expression.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const functionMatches: RegExpMatchArray = obfuscatedCode.match(functionRegExp); - const yieldExpressionMatches: RegExpMatchArray = obfuscatedCode.match(yieldExpressionRegExp); + const yieldExpressionMatches: RegExpMatchArray = ( + obfuscatedCode.match(yieldExpressionRegExp) + ); if (functionMatches) { functionMatchesLength = functionMatches.length; @@ -379,11 +361,11 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('match #1: shouldn\'t add dead code', () => { + it("match #1: shouldn't add dead code", () => { assert.equal(functionMatchesLength, expectedFunctionMatchesLength); }); - it('match #2: shouldn\'t add dead code', () => { + it("match #2: shouldn't add dead code", () => { assert.equal(yieldExpressionMatchesLength, expectedAwaitExpressionMatchesLength); }); }); @@ -392,13 +374,10 @@ describe('DeadCodeInjectionTransformer', () => { const functionRegExp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, - 'g' - ); - const superExpressionRegExp: RegExp = new RegExp( - `super *\\(\\);`, + `\\};`, 'g' ); + const superExpressionRegExp: RegExp = new RegExp(`super *\\(\\);`, 'g'); const expectedFunctionMatchesLength: number = 4; const expectedSuperExpressionMatchesLength: number = 1; @@ -408,18 +387,17 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/super-expression.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const functionMatches: RegExpMatchArray = obfuscatedCode.match(functionRegExp); - const superExpressionMatches: RegExpMatchArray = obfuscatedCode.match(superExpressionRegExp); + const superExpressionMatches: RegExpMatchArray = ( + obfuscatedCode.match(superExpressionRegExp) + ); if (functionMatches) { functionMatchesLength = functionMatches.length; @@ -430,11 +408,11 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('match #1: shouldn\'t add dead code', () => { + it("match #1: shouldn't add dead code", () => { assert.equal(functionMatchesLength, expectedFunctionMatchesLength); }); - it('match #2: shouldn\'t add dead code', () => { + it("match #2: shouldn't add dead code", () => { assert.equal(superExpressionMatchesLength, expectedSuperExpressionMatchesLength); }); }); @@ -443,7 +421,7 @@ describe('DeadCodeInjectionTransformer', () => { const functionRegExp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, + `\\};`, 'g' ); const awaitExpressionRegExp: RegExp = new RegExp( @@ -459,18 +437,17 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/for-await-expression.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const functionMatches: RegExpMatchArray = obfuscatedCode.match(functionRegExp); - const awaitExpressionMatches: RegExpMatchArray = obfuscatedCode.match(awaitExpressionRegExp); + const awaitExpressionMatches: RegExpMatchArray = ( + obfuscatedCode.match(awaitExpressionRegExp) + ); if (functionMatches) { functionMatchesLength = functionMatches.length; @@ -481,11 +458,11 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('match #1: shouldn\'t add dead code', () => { + it("match #1: shouldn't add dead code", () => { assert.equal(functionMatchesLength, expectedFunctionMatchesLength); }); - it('match #2: shouldn\'t add dead code', () => { + it("match #2: shouldn't add dead code", () => { assert.equal(awaitExpressionMatchesLength, expectedAwaitExpressionMatchesLength); }); }); @@ -494,13 +471,10 @@ describe('DeadCodeInjectionTransformer', () => { const functionRegExp: RegExp = new RegExp( `var ${variableMatch} *= *function *\\(\\) *\\{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\};`, - 'g' - ); - const privateIdentifierRegExp: RegExp = new RegExp( - `this\.#private *= *0x1;`, + `\\};`, 'g' ); + const privateIdentifierRegExp: RegExp = new RegExp(`this\.#private *= *0x1;`, 'g'); const expectedFunctionMatchesLength: number = 4; const expectedPrivateIdentifierMatchesLength: number = 1; @@ -510,18 +484,17 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/private-identifier.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); const functionMatches: RegExpMatchArray = obfuscatedCode.match(functionRegExp); - const privateIdentifierMatches: RegExpMatchArray = obfuscatedCode.match(privateIdentifierRegExp); + const privateIdentifierMatches: RegExpMatchArray = ( + obfuscatedCode.match(privateIdentifierRegExp) + ); if (functionMatches) { functionMatchesLength = functionMatches.length; @@ -532,11 +505,11 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('match #1: shouldn\'t add dead code', () => { + it("match #1: shouldn't add dead code", () => { assert.equal(functionMatchesLength, expectedFunctionMatchesLength); }); - it('match #2: shouldn\'t add dead code', () => { + it("match #2: shouldn't add dead code", () => { assert.equal(privateIdentifierMatchesLength, expectedPrivateIdentifierMatchesLength); }); }); @@ -550,34 +523,38 @@ describe('DeadCodeInjectionTransformer', () => { const ifMatch: string = `if *\\(!!\\[\\]\\) *\\{`; const functionMatch: string = `var ${variableMatch} *= *function *\\(\\) *\\{`; - const match1: string = `` + + const match1: string = + `` + `if *\\(${stringArrayCallMatch} *=== *${stringArrayCallMatch}\\) *\\{` + - `console\\[${stringArrayCallMatch}]\\(${stringArrayCallMatch}\\);` + + `console\\[${stringArrayCallMatch}]\\(${stringArrayCallMatch}\\);` + `\\} *else *\\{` + - `${variableMatch}\\(${stringArrayCallMatch}\\);` + + `${variableMatch}\\(${stringArrayCallMatch}\\);` + `\\}` + - ``; - const match2: string = `` + + ``; + const match2: string = + `` + `if *\\(${stringArrayCallMatch} *!== *${stringArrayCallMatch}\\) *\\{` + - `console\\[${stringArrayCallMatch}]\\(${stringArrayCallMatch}\\);` + + `console\\[${stringArrayCallMatch}]\\(${stringArrayCallMatch}\\);` + `\\} *else *\\{` + - `${variableMatch}\\(${stringArrayCallMatch}\\);` + + `${variableMatch}\\(${stringArrayCallMatch}\\);` + `\\}` + - ``; - const match3: string = `` + + ``; + const match3: string = + `` + `if *\\(${stringArrayCallMatch} *=== *${stringArrayCallMatch}\\) *\\{` + - `${variableMatch}\\(${stringArrayCallMatch}\\);` + + `${variableMatch}\\(${stringArrayCallMatch}\\);` + `\\} *else *\\{` + - `console\\[${stringArrayCallMatch}]\\(${stringArrayCallMatch}\\);` + + `console\\[${stringArrayCallMatch}]\\(${stringArrayCallMatch}\\);` + `\\}` + - ``; - const match4: string = `` + + ``; + const match4: string = + `` + `if *\\(${stringArrayCallMatch} *!== *${stringArrayCallMatch}\\) *\\{` + - `${variableMatch}\\(${stringArrayCallMatch}\\);` + + `${variableMatch}\\(${stringArrayCallMatch}\\);` + `\\} *else *\\{` + - `console\\[${stringArrayCallMatch}]\\(${stringArrayCallMatch}\\);` + + `console\\[${stringArrayCallMatch}]\\(${stringArrayCallMatch}\\);` + `\\}` + - ``; + ``; let distribution1: number = 0, distribution2: number = 0, @@ -598,17 +575,13 @@ describe('DeadCodeInjectionTransformer', () => { let count4: number = 0; for (let i = 0; i < samplesCount; i++) { - - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); if (regExp1.test(obfuscatedCode)) { count1++; @@ -648,7 +621,7 @@ describe('DeadCodeInjectionTransformer', () => { const regExp: RegExp = new RegExp( `if *\\(!!\\[\\]\\) *{` + `console\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\}` + `\\}` ); let obfuscatedCode: string; @@ -656,19 +629,16 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/block-scope-is-program-node.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t add dead code in block statements with `ProgramNode` block scope', () => { + it("shouldn't add dead code in block statements with `ProgramNode` block scope", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -679,17 +649,16 @@ describe('DeadCodeInjectionTransformer', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/obfuscation-of-dead-code-block-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/obfuscation-of-dead-code-block-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - debugProtection: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + debugProtection: true + }).getObfuscatedCode(); }); it('should correctly obfuscate dead-code block statements and prevent any exposing of internal variable names', () => { @@ -757,18 +726,17 @@ describe('DeadCodeInjectionTransformer', () => { * This should never happen. */ describe('Variant #1', () => { - const functionParameterMatch: string = `` + - `\\(function\\((\\w)\\){` + - ``; - const deadCodeMatch: string = `` + + const functionParameterMatch: string = `` + `\\(function\\((\\w)\\){` + ``; + const deadCodeMatch: string = + `` + `function \\w *\\(\\w\\) *{` + - `if *\\(.{0,30}\\) *{` + - `var (\\w).*?;` + - `} *else *{` + - `return *(\\w).*?;` + - `}` + + `if *\\(.{0,30}\\) *{` + + `var (\\w).*?;` + + `} *else *{` + + `return *(\\w).*?;` + `}` + - ``; + `}` + + ``; const functionParameterRegExp: RegExp = new RegExp(functionParameterMatch); const deadCodeRegExp: RegExp = new RegExp(deadCodeMatch); @@ -778,23 +746,20 @@ describe('DeadCodeInjectionTransformer', () => { variableDeclarationIdentifierName: string | null, obfuscatedCode: string; - before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/unique-names-for-dead-code-identifiers.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/unique-names-for-dead-code-identifiers.js' + ); for (let i: number = 0; i < 100; i++) { while (true) { try { - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); functionIdentifierName = getRegExpMatch(obfuscatedCode, functionParameterRegExp, 0); variableDeclarationIdentifierName = getRegExpMatch(obfuscatedCode, deadCodeRegExp, 0); returnIdentifierName = getRegExpMatch(obfuscatedCode, deadCodeRegExp, 1); @@ -821,18 +786,17 @@ describe('DeadCodeInjectionTransformer', () => { }); describe('Variant #2', () => { - const functionParameterMatch: string = `` + - `\\(function\\((\\w)\\){` + - ``; - const deadCodeMatch: string = `` + + const functionParameterMatch: string = `` + `\\(function\\((\\w)\\){` + ``; + const deadCodeMatch: string = + `` + `function \\w *\\(\\w\\) *{` + - `if *\\(.{0,30}\\) *{` + - `return *(\\w).{0,40};` + - `} *else *{` + - `var (\\w).*?;` + - `}` + + `if *\\(.{0,30}\\) *{` + + `return *(\\w).{0,40};` + + `} *else *{` + + `var (\\w).*?;` + `}` + - ``; + `}` + + ``; const functionParameterRegExp: RegExp = new RegExp(functionParameterMatch); const deadCodeRegExp: RegExp = new RegExp(deadCodeMatch); @@ -842,23 +806,20 @@ describe('DeadCodeInjectionTransformer', () => { variableDeclarationIdentifierName: string | null, obfuscatedCode: string; - before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/unique-names-for-dead-code-identifiers.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/unique-names-for-dead-code-identifiers.js' + ); for (let i: number = 0; i < 100; i++) { while (true) { try { - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); functionIdentifierName = getRegExpMatch(obfuscatedCode, functionParameterRegExp, 0); returnIdentifierName = getRegExpMatch(obfuscatedCode, deadCodeRegExp, 0); variableDeclarationIdentifierName = getRegExpMatch(obfuscatedCode, deadCodeRegExp, 1); @@ -888,8 +849,7 @@ describe('DeadCodeInjectionTransformer', () => { describe('Variant #9 - block statements with empty body', () => { const regExp: RegExp = new RegExp( - `function *${variableMatch} *\\(\\) *{ *} *` + - `${variableMatch} *\\(\\); *`, + `function *${variableMatch} *\\(\\) *{ *} *` + `${variableMatch} *\\(\\); *`, 'g' ); const expectedMatchesLength: number = 5; @@ -899,16 +859,13 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/block-statement-empty-body.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1 + }).getObfuscatedCode(); const functionMatches: RegExpMatchArray = obfuscatedCode.match(regExp); @@ -917,7 +874,7 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('shouldn\'t add dead code conditions to the block empty block statements', () => { + it("shouldn't add dead code conditions to the block empty block statements", () => { assert.isAtLeast(matchesLength, expectedMatchesLength); }); }); @@ -926,8 +883,8 @@ describe('DeadCodeInjectionTransformer', () => { describe('Variant #1: collecting of block statements', () => { const regExp: RegExp = new RegExp( `${variableMatch} *\\(\\); *` + - `var ${variableMatch} *= *0x2; *` + - `function *${variableMatch} *\\(\\) *{ *} *`, + `var ${variableMatch} *= *0x2; *` + + `function *${variableMatch} *\\(\\) *{ *} *`, 'g' ); const expectedMatchesLength: number = 5; @@ -935,18 +892,17 @@ describe('DeadCodeInjectionTransformer', () => { let matchesLength: number = 0; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/block-statement-with-scope-hoisting-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/block-statement-with-scope-hoisting-1.js' + ); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1 + }).getObfuscatedCode(); const functionMatches: RegExpMatchArray = obfuscatedCode.match(regExp); @@ -955,7 +911,7 @@ describe('DeadCodeInjectionTransformer', () => { } }); - it('shouldn\'t collect block statements with scope-hoisting', () => { + it("shouldn't collect block statements with scope-hoisting", () => { assert.equal(matchesLength, expectedMatchesLength); }); }); @@ -968,28 +924,27 @@ describe('DeadCodeInjectionTransformer', () => { `var ${variableMatch} *= *0x2; *` + `function *${variableMatch} *\\(\\) *{ *} *` + `var ${variableMatch} *= *0x3; *` + - `}`, + `}`, 'g' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/block-statement-with-scope-hoisting-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/block-statement-with-scope-hoisting-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t wrap block statements in dead code conditions', () => { + it("shouldn't wrap block statements in dead code conditions", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -998,13 +953,11 @@ describe('DeadCodeInjectionTransformer', () => { describe('Variant #11 - prevailing kind of variables of inserted code', () => { describe('Variant #1: base', () => { const variableDeclarationsRegExp: RegExp = new RegExp( - `const ${variableMatch} *= *\\[\\]; *` + - `var ${variableMatch} *= *\\[\\]; *`, + `const ${variableMatch} *= *\\[\\]; *` + `var ${variableMatch} *= *\\[\\]; *`, 'g' ); const invalidVariableDeclarationsRegExp: RegExp = new RegExp( - `var ${variableMatch} *= *\\[\\]; *` + - `var ${variableMatch} *= *\\[\\]; *`, + `var ${variableMatch} *= *\\[\\]; *` + `var ${variableMatch} *= *\\[\\]; *`, 'g' ); @@ -1022,29 +975,26 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1 + }).getObfuscatedCode(); }); - it('Match #1: shouldn\'t replace kinds of variables of inserted original code', () => { + it("Match #1: shouldn't replace kinds of variables of inserted original code", () => { assert.match(obfuscatedCode, variableDeclarationsRegExp); }); - it('Match #2: shouldn\'t replace kinds of variables of inserted original code', () => { + it("Match #2: shouldn't replace kinds of variables of inserted original code", () => { assert.notMatch(obfuscatedCode, invalidVariableDeclarationsRegExp); }); - it('Match #3: shouldn\'t replace kinds of variables of inserted original code', () => { + it("Match #3: shouldn't replace kinds of variables of inserted original code", () => { assert.match(obfuscatedCode, forLoopRegExp); }); - it('Match #4: shouldn\'t replace kinds of variables of inserted original code', () => { + it("Match #4: shouldn't replace kinds of variables of inserted original code", () => { assert.notMatch(obfuscatedCode, invalidForLoopRegExp); }); }); @@ -1053,11 +1003,11 @@ describe('DeadCodeInjectionTransformer', () => { describe('Variant #12 - correct integration with `stringArrayWrappersChainedCalls` option', () => { const regExp: RegExp = new RegExp( `var ${variableMatch} *= *${variableMatch}; *` + - `if *\\(${variableMatch}\\(${hexMatch}\\) *[=|!]== *${variableMatch}\\(${hexMatch}\\)\\) *\\{`+ + `if *\\(${variableMatch}\\(${hexMatch}\\) *[=|!]== *${variableMatch}\\(${hexMatch}\\)\\) *\\{` + `(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\} *else *\\{`+ + `\\} *else *\\{` + `(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` + - `\\}`, + `\\}`, 'g' ); const expectedMatchesLength: number = 5; @@ -1067,18 +1017,15 @@ describe('DeadCodeInjectionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input-1.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1, - stringArrayWrappersChainedCalls: true - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1, + stringArrayWrappersChainedCalls: true + }).getObfuscatedCode(); const matches: RegExpMatchArray = obfuscatedCode.match(regExp); if (matches) { @@ -1092,30 +1039,26 @@ describe('DeadCodeInjectionTransformer', () => { }); describe('Variant #13 - correct integration with `EvalCallExpressionTransformer`', () => { - const evalWithDeadCodeRegExp: RegExp = new RegExp( - `eval\\(\'if *\\(${variableMatch}`, - 'g' - ); + const evalWithDeadCodeRegExp: RegExp = new RegExp(`eval\\(\'if *\\(${variableMatch}`, 'g'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/eval-call-expression-transformer-integration.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/eval-call-expression-transformer-integration.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); console.log(obfuscatedCode); }); - it('match #1: shouldn\'t add dead code to the eval call expression', () => { + it("match #1: shouldn't add dead code to the eval call expression", () => { assert.notMatch(obfuscatedCode, evalWithDeadCodeRegExp); }); }); diff --git a/test/functional-tests/node-transformers/finalizing-transformers/directive-placement-transformer/DirectivePlacementTransformer.spec.ts b/test/functional-tests/node-transformers/finalizing-transformers/directive-placement-transformer/DirectivePlacementTransformer.spec.ts index 3ad9387a7..35862d378 100644 --- a/test/functional-tests/node-transformers/finalizing-transformers/directive-placement-transformer/DirectivePlacementTransformer.spec.ts +++ b/test/functional-tests/node-transformers/finalizing-transformers/directive-placement-transformer/DirectivePlacementTransformer.spec.ts @@ -12,24 +12,18 @@ describe('DirectivePlacementTransformer', function () { describe('Variant #1: program scope', () => { describe('Variant #1: directive at the top of program scope', () => { - const directiveRegExp: RegExp = new RegExp( - '^\'use strict\';.*' + - getStringArrayRegExp(['test']).source - ); + const directiveRegExp: RegExp = new RegExp("^'use strict';.*" + getStringArrayRegExp(['test']).source); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/top-of-program-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should keep directive at the top of program scope', () => { @@ -40,8 +34,7 @@ describe('DirectivePlacementTransformer', function () { describe('Variant #2: directive-like string literal at the middle of program scope', () => { const stringArrayStorageRegExp: RegExp = getStringArrayRegExp(['test', 'use\\\\x20strict']); const directiveRegExp: RegExp = new RegExp( - 'var test *= *_0x([a-f0-9]){4}\\(0x0\\);.*' + - '_0x([a-f0-9]){4}\\(0x1\\);' + 'var test *= *_0x([a-f0-9]){4}\\(0x0\\);.*' + '_0x([a-f0-9]){4}\\(0x1\\);' ); let obfuscatedCode: string; @@ -49,14 +42,11 @@ describe('DirectivePlacementTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/middle-of-program-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add directive-like string literal to the string array', () => { @@ -73,7 +63,7 @@ describe('DirectivePlacementTransformer', function () { describe('Variant #1: directive at the top of function declaration scope', () => { const directiveRegExp: RegExp = new RegExp( 'function test\\(\\) *{ *' + - '\'use strict\'; *' + + "'use strict'; *" + 'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4}; *' + 'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x0\\);' ); @@ -83,15 +73,12 @@ describe('DirectivePlacementTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/top-of-function-declaration-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should keep directive at the top of function declaration scope', () => { @@ -112,28 +99,25 @@ describe('DirectivePlacementTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/middle-of-function-declaration-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should keep directive-like string literal at the middle of function declaration scope', () => { assert.match(obfuscatedCode, directiveRegExp); }); - }) + }); }); describe('Variant #3: function expression scope', () => { describe('Variant #1: directive at the top of function expression scope', () => { const directiveRegExp: RegExp = new RegExp( 'var test *= *function *\\(\\) *{ *' + - '\'use strict\'; *' + + "'use strict'; *" + 'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4}; *' + 'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x0\\);' ); @@ -143,15 +127,12 @@ describe('DirectivePlacementTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/top-of-function-expression-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should keep directive at the top of function expression scope', () => { @@ -172,28 +153,25 @@ describe('DirectivePlacementTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/middle-of-function-expression-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should keep directive-like string literal at the middle of function expression scope', () => { assert.match(obfuscatedCode, directiveRegExp); }); - }) + }); }); describe('Variant #4: arrow function expression scope', () => { describe('Variant #1: directive at the top of arrow function expression scope', () => { const directiveRegExp: RegExp = new RegExp( 'var test *= *\\(\\) *=> *{ *' + - '\'use strict\'; *' + + "'use strict'; *" + 'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4}; *' + 'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x0\\);' ); @@ -201,17 +179,16 @@ describe('DirectivePlacementTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/top-of-arrow-function-expression-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/top-of-arrow-function-expression-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should keep directive at the top of arrow function expression scope', () => { @@ -230,22 +207,21 @@ describe('DirectivePlacementTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/middle-of-arrow-function-expression-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/middle-of-arrow-function-expression-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should keep directive-like string literal at the middle of arrow function expression scope', () => { assert.match(obfuscatedCode, directiveRegExp); }); - }) + }); }); }); diff --git a/test/functional-tests/node-transformers/finalizing-transformers/escape-sequence-transformer/EscapeSequenceTransformer.spec.ts b/test/functional-tests/node-transformers/finalizing-transformers/escape-sequence-transformer/EscapeSequenceTransformer.spec.ts index 016f06f55..d20ffa39a 100644 --- a/test/functional-tests/node-transformers/finalizing-transformers/escape-sequence-transformer/EscapeSequenceTransformer.spec.ts +++ b/test/functional-tests/node-transformers/finalizing-transformers/escape-sequence-transformer/EscapeSequenceTransformer.spec.ts @@ -19,17 +19,15 @@ describe('EscapeSequenceTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/error-when-non-latin.js'); - testFunc = () => JavaScriptObfuscator.obfuscate( - code, - { + testFunc = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, stringArray: true, stringArrayThreshold: 1 - } - ); + }); }); - it('should\'t throw an error', () => { + it("should't throw an error", () => { assert.doesNotThrow(testFunc); }); }); @@ -42,14 +40,10 @@ describe('EscapeSequenceTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - unicodeEscapeSequence: true - - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + unicodeEscapeSequence: true + }).getObfuscatedCode(); }); it('should replace literal node value with unicode escape sequence', () => { @@ -66,18 +60,13 @@ describe('EscapeSequenceTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumericString - ], - stringArrayThreshold: 1, - unicodeEscapeSequence: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumericString], + stringArrayThreshold: 1, + unicodeEscapeSequence: true + }).getObfuscatedCode(); }); it('match #1: should replace literal node value with unicode escape sequence from string array', () => { @@ -99,14 +88,11 @@ describe('EscapeSequenceTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - reservedStrings: ['foo'], - unicodeEscapeSequence: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + reservedStrings: ['foo'], + unicodeEscapeSequence: true + }).getObfuscatedCode(); }); it('match #1: should ignore reserved strings', () => { @@ -126,13 +112,10 @@ describe('EscapeSequenceTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - reservedStrings: ['a'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + reservedStrings: ['a'] + }).getObfuscatedCode(); }); it('match #1: should ignore reserved strings', () => { @@ -150,14 +133,11 @@ describe('EscapeSequenceTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/force-transform-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: ['bar'], - unicodeEscapeSequence: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: ['bar'], + unicodeEscapeSequence: false + }).getObfuscatedCode(); }); it('match #1: should not encode force transform string with unicode escape sequence', () => { @@ -172,15 +152,15 @@ describe('EscapeSequenceTransformer', function () { describe('Variant #6: `stringArrayWrappersCount` option enabled', () => { const stringArrayCallRegExp: RegExp = new RegExp( 'const f *= *b;.*' + - 'const foo *= *f\\(\'\\\\x30\\\\x78\\\\x30\'\\);.*' + - 'const bar *= *f\\(\'\\\\x30\\\\x78\\\\x31\'\\);.*' + - 'const baz *= *f\\(\'\\\\x30\\\\x78\\\\x32\'\\);.*' + - 'function test\\( *\\) *{' + + "const foo *= *f\\('\\\\x30\\\\x78\\\\x30'\\);.*" + + "const bar *= *f\\('\\\\x30\\\\x78\\\\x31'\\);.*" + + "const baz *= *f\\('\\\\x30\\\\x78\\\\x32'\\);.*" + + 'function test\\( *\\) *{' + 'const g *= *f;' + - 'const c *= *g\\(\'\\\\x30\\\\x78\\\\x33\'\\);' + - 'const d *= *g\\(\'\\\\x30\\\\x78\\\\x34\'\\);' + - 'const e *= *g\\(\'\\\\x30\\\\x78\\\\x35\'\\);' + - '}' + "const c *= *g\\('\\\\x30\\\\x78\\\\x33'\\);" + + "const d *= *g\\('\\\\x30\\\\x78\\\\x34'\\);" + + "const e *= *g\\('\\\\x30\\\\x78\\\\x35'\\);" + + '}' ); let obfuscatedCode: string; @@ -188,21 +168,16 @@ describe('EscapeSequenceTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumericString - ], - stringArrayThreshold: 1, - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 1, - unicodeEscapeSequence: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumericString], + stringArrayThreshold: 1, + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 1, + unicodeEscapeSequence: true + }).getObfuscatedCode(); }); it('should encode calls to the string array wrappers', () => { diff --git a/test/functional-tests/node-transformers/initializing-transformers/comments-transformer/CommentsTransformer.spec.ts b/test/functional-tests/node-transformers/initializing-transformers/comments-transformer/CommentsTransformer.spec.ts index ef1d22af0..cce522b84 100644 --- a/test/functional-tests/node-transformers/initializing-transformers/comments-transformer/CommentsTransformer.spec.ts +++ b/test/functional-tests/node-transformers/initializing-transformers/comments-transformer/CommentsTransformer.spec.ts @@ -18,12 +18,9 @@ describe('CommentsTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/no-preserved-words.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should remove comments without preserved words', () => { @@ -39,12 +36,9 @@ describe('CommentsTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/preserved-words.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should keep comments with preserved words', () => { @@ -60,12 +54,9 @@ describe('CommentsTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/combined-words-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should keep comments with preserved words', () => { @@ -74,26 +65,25 @@ describe('CommentsTransformer', () => { }); describe('Variant #4: comment with preserved and non-preserved words', () => { - const regExp: RegExp = new RegExp(``+ - `^\\/\\*\\* *${lineSeparatorEscaped}` + - ` *\\* *@license *${lineSeparatorEscaped}` + - ` *\\* *test${lineSeparatorEscaped}` + - ` *\\*\\/${lineSeparatorEscaped}` + - `var test *= *0x1;` + - ` *\\/\\*\\* *@preserved *\\*\\/$` + - ``); + const regExp: RegExp = new RegExp( + `` + + `^\\/\\*\\* *${lineSeparatorEscaped}` + + ` *\\* *@license *${lineSeparatorEscaped}` + + ` *\\* *test${lineSeparatorEscaped}` + + ` *\\*\\/${lineSeparatorEscaped}` + + `var test *= *0x1;` + + ` *\\/\\*\\* *@preserved *\\*\\/$` + + `` + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/combined-words-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should keep comments with preserved words', () => { @@ -107,12 +97,9 @@ describe('CommentsTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/comments-only-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should remove comment without preserved words', () => { @@ -128,12 +115,9 @@ describe('CommentsTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/comments-only-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should keep comments with preserved words', () => { @@ -144,23 +128,21 @@ describe('CommentsTransformer', () => { describe('Variant #7: simple comment with preserved words and additional code helper is inserted', () => { describe('Variant #1: `stringArray` code helper', () => { const regExp: RegExp = new RegExp( - '^\\/\\/ *@license *test *comment *\\n*.*' + - getStringArrayRegExp(['abc']).source + '^\\/\\/ *@license *test *comment *\\n*.*' + getStringArrayRegExp(['abc']).source ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/preserved-words-additional-code-helper-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/preserved-words-additional-code-helper-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should keep comments with preserved words and move heading comment to the top', () => { @@ -171,22 +153,21 @@ describe('CommentsTransformer', () => { describe('Variant #2: `transformObjectKeys` code helper', () => { const regExp: RegExp = new RegExp( '^\\/\\/ *@license *test *comment *\\n*var _0x([a-f0-9]){4,6} *= *{};\\n*' + - '_0x([a-f0-9]){4,6}\\[\'foo\'] *= *\'bar\';\\n*' + - 'var test *= *_0x([a-f0-9]){4,6};$' + "_0x([a-f0-9]){4,6}\\['foo'] *= *'bar';\\n*" + + 'var test *= *_0x([a-f0-9]){4,6};$' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/preserved-words-additional-code-helper-2.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - transformObjectKeys: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/preserved-words-additional-code-helper-2.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should keep comments with preserved words and move heading comment to the top', () => { diff --git a/test/functional-tests/node-transformers/preparing-transformers/eval-call-expression-transformer/EvalCallExpressionTransformer.spec.ts b/test/functional-tests/node-transformers/preparing-transformers/eval-call-expression-transformer/EvalCallExpressionTransformer.spec.ts index 0032215d0..b438ae1cb 100644 --- a/test/functional-tests/node-transformers/preparing-transformers/eval-call-expression-transformer/EvalCallExpressionTransformer.spec.ts +++ b/test/functional-tests/node-transformers/preparing-transformers/eval-call-expression-transformer/EvalCallExpressionTransformer.spec.ts @@ -22,12 +22,9 @@ describe('EvalCallExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-reference.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); functionIdentifierName = getRegExpMatch(obfuscatedCode, functionIdentifierRegExp); variableReferenceIdentifierName = getRegExpMatch(obfuscatedCode, evalExpressionRegExp); @@ -53,12 +50,9 @@ describe('EvalCallExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/call-expression-identifier-reference.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); functionIdentifierName = getRegExpMatch(obfuscatedCode, functionIdentifierRegExp); variableReferenceIdentifierName = getRegExpMatch(obfuscatedCode, evalExpressionRegExp); @@ -81,12 +75,9 @@ describe('EvalCallExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/multiple-statements-eval.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should obfuscate eval string', () => { @@ -97,24 +88,20 @@ describe('EvalCallExpressionTransformer', () => { describe('Variant #4: string array calls wrapper call', () => { describe('Variant #1: hexadecimal number indexes type', () => { const stringArrayRegExp: RegExp = getStringArrayRegExp(['log', 'bar']); - const stringArrayCallsWrapperRegExp: RegExp = /eval *\('console\[_0x([a-f0-9]){4,6}\(0\)]\(_0x([a-f0-9]){4,6}\(1\)\);'\);/; + const stringArrayCallsWrapperRegExp: RegExp = + /eval *\('console\[_0x([a-f0-9]){4,6}\(0\)]\(_0x([a-f0-9]){4,6}\(1\)\);'\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/string-array-calls-wrapper-call.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumber - ], - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumber], + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should add strings from eval expression to the string array', () => { @@ -128,24 +115,20 @@ describe('EvalCallExpressionTransformer', () => { describe('Variant #1: hexadecimal numeric string indexes type', () => { const stringArrayRegExp: RegExp = getStringArrayRegExp(['log', 'bar']); - const stringArrayCallsWrapperRegExp: RegExp = /eval *\('console\[_0x([a-f0-9]){4,6}\(\\'0x0\\'\)]\(_0x([a-f0-9]){4,6}\(\\'0x1\\'\)\);'\);/; + const stringArrayCallsWrapperRegExp: RegExp = + /eval *\('console\[_0x([a-f0-9]){4,6}\(\\'0x0\\'\)]\(_0x([a-f0-9]){4,6}\(\\'0x1\\'\)\);'\);/; let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/string-array-calls-wrapper-call.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumericString - ], - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumericString], + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should add strings from eval expression to the string array', () => { @@ -169,12 +152,9 @@ describe('EvalCallExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/eval-expression-as-argument.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); functionIdentifierName = getRegExpMatch(obfuscatedCode, functionIdentifierRegExp); variableReferenceIdentifierName = getRegExpMatch(obfuscatedCode, evalExpressionRegExp); @@ -190,15 +170,17 @@ describe('EvalCallExpressionTransformer', () => { }); describe('Variant #6: nested eval expressions', () => { - const functionIdentifierRegExp: RegExp = /function *_0x(?:[a-f0-9]){4,6} *\((_0x(?:[a-f0-9]){4,6}), *(_0x(?:[a-f0-9]){4,6})\)/; - const evalExpressionMatch: string = `` + + const functionIdentifierRegExp: RegExp = + /function *_0x(?:[a-f0-9]){4,6} *\((_0x(?:[a-f0-9]){4,6}), *(_0x(?:[a-f0-9]){4,6})\)/; + const evalExpressionMatch: string = + `` + `eval *\\('` + - `var (_0x(?:[a-f0-9]){4,6}) *= *(_0x(?:[a-f0-9]){4,6}) *\\+ *(_0x(?:[a-f0-9]){4,6});` + - `eval\\(\\\\'` + - `(_0x(?:[a-f0-9]){4,6}) *\\+ *(_0x(?:[a-f0-9]){4,6});` + - `\\\\'\\);` + + `var (_0x(?:[a-f0-9]){4,6}) *= *(_0x(?:[a-f0-9]){4,6}) *\\+ *(_0x(?:[a-f0-9]){4,6});` + + `eval\\(\\\\'` + + `(_0x(?:[a-f0-9]){4,6}) *\\+ *(_0x(?:[a-f0-9]){4,6});` + + `\\\\'\\);` + `'\\);` + - ``; + ``; const evalExpressionRegExp: RegExp = new RegExp(evalExpressionMatch); const expectedEvaluationResult: number = 4; @@ -215,12 +197,9 @@ describe('EvalCallExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/nested-eval-expressions.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); functionIdentifierAName = getRegExpMatch(obfuscatedCode, functionIdentifierRegExp, 0); functionIdentifierBName = getRegExpMatch(obfuscatedCode, functionIdentifierRegExp, 1); @@ -267,17 +246,14 @@ describe('EvalCallExpressionTransformer', () => { describe('Variant #7: wrong eval string', () => { const evalExpressionRegExp: RegExp = /eval *\('~'\);/; - let obfuscatedCode: string + let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrong-eval-string.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should skip obfuscation of eval string', () => { @@ -296,12 +272,9 @@ describe('EvalCallExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/eval-expression-template-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); functionIdentifierName = getRegExpMatch(obfuscatedCode, functionIdentifierRegExp); variableReferenceIdentifierName = getRegExpMatch(obfuscatedCode, evalExpressionRegExp); @@ -318,13 +291,14 @@ describe('EvalCallExpressionTransformer', () => { describe('Variant #9: integration with control flow flattening', () => { const variableMatch: string = '_0x([a-f0-9]){4,6}'; - const controlFlowStorageNodeMatch: string = `` + + const controlFlowStorageNodeMatch: string = + `` + `var ${variableMatch} *= *\\{` + - `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}\\) *\\{` + - `return *${variableMatch} *\\+ *${variableMatch};` + - `\\}` + + `'\\w{5}' *: *function *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `return *${variableMatch} *\\+ *${variableMatch};` + + `\\}` + `\\};` + - ``; + ``; const controlFlowStorageNodeRegExp: RegExp = new RegExp(controlFlowStorageNodeMatch); const evalExpressionRegExp: RegExp = new RegExp( `eval *\\('${variableMatch}\\[\\\\'\\w{5}\\\\']\\(${variableMatch}, *${variableMatch}\\);'\\);` @@ -335,14 +309,11 @@ describe('EvalCallExpressionTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/control-flow-flattening-integration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('should add control flow storage node', () => { diff --git a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec.ts b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec.ts index 2b08f7ea1..55da05b23 100644 --- a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec.ts +++ b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec.ts @@ -9,7 +9,7 @@ import { readFileAsString } from '../../../../../helpers/readFileAsString'; describe('BlackListObfuscatingGuard', () => { describe('check', () => { - describe('`\'use strict\';` operator', () => { + describe("`'use strict';` operator", () => { const useStrictOperatorRegExp: RegExp = /'use *strict';/; const stringArrayLatinRegExp: RegExp = getStringArrayRegExp(['abc']); const stringArrayCallRegExp: RegExp = /var test *= *_0x(\w){4}\(0x0\)/; @@ -19,17 +19,14 @@ describe('BlackListObfuscatingGuard', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/use-strict-operator.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t obfuscate `use strict` operator', () => { + it("match #1: shouldn't obfuscate `use strict` operator", () => { assert.match(obfuscatedCode, useStrictOperatorRegExp); }); diff --git a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts index 0d77c5702..c8822dfb0 100644 --- a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts +++ b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts @@ -19,12 +19,9 @@ describe('ConditionalCommentObfuscatingGuard', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should remove `disable` conditional comment from the code', () => { @@ -56,12 +53,9 @@ describe('ConditionalCommentObfuscatingGuard', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/disable-and-enable-comments-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should remove `disable` conditional comment from the code', () => { @@ -94,13 +88,10 @@ describe('ConditionalCommentObfuscatingGuard', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/disable-and-enable-comments-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('match #1: should ignore variable declaration after `disable` conditional comment', () => { @@ -121,12 +112,9 @@ describe('ConditionalCommentObfuscatingGuard', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/disable-from-beginning.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should ignore variable declaration after `disable` conditional comment', () => { @@ -139,7 +127,8 @@ describe('ConditionalCommentObfuscatingGuard', () => { }); describe('Variant #5: `disable` and `enable` conditional comments with dead code injection', () => { - const obfuscatedFunctionExpressionRegExp: RegExp = /var _0x([a-f0-9]){4,6} *= *function *\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\) *{/g; + const obfuscatedFunctionExpressionRegExp: RegExp = + /var _0x([a-f0-9]){4,6} *= *function *\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\) *{/g; const expectedObfuscatedFunctionExpressionLength: number = 3; const ignoredFunctionExpression1RegExp: RegExp = /var bar *= *function *\(a, *b, *c\) *{/; @@ -158,21 +147,17 @@ describe('ConditionalCommentObfuscatingGuard', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/dead-code-injection.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1 + }).getObfuscatedCode(); const obfuscatedFunctionExpressionMatches: RegExpMatchArray | null = obfuscatedCode.match( obfuscatedFunctionExpressionRegExp ); - const obfuscatedFunctionCallMatches: RegExpMatchArray | null = obfuscatedCode.match( - obfuscatedFunctionCallRegExp - ); + const obfuscatedFunctionCallMatches: RegExpMatchArray | null = + obfuscatedCode.match(obfuscatedFunctionCallRegExp); obfuscatedFunctionExpressionMatchesLength = obfuscatedFunctionExpressionMatches ? obfuscatedFunctionExpressionMatches.length @@ -209,7 +194,8 @@ describe('ConditionalCommentObfuscatingGuard', () => { }); describe('Variant #6: `disable` and `enable` conditional comments with control flow flattening', () => { - const obfuscatedVariableDeclarationRegExp: RegExp = /var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\['\w{5}'];/; + const obfuscatedVariableDeclarationRegExp: RegExp = + /var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\['\w{5}'];/; const ignoredVariableDeclarationRegExp: RegExp = /var bar *= *'bar';/; let obfuscatedCode: string; @@ -217,14 +203,11 @@ describe('ConditionalCommentObfuscatingGuard', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/control-flow-flattening.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should obfuscate variable declaration before `disable` conditional comment', () => { diff --git a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/force-transform-string-obfuscating-guard/ForceTransformStringObfuscatingGuard.spec.ts b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/force-transform-string-obfuscating-guard/ForceTransformStringObfuscatingGuard.spec.ts index d4d0784ab..85be4c193 100644 --- a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/force-transform-string-obfuscating-guard/ForceTransformStringObfuscatingGuard.spec.ts +++ b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/force-transform-string-obfuscating-guard/ForceTransformStringObfuscatingGuard.spec.ts @@ -11,26 +11,20 @@ import { readFileAsString } from '../../../../../helpers/readFileAsString'; describe('ForceTransformStringObfuscatingGuard', () => { describe('check', () => { describe('`forceTransformStrings` option is enabled', () => { - const obfuscatingGuardRegExp: RegExp = new RegExp( - 'var foo *= *\'foo\';.*' + - 'var bar *= *b\\(0x0\\);' - ); + const obfuscatingGuardRegExp: RegExp = new RegExp("var foo *= *'foo';.*" + 'var bar *= *b\\(0x0\\);'); let obfuscatedCode: string; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/base-behaviour.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: ['bar'], - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: ['bar'], + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 0 + }).getObfuscatedCode(); }); it('match #1: should obfuscate force transform strings', () => { @@ -39,29 +33,23 @@ describe('ForceTransformStringObfuscatingGuard', () => { }); describe('`forceTransformStrings` option is disabled', () => { - const obfuscatingGuardRegExp: RegExp = new RegExp( - 'var foo *= *\'foo\';' + - 'var bar *= *\'bar\';' - ); + const obfuscatingGuardRegExp: RegExp = new RegExp("var foo *= *'foo';" + "var bar *= *'bar';"); let obfuscatedCode: string; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/base-behaviour.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: [], - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: [], + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 0 + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t obfuscate strings', () => { + it("match #1: shouldn't obfuscate strings", () => { assert.match(obfuscatedCode, obfuscatingGuardRegExp); }); }); diff --git a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/ignored-import-obfuscating-guard/IgnoredImportObfuscatingGuard.spec.ts b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/ignored-import-obfuscating-guard/IgnoredImportObfuscatingGuard.spec.ts index fe6e71671..ea77a67a1 100644 --- a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/ignored-import-obfuscating-guard/IgnoredImportObfuscatingGuard.spec.ts +++ b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/ignored-import-obfuscating-guard/IgnoredImportObfuscatingGuard.spec.ts @@ -10,10 +10,10 @@ describe('IgnoredImportObfuscatingGuard', () => { describe('check', () => { describe('`ignoreImports` option is enabled', () => { const obfuscatingGuardRegExp: RegExp = new RegExp( - 'const foo *= *require\\(\'\\./foo\'\\);.*' + - 'import _0x(?:[a-f0-9]){4,6} from *\'\\./bar\';.*' + - 'const baz *= *_0x(?:[a-f0-9]){4,6}\\(0x0\\);.*' + - 'const bark *= *await import\\(\'\\./bark\'\\);' + "const foo *= *require\\('\\./foo'\\);.*" + + "import _0x(?:[a-f0-9]){4,6} from *'\\./bar';.*" + + 'const baz *= *_0x(?:[a-f0-9]){4,6}\\(0x0\\);.*' + + "const bark *= *await import\\('\\./bark'\\);" ); let obfuscatedCode: string; @@ -21,18 +21,15 @@ describe('IgnoredImportObfuscatingGuard', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/base-behaviour.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - ignoreImports: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + ignoreImports: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t obfuscate imports', () => { + it("match #1: shouldn't obfuscate imports", () => { assert.match(obfuscatedCode, obfuscatingGuardRegExp); }); }); @@ -40,9 +37,9 @@ describe('IgnoredImportObfuscatingGuard', () => { describe('`ignoreImports` option is disabled', () => { const obfuscatingGuardRegExp: RegExp = new RegExp( 'const foo *= *require\\(_0x(?:[a-f0-9]){4,6}\\(0x0\\)\\);.*' + - 'import _0x(?:[a-f0-9]){4,6} from *\'\\./bar\';.*' + - 'const baz *= *_0x(?:[a-f0-9]){4,6}\\(0x1\\);.*' + - 'const bark *= *await import\\(_0x(?:[a-f0-9]){4,6}\\(0x2\\)\\);' + "import _0x(?:[a-f0-9]){4,6} from *'\\./bar';.*" + + 'const baz *= *_0x(?:[a-f0-9]){4,6}\\(0x1\\);.*' + + 'const bark *= *await import\\(_0x(?:[a-f0-9]){4,6}\\(0x2\\)\\);' ); let obfuscatedCode: string; @@ -50,15 +47,12 @@ describe('IgnoredImportObfuscatingGuard', () => { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/base-behaviour.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - ignoreImports: false, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + ignoreImports: false, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should obfuscate imports', () => { diff --git a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/reserved-string-obfuscating-guard/ReservedStringObfuscatingGuard.spec.ts b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/reserved-string-obfuscating-guard/ReservedStringObfuscatingGuard.spec.ts index 206ec6586..2b25bac2a 100644 --- a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/reserved-string-obfuscating-guard/ReservedStringObfuscatingGuard.spec.ts +++ b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/reserved-string-obfuscating-guard/ReservedStringObfuscatingGuard.spec.ts @@ -9,46 +9,42 @@ import { readFileAsString } from '../../../../../helpers/readFileAsString'; describe('ReservedStringObfuscatingGuard', () => { describe('check', () => { describe('`reservedStrings` option is enabled', () => { - const obfuscatingGuardRegExp: RegExp = /var test1 *= *'foo' *\+ *'foo'; *var test2 *= *'barbar'; *var test3 *= *'baz' *\+ *'baz';/; + const obfuscatingGuardRegExp: RegExp = + /var test1 *= *'foo' *\+ *'foo'; *var test2 *= *'barbar'; *var test3 *= *'baz' *\+ *'baz';/; let obfuscatedCode: string; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/base-behaviour.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - reservedStrings: ['bar'], - splitStrings: true, - splitStringsChunkLength: 3 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + reservedStrings: ['bar'], + splitStrings: true, + splitStringsChunkLength: 3 + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t obfuscate reserved strings', () => { + it("match #1: shouldn't obfuscate reserved strings", () => { assert.match(obfuscatedCode, obfuscatingGuardRegExp); }); }); describe('`reservedStrings` option is disabled', () => { - const obfuscatingGuardRegExp: RegExp = /var test1 *= *'foo' *\+ *'foo'; *var test2 *= *'bar' *\+ *'bar'; *var test3 *= *'baz' *\+ *'baz';/; + const obfuscatingGuardRegExp: RegExp = + /var test1 *= *'foo' *\+ *'foo'; *var test2 *= *'bar' *\+ *'bar'; *var test3 *= *'baz' *\+ *'baz';/; let obfuscatedCode: string; beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/base-behaviour.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - reservedStrings: [], - splitStrings: true, - splitStringsChunkLength: 3 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + reservedStrings: [], + splitStrings: true, + splitStringsChunkLength: 3 + }).getObfuscatedCode(); }); it('match #1: should obfuscate all strings', () => { diff --git a/test/functional-tests/node-transformers/preparing-transformers/variable-preserve-transformer/VariablePreserveTransformer.spec.ts b/test/functional-tests/node-transformers/preparing-transformers/variable-preserve-transformer/VariablePreserveTransformer.spec.ts index 17895c56b..1aab5aa12 100644 --- a/test/functional-tests/node-transformers/preparing-transformers/variable-preserve-transformer/VariablePreserveTransformer.spec.ts +++ b/test/functional-tests/node-transformers/preparing-transformers/variable-preserve-transformer/VariablePreserveTransformer.spec.ts @@ -21,17 +21,16 @@ describe('VariablePreserveTransformer', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-identifier-name-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: 'mangled', - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-identifier-name-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: 'mangled', + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should generate non-preserved name for string array storage', () => { @@ -53,18 +52,17 @@ describe('VariablePreserveTransformer', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-identifier-name-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: 'mangled', - renameGlobals: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/string-array-storage-identifier-name-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: 'mangled', + renameGlobals: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should generate non-preserved name for string array storage', () => { @@ -85,16 +83,15 @@ describe('VariablePreserveTransformer', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/transform-object-keys-identifier-name-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: 'mangled', - transformObjectKeys: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/transform-object-keys-identifier-name-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: 'mangled', + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should generate non-preserved name for `transformObjectKeys` identifier', () => { @@ -113,17 +110,16 @@ describe('VariablePreserveTransformer', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/transform-object-keys-identifier-name-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: 'mangled', - renameGlobals: true, - transformObjectKeys: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/transform-object-keys-identifier-name-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: 'mangled', + renameGlobals: true, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('should generate non-preserved name for `transformObjectKeys` identifier', () => { @@ -146,14 +142,11 @@ describe('VariablePreserveTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/ignored-node-identifier-name-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: 'mangled', - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: 'mangled', + renameGlobals: true + }).getObfuscatedCode(); }); it('should generate non-preserved name for global identifier', () => { @@ -176,16 +169,15 @@ describe('VariablePreserveTransformer', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/destructed-object-property-identifier-name-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: 'mangled', - renameGlobals: false - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/destructed-object-property-identifier-name-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: 'mangled', + renameGlobals: false + }).getObfuscatedCode(); }); it('should generate non-preserved name for variable name', () => { @@ -205,16 +197,15 @@ describe('VariablePreserveTransformer', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/destructed-object-property-identifier-name-2.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: 'mangled', - renameGlobals: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/destructed-object-property-identifier-name-2.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: 'mangled', + renameGlobals: true + }).getObfuscatedCode(); }); it('should generate non-preserved name for variable declaration', () => { @@ -238,16 +229,15 @@ describe('VariablePreserveTransformer', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/destructed-object-property-identifier-name-3.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: 'mangled', - renameGlobals: false - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/destructed-object-property-identifier-name-3.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: 'mangled', + renameGlobals: false + }).getObfuscatedCode(); }); it('should generate non-preserved name for variable declaration', () => { diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/identifier-replacer/IdentifierReplacer.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/identifier-replacer/IdentifierReplacer.spec.ts index 42c8baccb..26da60efd 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/identifier-replacer/IdentifierReplacer.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/identifier-replacer/IdentifierReplacer.spec.ts @@ -14,20 +14,14 @@ describe('IdentifierReplacer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/local-reserved-names.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - reservedNames: ['[abc|ghi]'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + reservedNames: ['[abc|ghi]'] + }).getObfuscatedCode(); }); it('Should keep reserved names without transformations when `reservedNames` option is enabled', () => { - assert.match( - obfuscatedCode, - /var abc *= *0x1; *var _0x([a-f0-9]){4,6} *= *0x2; *var ghi *= *0x3;/ - ); + assert.match(obfuscatedCode, /var abc *= *0x1; *var _0x([a-f0-9]){4,6} *= *0x2; *var ghi *= *0x3;/); }); }); @@ -37,21 +31,15 @@ describe('IdentifierReplacer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/global-reserved-names.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - reservedNames: ['[abc|ghi]'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + reservedNames: ['[abc|ghi]'] + }).getObfuscatedCode(); }); it('Should keep reserved names without transformations when `reservedNames` option is enabled', () => { - assert.match( - obfuscatedCode, - /var abc *= *0x1; *var _0x([a-f0-9]){4,6} *= *0x2; *var ghi *= *0x3;/ - ); + assert.match(obfuscatedCode, /var abc *= *0x1; *var _0x([a-f0-9]){4,6} *= *0x2; *var ghi *= *0x3;/); }); }); }); diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/labeled-statement-transformer/LabeledStatementTransformer.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/labeled-statement-transformer/LabeledStatementTransformer.spec.ts index 38cef9d93..9ac6de418 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/labeled-statement-transformer/LabeledStatementTransformer.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/labeled-statement-transformer/LabeledStatementTransformer.spec.ts @@ -14,19 +14,16 @@ describe('LabeledStatementTransformer', () => { const breakStatementRegExp: RegExp = /break *(_0x([a-f0-9]){4,6});/; let obfuscatedCode: string, - firstMatch: string|undefined, - secondMatch: string|undefined, - thirdMatch: string|undefined; + firstMatch: string | undefined, + secondMatch: string | undefined, + thirdMatch: string | undefined; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); firstMatch = getRegExpMatch(obfuscatedCode, labeledStatementRegExp); secondMatch = getRegExpMatch(obfuscatedCode, continueStatementRegExp); diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/catch-clause/CatchClause.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/catch-clause/CatchClause.spec.ts index 466d996b3..2c6db06dd 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/catch-clause/CatchClause.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/catch-clause/CatchClause.spec.ts @@ -16,18 +16,14 @@ describe('ScopeIdentifiersTransformer CatchClause identifiers', () => { const paramNameRegExp: RegExp = /catch *\((_0x([a-f0-9]){4,6})\) *\{/; const bodyParamNameRegExp: RegExp = /console\['log'\]\((_0x([a-f0-9]){4,6})\);/; - let firstMatch: string | undefined, - secondMatch: string | undefined; + let firstMatch: string | undefined, secondMatch: string | undefined; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); firstMatch = getRegExpMatch(obfuscatedCode, paramNameRegExp); secondMatch = getRegExpMatch(obfuscatedCode, bodyParamNameRegExp); }); @@ -54,19 +50,16 @@ describe('ScopeIdentifiersTransformer CatchClause identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform function parameter object pattern identifier', () => { + it("match #1: shouldn't transform function parameter object pattern identifier", () => { assert.match(obfuscatedCode, functionParameterMatch); }); - it('match #2: shouldn\'t transform function parameter object pattern identifier', () => { + it("match #2: shouldn't transform function parameter object pattern identifier", () => { assert.match(obfuscatedCode, functionBodyMatch); }); }); @@ -78,12 +71,9 @@ describe('ScopeIdentifiersTransformer CatchClause identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/optional-catch-binding.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should transform catch clause node', () => { @@ -102,15 +92,12 @@ describe('ScopeIdentifiersTransformer CatchClause identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/global-variable-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform variable identifier if `renameGlobals` option is disabled', () => { + it("match #1: shouldn't transform variable identifier if `renameGlobals` option is disabled", () => { assert.match(obfuscatedCode, globalVariableRegExp); }); }); @@ -121,13 +108,10 @@ describe('ScopeIdentifiersTransformer CatchClause identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/global-variable-scope.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('match #1: should transform variable identifier if `renameGlobals` option is enabled', () => { diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts index 2be6ed5db..989eb4d92 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts @@ -16,19 +16,14 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { const classNameIdentifierRegExp: RegExp = /class *(_0x[a-f0-9]{4,6}) *\{/; const classCallIdentifierRegExp: RegExp = /new *(_0x[a-f0-9]{4,6}) *\( *\);/; - let obfuscatedCode: string, - classNameIdentifier: string, - classCallIdentifier: string; + let obfuscatedCode: string, classNameIdentifier: string, classCallIdentifier: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); classCallIdentifier = getRegExpMatch(obfuscatedCode, classCallIdentifierRegExp); }); @@ -47,21 +42,20 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/parent-block-scope-is-program-node.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform class name', () => { + it("match #1: shouldn't transform class name", () => { assert.match(obfuscatedCode, classNameIdentifierRegExp); }); - it('match #2: shouldn\'t transform class name', () => { + it("match #2: shouldn't transform class name", () => { assert.match(obfuscatedCode, classCallIdentifierRegExp); }); }); @@ -75,26 +69,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-global-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-global-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - target: ObfuscationTarget.Browser - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + target: ObfuscationTarget.Browser + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform class name', () => { + it("match #1: shouldn't transform class name", () => { assert.match(obfuscatedCode, classNameIdentifierRegExp); }); - it('match #2: shouldn\'t transform class name reference outside of class', () => { + it("match #2: shouldn't transform class name reference outside of class", () => { assert.match(obfuscatedCode, outerClassNameReferenceRegExp); }); - it('match #3: shouldn\'t transform class name reference inside class', () => { + it("match #3: shouldn't transform class name reference inside class", () => { assert.match(obfuscatedCode, innerClassNameReferenceRegExp); }); }); @@ -110,19 +103,24 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let innerClassNameReferenceIdentifierName: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-function-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-function-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - target: ObfuscationTarget.Browser - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + target: ObfuscationTarget.Browser + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); - outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); - innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + outerClassNameReferenceRegExp + ); + innerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + innerClassNameReferenceRegExp + ); }); it('match #1: should transform class name', () => { @@ -156,26 +154,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-global-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-global-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - target: ObfuscationTarget.Node - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + target: ObfuscationTarget.Node + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform class name', () => { + it("match #1: shouldn't transform class name", () => { assert.match(obfuscatedCode, classNameIdentifierRegExp); }); - it('match #2: shouldn\'t transform class name reference outside of class', () => { + it("match #2: shouldn't transform class name reference outside of class", () => { assert.match(obfuscatedCode, outerClassNameReferenceRegExp); }); - it('match #3: shouldn\'t transform class name reference inside class', () => { + it("match #3: shouldn't transform class name reference inside class", () => { assert.match(obfuscatedCode, innerClassNameReferenceRegExp); }); }); @@ -191,19 +188,24 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let innerClassNameReferenceIdentifierName: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-function-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-function-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - target: ObfuscationTarget.Node - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + target: ObfuscationTarget.Node + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); - outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); - innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + outerClassNameReferenceRegExp + ); + innerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + innerClassNameReferenceRegExp + ); }); it('match #1: should transform class name', () => { @@ -237,26 +239,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-global-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-global-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - target: ObfuscationTarget.ServiceWorker - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + target: ObfuscationTarget.ServiceWorker + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform class name', () => { + it("match #1: shouldn't transform class name", () => { assert.match(obfuscatedCode, classNameIdentifierRegExp); }); - it('match #2: shouldn\'t transform class name reference outside of class', () => { + it("match #2: shouldn't transform class name reference outside of class", () => { assert.match(obfuscatedCode, outerClassNameReferenceRegExp); }); - it('match #3: shouldn\'t transform class name reference inside class', () => { + it("match #3: shouldn't transform class name reference inside class", () => { assert.match(obfuscatedCode, innerClassNameReferenceRegExp); }); }); @@ -272,19 +273,24 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let innerClassNameReferenceIdentifierName: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-function-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-function-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - target: ObfuscationTarget.ServiceWorker - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + target: ObfuscationTarget.ServiceWorker + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); - outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); - innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + outerClassNameReferenceRegExp + ); + innerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + innerClassNameReferenceRegExp + ); }); it('match #1: should transform class name', () => { @@ -318,15 +324,14 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/parent-block-scope-is-program-node.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('match #1: should transform class name', () => { @@ -345,15 +350,14 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/rename-globals-identifier-transformation.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/rename-globals-identifier-transformation.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('match #1: should transform identifier name inside class method', () => { @@ -377,20 +381,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let innerClassNameReferenceIdentifierName: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-global-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-global-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - target: ObfuscationTarget.Browser - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + target: ObfuscationTarget.Browser + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); - outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); - innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + outerClassNameReferenceRegExp + ); + innerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + innerClassNameReferenceRegExp + ); }); it('match #1: should transform class name', () => { @@ -425,20 +434,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let innerClassNameReferenceIdentifierName: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-function-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-function-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - target: ObfuscationTarget.Browser - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + target: ObfuscationTarget.Browser + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); - outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); - innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + outerClassNameReferenceRegExp + ); + innerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + innerClassNameReferenceRegExp + ); }); it('match #1: should transform class name', () => { @@ -475,20 +489,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let innerClassNameReferenceIdentifierName: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-global-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-global-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - target: ObfuscationTarget.Node - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + target: ObfuscationTarget.Node + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); - outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); - innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + outerClassNameReferenceRegExp + ); + innerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + innerClassNameReferenceRegExp + ); }); it('match #1: should transform class name', () => { @@ -523,20 +542,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let innerClassNameReferenceIdentifierName: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-function-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-function-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - target: ObfuscationTarget.Node - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + target: ObfuscationTarget.Node + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); - outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); - innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + outerClassNameReferenceRegExp + ); + innerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + innerClassNameReferenceRegExp + ); }); it('match #1: should transform class name', () => { @@ -573,20 +597,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let innerClassNameReferenceIdentifierName: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-global-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-global-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - target: ObfuscationTarget.ServiceWorker - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + target: ObfuscationTarget.ServiceWorker + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); - outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); - innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + outerClassNameReferenceRegExp + ); + innerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + innerClassNameReferenceRegExp + ); }); it('match #1: should transform class name', () => { @@ -621,20 +650,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let innerClassNameReferenceIdentifierName: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/class-name-references-function-scope.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/class-name-references-function-scope.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - target: ObfuscationTarget.ServiceWorker - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + target: ObfuscationTarget.ServiceWorker + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); - outerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, outerClassNameReferenceRegExp); - innerClassNameReferenceIdentifierName = getRegExpMatch(obfuscatedCode, innerClassNameReferenceRegExp); + outerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + outerClassNameReferenceRegExp + ); + innerClassNameReferenceIdentifierName = getRegExpMatch( + obfuscatedCode, + innerClassNameReferenceRegExp + ); }); it('match #1: should transform class name', () => { @@ -661,7 +695,7 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { }); }); - describe('Variant #3: preserved identifier names shouldn\'t be used as identifier names', () => { + describe("Variant #3: preserved identifier names shouldn't be used as identifier names", () => { const classDeclarationRegExp: RegExp = /class *e *{/; const variableDeclarationsRegExp: RegExp = /let f, *g, *h, *i;/; const classReferenceRegExp: RegExp = /new e\(\);/; @@ -669,26 +703,25 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevent-using-of-preserved-identifiers.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/prevent-using-of-preserved-identifiers.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); - it('Match #1: shouldn\'t use preserved identifier name as class declaration name', () => { + it("Match #1: shouldn't use preserved identifier name as class declaration name", () => { assert.match(obfuscatedCode, classDeclarationRegExp); }); - it('Match #2: shouldn\'t use preserved identifier name as variable declarations', () => { + it("Match #2: shouldn't use preserved identifier name as variable declarations", () => { assert.match(obfuscatedCode, variableDeclarationsRegExp); }); - it('Match #3: shouldn\'t use preserved identifier name as class reference identifier', () => { + it("Match #3: shouldn't use preserved identifier name as class reference identifier", () => { assert.match(obfuscatedCode, classReferenceRegExp); }); }); @@ -701,16 +734,13 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/named-export.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); - it('shouldn\'t transform identifiers in named export', () => { + it("shouldn't transform identifiers in named export", () => { assert.match(obfuscatedCode, namedExportRegExp); }); }); @@ -724,13 +754,10 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/default-export.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('Match #1: should transform identifiers in variable declaration', () => { @@ -750,13 +777,10 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/default-export-inline.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('Match #1: should produce correct code', () => { @@ -772,12 +796,9 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/super-class-expression-parenthesis.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should keep super class expression parenthesis', () => { diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-expression/ClassExpression.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-expression/ClassExpression.spec.ts index e5e07857e..5ea1c3c5e 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-expression/ClassExpression.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/class-expression/ClassExpression.spec.ts @@ -13,19 +13,14 @@ describe('ScopeIdentifiersTransformer ClassExpression identifiers', () => { const classNameIdentifierRegExp: RegExp = /var (_0x[a-f0-9]{4,6}) *= *class *\{/; const classCallIdentifierRegExp: RegExp = /new *(_0x[a-f0-9]{4,6}) *\( *\);/; - let obfuscatedCode: string, - classNameIdentifier: string, - classCallIdentifier: string; + let obfuscatedCode: string, classNameIdentifier: string, classCallIdentifier: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/base.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp); classCallIdentifier = getRegExpMatch(obfuscatedCode, classCallIdentifierRegExp); }); @@ -44,19 +39,16 @@ describe('ScopeIdentifiersTransformer ClassExpression identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform class name', () => { + it("match #1: shouldn't transform class name", () => { assert.match(obfuscatedCode, classNameIdentifierRegExp); }); - it('match #2: shouldn\'t transform class name', () => { + it("match #2: shouldn't transform class name", () => { assert.match(obfuscatedCode, classCallIdentifierRegExp); }); }); diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts index 6c6bc4024..9fc22b04c 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts @@ -14,19 +14,14 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { const functionNameIdentifierRegExp: RegExp = /function *(_0x[a-f0-9]{4,6}) *\(\) *\{/; const functionCallIdentifierRegExp: RegExp = /(_0x[a-f0-9]{4,6}) *\( *\);/; - let obfuscatedCode: string, - functionNameIdentifier: string, - functionCallIdentifier: string; + let obfuscatedCode: string, functionNameIdentifier: string, functionCallIdentifier: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); functionNameIdentifier = getRegExpMatch(obfuscatedCode, functionNameIdentifierRegExp); functionCallIdentifier = getRegExpMatch(obfuscatedCode, functionCallIdentifierRegExp); }); @@ -44,21 +39,20 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/parent-block-scope-is-program-node.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform function name', () => { + it("match #1: shouldn't transform function name", () => { assert.match(obfuscatedCode, functionNameIdentifierRegExp); }); - it('match #2: shouldn\'t transform function name', () => { + it("match #2: shouldn't transform function name", () => { assert.match(obfuscatedCode, functionCallIdentifierRegExp); }); }); @@ -70,15 +64,14 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/parent-block-scope-is-program-node.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('match #1: should transform function name', () => { @@ -95,19 +88,14 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { const functionNameIdentifierRegExp: RegExp = /function *\* *(_0x[a-f0-9]{4,6}) *\(\) *\{/; const functionCallIdentifierRegExp: RegExp = /let _0x[a-f0-9]{4,6} *= *(_0x[a-f0-9]{4,6}) *\( *\);/; - let obfuscatedCode: string, - functionNameIdentifier: string, - functionCallIdentifier: string; + let obfuscatedCode: string, functionNameIdentifier: string, functionCallIdentifier: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/generator-function.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); functionNameIdentifier = getRegExpMatch(obfuscatedCode, functionNameIdentifierRegExp); functionCallIdentifier = getRegExpMatch(obfuscatedCode, functionCallIdentifierRegExp); }); @@ -121,19 +109,14 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { const functionNameIdentifierRegExp: RegExp = /async *function *(_0x[a-f0-9]{4,6}) *\(\) *\{/; const functionCallIdentifierRegExp: RegExp = /await *(_0x[a-f0-9]{4,6}) *\( *\);/; - let obfuscatedCode: string, - functionNameIdentifier: string, - functionCallIdentifier: string; + let obfuscatedCode: string, functionNameIdentifier: string, functionCallIdentifier: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/async-function.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); functionNameIdentifier = getRegExpMatch(obfuscatedCode, functionNameIdentifierRegExp); functionCallIdentifier = getRegExpMatch(obfuscatedCode, functionCallIdentifierRegExp); }); @@ -143,7 +126,7 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { }); }); - describe('Variant #5: preserved identifier names shouldn\'t be used as identifier names', () => { + describe("Variant #5: preserved identifier names shouldn't be used as identifier names", () => { describe('Variant #1', () => { const functionDeclarationRegExp: RegExp = /function *e\(\) *{/; const variableDeclarationsRegExp: RegExp = /let f, *g, *h, *i;/; @@ -151,22 +134,21 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevent-using-of-preserved-identifiers-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/prevent-using-of-preserved-identifiers-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); - it('Match #1: shouldn\'t use preserved identifier name as function declaration name', () => { + it("Match #1: shouldn't use preserved identifier name as function declaration name", () => { assert.match(obfuscatedCode, functionDeclarationRegExp); }); - it('Match #2: shouldn\'t use preserved identifier name as variable declarations', () => { + it("Match #2: shouldn't use preserved identifier name as variable declarations", () => { assert.match(obfuscatedCode, variableDeclarationsRegExp); }); }); @@ -180,16 +162,13 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/named-export.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); - it('shouldn\'t transform identifiers in named export', () => { + it("shouldn't transform identifiers in named export", () => { assert.match(obfuscatedCode, namedExportRegExp); }); }); @@ -203,13 +182,10 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/default-export.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('Match #1: should transform identifiers in variable declaration', () => { @@ -229,13 +205,10 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/default-export-inline.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('Match #1: should produce correct code', () => { diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/function/Function.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/function/Function.spec.ts index 46cd48d1d..fc908e90a 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/function/Function.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/function/Function.spec.ts @@ -26,21 +26,19 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); - - const functionParamIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionParamIdentifierRegExp); - const functionBodyIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionBodyIdentifierRegExp); - const variableDeclarationIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(variableDeclarationRegExp); - const returnStatementIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(returnStatementIdentifierRegExp); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); + + const functionParamIdentifierMatch: RegExpMatchArray | null = + obfuscatedCode.match(functionParamIdentifierRegExp); + const functionBodyIdentifierMatch: RegExpMatchArray | null = + obfuscatedCode.match(functionBodyIdentifierRegExp); + const variableDeclarationIdentifierMatch: RegExpMatchArray | null = + obfuscatedCode.match(variableDeclarationRegExp); + const returnStatementIdentifierMatch: RegExpMatchArray | null = obfuscatedCode.match( + returnStatementIdentifierRegExp + ); functionParamIdentifierName = (functionParamIdentifierMatch)[1]; functionBodyIdentifierName = (functionBodyIdentifierMatch)[1]; @@ -60,7 +58,7 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { assert.equal(variableDeclarationIdentifierName, returnStatementIdentifierName); }); - it('shouldn\'t transform other variables in function body', () => { + it("shouldn't transform other variables in function body", () => { assert.match(obfuscatedCode, variableReferenceRegExp); }); }); @@ -79,19 +77,18 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-id-name-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); - const functionExpressionParamIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionExpressionParamIdentifierRegExp); - const innerFunctionNameIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(innerFunctionNameIdentifierRegExp); - const functionObjectIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionObjectIdentifierRegExp); + const functionExpressionParamIdentifierMatch: RegExpMatchArray | null = obfuscatedCode.match( + functionExpressionParamIdentifierRegExp + ); + const innerFunctionNameIdentifierMatch: RegExpMatchArray | null = obfuscatedCode.match( + innerFunctionNameIdentifierRegExp + ); + const functionObjectIdentifierMatch: RegExpMatchArray | null = + obfuscatedCode.match(functionObjectIdentifierRegExp); functionExpressionParamIdentifierName = (functionExpressionParamIdentifierMatch)[1]; innerFunctionNameIdentifierName = (innerFunctionNameIdentifierMatch)[1]; @@ -135,17 +132,14 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-id-name-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); - const functionIdentifiersMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionIdentifiersRegExp); - const functionObjectIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionObjectIdentifierRegExp); + const functionIdentifiersMatch: RegExpMatchArray | null = + obfuscatedCode.match(functionIdentifiersRegExp); + const functionObjectIdentifierMatch: RegExpMatchArray | null = + obfuscatedCode.match(functionObjectIdentifierRegExp); functionIdentifierName = (functionIdentifiersMatch)[1]; functionParamIdentifierName = (functionIdentifiersMatch)[2]; @@ -164,7 +158,7 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { assert.equal(functionIdentifierName, functionObjectIdentifierName); }); - it('should\'t generate same names for function id and parameter identifiers', () => { + it("should't generate same names for function id and parameter identifiers", () => { assert.notEqual(functionIdentifierName, functionParamIdentifierName); }); }); @@ -182,18 +176,15 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-id-name-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: false - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: false + }).getObfuscatedCode(); - const functionIdentifiersMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionIdentifiersRegExp); - const functionObjectIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionObjectIdentifierRegExp); + const functionIdentifiersMatch: RegExpMatchArray | null = + obfuscatedCode.match(functionIdentifiersRegExp); + const functionObjectIdentifierMatch: RegExpMatchArray | null = + obfuscatedCode.match(functionObjectIdentifierRegExp); functionIdentifierName = (functionIdentifiersMatch)[1]; functionParamIdentifierName = (functionIdentifiersMatch)[2]; @@ -233,18 +224,15 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-id-name-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); - const functionIdentifiersMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionIdentifiersRegExp); - const functionObjectIdentifierMatch: RegExpMatchArray|null = obfuscatedCode - .match(functionObjectIdentifierRegExp); + const functionIdentifiersMatch: RegExpMatchArray | null = + obfuscatedCode.match(functionIdentifiersRegExp); + const functionObjectIdentifierMatch: RegExpMatchArray | null = + obfuscatedCode.match(functionObjectIdentifierRegExp); functionIdentifierName = (functionIdentifiersMatch)[1]; functionParamIdentifierName = (functionIdentifiersMatch)[2]; @@ -263,11 +251,11 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { assert.equal(functionIdentifierName, functionObjectIdentifierName); }); - it('shouldn\'t generate same names for function parameter and function object identifiers', () => { + it("shouldn't generate same names for function parameter and function object identifiers", () => { assert.notEqual(functionParamIdentifierName, functionObjectIdentifierName); }); - it('shouldn\'t generate same names for function id and parameter identifiers', () => { + it("shouldn't generate same names for function id and parameter identifiers", () => { assert.notEqual(functionIdentifierName, functionParamIdentifierName); }); }); @@ -286,25 +274,23 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform function parameter object pattern identifier', () => { + it("match #1: shouldn't transform function parameter object pattern identifier", () => { assert.match(obfuscatedCode, functionParameterRegExp); }); - it('match #2: shouldn\'t transform function parameter object pattern identifier', () => { + it("match #2: shouldn't transform function parameter object pattern identifier", () => { assert.match(obfuscatedCode, functionBodyRegExp); }); }); describe('Variant #2: correct transformation when identifier with same name in parent scope exist', () => { - const functionParameterRegExp: RegExp = /^\(function *\(\) *{ *function *_0x[a-f0-9]{4,6} *\(_0x[a-f0-9]{4,6}\) *\{/; + const functionParameterRegExp: RegExp = + /^\(function *\(\) *{ *function *_0x[a-f0-9]{4,6} *\(_0x[a-f0-9]{4,6}\) *\{/; const callbackParameterRegExp: RegExp = /\['then'] *\(\({ *data *}\)/; const callbackBodyRegExp: RegExp = /console\['log']\(data\)/; const returnRegExp: RegExp = /return _0x[a-f0-9]{4,6};/; @@ -314,23 +300,20 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should transform function parameter identifier', () => { assert.match(obfuscatedCode, functionParameterRegExp); }); - it('match #2: shouldn\'t transform callback parameter object pattern identifier', () => { + it("match #2: shouldn't transform callback parameter object pattern identifier", () => { assert.match(obfuscatedCode, callbackParameterRegExp); }); - it('match #3: shouldn\'t transform callback body identifier', () => { + it("match #3: shouldn't transform callback body identifier", () => { assert.match(obfuscatedCode, callbackBodyRegExp); }); @@ -340,7 +323,8 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { }); describe('Variant #3: correct transformation when parent scope identifier conflicts with current scope object pattern identifier', () => { - const functionObjectPatternParameterRegExp1: RegExp = /function _0x[a-f0-9]{4,6} *\({data, *\.\.\._0x[a-f0-9]{4,6}}\) *{/; + const functionObjectPatternParameterRegExp1: RegExp = + /function _0x[a-f0-9]{4,6} *\({data, *\.\.\._0x[a-f0-9]{4,6}}\) *{/; const functionObjectPatternParameterRegExp2: RegExp = /function _0x[a-f0-9]{4,6} *\({options}\) *{/; const returnRegExp1: RegExp = /return data *\+ *options *\+ *_0x[a-f0-9]{4,6};/; const returnRegExp2: RegExp = /return _0x[a-f0-9]{4,6};/; @@ -350,12 +334,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should transform function parameter object pattern rest identifier', () => { @@ -377,7 +358,8 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { describe('Variant #4: shorthand property node', () => { const functionObjectPatternParameterRegExp1: RegExp = /function _0x[a-f0-9]{4,6} *\({id}\) *{/; - const functionObjectPatternParameterRegExp2: RegExp = /function _0x[a-f0-9]{4,6} *\({id: *_0x[a-f0-9]{4,6}}\) *{/; + const functionObjectPatternParameterRegExp2: RegExp = + /function _0x[a-f0-9]{4,6} *\({id: *_0x[a-f0-9]{4,6}}\) *{/; const consoleLogRegExp: RegExp = /console\['log']\(id\);/; const returnRegExp: RegExp = /return id *\+ *_0x[a-f0-9]{4,6};/; @@ -386,12 +368,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-4.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should transform function parameter object pattern rest identifier', () => { @@ -418,15 +397,12 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-5.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform function parameter identifier and reference identifier', () => { + it("match #1: shouldn't transform function parameter identifier and reference identifier", () => { assert.match(obfuscatedCode, objectPatternRegExp); }); }); @@ -440,19 +416,16 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-6.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform function parameter object pattern property identifier', () => { + it("match #1: shouldn't transform function parameter object pattern property identifier", () => { assert.match(obfuscatedCode, functionParameterRegExp); }); - it('match #2: shouldn\'t transform function body identifier', () => { + it("match #2: shouldn't transform function body identifier", () => { assert.match(obfuscatedCode, functionBodyRegExp); }); }); @@ -466,12 +439,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-7.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should correctly transform function parameter identifiers', () => { @@ -494,12 +464,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/assignment-pattern-as-parameter-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should transform function parameter assignment pattern identifier', () => { @@ -525,12 +492,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/assignment-pattern-as-parameter-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); variableDeclarationIdentifierName = getRegExpMatch(obfuscatedCode, variableDeclarationRegExp); functionParameterIdentifierName = getRegExpMatch(obfuscatedCode, functionParameterRegExp); functionDefaultParameterIdentifierName = getRegExpMatch(obfuscatedCode, functionParameterRegExp, 1); @@ -560,7 +524,8 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { describe('Variant #3: identifier as right value', () => { const variableDeclarationRegExp: RegExp = /var (_0x[a-f0-9]{4,6}) *= *0x1;/; - const functionParameterRegExp: RegExp = /function *\((_0x[a-f0-9]{4,6}), *(_0x[a-f0-9]{4,6}) *= *(_0x[a-f0-9]{4,6})\) *\{/; + const functionParameterRegExp: RegExp = + /function *\((_0x[a-f0-9]{4,6}), *(_0x[a-f0-9]{4,6}) *= *(_0x[a-f0-9]{4,6})\) *\{/; const functionBodyRegExp: RegExp = /return *(_0x[a-f0-9]{4,6}) *\+ *(_0x[a-f0-9]{4,6});/; let obfuscatedCode: string, @@ -574,12 +539,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/assignment-pattern-as-parameter-3.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); variableDeclarationIdentifierName = getRegExpMatch(obfuscatedCode, variableDeclarationRegExp); functionParameterIdentifierName = getRegExpMatch(obfuscatedCode, functionParameterRegExp); @@ -602,15 +564,15 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { assert.match(obfuscatedCode, functionBodyRegExp); }); - it('equal #1:shouldn\'t keep same names for variable declaration identifier and function parameters identifiers', () => { + it("equal #1:shouldn't keep same names for variable declaration identifier and function parameters identifiers", () => { assert.notEqual(variableDeclarationIdentifierName, functionParameterIdentifierName); }); - it('equal #2: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers', () => { + it("equal #2: shouldn't keep same names for variable declaration identifier and function parameters identifiers", () => { assert.notEqual(variableDeclarationIdentifierName, functionDefaultParameterIdentifierName1); }); - it('equal #3: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers', () => { + it("equal #3: shouldn't keep same names for variable declaration identifier and function parameters identifiers", () => { assert.notEqual(variableDeclarationIdentifierName, functionDefaultParameterIdentifierName2); }); @@ -640,12 +602,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/array-pattern-as-parameter.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); arrayPatternIdentifierName1 = getRegExpMatch(obfuscatedCode, functionParameterRegExp); arrayPatternIdentifierName2 = getRegExpMatch(obfuscatedCode, functionParameterRegExp, 1); @@ -671,12 +630,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/rest-parameter.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should transform function rest parameter', () => { @@ -697,12 +653,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/array-rest-parameter.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should transform function rest parameter', () => { @@ -725,12 +678,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-rest-parameter.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should transform function rest parameter', () => { @@ -753,12 +703,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/default-parameter-as-identifier.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: shouldn transform variable declaration', () => { @@ -773,8 +720,6 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { assert.match(obfuscatedCode, functionBodyRegExp); }); }); - - }); describe('ignored identifier names set', () => { @@ -786,12 +731,9 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/identifier-names-set-object-pattern.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should transform identifiers in function body', () => { @@ -802,24 +744,24 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { describe('correct block scope detection of arrow function expression', () => { describe('Variant #1: block statement body', () => { - const regExpMatch: string = `` + + const regExpMatch: string = + `` + `\\[]` + `\\['map']\\(_0x[a-f0-9]{4,6} *=> *\\{ *return 0x1; *\\}\\)` + `\\['map']\\(_0x[a-f0-9]{4,6} *=> *\\[foo]\\);` + - ``; + ``; const regExp: RegExp = new RegExp(regExpMatch); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/arrow-function-with-expression-body-block-scope-detection-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/arrow-function-with-expression-body-block-scope-detection-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should transform identifiers in arrow function expression body', () => { @@ -828,24 +770,24 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => { }); describe('Variant #2: expression statement body', () => { - const regExpMatch: string = `` + + const regExpMatch: string = + `` + `\\[]` + `\\['map']\\(_0x[a-f0-9]{4,6} *=> *0x1\\)` + `\\['map']\\(_0x[a-f0-9]{4,6} *=> *\\[foo]\\);` + - ``; + ``; const regExp: RegExp = new RegExp(regExpMatch); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/arrow-function-with-expression-body-block-scope-detection-2.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/arrow-function-with-expression-body-block-scope-detection-2.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should transform identifiers in arrow function expression body', () => { diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/import-declaration/ImportDeclaration.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/import-declaration/ImportDeclaration.spec.ts index 21d9d5885..4b5800373 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/import-declaration/ImportDeclaration.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/import-declaration/ImportDeclaration.spec.ts @@ -13,19 +13,14 @@ describe('ScopeIdentifiersTransformer ImportDeclaration identifiers', () => { const importSpecifierRegExp: RegExp = /import (_0x[a-f0-9]{4,6}) from *'\.\/foo';/; const consoleLogRegExp: RegExp = /console\['log']\((_0x[a-f0-9]{4,6})\);/; - let obfuscatedCode: string, - importSpecifierIdentifier: string, - consoleLogIdentifier: string; + let obfuscatedCode: string, importSpecifierIdentifier: string, consoleLogIdentifier: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/default-import.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); importSpecifierIdentifier = getRegExpMatch(obfuscatedCode, importSpecifierRegExp); consoleLogIdentifier = getRegExpMatch(obfuscatedCode, consoleLogRegExp); }); @@ -39,19 +34,14 @@ describe('ScopeIdentifiersTransformer ImportDeclaration identifiers', () => { const importSpecifierRegExp: RegExp = /import *\* *as *(_0x[a-f0-9]{4,6}) *from *'\.\/foo';/; const consoleLogRegExp: RegExp = /console\['log']\((_0x[a-f0-9]{4,6})\);/; - let obfuscatedCode: string, - importSpecifierIdentifier: string, - consoleLogIdentifier: string; + let obfuscatedCode: string, importSpecifierIdentifier: string, consoleLogIdentifier: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/namespace-import.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); importSpecifierIdentifier = getRegExpMatch(obfuscatedCode, importSpecifierRegExp); consoleLogIdentifier = getRegExpMatch(obfuscatedCode, consoleLogRegExp); }); @@ -71,19 +61,16 @@ describe('ScopeIdentifiersTransformer ImportDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/named-import-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('Match #1: shouldn\'t transform import specifier identifier name', () => { + it("Match #1: shouldn't transform import specifier identifier name", () => { assert.match(obfuscatedCode, importSpecifierRegExp); }); - it('Match #2: shouldn\'t transform import specifier identifier name', () => { + it("Match #2: shouldn't transform import specifier identifier name", () => { assert.match(obfuscatedCode, consoleLogRegExp); }); }); @@ -92,19 +79,14 @@ describe('ScopeIdentifiersTransformer ImportDeclaration identifiers', () => { const importSpecifierRegExp: RegExp = /import *{foo as (_0x[a-f0-9]{4,6})} *from *'\.\/foo';/; const consoleLogRegExp: RegExp = /console\['log']\((_0x[a-f0-9]{4,6})\);/; - let obfuscatedCode: string, - importSpecifierIdentifier: string, - consoleLogIdentifier: string; + let obfuscatedCode: string, importSpecifierIdentifier: string, consoleLogIdentifier: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/named-import-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); importSpecifierIdentifier = getRegExpMatch(obfuscatedCode, importSpecifierRegExp); consoleLogIdentifier = getRegExpMatch(obfuscatedCode, consoleLogRegExp); }); @@ -119,20 +101,15 @@ describe('ScopeIdentifiersTransformer ImportDeclaration identifiers', () => { const importSpecifierRegExp: RegExp = /import *\* *as *(bark_0x[a-f0-9]{4,6}) *from *'\.\/foo';/; const consoleLogRegExp: RegExp = /console\['log']\((bark_0x[a-f0-9]{4,6})\);/; - let obfuscatedCode: string, - importSpecifierIdentifier: string, - consoleLogIdentifier: string; + let obfuscatedCode: string, importSpecifierIdentifier: string, consoleLogIdentifier: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/namespace-import.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifiersPrefix: 'bark' - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifiersPrefix: 'bark' + }).getObfuscatedCode(); importSpecifierIdentifier = getRegExpMatch(obfuscatedCode, importSpecifierRegExp); consoleLogIdentifier = getRegExpMatch(obfuscatedCode, consoleLogRegExp); }); @@ -152,13 +129,10 @@ describe('ScopeIdentifiersTransformer ImportDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/no-invalid-mark-as-renamed-identifier.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('Match 1: should transform first import specifier identifier name', () => { @@ -182,13 +156,10 @@ describe('ScopeIdentifiersTransformer ImportDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/dynamic-import.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('should support dynamic import', () => { diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts index 60430f452..d1be22072 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts @@ -21,12 +21,9 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should transform `variableDeclaration` node', () => { @@ -48,19 +45,16 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform `variableDeclaration` node', () => { + it("match #1: shouldn't transform `variableDeclaration` node", () => { assert.match(obfuscatedCode, variableDeclarationRegExp); }); - it('match #2: shouldn\'t transform `variableDeclaration` node', () => { + it("match #2: shouldn't transform `variableDeclaration` node", () => { assert.match(obfuscatedCode, variableCallRegExp); }); }); @@ -74,13 +68,10 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('match #1: should transform `variableDeclaration` node', () => { @@ -101,12 +92,9 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/var-kind.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should transform variable call (`identifier` node) outside of block scope of node in which this variable was declared with `var` kind', () => { @@ -122,15 +110,12 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/let-kind.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('shouldn\'t transform variable call (`identifier` node) outside of block scope of node in which this variable was declared with `let` kind', () => { + it("shouldn't transform variable call (`identifier` node) outside of block scope of node in which this variable was declared with `let` kind", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -142,14 +127,13 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-call-before-variable-declaration-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-call-before-variable-declaration-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should transform variable call (`identifier` node name) before variable declaration if this call is inside function body', () => { @@ -162,27 +146,27 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { }); describe(`Variant #6: variable calls before variable declaration when function param has the same name as variables name`, () => { - const functionParamIdentifierRegExp: RegExp = /function *_0x[a-f0-9]{4,6} *\((_0x[a-f0-9]{4,6})\,(_0x[a-f0-9]{4,6})\) *\{/; + const functionParamIdentifierRegExp: RegExp = + /function *_0x[a-f0-9]{4,6} *\((_0x[a-f0-9]{4,6})\,(_0x[a-f0-9]{4,6})\) *\{/; const innerFunctionParamIdentifierRegExp: RegExp = /function _0x[a-f0-9]{4,6} *\((_0x[a-f0-9]{4,6})\) *\{/; const consoleLogIdentifierRegExp: RegExp = /console\['log'\]\((_0x[a-f0-9]{4,6})\)/; const objectIdentifierRegExp: RegExp = /return\{'t':(_0x[a-f0-9]{4,6})\}/; const variableDeclarationIdentifierRegExp: RegExp = /var (_0x[a-f0-9]{4,6});/; - let outerFunctionParamIdentifierName: string|null, - innerFunctionParamIdentifierName: string|null, - consoleLogIdentifierName: string|null, - objectIdentifierName: string|null, - variableDeclarationIdentifierName: string|null; + let outerFunctionParamIdentifierName: string | null, + innerFunctionParamIdentifierName: string | null, + consoleLogIdentifierName: string | null, + objectIdentifierName: string | null, + variableDeclarationIdentifierName: string | null; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-call-before-variable-declaration-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-call-before-variable-declaration-2.js' + ); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); outerFunctionParamIdentifierName = getRegExpMatch(obfuscatedCode, functionParamIdentifierRegExp); innerFunctionParamIdentifierName = getRegExpMatch(obfuscatedCode, innerFunctionParamIdentifierRegExp); @@ -223,21 +207,20 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { const objectIdentifierRegExp: RegExp = /return\{'t':(_0x[a-f0-9]{4,6})\}/; const variableDeclarationIdentifierRegExp: RegExp = /var (_0x[a-f0-9]{4,6});/; - let catchClauseParamIdentifierName: string|null, - innerFunctionParamIdentifierName: string|null, - consoleLogIdentifierName: string|null, - objectIdentifierName: string|null, - variableDeclarationIdentifierName: string|null; + let catchClauseParamIdentifierName: string | null, + innerFunctionParamIdentifierName: string | null, + consoleLogIdentifierName: string | null, + objectIdentifierName: string | null, + variableDeclarationIdentifierName: string | null; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-call-before-variable-declaration-3.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-call-before-variable-declaration-3.js' + ); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); catchClauseParamIdentifierName = getRegExpMatch(obfuscatedCode, catchClauseParamIdentifierRegExp); innerFunctionParamIdentifierName = getRegExpMatch(obfuscatedCode, innerFunctionParamIdentifierRegExp); @@ -280,15 +263,12 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/property-identifier.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('shouldn\'t replace property node identifier', () => { + it("shouldn't replace property node identifier", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -301,15 +281,12 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/member-expression-identifier.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('shouldn\'t replace computed member expression identifier', () => { + it("shouldn't replace computed member expression identifier", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -327,26 +304,24 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform object pattern variable declarator', () => { + it("match #1: shouldn't transform object pattern variable declarator", () => { assert.match(obfuscatedCode, objectPatternVariableDeclaratorRegExp); }); - it('match #2: shouldn\'t transform object pattern variable declarator', () => { + it("match #2: shouldn't transform object pattern variable declarator", () => { assert.match(obfuscatedCode, variableUsageRegExp); }); }); describe('Variant #2: nested object pattern with property alias', () => { - const objectPatternVariableDeclaratorRegExp: RegExp = /var \{ *bar *: *{ *baz *: *_0x([a-f0-9]){4,6} *= *0x1 *\} *\} *= *\{ *'bar' *: *\{ *'baz' *: *0x2 *\} *\};/; + const objectPatternVariableDeclaratorRegExp: RegExp = + /var \{ *bar *: *{ *baz *: *_0x([a-f0-9]){4,6} *= *0x1 *\} *\} *= *\{ *'bar' *: *\{ *'baz' *: *0x2 *\} *\};/; const variableUsageRegExp: RegExp = /console\['log'\]\(bar, *baz, *_0x([a-f0-9]){4,6}\);/; let obfuscatedCode: string; @@ -354,27 +329,25 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); - it('match #1: shouldn\'t transform object pattern variable declarator', () => { + it("match #1: shouldn't transform object pattern variable declarator", () => { assert.match(obfuscatedCode, objectPatternVariableDeclaratorRegExp); }); - it('match #2: shouldn\'t transform object pattern variable declarator', () => { + it("match #2: shouldn't transform object pattern variable declarator", () => { assert.match(obfuscatedCode, variableUsageRegExp); }); }); }); describe('Variant #10: array pattern as variable declarator', () => { - const objectPatternVariableDeclaratorRegExp: RegExp = /var \[ *(_0x([a-f0-9]){4,6}), *(_0x([a-f0-9]){4,6}) *\] *= *\[0x1, *0x2\];/; + const objectPatternVariableDeclaratorRegExp: RegExp = + /var \[ *(_0x([a-f0-9]){4,6}), *(_0x([a-f0-9]){4,6}) *\] *= *\[0x1, *0x2\];/; const variableUsageRegExp: RegExp = /console\['log'\]\((_0x([a-f0-9]){4,6}), *(_0x([a-f0-9]){4,6})\);/; let obfuscatedCode: string, @@ -386,12 +359,9 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/array-pattern.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); objectPatternIdentifierName1 = getRegExpMatch(obfuscatedCode, objectPatternVariableDeclaratorRegExp); objectPatternIdentifierName2 = getRegExpMatch(obfuscatedCode, objectPatternVariableDeclaratorRegExp, 1); @@ -424,12 +394,9 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/computed-object-expression-identifier.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('should transform computed object expression identifier', () => { @@ -445,20 +412,17 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/method-definition-identifier.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('shouldn\'t transform method definition node key identifier', () => { + it("shouldn't transform method definition node key identifier", () => { assert.match(obfuscatedCode, regExp); }); }); - describe('Variant #13: preserved identifier names shouldn\'t be used as identifier names', () => { + describe("Variant #13: preserved identifier names shouldn't be used as identifier names", () => { describe('Variant #1', () => { const variableDeclarationRegExp: RegExp = /var e *= *0x1;/; const functionDeclarationRegExp1: RegExp = /function *f *\(\) *{}/; @@ -469,34 +433,33 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevent-using-of-preserved-identifiers-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/prevent-using-of-preserved-identifiers-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); - it('Match #1: shouldn\'t use preserved identifier name as variable declaration name', () => { + it("Match #1: shouldn't use preserved identifier name as variable declaration name", () => { assert.match(obfuscatedCode, variableDeclarationRegExp); }); - it('Match #2: shouldn\'t use preserved identifier name as function declaration name', () => { + it("Match #2: shouldn't use preserved identifier name as function declaration name", () => { assert.match(obfuscatedCode, functionDeclarationRegExp1); }); - it('Match #3: shouldn\'t use preserved identifier name as function declaration name', () => { + it("Match #3: shouldn't use preserved identifier name as function declaration name", () => { assert.match(obfuscatedCode, functionDeclarationRegExp2); }); - it('Match #4: shouldn\'t use preserved identifier name as function declaration name', () => { + it("Match #4: shouldn't use preserved identifier name as function declaration name", () => { assert.match(obfuscatedCode, functionDeclarationRegExp3); }); - it('Match #5: shouldn\'t use preserved identifier name as function declaration name', () => { + it("Match #5: shouldn't use preserved identifier name as function declaration name", () => { assert.match(obfuscatedCode, functionDeclarationRegExp4); }); }); @@ -510,30 +473,29 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevent-using-of-preserved-identifiers-2.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/prevent-using-of-preserved-identifiers-2.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); - it('Match #1: shouldn\'t use preserved identifier name as variable declaration name', () => { + it("Match #1: shouldn't use preserved identifier name as variable declaration name", () => { assert.match(obfuscatedCode, variableDeclarationRegExp1); }); - it('Match #2: shouldn\'t use preserved identifier name as variable declaration name', () => { + it("Match #2: shouldn't use preserved identifier name as variable declaration name", () => { assert.match(obfuscatedCode, variableDeclarationRegExp2); }); - it('Match #3: shouldn\'t use preserved identifier name as function declaration name', () => { + it("Match #3: shouldn't use preserved identifier name as function declaration name", () => { assert.match(obfuscatedCode, functionDeclarationRegExp); }); - it('Match #4: shouldn\'t use preserved identifier name as variable declaration name', () => { + it("Match #4: shouldn't use preserved identifier name as variable declaration name", () => { assert.match(obfuscatedCode, variableDeclarationRegExp3); }); }); @@ -547,16 +509,13 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/named-export.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); - it('shouldn\'t transform identifiers in named export', () => { + it("shouldn't transform identifiers in named export", () => { assert.match(obfuscatedCode, namedExportRegExp); }); }); @@ -570,13 +529,10 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/default-export.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true + }).getObfuscatedCode(); }); it('Match #1: should transform identifiers in variable declaration', () => { @@ -597,12 +553,9 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/array-rest.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should transform object name', () => { @@ -625,12 +578,9 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-rest-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('Match #1: should transform object name', () => { @@ -653,14 +603,13 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/destructing-assignment-without-declaration-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/destructing-assignment-without-declaration-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should transform variables declaration', () => { @@ -681,22 +630,24 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { }); describe('Variant #19: destructing assignment without declaration #2', () => { - const variablesDeclaration: RegExp = /var _0x[a-f0-9]{4,6} *= *'a', *_0x[a-f0-9]{4,6} *= *'b', *_0x[a-f0-9]{4,6};/; - const destructingAssignmentRegExp: RegExp = /\({ *\[_0x[a-f0-9]{4,6}]: *_0x[a-f0-9]{4,6}, *\[_0x[a-f0-9]{4,6}]: *_0x[a-f0-9]{4,6} *} *= *{ *'a' *: *0x1, *'b' *: *0x2 *}\);/; + const variablesDeclaration: RegExp = + /var _0x[a-f0-9]{4,6} *= *'a', *_0x[a-f0-9]{4,6} *= *'b', *_0x[a-f0-9]{4,6};/; + const destructingAssignmentRegExp: RegExp = + /\({ *\[_0x[a-f0-9]{4,6}]: *_0x[a-f0-9]{4,6}, *\[_0x[a-f0-9]{4,6}]: *_0x[a-f0-9]{4,6} *} *= *{ *'a' *: *0x1, *'b' *: *0x2 *}\);/; const identifierAssignmentRegExp: RegExp = /_0x[a-f0-9]{4,6} *= *0x3;/; - const variablesUsageRegExp: RegExp = /console\['log']\(_0x[a-f0-9]{4,6}, *_0x[a-f0-9]{4,6}, *_0x[a-f0-9]{4,6}\);/; + const variablesUsageRegExp: RegExp = + /console\['log']\(_0x[a-f0-9]{4,6}, *_0x[a-f0-9]{4,6}, *_0x[a-f0-9]{4,6}\);/; let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/destructing-assignment-without-declaration-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/destructing-assignment-without-declaration-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should transform variables declaration', () => { @@ -720,20 +671,20 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => { stubNodeTransformers([ObjectPatternPropertiesTransformer]); const variablesDeclaration: RegExp = /var a, *_0x[a-f0-9]{4,6};/; - const destructingAssignmentRegExp: RegExp = /\({ *a, *\.\.\._0x[a-f0-9]{4,6} *} *= *{ *'a' *: *0x1, *'b' *: *0x2 *}\);/; + const destructingAssignmentRegExp: RegExp = + /\({ *a, *\.\.\._0x[a-f0-9]{4,6} *} *= *{ *'a' *: *0x1, *'b' *: *0x2 *}\);/; const variablesUsageRegExp: RegExp = /console\['log']\(a, *_0x[a-f0-9]{4,6}\);/; let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/destructing-assignment-without-declaration-3.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/destructing-assignment-without-declaration-3.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); it('match #1: should transform variables declaration', () => { diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts index fb413c8bc..8cfedca29 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts @@ -16,19 +16,16 @@ describe('ScopeThroughIdentifiersTransformer ClassDeclaration identifiers', () = before(() => { const code: string = readFileAsString(__dirname + '/fixtures/class-call-with-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - 'Foo': 'Foo_from_cache' - }, - propertyIdentifiers: {} - } + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + Foo: 'Foo_from_cache' + }, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should skip transformation of class name', () => { @@ -49,19 +46,16 @@ describe('ScopeThroughIdentifiersTransformer ClassDeclaration identifiers', () = before(() => { const code: string = readFileAsString(__dirname + '/fixtures/class-call-without-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - 'Foo': 'Foo_from_cache' - }, - propertyIdentifiers: {} - } + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + Foo: 'Foo_from_cache' + }, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should transform class name', () => { @@ -77,17 +71,14 @@ describe('ScopeThroughIdentifiersTransformer ClassDeclaration identifiers', () = before(() => { const code: string = readFileAsString(__dirname + '/fixtures/class-call-without-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: {}, - propertyIdentifiers: {} - } + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: {}, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not transform class name', () => { diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts index 0a8ab0148..e8885df83 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts @@ -16,19 +16,16 @@ describe('ScopeThroughIdentifiersTransformer FunctionDeclaration identifiers', ( before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-call-with-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - 'foo': 'foo_from_cache' - }, - propertyIdentifiers: {} - } + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + foo: 'foo_from_cache' + }, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should skip transformation of function name', () => { @@ -49,19 +46,16 @@ describe('ScopeThroughIdentifiersTransformer FunctionDeclaration identifiers', ( before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-call-without-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - 'foo': 'foo_from_cache' - }, - propertyIdentifiers: {} - } + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + foo: 'foo_from_cache' + }, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should transform function name', () => { @@ -77,17 +71,14 @@ describe('ScopeThroughIdentifiersTransformer FunctionDeclaration identifiers', ( before(() => { const code: string = readFileAsString(__dirname + '/fixtures/function-call-without-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: {}, - propertyIdentifiers: {} - } + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: {}, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not transform function name', () => { diff --git a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts index dad4ef79a..c1bba81ee 100644 --- a/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts +++ b/test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts @@ -16,19 +16,16 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', ( before(() => { const code: string = readFileAsString(__dirname + '/fixtures/variable-reference-with-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - 'foo': 'foo_from_cache' - }, - propertyIdentifiers: {} - } + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + foo: 'foo_from_cache' + }, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should skip transformation of variable declaration name', () => { @@ -48,21 +45,20 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', ( let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-reference-without-declaration-global-scope.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - 'foo': 'foo_from_cache' - }, - propertyIdentifiers: {} - } + const code: string = readFileAsString( + __dirname + '/fixtures/variable-reference-without-declaration-global-scope.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + foo: 'foo_from_cache' + }, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should transform variable reference name', () => { @@ -76,19 +72,18 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', ( let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-reference-without-declaration-global-scope.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: {}, - propertyIdentifiers: {} - } + const code: string = readFileAsString( + __dirname + '/fixtures/variable-reference-without-declaration-global-scope.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: {}, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not transform variable reference name', () => { @@ -102,22 +97,21 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', ( let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-reference-without-declaration-global-scope.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - 'foo': 'foo_from_cache' - }, - propertyIdentifiers: {} + const code: string = readFileAsString( + __dirname + '/fixtures/variable-reference-without-declaration-global-scope.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + foo: 'foo_from_cache' }, - reservedNames: ['^foo$'] - } - ).getObfuscatedCode(); + propertyIdentifiers: {} + }, + reservedNames: ['^foo$'] + }).getObfuscatedCode(); }); it('should not transform variable reference name', () => { @@ -133,21 +127,20 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', ( let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-reference-without-declaration-local-scope.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - 'foo': 'foo_from_cache' - }, - propertyIdentifiers: {} - } + const code: string = readFileAsString( + __dirname + '/fixtures/variable-reference-without-declaration-local-scope.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + foo: 'foo_from_cache' + }, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should transform variable reference name', () => { @@ -161,19 +154,18 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', ( let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-reference-without-declaration-local-scope.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: {}, - propertyIdentifiers: {} - } + const code: string = readFileAsString( + __dirname + '/fixtures/variable-reference-without-declaration-local-scope.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: {}, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not transform variable reference name', () => { @@ -187,22 +179,21 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', ( let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-reference-without-declaration-local-scope.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameGlobals: true, - identifierNamesCache: { - globalIdentifiers: { - 'foo': 'foo_from_cache' - }, - propertyIdentifiers: {} + const code: string = readFileAsString( + __dirname + '/fixtures/variable-reference-without-declaration-local-scope.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameGlobals: true, + identifierNamesCache: { + globalIdentifiers: { + foo: 'foo_from_cache' }, - reservedNames: ['^foo$'] - } - ).getObfuscatedCode(); + propertyIdentifiers: {} + }, + reservedNames: ['^foo$'] + }).getObfuscatedCode(); }); it('should not transform variable reference name', () => { diff --git a/test/functional-tests/node-transformers/rename-properties-transformers/rename-properties-transformer/RenamePropertiesTransformer.spec.ts b/test/functional-tests/node-transformers/rename-properties-transformers/rename-properties-transformer/RenamePropertiesTransformer.spec.ts index 8f0a46efe..10d1112ec 100644 --- a/test/functional-tests/node-transformers/rename-properties-transformers/rename-properties-transformer/RenamePropertiesTransformer.spec.ts +++ b/test/functional-tests/node-transformers/rename-properties-transformers/rename-properties-transformer/RenamePropertiesTransformer.spec.ts @@ -19,21 +19,17 @@ describe('RenamePropertiesTransformer', () => { const property3RegExp: RegExp = /\['(_0x[a-f0-9]{4,6})']: *0x3/; const property4RegExp: RegExp = /\[hawk]: *0x4/; - let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/base.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Match #1: should rename property', () => { @@ -64,15 +60,12 @@ describe('RenamePropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/property-definition-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Match #1: should rename property definition', () => { @@ -100,21 +93,17 @@ describe('RenamePropertiesTransformer', () => { const property3RegExp: RegExp = /\['c']: *0x3/; const property4RegExp: RegExp = /\[hawk]: *0x4/; - let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/base.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Match #1: should rename property', () => { @@ -145,15 +134,12 @@ describe('RenamePropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/property-definition-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Match #1: should rename property definition', () => { @@ -181,22 +167,18 @@ describe('RenamePropertiesTransformer', () => { const property3RegExp: RegExp = /\['c']: *0x3/; const property4RegExp: RegExp = /\[d]: *0x4/; - let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/base.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - renameGlobals: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + renameGlobals: true + }).getObfuscatedCode(); }); it('Match #1: should rename variable name', () => { @@ -225,29 +207,28 @@ describe('RenamePropertiesTransformer', () => { }); describe('Variant #4: properties rename of nested objects', () => { - const regExp: RegExp = new RegExp('' + - 'const foo *= *{' + - '\'a\': *{' + - '\'b\': *0x1' + + const regExp: RegExp = new RegExp( + '' + + 'const foo *= *{' + + "'a': *{" + + "'b': *0x1" + '}' + - '};' + - 'const bar *= *foo\\[\'a\']\\[\'b\'];' + - ''); + '};' + + "const bar *= *foo\\['a']\\['b'];" + + '' + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/nested-objects.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Should rename property', () => { @@ -256,28 +237,27 @@ describe('RenamePropertiesTransformer', () => { }); describe('Variant #5: properties rename of rest element', () => { - const regExp: RegExp = new RegExp('' + - 'const foo *= *{' + - '\'a\': *0x1' + - '};' + - 'const \\{a: *bar} *= *foo;' + - 'const baz *= *bar;' + - ''); + const regExp: RegExp = new RegExp( + '' + + 'const foo *= *{' + + "'a': *0x1" + + '};' + + 'const \\{a: *bar} *= *foo;' + + 'const baz *= *bar;' + + '' + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/rest-element.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Should rename property', () => { @@ -286,30 +266,29 @@ describe('RenamePropertiesTransformer', () => { }); describe('Variant #6: reserved dom properties', () => { - const regExp: RegExp = new RegExp('' + - 'const foo *= *{' + - '\'a\': *0x1,' + - '\'join\': *0x2,' + - '\'b\': *0x3,' + - '\'c\': *0x4' + - '};' + - 'const baz *= *foo\\[\'a\'] *\\+ *foo\\[\'join\'] *\\+ *foo\\[\'b\'] *\\+ *foo\\[\'c\'];' + - ''); + const regExp: RegExp = new RegExp( + '' + + 'const foo *= *{' + + "'a': *0x1," + + "'join': *0x2," + + "'b': *0x3," + + "'c': *0x4" + + '};' + + "const baz *= *foo\\['a'] *\\+ *foo\\['join'] *\\+ *foo\\['b'] *\\+ *foo\\['c'];" + + '' + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/reserved-properties.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Should rename non-reserved properties', () => { @@ -318,31 +297,30 @@ describe('RenamePropertiesTransformer', () => { }); describe('Variant #7: reserved names properties', () => { - const regExp: RegExp = new RegExp('' + - 'const foo *= *{' + - '\'a\': *0x1,' + - '\'join\': *0x2,' + - '\'reserved\': *0x3,' + - '\'private_\': *0x4' + - '};' + - 'const baz *= *foo\\[\'a\'] *\\+ *foo\\[\'join\'] *\\+ *foo\\[\'reserved\'] *\\+ *foo\\[\'private_\'];' + - ''); + const regExp: RegExp = new RegExp( + '' + + 'const foo *= *{' + + "'a': *0x1," + + "'join': *0x2," + + "'reserved': *0x3," + + "'private_': *0x4" + + '};' + + "const baz *= *foo\\['a'] *\\+ *foo\\['join'] *\\+ *foo\\['reserved'] *\\+ *foo\\['private_'];" + + '' + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/reserved-properties.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - reservedNames: ['^reserved$', '_$'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + reservedNames: ['^reserved$', '_$'] + }).getObfuscatedCode(); }); it('Should rename non-reserved properties', () => { @@ -351,29 +329,28 @@ describe('RenamePropertiesTransformer', () => { }); describe('Variant #8: class methods', () => { - const regExp: RegExp = new RegExp('' + - 'class Foo *{' + - '\\[\'a\'] *\\(\\) *{}' + - '}' + - 'const foo *= *new Foo\\(\\);' + - 'foo\\[\'a\']\\(\\);' + - ''); + const regExp: RegExp = new RegExp( + '' + + 'class Foo *{' + + "\\['a'] *\\(\\) *{}" + + '}' + + 'const foo *= *new Foo\\(\\);' + + "foo\\['a']\\(\\);" + + '' + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/class-methods.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - reservedNames: ['^reserved$', '_$'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + reservedNames: ['^reserved$', '_$'] + }).getObfuscatedCode(); }); it('Should rename class method name', () => { @@ -384,9 +361,9 @@ describe('RenamePropertiesTransformer', () => { describe('Variant #9: integration with `splitStrings` option', () => { const propertyRegExp: RegExp = new RegExp( 'const foo *= *{' + - '\'a\': *\'long\' *\\+ *\'Prop\' *\\+ *\'erty\' *\\+ *\'Valu\' *\\+ *\'e\'' + - '};' + - 'foo\\[\'a\'];' + "'a': *'long' *\\+ *'Prop' *\\+ *'erty' *\\+ *'Valu' *\\+ *'e'" + + '};' + + "foo\\['a'];" ); let obfuscatedCode: string; @@ -394,17 +371,14 @@ describe('RenamePropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/split-strings-integration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - splitStrings: true, - splitStringsChunkLength: 4 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + splitStrings: true, + splitStringsChunkLength: 4 + }).getObfuscatedCode(); }); it('Should rename property before `splitStrings` option will applied', () => { @@ -415,30 +389,29 @@ describe('RenamePropertiesTransformer', () => { describe('Variant #10: integration with `controlFlowFlattening` option', () => { const propertyRegExp: RegExp = new RegExp( 'const b *= *{ *' + - '\'\\w{5}\' *: *\'a\' *' + - '}; *' + - 'const c *= *{' + - '\'a\': *0x1' + - '};' + - 'c\\[b\\[\'\\w{5}\']];' + "'\\w{5}' *: *'a' *" + + '}; *' + + 'const c *= *{' + + "'a': *0x1" + + '};' + + "c\\[b\\['\\w{5}']];" ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/control-flow-flattening-integration.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/control-flow-flattening-integration.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + }).getObfuscatedCode(); }); it('Should correctly rename property when `controlFlowFlattening` option is enabled', () => { @@ -448,27 +421,23 @@ describe('RenamePropertiesTransformer', () => { describe('Variant #11: integration with `transformObjectKeys` option', () => { const propertyRegExp: RegExp = new RegExp( - 'const b *= *{}; *' + - 'b\\[\'a\'] *= *0x1;' + - 'const foo *= *b;' + - 'foo\\[\'a\'];' + 'const b *= *{}; *' + "b\\['a'] *= *0x1;" + 'const foo *= *b;' + "foo\\['a'];" ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/transform-object-keys-integration.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - transformObjectKeys: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/transform-object-keys-integration.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + transformObjectKeys: true + }).getObfuscatedCode(); }); it('Should correctly rename property when `transformObjectKeys` option is enabled', () => { @@ -486,14 +455,11 @@ describe('RenamePropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/boolean-literal-node.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe + }).getObfuscatedCode(); }); it('Match #1: should skip literal property with invalid type', () => { @@ -510,16 +476,13 @@ describe('RenamePropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/duplicated-generated-names-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Unsafe, - identifierNamesGenerator: 'mangled', - reservedNames: ['^a$'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Unsafe, + identifierNamesGenerator: 'mangled', + reservedNames: ['^a$'] + }).getObfuscatedCode(); }); it('Match #1: should skip literal property with invalid type', () => { @@ -530,43 +493,44 @@ describe('RenamePropertiesTransformer', () => { describe('Mode: `safe`', () => { describe('Variant #1: base properties rename', () => { - const declarationsRegExp: RegExp = new RegExp('' + - 'const object *= *{' + - '\'foo\': *0x1, *' + - '\'a\': *0x2 *' + - '}; *' + - 'class Class *{ *' + - '\\[\'baz\'] *= *0x1; *' + - 'static *\\[\'b\'] *= *0x2;*' + - 'static *\\[\'hawk\'] *\\(\\) *{} *' + - 'static *\\[\'c\'] *\\(\\) *{} *' + - '}' + - ''); - const referencesRegExp: RegExp = new RegExp('' + - 'console\\[\'log\']\\(' + - 'object\\[\'foo\'], *' + - 'object\\[\'a\'], *' + - 'Class\\[\'baz\'], *' + - 'Class\\[\'b\'], *' + - 'Class\\[\'hawk\'], *' + - 'Class\\[\'c\'] *' + - '\\);' + - ''); + const declarationsRegExp: RegExp = new RegExp( + '' + + 'const object *= *{' + + "'foo': *0x1, *" + + "'a': *0x2 *" + + '}; *' + + 'class Class *{ *' + + "\\['baz'] *= *0x1; *" + + "static *\\['b'] *= *0x2;*" + + "static *\\['hawk'] *\\(\\) *{} *" + + "static *\\['c'] *\\(\\) *{} *" + + '}' + + '' + ); + const referencesRegExp: RegExp = new RegExp( + '' + + "console\\['log']\\(" + + "object\\['foo'], *" + + "object\\['a'], *" + + "Class\\['baz'], *" + + "Class\\['b'], *" + + "Class\\['hawk'], *" + + "Class\\['c'] *" + + '\\);' + + '' + ); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/safe-mode.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Safe, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Safe, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('Should rename property declarations', () => { @@ -586,16 +550,13 @@ describe('RenamePropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/duplicated-generated-names-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - renamePropertiesMode: RenamePropertiesMode.Safe, - identifierNamesGenerator: 'mangled', - reservedNames: ['^a$'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + renamePropertiesMode: RenamePropertiesMode.Safe, + identifierNamesGenerator: 'mangled', + reservedNames: ['^a$'] + }).getObfuscatedCode(); }); it('Match #1: should skip literal property with invalid type', () => { @@ -615,17 +576,14 @@ describe('RenamePropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/property-identifier-names-cache.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - identifierNamesCache: { - globalIdentifiers: {}, - propertyIdentifiers: {} - } + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + identifierNamesCache: { + globalIdentifiers: {}, + propertyIdentifiers: {} } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('Match #1: should rename property', () => { @@ -651,20 +609,17 @@ describe('RenamePropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/property-identifier-names-cache.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - identifierNamesCache: { - globalIdentifiers: {}, - propertyIdentifiers: { - bar: 'bar_from_cache', - baz: 'baz_from_cache' - } + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + identifierNamesCache: { + globalIdentifiers: {}, + propertyIdentifiers: { + bar: 'bar_from_cache', + baz: 'baz_from_cache' } } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('Match #1: should rename property based on the cache value', () => { @@ -690,21 +645,18 @@ describe('RenamePropertiesTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/property-identifier-names-cache.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - renameProperties: true, - identifierNamesCache: { - globalIdentifiers: {}, - propertyIdentifiers: { - bar: 'bar_from_cache', - baz: 'baz_from_cache' - } - }, - reservedNames: ['^baz$'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + renameProperties: true, + identifierNamesCache: { + globalIdentifiers: {}, + propertyIdentifiers: { + bar: 'bar_from_cache', + baz: 'baz_from_cache' + } + }, + reservedNames: ['^baz$'] + }).getObfuscatedCode(); }); it('Match #1: should rename property based on the cache value', () => { diff --git a/test/functional-tests/node-transformers/simplifying-transformers/block-statement-simplify-transformer/BlockStatementSimplifyTransformer.spec.ts b/test/functional-tests/node-transformers/simplifying-transformers/block-statement-simplify-transformer/BlockStatementSimplifyTransformer.spec.ts index 10928997b..73151a55a 100644 --- a/test/functional-tests/node-transformers/simplifying-transformers/block-statement-simplify-transformer/BlockStatementSimplifyTransformer.spec.ts +++ b/test/functional-tests/node-transformers/simplifying-transformers/block-statement-simplify-transformer/BlockStatementSimplifyTransformer.spec.ts @@ -10,25 +10,17 @@ describe('BlockStatementSimplifyTransformer', () => { describe('Full `BlockStatement` simplify cases', () => { describe('No `ReturnStatement`', () => { describe('Variant #1: single statement', () => { - const regExp: RegExp = new RegExp( - 'function foo *\\(\\) *{ *' + - 'bar\\(\\); *' + - '}' - ); - + const regExp: RegExp = new RegExp('function foo *\\(\\) *{ *' + 'bar\\(\\); *' + '}'); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/full-no-return-single-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify block statement', () => { @@ -38,24 +30,20 @@ describe('BlockStatementSimplifyTransformer', () => { describe('Variant #2: multiple statements', () => { const regExp: RegExp = new RegExp( - 'function foo *\\(\\) *{ *' + - 'bar\\(\\), *baz\\(\\), *bark\\(\\); *' + - '}' + 'function foo *\\(\\) *{ *' + 'bar\\(\\), *baz\\(\\), *bark\\(\\); *' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-no-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-no-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify block statement', () => { @@ -66,25 +54,17 @@ describe('BlockStatementSimplifyTransformer', () => { describe('With `ReturnStatement`', () => { describe('Variant #1: single statement', () => { - const regExp: RegExp = new RegExp( - 'function foo *\\(\\) *{ *' + - 'return bar\\(\\); *' + - '}' - ); - + const regExp: RegExp = new RegExp('function foo *\\(\\) *{ *' + 'return bar\\(\\); *' + '}'); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/full-return-single-statement.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify block statement', () => { @@ -94,24 +74,18 @@ describe('BlockStatementSimplifyTransformer', () => { describe('Variant #2: multiple statements', () => { const regExp: RegExp = new RegExp( - 'function foo *\\(\\) *{ *' + - 'return bar\\(\\), *baz\\(\\), *bark\\(\\); *' + - '}' + 'function foo *\\(\\) *{ *' + 'return bar\\(\\), *baz\\(\\), *bark\\(\\); *' + '}' ); - let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/full-return-multiple-statements.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify block statement', () => { @@ -125,24 +99,20 @@ describe('BlockStatementSimplifyTransformer', () => { describe('No `ReturnStatement`', () => { describe('Variant #1: single statement', () => { const regExp: RegExp = new RegExp( - 'function foo *\\(\\) *{ *' + - 'var _0x([a-f0-9]){4,6} *= *baz\\(\\);' + - '}' + 'function foo *\\(\\) *{ *' + 'var _0x([a-f0-9]){4,6} *= *baz\\(\\);' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-no-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-no-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify block statement', () => { @@ -155,22 +125,20 @@ describe('BlockStatementSimplifyTransformer', () => { 'function foo *\\(\\) *{ *' + 'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' + 'bark\\(\\), *hawk\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-no-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-no-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify block statement', () => { @@ -185,22 +153,20 @@ describe('BlockStatementSimplifyTransformer', () => { 'function foo *\\(\\) *{ *' + 'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' + 'return bark\\(\\), *hawk\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify block statement', () => { @@ -216,24 +182,22 @@ describe('BlockStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'function foo *\\(\\) *{ *' + 'var _0x([a-f0-9]){4,6} *= *function *\\(\\) *{}, *' + - '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{}, *' + - '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{}; *' + - '}' + '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{}, *' + + '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{}; *' + + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarations-merge-transformer-integration-1.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarations-merge-transformer-integration-1.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify block statement', () => { diff --git a/test/functional-tests/node-transformers/simplifying-transformers/expression-statements-merge-transformer/ExpressionStatementsMergeTransformer.spec.ts b/test/functional-tests/node-transformers/simplifying-transformers/expression-statements-merge-transformer/ExpressionStatementsMergeTransformer.spec.ts index c73880216..0f9ffeb1f 100644 --- a/test/functional-tests/node-transformers/simplifying-transformers/expression-statements-merge-transformer/ExpressionStatementsMergeTransformer.spec.ts +++ b/test/functional-tests/node-transformers/simplifying-transformers/expression-statements-merge-transformer/ExpressionStatementsMergeTransformer.spec.ts @@ -9,26 +9,18 @@ import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFac describe('ExpressionStatementsMergeTransformer', () => { describe('Variant #1: simple', () => { const regExp: RegExp = new RegExp( - 'function foo *\\(\\) *{ *' + - 'bar\\(\\), *' + - 'baz\\(\\), *' + - 'bark\\(\\); *' + - '}' + 'function foo *\\(\\) *{ *' + 'bar\\(\\), *' + 'baz\\(\\), *' + 'bark\\(\\); *' + '}' ); - let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should merge expression statements', () => { @@ -39,30 +31,26 @@ describe('ExpressionStatementsMergeTransformer', () => { describe('Variant #2: complex', () => { const regExp: RegExp = new RegExp( 'function foo *\\(\\) *{ *' + - 'console\\[\'log\']\\(0x1\\), *' + - 'console\\[\'log\']\\(0x2\\); *' + + "console\\['log']\\(0x1\\), *" + + "console\\['log']\\(0x2\\); *" + 'function _0x([a-f0-9]){4,6} *\\(\\) *{ *} *' + - 'console\\[\'log\']\\(0x3\\), *' + - 'console\\[\'log\']\\(0x4\\), *' + - 'console\\[\'log\']\\(0x5\\); *' + + "console\\['log']\\(0x3\\), *" + + "console\\['log']\\(0x4\\), *" + + "console\\['log']\\(0x5\\); *" + 'const _0x([a-f0-9]){4,6} *= *0x6; *' + - 'console\\[\'log\']\\(0x7\\); *' + - '}' + "console\\['log']\\(0x7\\); *" + + '}' ); - let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/complex.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should merge expression statements', () => { diff --git a/test/functional-tests/node-transformers/simplifying-transformers/if-statement-simplify-transformer/IfStatementSimplifyTransformer.spec.ts b/test/functional-tests/node-transformers/simplifying-transformers/if-statement-simplify-transformer/IfStatementSimplifyTransformer.spec.ts index f24c16230..6889daf5b 100644 --- a/test/functional-tests/node-transformers/simplifying-transformers/if-statement-simplify-transformer/IfStatementSimplifyTransformer.spec.ts +++ b/test/functional-tests/node-transformers/simplifying-transformers/if-statement-simplify-transformer/IfStatementSimplifyTransformer.spec.ts @@ -11,23 +11,19 @@ describe('IfStatementSimplifyTransformer', () => { describe('Consequent only', () => { describe('No `ReturnStatement`', () => { describe('Variant #1: single statement', () => { - const regExp: RegExp = new RegExp( - '!!\\[] *&& *bar\\(\\);' - ); - + const regExp: RegExp = new RegExp('!!\\[] *&& *bar\\(\\);'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-only-no-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-only-no-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -36,23 +32,19 @@ describe('IfStatementSimplifyTransformer', () => { }); describe('Variant #2: multiple statements', () => { - const regExp: RegExp = new RegExp( - '!!\\[] *&& *\\(bar\\(\\) *, *baz\\(\\) *, *bark\\(\\)\\);' - ); - + const regExp: RegExp = new RegExp('!!\\[] *&& *\\(bar\\(\\) *, *baz\\(\\) *, *bark\\(\\)\\);'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-only-no-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-only-no-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -63,24 +55,19 @@ describe('IfStatementSimplifyTransformer', () => { describe('With `ReturnStatement`', () => { describe('Variant #1: single statement', () => { - const regExp: RegExp = new RegExp( - 'if *\\(!!\\[]\\) *' + - 'return *bar\\(\\);' - ); - + const regExp: RegExp = new RegExp('if *\\(!!\\[]\\) *' + 'return *bar\\(\\);'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-only-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-only-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -90,23 +77,20 @@ describe('IfStatementSimplifyTransformer', () => { describe('Variant #2: multiple statements', () => { const regExp: RegExp = new RegExp( - 'if *\\(!!\\[]\\) *' + - 'return *bar\\(\\) *, *baz\\(\\) *, *bark\\(\\);' + 'if *\\(!!\\[]\\) *' + 'return *bar\\(\\) *, *baz\\(\\) *, *bark\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-only-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-only-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -118,22 +102,20 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *\\{ *' + 'bar\\(\\), *baz\\(\\); *return bark\\(\\); *hawk\\(\\), *eagle\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-only-statements-after-return.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-only-statements-after-return.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -146,25 +128,19 @@ describe('IfStatementSimplifyTransformer', () => { describe('Consequent and alternate', () => { describe('No `ReturnStatement`', () => { describe('Variant #1: single statement', () => { - const regExp: RegExp = new RegExp( - '!!\\[] *' + - '\\? *bar\\(\\) *' + - ': *baz\\(\\);' - ); - + const regExp: RegExp = new RegExp('!!\\[] *' + '\\? *bar\\(\\) *' + ': *baz\\(\\);'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-no-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-and-alternate-no-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -179,19 +155,17 @@ describe('IfStatementSimplifyTransformer', () => { ': *\\(hawk\\(\\) *, *pork\\(\\) *, *eagle\\(\\)\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-no-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-and-alternate-no-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -203,25 +177,20 @@ describe('IfStatementSimplifyTransformer', () => { describe('With consequent `ReturnStatement`', () => { describe('Variant #1: single statement', () => { const regExp: RegExp = new RegExp( - 'if *\\(!!\\[]\\) *' + - 'return *bar\\(\\); *' + - 'else *' + - 'baz\\(\\);' + 'if *\\(!!\\[]\\) *' + 'return *bar\\(\\); *' + 'else *' + 'baz\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-consequent-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-and-alternate-consequent-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -233,23 +202,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *' + 'return *bar\\(\\) *, *baz\\(\\) *, *bark\\(\\); *' + - 'else *' + + 'else *' + 'hawk\\(\\) *, *pork\\(\\) *, *eagle\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-consequent-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + + '/fixtures/full-consequent-and-alternate-consequent-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -261,22 +229,21 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *\\{ *' + 'bar\\(\\), *baz\\(\\); *return bark\\(\\); *cat\\(\\), *dog\\(\\); *' + - '\\} *else *' + + '\\} *else *' + 'hawk\\(\\), *pork\\(\\), *eagle\\(\\);' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-consequent-statements-after-return.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-and-alternate-consequent-statements-after-return.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -288,25 +255,20 @@ describe('IfStatementSimplifyTransformer', () => { describe('With alternate `ReturnStatement`', () => { describe('Variant #1: single statement', () => { const regExp: RegExp = new RegExp( - 'if *\\(!!\\[]\\) *' + - 'bar\\(\\); *' + - 'else *' + - 'return *baz\\(\\);' + 'if *\\(!!\\[]\\) *' + 'bar\\(\\); *' + 'else *' + 'return *baz\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-alternate-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-and-alternate-alternate-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -318,23 +280,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *' + 'bar\\(\\) *, *baz\\(\\) *, *bark\\(\\); *' + - 'else *' + + 'else *' + 'return *hawk\\(\\) *, *pork\\(\\) *, *eagle\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-alternate-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + + '/fixtures/full-consequent-and-alternate-alternate-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -346,23 +307,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *' + 'bar\\(\\), *baz\\(\\), *bark\\(\\); *' + - 'else *\\{ *' + + 'else *\\{ *' + 'hawk\\(\\), *eagle\\(\\); *return cow\\(\\); *cat\\(\\), *dog\\(\\);' + - '\\}' + '\\}' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-alternate-statements-after-return.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-and-alternate-alternate-statements-after-return.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -373,25 +333,19 @@ describe('IfStatementSimplifyTransformer', () => { describe('With consequent and alternate `ReturnStatement`', () => { describe('Variant #1: single statement', () => { - const regExp: RegExp = new RegExp( - 'return *!!\\[] *' + - '\\? *bar\\(\\) *' + - ': *baz\\(\\);' - ); - + const regExp: RegExp = new RegExp('return *!!\\[] *' + '\\? *bar\\(\\) *' + ': *baz\\(\\);'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-and-alternate-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -406,19 +360,17 @@ describe('IfStatementSimplifyTransformer', () => { ': *\\(hawk\\(\\) *, *pork\\(\\) *, *eagle\\(\\)\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/full-consequent-and-alternate-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/full-consequent-and-alternate-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -433,24 +385,19 @@ describe('IfStatementSimplifyTransformer', () => { describe('Consequent only', () => { describe('No `ReturnStatement`', () => { describe('Variant #1: single statement', () => { - const regExp: RegExp = new RegExp( - 'if *\\(!!\\[]\\) *' + - 'var _0x([a-f0-9]){4,6} *= *baz\\(\\);' - ); - + const regExp: RegExp = new RegExp('if *\\(!!\\[]\\) *' + 'var _0x([a-f0-9]){4,6} *= *baz\\(\\);'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-only-no-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-consequent-only-no-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -463,22 +410,20 @@ describe('IfStatementSimplifyTransformer', () => { 'if *\\(!!\\[]\\) *{ *' + 'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' + 'bark\\(\\), *hawk\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-only-no-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-consequent-only-no-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -493,22 +438,20 @@ describe('IfStatementSimplifyTransformer', () => { 'if *\\(!!\\[]\\) *{ *' + 'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' + 'return bark\\(\\), *hawk\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-only-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-consequent-only-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -522,22 +465,20 @@ describe('IfStatementSimplifyTransformer', () => { 'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' + 'return bark\\(\\); *' + 'hawk\\(\\), *eagle\\(\\); *' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-only-statements-after-return.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-consequent-only-statements-after-return.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -553,23 +494,21 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *' + 'var *_0x([a-f0-9]){4,6} *= *baz\\(\\); *' + - 'else *' + + 'else *' + 'var *_0x([a-f0-9]){4,6} *= *hawk\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-no-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-consequent-and-alternate-no-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -581,27 +520,25 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'const *_0x([a-f0-9]){4,6} *= *baz\\(\\), *' + - '_0x([a-f0-9]){4,6} *= *hawk\\(\\); *' + + '_0x([a-f0-9]){4,6} *= *hawk\\(\\); *' + 'eagle\\(\\), *pork\\(\\);' + - '} *else *{ *' + + '} *else *{ *' + 'const *_0x([a-f0-9]){4,6} *= *cow\\(\\); *' + 'lion\\(\\), *pig\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-no-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-consequent-and-alternate-no-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -613,25 +550,23 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *' + 'var *_0x([a-f0-9]){4,6} *= *baz\\(\\); *' + - 'else *{ *' + + 'else *{ *' + 'const *_0x([a-f0-9]){4,6} *= *hawk\\(\\); *' + 'eagle\\(\\), *dog\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-no-return-mixed-statements-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-consequent-and-alternate-no-return-mixed-statements-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -643,25 +578,23 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'const *_0x([a-f0-9]){4,6} *= *baz\\(\\), *' + - '_0x([a-f0-9]){4,6} *= *hawk\\(\\); *' + + '_0x([a-f0-9]){4,6} *= *hawk\\(\\); *' + 'eagle\\(\\), *pork\\(\\);' + - '} *else *' + + '} *else *' + 'var *_0x([a-f0-9]){4,6} *= *cow\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-no-return-mixed-statements-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-consequent-and-alternate-no-return-mixed-statements-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -675,23 +608,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *' + 'return *bar\\(\\); *' + - 'else *' + + 'else *' + 'var *_0x([a-f0-9]){4,6} *= *bark\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-consequent-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + + '/fixtures/partial-consequent-and-alternate-consequent-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -703,27 +635,26 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'const *_0x([a-f0-9]){4,6} *= *baz\\(\\), *' + - '_0x([a-f0-9]){4,6} *= *hawk\\(\\); *' + + '_0x([a-f0-9]){4,6} *= *hawk\\(\\); *' + 'return *eagle\\(\\), *cat\\(\\);' + - '} *else *{ *' + + '} *else *{ *' + 'const *_0x([a-f0-9]){4,6} *= *pig\\(\\); *' + 'lion\\(\\), *dog\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-consequent-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + + '/fixtures/partial-consequent-and-alternate-consequent-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -737,25 +668,24 @@ describe('IfStatementSimplifyTransformer', () => { 'const *_0x([a-f0-9]){4,6} *= *baz\\(\\); *' + 'return hawk\\(\\); *' + 'eagle\\(\\), *cat\\(\\);' + - '} *else *{ *' + + '} *else *{ *' + 'const *_0x([a-f0-9]){4,6} *= *pig\\(\\); *' + 'lion\\(\\), *dog\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-consequent-statements-after-return.js'); + const code: string = readFileAsString( + __dirname + + '/fixtures/partial-consequent-and-alternate-consequent-statements-after-return.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -769,23 +699,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *' + 'var *_0x([a-f0-9]){4,6} *= *baz\\(\\); *' + - 'else *' + + 'else *' + 'return *bark\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-alternate-return-single-statement.js'); + const code: string = readFileAsString( + __dirname + + '/fixtures/partial-consequent-and-alternate-alternate-return-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -798,26 +727,25 @@ describe('IfStatementSimplifyTransformer', () => { 'if *\\(!!\\[]\\) *{ *' + 'const *_0x([a-f0-9]){4,6} *= *baz\\(\\); *' + 'bark\\(\\), *hawk\\(\\);' + - '} *else *{ *' + + '} *else *{ *' + 'const *_0x([a-f0-9]){4,6} *= *pork\\(\\), *' + - '_0x([a-f0-9]){4,6} *= *dog\\(\\); *' + + '_0x([a-f0-9]){4,6} *= *dog\\(\\); *' + 'return *pig\\(\\), *lion\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-alternate-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + + '/fixtures/partial-consequent-and-alternate-alternate-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -830,26 +758,25 @@ describe('IfStatementSimplifyTransformer', () => { 'if *\\(!!\\[]\\) *{ *' + 'const *_0x([a-f0-9]){4,6} *= *baz\\(\\); *' + 'bark\\(\\), *hawk\\(\\);' + - '} *else *{ *' + + '} *else *{ *' + 'const *_0x([a-f0-9]){4,6} *= *pork\\(\\); *' + 'return dog\\(\\); *' + 'pig\\(\\), *lion\\(\\); *' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-alternate-statements-after-return.js'); + const code: string = readFileAsString( + __dirname + + '/fixtures/partial-consequent-and-alternate-alternate-statements-after-return.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -863,28 +790,26 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'const *_0x([a-f0-9]){4,6} *= *baz\\(\\), *' + - '_0x([a-f0-9]){4,6} *= *eagle\\(\\); *' + + '_0x([a-f0-9]){4,6} *= *eagle\\(\\); *' + 'return *hawk\\(\\), *lion\\(\\);' + - '} *else *{ *' + + '} *else *{ *' + 'const *_0x([a-f0-9]){4,6} *= *dog\\(\\), *' + - '_0x([a-f0-9]){4,6} *= *hamster\\(\\); *' + + '_0x([a-f0-9]){4,6} *= *hamster\\(\\); *' + 'return *parrot\\(\\), *bull\\(\\);' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-and-alternate-return-multiple-statements.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/partial-consequent-and-alternate-return-multiple-statements.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -901,23 +826,21 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *' + 'var _0x([a-f0-9]){4,6} *= *function *\\(\\) *{}, *' + - '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{}, *' + - '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{};' + '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{}, *' + + '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{};' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/variable-declarations-merge-transformer-integration-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/variable-declarations-merge-transformer-integration-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should simplify if statement', () => { @@ -928,28 +851,26 @@ describe('IfStatementSimplifyTransformer', () => { describe('Prohibited single statement', () => { describe('Variant #1: `IfStatement` as prohibited single statement', () => { - describe('Variant #1: `IfStatement` with `var` variable inside`' , () => { + describe('Variant #1: `IfStatement` with `var` variable inside`', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'if *\\(!\\[]\\) *' + - 'var _0x([a-f0-9]){4,6} *= *baz\\(\\); *' + - '} *else *' + + 'var _0x([a-f0-9]){4,6} *= *baz\\(\\); *' + + '} *else *' + 'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/if-statement-as-prohibited-single-statement-1.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/if-statement-as-prohibited-single-statement-1.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -957,29 +878,27 @@ describe('IfStatementSimplifyTransformer', () => { }); }); - describe('Variant #2: `IfStatement` with `const` variable inside`' , () => { + describe('Variant #2: `IfStatement` with `const` variable inside`', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'if *\\(!\\[]\\) *{ *' + - 'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' + + 'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' + '} *' + - '} *else *' + + '} *else *' + 'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/if-statement-as-prohibited-single-statement-2.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/if-statement-as-prohibited-single-statement-2.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -993,27 +912,26 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'for *\\( *' + - 'let _0x([a-f0-9]){4,6} *= *0x0; *' + - '_0x([a-f0-9]){4,6} *< *0x1; *' + - '_0x([a-f0-9]){4,6}\\+\\+ *' + + 'let _0x([a-f0-9]){4,6} *= *0x0; *' + + '_0x([a-f0-9]){4,6} *< *0x1; *' + + '_0x([a-f0-9]){4,6}\\+\\+ *' + '\\) *' + - 'console\\[\'log\']\\(_0x([a-f0-9]){4,6}\\); *' + - '} *else *' + + "console\\['log']\\(_0x([a-f0-9]){4,6}\\); *" + + '} *else *' + 'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/single-line-for-statement-as-prohibited-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/single-line-for-statement-as-prohibited-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -1025,23 +943,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'for *\\(const _0x([a-f0-9]){4,6} of *\\[\\]\\) *' + - 'console\\[\'log\']\\(_0x([a-f0-9]){4,6}\\); *' + - '} *else *' + + "console\\['log']\\(_0x([a-f0-9]){4,6}\\); *" + + '} *else *' + 'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/single-line-for-of-statement-as-prohibited-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/single-line-for-of-statement-as-prohibited-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -1053,23 +970,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'for *\\(const _0x([a-f0-9]){4,6} in *\\{\\}\\) *' + - 'console\\[\'log\']\\(_0x([a-f0-9]){4,6}\\); *' + - '} *else *' + + "console\\['log']\\(_0x([a-f0-9]){4,6}\\); *" + + '} *else *' + 'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/single-line-for-in-statement-as-prohibited-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/single-line-for-in-statement-as-prohibited-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -1081,23 +997,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'while *\\(!!\\[]\\) *' + - 'console\\[\'log\']\\(0x1\\); *' + - '} *else *' + + "console\\['log']\\(0x1\\); *" + + '} *else *' + 'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/single-line-while-statement-as-prohibited-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/single-line-while-statement-as-prohibited-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -1109,24 +1024,23 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'do *' + - 'console\\[\'log\']\\(0x1\\); *' + + "console\\['log']\\(0x1\\); *" + 'while *\\(!!\\[]\\); *' + - '} *else *' + + '} *else *' + 'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/single-line-do-while-statement-as-prohibited-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/single-line-do-while-statement-as-prohibited-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -1138,23 +1052,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + '_0x([a-f0-9]){4,6}: *' + - 'console\\[\'log\']\\(0x1\\); *' + - '} *else *' + + "console\\['log']\\(0x1\\); *" + + '} *else *' + 'var _0x([a-f0-9]){4,6} *= *hawk\\(\\);' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/single-line-labeled-statement-as-prohibited-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/single-line-labeled-statement-as-prohibited-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -1167,24 +1080,22 @@ describe('IfStatementSimplifyTransformer', () => { const regExp: RegExp = new RegExp( 'if *\\(!!\\[]\\) *{ *' + 'function _0x([a-f0-9]){4,6} *\\(\\) *{} *' + - '} *else *{ *' + + '} *else *{ *' + 'function _0x([a-f0-9]){4,6} *\\(\\) *{} *' + - '}' + '}' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/function-declaration-as-prohibited-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/function-declaration-as-prohibited-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -1193,25 +1104,19 @@ describe('IfStatementSimplifyTransformer', () => { }); describe('Variant #4: `let` `VariableDeclaration` as prohibited single statement', () => { - const regExp: RegExp = new RegExp( - 'if *\\(!!\\[]\\) *{ *' + - 'let foo *= *0x1; *' + - '}' - ); - + const regExp: RegExp = new RegExp('if *\\(!!\\[]\\) *{ *' + 'let foo *= *0x1; *' + '}'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/let-variable-declaration-as-prohibited-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/let-variable-declaration-as-prohibited-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { @@ -1220,25 +1125,19 @@ describe('IfStatementSimplifyTransformer', () => { }); describe('Variant #5: `const` `VariableDeclaration` as prohibited single statement', () => { - const regExp: RegExp = new RegExp( - 'if *\\(!!\\[]\\) *{ *' + - 'const foo *= *0x1; *' + - '}' - ); - + const regExp: RegExp = new RegExp('if *\\(!!\\[]\\) *{ *' + 'const foo *= *0x1; *' + '}'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/const-variable-declaration-as-prohibited-single-statement.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/const-variable-declaration-as-prohibited-single-statement.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should not simplify if statement', () => { diff --git a/test/functional-tests/node-transformers/simplifying-transformers/variable-declarations-merge-transformer/VariableDeclarationsMergeTransformer.spec.ts b/test/functional-tests/node-transformers/simplifying-transformers/variable-declarations-merge-transformer/VariableDeclarationsMergeTransformer.spec.ts index 168edecd5..f91c2842d 100644 --- a/test/functional-tests/node-transformers/simplifying-transformers/variable-declarations-merge-transformer/VariableDeclarationsMergeTransformer.spec.ts +++ b/test/functional-tests/node-transformers/simplifying-transformers/variable-declarations-merge-transformer/VariableDeclarationsMergeTransformer.spec.ts @@ -11,23 +11,17 @@ import { ObjectPatternPropertiesTransformer } from '../../../../../src/node-tran describe('VariableDeclarationsMergeTransformer', () => { describe('base behaviour', () => { describe('Variant #1: single variable declaration', () => { - const regExp: RegExp = new RegExp( - 'var foo *= *0x1;' - ); - + const regExp: RegExp = new RegExp('var foo *= *0x1;'); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/single-declaration.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should keep single declaration', () => { @@ -36,25 +30,17 @@ describe('VariableDeclarationsMergeTransformer', () => { }); describe('Variant #2: multiple variable declarations', () => { - const regExp: RegExp = new RegExp( - 'var foo *= *0x1, *' + - 'bar *= *0x2, *' + - 'baz *= *0x3;' - ); - + const regExp: RegExp = new RegExp('var foo *= *0x1, *' + 'bar *= *0x2, *' + 'baz *= *0x3;'); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/multiple-declarations.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should merge variable declarations', () => { @@ -64,24 +50,20 @@ describe('VariableDeclarationsMergeTransformer', () => { describe('Variant #3: multiple variable declarations with multiple declarators', () => { const regExp: RegExp = new RegExp( - 'var foo *= *0x1, *' + - 'bar *= *0x2, *' + - 'baz *= *0x3, *' + - 'bark *= *0x4;' + 'var foo *= *0x1, *' + 'bar *= *0x2, *' + 'baz *= *0x3, *' + 'bark *= *0x4;' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/multiple-declarations-with-multiple-declarators.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/multiple-declarations-with-multiple-declarators.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should merge variable declarations', () => { @@ -93,23 +75,22 @@ describe('VariableDeclarationsMergeTransformer', () => { const regExp: RegExp = new RegExp( 'var foo *= *0x1, *' + 'bar *= *0x2; *' + - 'console\\[\'log\']\\(\'123\'\\); *' + - 'var baz *= *0x3, *' + + "console\\['log']\\('123'\\); *" + + 'var baz *= *0x3, *' + 'bark *= *0x4;' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/splitted-declarations-with-other-statement.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/splitted-declarations-with-other-statement.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should merge variable declarations', () => { @@ -118,25 +99,19 @@ describe('VariableDeclarationsMergeTransformer', () => { }); describe('Variant #5: multiple variable declarations without declarators', () => { - const regExp: RegExp = new RegExp( - 'var foo, *' + - 'bar, *' + - 'baz;' - ); - + const regExp: RegExp = new RegExp('var foo, *' + 'bar, *' + 'baz;'); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/multiple-declarations-without-declarators.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/multiple-declarations-without-declarators.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should merge variable declarations', () => { @@ -148,27 +123,25 @@ describe('VariableDeclarationsMergeTransformer', () => { const regExp: RegExp = new RegExp( 'var foo *= *function *\\(\\) *{ *}, *' + 'bar *= *function *\\(\\) *{ *' + - 'var _0x([a-f0-9]){4,6} *= *function *\\(\\) *{ *}, *' + - '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{ *' + - 'var _0x([a-f0-9]){4,6} *= *0x1, *' + - '_0x([a-f0-9]){4,6} *= *0x2; *' + - '}; *' + + 'var _0x([a-f0-9]){4,6} *= *function *\\(\\) *{ *}, *' + + '_0x([a-f0-9]){4,6} *= *function *\\(\\) *{ *' + + 'var _0x([a-f0-9]){4,6} *= *0x1, *' + + '_0x([a-f0-9]){4,6} *= *0x2; *' + + '}; *' + '};' ); - let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/declarations-inside-nested-function-expressions.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/declarations-inside-nested-function-expressions.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should merge variable declarations', () => { @@ -180,24 +153,17 @@ describe('VariableDeclarationsMergeTransformer', () => { describe('object pattern as initializer', () => { stubNodeTransformers([ObjectPatternPropertiesTransformer]); - const regExp: RegExp = new RegExp( - 'var foo *= *0x1, *' + - '{bar} *= *{\'bar\': *0x2}, *' + - 'baz *= *0x3;' - ); + const regExp: RegExp = new RegExp('var foo *= *0x1, *' + "{bar} *= *{'bar': *0x2}, *" + 'baz *= *0x3;'); let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-initializer.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should merge variable declarations with object pattern', () => { @@ -209,9 +175,9 @@ describe('VariableDeclarationsMergeTransformer', () => { const regExp: RegExp = new RegExp( 'var foo *= *0x1, *' + 'bar *= *0x2; *' + - 'let baz *= *0x3, *' + + 'let baz *= *0x3, *' + 'bark *= *0x4;' + - 'const hawk *= *0x5, *' + + 'const hawk *= *0x5, *' + 'pork *= *0x6;' ); @@ -220,13 +186,10 @@ describe('VariableDeclarationsMergeTransformer', () => { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/different-variables-kind.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - simplify: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + simplify: true + }).getObfuscatedCode(); }); it('should keep unmerged variable declarations with different variable kinds', () => { diff --git a/test/functional-tests/node-transformers/string-array-transformers/string-array-rotate-function-transformer/StringArrayRotateFunctionTransformer.spec.ts b/test/functional-tests/node-transformers/string-array-transformers/string-array-rotate-function-transformer/StringArrayRotateFunctionTransformer.spec.ts index a5b99b10b..c5f162cb0 100644 --- a/test/functional-tests/node-transformers/string-array-transformers/string-array-rotate-function-transformer/StringArrayRotateFunctionTransformer.spec.ts +++ b/test/functional-tests/node-transformers/string-array-transformers/string-array-rotate-function-transformer/StringArrayRotateFunctionTransformer.spec.ts @@ -27,15 +27,12 @@ describe('StringArrayRotateFunctionTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should correctly append code helper into the obfuscated code', () => { @@ -43,24 +40,21 @@ describe('StringArrayRotateFunctionTransformer', function () { }); }); - describe('`stringArray` option isn\'t set', () => { + describe("`stringArray` option isn't set", () => { let obfuscatedCode: string; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: false, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: false, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t append code helper into the obfuscated code', () => { + it("shouldn't append code helper into the obfuscated code", () => { assert.notMatch(obfuscatedCode, regExp); }); }); @@ -71,15 +65,12 @@ describe('StringArrayRotateFunctionTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: true, - stringArray: true, - stringArrayThreshold: 0.00001 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: true, + stringArray: true, + stringArrayThreshold: 0.00001 + }).getObfuscatedCode(); }); it('should correctly append code helper into the obfuscated code', () => { @@ -93,15 +84,12 @@ describe('StringArrayRotateFunctionTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: true, - stringArray: true, - stringArrayThreshold: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: true, + stringArray: true, + stringArrayThreshold: 0 + }).getObfuscatedCode(); }); it('should correctly append code helper into the obfuscated code', () => { @@ -115,18 +103,15 @@ describe('StringArrayRotateFunctionTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/no-string-literals.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t append code helper into the obfuscated code', () => { + it("shouldn't append code helper into the obfuscated code", () => { assert.notMatch(obfuscatedCode, regExp); }); }); @@ -139,58 +124,51 @@ describe('StringArrayRotateFunctionTransformer', function () { let hasRuntimeErrors: boolean = false; - before(async() => { + before(async () => { const code: string = readFileAsString(__dirname + '/fixtures/code-evaluation.js'); const obfuscateFunc = () => { - return JavaScriptObfuscator.obfuscate( - code, - { - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1, - deadCodeInjection: true, - deadCodeInjectionThreshold: 1, - debugProtection: true, - disableConsoleOutput: true, - identifierNamesGenerator: IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator, - numbersToExpressions: true, - simplify: true, - renameProperties: true, - stringArrayRotate: true, - selfDefending: true, - splitStrings: true, - splitStringsChunkLength: 3, - stringArray: true, - stringArrayCallsTransform: true, - stringArrayCallsTransformThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Base64, - StringArrayEncoding.Rc4 - ], - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumber, - StringArrayIndexesType.HexadecimalNumericString - ], - stringArrayIndexShift: true, - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 5, - stringArrayWrappersParametersMaxCount: 5, - stringArrayWrappersType: StringArrayWrappersType.Function, - stringArrayThreshold: 1, - transformObjectKeys: true, - unicodeEscapeSequence: true - } - ).getObfuscatedCode(); + return JavaScriptObfuscator.obfuscate(code, { + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1, + debugProtection: true, + disableConsoleOutput: true, + identifierNamesGenerator: IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator, + numbersToExpressions: true, + simplify: true, + renameProperties: true, + stringArrayRotate: true, + selfDefending: true, + splitStrings: true, + splitStringsChunkLength: 3, + stringArray: true, + stringArrayCallsTransform: true, + stringArrayCallsTransformThreshold: 1, + stringArrayEncoding: [ + StringArrayEncoding.None, + StringArrayEncoding.Base64, + StringArrayEncoding.Rc4 + ], + stringArrayIndexesType: [ + StringArrayIndexesType.HexadecimalNumber, + StringArrayIndexesType.HexadecimalNumericString + ], + stringArrayIndexShift: true, + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 5, + stringArrayWrappersParametersMaxCount: 5, + stringArrayWrappersType: StringArrayWrappersType.Function, + stringArrayThreshold: 1, + transformObjectKeys: true, + unicodeEscapeSequence: true + }).getObfuscatedCode(); }; - for (let i = 0; i < samplesCount; i++) { try { - const evaluationResult = await evaluateInWorker( - obfuscateFunc(), - evaluationTimeout - ); + const evaluationResult = await evaluateInWorker(obfuscateFunc(), evaluationTimeout); if (evaluationResult !== 'fooooooo') { hasRuntimeErrors = true; @@ -229,21 +207,18 @@ describe('StringArrayRotateFunctionTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/early-successful-comparison.js'); for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - seed: i, - stringArrayRotate: true, - stringArrayShuffle: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + seed: i, + stringArrayRotate: true, + stringArrayShuffle: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); try { await evaluateInWorker(obfuscatedCode, evaluationTimeout); } catch (error) { - evaluationError = error + evaluationError = error; break; } @@ -257,7 +232,7 @@ describe('StringArrayRotateFunctionTransformer', function () { after(() => { numberNumericalExpressionAnalyzerAnalyzeStub.restore(); stringArrayRotateFunctionTransformerGetComparisonValueStub.restore(); - }) + }); }); }); }); diff --git a/test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec.ts b/test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec.ts index 49b58313e..cc904f9da 100644 --- a/test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec.ts +++ b/test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec.ts @@ -21,11 +21,11 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #1: option value is lower then count `literal` nodes in the scope', () => { const stringArrayCallRegExp: RegExp = new RegExp( '(? { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 2 + }).getObfuscatedCode(); }); it('should add scope calls wrappers', () => { @@ -52,11 +49,11 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #2: option value is bigger then count `literal` nodes in the scope', () => { const stringArrayCallRegExp: RegExp = new RegExp( '(? { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 5 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 5 + }).getObfuscatedCode(); }); it('should add scope calls wrappers', () => { @@ -83,10 +77,10 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #3: correct wrappers order', () => { const stringArrayCallRegExp: RegExp = new RegExp( 'const f *= *b;.*' + - 'const g *= *b;.*' + - 'const foo *= *[f|g]\\(0x0\\);.*' + - 'const bar *= *[f|g]\\(0x1\\);.*' + - 'const baz *= *[f|g]\\(0x2\\);' + 'const g *= *b;.*' + + 'const foo *= *[f|g]\\(0x0\\);.*' + + 'const bar *= *[f|g]\\(0x1\\);.*' + + 'const baz *= *[f|g]\\(0x2\\);' ); let obfuscatedCode: string; @@ -94,16 +88,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 2 + }).getObfuscatedCode(); }); it('should add scope calls wrappers', () => { @@ -114,10 +105,10 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #4: `identifiersPrefix` option is set', () => { const stringArrayCallRegExp: RegExp = new RegExp( 'const foo_d *= *foo_b;.*' + - 'const foo_e *= *foo_b;.*' + - 'const foo *= *foo_[d|e]\\(0x0\\);.*' + - 'const bar *= *foo_[d|e]\\(0x1\\);.*' + - 'const baz *= *foo_[d|e]\\(0x2\\);' + 'const foo_e *= *foo_b;.*' + + 'const foo *= *foo_[d|e]\\(0x0\\);.*' + + 'const bar *= *foo_[d|e]\\(0x1\\);.*' + + 'const baz *= *foo_[d|e]\\(0x2\\);' ); let obfuscatedCode: string; @@ -125,17 +116,14 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'foo_', - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'foo_', + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 2 + }).getObfuscatedCode(); }); it('should add scope calls wrappers', () => { @@ -153,7 +141,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x3\\);' + 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x4\\);' + 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x5\\);' + - '}' + '}' ); let obfuscatedCode: string; @@ -161,15 +149,12 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 2 + }).getObfuscatedCode(); }); it('should add scope calls wrappers', () => { @@ -186,7 +171,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x3\\);' + 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x4\\);' + 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x5\\);' + - '}' + '}' ); let obfuscatedCode: string; @@ -194,15 +179,12 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 5 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 5 + }).getObfuscatedCode(); }); it('should add scope calls wrappers', () => { @@ -218,7 +200,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { 'const c *= *[h|i]\\(0x3\\);' + 'const d *= *[h|i]\\(0x4\\);' + 'const e *= *[h|i]\\(0x5\\);' + - '}' + '}' ); let obfuscatedCode: string; @@ -226,16 +208,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 2 + }).getObfuscatedCode(); }); it('should add scope calls wrappers', () => { @@ -246,28 +225,27 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #4: correct wrapper for the function default parameter', () => { const stringArrayCallRegExp: RegExp = new RegExp( 'const e *= *b;.*' + - 'const foo *= *e\\(0x0\\);.*' + - 'function test *\\(c *= *e\\(0x1\\)\\) *{' + + 'const foo *= *e\\(0x0\\);.*' + + 'function test *\\(c *= *e\\(0x1\\)\\) *{' + 'const f *= *b;' + 'const d *= *f\\(0x2\\);' + - '}' + '}' ); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/wrapper-for-the-function-default-parameter.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/wrapper-for-the-function-default-parameter.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should add scope calls wrappers', () => { @@ -283,7 +261,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { 'const a *= *[f|g]\\(0x3\\);' + 'const b *= *[f|g]\\(0x4\\);' + 'const c *= *[f|g]\\(0x5\\);' + - '}' + '}' ); let obfuscatedCode: string; @@ -291,17 +269,14 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - identifiersPrefix: 'foo_', - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + identifiersPrefix: 'foo_', + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 2 + }).getObfuscatedCode(); }); it('should add scope calls wrappers', () => { @@ -313,10 +288,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #3: prohibited scopes', () => { describe('Variant #1: if statement scope', () => { const stringArrayCallRegExp: RegExp = new RegExp( - 'var c *= *b;.*' + - 'if *\\(!!\\[]\\) *{' + - 'var foo *= *c\\(0x0\\);' + - '}' + 'var c *= *b;.*' + 'if *\\(!!\\[]\\) *{' + 'var foo *= *c\\(0x0\\);' + '}' ); let obfuscatedCode: string; @@ -324,16 +296,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prohibited-scope-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should not add scope calls wrappers to a prohibited scope', () => { @@ -343,8 +312,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #2: arrow function scope without statements', () => { const stringArrayCallRegExp: RegExp = new RegExp( - 'var c *= *b;.*' + - '\\[]\\[c\\(0x0\\)]\\(\\(\\) *=> *c\\(0x1\\)\\);' + 'var c *= *b;.*' + '\\[]\\[c\\(0x0\\)]\\(\\(\\) *=> *c\\(0x1\\)\\);' ); let obfuscatedCode: string; @@ -352,16 +320,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/prohibited-scope-2.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should not add scope calls wrappers to a prohibited scope', () => { @@ -373,11 +338,11 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #4: prevailing kind of variables', () => { const stringArrayCallRegExp: RegExp = new RegExp( '(? { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-var.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 2 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 2 + }).getObfuscatedCode(); }); it('should add scope calls wrappers with a correct variables kind', () => { @@ -408,15 +370,12 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-eval.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 5 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 5 + }).getObfuscatedCode(); evaluationResult = eval(obfuscatedCode); }); @@ -431,25 +390,25 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #1: `Mangled` identifier names generator', () => { const stringArrayCallRegExp: RegExp = new RegExp( 'const q *= *b;.*' + - 'const foo *= *q\\(0x0\\);.*' + - 'function test\\(c, *d\\) *{' + + 'const foo *= *q\\(0x0\\);.*' + + 'function test\\(c, *d\\) *{' + 'const r *= *q;' + 'const e *= *r\\(0x1\\);' + 'const f *= *r\\(0x2\\);' + 'function g\\(h, *i\\) *{' + - 'const s *= *r;' + - 'const j *= *s\\(0x3\\);' + - 'const k *= *s\\(0x4\\);' + - 'function l\\(m, *n *\\) *{' + - 'const t *= *s;' + - 'const o *= *t\\(0x3\\);' + - 'const p *= *t\\(0x4\\);' + - 'return o *\\+ *p;' + - '}' + - 'return j *\\+ *k;' + + 'const s *= *r;' + + 'const j *= *s\\(0x3\\);' + + 'const k *= *s\\(0x4\\);' + + 'function l\\(m, *n *\\) *{' + + 'const t *= *s;' + + 'const o *= *t\\(0x3\\);' + + 'const p *= *t\\(0x4\\);' + + 'return o *\\+ *p;' + + '}' + + 'return j *\\+ *k;' + '}' + 'return e *\\+ *f *\\+ *g\\(\\);' + - '}' + '}' ); let obfuscatedCode: string; @@ -457,17 +416,14 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/chained-calls-1.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 1 + }).getObfuscatedCode(); }); it('should add correct scope calls wrappers', () => { @@ -487,21 +443,16 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/chained-calls-1.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Rc4 - ], - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 5 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: + IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Rc4], + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 5 + }).getObfuscatedCode(); const evaluationResult: string = eval(obfuscatedCode); @@ -526,21 +477,15 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/chained-calls-1.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Rc4 - ], - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 5 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Rc4], + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 5 + }).getObfuscatedCode(); const evaluationResult: string = eval(obfuscatedCode); @@ -567,21 +512,16 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/chained-calls-2.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Rc4 - ], - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 5 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: + IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Rc4], + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 5 + }).getObfuscatedCode(); const evaluationResult: string = eval(obfuscatedCode); @@ -606,21 +546,15 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/chained-calls-2.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Rc4 - ], - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 5 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Rc4], + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 5 + }).getObfuscatedCode(); const evaluationResult: string = eval(obfuscatedCode); @@ -647,26 +581,24 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #1: `hexadecimal-number` indexes type', () => { const getStringArrayCallsWrapperMatch = (stringArrayCallsWrapperName: string) => `function *${stringArrayCallsWrapperName} *\\(c, *d\\) *{` + - `return b\\([cd] *-(?: -)?${hexadecimalIndexMatch}, *[cd]\\);` + + `return b\\([cd] *-(?: -)?${hexadecimalIndexMatch}, *[cd]\\);` + '}'; const stringArrayScopeCallsWrapperRegExp1: RegExp = new RegExp( getStringArrayCallsWrapperMatch('f') ); const stringArrayScopeCallsWrapperRegExp2: RegExp = new RegExp( - 'function test *\\( *\\) *{.*' + - `${getStringArrayCallsWrapperMatch('g')}.*?` + - '}' + 'function test *\\( *\\) *{.*' + `${getStringArrayCallsWrapperMatch('g')}.*?` + '}' ); const stringArrayCallsWrapperCallsRegExp: RegExp = new RegExp( `const foo *= *f\\(-? *${hexadecimalIndexMatch}\\, *-? *${hexadecimalIndexMatch}\\);.*` + - `const bar *= *f\\(-? *${hexadecimalIndexMatch}\\, *-? *${hexadecimalIndexMatch}\\);.*` + - `const baz *= *f\\(-? *${hexadecimalIndexMatch}\\, *-? *${hexadecimalIndexMatch}\\);.*` + - 'function test *\\( *\\) *{.*' + + `const bar *= *f\\(-? *${hexadecimalIndexMatch}\\, *-? *${hexadecimalIndexMatch}\\);.*` + + `const baz *= *f\\(-? *${hexadecimalIndexMatch}\\, *-? *${hexadecimalIndexMatch}\\);.*` + + 'function test *\\( *\\) *{.*' + `const c *= *g\\(-? *${hexadecimalIndexMatch}\\, *-? *${hexadecimalIndexMatch}\\);.*` + `const d *= *g\\(-? *${hexadecimalIndexMatch}\\, *-? *${hexadecimalIndexMatch}\\);.*` + `const e *= *g\\(-? *${hexadecimalIndexMatch}\\, *-? *${hexadecimalIndexMatch}\\);.*` + - '}' + '}' ); let obfuscatedCode: string; @@ -674,21 +606,17 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - const getObfuscatedCode: () => string = () => JavaScriptObfuscator.obfuscate( - code, - { + const getObfuscatedCode: () => string = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, stringArray: true, - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumber - ], + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumber], stringArrayThreshold: 1, stringArrayWrappersChainedCalls: false, stringArrayWrappersCount: 1, stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); obfuscatedCode = getObfuscatedCode(); areSuccessEvaluations = checkCodeEvaluation( @@ -717,26 +645,24 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #2: `hexadecimal-numeric-string` indexes type', () => { const getStringArrayCallsWrapperMatch = (stringArrayCallsWrapperName: string) => `function *${stringArrayCallsWrapperName} *\\(c, *d\\) *{` + - `return b\\([cd] *-(?: -)?'${hexadecimalIndexMatch}', *[cd]\\);` + + `return b\\([cd] *-(?: -)?'${hexadecimalIndexMatch}', *[cd]\\);` + '}'; const stringArrayScopeCallsWrapperRegExp1: RegExp = new RegExp( getStringArrayCallsWrapperMatch('f') ); const stringArrayScopeCallsWrapperRegExp2: RegExp = new RegExp( - 'function test *\\( *\\) *{.*' + - `${getStringArrayCallsWrapperMatch('g')}.*?` + - '}' + 'function test *\\( *\\) *{.*' + `${getStringArrayCallsWrapperMatch('g')}.*?` + '}' ); const stringArrayCallsWrapperCallRegExp: RegExp = new RegExp( `const foo *= *f\\(-? *'${hexadecimalIndexMatch}', *-? *'${hexadecimalIndexMatch}'\\);.*` + - `const bar *= *f\\(-? *'${hexadecimalIndexMatch}', *-? *'${hexadecimalIndexMatch}'\\);.*` + - `const baz *= *f\\(-? *'${hexadecimalIndexMatch}', *-? *'${hexadecimalIndexMatch}'\\);.*` + - 'function test *\\( *\\) *{.*' + + `const bar *= *f\\(-? *'${hexadecimalIndexMatch}', *-? *'${hexadecimalIndexMatch}'\\);.*` + + `const baz *= *f\\(-? *'${hexadecimalIndexMatch}', *-? *'${hexadecimalIndexMatch}'\\);.*` + + 'function test *\\( *\\) *{.*' + `const c *= *g\\(-? *'${hexadecimalIndexMatch}', *-? *'${hexadecimalIndexMatch}'\\);.*` + `const d *= *g\\(-? *'${hexadecimalIndexMatch}', *-? *'${hexadecimalIndexMatch}'\\);.*` + `const e *= *g\\(-? *'${hexadecimalIndexMatch}', *-? *'${hexadecimalIndexMatch}'\\);.*` + - '}' + '}' ); let obfuscatedCode: string; @@ -744,21 +670,17 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - const getObfuscatedCode = () => JavaScriptObfuscator.obfuscate( - code, - { + const getObfuscatedCode = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, stringArray: true, - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumericString - ], + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumericString], stringArrayThreshold: 1, stringArrayWrappersChainedCalls: false, stringArrayWrappersCount: 1, stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); obfuscatedCode = getObfuscatedCode(); areSuccessEvaluations = checkCodeEvaluation( @@ -789,28 +711,28 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const stringArrayScopeCallsWrapperRegExp1: RegExp = new RegExp( 'function *f *\\(c, *d\\) *{' + `return b\\([cd] *-(?: -)?${hexadecimalIndexMatch}, *[cd]\\);` + - '}.*' + '}.*' ); const stringArrayScopeCallsWrapperRegExp2: RegExp = new RegExp( 'function test *\\( *\\) *{.*' + 'function *g *\\(c, *d\\) *{' + - `return f\\(` + - // order of arguments depends on the parent wrapper parameters order - `[cd](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + - `[cd](?: *-(?: -)?${hexadecimalIndexMatch})?` + - `\\);` + + `return f\\(` + + // order of arguments depends on the parent wrapper parameters order + `[cd](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + + `[cd](?: *-(?: -)?${hexadecimalIndexMatch})?` + + `\\);` + '}.*' + - '}' + '}' ); const stringArrayCallsWrapperCallRegExp: RegExp = new RegExp( `const foo *= *f\\(-? *${hexadecimalIndexMatch}, *-? *${hexadecimalIndexMatch}\\);.*` + - `const bar *= *f\\(-? *${hexadecimalIndexMatch}, *-? *${hexadecimalIndexMatch}\\);.*` + - `const baz *= *f\\(-? *${hexadecimalIndexMatch}, *-? *${hexadecimalIndexMatch}\\);.*` + - 'function test *\\( *\\) *{.*' + + `const bar *= *f\\(-? *${hexadecimalIndexMatch}, *-? *${hexadecimalIndexMatch}\\);.*` + + `const baz *= *f\\(-? *${hexadecimalIndexMatch}, *-? *${hexadecimalIndexMatch}\\);.*` + + 'function test *\\( *\\) *{.*' + `const c *= *g\\(-? *${hexadecimalIndexMatch}, *-? *${hexadecimalIndexMatch}\\);.*` + `const d *= *g\\(-? *${hexadecimalIndexMatch}, *-? *${hexadecimalIndexMatch}\\);.*` + `const e *= *g\\(-? *${hexadecimalIndexMatch}, *-? *${hexadecimalIndexMatch}\\);.*` + - '}' + '}' ); let obfuscatedCode: string; @@ -818,9 +740,8 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - const getObfuscatedCode = () => JavaScriptObfuscator.obfuscate( - code, - { + const getObfuscatedCode = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, stringArray: true, @@ -828,8 +749,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { stringArrayWrappersChainedCalls: true, stringArrayWrappersCount: 1, stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); obfuscatedCode = getObfuscatedCode(); areSuccessEvaluations = checkCodeEvaluation( @@ -859,27 +779,28 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const stringArrayScopeCallsWrapperRegExp: RegExp = new RegExp( 'function test *\\( *\\) *{.*' + 'function *f*\\(c, *d\\) *{' + - `return b\\([cd] *-(?: -)?${hexadecimalIndexMatch}, *[cd]\\);` + + `return b\\([cd] *-(?: -)?${hexadecimalIndexMatch}, *[cd]\\);` + '}.*' + - '}' + '}' ); const stringArrayCallsWrapperCallRegExp: RegExp = new RegExp( '(? { - const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const-no-root-wrappers.js'); - const getObfuscatedCode = () => JavaScriptObfuscator.obfuscate( - code, - { + const code: string = readFileAsString( + __dirname + '/fixtures/wrappers-count-const-no-root-wrappers.js' + ); + const getObfuscatedCode = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, stringArray: true, @@ -887,8 +808,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { stringArrayWrappersChainedCalls: true, stringArrayWrappersCount: 1, stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); obfuscatedCode = getObfuscatedCode(); areSuccessEvaluations = checkCodeEvaluation( @@ -921,21 +841,17 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/chained-calls-1.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None - ], - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 5, - stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: + IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None], + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 5, + stringArrayWrappersType: StringArrayWrappersType.Function + }).getObfuscatedCode(); const evaluationResult: string = eval(obfuscatedCode); @@ -960,21 +876,16 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/chained-calls-1.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None - ], - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 5, - stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None], + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 5, + stringArrayWrappersType: StringArrayWrappersType.Function + }).getObfuscatedCode(); const evaluationResult: string = eval(obfuscatedCode); @@ -1001,22 +912,17 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/chained-calls-2.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Rc4 - ], - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 5, - stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: + IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Rc4], + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 5, + stringArrayWrappersType: StringArrayWrappersType.Function + }).getObfuscatedCode(); const evaluationResult: string = eval(obfuscatedCode); @@ -1041,22 +947,16 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/chained-calls-2.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Rc4 - ], - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 5, - stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Rc4], + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 5, + stringArrayWrappersType: StringArrayWrappersType.Function + }).getObfuscatedCode(); const evaluationResult: string = eval(obfuscatedCode); @@ -1083,32 +983,32 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const stringArrayScopeCallsWrapperRegExp1: RegExp = new RegExp( 'function *f *\\(c, *d, *e, *h, *i\\) *{' + `return b\\([cdehi] *-(?: -)?${hexadecimalIndexMatch}, *[cdehi]\\);` + - '}.*' + '}.*' ); const stringArrayScopeCallsWrapperRegExp2: RegExp = new RegExp( 'function test *\\( *\\) *{.*' + 'function *g *\\(c, *d, *e, *h, *i\\) *{' + - `return f\\(` + - // order of arguments depends on the parent wrapper parameters order - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?` + - `\\);` + + `return f\\(` + + // order of arguments depends on the parent wrapper parameters order + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?` + + `\\);` + '}.*' + - '}' + '}' ); const stringArrayCallsWrapperCallRegExp: RegExp = new RegExp( `const foo *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + - `const bar *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + - `const baz *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + - 'function test *\\( *\\) *{.*' + + `const bar *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + + `const baz *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + + 'function test *\\( *\\) *{.*' + `const c *= *g\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + `const d *= *g\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + `const e *= *g\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + - '}' + '}' ); let obfuscatedCode: string; @@ -1116,9 +1016,8 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - const getObfuscatedCode = () => JavaScriptObfuscator.obfuscate( - code, - { + const getObfuscatedCode = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, stringArray: true, @@ -1127,8 +1026,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { stringArrayWrappersCount: 1, stringArrayWrappersParametersMaxCount: 5, stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); obfuscatedCode = getObfuscatedCode(); areSuccessEvaluations = checkCodeEvaluation( @@ -1162,32 +1060,32 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { const stringArrayScopeCallsWrapperRegExp1: RegExp = new RegExp( 'function *f *\\(c, *d, *e, *h, *i\\) *{' + `return b\\([cdehi] *-(?: -)?${hexadecimalIndexMatch}, *[cdehi]\\);` + - '}.*' + '}.*' ); const stringArrayScopeCallsWrapperRegExp2: RegExp = new RegExp( 'function test *\\( *\\) *{.*' + 'function *g *\\(c, *d, *e, *h, *i\\) *{' + - `return f\\(` + - // order of arguments depends on the parent wrapper parameters order - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + - `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?` + - `\\);` + + `return f\\(` + + // order of arguments depends on the parent wrapper parameters order + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?, *` + + `[cdehi](?: *-(?: -)?${hexadecimalIndexMatch})?` + + `\\);` + '}.*' + - '}' + '}' ); const stringArrayCallsWrapperCallRegExp: RegExp = new RegExp( `const foo *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + - `const bar *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + - `const baz *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + - 'function test *\\( *\\) *{.*' + + `const bar *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + + `const baz *= *f\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + + 'function test *\\( *\\) *{.*' + `const c *= *g\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + `const d *= *g\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + `const e *= *g\\(${stringArrayWrapperArgumentsRegExpString}\\);.*` + - '}' + '}' ); let obfuscatedCode: string; @@ -1195,22 +1093,18 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - const getObfuscatedCode = () => JavaScriptObfuscator.obfuscate( - code, - { + const getObfuscatedCode = () => + JavaScriptObfuscator.obfuscate(code, { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, stringArray: true, - stringArrayEncoding: [ - StringArrayEncoding.Rc4 - ], + stringArrayEncoding: [StringArrayEncoding.Rc4], stringArrayThreshold: 1, stringArrayWrappersChainedCalls: true, stringArrayWrappersCount: 1, stringArrayWrappersParametersMaxCount: 5, stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); obfuscatedCode = getObfuscatedCode(); areSuccessEvaluations = checkCodeEvaluation( @@ -1240,7 +1134,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #6: different indexes for calls wrappers', () => { const getStringArrayScopeCallsWrapperMatch = (stringArrayScopeCallsWrapperName: string) => `function *${stringArrayScopeCallsWrapperName} *\\(e, *f\\) *{` + - `return b\\([ef] *-(?: -)?(${hexadecimalIndexMatch}), *[ef]\\);` + + `return b\\([ef] *-(?: -)?(${hexadecimalIndexMatch}), *[ef]\\);` + '}.*'; const stringArrayScopeCallsWrapperIndexRegExp1: RegExp = new RegExp( @@ -1255,22 +1149,21 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { let differentIndexesMatchesDelta: number = 3; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/function-calls-wrappers-different-indexes.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/function-calls-wrappers-different-indexes.js' + ); for (let i = 0; i < differentIndexesMatchesSamplesCount; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, - stringArray: true, - stringArrayThreshold: 1, - stringArrayWrappersChainedCalls: true, - stringArrayWrappersCount: 2, - stringArrayWrappersParametersMaxCount: 2, - stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 2, + stringArrayWrappersParametersMaxCount: 2, + stringArrayWrappersType: StringArrayWrappersType.Function + }).getObfuscatedCode(); const indexMatch1 = getRegExpMatch(obfuscatedCode, stringArrayScopeCallsWrapperIndexRegExp1); const indexMatch2 = getRegExpMatch(obfuscatedCode, stringArrayScopeCallsWrapperIndexRegExp2); @@ -1297,13 +1190,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #1: `1` scope calls wrapper for each encoding type', () => { const stringArrayWrappersRegExp: RegExp = new RegExp( '(? { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Base64 - ], - stringArrayWrappersCount: 1, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Base64], + stringArrayWrappersCount: 1, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add scope calls wrappers for both `none` and `base64` string array wrappers', () => { @@ -1334,13 +1221,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { describe('Variant #2: `2` scope calls wrappers for each encoding type', () => { const stringArrayWrappersRegExp: RegExp = new RegExp( '(? { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Base64 - ], - stringArrayWrappersCount: 2, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Base64], + stringArrayWrappersCount: 2, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add scope calls wrappers for both `none` and `base64` string array wrappers', () => { @@ -1380,7 +1261,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x3\\);' + 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x4\\);' + 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x5\\);' + - '}' + '}' ); let obfuscatedCode: string; @@ -1388,19 +1269,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Base64 - ], - stringArrayWrappersCount: 1, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Base64], + stringArrayWrappersCount: 1, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add scope calls wrappers for both `none` and `base64` string array wrappers', () => { @@ -1419,7 +1294,7 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x3\\);' + 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x4\\);' + 'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(0x5\\);' + - '}' + '}' ); let obfuscatedCode: string; @@ -1427,19 +1302,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Base64 - ], - stringArrayWrappersCount: 2, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Base64], + stringArrayWrappersCount: 2, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should add scope calls wrappers for both `none` and `base64` string array wrappers', () => { @@ -1457,19 +1326,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-eval.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Rc4 - ], - stringArrayWrappersCount: 5 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Rc4], + stringArrayWrappersCount: 5 + }).getObfuscatedCode(); evaluationResult = eval(obfuscatedCode); }); @@ -1488,19 +1351,13 @@ describe('StringArrayScopeCallsWrapperTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-eval.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.Base64, - StringArrayEncoding.Rc4 - ], - stringArrayWrappersCount: 5 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayEncoding: [StringArrayEncoding.Base64, StringArrayEncoding.Rc4], + stringArrayWrappersCount: 5 + }).getObfuscatedCode(); evaluationResult = eval(obfuscatedCode); }); diff --git a/test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/StringArrayTransformer.spec.ts b/test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/StringArrayTransformer.spec.ts index 8646325ab..74e323bff 100644 --- a/test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/StringArrayTransformer.spec.ts +++ b/test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/StringArrayTransformer.spec.ts @@ -26,14 +26,11 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should replace literal node value with value from string array', () => { @@ -53,15 +50,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); }); - it('shouldn\'t replace literal node value with value from string array', () => { + it("shouldn't replace literal node value with value from string array", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -75,17 +69,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumber - ] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumber] + }).getObfuscatedCode(); }); it('match #1: should transform string array index with the passed index type', () => { @@ -101,17 +90,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumericString - ] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumericString] + }).getObfuscatedCode(); }); it('match #1: should transform string array index with the passed index type', () => { @@ -137,18 +121,15 @@ describe('StringArrayTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); for (let i = 0; i < samplesCount; i++) { - const obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayIndexesType: [ - StringArrayIndexesType.HexadecimalNumber, - StringArrayIndexesType.HexadecimalNumericString - ] - } - ).getObfuscatedCode(); + const obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayIndexesType: [ + StringArrayIndexesType.HexadecimalNumber, + StringArrayIndexesType.HexadecimalNumericString + ] + }).getObfuscatedCode(); if (obfuscatedCode.match(hexadecimalNumberIndexTypeRegExp)) { hexadecimalNumberIndexTypeMatchesCount += 1; @@ -159,7 +140,8 @@ describe('StringArrayTransformer', function () { } hexadecimalNumberIndexTypeMatchesChance = hexadecimalNumberIndexTypeMatchesCount / samplesCount; - hexadecimalNumericStringIndexTypeMatchesChance = hexadecimalNumericStringIndexTypeMatchesCount / samplesCount; + hexadecimalNumericStringIndexTypeMatchesChance = + hexadecimalNumericStringIndexTypeMatchesCount / samplesCount; } }); @@ -168,16 +150,24 @@ describe('StringArrayTransformer', function () { }); it('should transform string array indexes with a `hexadecimal-numeric-string` type', () => { - assert.closeTo(hexadecimalNumericStringIndexTypeMatchesChance, expectedMatchesChance, expectedMatchesDelta); + assert.closeTo( + hexadecimalNumericStringIndexTypeMatchesChance, + expectedMatchesChance, + expectedMatchesDelta + ); }); }); }); describe('Variant #4: `stringArrayIndexShift` option is enabled', () => { - const stringArrayIndexShiftRegExp: RegExp = /_0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6} *- *(0x[a-z0-9]{1,3});/; - const stringArrayCallRegExp1: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4}\((0x[a-z0-9]{1,3})\) *\+ *0x1;/; - const stringArrayCallRegExp2: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4}\((0x[a-z0-9]{1,3})\) *\+ *0x2;/; - const stringArrayCallRegExp3: RegExp = /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4}\((0x[a-z0-9]{1,3})\) *\+ *0x3;/; + const stringArrayIndexShiftRegExp: RegExp = + /_0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6} *- *(0x[a-z0-9]{1,3});/; + const stringArrayCallRegExp1: RegExp = + /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4}\((0x[a-z0-9]{1,3})\) *\+ *0x1;/; + const stringArrayCallRegExp2: RegExp = + /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4}\((0x[a-z0-9]{1,3})\) *\+ *0x2;/; + const stringArrayCallRegExp3: RegExp = + /var _0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4}\((0x[a-z0-9]{1,3})\) *\+ *0x3;/; const expectedEvaluationResult: string = 'foo1bar2baz3'; @@ -194,17 +184,17 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/string-array-index-shift.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayIndexShift: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayIndexShift: true + }).getObfuscatedCode(); - stringArrayIndexShiftIndexValue = parseInt(getRegExpMatch(obfuscatedCode, stringArrayIndexShiftRegExp), 16); + stringArrayIndexShiftIndexValue = parseInt( + getRegExpMatch(obfuscatedCode, stringArrayIndexShiftRegExp), + 16 + ); stringArrayCallIndexValue1 = parseInt(getRegExpMatch(obfuscatedCode, stringArrayCallRegExp1), 16); stringArrayCallIndexValue2 = parseInt(getRegExpMatch(obfuscatedCode, stringArrayCallRegExp2), 16); stringArrayCallIndexValue3 = parseInt(getRegExpMatch(obfuscatedCode, stringArrayCallRegExp3), 16); @@ -237,18 +227,18 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/string-array-index-shift.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayIndexShift: true, - stringArrayRotate: true - } - ).getObfuscatedCode(); - - stringArrayIndexShiftIndexValue = parseInt(getRegExpMatch(obfuscatedCode, stringArrayIndexShiftRegExp), 16); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayIndexShift: true, + stringArrayRotate: true + }).getObfuscatedCode(); + + stringArrayIndexShiftIndexValue = parseInt( + getRegExpMatch(obfuscatedCode, stringArrayIndexShiftRegExp), + 16 + ); stringArrayCallIndexValue1 = parseInt(getRegExpMatch(obfuscatedCode, stringArrayCallRegExp1), 16); stringArrayCallIndexValue2 = parseInt(getRegExpMatch(obfuscatedCode, stringArrayCallRegExp2), 16); stringArrayCallIndexValue3 = parseInt(getRegExpMatch(obfuscatedCode, stringArrayCallRegExp3), 16); @@ -269,16 +259,13 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/string-array-index-shift.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayIndexShift: true, - stringArrayShuffle: true - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayIndexShift: true, + stringArrayShuffle: true + }).getObfuscatedCode(); evaluationResult = eval(obfuscatedCode); }); @@ -296,17 +283,14 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/string-array-index-shift.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - stringArrayIndexShift: true, - stringArrayWrappersCount: 1, - stringArrayWrappersType: StringArrayWrappersType.Function - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + stringArrayIndexShift: true, + stringArrayWrappersCount: 1, + stringArrayWrappersType: StringArrayWrappersType.Function + }).getObfuscatedCode(); evaluationResult = eval(obfuscatedCode); }); @@ -324,23 +308,18 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/string-array-index-shift.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: true, - stringArrayShuffle: true, - stringArray: true, - stringArrayEncoding: [ - StringArrayEncoding.Rc4 - ], - stringArrayIndexShift: true, - stringArrayThreshold: 1, - stringArrayWrappersCount: 2, - stringArrayWrappersChainedCalls: true, - stringArrayWrappersType: 'function' - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: true, + stringArrayShuffle: true, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.Rc4], + stringArrayIndexShift: true, + stringArrayThreshold: 1, + stringArrayWrappersCount: 2, + stringArrayWrappersChainedCalls: true, + stringArrayWrappersType: 'function' + }).getObfuscatedCode(); evaluationResult = eval(obfuscatedCode); }); @@ -364,14 +343,11 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/same-literal-values.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should create only one item in string array for same literal node values', () => { @@ -391,17 +367,14 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/short-literal-value.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); - it('shouldn\'t replace short literal node value with value from string array', () => { + it("shouldn't replace short literal node value with value from string array", () => { assert.match(obfuscatedCode, regExp); }); }); @@ -411,7 +384,7 @@ describe('StringArrayTransformer', function () { 'function _0x([a-f0-9]){4} *\\(\\) *{' + `var _0x([a-f0-9]){4,6} *= *\\[\'${swapLettersCase('dGVzdA')}\'];.*` + 'return _0x([a-f0-9]){4}\\(\\); *' + - '}' + '}' ); const stringArrayCallRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\(0x0\);/; @@ -420,15 +393,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayEncoding: [StringArrayEncoding.Base64], - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.Base64], + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should replace literal node value with value from string array encoded using base64', () => { @@ -449,15 +419,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayEncoding: [StringArrayEncoding.Rc4], - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.Rc4], + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('should replace literal node value with value from string array encoded using rc4', () => { @@ -477,16 +444,13 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/same-literal-values.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - seed: 1, // set seed to prevent rare case when all encoded values are the same - stringArray: true, - stringArrayEncoding: [StringArrayEncoding.Rc4], - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + seed: 1, // set seed to prevent rare case when all encoded values are the same + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.Rc4], + stringArrayThreshold: 1 + }).getObfuscatedCode(); encodedLiteralValue1 = getRegExpMatch(obfuscatedCode, variableRegExp1); encodedLiteralValue2 = getRegExpMatch(obfuscatedCode, variableRegExp2); @@ -526,18 +490,12 @@ describe('StringArrayTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Base64 - ], - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Base64], + stringArrayThreshold: 1 + }).getObfuscatedCode(); if (obfuscatedCode.match(noneEncodingRegExp)) { noneEncodingMatchesCount = noneEncodingMatchesCount + 1; @@ -582,18 +540,12 @@ describe('StringArrayTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Rc4 - ], - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Rc4], + stringArrayThreshold: 1 + }).getObfuscatedCode(); if (obfuscatedCode.match(noneEncodingRegExp)) { noneEncodingMatchesCount = noneEncodingMatchesCount + 1; @@ -638,18 +590,12 @@ describe('StringArrayTransformer', function () { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); for (let i = 0; i < samplesCount; i++) { - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayEncoding: [ - StringArrayEncoding.Base64, - StringArrayEncoding.Rc4 - ], - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.Base64, StringArrayEncoding.Rc4], + stringArrayThreshold: 1 + }).getObfuscatedCode(); if (obfuscatedCode.match(base64EncodingRegExp)) { base64EncodingMatchesCount = base64EncodingMatchesCount + 1; @@ -682,27 +628,19 @@ describe('StringArrayTransformer', function () { const regExp1: RegExp = /var test *= *_0x([a-f0-9]){4}\(0x0\);/g; const regExp2: RegExp = /var test *= *'test';/g; - let stringArrayProbability: number, - noStringArrayProbability: number; + let stringArrayProbability: number, noStringArrayProbability: number; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - `${code}\n`.repeat(samples), - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: stringArrayThreshold - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(`${code}\n`.repeat(samples), { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: stringArrayThreshold + }).getObfuscatedCode(); - const stringArrayMatchesLength: number = obfuscatedCode - .match(regExp1)! - .length; - const noStringArrayMatchesLength: number = obfuscatedCode - .match(regExp2)! - .length; + const stringArrayMatchesLength: number = obfuscatedCode.match(regExp1)!.length; + const noStringArrayMatchesLength: number = obfuscatedCode.match(regExp2)!.length; stringArrayProbability = stringArrayMatchesLength / samples; noStringArrayProbability = noStringArrayMatchesLength / samples; @@ -712,7 +650,7 @@ describe('StringArrayTransformer', function () { assert.closeTo(stringArrayProbability, stringArrayThreshold, delta); }); - it('Variant #2: shouldn\'t replace literal node value with value from string array with `(1 - stringArrayThreshold)` chance', () => { + it("Variant #2: shouldn't replace literal node value with value from string array with `(1 - stringArrayThreshold)` chance", () => { assert.closeTo(noStringArrayProbability, stringArrayThreshold, delta); }); }); @@ -725,15 +663,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/string-array-calls-wrapper-name.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator + }).getObfuscatedCode(); }); it('match #1: should keep identifier with string array calls wrapper name untouched after obfuscation', () => { @@ -752,15 +687,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - reservedStrings: ['foo'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + reservedStrings: ['foo'] + }).getObfuscatedCode(); }); it('match #1: should ignore reserved strings', () => { @@ -781,15 +713,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - reservedStrings: ['foo', 'bar'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + reservedStrings: ['foo', 'bar'] + }).getObfuscatedCode(); }); it('match #1: should ignore reserved strings', () => { @@ -812,15 +741,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - reservedStrings: ['ar$'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + reservedStrings: ['ar$'] + }).getObfuscatedCode(); }); it('match #1: should transform non-reserved strings', () => { @@ -841,15 +767,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1, - reservedStrings: ['^fo', '.ar'] - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + reservedStrings: ['^fo', '.ar'] + }).getObfuscatedCode(); }); it('match #1: should ignore reserved strings', () => { @@ -874,15 +797,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/force-transform-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: ['bar'], - stringArray: true, - stringArrayThreshold: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: ['bar'], + stringArray: true, + stringArrayThreshold: 0 + }).getObfuscatedCode(); }); it('match #1: should not transform string', () => { @@ -903,15 +823,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/force-transform-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: ['foo', 'bar'], - stringArray: true, - stringArrayThreshold: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: ['foo', 'bar'], + stringArray: true, + stringArrayThreshold: 0 + }).getObfuscatedCode(); }); it('match #1: should transform force transform string', () => { @@ -934,15 +851,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/force-transform-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: ['ar$'], - stringArray: true, - stringArrayThreshold: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: ['ar$'], + stringArray: true, + stringArrayThreshold: 0 + }).getObfuscatedCode(); }); it('match #1: should not transform string', () => { @@ -963,15 +877,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/force-transform-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: ['^fo', '.ar'], - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: ['^fo', '.ar'], + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should transform force transform string', () => { @@ -994,15 +905,12 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/force-transform-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: ['foo', 'bar'], - stringArray: false, - stringArrayThreshold: 0 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: ['foo', 'bar'], + stringArray: false, + stringArrayThreshold: 0 + }).getObfuscatedCode(); }); it('match #1: should not transform string', () => { @@ -1025,16 +933,13 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/force-transform-strings-option.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: ['bar'], - reservedStrings: ['foo', 'bar'], - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: ['bar'], + reservedStrings: ['foo', 'bar'], + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should not transform string', () => { @@ -1056,17 +961,16 @@ describe('StringArrayTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/force-transform-strings-option-conditional-comments.js'); - - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - forceTransformStrings: ['bar'], - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const code: string = readFileAsString( + __dirname + '/fixtures/force-transform-strings-option-conditional-comments.js' + ); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + forceTransformStrings: ['bar'], + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should not transform string', () => { @@ -1086,7 +990,7 @@ describe('StringArrayTransformer', function () { describe('Variant #16: object expression key literal', () => { describe('Variant #1: base key literal', () => { - const stringArrayRegExp: RegExp = getStringArrayRegExp(['bar']) + const stringArrayRegExp: RegExp = getStringArrayRegExp(['bar']); const objectExpressionRegExp: RegExp = /var test *= *{'foo' *: *_0x([a-f0-9]){4}\(0x0\)};/; let obfuscatedCode: string; @@ -1094,14 +998,11 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/object-expression-key-literal.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should not add object expression key literal to the string array', () => { @@ -1114,22 +1015,22 @@ describe('StringArrayTransformer', function () { }); describe('Variant #2: computed key literal', () => { - const stringArrayRegExp: RegExp = getStringArrayRegExp(['foo', 'bar']) - const objectExpressionRegExp: RegExp = /var test *= *{\[_0x([a-f0-9]){4}\(0x0\)] *: *_0x([a-f0-9]){4}\(0x1\)};/; + const stringArrayRegExp: RegExp = getStringArrayRegExp(['foo', 'bar']); + const objectExpressionRegExp: RegExp = + /var test *= *{\[_0x([a-f0-9]){4}\(0x0\)] *: *_0x([a-f0-9]){4}\(0x1\)};/; let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/object-expression-computed-key-literal.js'); + const code: string = readFileAsString( + __dirname + '/fixtures/object-expression-computed-key-literal.js' + ); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('match #1: should add object expression computed key literal to the string array', () => { @@ -1150,14 +1051,11 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/import-declaration-source.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('Should not add `ImportDeclaration` source literal to the string array', () => { @@ -1173,14 +1071,11 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/export-all-declaration-source.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('Should not add `ExportAllDeclaration` source literal to the string array', () => { @@ -1196,14 +1091,11 @@ describe('StringArrayTransformer', function () { before(() => { const code: string = readFileAsString(__dirname + '/fixtures/export-named-declaration-source.js'); - obfuscatedCode = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); }); it('Should not add `ExportNamedDeclaration` source literal to the string array', () => { diff --git a/test/functional-tests/options/Options.spec.ts b/test/functional-tests/options/Options.spec.ts index 86c69389d..53cc30adf 100644 --- a/test/functional-tests/options/Options.spec.ts +++ b/test/functional-tests/options/Options.spec.ts @@ -24,19 +24,17 @@ use(chaiExclude); /** * @param {TInputOptions} inputOptions */ -function getOptions (inputOptions: TInputOptions): IOptions { +function getOptions(inputOptions: TInputOptions): IOptions { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', inputOptions); - return inversifyContainerFacade - .get(ServiceIdentifiers.IOptions); + return inversifyContainerFacade.get(ServiceIdentifiers.IOptions); } describe('Options', () => { describe('Options preset', () => { - let options: IOptions, - expectedOptions: TInputOptions; + let options: IOptions, expectedOptions: TInputOptions; describe('Preset selection', () => { describe('Default preset', () => { diff --git a/test/functional-tests/options/OptionsNormalizer.spec.ts b/test/functional-tests/options/OptionsNormalizer.spec.ts index 76622cf62..d09abc247 100644 --- a/test/functional-tests/options/OptionsNormalizer.spec.ts +++ b/test/functional-tests/options/OptionsNormalizer.spec.ts @@ -20,15 +20,15 @@ import { InversifyContainerFacade } from '../../../src/container/InversifyContai * @param optionsPreset * @returns {IOptions} */ -function getNormalizedOptions (optionsPreset: TInputOptions): TInputOptions { +function getNormalizedOptions(optionsPreset: TInputOptions): TInputOptions { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', optionsPreset); - const options: IOptions = inversifyContainerFacade - .get(ServiceIdentifiers.IOptions); - const optionsNormalizer: IOptionsNormalizer = inversifyContainerFacade - .get(ServiceIdentifiers.IOptionsNormalizer); + const options: IOptions = inversifyContainerFacade.get(ServiceIdentifiers.IOptions); + const optionsNormalizer: IOptionsNormalizer = inversifyContainerFacade.get( + ServiceIdentifiers.IOptionsNormalizer + ); return optionsNormalizer.normalize(options); } @@ -42,8 +42,7 @@ function getDefaultOptions(): TInputOptions { describe('OptionsNormalizer', () => { describe('normalize', () => { - let optionsPreset: TInputOptions, - expectedOptionsPreset: TInputOptions; + let optionsPreset: TInputOptions, expectedOptionsPreset: TInputOptions; describe('controlFlowFlatteningThresholdRule', () => { before(() => { @@ -164,17 +163,13 @@ describe('OptionsNormalizer', () => { before(() => { optionsPreset = getNormalizedOptions({ ...getDefaultOptions(), - domainLock: [ - 'localhost' - ], + domainLock: ['localhost'], domainLockRedirectUrl: 'https://example.com' }); expectedOptionsPreset = { ...getDefaultOptions(), - domainLock: [ - 'localhost' - ], + domainLock: ['localhost'], domainLockRedirectUrl: 'https://example.com' }; }); @@ -209,18 +204,12 @@ describe('OptionsNormalizer', () => { before(() => { optionsPreset = getNormalizedOptions({ ...getDefaultOptions(), - domainLock: [ - '//localhost:9000', - 'https://google.ru/abc?cde=fgh' - ] + domainLock: ['//localhost:9000', 'https://google.ru/abc?cde=fgh'] }); expectedOptionsPreset = { ...getDefaultOptions(), - domainLock: [ - 'localhost', - 'google.ru' - ] + domainLock: ['localhost', 'google.ru'] }; }); @@ -230,7 +219,7 @@ describe('OptionsNormalizer', () => { }); describe('inputFileNameRule', () => { - describe('Variant #1: extension isn\'t set', () => { + describe("Variant #1: extension isn't set", () => { before(() => { optionsPreset = getNormalizedOptions({ ...getDefaultOptions(), @@ -536,7 +525,7 @@ describe('OptionsNormalizer', () => { before(() => { optionsPreset = getNormalizedOptions({ ...getDefaultOptions(), - sourceMapBaseUrl: 'http://localhost:9000', + sourceMapBaseUrl: 'http://localhost:9000' }); expectedOptionsPreset = { @@ -800,9 +789,7 @@ describe('OptionsNormalizer', () => { expectedOptionsPreset = { ...getDefaultOptions(), - stringArrayEncoding: [ - StringArrayEncoding.None - ] + stringArrayEncoding: [StringArrayEncoding.None] }; }); @@ -831,4 +818,4 @@ describe('OptionsNormalizer', () => { }); }); }); -}); \ No newline at end of file +}); diff --git a/test/functional-tests/options/domain-lock-destination/Validation.spec.ts b/test/functional-tests/options/domain-lock-destination/Validation.spec.ts index 4fb8b2a8f..155ab6b34 100644 --- a/test/functional-tests/options/domain-lock-destination/Validation.spec.ts +++ b/test/functional-tests/options/domain-lock-destination/Validation.spec.ts @@ -11,13 +11,11 @@ describe('`domainLockRedirectUrl` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, domainLockRedirectUrl: 'https://example.com/path' - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -29,13 +27,11 @@ describe('`domainLockRedirectUrl` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, domainLockRedirectUrl: 'example.com/path' - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -47,13 +43,11 @@ describe('`domainLockRedirectUrl` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, domainLockRedirectUrl: '/path' - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -65,13 +59,11 @@ describe('`domainLockRedirectUrl` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, domainLockRedirectUrl: 'about:blank' - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -86,13 +78,11 @@ describe('`domainLockRedirectUrl` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, domainLockRedirectUrl: 'foo' - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not pass validation', () => { diff --git a/test/functional-tests/options/domain-lock/Validation.spec.ts b/test/functional-tests/options/domain-lock/Validation.spec.ts index 4ec195dd7..765ffd0aa 100644 --- a/test/functional-tests/options/domain-lock/Validation.spec.ts +++ b/test/functional-tests/options/domain-lock/Validation.spec.ts @@ -13,14 +13,12 @@ describe('`domainLock` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, domainLock: ['www.example.com'], target: ObfuscationTarget.Browser - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation when obfuscation target is `browser`', () => { @@ -32,14 +30,12 @@ describe('`domainLock` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, domainLock: [], target: ObfuscationTarget.Node - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation when obfuscation target is `node` and value is default', () => { @@ -54,14 +50,12 @@ describe('`domainLock` validation', () => { describe('Variant #1: obfuscation target: `node`', () => { beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, domainLock: ['www.example.com'], target: ObfuscationTarget.Node - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not pass validation when obfuscation target is `node` and value is not default', () => { @@ -71,14 +65,12 @@ describe('`domainLock` validation', () => { describe('Variant #1: obfuscation target: `service-worker`', () => { beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, domainLock: ['www.example.com'], target: ObfuscationTarget.ServiceWorker - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not pass validation when obfuscation target is `service-worker` and value is not default', () => { diff --git a/test/functional-tests/options/identifier-names-cache/Validation.spec.ts b/test/functional-tests/options/identifier-names-cache/Validation.spec.ts index b6f60c10c..e4c3c8b30 100644 --- a/test/functional-tests/options/identifier-names-cache/Validation.spec.ts +++ b/test/functional-tests/options/identifier-names-cache/Validation.spec.ts @@ -11,9 +11,8 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: { globalIdentifiers: { @@ -23,8 +22,7 @@ describe('`identifierNamesCache` validation', () => { bar: '_0x654321' } } - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -36,9 +34,8 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: { globalIdentifiers: { @@ -46,8 +43,7 @@ describe('`identifierNamesCache` validation', () => { }, propertyIdentifiers: {} } - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -59,16 +55,14 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: { globalIdentifiers: {}, propertyIdentifiers: {} } - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -80,17 +74,15 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: { globalIdentifiers: { foo: '_0x123456' } } - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -102,13 +94,11 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: {} - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -120,13 +110,11 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: null - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -142,13 +130,11 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: 'cache' - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not pass validation', () => { @@ -160,19 +146,17 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: { globalIdentifiers: { foo: 1, - bar: 2, + bar: 2 }, propertyIdentifiers: {} } - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not pass validation', () => { @@ -184,22 +168,20 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: { globalIdentifiers: { foo: 1, - bar: 2, + bar: 2 }, propertyIdentifiers: { baz: 3, - bark: 4, + bark: 4 } } - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not pass validation', () => { @@ -211,21 +193,19 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: { globalIdentifiers: { foo: 1, - bar: '_0x1234567', + bar: '_0x1234567' }, propertyIdentifiers: { foo: '_0x123456' } } - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not pass validation', () => { @@ -237,16 +217,14 @@ describe('`identifierNamesCache` validation', () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, identifierNamesCache: { globalIdentifiers: null, propertyIdentifiers: null } - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not pass validation', () => { diff --git a/test/functional-tests/options/input-file-name/Validation.spec.ts b/test/functional-tests/options/input-file-name/Validation.spec.ts index 501b0944b..a4273c869 100644 --- a/test/functional-tests/options/input-file-name/Validation.spec.ts +++ b/test/functional-tests/options/input-file-name/Validation.spec.ts @@ -8,18 +8,16 @@ import { SourceMapSourcesMode } from '../../../../src/enums/source-map/SourceMap describe('`inputFileName` validation', () => { describe('IsInputFileName', () => { describe('Variant #1: positive validation', () => { - describe('Variant #1: empty string when `sourceMapSourcesMode: \'sources-content\'', () => { + describe("Variant #1: empty string when `sourceMapSourcesMode: 'sources-content'", () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, inputFileName: '', sourceMapSourcesMode: SourceMapSourcesMode.SourcesContent - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -27,18 +25,16 @@ describe('`inputFileName` validation', () => { }); }); - describe('Variant #2: string with input file name when `sourceMapSourcesMode: \'sources\'', () => { + describe("Variant #2: string with input file name when `sourceMapSourcesMode: 'sources'", () => { let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, inputFileName: 'some-file.js', sourceMapSourcesMode: SourceMapSourcesMode.Sources - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should pass validation', () => { @@ -48,19 +44,17 @@ describe('`inputFileName` validation', () => { }); describe('Variant #2: negative validation', () => { - describe('Variant #1: empty string when `sourceMapSourcesMode: \'sources\'', () => { + describe("Variant #1: empty string when `sourceMapSourcesMode: 'sources'", () => { const expectedError: string = 'should not be empty'; let testFunc: () => string; beforeEach(() => { - testFunc = () => JavaScriptObfuscator.obfuscate( - '', - { + testFunc = () => + JavaScriptObfuscator.obfuscate('', { ...NO_ADDITIONAL_NODES_PRESET, inputFileName: '', sourceMapSourcesMode: SourceMapSourcesMode.Sources - } - ).getObfuscatedCode(); + }).getObfuscatedCode(); }); it('should not pass validation', () => { diff --git a/test/functional-tests/storages/string-array-transformers/string-array-storage/StringArrayStorage.spec.ts b/test/functional-tests/storages/string-array-transformers/string-array-storage/StringArrayStorage.spec.ts index 4ac2960a8..507fb1c42 100644 --- a/test/functional-tests/storages/string-array-transformers/string-array-storage/StringArrayStorage.spec.ts +++ b/test/functional-tests/storages/string-array-transformers/string-array-storage/StringArrayStorage.spec.ts @@ -19,8 +19,7 @@ describe('StringArrayStorage', () => { const stringArrayVariantRegExp: RegExp = /var.*= *\[(?:'.*?', *)?'test'(?:, *'.*?')?];.*/; const literalNodeVariantRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\(0x.\);/g; - let stringArrayVariantProbability: number, - literalNodeVariantProbability: number; + let stringArrayVariantProbability: number, literalNodeVariantProbability: number; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/one-string.js'); @@ -28,25 +27,22 @@ describe('StringArrayStorage', () => { let stringArrayVariantMatchesLength: number = 0; let literalNodeVariantMatchesLength: number = 0; - for (let i = 0; i < samples; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); - - if (obfuscatedCode.match(stringArrayVariantRegExp)) { - stringArrayVariantMatchesLength++; - } - - if (obfuscatedCode.match(literalNodeVariantRegExp)) { - literalNodeVariantMatchesLength++; - } - } + for (let i = 0; i < samples; i++) { + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); + + if (obfuscatedCode.match(stringArrayVariantRegExp)) { + stringArrayVariantMatchesLength++; + } + + if (obfuscatedCode.match(literalNodeVariantRegExp)) { + literalNodeVariantMatchesLength++; + } + } stringArrayVariantProbability = stringArrayVariantMatchesLength / samples; literalNodeVariantProbability = literalNodeVariantMatchesLength / samples; @@ -76,13 +72,13 @@ describe('StringArrayStorage', () => { const stringArrayVariantRegExps: RegExp[] = [ /var.*= *\['foo', *'bar', *'baz'(?:, *'.*?')+];.*/, - /var.*= *\[(?:'.*?', *)+'foo', *'bar', *'baz'];.*/, + /var.*= *\[(?:'.*?', *)+'foo', *'bar', *'baz'];.*/ ]; const literalNodeVariantRegExps: RegExp[] = [ new RegExp( `var foo *= *_0x([a-f0-9]){4}\\(0x.\\);.*` + - `var bar *= *_0x([a-f0-9]){4}\\(0x.\\);.*` + - `var baz *= *_0x([a-f0-9]){4}\\(0x.\\);` + `var bar *= *_0x([a-f0-9]){4}\\(0x.\\);.*` + + `var baz *= *_0x([a-f0-9]){4}\\(0x.\\);` ) ]; @@ -96,15 +92,12 @@ describe('StringArrayStorage', () => { const code: string = readFileAsString(__dirname + '/fixtures/three-strings.js'); for (let i = 0; i < samples; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayRotate: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayRotate: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); for (let variantIndex = 0; variantIndex < stringArrayVariantsCount; variantIndex++) { if (obfuscatedCode.match(stringArrayVariantRegExps[variantIndex])) { @@ -118,11 +111,13 @@ describe('StringArrayStorage', () => { } for (let variantIndex = 0; variantIndex < stringArrayVariantsCount; variantIndex++) { - stringArrayVariantProbabilities[variantIndex] = stringArrayVariantMatchesLength[variantIndex] / samples; + stringArrayVariantProbabilities[variantIndex] = + stringArrayVariantMatchesLength[variantIndex] / samples; } for (let variantIndex = 0; variantIndex < literalNodeVariantsCount; variantIndex++) { - literalNodeVariantProbabilities[variantIndex] = literalNodeVariantMatchesLength[variantIndex] / samples; + literalNodeVariantProbabilities[variantIndex] = + literalNodeVariantMatchesLength[variantIndex] / samples; } }); @@ -131,7 +126,11 @@ describe('StringArrayStorage', () => { const variantNumber: number = variantIndex + 1; it(`Variant #${variantNumber}: should create string array variant`, () => { - assert.closeTo(stringArrayVariantProbabilities[variantIndex], expectedStringArrayVariantProbability, delta); + assert.closeTo( + stringArrayVariantProbabilities[variantIndex], + expectedStringArrayVariantProbability, + delta + ); }); } }); @@ -141,7 +140,11 @@ describe('StringArrayStorage', () => { const variantNumber: number = variantIndex + 1; it(`Variant #${variantNumber}: should replace literal node with call to string array variant`, () => { - assert.closeTo(literalNodeVariantProbabilities[variantIndex], expectedLiteralNodeVariantProbability, delta); + assert.closeTo( + literalNodeVariantProbabilities[variantIndex], + expectedLiteralNodeVariantProbability, + delta + ); }); } }); @@ -159,8 +162,7 @@ describe('StringArrayStorage', () => { const stringArrayVariantRegExp1: RegExp = getStringArrayRegExp(['test']); const literalNodeVariant1RegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\(0x0\);/g; - let stringArrayVariant1Probability: number, - literalNodeVariant1Probability: number; + let stringArrayVariant1Probability: number, literalNodeVariant1Probability: number; before(() => { const code: string = readFileAsString(__dirname + '/fixtures/one-string.js'); @@ -169,15 +171,12 @@ describe('StringArrayStorage', () => { let literalNodeVariant1MatchesLength: number = 0; for (let i = 0; i < samples; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayShuffle: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayShuffle: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); if (obfuscatedCode.match(stringArrayVariantRegExp1)) { stringArrayVariant1MatchesLength++; @@ -224,33 +223,33 @@ describe('StringArrayStorage', () => { const literalNodeVariantRegExps: RegExp[] = [ new RegExp( `var foo *= *_0x([a-f0-9]){4}\\(0x0\\);.*` + - `var bar *= *_0x([a-f0-9]){4}\\(0x1\\);.*` + - `var baz *= *_0x([a-f0-9]){4}\\(0x2\\);` + `var bar *= *_0x([a-f0-9]){4}\\(0x1\\);.*` + + `var baz *= *_0x([a-f0-9]){4}\\(0x2\\);` ), new RegExp( `var foo *= *_0x([a-f0-9]){4}\\(0x0\\);.*` + - `var bar *= *_0x([a-f0-9]){4}\\(0x2\\);.*` + - `var baz *= *_0x([a-f0-9]){4}\\(0x1\\);` + `var bar *= *_0x([a-f0-9]){4}\\(0x2\\);.*` + + `var baz *= *_0x([a-f0-9]){4}\\(0x1\\);` ), new RegExp( `var foo *= *_0x([a-f0-9]){4}\\(0x1\\);.*` + - `var bar *= *_0x([a-f0-9]){4}\\(0x0\\);.*` + - `var baz *= *_0x([a-f0-9]){4}\\(0x2\\);` + `var bar *= *_0x([a-f0-9]){4}\\(0x0\\);.*` + + `var baz *= *_0x([a-f0-9]){4}\\(0x2\\);` ), new RegExp( `var foo *= *_0x([a-f0-9]){4}\\(0x1\\);.*` + - `var bar *= *_0x([a-f0-9]){4}\\(0x2\\);.*` + - `var baz *= *_0x([a-f0-9]){4}\\(0x0\\);` + `var bar *= *_0x([a-f0-9]){4}\\(0x2\\);.*` + + `var baz *= *_0x([a-f0-9]){4}\\(0x0\\);` ), new RegExp( `var foo *= *_0x([a-f0-9]){4}\\(0x2\\);.*` + - `var bar *= *_0x([a-f0-9]){4}\\(0x0\\);.*` + - `var baz *= *_0x([a-f0-9]){4}\\(0x1\\);` + `var bar *= *_0x([a-f0-9]){4}\\(0x0\\);.*` + + `var baz *= *_0x([a-f0-9]){4}\\(0x1\\);` ), new RegExp( `var foo *= *_0x([a-f0-9]){4}\\(0x2\\);.*` + - `var bar *= *_0x([a-f0-9]){4}\\(0x1\\);.*` + - `var baz *= *_0x([a-f0-9]){4}\\(0x0\\);` + `var bar *= *_0x([a-f0-9]){4}\\(0x1\\);.*` + + `var baz *= *_0x([a-f0-9]){4}\\(0x0\\);` ) ]; @@ -264,15 +263,12 @@ describe('StringArrayStorage', () => { const code: string = readFileAsString(__dirname + '/fixtures/three-strings.js'); for (let i = 0; i < samples; i++) { - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...NO_ADDITIONAL_NODES_PRESET, - stringArrayShuffle: true, - stringArray: true, - stringArrayThreshold: 1 - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + stringArrayShuffle: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); for (let variantIndex = 0; variantIndex < variantsCount; variantIndex++) { if (obfuscatedCode.match(stringArrayVariantRegExps[variantIndex])) { @@ -286,10 +282,11 @@ describe('StringArrayStorage', () => { } for (let variantIndex = 0; variantIndex < variantsCount; variantIndex++) { - stringArrayVariantProbabilities[variantIndex] = stringArrayVariantMatchesLength[variantIndex] / samples; - literalNodeVariantProbabilities[variantIndex] = literalNodeVariantMatchesLength[variantIndex] / samples; + stringArrayVariantProbabilities[variantIndex] = + stringArrayVariantMatchesLength[variantIndex] / samples; + literalNodeVariantProbabilities[variantIndex] = + literalNodeVariantMatchesLength[variantIndex] / samples; } - }); for (let variantIndex = 0; variantIndex < variantsCount; variantIndex++) { diff --git a/test/helpers/atob.ts b/test/helpers/atob.ts index b98c72a34..eaf989054 100644 --- a/test/helpers/atob.ts +++ b/test/helpers/atob.ts @@ -2,6 +2,6 @@ * @param {string} encodedString * @returns {string} */ -export function atob (encodedString: string): string { +export function atob(encodedString: string): string { return Buffer.from(encodedString, 'base64').toString(); } diff --git a/test/helpers/beautifyCode.ts b/test/helpers/beautifyCode.ts index 48422086a..f116dd3e8 100644 --- a/test/helpers/beautifyCode.ts +++ b/test/helpers/beautifyCode.ts @@ -7,10 +7,10 @@ const beautify = require('js-beautify').js; * @param {" " | " "} character * @returns {string} */ -export function beautifyCode (code: string, character: 'space' | 'tab'): string { +export function beautifyCode(code: string, character: 'space' | 'tab'): string { const indentCharacter: string = character === 'space' ? '\x20' : '\x09'; return beautify(code, { indent_char: indentCharacter }); -} \ No newline at end of file +} diff --git a/test/helpers/buildLargeCode.ts b/test/helpers/buildLargeCode.ts index a7fc67f52..42adac7d7 100644 --- a/test/helpers/buildLargeCode.ts +++ b/test/helpers/buildLargeCode.ts @@ -1,4 +1,4 @@ -export function buildLargeCode (linesOfCode: number): string { +export function buildLargeCode(linesOfCode: number): string { return new LargeCodeBuilder(linesOfCode).build(); } @@ -16,11 +16,11 @@ class LargeCodeBuilder { /** * @param {number} linesOfCode */ - constructor (linesOfCode: number) { + constructor(linesOfCode: number) { this.linesOfCode = linesOfCode; } - public build (): string { + public build(): string { const lastLineIndex: number = this.linesOfCode - 1; let funcIndex: number = 0, @@ -77,7 +77,7 @@ class LargeCodeBuilder { * @param {string} line * @returns {string} */ - private addLine (line: string): void { + private addLine(line: string): void { this.code += `\n${line}`; } } diff --git a/test/helpers/checkCodeEvaluation.ts b/test/helpers/checkCodeEvaluation.ts index edda4f5ca..bf78b9d0b 100644 --- a/test/helpers/checkCodeEvaluation.ts +++ b/test/helpers/checkCodeEvaluation.ts @@ -6,7 +6,7 @@ * @param expectedResult * @returns {{areSuccessEvaluations: boolean, errorMessage?: string}} */ -export function checkCodeEvaluation ( +export function checkCodeEvaluation( codeGetterFunction: () => string, runsAmount: number, expectedResult?: any @@ -35,4 +35,4 @@ export function checkCodeEvaluation ( return { areSuccessEvaluations: true }; -} \ No newline at end of file +} diff --git a/test/helpers/evaluateInWorker.ts b/test/helpers/evaluateInWorker.ts index 12d739320..b2627e5d3 100644 --- a/test/helpers/evaluateInWorker.ts +++ b/test/helpers/evaluateInWorker.ts @@ -4,10 +4,7 @@ import { spawn, Thread, Worker } from 'threads'; * @param {string} code * @returns {Promise} */ -export function evaluateInWorker( - code: string, - waitTimeout: number -): Promise { +export function evaluateInWorker(code: string, waitTimeout: number): Promise { return new Promise(async (resolve, reject) => { const evaluationWorker = await spawn(new Worker('./workers/evaluation-worker')); @@ -30,4 +27,4 @@ export function evaluateInWorker( reject(error); } }); -} \ No newline at end of file +} diff --git a/test/helpers/get-string-array-regexp.ts b/test/helpers/get-string-array-regexp.ts index 94f4997c5..46f2b6918 100644 --- a/test/helpers/get-string-array-regexp.ts +++ b/test/helpers/get-string-array-regexp.ts @@ -1,28 +1,25 @@ const defaultOptions = { name: '_0x([a-f0-9]){4}', kind: 'var' -} +}; /** * Returns string array RegExp * * @returns {RegExp} */ -export function getStringArrayRegExp( - stringArrayItems: string[], - options: Partial = {} -): RegExp { +export function getStringArrayRegExp(stringArrayItems: string[], options: Partial = {}): RegExp { const mergedOptions = { ...defaultOptions, ...options }; - const {name, kind} = mergedOptions; + const { name, kind } = mergedOptions; return new RegExp( `function (${name}) *\\(\\) *{` + `${kind}.*= *\\[${stringArrayItems.map((item: string) => `\'${item}\'`).join(',')}];.*` + `return ${name}\\(\\); *` + - '}' + '}' ); -} \ No newline at end of file +} diff --git a/test/helpers/getRegExpMatch.ts b/test/helpers/getRegExpMatch.ts index f03fd973b..fcf214634 100644 --- a/test/helpers/getRegExpMatch.ts +++ b/test/helpers/getRegExpMatch.ts @@ -4,7 +4,7 @@ * @param matchIndex * @return {string} */ -export function getRegExpMatch (str: string, regExp: RegExp, matchIndex: number = 0): string { +export function getRegExpMatch(str: string, regExp: RegExp, matchIndex: number = 0): string { const match: RegExpMatchArray | null = str.match(regExp); if (!match) { diff --git a/test/helpers/minimizeCode.ts b/test/helpers/minimizeCode.ts index 622b8292b..b0827fd2d 100644 --- a/test/helpers/minimizeCode.ts +++ b/test/helpers/minimizeCode.ts @@ -1,4 +1,4 @@ -import {minify} from 'terser'; +import { minify } from 'terser'; /** * Minimizes code @@ -6,8 +6,8 @@ import {minify} from 'terser'; * @param {string} code * @returns {string} */ -export async function minimizeCode (code: string): Promise { +export async function minimizeCode(code: string): Promise { const result = await minify(code); return result.code ?? ''; -} \ No newline at end of file +} diff --git a/test/helpers/parseSourceMapFromObfuscatedCode.ts b/test/helpers/parseSourceMapFromObfuscatedCode.ts index 75e044623..eeb626316 100644 --- a/test/helpers/parseSourceMapFromObfuscatedCode.ts +++ b/test/helpers/parseSourceMapFromObfuscatedCode.ts @@ -6,6 +6,6 @@ import { atob } from './atob'; * @param {string} obfuscatedCodeWithInlineSourceMap * @returns {ISourceMap} */ -export function parseSourceMapFromObfuscatedCode (obfuscatedCodeWithInlineSourceMap: string): ISourceMap { +export function parseSourceMapFromObfuscatedCode(obfuscatedCodeWithInlineSourceMap: string): ISourceMap { return JSON.parse(atob(obfuscatedCodeWithInlineSourceMap.split('base64,')[1])); } diff --git a/test/helpers/readFileAsString.ts b/test/helpers/readFileAsString.ts index 1d5dde0de..3e39b71f3 100644 --- a/test/helpers/readFileAsString.ts +++ b/test/helpers/readFileAsString.ts @@ -4,6 +4,6 @@ import * as fs from 'fs'; * @param path * @returns {string} */ -export function readFileAsString (path: string): string { +export function readFileAsString(path: string): string { return fs.readFileSync(path, 'utf8'); -} \ No newline at end of file +} diff --git a/test/helpers/removeRangesFromStructure.ts b/test/helpers/removeRangesFromStructure.ts index db26a3a44..38fa3ec15 100644 --- a/test/helpers/removeRangesFromStructure.ts +++ b/test/helpers/removeRangesFromStructure.ts @@ -7,7 +7,7 @@ import { TStatement } from '../../src/types/node/TStatement'; * @param {TStatement[]} structure * @returns {TStatement[]} */ -export function removeRangesFromStructure (structure: TStatement[]): TStatement[] { +export function removeRangesFromStructure(structure: TStatement[]): TStatement[] { for (const statement of structure) { estraverse.replace(statement, { enter: (node: ESTree.Node): ESTree.Node => { @@ -25,4 +25,4 @@ export function removeRangesFromStructure (structure: TStatement[]): TStatement[ } return structure; -} \ No newline at end of file +} diff --git a/test/helpers/stubNodeTransformers.ts b/test/helpers/stubNodeTransformers.ts index 4e5125f03..ade2c8a65 100644 --- a/test/helpers/stubNodeTransformers.ts +++ b/test/helpers/stubNodeTransformers.ts @@ -3,14 +3,12 @@ import * as sinon from 'sinon'; import { INodeTransformer } from '../../src/interfaces/node-transformers/INodeTransformer'; -export function stubNodeTransformers (nodeTransformers: (new (...args: any[]) => INodeTransformer)[]): void { +export function stubNodeTransformers(nodeTransformers: (new (...args: any[]) => INodeTransformer)[]): void { const transformerStubs: sinon.SinonStub[] = []; mocha.before(() => { for (const nodeTransformer of nodeTransformers) { - const stub: sinon.SinonStub = sinon - .stub(nodeTransformer.prototype, 'getVisitor') - .callsFake(() => null); + const stub: sinon.SinonStub = sinon.stub(nodeTransformer.prototype, 'getVisitor').callsFake(() => null); transformerStubs.push(stub); } diff --git a/test/helpers/swapLettersCase.ts b/test/helpers/swapLettersCase.ts index aa18ffdb4..a5a664ba0 100644 --- a/test/helpers/swapLettersCase.ts +++ b/test/helpers/swapLettersCase.ts @@ -2,13 +2,9 @@ * @param {string} value * @returns {string} */ -export function swapLettersCase (value: string): string { +export function swapLettersCase(value: string): string { return value .split('') - .map((letter: string) => - letter === letter.toUpperCase() - ? letter.toLowerCase() - : letter.toUpperCase() - ) + .map((letter: string) => (letter === letter.toUpperCase() ? letter.toLowerCase() : letter.toUpperCase())) .join(''); } diff --git a/test/index.spec.ts b/test/index.spec.ts index d8ed26ebd..4c585766c 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -48,7 +48,7 @@ import './unit-tests/utils/CryptUtilsStringArray.spec'; import './unit-tests/utils/EscapeSequenceEncoder.spec'; import './unit-tests/utils/LevelledTopologicalSorter.spec'; import './unit-tests/utils/NumberUtils.spec'; -import './unit-tests/utils/ObfuscatedCodeFileUtils.spec' +import './unit-tests/utils/ObfuscatedCodeFileUtils.spec'; import './unit-tests/utils/RandomGenerator.spec'; import './unit-tests/utils/SetUtils.spec'; import './unit-tests/utils/StringUtils.spec'; diff --git a/test/mocks/StdoutWriteMock.ts b/test/mocks/StdoutWriteMock.ts index c7881795f..97b86c8b3 100644 --- a/test/mocks/StdoutWriteMock.ts +++ b/test/mocks/StdoutWriteMock.ts @@ -7,20 +7,20 @@ export class StdoutWriteMock { /** * @type any */ - private stdoutWriteMock: any = (() => {}); + private stdoutWriteMock: any = () => {}; /** * @param stdoutWrite */ - constructor (stdoutWrite: any) { + constructor(stdoutWrite: any) { this.stdoutWrite = stdoutWrite; } - public mute (): void { + public mute(): void { process.stdout.write = this.stdoutWriteMock; } - public restore (): void { + public restore(): void { process.stdout.write = this.stdoutWrite; } } diff --git a/test/performance-tests/JavaScriptObfuscatorMemory.spec.ts b/test/performance-tests/JavaScriptObfuscatorMemory.spec.ts index 2f58cecbc..e8b78da3f 100644 --- a/test/performance-tests/JavaScriptObfuscatorMemory.spec.ts +++ b/test/performance-tests/JavaScriptObfuscatorMemory.spec.ts @@ -6,7 +6,7 @@ import { StringArrayEncoding } from '../../src/enums/node-transformers/string-ar import { JavaScriptObfuscator } from '../../src/JavaScriptObfuscatorFacade'; -const heapValueToMB = (value: number) => Math.round(value / 1024 / 1024 * 100) / 100; +const heapValueToMB = (value: number) => Math.round((value / 1024 / 1024) * 100) / 100; describe('JavaScriptObfuscator memory', function () { const iterationsCount: number = 500; @@ -23,32 +23,29 @@ describe('JavaScriptObfuscator memory', function () { let prevHeapUsed: number | null = null; for (let i: number = 0; i < iterationsCount; i++) { - JavaScriptObfuscator.obfuscate( - sourceCode, - { - compact: true, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 0.75, - deadCodeInjection: true, - deadCodeInjectionThreshold: 0.4, - debugProtection: false, - debugProtectionInterval: 0, - disableConsoleOutput: true, - identifierNamesGenerator: 'mangled', - log: false, - renameGlobals: false, - stringArrayRotate: true, - selfDefending: true, - stringArrayShuffle: true, - splitStrings: true, - splitStringsChunkLength: 2, - stringArray: true, - stringArrayEncoding: [StringArrayEncoding.Base64], - stringArrayThreshold: 0.75, - transformObjectKeys: true, - unicodeEscapeSequence: false - } - ); + JavaScriptObfuscator.obfuscate(sourceCode, { + compact: true, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 0.75, + deadCodeInjection: true, + deadCodeInjectionThreshold: 0.4, + debugProtection: false, + debugProtectionInterval: 0, + disableConsoleOutput: true, + identifierNamesGenerator: 'mangled', + log: false, + renameGlobals: false, + stringArrayRotate: true, + selfDefending: true, + stringArrayShuffle: true, + splitStrings: true, + splitStringsChunkLength: 2, + stringArray: true, + stringArrayEncoding: [StringArrayEncoding.Base64], + stringArrayThreshold: 0.75, + transformObjectKeys: true, + unicodeEscapeSequence: false + }); const heap = process.memoryUsage(); const heapUsed: number = heapValueToMB(heap.heapUsed); diff --git a/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts b/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts index 1078400a0..795373781 100644 --- a/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts +++ b/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts @@ -40,11 +40,7 @@ describe('JavaScriptObfuscator runtime eval', function () { stringArray: true, stringArrayCallsTransform: true, stringArrayCallsTransformThreshold: 1, - stringArrayEncoding: [ - StringArrayEncoding.None, - StringArrayEncoding.Base64, - StringArrayEncoding.Rc4 - ], + stringArrayEncoding: [StringArrayEncoding.None, StringArrayEncoding.Base64, StringArrayEncoding.Rc4], stringArrayIndexesType: [ StringArrayIndexesType.HexadecimalNumber, StringArrayIndexesType.HexadecimalNumericString @@ -168,7 +164,7 @@ describe('JavaScriptObfuscator runtime eval', function () { let evaluationResult: string; try { - evaluationResult = eval(obfuscatedCode) + evaluationResult = eval(obfuscatedCode); } catch (e) { throw new Error(`Evaluation error: ${e.message}. Code: ${obfuscatedCode}`); } @@ -194,10 +190,7 @@ describe('JavaScriptObfuscator runtime eval', function () { } ).getObfuscatedCode(); - assert.equal( - eval(obfuscatedCode), - '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08' - ); + assert.equal(eval(obfuscatedCode), '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'); }); }); @@ -209,14 +202,11 @@ describe('JavaScriptObfuscator runtime eval', function () { beforeEach(() => { const code: string = readFileAsString(process.cwd() + '/dist/index.js'); - const obfuscationResult = JavaScriptObfuscator.obfuscate( - code, - { - ...baseOptions, - ...options, - renameProperties: false - } - ); + const obfuscationResult = JavaScriptObfuscator.obfuscate(code, { + ...baseOptions, + ...options, + renameProperties: false + }); const obfuscatorOptions = obfuscationResult.getOptions(); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); @@ -241,10 +231,7 @@ describe('JavaScriptObfuscator runtime eval', function () { }); it('should obfuscate code without any runtime errors after obfuscation: Variant #3 obfuscator', () => { - assert.equal( - evaluationResult, - 'var foo=0x1;' - ); + assert.equal(evaluationResult, 'var foo=0x1;'); }); }); @@ -281,15 +268,12 @@ describe('JavaScriptObfuscator runtime eval', function () { beforeEach(() => { const code: string = readFileAsString(__dirname + '/fixtures/webpack-bootstrap.js'); - const obfuscatedCode: string = JavaScriptObfuscator.obfuscate( - code, - { - ...baseOptions, - ...options, - ...webpackBootstrapOptions, - reservedNames: ['^foo$'] - } - ).getObfuscatedCode(); + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...baseOptions, + ...options, + ...webpackBootstrapOptions, + reservedNames: ['^foo$'] + }).getObfuscatedCode(); try { evaluationResult = eval(` diff --git a/test/unit-tests/analyzers/number-numerical-expression-analyzer/NumberNumericalExpressionAnalyzer.spec.ts b/test/unit-tests/analyzers/number-numerical-expression-analyzer/NumberNumericalExpressionAnalyzer.spec.ts index dc203fd9d..4bf415536 100644 --- a/test/unit-tests/analyzers/number-numerical-expression-analyzer/NumberNumericalExpressionAnalyzer.spec.ts +++ b/test/unit-tests/analyzers/number-numerical-expression-analyzer/NumberNumericalExpressionAnalyzer.spec.ts @@ -18,11 +18,11 @@ import { NumberNumericalExpressionAnalyzer } from '../../../../src/analyzers/num */ const numberNumericalExpressionDataToString = (data: TNumberNumericalExpressionData) => data - .map((part: number | number[]) => Array.isArray(part) ? part.join('*') : part) + .map((part: number | number[]) => (Array.isArray(part) ? part.join('*') : part)) .join('+') .replace(/\+-/g, '-'); -describe('NumberNumericalExpressionAnalyzer', function() { +describe('NumberNumericalExpressionAnalyzer', function () { let numberNumericalExpressionAnalyzer: INumberNumericalExpressionAnalyzer; this.timeout(10000); @@ -31,8 +31,9 @@ describe('NumberNumericalExpressionAnalyzer', function() { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - numberNumericalExpressionAnalyzer = inversifyContainerFacade - .get(ServiceIdentifiers.INumberNumericalExpressionAnalyzer); + numberNumericalExpressionAnalyzer = inversifyContainerFacade.get( + ServiceIdentifiers.INumberNumericalExpressionAnalyzer + ); }); describe('analyze', () => { @@ -192,10 +193,11 @@ describe('NumberNumericalExpressionAnalyzer', function() { let testFunc: () => void; before(() => { - testFunc = () => numberNumericalExpressionAnalyzer.analyze( - number, - NumberNumericalExpressionAnalyzer.defaultAdditionalPartsCount - ); + testFunc = () => + numberNumericalExpressionAnalyzer.analyze( + number, + NumberNumericalExpressionAnalyzer.defaultAdditionalPartsCount + ); }); it('should throw error', () => { diff --git a/test/unit-tests/analyzers/prevailing-kind-of-variables-analyzer/PrevailingKindOfVariablesAnalyzer.spec.ts b/test/unit-tests/analyzers/prevailing-kind-of-variables-analyzer/PrevailingKindOfVariablesAnalyzer.spec.ts index 92174018d..e50d254b3 100644 --- a/test/unit-tests/analyzers/prevailing-kind-of-variables-analyzer/PrevailingKindOfVariablesAnalyzer.spec.ts +++ b/test/unit-tests/analyzers/prevailing-kind-of-variables-analyzer/PrevailingKindOfVariablesAnalyzer.spec.ts @@ -18,8 +18,9 @@ describe('PrevailingKindOfVariablesAnalyzer', () => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - prevailingKindOfVariablesAnalyzer = inversifyContainerFacade - .get(ServiceIdentifiers.IPrevailingKindOfVariablesAnalyzer); + prevailingKindOfVariablesAnalyzer = inversifyContainerFacade.get( + ServiceIdentifiers.IPrevailingKindOfVariablesAnalyzer + ); }); describe('analyze', () => { @@ -31,30 +32,15 @@ describe('PrevailingKindOfVariablesAnalyzer', () => { before(() => { const astTree: ESTree.Program = NodeFactory.programNode([ NodeFactory.variableDeclarationNode( - [ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('foo'), - null - ) - ], + [NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('foo'), null)], 'var' ), NodeFactory.variableDeclarationNode( - [ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('bar'), - null - ) - ], + [NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('bar'), null)], 'const' ), NodeFactory.variableDeclarationNode( - [ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('baz'), - null - ) - ], + [NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('baz'), null)], 'var' ) ]); @@ -74,30 +60,15 @@ describe('PrevailingKindOfVariablesAnalyzer', () => { before(() => { const astTree: ESTree.Program = NodeFactory.programNode([ NodeFactory.variableDeclarationNode( - [ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('foo'), - null - ) - ], + [NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('foo'), null)], 'let' ), NodeFactory.variableDeclarationNode( - [ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('bar'), - null - ) - ], + [NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('bar'), null)], 'var' ), NodeFactory.variableDeclarationNode( - [ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('baz'), - null - ) - ], + [NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('baz'), null)], 'let' ) ]); @@ -117,30 +88,15 @@ describe('PrevailingKindOfVariablesAnalyzer', () => { before(() => { const astTree: ESTree.Program = NodeFactory.programNode([ NodeFactory.variableDeclarationNode( - [ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('foo'), - null - ) - ], + [NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('foo'), null)], 'let' ), NodeFactory.variableDeclarationNode( - [ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('bar'), - null - ) - ], + [NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('bar'), null)], 'const' ), NodeFactory.variableDeclarationNode( - [ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('baz'), - null - ) - ], + [NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('baz'), null)], 'const' ) ]); diff --git a/test/unit-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts b/test/unit-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts index 979655a39..8c74a3732 100644 --- a/test/unit-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts +++ b/test/unit-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts @@ -19,8 +19,7 @@ describe('ScopeAnalyzer', () => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - scopeAnalyzer = inversifyContainerFacade - .get(ServiceIdentifiers.IScopeAnalyzer); + scopeAnalyzer = inversifyContainerFacade.get(ServiceIdentifiers.IScopeAnalyzer); }); describe('analyze', () => { @@ -65,10 +64,7 @@ describe('ScopeAnalyzer', () => { beforeEach(() => { const variableDeclarationNode: ESTree.VariableDeclaration = NodeFactory.variableDeclarationNode([ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('foo'), - NodeFactory.literalNode(1) - ) + NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('foo'), NodeFactory.literalNode(1)) ]); const programNode: ESTree.Program = NodeFactory.programNode([variableDeclarationNode]); @@ -112,10 +108,7 @@ describe('ScopeAnalyzer', () => { beforeEach(() => { const variableDeclarationNode: ESTree.VariableDeclaration = NodeFactory.variableDeclarationNode([ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('foo'), - NodeFactory.literalNode(1) - ) + NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('foo'), NodeFactory.literalNode(1)) ]); const programNode: ESTree.Program = NodeFactory.programNode([variableDeclarationNode]); @@ -137,28 +130,17 @@ describe('ScopeAnalyzer', () => { beforeEach(() => { const variableDeclarationNode: ESTree.VariableDeclaration = NodeFactory.variableDeclarationNode([ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('foo'), - NodeFactory.literalNode(1) - ) + NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('foo'), NodeFactory.literalNode(1)) ]); const programNode: ESTree.Program = NodeFactory.programNode([ NodeFactory.ifStatementNode( - NodeFactory.binaryExpressionNode( - '+', - NodeFactory.literalNode(1), - NodeFactory.literalNode(2) - ), - NodeFactory.blockStatementNode([ - variableDeclarationNode - ]), + NodeFactory.binaryExpressionNode('+', NodeFactory.literalNode(1), NodeFactory.literalNode(2)), + NodeFactory.blockStatementNode([variableDeclarationNode]), NodeFactory.blockStatementNode([ NodeFactory.functionDeclarationNode( 'bar', [], - NodeFactory.blockStatementNode([ - variableDeclarationNode - ]) + NodeFactory.blockStatementNode([variableDeclarationNode]) ) ]) ) diff --git a/test/unit-tests/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.spec.ts b/test/unit-tests/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.spec.ts index 4196b4bb2..72e19f7b8 100644 --- a/test/unit-tests/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.spec.ts +++ b/test/unit-tests/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.spec.ts @@ -194,10 +194,7 @@ describe('StringArrayStorageAnalyzer', () => { NodeFactory.variableDeclaratorNode( NodeFactory.identifierNode('bar'), NodeFactory.objectExpressionNode([ - NodeFactory.propertyNode( - literalNode2, - NodeFactory.literalNode(1) - ) + NodeFactory.propertyNode(literalNode2, NodeFactory.literalNode(1)) ]) ) ]) @@ -220,7 +217,7 @@ describe('StringArrayStorageAnalyzer', () => { describe('Analyzes of the AST tree with ignored string literal nodes', () => { const literalNode1: ESTree.Literal = NodeFactory.literalNode('foo'); const literalNode2: ESTree.Literal = NodeFactory.literalNode('bar'); - NodeMetadata.set(literalNode2, {ignoredNode: true}); + NodeMetadata.set(literalNode2, { ignoredNode: true }); const expectedStringArrayStorageItemData1: IStringArrayStorageItemData = { encodedValue: 'foo', @@ -263,7 +260,7 @@ describe('StringArrayStorageAnalyzer', () => { describe('Variant #1: Force obfuscate string when threshold is `0`', () => { const literalNode1: ESTree.Literal = NodeFactory.literalNode('foo'); const literalNode2: ESTree.Literal = NodeFactory.literalNode('bar'); - NodeMetadata.set(literalNode2, {forceTransformNode: true}); + NodeMetadata.set(literalNode2, { forceTransformNode: true }); const expectedStringArrayStorageItemData1: undefined = undefined; const expectedStringArrayStorageItemData2: IStringArrayStorageItemData = { @@ -305,7 +302,7 @@ describe('StringArrayStorageAnalyzer', () => { describe('Variant #2: Force obfuscate string when string value shorter than allowed length', () => { const literalNode1: ESTree.Literal = NodeFactory.literalNode('a'); const literalNode2: ESTree.Literal = NodeFactory.literalNode('b'); - NodeMetadata.set(literalNode2, {forceTransformNode: true}); + NodeMetadata.set(literalNode2, { forceTransformNode: true }); const expectedStringArrayStorageItemData1: undefined = undefined; const expectedStringArrayStorageItemData2: IStringArrayStorageItemData = { @@ -416,7 +413,8 @@ describe('StringArrayStorageAnalyzer', () => { const stringArrayStorageItemData2: IStringArrayStorageItemData | undefined = stringArrayStorageAnalyzer.getItemDataForLiteralNode(literalNode2); - isStringArrayStorageItemDataEmpty = !stringArrayStorageItemData1 && !stringArrayStorageItemData2; + isStringArrayStorageItemDataEmpty = + !stringArrayStorageItemData1 && !stringArrayStorageItemData2; if (!isStringArrayStorageItemDataEmpty) { break; diff --git a/test/unit-tests/cli/sanitizers/BooleanSanitizer.spec.ts b/test/unit-tests/cli/sanitizers/BooleanSanitizer.spec.ts index 90b8141c2..c81559a35 100644 --- a/test/unit-tests/cli/sanitizers/BooleanSanitizer.spec.ts +++ b/test/unit-tests/cli/sanitizers/BooleanSanitizer.spec.ts @@ -2,7 +2,6 @@ import { assert } from 'chai'; import { BooleanSanitizer } from '../../../../src/cli/sanitizers/BooleanSanitizer'; - describe('BooleanSanitizer', () => { describe('Variant #1: input value `true`', () => { const inputValue: string = 'true'; diff --git a/test/unit-tests/cli/utils/IdentifierNamesCacheFileUtils.spec.ts b/test/unit-tests/cli/utils/IdentifierNamesCacheFileUtils.spec.ts index b0ff913f1..6e2b47c03 100644 --- a/test/unit-tests/cli/utils/IdentifierNamesCacheFileUtils.spec.ts +++ b/test/unit-tests/cli/utils/IdentifierNamesCacheFileUtils.spec.ts @@ -19,7 +19,7 @@ describe('IdentifierNamesCacheFileUtils', () => { propertyIdentifiers: { bar: '_0x654321' } - } + }; const fileContent: string = JSON.stringify(expectedIdentifierNamesCache); const tmpDirectoryPath: string = path.join('test', 'tmp'); diff --git a/test/unit-tests/cli/utils/ObfuscatedCodeFileUtils.spec.ts b/test/unit-tests/cli/utils/ObfuscatedCodeFileUtils.spec.ts index 4556b5d64..ce87401ed 100644 --- a/test/unit-tests/cli/utils/ObfuscatedCodeFileUtils.spec.ts +++ b/test/unit-tests/cli/utils/ObfuscatedCodeFileUtils.spec.ts @@ -11,11 +11,8 @@ describe('obfuscatedCodeFileUtils', () => { describe('getOutputCodePath', () => { before(() => { - mkdirp.sync(path.join(tmpDirectoryPath, 'input', 'nested',)); - fs.writeFileSync( - path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js'), - 'var foo = 1;' - ); + mkdirp.sync(path.join(tmpDirectoryPath, 'input', 'nested')); + fs.writeFileSync(path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js'), 'var foo = 1;'); }); describe('Variant #1: raw input path is a file path, raw output path is a file path', () => { @@ -27,12 +24,9 @@ describe('obfuscatedCodeFileUtils', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); @@ -50,12 +44,9 @@ describe('obfuscatedCodeFileUtils', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); @@ -72,12 +63,9 @@ describe('obfuscatedCodeFileUtils', () => { let testFunc: () => string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); testFunc = () => obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); @@ -91,21 +79,14 @@ describe('obfuscatedCodeFileUtils', () => { const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js'); const rawInputPath: string = path.join(tmpDirectoryPath, 'input'); const rawOutputPath: string = path.join(tmpDirectoryPath, 'output'); - const expectedOutputCodePath: string = path.join( - tmpDirectoryPath, - 'output', - 'test-input.js' - ); + const expectedOutputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-input.js'); let outputCodePath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); @@ -118,21 +99,14 @@ describe('obfuscatedCodeFileUtils', () => { const inputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js'); const rawInputPath: string = path.join(tmpDirectoryPath, 'input'); const rawOutputPath: string = path.join('.', tmpDirectoryPath, 'output'); - const expectedOutputCodePath: string = path.join( - tmpDirectoryPath, - 'output', - 'test-input.js' - ); + const expectedOutputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-input.js'); let outputCodePath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); @@ -145,22 +119,14 @@ describe('obfuscatedCodeFileUtils', () => { const inputPath: string = path.join(tmpDirectoryPath, 'input', 'nested', 'test-input.js'); const rawInputPath: string = path.join(tmpDirectoryPath, 'input'); const rawOutputPath: string = path.join(tmpDirectoryPath, 'output'); - const expectedOutputCodePath: string = path.join( - tmpDirectoryPath, - 'output', - 'nested', - 'test-input.js' - ); + const expectedOutputCodePath: string = path.join(tmpDirectoryPath, 'output', 'nested', 'test-input.js'); let outputCodePath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); @@ -184,12 +150,9 @@ describe('obfuscatedCodeFileUtils', () => { let outputCodePath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); @@ -202,21 +165,14 @@ describe('obfuscatedCodeFileUtils', () => { const inputPath: string = path.join('test-input.js'); const rawInputPath: string = path.join('.'); const rawOutputPath: string = path.join(tmpDirectoryPath, 'output'); - const expectedOutputCodePath: string = path.join( - tmpDirectoryPath, - 'output', - 'test-input.js' - ); + const expectedOutputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-input.js'); let outputCodePath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); @@ -229,21 +185,14 @@ describe('obfuscatedCodeFileUtils', () => { const inputPath: string = path.join('test-input.js'); const rawInputPath: string = path.join('./'); const rawOutputPath: string = path.join(tmpDirectoryPath, 'output'); - const expectedOutputCodePath: string = path.join( - tmpDirectoryPath, - 'output', - 'test-input.js' - ); + const expectedOutputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-input.js'); let outputCodePath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); outputCodePath = obfuscatedCodeFileUtils.getOutputCodePath(inputPath); }); @@ -266,7 +215,13 @@ describe('obfuscatedCodeFileUtils', () => { describe('Variant #1: raw input absolute path is a directory path, raw output absolute path is a directory path', () => { describe('Variant #1: base directory name', () => { - const inputPath: string = path.join(baseDirnamePath, tmpDirectoryPath, 'input', 'nested', 'test-input.js'); + const inputPath: string = path.join( + baseDirnamePath, + tmpDirectoryPath, + 'input', + 'nested', + 'test-input.js' + ); const rawInputPath: string = path.join(baseDirnamePath, tmpDirectoryPath, 'input'); const rawOutputPath: string = path.join(baseDirnamePath, tmpDirectoryPath, 'output'); const expectedOutputCodePath: string = path.join( @@ -313,7 +268,11 @@ describe('obfuscatedCodeFileUtils', () => { const rawInputPath: string = path.join(tmpDirectoryPath, 'input', 'test-input.js'); const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js'); const outputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js'); - const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js.map'); + const expectedOutputSourceMapPath: string = path.join( + tmpDirectoryPath, + 'output', + 'test-output.js.map' + ); let outputSourceMapPath: string; @@ -336,7 +295,11 @@ describe('obfuscatedCodeFileUtils', () => { const rawInputPath: string = path.join(tmpDirectoryPath, 'input.with.dot', 'test-input.js'); const rawOutputPath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js'); const outputCodePath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js'); - const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js.map'); + const expectedOutputSourceMapPath: string = path.join( + tmpDirectoryPath, + 'output.with.dot', + 'test-output.js.map' + ); let outputSourceMapPath: string; @@ -373,7 +336,10 @@ describe('obfuscatedCodeFileUtils', () => { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName + ); }); it('should return output path for source map', () => { @@ -397,7 +363,10 @@ describe('obfuscatedCodeFileUtils', () => { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName + ); }); it('should return output path for source map', () => { @@ -421,7 +390,10 @@ describe('obfuscatedCodeFileUtils', () => { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName + ); }); it('should return output path for source map', () => { @@ -434,7 +406,12 @@ describe('obfuscatedCodeFileUtils', () => { const rawOutputPath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js'); const outputCodePath: string = path.join(tmpDirectoryPath, 'output', 'test-output.js'); const sourceMapFileName: string = path.join('parent', 'foo.js.map'); - const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output', 'parent', 'foo.js.map'); + const expectedOutputSourceMapPath: string = path.join( + tmpDirectoryPath, + 'output', + 'parent', + 'foo.js.map' + ); let outputSourceMapPath: string; @@ -445,7 +422,10 @@ describe('obfuscatedCodeFileUtils', () => { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName + ); }); it('should return output path for source map', () => { @@ -458,7 +438,12 @@ describe('obfuscatedCodeFileUtils', () => { const rawOutputPath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js'); const outputCodePath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'test-output.js'); const sourceMapFileName: string = path.join('parent', 'foo.js.map'); - const expectedOutputSourceMapPath: string = path.join(tmpDirectoryPath, 'output.with.dot', 'parent', 'foo.js.map'); + const expectedOutputSourceMapPath: string = path.join( + tmpDirectoryPath, + 'output.with.dot', + 'parent', + 'foo.js.map' + ); let outputSourceMapPath: string; @@ -469,7 +454,10 @@ describe('obfuscatedCodeFileUtils', () => { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName + ); }); it('should return output path for source map', () => { @@ -541,7 +529,12 @@ describe('obfuscatedCodeFileUtils', () => { const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js'); const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js'); const sourceMapFileName: string = path.join('foo'); - const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'foo.js.map'); + const expectedOutputSourceMapPath: string = path.join( + 'C:\\', + tmpDirectoryPath, + 'output', + 'foo.js.map' + ); let outputSourceMapPath: string; @@ -552,7 +545,10 @@ describe('obfuscatedCodeFileUtils', () => { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName + ); }); it('should return output path for source map', () => { @@ -565,7 +561,12 @@ describe('obfuscatedCodeFileUtils', () => { const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js'); const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js'); const sourceMapFileName: string = path.join('foo.js.map'); - const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'foo.js.map'); + const expectedOutputSourceMapPath: string = path.join( + 'C:\\', + tmpDirectoryPath, + 'output', + 'foo.js.map' + ); let outputSourceMapPath: string; @@ -576,7 +577,10 @@ describe('obfuscatedCodeFileUtils', () => { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName + ); }); it('should return output path for source map', () => { @@ -589,7 +593,13 @@ describe('obfuscatedCodeFileUtils', () => { const rawOutputPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js'); const outputCodePath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'test-output.js'); const sourceMapFileName: string = path.join('C:\\', 'parent', 'foo.js.map'); - const expectedOutputSourceMapPath: string = path.join('C:\\', tmpDirectoryPath, 'output', 'parent', 'foo.js.map'); + const expectedOutputSourceMapPath: string = path.join( + 'C:\\', + tmpDirectoryPath, + 'output', + 'parent', + 'foo.js.map' + ); let outputSourceMapPath: string; @@ -600,7 +610,10 @@ describe('obfuscatedCodeFileUtils', () => { output: rawOutputPath } ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName + ); }); it('should return output path for source map', () => { @@ -619,12 +632,9 @@ describe('obfuscatedCodeFileUtils', () => { let testFunc: () => string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); testFunc = () => obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath); }); @@ -643,13 +653,13 @@ describe('obfuscatedCodeFileUtils', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -667,13 +677,13 @@ describe('obfuscatedCodeFileUtils', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -691,13 +701,13 @@ describe('obfuscatedCodeFileUtils', () => { let outputSourceMapPath: string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); + outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath( + outputCodePath, + sourceMapFileName ); - outputSourceMapPath = obfuscatedCodeFileUtils.getOutputSourceMapPath(outputCodePath, sourceMapFileName); }); it('should return output path for source map', () => { @@ -713,12 +723,9 @@ describe('obfuscatedCodeFileUtils', () => { let testFunc: () => string; before(() => { - const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( - rawInputPath, - { - output: rawOutputPath - } - ); + const obfuscatedCodeFileUtils: ObfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils(rawInputPath, { + output: rawOutputPath + }); testFunc = () => obfuscatedCodeFileUtils.getOutputSourceMapPath('', ''); }); diff --git a/test/unit-tests/cli/utils/SourceCodeFileUtils.spec.ts b/test/unit-tests/cli/utils/SourceCodeFileUtils.spec.ts index d69ab1bb5..f7dbb8437 100644 --- a/test/unit-tests/cli/utils/SourceCodeFileUtils.spec.ts +++ b/test/unit-tests/cli/utils/SourceCodeFileUtils.spec.ts @@ -23,10 +23,12 @@ describe('SourceCodeFileUtils', () => { describe('Variant #1: `inputPath` is a valid path', () => { const tmpFileName: string = 'test.js'; const inputPath: string = path.join(tmpDirectoryPath, tmpFileName); - const expectedFilesData: IFileData[] = [{ - content: fileContent, - filePath: inputPath - }]; + const expectedFilesData: IFileData[] = [ + { + content: fileContent, + filePath: inputPath + } + ]; let filesData: IFileData[]; @@ -80,24 +82,23 @@ describe('SourceCodeFileUtils', () => { }); describe('Variant #4: `exclude` option', () => { - describe('Variant #1: `inputPath` isn\'t excluded path', () => { + describe("Variant #1: `inputPath` isn't excluded path", () => { const tmpFileName: string = 'test.js'; const inputPath: string = path.join(tmpDirectoryPath, tmpFileName); - const expectedFilesData: IFileData[] = [{ - content: fileContent, - filePath: inputPath - }]; + const expectedFilesData: IFileData[] = [ + { + content: fileContent, + filePath: inputPath + } + ]; let filesData: IFileData[]; before(() => { fs.writeFileSync(inputPath, fileContent); - filesData = new SourceCodeFileUtils( - inputPath, - { - exclude: [path.join('**', 'foo.js')] - } - ).readSourceCode(); + filesData = new SourceCodeFileUtils(inputPath, { + exclude: [path.join('**', 'foo.js')] + }).readSourceCode(); }); it('should return valid files data', () => { @@ -118,12 +119,10 @@ describe('SourceCodeFileUtils', () => { before(() => { fs.writeFileSync(inputPath, fileContent); - testFunc = () => new SourceCodeFileUtils( - inputPath, - { + testFunc = () => + new SourceCodeFileUtils(inputPath, { exclude: [path.join('**', tmpFileName)] - } - ).readSourceCode(); + }).readSourceCode(); }); it('should throw an error if `inputPath` is the excluded file path', () => { @@ -143,12 +142,10 @@ describe('SourceCodeFileUtils', () => { before(() => { fs.writeFileSync(inputPath, fileContent); - testFunc = () => new SourceCodeFileUtils( - inputPath, - { + testFunc = () => + new SourceCodeFileUtils(inputPath, { exclude: [tmpFileName] - } - ).readSourceCode(); + }).readSourceCode(); }); it('should throw an error if `inputPath` is the excluded file path', () => { @@ -168,12 +165,10 @@ describe('SourceCodeFileUtils', () => { before(() => { fs.writeFileSync(inputPath, fileContent); - testFunc = () => new SourceCodeFileUtils( - inputPath, - { + testFunc = () => + new SourceCodeFileUtils(inputPath, { exclude: [inputPath] - } - ).readSourceCode(); + }).readSourceCode(); }); it('should throw an error if `inputPath` is the excluded file path', () => { @@ -306,7 +301,7 @@ describe('SourceCodeFileUtils', () => { }); describe('Variant #4: `exclude` option', () => { - describe('Variant #1: `inputPath` isn\'t excluded path', () => { + describe("Variant #1: `inputPath` isn't excluded path", () => { const tmpFileName1: string = 'foo.js'; const tmpFileName2: string = 'bar.js'; const tmpFileName3: string = 'baz.png'; @@ -334,12 +329,9 @@ describe('SourceCodeFileUtils', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeFileUtils( - tmpDirectoryPath, - { - exclude: ['**/hawk.js'] - } - ).readSourceCode(); + result = new SourceCodeFileUtils(tmpDirectoryPath, { + exclude: ['**/hawk.js'] + }).readSourceCode(); }); it('should return files data', () => { @@ -383,15 +375,9 @@ describe('SourceCodeFileUtils', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeFileUtils( - tmpDirectoryPath, - { - exclude: [ - `**/${tmpFileName2}`, - `**/${tmpFileName4}` - ] - } - ).readSourceCode(); + result = new SourceCodeFileUtils(tmpDirectoryPath, { + exclude: [`**/${tmpFileName2}`, `**/${tmpFileName4}`] + }).readSourceCode(); }); it('should return files data', () => { @@ -434,15 +420,9 @@ describe('SourceCodeFileUtils', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeFileUtils( - tmpDirectoryPath, - { - exclude: [ - tmpFileName2, - tmpFileName4 - ] - } - ).readSourceCode(); + result = new SourceCodeFileUtils(tmpDirectoryPath, { + exclude: [tmpFileName2, tmpFileName4] + }).readSourceCode(); }); it('should return files data', () => { @@ -485,15 +465,9 @@ describe('SourceCodeFileUtils', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - result = new SourceCodeFileUtils( - tmpDirectoryPath, - { - exclude: [ - filePath2, - filePath4 - ] - } - ).readSourceCode(); + result = new SourceCodeFileUtils(tmpDirectoryPath, { + exclude: [filePath2, filePath4] + }).readSourceCode(); }); it('should return files data', () => { @@ -525,12 +499,10 @@ describe('SourceCodeFileUtils', () => { fs.writeFileSync(filePath2, fileContent); fs.writeFileSync(filePath3, fileContent); fs.writeFileSync(filePath4, fileContent); - testFunc = () => new SourceCodeFileUtils( - tmpDirectoryPath, - { + testFunc = () => + new SourceCodeFileUtils(tmpDirectoryPath, { exclude: [tmpDirectoryPath] - } - ).readSourceCode(); + }).readSourceCode(); }); it('should return files data', () => { diff --git a/test/unit-tests/decorators/initializable/Initializable.spec.ts b/test/unit-tests/decorators/initializable/Initializable.spec.ts index 7d3f07334..5396aceef 100644 --- a/test/unit-tests/decorators/initializable/Initializable.spec.ts +++ b/test/unit-tests/decorators/initializable/Initializable.spec.ts @@ -12,7 +12,7 @@ describe('@initializable', () => { @initializable() public property!: string; - public initialize (property: string): void { + public initialize(property: string): void { this.property = property; } } @@ -24,7 +24,7 @@ describe('@initializable', () => { foo.property; }; - it('shouldn\'t throws an errors if property was initialized', () => { + it("shouldn't throws an errors if property was initialized", () => { assert.doesNotThrow(testFunc, Error); }); }); @@ -36,11 +36,11 @@ describe('@initializable', () => { @initializable() public property!: string; - public initialize (property: string): void { + public initialize(property: string): void { this.property = property; } - public bar (): void {} + public bar(): void {} } const foo: Foo = new Foo(); @@ -49,7 +49,7 @@ describe('@initializable', () => { foo.bar(); }; - it('shouldn\'t throw an error if `initialize` method was called first', () => { + it("shouldn't throw an error if `initialize` method was called first", () => { assert.doesNotThrow(testFunc, /Class should be initialized/); }); }); @@ -60,11 +60,11 @@ describe('@initializable', () => { @initializable() public property!: string; - public initialize (property: string): void { + public initialize(property: string): void { this.innerInitialize(property); } - public innerInitialize (property: string): void { + public innerInitialize(property: string): void { this.property = property; } } @@ -74,7 +74,7 @@ describe('@initializable', () => { foo.initialize('baz'); }; - it('shouldn\'t throw an error if other method was called inside `initialize` method', () => { + it("shouldn't throw an error if other method was called inside `initialize` method", () => { assert.doesNotThrow(testFunc, /Class should be initialized/); }); }); @@ -85,12 +85,11 @@ describe('@initializable', () => { @initializable() public property!: string; - public initialize (property: string): void { + public initialize(property: string): void { this.innerInitialize(property); } - public innerInitialize (property: string): void { - } + public innerInitialize(property: string): void {} } const foo: Foo = new Foo(); @@ -103,17 +102,17 @@ describe('@initializable', () => { }); }); - describe('Variant #4: `initialize` method wasn\'t called first', () => { + describe("Variant #4: `initialize` method wasn't called first", () => { const testFunc: () => void = () => { class Foo { @initializable() public property!: string; - public initialize (property: string): void { + public initialize(property: string): void { this.property = property; } - public bar (): void {} + public bar(): void {} } const foo: Foo = new Foo(); @@ -122,22 +121,22 @@ describe('@initializable', () => { foo.initialize('baz'); }; - it('should throws an error if `initialize` method wasn\'t called first', () => { + it("should throws an error if `initialize` method wasn't called first", () => { assert.throws(testFunc, /Class should be initialized/); }); }); - describe('Variant #5: `initialize` method wasn\'t called', () => { + describe("Variant #5: `initialize` method wasn't called", () => { const testFunc: () => void = () => { class Foo { @initializable() public property!: string; - public initialize (property: string): void { + public initialize(property: string): void { this.property = property; } - public bar (): void {} + public bar(): void {} } const foo: Foo = new Foo(); @@ -145,20 +144,19 @@ describe('@initializable', () => { foo.bar(); }; - it('should throws an error if `initialize` method wasn\'t called first', () => { + it("should throws an error if `initialize` method wasn't called first", () => { assert.throws(testFunc, /Class should be initialized/); }); }); }); - describe('Variant #3: property didn\'t initialized', () => { + describe("Variant #3: property didn't initialized", () => { const testFunc: () => void = () => { class Foo implements IInitializable { @initializable() public property!: string; - public initialize (property: string): void { - } + public initialize(property: string): void {} } const foo: Foo = new Foo(); @@ -168,7 +166,7 @@ describe('@initializable', () => { foo.property; }; - it('should throws an error if property didn\'t initialized', () => { + it("should throws an error if property didn't initialized", () => { assert.throws(testFunc, /Property `property` is not initialized/); }); }); diff --git a/test/unit-tests/generators/identifier-names-generators/DictionarylIdentifierNamesGenerator.spec.ts b/test/unit-tests/generators/identifier-names-generators/DictionarylIdentifierNamesGenerator.spec.ts index 69a362119..55e63bb15 100644 --- a/test/unit-tests/generators/identifier-names-generators/DictionarylIdentifierNamesGenerator.spec.ts +++ b/test/unit-tests/generators/identifier-names-generators/DictionarylIdentifierNamesGenerator.spec.ts @@ -12,8 +12,7 @@ import { IdentifierNamesGenerator } from '../../../../src/enums/generators/ident import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade'; describe('DictionaryIdentifierNamesGenerator', () => { - let identifierNamesGenerator: IIdentifierNamesGenerator, - dictionaryIdentifierName: string; + let identifierNamesGenerator: IIdentifierNamesGenerator, dictionaryIdentifierName: string; describe('generateNext', () => { describe('Base behaviour', () => { diff --git a/test/unit-tests/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.spec.ts b/test/unit-tests/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.spec.ts index 3800b7716..190edad8c 100644 --- a/test/unit-tests/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.spec.ts +++ b/test/unit-tests/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.spec.ts @@ -14,9 +14,7 @@ import { InversifyContainerFacade } from '../../../../src/container/InversifyCon describe('HexadecimalIdentifierNamesGenerator', () => { describe('generateNext', () => { describe('Base', () => { - let identifierNamesGenerator: IIdentifierNamesGenerator, - hexadecimalIdentifierName: string, - regExp: RegExp; + let identifierNamesGenerator: IIdentifierNamesGenerator, hexadecimalIdentifierName: string, regExp: RegExp; before(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); @@ -33,13 +31,11 @@ describe('HexadecimalIdentifierNamesGenerator', () => { it('should return hexadecimal name', () => { assert.match(hexadecimalIdentifierName, regExp); - }) + }); }); describe('Custom length', () => { - let identifierNamesGenerator: IIdentifierNamesGenerator, - hexadecimalIdentifierName: string, - regExp: RegExp; + let identifierNamesGenerator: IIdentifierNamesGenerator, hexadecimalIdentifierName: string, regExp: RegExp; before(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); @@ -56,15 +52,14 @@ describe('HexadecimalIdentifierNamesGenerator', () => { it('should return hexadecimal name', () => { assert.match(hexadecimalIdentifierName, regExp); - }) + }); }); }); describe('generateForGlobalScope', () => { const regExp: RegExp = /^foo_0x(\w){4,6}$/; - let identifierNamesGenerator: IIdentifierNamesGenerator, - hexadecimalIdentifierName: string; + let identifierNamesGenerator: IIdentifierNamesGenerator, hexadecimalIdentifierName: string; before(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); @@ -82,7 +77,7 @@ describe('HexadecimalIdentifierNamesGenerator', () => { it('should return hexadecimal name with prefix', () => { assert.match(hexadecimalIdentifierName, regExp); - }) + }); }); describe('generateForLabel', () => { @@ -105,25 +100,25 @@ describe('HexadecimalIdentifierNamesGenerator', () => { IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator ); - identifierNamesGenerator.generateForLabel(label1) - identifierNamesGenerator.generateForLabel(label1) + identifierNamesGenerator.generateForLabel(label1); + identifierNamesGenerator.generateForLabel(label1); hexadecimalIdentifierName1 = identifierNamesGenerator.generateForLabel(label1); - identifierNamesGenerator.generateForLabel(label2) - identifierNamesGenerator.generateForLabel(label2) + identifierNamesGenerator.generateForLabel(label2); + identifierNamesGenerator.generateForLabel(label2); hexadecimalIdentifierName2 = identifierNamesGenerator.generateForLabel(label2); }); it('should return valid hexadecimal name 1', () => { assert.match(hexadecimalIdentifierName1, regExp); - }) + }); it('should return valid hexadecimal name 2', () => { assert.match(hexadecimalIdentifierName2, regExp); - }) + }); it('should generate different hexadecimal names for different labels', () => { assert.notEqual(hexadecimalIdentifierName1, hexadecimalIdentifierName2); - }) + }); }); }); diff --git a/test/unit-tests/generators/identifier-names-generators/MangledShuffledlIdentifierNamesGenerator.spec.ts b/test/unit-tests/generators/identifier-names-generators/MangledShuffledlIdentifierNamesGenerator.spec.ts index 2e53bb9db..79519a24a 100644 --- a/test/unit-tests/generators/identifier-names-generators/MangledShuffledlIdentifierNamesGenerator.spec.ts +++ b/test/unit-tests/generators/identifier-names-generators/MangledShuffledlIdentifierNamesGenerator.spec.ts @@ -14,8 +14,7 @@ import { MangledShuffledIdentifierNamesGenerator } from '../../../../src/generat describe('MangledShuffledIdentifierNamesGenerator', () => { describe('generateNext', () => { - let identifierNamesGenerator: IIdentifierNamesGenerator, - mangledIdentifierName: string; + let identifierNamesGenerator: IIdentifierNamesGenerator, mangledIdentifierName: string; beforeEach(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); @@ -86,8 +85,7 @@ describe('MangledShuffledIdentifierNamesGenerator', () => { }); describe('generateForGlobalScope', () => { - let identifierNamesGenerator: IIdentifierNamesGenerator, - mangledIdentifierName: string; + let identifierNamesGenerator: IIdentifierNamesGenerator, mangledIdentifierName: string; before(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); @@ -145,7 +143,7 @@ describe('MangledShuffledIdentifierNamesGenerator', () => { it('should return the same mangled names set for different labels', () => { assert.deepEqual(mangledNames1, mangledNames2); - }) + }); }); describe('isIncrementedMangledName', function () { @@ -155,10 +153,11 @@ describe('MangledShuffledIdentifierNamesGenerator', () => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - const identifierNamesGenerator: IIdentifierNamesGenerator = inversifyContainerFacade.getNamed( - ServiceIdentifiers.IIdentifierNamesGenerator, - IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator - ); + const identifierNamesGenerator: IIdentifierNamesGenerator = + inversifyContainerFacade.getNamed( + ServiceIdentifiers.IIdentifierNamesGenerator, + IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator + ); let isSuccessComparison: boolean = true; let mangledName: string = ''; @@ -169,10 +168,13 @@ describe('MangledShuffledIdentifierNamesGenerator', () => { let resultReversed: boolean; mangledName = identifierNamesGenerator.generateNext(); - resultNormal = (identifierNamesGenerator) - .isIncrementedMangledName(mangledName, prevMangledName); - resultReversed = (identifierNamesGenerator) - .isIncrementedMangledName(prevMangledName, mangledName); + resultNormal = (identifierNamesGenerator).isIncrementedMangledName( + mangledName, + prevMangledName + ); + resultReversed = (( + identifierNamesGenerator + )).isIncrementedMangledName(prevMangledName, mangledName); if (!resultNormal || resultReversed) { isSuccessComparison = false; @@ -197,7 +199,7 @@ describe('MangledShuffledIdentifierNamesGenerator', () => { beforeEach(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); - inversifyContainerFacade.load('', '', {} ); + inversifyContainerFacade.load('', '', {}); identifierNamesGenerator = inversifyContainerFacade.getNamed( ServiceIdentifiers.IIdentifierNamesGenerator, IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator diff --git a/test/unit-tests/generators/identifier-names-generators/MangledlIdentifierNamesGenerator.spec.ts b/test/unit-tests/generators/identifier-names-generators/MangledlIdentifierNamesGenerator.spec.ts index 8b8125104..e64af8560 100644 --- a/test/unit-tests/generators/identifier-names-generators/MangledlIdentifierNamesGenerator.spec.ts +++ b/test/unit-tests/generators/identifier-names-generators/MangledlIdentifierNamesGenerator.spec.ts @@ -14,8 +14,7 @@ import { MangledIdentifierNamesGenerator } from '../../../../src/generators/iden describe('MangledIdentifierNamesGenerator', () => { describe('generateNext', () => { - let identifierNamesGenerator: IIdentifierNamesGenerator, - mangledIdentifierName: string; + let identifierNamesGenerator: IIdentifierNamesGenerator, mangledIdentifierName: string; beforeEach(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); @@ -105,8 +104,7 @@ describe('MangledIdentifierNamesGenerator', () => { const expectedMangledIdentifierPosition1: number = 261; const expectedMangledIdentifierPosition2: number = 262; - let mangledIdentifierName1: string, - mangledIdentifierName2: string; + let mangledIdentifierName1: string, mangledIdentifierName2: string; beforeEach(() => { for (let i: number = 0; i <= expectedMangledIdentifierPosition2; i++) { @@ -124,15 +122,14 @@ describe('MangledIdentifierNamesGenerator', () => { assert.equal(mangledIdentifierName1, expectedMangledIdentifierName1); }); - it('shouldn\'t return reserved mangled name', () => { + it("shouldn't return reserved mangled name", () => { assert.equal(mangledIdentifierName2, expectedMangledIdentifierName2); }); }); }); describe('generateForGlobalScope', () => { - let identifierNamesGenerator: IIdentifierNamesGenerator, - mangledIdentifierName: string; + let identifierNamesGenerator: IIdentifierNamesGenerator, mangledIdentifierName: string; before(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); @@ -178,8 +175,8 @@ describe('MangledIdentifierNamesGenerator', () => { const mangledNames1: string[] = []; const mangledNames2: string[] = []; - const expectedMangledNames1: string[] = ['a', 'b', 'c'] - const expectedMangledNames2: string[] = ['a', 'b'] + const expectedMangledNames1: string[] = ['a', 'b', 'c']; + const expectedMangledNames2: string[] = ['a', 'b']; let identifierNamesGenerator: IIdentifierNamesGenerator; @@ -204,11 +201,11 @@ describe('MangledIdentifierNamesGenerator', () => { it('should return valid mangled names for label 1', () => { assert.deepEqual(mangledNames1, expectedMangledNames1); - }) + }); it('should return valid mangled names for label 2', () => { assert.deepEqual(mangledNames2, expectedMangledNames2); - }) + }); }); describe('isIncrementedMangledName', function () { @@ -218,10 +215,11 @@ describe('MangledIdentifierNamesGenerator', () => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - const identifierNamesGenerator: IIdentifierNamesGenerator = inversifyContainerFacade.getNamed( - ServiceIdentifiers.IIdentifierNamesGenerator, - IdentifierNamesGenerator.MangledIdentifierNamesGenerator - ); + const identifierNamesGenerator: IIdentifierNamesGenerator = + inversifyContainerFacade.getNamed( + ServiceIdentifiers.IIdentifierNamesGenerator, + IdentifierNamesGenerator.MangledIdentifierNamesGenerator + ); let isSuccessComparison: boolean = true; let mangledName: string = ''; @@ -232,10 +230,14 @@ describe('MangledIdentifierNamesGenerator', () => { let resultReversed: boolean; mangledName = identifierNamesGenerator.generateNext(); - resultNormal = (identifierNamesGenerator) - .isIncrementedMangledName(mangledName, prevMangledName); - resultReversed = (identifierNamesGenerator) - .isIncrementedMangledName(prevMangledName, mangledName); + resultNormal = (identifierNamesGenerator).isIncrementedMangledName( + mangledName, + prevMangledName + ); + resultReversed = (identifierNamesGenerator).isIncrementedMangledName( + prevMangledName, + mangledName + ); if (!resultNormal || resultReversed) { isSuccessComparison = false; @@ -322,7 +324,7 @@ describe('MangledIdentifierNamesGenerator', () => { beforeEach(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); - inversifyContainerFacade.load('', '', {} ); + inversifyContainerFacade.load('', '', {}); identifierNamesGenerator = inversifyContainerFacade.getNamed( ServiceIdentifiers.IIdentifierNamesGenerator, IdentifierNamesGenerator.MangledIdentifierNamesGenerator diff --git a/test/unit-tests/javascript-obfuscator/ASTParserFacade.spec.ts b/test/unit-tests/javascript-obfuscator/ASTParserFacade.spec.ts index abdb2d45f..2546cebea 100644 --- a/test/unit-tests/javascript-obfuscator/ASTParserFacade.spec.ts +++ b/test/unit-tests/javascript-obfuscator/ASTParserFacade.spec.ts @@ -8,8 +8,9 @@ describe('ASTParserFacade', () => { describe(`parse`, () => { describe(`\`Unexpected token\` error code preview`, () => { describe('Variant #1: 5 lines of code', () => { - const sourceCode: string = `` + - `var foo = 1; + const sourceCode: string = + `` + + `var foo = 1; var bar = 2; var baz = 3;, var bark = 4; @@ -27,8 +28,9 @@ describe('ASTParserFacade', () => { }); describe('Variant #2: 15 lines of code', () => { - const sourceCode: string = `` + - `var var1 = 1; + const sourceCode: string = + `` + + `var var1 = 1; var var2 = 2; var var3 = 3; var var4 = 4; @@ -51,12 +53,16 @@ describe('ASTParserFacade', () => { }); it('should output code preview when AST parser throws a parse error', () => { - assert.throws(testFunc, /ERROR at line 13: Unexpected token \(13:28\)\n.*\.\.\.var baz = 3;,\.\.\./); + assert.throws( + testFunc, + /ERROR at line 13: Unexpected token \(13:28\)\n.*\.\.\.var baz = 3;,\.\.\./ + ); }); }); describe('Variant #3: code with functions', () => { - const sourceCode: string = `` + + const sourceCode: string = + `` + `function bar () { var a = 1; } @@ -74,7 +80,10 @@ describe('ASTParserFacade', () => { }); it('should output code preview when AST parser throws a parse error', () => { - assert.throws(testFunc, /ERROR at line 4: Unexpected token \(4:28\)\n.*\.\.\.functin baz \(\) {\.\.\./); + assert.throws( + testFunc, + /ERROR at line 4: Unexpected token \(4:28\)\n.*\.\.\.functin baz \(\) {\.\.\./ + ); }); }); }); diff --git a/test/unit-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts b/test/unit-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts index f4334e5be..ca05b734e 100644 --- a/test/unit-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts +++ b/test/unit-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts @@ -21,24 +21,19 @@ describe('JavaScriptObfuscator', () => { describe('Variant #1: default behaviour', () => { const regExp: RegExp = new RegExp(`sourceMappingURL=${sourceMapUrl}`); - let obfuscatedCode: string, - sourceMapObject: any; + let obfuscatedCode: string, sourceMapObject: any; before(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); - inversifyContainerFacade.load( - '', - '', - { - ...NO_ADDITIONAL_NODES_PRESET, - sourceMap: true, - sourceMapFileName: sourceMapUrl - } + inversifyContainerFacade.load('', '', { + ...NO_ADDITIONAL_NODES_PRESET, + sourceMap: true, + sourceMapFileName: sourceMapUrl + }); + javaScriptObfuscator = inversifyContainerFacade.get( + ServiceIdentifiers.IJavaScriptObfuscator ); - javaScriptObfuscator = inversifyContainerFacade - .get(ServiceIdentifiers.IJavaScriptObfuscator); - const obfuscationResult: IObfuscationResult = javaScriptObfuscator.obfuscate(code); @@ -59,25 +54,20 @@ describe('JavaScriptObfuscator', () => { const sourceMapBaseUrl: string = 'http://localhost:9000'; const regExp: RegExp = new RegExp(`sourceMappingURL=${sourceMapBaseUrl}/${sourceMapUrl}$`); - let obfuscatedCode: string, - sourceMapObject: any; + let obfuscatedCode: string, sourceMapObject: any; before(() => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); - inversifyContainerFacade.load( - '', - '', - { - ...NO_ADDITIONAL_NODES_PRESET, - sourceMap: true, - sourceMapBaseUrl: sourceMapBaseUrl, - sourceMapFileName: sourceMapUrl - } + inversifyContainerFacade.load('', '', { + ...NO_ADDITIONAL_NODES_PRESET, + sourceMap: true, + sourceMapBaseUrl: sourceMapBaseUrl, + sourceMapFileName: sourceMapUrl + }); + javaScriptObfuscator = inversifyContainerFacade.get( + ServiceIdentifiers.IJavaScriptObfuscator ); - javaScriptObfuscator = inversifyContainerFacade - .get(ServiceIdentifiers.IJavaScriptObfuscator); - const obfuscationResult: IObfuscationResult = javaScriptObfuscator.obfuscate(code); diff --git a/test/unit-tests/logger/Logger.spec.ts b/test/unit-tests/logger/Logger.spec.ts index a490f88a0..92885c5ad 100644 --- a/test/unit-tests/logger/Logger.spec.ts +++ b/test/unit-tests/logger/Logger.spec.ts @@ -21,9 +21,7 @@ describe('Logger', () => { const loggingMessage: string = '[javascript-obfuscator] foo'; const expectedConsoleLogCallResult: boolean = true; - let consoleLogSpy: sinon.SinonSpy, - consoleLogCallResult: boolean, - loggingMessageResult: string; + let consoleLogSpy: sinon.SinonSpy, consoleLogCallResult: boolean, loggingMessageResult: string; before(() => { consoleLogSpy = sinon.spy(console, 'log'); @@ -106,7 +104,7 @@ describe('Logger', () => { consoleLogCallResult = consoleLogSpy.called; }); - it('shouldn\'t call `console.log`', () => { + it("shouldn't call `console.log`", () => { assert.equal(consoleLogCallResult, expectedConsoleLogCallResult); }); @@ -177,7 +175,7 @@ describe('Logger', () => { consoleLogCallResult = consoleLogSpy.called; }); - it('shouldn\'t call `console.log`', () => { + it("shouldn't call `console.log`", () => { assert.equal(consoleLogCallResult, expectedConsoleLogCallResult); }); @@ -248,7 +246,7 @@ describe('Logger', () => { consoleLogCallResult = consoleLogSpy.called; }); - it('shouldn\'t call `console.log`', () => { + it("shouldn't call `console.log`", () => { assert.equal(consoleLogCallResult, expectedConsoleLogCallResult); }); diff --git a/test/unit-tests/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.spec.ts b/test/unit-tests/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.spec.ts index 411ef6a95..3e06b2571 100644 --- a/test/unit-tests/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.spec.ts +++ b/test/unit-tests/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.spec.ts @@ -20,23 +20,19 @@ describe('ObfuscatingGuardsTransformer', () => { const forceTransformString: string = 'important string'; const ignoredAndForceTransformString: string = 'important ignored string'; - let inversifyContainerFacade: IInversifyContainerFacade, - obfuscatingGuardsTransformer: INodeTransformer; + let inversifyContainerFacade: IInversifyContainerFacade, obfuscatingGuardsTransformer: INodeTransformer; before(() => { inversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', { - forceTransformStrings: [ - forceTransformString, - ignoredAndForceTransformString - ], - reservedStrings: [ - ignoredAndForceTransformString - ] + forceTransformStrings: [forceTransformString, ignoredAndForceTransformString], + reservedStrings: [ignoredAndForceTransformString] }); - obfuscatingGuardsTransformer = inversifyContainerFacade - .getNamed(ServiceIdentifiers.INodeTransformer, NodeTransformer.ObfuscatingGuardsTransformer); + obfuscatingGuardsTransformer = inversifyContainerFacade.getNamed( + ServiceIdentifiers.INodeTransformer, + NodeTransformer.ObfuscatingGuardsTransformer + ); }); describe('Variant #1: transform node', () => { @@ -82,8 +78,9 @@ describe('ObfuscatingGuardsTransformer', () => { ignoredNode: true }); - result = obfuscatingGuardsTransformer - .transformNode(expressionStatement, expressionStatement); + result = ( + obfuscatingGuardsTransformer.transformNode(expressionStatement, expressionStatement) + ); }); it('should add `ignoredNode` property with `true` value to given node', () => { @@ -92,7 +89,7 @@ describe('ObfuscatingGuardsTransformer', () => { }); describe('Variant #3: force transform node', () => { - const literalNode: ESTree.Literal = NodeFactory.literalNode(forceTransformString); + const literalNode: ESTree.Literal = NodeFactory.literalNode(forceTransformString); const expectedResult: ESTree.Literal = NodeUtils.clone(literalNode); @@ -107,8 +104,7 @@ describe('ObfuscatingGuardsTransformer', () => { ignoredNode: false }); - result = obfuscatingGuardsTransformer - .transformNode(literalNode, literalNode); + result = obfuscatingGuardsTransformer.transformNode(literalNode, literalNode); }); it('should add `forceTransformNode` property with `true` value to given node', () => { @@ -132,8 +128,7 @@ describe('ObfuscatingGuardsTransformer', () => { ignoredNode: false }); - result = obfuscatingGuardsTransformer - .transformNode(literalNode, literalNode); + result = obfuscatingGuardsTransformer.transformNode(literalNode, literalNode); }); it('should add correct metadata to given node', () => { diff --git a/test/unit-tests/node/node-appender/NodeAppender.spec.ts b/test/unit-tests/node/node-appender/NodeAppender.spec.ts index c0891eeb1..a4451c9d2 100644 --- a/test/unit-tests/node/node-appender/NodeAppender.spec.ts +++ b/test/unit-tests/node/node-appender/NodeAppender.spec.ts @@ -25,11 +25,7 @@ import { NodeUtils } from '../../../../src/node/NodeUtils'; * @return {TStatement[]} */ const convertCodeToStructure: (fixturePath: string) => TStatement[] = (fixturePath) => { - return removeRangesFromStructure( - NodeUtils.convertCodeToStructure( - readFileAsString(`${__dirname}${fixturePath}`) - ) - ); + return removeRangesFromStructure(NodeUtils.convertCodeToStructure(readFileAsString(`${__dirname}${fixturePath}`))); }; /** @@ -42,9 +38,7 @@ const convertCodeToAst: (fixturePath: string) => ESTree.Program = (fixturePath) describe('NodeAppender', () => { describe('append', () => { - let astTree: ESTree.Program, - expectedAstTree: ESTree.Program, - node: TStatement[]; + let astTree: ESTree.Program, expectedAstTree: ESTree.Program, node: TStatement[]; before(() => { node = convertCodeToStructure('/fixtures/simple-input.js'); @@ -73,8 +67,9 @@ describe('NodeAppender', () => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - callsGraphAnalyzer = inversifyContainerFacade - .get(ServiceIdentifiers.ICallsGraphAnalyzer); + callsGraphAnalyzer = inversifyContainerFacade.get( + ServiceIdentifiers.ICallsGraphAnalyzer + ); }); beforeEach(() => { @@ -84,7 +79,9 @@ describe('NodeAppender', () => { describe('Variant #1: nested function calls', () => { beforeEach(() => { astTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/variant-1.js'); - expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/variant-1-expected.js'); + expectedAstTree = convertCodeToAst( + '/fixtures/append-node-to-optimal-block-scope/variant-1-expected.js' + ); callsGraphData = callsGraphAnalyzer.analyze(astTree); NodeAppender.appendToOptimalBlockScope(callsGraphData, astTree, node); @@ -98,11 +95,12 @@ describe('NodeAppender', () => { describe('Variant #2: nested function calls', () => { beforeEach(() => { astTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/variant-2.js'); - expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/variant-2-expected.js'); + expectedAstTree = convertCodeToAst( + '/fixtures/append-node-to-optimal-block-scope/variant-2-expected.js' + ); callsGraphData = callsGraphAnalyzer.analyze(astTree); NodeAppender.appendToOptimalBlockScope(callsGraphData, astTree, node); - }); it('should append node into first and deepest function call in nested function calls', () => { @@ -119,11 +117,12 @@ describe('NodeAppender', () => { describe('Variant #1: append by specific index in nested function calls', () => { beforeEach(() => { - expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/by-index-variant-1-expected.js'); + expectedAstTree = convertCodeToAst( + '/fixtures/append-node-to-optimal-block-scope/by-index-variant-1-expected.js' + ); callsGraphData = callsGraphAnalyzer.analyze(astTree); NodeAppender.appendToOptimalBlockScope(callsGraphData, astTree, node, 2); - }); it('should append node into deepest function call by specified index in nested function calls', () => { @@ -133,11 +132,12 @@ describe('NodeAppender', () => { describe('Variant #2: append by specific index in nested function calls', () => { beforeEach(() => { - expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/by-index-variant-2-expected.js'); + expectedAstTree = convertCodeToAst( + '/fixtures/append-node-to-optimal-block-scope/by-index-variant-2-expected.js' + ); callsGraphData = callsGraphAnalyzer.analyze(astTree); NodeAppender.appendToOptimalBlockScope(callsGraphData, astTree, node, 1); - }); it('should append node into deepest function call by specified index in nested function calls', () => { @@ -148,16 +148,12 @@ describe('NodeAppender', () => { describe('Variant #3: append by specific index in nested function calls', () => { beforeEach(() => { astTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/by-index-variant-3.js'); - expectedAstTree = convertCodeToAst('/fixtures/append-node-to-optimal-block-scope/by-index-variant-3-expected.js'); - - callsGraphData = callsGraphAnalyzer.analyze(astTree); - NodeAppender.appendToOptimalBlockScope( - callsGraphData, - astTree, - node, - callsGraphData.length - 1 + expectedAstTree = convertCodeToAst( + '/fixtures/append-node-to-optimal-block-scope/by-index-variant-3-expected.js' ); + callsGraphData = callsGraphAnalyzer.analyze(astTree); + NodeAppender.appendToOptimalBlockScope(callsGraphData, astTree, node, callsGraphData.length - 1); }); it('should append node into deepest function call by specified index in nested function calls', () => { @@ -214,9 +210,7 @@ describe('NodeAppender', () => { }); describe('insertAtIndex', () => { - let astTree: ESTree.Program, - expectedAstTree: ESTree.Program, - node: TStatement[]; + let astTree: ESTree.Program, expectedAstTree: ESTree.Program, node: TStatement[]; before(() => { node = convertCodeToStructure('/fixtures/simple-input.js'); @@ -235,9 +229,7 @@ describe('NodeAppender', () => { }); describe('prepend', () => { - let astTree: ESTree.Program, - expectedAstTree: ESTree.Program, - node: TStatement[]; + let astTree: ESTree.Program, expectedAstTree: ESTree.Program, node: TStatement[]; before(() => { node = convertCodeToStructure('/fixtures/simple-input.js'); @@ -257,8 +249,7 @@ describe('NodeAppender', () => { describe('remove', () => { describe('Variant #1: valid index', () => { - let astTree: ESTree.Program, - expectedAstTree: ESTree.Program; + let astTree: ESTree.Program, expectedAstTree: ESTree.Program; before(() => { astTree = convertCodeToAst('/fixtures/remove-node/valid-index.js'); @@ -276,8 +267,7 @@ describe('NodeAppender', () => { }); describe('Variant #2: invalid index', () => { - let astTree: ESTree.Program, - expectedAstTree: ESTree.Program; + let astTree: ESTree.Program, expectedAstTree: ESTree.Program; before(() => { astTree = convertCodeToAst('/fixtures/remove-node/invalid-index.js'); diff --git a/test/unit-tests/node/node-guards/NodeGuards.spec.ts b/test/unit-tests/node/node-guards/NodeGuards.spec.ts index df9f82e07..00f9324d7 100644 --- a/test/unit-tests/node/node-guards/NodeGuards.spec.ts +++ b/test/unit-tests/node/node-guards/NodeGuards.spec.ts @@ -13,9 +13,7 @@ describe('NodeGuards', () => { const expectedResult: boolean = true; const node: ESTree.IfStatement = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -34,13 +32,9 @@ describe('NodeGuards', () => { const node: ESTree.IfStatement = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ]), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -58,12 +52,8 @@ describe('NodeGuards', () => { const expectedResult: boolean = true; const node: ESTree.IfStatement = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)), + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -99,15 +89,9 @@ describe('NodeGuards', () => { const node: ESTree.IfStatement = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ]), - NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) - ]) + NodeFactory.blockStatementNode([NodeFactory.expressionStatementNode(NodeFactory.literalNode(true))]) ); let result: boolean; @@ -128,11 +112,7 @@ describe('NodeGuards', () => { describe('Variant #1: block statement of function declaration', () => { const expectedResult: boolean = true; const node: ESTree.Node = NodeFactory.blockStatementNode(); - const parentNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode( - 'foo', - [], - node - ); + const parentNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode('foo', [], node); let result: boolean; @@ -149,10 +129,7 @@ describe('NodeGuards', () => { describe('Variant #2: block statement of function expression', () => { const expectedResult: boolean = true; const node: ESTree.Node = NodeFactory.blockStatementNode(); - const parentNode: ESTree.FunctionExpression = NodeFactory.functionExpressionNode( - [], - node - ); + const parentNode: ESTree.FunctionExpression = NodeFactory.functionExpressionNode([], node); let result: boolean; @@ -170,10 +147,7 @@ describe('NodeGuards', () => { describe('false checks', () => { describe('Variant #1: switch-case node', () => { const expectedResult: boolean = false; - const node: ESTree.Node = NodeFactory.switchCaseNode( - NodeFactory.literalNode(1), - [] - ); + const node: ESTree.Node = NodeFactory.switchCaseNode(NodeFactory.literalNode(1), []); const parentNode: ESTree.FunctionDeclaration = NodeFactory.functionDeclarationNode( 'foo', [], @@ -181,10 +155,7 @@ describe('NodeGuards', () => { NodeFactory.switchStatementNode( NodeFactory.memberExpressionNode( NodeFactory.identifierNode('bar'), - NodeFactory.updateExpressionNode( - '++', - NodeFactory.identifierNode('baz') - ), + NodeFactory.updateExpressionNode('++', NodeFactory.identifierNode('baz')), true ), [node] @@ -212,10 +183,7 @@ describe('NodeGuards', () => { [], NodeFactory.blockStatementNode([ NodeFactory.expressionStatementNode( - NodeFactory.callExpressionNode( - NodeFactory.identifierNode('bar'), - [node] - ) + NodeFactory.callExpressionNode(NodeFactory.identifierNode('bar'), [node]) ) ]) ); @@ -261,9 +229,7 @@ describe('NodeGuards', () => { const expectedResult: boolean = true; const node: ESTree.IfStatement = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -282,13 +248,9 @@ describe('NodeGuards', () => { const node: ESTree.IfStatement = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ]), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -306,12 +268,8 @@ describe('NodeGuards', () => { const expectedResult: boolean = true; const node: ESTree.IfStatement = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)), + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -330,23 +288,11 @@ describe('NodeGuards', () => { const expectedResult: boolean = true; const node: ESTree.ForStatement = NodeFactory.forStatementNode( NodeFactory.variableDeclarationNode([ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('i'), - NodeFactory.literalNode(0) - ) + NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('i'), NodeFactory.literalNode(0)) ]), - NodeFactory.binaryExpressionNode( - '<', - NodeFactory.identifierNode('i'), - NodeFactory.literalNode(10) - ), - NodeFactory.updateExpressionNode( - '++', - NodeFactory.identifierNode('i') - ), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.binaryExpressionNode('<', NodeFactory.identifierNode('i'), NodeFactory.literalNode(10)), + NodeFactory.updateExpressionNode('++', NodeFactory.identifierNode('i')), + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -364,17 +310,10 @@ describe('NodeGuards', () => { const expectedResult: boolean = true; const node: ESTree.ForInStatement = NodeFactory.forInStatementNode( NodeFactory.variableDeclarationNode([ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('key'), - null - ) + NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('key'), null) ]), - NodeFactory.objectExpressionNode( - [] - ), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.objectExpressionNode([]), + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -393,17 +332,10 @@ describe('NodeGuards', () => { const node: ESTree.ForOfStatement = NodeFactory.forOfStatementNode( false, NodeFactory.variableDeclarationNode([ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('key'), - null - ) + NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('key'), null) ]), - NodeFactory.objectExpressionNode( - [] - ), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.objectExpressionNode([]), + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -421,9 +353,7 @@ describe('NodeGuards', () => { const expectedResult: boolean = true; const node: ESTree.WhileStatement = NodeFactory.whileStatementNode( NodeFactory.literalNode(true), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -440,9 +370,7 @@ describe('NodeGuards', () => { describe('Variant #6: `DoWhileStatement` node', () => { const expectedResult: boolean = true; const node: ESTree.DoWhileStatement = NodeFactory.doWhileStatementNode( - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ), + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)), NodeFactory.literalNode(true) ); @@ -461,9 +389,7 @@ describe('NodeGuards', () => { const expectedResult: boolean = true; const node: ESTree.LabeledStatement = NodeFactory.labeledStatementNode( NodeFactory.identifierNode('label'), - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ); let result: boolean; @@ -485,14 +411,10 @@ describe('NodeGuards', () => { const node: ESTree.IfStatement = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ]), NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ]) ); @@ -512,25 +434,11 @@ describe('NodeGuards', () => { const expectedResult: boolean = false; const node: ESTree.ForStatement = NodeFactory.forStatementNode( NodeFactory.variableDeclarationNode([ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('i'), - NodeFactory.literalNode(0) - ) + NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('i'), NodeFactory.literalNode(0)) ]), - NodeFactory.binaryExpressionNode( - '<', - NodeFactory.identifierNode('i'), - NodeFactory.literalNode(10) - ), - NodeFactory.updateExpressionNode( - '++', - NodeFactory.identifierNode('i') - ), - NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) - ]) + NodeFactory.binaryExpressionNode('<', NodeFactory.identifierNode('i'), NodeFactory.literalNode(10)), + NodeFactory.updateExpressionNode('++', NodeFactory.identifierNode('i')), + NodeFactory.blockStatementNode([NodeFactory.expressionStatementNode(NodeFactory.literalNode(true))]) ); let result: boolean; @@ -548,19 +456,10 @@ describe('NodeGuards', () => { const expectedResult: boolean = false; const node: ESTree.ForInStatement = NodeFactory.forInStatementNode( NodeFactory.variableDeclarationNode([ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('key'), - null - ) + NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('key'), null) ]), - NodeFactory.objectExpressionNode( - [] - ), - NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) - ]) + NodeFactory.objectExpressionNode([]), + NodeFactory.blockStatementNode([NodeFactory.expressionStatementNode(NodeFactory.literalNode(true))]) ); let result: boolean; @@ -579,19 +478,10 @@ describe('NodeGuards', () => { const node: ESTree.ForOfStatement = NodeFactory.forOfStatementNode( false, NodeFactory.variableDeclarationNode([ - NodeFactory.variableDeclaratorNode( - NodeFactory.identifierNode('key'), - null - ) + NodeFactory.variableDeclaratorNode(NodeFactory.identifierNode('key'), null) ]), - NodeFactory.objectExpressionNode( - [] - ), - NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) - ]) + NodeFactory.objectExpressionNode([]), + NodeFactory.blockStatementNode([NodeFactory.expressionStatementNode(NodeFactory.literalNode(true))]) ); let result: boolean; @@ -609,11 +499,7 @@ describe('NodeGuards', () => { const expectedResult: boolean = false; const node: ESTree.WhileStatement = NodeFactory.whileStatementNode( NodeFactory.literalNode(true), - NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) - ]) + NodeFactory.blockStatementNode([NodeFactory.expressionStatementNode(NodeFactory.literalNode(true))]) ); let result: boolean; @@ -631,9 +517,7 @@ describe('NodeGuards', () => { const expectedResult: boolean = false; const node: ESTree.DoWhileStatement = NodeFactory.doWhileStatementNode( NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode(true)) ]), NodeFactory.literalNode(true) ); @@ -653,11 +537,7 @@ describe('NodeGuards', () => { const expectedResult: boolean = false; const node: ESTree.LabeledStatement = NodeFactory.labeledStatementNode( NodeFactory.identifierNode('label'), - NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode(true) - ) - ]) + NodeFactory.blockStatementNode([NodeFactory.expressionStatementNode(NodeFactory.literalNode(true))]) ); let result: boolean; @@ -723,10 +603,7 @@ describe('NodeGuards', () => { describe('Variant #4: switch case node', () => { const expectedResult: boolean = true; - const node: ESTree.Node = NodeFactory.switchCaseNode( - NodeFactory.literalNode(1), - [] - ); + const node: ESTree.Node = NodeFactory.switchCaseNode(NodeFactory.literalNode(1), []); let result: boolean; @@ -791,10 +668,7 @@ describe('NodeGuards', () => { describe('Variant #4: switch-statement node', () => { const expectedResult: boolean = false; - const node: ESTree.Node = NodeFactory.switchStatementNode( - NodeFactory.identifierNode('foo'), - [] - ); + const node: ESTree.Node = NodeFactory.switchStatementNode(NodeFactory.identifierNode('foo'), []); let result: boolean; diff --git a/test/unit-tests/node/node-lexical-scope-utils/NodeLexicalScopeUtils.spec.ts b/test/unit-tests/node/node-lexical-scope-utils/NodeLexicalScopeUtils.spec.ts index 9b1a58ead..a68024fba 100644 --- a/test/unit-tests/node/node-lexical-scope-utils/NodeLexicalScopeUtils.spec.ts +++ b/test/unit-tests/node/node-lexical-scope-utils/NodeLexicalScopeUtils.spec.ts @@ -33,9 +33,7 @@ describe('NodeLexicalScopeUtils', () => { ifStatementBlockStatementNode2 ); - ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ - ifStatementNode2 - ]); + ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ifStatementNode2]); ifStatementNode1 = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), @@ -47,11 +45,13 @@ describe('NodeLexicalScopeUtils', () => { ifStatementNode1 ]); - functionDeclarationNode = NodeFactory.functionDeclarationNode('test', [], functionDeclarationBlockStatementNode); + functionDeclarationNode = NodeFactory.functionDeclarationNode( + 'test', + [], + functionDeclarationBlockStatementNode + ); - programNode = NodeFactory.programNode([ - functionDeclarationNode - ]); + programNode = NodeFactory.programNode([functionDeclarationNode]); programNode.parentNode = programNode; functionDeclarationNode.parentNode = programNode; @@ -73,7 +73,10 @@ describe('NodeLexicalScopeUtils', () => { }); it('should return lexical scope node for `functionDeclaration blockStatement` node child node', () => { - assert.deepEqual(NodeLexicalScopeUtils.getLexicalScope(functionDeclarationBlockStatementNode), functionDeclarationNode); + assert.deepEqual( + NodeLexicalScopeUtils.getLexicalScope(functionDeclarationBlockStatementNode), + functionDeclarationNode + ); }); it('should return lexical scope node for `expressionStatement` node #1 child node', () => { @@ -85,11 +88,17 @@ describe('NodeLexicalScopeUtils', () => { }); it('should return lexical scope node for `ifStatement blockStatement` node #1 child node', () => { - assert.deepEqual(NodeLexicalScopeUtils.getLexicalScope(ifStatementBlockStatementNode1), functionDeclarationNode); + assert.deepEqual( + NodeLexicalScopeUtils.getLexicalScope(ifStatementBlockStatementNode1), + functionDeclarationNode + ); }); it('should return lexical scope node for `ifStatement blockStatement` node #2 child node', () => { - assert.deepEqual(NodeLexicalScopeUtils.getLexicalScope(ifStatementBlockStatementNode2), functionDeclarationNode); + assert.deepEqual( + NodeLexicalScopeUtils.getLexicalScope(ifStatementBlockStatementNode2), + functionDeclarationNode + ); }); it('should return lexical scope node for `expressionStatement` node #3 child node', () => { @@ -128,9 +137,7 @@ describe('NodeLexicalScopeUtils', () => { ifStatementBlockStatementNode2 ); - ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ - ifStatementNode2 - ]); + ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ifStatementNode2]); ifStatementNode1 = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), @@ -142,11 +149,13 @@ describe('NodeLexicalScopeUtils', () => { ifStatementNode1 ]); - functionDeclarationNode = NodeFactory.functionDeclarationNode('test', [], functionDeclarationBlockStatementNode); + functionDeclarationNode = NodeFactory.functionDeclarationNode( + 'test', + [], + functionDeclarationBlockStatementNode + ); - programNode = NodeFactory.programNode([ - functionDeclarationNode - ]); + programNode = NodeFactory.programNode([functionDeclarationNode]); programNode.parentNode = programNode; functionDeclarationNode.parentNode = programNode; @@ -164,7 +173,10 @@ describe('NodeLexicalScopeUtils', () => { }); it('should return lexical scope node for `functionDeclaration` node child node #1', () => { - assert.deepEqual(NodeLexicalScopeUtils.getLexicalScopes(functionDeclarationNode)[0], functionDeclarationNode); + assert.deepEqual( + NodeLexicalScopeUtils.getLexicalScopes(functionDeclarationNode)[0], + functionDeclarationNode + ); }); it('should return lexical scope node for `functionDeclaration` node child node #2', () => { @@ -172,11 +184,17 @@ describe('NodeLexicalScopeUtils', () => { }); it('should return lexical scope node for `functionDeclaration blockStatement` node child node #1', () => { - assert.deepEqual(NodeLexicalScopeUtils.getLexicalScopes(functionDeclarationBlockStatementNode)[0], functionDeclarationNode); + assert.deepEqual( + NodeLexicalScopeUtils.getLexicalScopes(functionDeclarationBlockStatementNode)[0], + functionDeclarationNode + ); }); it('should return lexical scope node for `expressionStatement` node #1 child node #1', () => { - assert.deepEqual(NodeLexicalScopeUtils.getLexicalScopes(expressionStatementNode1)[0], functionDeclarationNode); + assert.deepEqual( + NodeLexicalScopeUtils.getLexicalScopes(expressionStatementNode1)[0], + functionDeclarationNode + ); }); it('should return lexical scope node for `expressionStatement` node #1 child node #2', () => { @@ -192,7 +210,10 @@ describe('NodeLexicalScopeUtils', () => { }); it('should return lexical scope node for `ifStatement blockStatement` node #1 child node #1', () => { - assert.deepEqual(NodeLexicalScopeUtils.getLexicalScopes(ifStatementBlockStatementNode1)[0], functionDeclarationNode); + assert.deepEqual( + NodeLexicalScopeUtils.getLexicalScopes(ifStatementBlockStatementNode1)[0], + functionDeclarationNode + ); }); it('should return lexical scope node for `ifStatement blockStatement` node #1 child node #2', () => { @@ -200,7 +221,10 @@ describe('NodeLexicalScopeUtils', () => { }); it('should return lexical scope node for `ifStatement blockStatement` node #2 child node #1', () => { - assert.deepEqual(NodeLexicalScopeUtils.getLexicalScopes(ifStatementBlockStatementNode2)[0], functionDeclarationNode); + assert.deepEqual( + NodeLexicalScopeUtils.getLexicalScopes(ifStatementBlockStatementNode2)[0], + functionDeclarationNode + ); }); it('should return lexical scope node for `ifStatement blockStatement` node #1 child node #2', () => { @@ -208,7 +232,10 @@ describe('NodeLexicalScopeUtils', () => { }); it('should return lexical scope node for `expressionStatement` node #3 child node #1', () => { - assert.deepEqual(NodeLexicalScopeUtils.getLexicalScopes(expressionStatementNode3)[0], functionDeclarationNode); + assert.deepEqual( + NodeLexicalScopeUtils.getLexicalScopes(expressionStatementNode3)[0], + functionDeclarationNode + ); }); it('should return lexical scope node for `expressionStatement` node #3 child node #2', () => { diff --git a/test/unit-tests/node/node-literal-utils/NodeLiteralUtils.spec.ts b/test/unit-tests/node/node-literal-utils/NodeLiteralUtils.spec.ts index 90e0e2c48..6342bbdbd 100644 --- a/test/unit-tests/node/node-literal-utils/NodeLiteralUtils.spec.ts +++ b/test/unit-tests/node/node-literal-utils/NodeLiteralUtils.spec.ts @@ -58,9 +58,7 @@ describe('NodeLiteralUtils', () => { let statementNode: ESTree.Statement; before(() => { - statementNode = NodeFactory.expressionStatementNode( - literalNode - ); + statementNode = NodeFactory.expressionStatementNode(literalNode); literalNode.parentNode = statementNode; }); @@ -77,10 +75,7 @@ describe('NodeLiteralUtils', () => { let propertyNode: ESTree.Property; before(() => { - propertyNode = NodeFactory.propertyNode( - literalNode, - NodeFactory.literalNode(1) - ); + propertyNode = NodeFactory.propertyNode(literalNode, NodeFactory.literalNode(1)); literalNode.parentNode = propertyNode; }); @@ -96,11 +91,7 @@ describe('NodeLiteralUtils', () => { let propertyNode: ESTree.Property; before(() => { - propertyNode = NodeFactory.propertyNode( - literalNode, - NodeFactory.literalNode(1), - true - ); + propertyNode = NodeFactory.propertyNode(literalNode, NodeFactory.literalNode(1), true); literalNode.parentNode = propertyNode; }); @@ -116,10 +107,7 @@ describe('NodeLiteralUtils', () => { let propertyNode: ESTree.Property; before(() => { - propertyNode = NodeFactory.propertyNode( - NodeFactory.literalNode(1), - literalNode - ); + propertyNode = NodeFactory.propertyNode(NodeFactory.literalNode(1), literalNode); literalNode.parentNode = propertyNode; }); @@ -137,16 +125,16 @@ describe('NodeLiteralUtils', () => { let importDeclarationNode: ESTree.ImportDeclaration; before(() => { - importDeclarationNode = NodeFactory.importDeclarationNode( - [], - literalNode - ); + importDeclarationNode = NodeFactory.importDeclarationNode([], literalNode); literalNode.parentNode = importDeclarationNode; }); it('should return false for import declaration literal node', () => { - assert.equal(NodeLiteralUtils.isProhibitedLiteralNode(literalNode, importDeclarationNode), true); + assert.equal( + NodeLiteralUtils.isProhibitedLiteralNode(literalNode, importDeclarationNode), + true + ); }); }); }); @@ -158,16 +146,16 @@ describe('NodeLiteralUtils', () => { let exportNamedDeclarationNode: ESTree.ExportNamedDeclaration; before(() => { - exportNamedDeclarationNode = NodeFactory.exportNamedDeclarationNode( - [], - literalNode - ); + exportNamedDeclarationNode = NodeFactory.exportNamedDeclarationNode([], literalNode); literalNode.parentNode = exportNamedDeclarationNode; }); it('should return false for export named declaration literal node', () => { - assert.equal(NodeLiteralUtils.isProhibitedLiteralNode(literalNode, exportNamedDeclarationNode), true); + assert.equal( + NodeLiteralUtils.isProhibitedLiteralNode(literalNode, exportNamedDeclarationNode), + true + ); }); }); }); @@ -179,16 +167,16 @@ describe('NodeLiteralUtils', () => { let exportAllDeclarationNode: ESTree.ExportAllDeclaration; before(() => { - exportAllDeclarationNode = NodeFactory.exportAllDeclarationNode( - literalNode, - null - ); + exportAllDeclarationNode = NodeFactory.exportAllDeclarationNode(literalNode, null); literalNode.parentNode = exportAllDeclarationNode; }); it('should return false for export all declaration literal node', () => { - assert.equal(NodeLiteralUtils.isProhibitedLiteralNode(literalNode, exportAllDeclarationNode), true); + assert.equal( + NodeLiteralUtils.isProhibitedLiteralNode(literalNode, exportAllDeclarationNode), + true + ); }); }); }); @@ -201,13 +189,9 @@ describe('NodeLiteralUtils', () => { let statementNode: ESTree.Statement; before(() => { - statementNode = NodeFactory.expressionStatementNode( - literalNode - ); + statementNode = NodeFactory.expressionStatementNode(literalNode); - const blockStatementNode: ESTree.BlockStatement = NodeFactory.blockStatementNode([ - statementNode - ]); + const blockStatementNode: ESTree.BlockStatement = NodeFactory.blockStatementNode([statementNode]); statementNode.parentNode = blockStatementNode; literalNode.parentNode = statementNode; diff --git a/test/unit-tests/node/node-metadata/NodeMetadata.spec.ts b/test/unit-tests/node/node-metadata/NodeMetadata.spec.ts index b508077b3..d806c8fc0 100644 --- a/test/unit-tests/node/node-metadata/NodeMetadata.spec.ts +++ b/test/unit-tests/node/node-metadata/NodeMetadata.spec.ts @@ -21,7 +21,7 @@ describe('NodeMetadata', () => { NodeMetadata.set(node, { ignoredNode: true, stringArrayCallLiteralNode: true - }) + }); }); it('should set metadata to the node', () => { @@ -32,17 +32,16 @@ describe('NodeMetadata', () => { describe('get', () => { const expectedValue: boolean = true; - let node: ESTree.Literal, - value: boolean | undefined; + let node: ESTree.Literal, value: boolean | undefined; before(() => { node = NodeFactory.literalNode('foo'); node.metadata = {}; node.metadata.stringArrayCallLiteralNode = true; - value = NodeMetadata.get< - ESTree.LiteralNodeMetadata, + value = NodeMetadata.get( + node, 'stringArrayCallLiteralNode' - >(node, 'stringArrayCallLiteralNode'); + ); }); it('should get metadata value of the node', () => { @@ -53,8 +52,7 @@ describe('NodeMetadata', () => { describe('isEvalHostNode', () => { const expectedValue: boolean = true; - let node: ESTree.FunctionExpression, - value: boolean | undefined; + let node: ESTree.FunctionExpression, value: boolean | undefined; before(() => { node = NodeFactory.functionExpressionNode([], NodeFactory.blockStatementNode([])); @@ -71,8 +69,7 @@ describe('NodeMetadata', () => { describe('isForceTransformNode', () => { const expectedValue: boolean = true; - let node: ESTree.Identifier, - value: boolean | undefined; + let node: ESTree.Identifier, value: boolean | undefined; before(() => { node = NodeFactory.identifierNode('foo'); @@ -89,8 +86,7 @@ describe('NodeMetadata', () => { describe('isIgnoredNode', () => { const expectedValue: boolean = true; - let node: ESTree.Identifier, - value: boolean | undefined; + let node: ESTree.Identifier, value: boolean | undefined; before(() => { node = NodeFactory.identifierNode('foo'); @@ -107,8 +103,7 @@ describe('NodeMetadata', () => { describe('propertyKeyToRenameNode', () => { const expectedValue: boolean = true; - let node: ESTree.Identifier, - value: boolean | undefined; + let node: ESTree.Identifier, value: boolean | undefined; before(() => { node = NodeFactory.identifierNode('foo'); @@ -125,8 +120,7 @@ describe('NodeMetadata', () => { describe('isStringArrayCallLiteralNode', () => { const expectedValue: boolean = true; - let node: ESTree.Literal, - value: boolean | undefined; + let node: ESTree.Literal, value: boolean | undefined; before(() => { node = NodeFactory.literalNode('foo'); diff --git a/test/unit-tests/node/node-statement-utils/NodeStatementUtils.spec.ts b/test/unit-tests/node/node-statement-utils/NodeStatementUtils.spec.ts index 0cd09b008..5382ffe66 100644 --- a/test/unit-tests/node/node-statement-utils/NodeStatementUtils.spec.ts +++ b/test/unit-tests/node/node-statement-utils/NodeStatementUtils.spec.ts @@ -34,9 +34,7 @@ describe('NodeStatementUtils', () => { ifStatementBlockStatementNode2 ); - ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ - ifStatementNode2 - ]); + ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ifStatementNode2]); ifStatementNode1 = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), @@ -48,11 +46,13 @@ describe('NodeStatementUtils', () => { ifStatementNode1 ]); - functionDeclarationNode = NodeFactory.functionDeclarationNode('test', [], functionDeclarationBlockStatementNode); + functionDeclarationNode = NodeFactory.functionDeclarationNode( + 'test', + [], + functionDeclarationBlockStatementNode + ); - programNode = NodeFactory.programNode([ - functionDeclarationNode - ]); + programNode = NodeFactory.programNode([functionDeclarationNode]); programNode.parentNode = programNode; functionDeclarationNode.parentNode = programNode; @@ -74,31 +74,52 @@ describe('NodeStatementUtils', () => { }); it('should return parent node with statements node for `functionDeclaration blockStatement` node child node', () => { - assert.deepEqual(NodeStatementUtils.getParentNodeWithStatements(functionDeclarationBlockStatementNode), programNode); + assert.deepEqual( + NodeStatementUtils.getParentNodeWithStatements(functionDeclarationBlockStatementNode), + programNode + ); }); it('should return parent node with statements node for `expressionStatement` node #1 child node', () => { - assert.deepEqual(NodeStatementUtils.getParentNodeWithStatements(expressionStatementNode1), functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodeWithStatements(expressionStatementNode1), + functionDeclarationBlockStatementNode + ); }); it('should return parent node with statements node for `ifStatement` node child node', () => { - assert.deepEqual(NodeStatementUtils.getParentNodeWithStatements(ifStatementNode1), functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodeWithStatements(ifStatementNode1), + functionDeclarationBlockStatementNode + ); }); it('should return parent node with statements node for `ifStatement blockStatement` node #1 child node', () => { - assert.deepEqual(NodeStatementUtils.getParentNodeWithStatements(ifStatementBlockStatementNode1), functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodeWithStatements(ifStatementBlockStatementNode1), + functionDeclarationBlockStatementNode + ); }); it('should return parent node with statements node for `ifStatement blockStatement` node #2 child node', () => { - assert.deepEqual(NodeStatementUtils.getParentNodeWithStatements(ifStatementBlockStatementNode2), functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodeWithStatements(ifStatementBlockStatementNode2), + functionDeclarationBlockStatementNode + ); }); it('should return parent node with statements node for `expressionStatement` node #3 child node', () => { - assert.deepEqual(NodeStatementUtils.getParentNodeWithStatements(expressionStatementNode3), functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodeWithStatements(expressionStatementNode3), + functionDeclarationBlockStatementNode + ); }); it('should throw a `ReferenceError` if node has no `parentNode` property', () => { - assert.throws(() => NodeStatementUtils.getParentNodeWithStatements(expressionStatementNode2), ReferenceError); + assert.throws( + () => NodeStatementUtils.getParentNodeWithStatements(expressionStatementNode2), + ReferenceError + ); }); }); @@ -129,9 +150,7 @@ describe('NodeStatementUtils', () => { ifStatementBlockStatementNode2 ); - ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ - ifStatementNode2 - ]); + ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ifStatementNode2]); ifStatementNode1 = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), @@ -143,11 +162,13 @@ describe('NodeStatementUtils', () => { ifStatementNode1 ]); - functionDeclarationNode = NodeFactory.functionDeclarationNode('test', [], functionDeclarationBlockStatementNode); + functionDeclarationNode = NodeFactory.functionDeclarationNode( + 'test', + [], + functionDeclarationBlockStatementNode + ); - programNode = NodeFactory.programNode([ - functionDeclarationNode - ]); + programNode = NodeFactory.programNode([functionDeclarationNode]); programNode.parentNode = programNode; functionDeclarationNode.parentNode = programNode; @@ -169,11 +190,17 @@ describe('NodeStatementUtils', () => { }); it('should return parent node with statements node for `functionDeclaration blockStatement` node child node #1', () => { - assert.deepEqual(NodeStatementUtils.getParentNodesWithStatements(functionDeclarationBlockStatementNode)[0], programNode); + assert.deepEqual( + NodeStatementUtils.getParentNodesWithStatements(functionDeclarationBlockStatementNode)[0], + programNode + ); }); it('should return parent node with statements node for `expressionStatement` node #1 child node #1', () => { - assert.deepEqual(NodeStatementUtils.getParentNodesWithStatements(expressionStatementNode1)[0], functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodesWithStatements(expressionStatementNode1)[0], + functionDeclarationBlockStatementNode + ); }); it('should return parent node with statements node for `expressionStatement` node #1 child node #2', () => { @@ -181,7 +208,10 @@ describe('NodeStatementUtils', () => { }); it('should return parent node with statements node for `ifStatement` node child node #1', () => { - assert.deepEqual(NodeStatementUtils.getParentNodesWithStatements(ifStatementNode1)[0], functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodesWithStatements(ifStatementNode1)[0], + functionDeclarationBlockStatementNode + ); }); it('should return parent node with statements node for `ifStatement` node child node #2', () => { @@ -189,23 +219,38 @@ describe('NodeStatementUtils', () => { }); it('should return parent node with statements node for `ifStatement blockStatement` node #1 child node #1', () => { - assert.deepEqual(NodeStatementUtils.getParentNodesWithStatements(ifStatementBlockStatementNode1)[0], functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodesWithStatements(ifStatementBlockStatementNode1)[0], + functionDeclarationBlockStatementNode + ); }); it('should return parent node with statements node for `ifStatement blockStatement` node #1 child node #2', () => { - assert.deepEqual(NodeStatementUtils.getParentNodesWithStatements(ifStatementBlockStatementNode1)[1], programNode); + assert.deepEqual( + NodeStatementUtils.getParentNodesWithStatements(ifStatementBlockStatementNode1)[1], + programNode + ); }); it('should return parent node with statements node for `ifStatement blockStatement` node #2 child node #1', () => { - assert.deepEqual(NodeStatementUtils.getParentNodesWithStatements(ifStatementBlockStatementNode2)[0], functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodesWithStatements(ifStatementBlockStatementNode2)[0], + functionDeclarationBlockStatementNode + ); }); it('should return parent node with statements node for `ifStatement blockStatement` node #1 child node #2', () => { - assert.deepEqual(NodeStatementUtils.getParentNodesWithStatements(ifStatementBlockStatementNode2)[1], programNode); + assert.deepEqual( + NodeStatementUtils.getParentNodesWithStatements(ifStatementBlockStatementNode2)[1], + programNode + ); }); it('should return parent node with statements node for `expressionStatement` node #3 child node #1', () => { - assert.deepEqual(NodeStatementUtils.getParentNodesWithStatements(expressionStatementNode3)[0], functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getParentNodesWithStatements(expressionStatementNode3)[0], + functionDeclarationBlockStatementNode + ); }); it('should return parent node with statements node for `expressionStatement` node #3 child node #2', () => { @@ -213,26 +258,21 @@ describe('NodeStatementUtils', () => { }); it('should throw a `ReferenceError` if node has no `parentNode` property', () => { - assert.throws(() => NodeStatementUtils.getParentNodesWithStatements(expressionStatementNode2)[0], ReferenceError); + assert.throws( + () => NodeStatementUtils.getParentNodesWithStatements(expressionStatementNode2)[0], + ReferenceError + ); }); }); describe('getNextSiblingStatement', () => { describe('Variant #1: block statement node as scope node', () => { - let statementNode1: ESTree.Statement, - statementNode2: ESTree.Statement, - statementNode3: ESTree.Statement; + let statementNode1: ESTree.Statement, statementNode2: ESTree.Statement, statementNode3: ESTree.Statement; before(() => { - statementNode1 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('a') - ); - statementNode2 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('b') - ); - statementNode3 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('c') - ); + statementNode1 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('a')); + statementNode2 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('b')); + statementNode3 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('c')); const blockStatementNode: ESTree.BlockStatement = NodeFactory.blockStatementNode([ statementNode1, @@ -259,29 +299,18 @@ describe('NodeStatementUtils', () => { }); describe('Variant #2: switch case node as scope node', () => { - let statementNode1: ESTree.Statement, - statementNode2: ESTree.Statement, - statementNode3: ESTree.Statement; + let statementNode1: ESTree.Statement, statementNode2: ESTree.Statement, statementNode3: ESTree.Statement; before(() => { - statementNode1 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('a') - ); - statementNode2 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('b') - ); - statementNode3 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('c') - ); - - const switchCaseNode: ESTree.SwitchCase = NodeFactory.switchCaseNode( - NodeFactory.literalNode(true), - [ - statementNode1, - statementNode2, - statementNode3 - ] - ); + statementNode1 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('a')); + statementNode2 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('b')); + statementNode3 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('c')); + + const switchCaseNode: ESTree.SwitchCase = NodeFactory.switchCaseNode(NodeFactory.literalNode(true), [ + statementNode1, + statementNode2, + statementNode3 + ]); statementNode1.parentNode = switchCaseNode; statementNode2.parentNode = switchCaseNode; @@ -304,20 +333,12 @@ describe('NodeStatementUtils', () => { describe('getPreviousSiblingStatement', () => { describe('Variant #1: block statement node as scope node', () => { - let statementNode1: ESTree.Statement, - statementNode2: ESTree.Statement, - statementNode3: ESTree.Statement; + let statementNode1: ESTree.Statement, statementNode2: ESTree.Statement, statementNode3: ESTree.Statement; before(() => { - statementNode1 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('a') - ); - statementNode2 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('b') - ); - statementNode3 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('c') - ); + statementNode1 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('a')); + statementNode2 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('b')); + statementNode3 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('c')); const blockStatementNode: ESTree.BlockStatement = NodeFactory.blockStatementNode([ statementNode1, @@ -344,29 +365,18 @@ describe('NodeStatementUtils', () => { }); describe('Variant #2: switch case node as scope node', () => { - let statementNode1: ESTree.Statement, - statementNode2: ESTree.Statement, - statementNode3: ESTree.Statement; + let statementNode1: ESTree.Statement, statementNode2: ESTree.Statement, statementNode3: ESTree.Statement; before(() => { - statementNode1 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('a') - ); - statementNode2 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('b') - ); - statementNode3 = NodeFactory.expressionStatementNode( - NodeFactory.identifierNode('c') - ); - - const switchCaseNode: ESTree.SwitchCase = NodeFactory.switchCaseNode( - NodeFactory.literalNode(true), - [ - statementNode1, - statementNode2, - statementNode3 - ] - ); + statementNode1 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('a')); + statementNode2 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('b')); + statementNode3 = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('c')); + + const switchCaseNode: ESTree.SwitchCase = NodeFactory.switchCaseNode(NodeFactory.literalNode(true), [ + statementNode1, + statementNode2, + statementNode3 + ]); statementNode1.parentNode = switchCaseNode; statementNode2.parentNode = switchCaseNode; @@ -407,40 +417,30 @@ describe('NodeStatementUtils', () => { identifierNode4 = NodeFactory.identifierNode('foo'); identifierNode5 = NodeFactory.identifierNode('bar'); - assignmentExpression = NodeFactory.assignmentExpressionNode( - '=', - identifierNode4, - identifierNode5 - ); + assignmentExpression = NodeFactory.assignmentExpressionNode('=', identifierNode4, identifierNode5); - expressionStatement = NodeFactory.expressionStatementNode( - assignmentExpression - ); + expressionStatement = NodeFactory.expressionStatementNode(assignmentExpression); variableDeclarationNode = NodeFactory.variableDeclarationNode([ NodeFactory.variableDeclaratorNode( identifierNode1, - NodeFactory.binaryExpressionNode( - '+', - identifierNode2, - identifierNode3 - ) + NodeFactory.binaryExpressionNode('+', identifierNode2, identifierNode3) ) ]); - functionDeclarationBlockStatementNode = NodeFactory.blockStatementNode([ - variableDeclarationNode - ]); + functionDeclarationBlockStatementNode = NodeFactory.blockStatementNode([variableDeclarationNode]); - functionDeclarationNode = NodeFactory.functionDeclarationNode('test', [], functionDeclarationBlockStatementNode); + functionDeclarationNode = NodeFactory.functionDeclarationNode( + 'test', + [], + functionDeclarationBlockStatementNode + ); programNode = NodeFactory.programNode([ functionDeclarationNode, NodeFactory.ifStatementNode( NodeFactory.literalNode(true), - NodeFactory.blockStatementNode([ - expressionStatement - ]) + NodeFactory.blockStatementNode([expressionStatement]) ) ]); @@ -454,11 +454,17 @@ describe('NodeStatementUtils', () => { }); it('should return root statement in scope for `functionDeclaration` node #1', () => { - assert.deepEqual(NodeStatementUtils.getRootStatementOfNode(functionDeclarationNode), functionDeclarationNode); + assert.deepEqual( + NodeStatementUtils.getRootStatementOfNode(functionDeclarationNode), + functionDeclarationNode + ); }); it('should return root statement in scope for `functionDeclaration blockStatement` node #1', () => { - assert.deepEqual(NodeStatementUtils.getRootStatementOfNode(functionDeclarationBlockStatementNode), functionDeclarationNode); + assert.deepEqual( + NodeStatementUtils.getRootStatementOfNode(functionDeclarationBlockStatementNode), + functionDeclarationNode + ); }); it('should return root statement in scope for `identifier` node #1', () => { @@ -515,9 +521,7 @@ describe('NodeStatementUtils', () => { ifStatementBlockStatementNode2 = NodeFactory.blockStatementNode(); - ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ - ifStatementNode3 - ]); + ifStatementBlockStatementNode1 = NodeFactory.blockStatementNode([ifStatementNode3]); ifStatementNode2 = NodeFactory.ifStatementNode( NodeFactory.literalNode(true), @@ -529,19 +533,9 @@ describe('NodeStatementUtils', () => { ifStatementBlockStatementNode1 ); - switchCaseNode = NodeFactory.switchCaseNode( - NodeFactory.literalNode(1), - [ - ifStatementNode2 - ] - ); + switchCaseNode = NodeFactory.switchCaseNode(NodeFactory.literalNode(1), [ifStatementNode2]); - switchStatementNode = NodeFactory.switchStatementNode( - NodeFactory.literalNode(1), - [ - switchCaseNode - ] - ); + switchStatementNode = NodeFactory.switchStatementNode(NodeFactory.literalNode(1), [switchCaseNode]); functionDeclarationBlockStatementNode = NodeFactory.blockStatementNode([ expressionStatementNode1, @@ -549,11 +543,13 @@ describe('NodeStatementUtils', () => { switchStatementNode ]); - functionDeclarationNode = NodeFactory.functionDeclarationNode('test', [], functionDeclarationBlockStatementNode); + functionDeclarationNode = NodeFactory.functionDeclarationNode( + 'test', + [], + functionDeclarationBlockStatementNode + ); - programNode = NodeFactory.programNode([ - functionDeclarationNode - ]); + programNode = NodeFactory.programNode([functionDeclarationNode]); programNode.parentNode = programNode; functionDeclarationNode.parentNode = programNode; @@ -583,15 +579,24 @@ describe('NodeStatementUtils', () => { }); it('should return scope node for `expressionStatement` node #1 child node', () => { - assert.deepEqual(NodeStatementUtils.getScopeOfNode(expressionStatementNode1), functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getScopeOfNode(expressionStatementNode1), + functionDeclarationBlockStatementNode + ); }); it('should return scope node for `ifStatement` node #1 child node', () => { - assert.deepEqual(NodeStatementUtils.getScopeOfNode(ifStatementNode1), functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getScopeOfNode(ifStatementNode1), + functionDeclarationBlockStatementNode + ); }); it('should return scope node for `switchStatement` node child node', () => { - assert.deepEqual(NodeStatementUtils.getScopeOfNode(switchStatementNode), functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getScopeOfNode(switchStatementNode), + functionDeclarationBlockStatementNode + ); }); it('should return scope node for `switchCase` node child node', () => { @@ -607,15 +612,24 @@ describe('NodeStatementUtils', () => { }); it('should return scope node for `ifStatement blockStatement` node #1 child node', () => { - assert.deepEqual(NodeStatementUtils.getScopeOfNode(ifStatementBlockStatementNode1), functionDeclarationBlockStatementNode); + assert.deepEqual( + NodeStatementUtils.getScopeOfNode(ifStatementBlockStatementNode1), + functionDeclarationBlockStatementNode + ); }); it('should return scope node for `ifStatement blockStatement` node #3 child node', () => { - assert.deepEqual(NodeStatementUtils.getScopeOfNode(ifStatementBlockStatementNode3), ifStatementBlockStatementNode1); + assert.deepEqual( + NodeStatementUtils.getScopeOfNode(ifStatementBlockStatementNode3), + ifStatementBlockStatementNode1 + ); }); it('should return scope node for `expressionStatement` node #3 child node', () => { - assert.deepEqual(NodeStatementUtils.getScopeOfNode(expressionStatementNode3), ifStatementBlockStatementNode3); + assert.deepEqual( + NodeStatementUtils.getScopeOfNode(expressionStatementNode3), + ifStatementBlockStatementNode3 + ); }); it('should throw a `ReferenceError` if node has no `parentNode` property', () => { diff --git a/test/unit-tests/node/node-utils/NodeUtils.spec.ts b/test/unit-tests/node/node-utils/NodeUtils.spec.ts index 16bdb7193..a45fb7c2c 100644 --- a/test/unit-tests/node/node-utils/NodeUtils.spec.ts +++ b/test/unit-tests/node/node-utils/NodeUtils.spec.ts @@ -11,8 +11,7 @@ import { NodeUtils } from '../../../../src/node/NodeUtils'; describe('NodeUtils', () => { describe('addXVerbatimPropertyTo', () => { - let literalNode: ESTree.Literal, - expectedLiteralNode: ESTree.Literal; + let literalNode: ESTree.Literal, expectedLiteralNode: ESTree.Literal; before(() => { literalNode = NodeFactory.literalNode('value'); @@ -30,13 +29,16 @@ describe('NodeUtils', () => { describe('clone', () => { describe('Variant #1: simple AST-tree', () => { - let programNode: ESTree.Program, - expectedProgramNode: ESTree.Program; + let programNode: ESTree.Program, expectedProgramNode: ESTree.Program; before(() => { // actual AST tree - const expressionStatementNode1: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier')); - const expressionStatementNode2: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier')); + const expressionStatementNode1: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode( + NodeFactory.identifierNode('identifier') + ); + const expressionStatementNode2: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode( + NodeFactory.identifierNode('identifier') + ); const ifStatementBlockStatementNode1: ESTree.BlockStatement = NodeFactory.blockStatementNode([ expressionStatementNode1, @@ -49,8 +51,12 @@ describe('NodeUtils', () => { ); // expected AST tree - const expressionStatementNode3: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier')); - const expressionStatementNode4: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(NodeFactory.identifierNode('identifier')); + const expressionStatementNode3: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode( + NodeFactory.identifierNode('identifier') + ); + const expressionStatementNode4: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode( + NodeFactory.identifierNode('identifier') + ); const ifStatementBlockStatementNode2: ESTree.BlockStatement = NodeFactory.blockStatementNode([ expressionStatementNode3, @@ -62,16 +68,8 @@ describe('NodeUtils', () => { ifStatementBlockStatementNode2 ); - programNode = NodeUtils.clone( - NodeFactory.programNode([ - ifStatementNode1 - ]) - ); - expectedProgramNode = NodeUtils.parentizeAst( - NodeFactory.programNode([ - ifStatementNode2 - ]) - ); + programNode = NodeUtils.clone(NodeFactory.programNode([ifStatementNode1])); + expectedProgramNode = NodeUtils.parentizeAst(NodeFactory.programNode([ifStatementNode2])); }); it('should clone given AST-tree', () => { @@ -80,8 +78,7 @@ describe('NodeUtils', () => { }); describe('Variant #2: array expression with `null` element', () => { - let programNode: ESTree.Program, - expectedProgramNode: ESTree.Program; + let programNode: ESTree.Program, expectedProgramNode: ESTree.Program; before(() => { // actual AST tree @@ -91,9 +88,8 @@ describe('NodeUtils', () => { null, NodeFactory.literalNode(4) ]); - const expressionStatementNode: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode( - arrayExpressionNode - ); + const expressionStatementNode: ESTree.ExpressionStatement = + NodeFactory.expressionStatementNode(arrayExpressionNode); // expected AST tree const expectedArrayExpressionNode: ESTree.ArrayExpression = NodeFactory.arrayExpressionNode([ @@ -102,19 +98,12 @@ describe('NodeUtils', () => { null, NodeFactory.literalNode(4) ]); - const expectedExpressionStatementNode: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode( - expectedArrayExpressionNode - ); + const expectedExpressionStatementNode: ESTree.ExpressionStatement = + NodeFactory.expressionStatementNode(expectedArrayExpressionNode); - programNode = NodeUtils.clone( - NodeFactory.programNode([ - expressionStatementNode - ]) - ); + programNode = NodeUtils.clone(NodeFactory.programNode([expressionStatementNode])); expectedProgramNode = NodeUtils.parentizeAst( - NodeFactory.programNode([ - expectedExpressionStatementNode - ]) + NodeFactory.programNode([expectedExpressionStatementNode]) ); }); @@ -125,8 +114,7 @@ describe('NodeUtils', () => { }); describe('convertCodeToStructure', () => { - let structure: TStatement[], - expectedStructure: TStatement[]; + let structure: TStatement[], expectedStructure: TStatement[]; before(() => { const code: string = ` @@ -135,10 +123,13 @@ describe('NodeUtils', () => { const identifierNode: ESTree.Identifier = NodeFactory.identifierNode('abc'); const literalNode: ESTree.Literal = NodeFactory.literalNode('cde'); - const variableDeclaratorNode: ESTree.VariableDeclarator = NodeFactory - .variableDeclaratorNode(identifierNode, literalNode); - const variableDeclarationNode: ESTree.VariableDeclaration = NodeFactory - .variableDeclarationNode([variableDeclaratorNode]); + const variableDeclaratorNode: ESTree.VariableDeclarator = NodeFactory.variableDeclaratorNode( + identifierNode, + literalNode + ); + const variableDeclarationNode: ESTree.VariableDeclaration = NodeFactory.variableDeclarationNode([ + variableDeclaratorNode + ]); const programNode: ESTree.Program = NodeFactory.programNode([variableDeclarationNode]); programNode.parentNode = programNode; @@ -147,9 +138,7 @@ describe('NodeUtils', () => { identifierNode.parentNode = variableDeclaratorNode; literalNode.parentNode = variableDeclaratorNode; - structure = removeRangesFromStructure( - NodeUtils.convertCodeToStructure(code) - ); + structure = removeRangesFromStructure(NodeUtils.convertCodeToStructure(code)); expectedStructure = [variableDeclarationNode]; }); @@ -159,8 +148,7 @@ describe('NodeUtils', () => { }); describe('convertStructureToCode', () => { - let structure: ESTree.Node[], - expectedCode: string; + let structure: ESTree.Node[], expectedCode: string; before(() => { structure = [ @@ -173,7 +161,7 @@ describe('NodeUtils', () => { ]) ]) ]; - expectedCode = 'var abc = \'cde\';'; + expectedCode = "var abc = 'cde';"; }); it('should convert `ESTree.Node[]` structure to source code', () => { @@ -182,17 +170,18 @@ describe('NodeUtils', () => { }); describe('getUnaryExpressionArgumentNode', () => { - let expectedNode: ESTree.Literal, - unaryExpressionArgumentNode: ESTree.Node; + let expectedNode: ESTree.Literal, unaryExpressionArgumentNode: ESTree.Node; before(() => { const literalNode: ESTree.Literal = NodeFactory.literalNode('test'); const unaryExpressionNode2: ESTree.UnaryExpression = NodeFactory.unaryExpressionNode('!', literalNode); - const unaryExpressionNode1: ESTree.UnaryExpression = NodeFactory.unaryExpressionNode('!', unaryExpressionNode2); - const expressionStatementNode: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(unaryExpressionNode1); - const programNode: ESTree.Program = NodeFactory.programNode([ - expressionStatementNode - ]); + const unaryExpressionNode1: ESTree.UnaryExpression = NodeFactory.unaryExpressionNode( + '!', + unaryExpressionNode2 + ); + const expressionStatementNode: ESTree.ExpressionStatement = + NodeFactory.expressionStatementNode(unaryExpressionNode1); + const programNode: ESTree.Program = NodeFactory.programNode([expressionStatementNode]); programNode.parentNode = programNode; expressionStatementNode.parentNode = programNode; @@ -225,17 +214,12 @@ describe('NodeUtils', () => { expressionStatementNode2 ]); - ifStatementNode = NodeFactory.ifStatementNode( - NodeFactory.literalNode(true), - ifStatementBlockStatementNode - ); + ifStatementNode = NodeFactory.ifStatementNode(NodeFactory.literalNode(true), ifStatementBlockStatementNode); }); describe('Variant #1: parentize AST-tree with `ProgramNode` as root node', () => { beforeEach(() => { - programNode = NodeFactory.programNode([ - ifStatementNode - ]); + programNode = NodeFactory.programNode([ifStatementNode]); programNode = NodeUtils.parentizeAst(programNode); }); @@ -285,9 +269,7 @@ describe('NodeUtils', () => { describe('Variant #3: parentize AST-tree and keep root node parent node', () => { beforeEach(() => { - programNode = NodeFactory.programNode([ - ifStatementNode - ]); + programNode = NodeFactory.programNode([ifStatementNode]); ifStatementNode.parentNode = programNode; ifStatementNode = NodeUtils.parentizeAst(ifStatementNode); diff --git a/test/unit-tests/node/numerical-expression-data-to-node-converter/NumericalExpressionDataToNodeConverter.spec.ts b/test/unit-tests/node/numerical-expression-data-to-node-converter/NumericalExpressionDataToNodeConverter.spec.ts index a8a849a5d..6b9f6916f 100644 --- a/test/unit-tests/node/numerical-expression-data-to-node-converter/NumericalExpressionDataToNodeConverter.spec.ts +++ b/test/unit-tests/node/numerical-expression-data-to-node-converter/NumericalExpressionDataToNodeConverter.spec.ts @@ -12,9 +12,7 @@ import { NumericalExpressionDataToNodeConverter } from '../../../../src/node/Num describe('NumericalExpressionDataToNodeConverter', () => { describe('convertIntegerNumberData', () => { describe('Variant #1: base', () => { - const numberNumericalExpressionData: TNumberNumericalExpressionData = [ - 1, [-2, 3], 4 - ]; + const numberNumericalExpressionData: TNumberNumericalExpressionData = [1, [-2, 3], 4]; const expectedExpressionNode: ESTree.Expression = NodeFactory.binaryExpressionNode( '+', @@ -23,12 +21,9 @@ describe('NumericalExpressionDataToNodeConverter', () => { NodeFactory.literalNode(1), NodeFactory.binaryExpressionNode( '*', - NodeFactory.unaryExpressionNode( - '-', - NodeFactory.literalNode(2), - ), + NodeFactory.unaryExpressionNode('-', NodeFactory.literalNode(2)), NodeFactory.literalNode(3) - ), + ) ), NodeFactory.literalNode(4) ); @@ -43,10 +38,7 @@ describe('NumericalExpressionDataToNodeConverter', () => { return isPositiveNumber ? numberLiteralNode - : NodeFactory.unaryExpressionNode( - '-', - numberLiteralNode - ); + : NodeFactory.unaryExpressionNode('-', numberLiteralNode); } ); }); @@ -59,9 +51,7 @@ describe('NumericalExpressionDataToNodeConverter', () => { describe('convertFloatNumberData', () => { describe('Variant #1: base', () => { - const integerNumberNumericalExpressionData: TNumberNumericalExpressionData = [ - 1, [-2, 3], 4 - ]; + const integerNumberNumericalExpressionData: TNumberNumericalExpressionData = [1, [-2, 3], 4]; const decimalPart: number = 0.000000001; const expectedExpressionNode: ESTree.Expression = NodeFactory.binaryExpressionNode( @@ -73,12 +63,9 @@ describe('NumericalExpressionDataToNodeConverter', () => { NodeFactory.literalNode(1), NodeFactory.binaryExpressionNode( '*', - NodeFactory.unaryExpressionNode( - '-', - NodeFactory.literalNode(2), - ), + NodeFactory.unaryExpressionNode('-', NodeFactory.literalNode(2)), NodeFactory.literalNode(3) - ), + ) ), NodeFactory.literalNode(4) ), @@ -96,10 +83,7 @@ describe('NumericalExpressionDataToNodeConverter', () => { return isPositiveNumber ? numberLiteralNode - : NodeFactory.unaryExpressionNode( - '-', - numberLiteralNode - ); + : NodeFactory.unaryExpressionNode('-', numberLiteralNode); } ); }); diff --git a/test/unit-tests/options/ValidationErrorsFormatter.spec.ts b/test/unit-tests/options/ValidationErrorsFormatter.spec.ts index a7845c5c4..8ecca25c0 100644 --- a/test/unit-tests/options/ValidationErrorsFormatter.spec.ts +++ b/test/unit-tests/options/ValidationErrorsFormatter.spec.ts @@ -9,15 +9,17 @@ describe('ValidationErrorsFormatter', () => { describe('Variant #1: one constraint group with one constraint', () => { const constraintGroupRegExp: RegExp = /`foo` *errors:/; const constraintRegExp: RegExp = /(?: *-)+ *constraint *text/; - const validationErrors: ValidationError[] = [{ - target: {}, - property: 'foo', - value: null, - constraints: { - 'constraint1': '- constraint text' - }, - children: [] - }]; + const validationErrors: ValidationError[] = [ + { + target: {}, + property: 'foo', + value: null, + constraints: { + constraint1: '- constraint text' + }, + children: [] + } + ]; let validationError: string; @@ -38,16 +40,18 @@ describe('ValidationErrorsFormatter', () => { const constraintGroupRegExp: RegExp = /`foo` *errors:/; const constraintRegExp1: RegExp = /(?: *-)+ constraint *text *#1/; const constraintRegExp2: RegExp = /(?: *-)+ constraint *text *#2/; - const validationErrors: ValidationError[] = [{ - target: {}, - property: 'foo', - value: null, - constraints: { - 'constraint1': '- constraint text #1', - 'constraint2': '- constraint text #2' - }, - children: [] - }]; + const validationErrors: ValidationError[] = [ + { + target: {}, + property: 'foo', + value: null, + constraints: { + constraint1: '- constraint text #1', + constraint2: '- constraint text #2' + }, + children: [] + } + ]; let validationError: string; @@ -70,12 +74,14 @@ describe('ValidationErrorsFormatter', () => { describe('Variant #3: one constraint group without constraints', () => { const constraintGroupRegExp: RegExp = /`foo` *error/; - const validationErrors: ValidationError[] = [{ - target: {}, - property: 'foo', - value: null, - children: [] - }]; + const validationErrors: ValidationError[] = [ + { + target: {}, + property: 'foo', + value: null, + children: [] + } + ]; let validationError: string; @@ -89,30 +95,34 @@ describe('ValidationErrorsFormatter', () => { }); describe('Variant #4: two constraint groups', () => { - const regExpMatch: string = `` + + const regExpMatch: string = + `` + `\`foo\` *errors:\\n` + - `(?: *-)+ *constraint *group *#1 *text\\n+` + + `(?: *-)+ *constraint *group *#1 *text\\n+` + `\`bar\` *errors:\\n` + - `(?: *-)+ *constraint *group *#2 *text\\n+` + - ``; + `(?: *-)+ *constraint *group *#2 *text\\n+` + + ``; const regExp: RegExp = new RegExp(regExpMatch); - const validationErrors: ValidationError[] = [{ - target: {}, - property: 'foo', - value: null, - constraints: { - 'constraint': '- constraint group #1 text' - }, - children: [] - }, { - target: {}, - property: 'bar', - value: null, - constraints: { - 'constraint': '- constraint group #2 text' + const validationErrors: ValidationError[] = [ + { + target: {}, + property: 'foo', + value: null, + constraints: { + constraint: '- constraint group #1 text' + }, + children: [] }, - children: [] - }]; + { + target: {}, + property: 'bar', + value: null, + constraints: { + constraint: '- constraint group #2 text' + }, + children: [] + } + ]; let validationError: string; diff --git a/test/unit-tests/source-code/ObfuscationResult.spec.ts b/test/unit-tests/source-code/ObfuscationResult.spec.ts index da93d6ae8..f25411cf6 100644 --- a/test/unit-tests/source-code/ObfuscationResult.spec.ts +++ b/test/unit-tests/source-code/ObfuscationResult.spec.ts @@ -22,23 +22,17 @@ import { InversifyContainerFacade } from '../../../src/container/InversifyContai * @param {TInputOptions} options * @returns {IObfuscationResult} */ -function getObfuscationResult ( - rawObfuscatedCode: string, - options: TInputOptions -): IObfuscationResult { +function getObfuscationResult(rawObfuscatedCode: string, options: TInputOptions): IObfuscationResult { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); - inversifyContainerFacade.load( - '', - '', - { - ...DEFAULT_PRESET, - ...options - } - ); + inversifyContainerFacade.load('', '', { + ...DEFAULT_PRESET, + ...options + }); - const obfuscationResult: IObfuscationResult = inversifyContainerFacade - .get(ServiceIdentifiers.IObfuscationResult); + const obfuscationResult: IObfuscationResult = inversifyContainerFacade.get( + ServiceIdentifiers.IObfuscationResult + ); obfuscationResult.initialize(rawObfuscatedCode, ''); @@ -52,7 +46,7 @@ function getObfuscationResult ( * @param sourceMapFileName * @param sourceMapMode */ -function getSourceMapObfuscationResult ( +function getSourceMapObfuscationResult( rawObfuscatedCode: string, sourceMap: string, sourceMapBaseUrl: string, @@ -61,20 +55,17 @@ function getSourceMapObfuscationResult ( ): IObfuscationResult { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); - inversifyContainerFacade.load( - '', - '', - { - ...DEFAULT_PRESET, - sourceMap: true, - sourceMapBaseUrl, - sourceMapFileName, - sourceMapMode - } - ); + inversifyContainerFacade.load('', '', { + ...DEFAULT_PRESET, + sourceMap: true, + sourceMapBaseUrl, + sourceMapFileName, + sourceMapMode + }); - const obfuscationResult: IObfuscationResult = inversifyContainerFacade - .get(ServiceIdentifiers.IObfuscationResult); + const obfuscationResult: IObfuscationResult = inversifyContainerFacade.get( + ServiceIdentifiers.IObfuscationResult + ); obfuscationResult.initialize(rawObfuscatedCode, sourceMap); @@ -106,7 +97,7 @@ describe('ObfuscatedCode', () => { describe('getObfuscatedCode', () => { let obfuscatedCode: string; - describe('source map doest\'t exist', () => { + describe("source map doest't exist", () => { before(() => { obfuscatedCode = getSourceMapObfuscationResult( expectedObfuscatedCode, @@ -184,12 +175,9 @@ describe('ObfuscatedCode', () => { let options: IOptions; before(() => { - options = getObfuscationResult( - expectedObfuscatedCode, - { - seed - } - ).getOptions(); + options = getObfuscationResult(expectedObfuscatedCode, { + seed + }).getOptions(); }); it('should return options object', () => { diff --git a/test/unit-tests/storages/ArrayStorage.spec.ts b/test/unit-tests/storages/ArrayStorage.spec.ts index e22107d98..693b5645e 100644 --- a/test/unit-tests/storages/ArrayStorage.spec.ts +++ b/test/unit-tests/storages/ArrayStorage.spec.ts @@ -9,12 +9,11 @@ import { IInversifyContainerFacade } from '../../../src/interfaces/container/IIn import { IOptions } from '../../../src/interfaces/options/IOptions'; import { IRandomGenerator } from '../../../src/interfaces/utils/IRandomGenerator'; - import { ArrayStorage } from '../../../src/storages/ArrayStorage'; import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade'; -class ConcreteStorage extends ArrayStorage { - constructor () { +class ConcreteStorage extends ArrayStorage { + constructor() { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); @@ -29,8 +28,8 @@ class ConcreteStorage extends ArrayStorage { /** * @returns {IArrayStorage} */ -const getStorageInstance = (): IArrayStorage => { - const storage: IArrayStorage = new ConcreteStorage (); +const getStorageInstance = (): IArrayStorage => { + const storage: IArrayStorage = new ConcreteStorage(); storage.initialize(); @@ -41,7 +40,7 @@ describe('ArrayStorage', () => { const storageKey: number = 0; const storageValue: string = 'foo'; - let storage: IArrayStorage ; + let storage: IArrayStorage; describe('initialize', () => { const expectedError: ErrorConstructor = Error; @@ -53,7 +52,7 @@ describe('ArrayStorage', () => { testFunc = () => storage.set(storageKey, storageValue); }); - it('should throws an error when storage isn\'t initialized', () => { + it("should throws an error when storage isn't initialized", () => { assert.throws(testFunc, expectedError); }); }); @@ -109,7 +108,7 @@ describe('ArrayStorage', () => { }); }); - describe('Variant #2: value isn\'t exist', () => { + describe("Variant #2: value isn't exist", () => { const expectedValue: undefined = undefined; let value: string; @@ -144,7 +143,7 @@ describe('ArrayStorage', () => { }); }); - describe('Variant #2: value isn\'t exist', () => { + describe("Variant #2: value isn't exist", () => { const expectedError: ErrorConstructor = Error; let testFunc: () => void; @@ -221,7 +220,7 @@ describe('ArrayStorage', () => { storage = getStorageInstance(); storage.set(storageKey, object); - key = storage.getKeyOf({...object}); + key = storage.getKeyOf({ ...object }); }); it('should return `null` if objects in `set` and `get` are two different objects', () => { @@ -247,10 +246,7 @@ describe('ArrayStorage', () => { describe('delete', () => { describe('Variant #1: value exist', () => { - const expectedUpdatedStorage: string[] = [ - 'foo', - 'baz' - ]; + const expectedUpdatedStorage: string[] = ['foo', 'baz']; const expectedUpdatedStorageLength: number = 2; const expectedDeletedValue: string = 'bar'; @@ -282,12 +278,8 @@ describe('ArrayStorage', () => { }); }); - describe('Variant #2: value isn\'t exist', () => { - const expectedUpdatedStorage: string[] = [ - 'foo', - 'bar', - 'baz' - ]; + describe("Variant #2: value isn't exist", () => { + const expectedUpdatedStorage: string[] = ['foo', 'bar', 'baz']; const expectedUpdatedStorageLength: number = 3; const expectedDeletedValue: undefined = undefined; @@ -333,7 +325,7 @@ describe('ArrayStorage', () => { storage = getStorageInstance(); storage.set(storageKey, storageValue); - const secondStorage: IArrayStorage = getStorageInstance(); + const secondStorage: IArrayStorage = getStorageInstance(); secondStorage.set(secondStorageKey, secondStorageValue); storage.mergeWith(secondStorage, false); @@ -360,7 +352,7 @@ describe('ArrayStorage', () => { storage = getStorageInstance(); storage.set(storageKey, storageValue); - const secondStorage: IArrayStorage = getStorageInstance(); + const secondStorage: IArrayStorage = getStorageInstance(); expectedStorageId = secondStorage.getStorageId(); secondStorage.set(secondStorageKey, secondStorageValue); diff --git a/test/unit-tests/storages/MapStorage.spec.ts b/test/unit-tests/storages/MapStorage.spec.ts index 96e2a79c6..94a8c938b 100644 --- a/test/unit-tests/storages/MapStorage.spec.ts +++ b/test/unit-tests/storages/MapStorage.spec.ts @@ -14,8 +14,8 @@ import { IRandomGenerator } from '../../../src/interfaces/utils/IRandomGenerator import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade'; import { MapStorage } from '../../../src/storages/MapStorage'; -class ConcreteStorage extends MapStorage { - constructor () { +class ConcreteStorage extends MapStorage { + constructor() { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); @@ -30,8 +30,8 @@ class ConcreteStorage extends MapStorage { /** * @returns {IMapStorage} */ -const getStorageInstance = (): IMapStorage => { - const storage: IMapStorage = new ConcreteStorage (); +const getStorageInstance = (): IMapStorage => { + const storage: IMapStorage = new ConcreteStorage(); storage.initialize(); @@ -42,7 +42,7 @@ describe('MapStorage', () => { const storageKey: string = 'foo'; const storageValue: string = 'bar'; - let storage: IMapStorage ; + let storage: IMapStorage; describe('initialize', () => { const expectedError: ErrorConstructor = Error; @@ -54,7 +54,7 @@ describe('MapStorage', () => { testFunc = () => storage.set(storageKey, storageValue); }); - it('should throws an error when storage isn\'t initialized', () => { + it("should throws an error when storage isn't initialized", () => { assert.throws(testFunc, expectedError); }); }); @@ -62,7 +62,7 @@ describe('MapStorage', () => { describe('getStorage', () => { const expectedInstanceOf: MapConstructor = Map; - let mapStorage: Map ; + let mapStorage: Map; before(() => { storage = getStorageInstance(); @@ -93,7 +93,7 @@ describe('MapStorage', () => { }); }); - describe('Variant #2: value isn\'t exist', () => { + describe("Variant #2: value isn't exist", () => { const expectedValue: undefined = undefined; let value: string; @@ -128,7 +128,7 @@ describe('MapStorage', () => { }); }); - describe('Variant #2: value isn\'t exist', () => { + describe("Variant #2: value isn't exist", () => { const expectedError: ErrorConstructor = Error; let testFunc: () => void; @@ -205,7 +205,7 @@ describe('MapStorage', () => { storage = getStorageInstance(); storage.set(storageKey, object); - key = storage.getKeyOf({...object}); + key = storage.getKeyOf({ ...object }); }); it('should return `null` if objects in `set` and `get` are two different objects', () => { @@ -251,7 +251,7 @@ describe('MapStorage', () => { }); }); - describe('Variant #2: item isn\'t presenting in storage', () => { + describe("Variant #2: item isn't presenting in storage", () => { const expectedItemExistence: boolean = false; let itemExistence: boolean; @@ -262,7 +262,7 @@ describe('MapStorage', () => { itemExistence = storage.has(storageKey); }); - it('should return `false` if item isn\'t presenting in storage', () => { + it("should return `false` if item isn't presenting in storage", () => { assert.equal(itemExistence, expectedItemExistence); }); }); @@ -298,7 +298,7 @@ describe('MapStorage', () => { storage = getStorageInstance(); storage.set(storageKey, storageValue); - const secondStorage: IMapStorage = getStorageInstance(); + const secondStorage: IMapStorage = getStorageInstance(); secondStorage.set(secondStorageKey, secondStorageValue); storage.mergeWith(secondStorage, false); diff --git a/test/unit-tests/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.spec.ts b/test/unit-tests/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.spec.ts index 2177b78d7..7eedcedda 100644 --- a/test/unit-tests/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.spec.ts +++ b/test/unit-tests/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.spec.ts @@ -23,11 +23,11 @@ const getStorageInstance = (options: Partial = DEFAULT_PRESET): IGl const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - const storage: IGlobalIdentifierNamesCacheStorage = new GlobalIdentifierNamesCacheStorage ( + const storage: IGlobalIdentifierNamesCacheStorage = new GlobalIdentifierNamesCacheStorage( inversifyContainerFacade.get(ServiceIdentifiers.IRandomGenerator), { ...DEFAULT_PRESET, - ...options as IOptions + ...(options as IOptions) } ); diff --git a/test/unit-tests/storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage.spec.ts b/test/unit-tests/storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage.spec.ts index 1e24553c0..9b8e0d48c 100644 --- a/test/unit-tests/storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage.spec.ts +++ b/test/unit-tests/storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage.spec.ts @@ -27,7 +27,7 @@ const getStorageInstance = (options: Partial = DEFAULT_PRESET): IPr inversifyContainerFacade.get(ServiceIdentifiers.IRandomGenerator), { ...DEFAULT_PRESET, - ...options as IOptions + ...(options as IOptions) } ); diff --git a/test/unit-tests/storages/string-array-transformers/literal-nodes-cache/LiteralNodesCacheStorage.spec.ts b/test/unit-tests/storages/string-array-transformers/literal-nodes-cache/LiteralNodesCacheStorage.spec.ts index 42dc9188c..ef8d2b8f4 100644 --- a/test/unit-tests/storages/string-array-transformers/literal-nodes-cache/LiteralNodesCacheStorage.spec.ts +++ b/test/unit-tests/storages/string-array-transformers/literal-nodes-cache/LiteralNodesCacheStorage.spec.ts @@ -28,7 +28,9 @@ const getStorageInstance = (options: TInputOptions = {}): ILiteralNodesCacheStor ...options }); - const storage: ILiteralNodesCacheStorage = inversifyContainerFacade.get(ServiceIdentifiers.ILiteralNodesCacheStorage); + const storage: ILiteralNodesCacheStorage = inversifyContainerFacade.get( + ServiceIdentifiers.ILiteralNodesCacheStorage + ); storage.initialize(); @@ -39,21 +41,18 @@ describe('LiteralNodesCacheStorage', () => { describe('buildKey', () => { const expectedCacheKey: string = 'foo-true'; - let cacheKey: string; + let cacheKey: string; before(() => { const literalNodesCacheStorage: ILiteralNodesCacheStorage = getStorageInstance(); - cacheKey = literalNodesCacheStorage.buildKey( - 'foo', - { - index: 1, - value: '_0x123abc', - encoding: StringArrayEncoding.Rc4, - encodedValue: 'encoded_value', - decodeKey: 'key' - } - ); + cacheKey = literalNodesCacheStorage.buildKey('foo', { + index: 1, + value: '_0x123abc', + encoding: StringArrayEncoding.Rc4, + encodedValue: 'encoded_value', + decodeKey: 'key' + }); }); it('should build a key for the storage', () => { @@ -62,7 +61,7 @@ describe('LiteralNodesCacheStorage', () => { }); describe('shouldUseCachedValue', () => { - const literalNode: ESTree.Literal = NodeFactory.literalNode('foo'); + const literalNode: ESTree.Literal = NodeFactory.literalNode('foo'); const key: string = 'key'; describe('Encoding is not `rc4` and `stringArrayWrappersCount` option is disabled', () => { @@ -77,16 +76,13 @@ describe('LiteralNodesCacheStorage', () => { literalNodesCacheStorage.set(key, literalNode); - result = literalNodesCacheStorage.shouldUseCachedValue( - key, - { - index: 1, - value: '_0x123abc', - encoding: StringArrayEncoding.Base64, - encodedValue: 'encoded_value', - decodeKey: 'key' - }, - ); + result = literalNodesCacheStorage.shouldUseCachedValue(key, { + index: 1, + value: '_0x123abc', + encoding: StringArrayEncoding.Base64, + encodedValue: 'encoded_value', + decodeKey: 'key' + }); }); it('should check if can use cached value', () => { @@ -95,7 +91,7 @@ describe('LiteralNodesCacheStorage', () => { }); describe('Encoding is `rc4` and `stringArrayWrappersCount` option is disabled', () => { - const expectedResult: boolean = false + const expectedResult: boolean = false; let result: boolean; @@ -106,16 +102,13 @@ describe('LiteralNodesCacheStorage', () => { literalNodesCacheStorage.set(key, literalNode); - result = literalNodesCacheStorage.shouldUseCachedValue( - key, - { - index: 1, - value: '_0x123abc', - encoding: StringArrayEncoding.Rc4, - encodedValue: 'encoded_value', - decodeKey: 'key' - }, - ); + result = literalNodesCacheStorage.shouldUseCachedValue(key, { + index: 1, + value: '_0x123abc', + encoding: StringArrayEncoding.Rc4, + encodedValue: 'encoded_value', + decodeKey: 'key' + }); }); it('should check if can use cached value', () => { @@ -137,16 +130,13 @@ describe('LiteralNodesCacheStorage', () => { literalNodesCacheStorage.set(key, literalNode); - result = literalNodesCacheStorage.shouldUseCachedValue( - key, - { - index: 1, - value: '_0x123abc', - encoding: StringArrayEncoding.Base64, - encodedValue: 'encoded_value', - decodeKey: 'key' - }, - ); + result = literalNodesCacheStorage.shouldUseCachedValue(key, { + index: 1, + value: '_0x123abc', + encoding: StringArrayEncoding.Base64, + encodedValue: 'encoded_value', + decodeKey: 'key' + }); }); it('should check if can use cached value', () => { diff --git a/test/unit-tests/storages/string-array-transformers/string-array/StringArrayStorage.spec.ts b/test/unit-tests/storages/string-array-transformers/string-array/StringArrayStorage.spec.ts index 9877d2961..76a0b1a07 100644 --- a/test/unit-tests/storages/string-array-transformers/string-array/StringArrayStorage.spec.ts +++ b/test/unit-tests/storages/string-array-transformers/string-array/StringArrayStorage.spec.ts @@ -41,10 +41,7 @@ const getStringArrayStorageItemData = ( value: string, decodeKeys: string[] ): IStringArrayStorageItemData | undefined => { - (stringArrayStorage).rc4Keys = [ - 'foo', - ...decodeKeys - ]; + (stringArrayStorage).rc4Keys = ['foo', ...decodeKeys]; return stringArrayStorage.get(value); }; @@ -61,8 +58,10 @@ describe('StringArrayStorage', () => { }); for (let i = 0; i < samplesCount; i++) { - const {encodedValue: firstEncodedValue} = getStringArrayStorageItemData(stringArrayStorage, '_15', ['CRDL']) || {}; - const {encodedValue: secondEncodedValue} = getStringArrayStorageItemData(stringArrayStorage, '_12', ['q9mB']) || {}; + const { encodedValue: firstEncodedValue } = + getStringArrayStorageItemData(stringArrayStorage, '_15', ['CRDL']) || {}; + const { encodedValue: secondEncodedValue } = + getStringArrayStorageItemData(stringArrayStorage, '_12', ['q9mB']) || {}; if (firstEncodedValue === secondEncodedValue) { isCollisionHappened = true; @@ -83,25 +82,18 @@ describe('StringArrayStorage', () => { before(() => { const stringArrayStorage: IStringArrayStorage = getStorageInstance({ - stringArrayEncoding: [ - StringArrayEncoding.Base64, - StringArrayEncoding.Rc4 - ] + stringArrayEncoding: [StringArrayEncoding.Base64, StringArrayEncoding.Rc4] }); for (let i = 0; i < samplesCount; i++) { - const { - encodedValue: firstEncodedValue, - encoding: firstEncodedValueEncoding - } = getStringArrayStorageItemData(stringArrayStorage, 'zxL', ['&Jfx', '[lR4']) || {}; - const { - encodedValue: secondEncodedValue, - encoding: secondEncodedValueEncoding - } = getStringArrayStorageItemData(stringArrayStorage, 'omC', ['&Jfx', '[lR4']) || {}; + const { encodedValue: firstEncodedValue, encoding: firstEncodedValueEncoding } = + getStringArrayStorageItemData(stringArrayStorage, 'zxL', ['&Jfx', '[lR4']) || {}; + const { encodedValue: secondEncodedValue, encoding: secondEncodedValueEncoding } = + getStringArrayStorageItemData(stringArrayStorage, 'omC', ['&Jfx', '[lR4']) || {}; if ( - firstEncodedValue === secondEncodedValue - && firstEncodedValueEncoding === secondEncodedValueEncoding + firstEncodedValue === secondEncodedValue && + firstEncodedValueEncoding === secondEncodedValueEncoding ) { isCollisionHappened = true; break; diff --git a/test/unit-tests/storages/string-array-transformers/visited-lexical-scope-nodes-stack/VisitedLexicalScopeNodesStackStorage.spec.ts b/test/unit-tests/storages/string-array-transformers/visited-lexical-scope-nodes-stack/VisitedLexicalScopeNodesStackStorage.spec.ts index 8ce326c85..bea1a7397 100644 --- a/test/unit-tests/storages/string-array-transformers/visited-lexical-scope-nodes-stack/VisitedLexicalScopeNodesStackStorage.spec.ts +++ b/test/unit-tests/storages/string-array-transformers/visited-lexical-scope-nodes-stack/VisitedLexicalScopeNodesStackStorage.spec.ts @@ -26,7 +26,9 @@ const getStorageInstance = (options: TInputOptions = {}): IVisitedLexicalScopeNo ...options }); - const storage: IVisitedLexicalScopeNodesStackStorage = inversifyContainerFacade.get(ServiceIdentifiers.IVisitedLexicalScopeNodesStackStorage); + const storage: IVisitedLexicalScopeNodesStackStorage = inversifyContainerFacade.get( + ServiceIdentifiers.IVisitedLexicalScopeNodesStackStorage + ); storage.initialize(); @@ -36,22 +38,16 @@ const getStorageInstance = (options: TInputOptions = {}): IVisitedLexicalScopeNo describe('VisitedLexicalScopeNodesStackStorage', () => { describe('getLastElement', () => { const firstElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('first') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('first')) ]); const secondElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('second') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('second')) ]); - const expectedLastElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('last') - ) + const expectedLastElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ + NodeFactory.expressionStatementNode(NodeFactory.literalNode('last')) ]); - let lastElement: TNodeWithLexicalScopeStatements | undefined; + let lastElement: TNodeWithLexicalScopeStatements | undefined; before(() => { const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = getStorageInstance(); @@ -70,25 +66,20 @@ describe('VisitedLexicalScopeNodesStackStorage', () => { describe('getPenultimateElement', () => { describe('Variant #1: three array elements', () => { const firstElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('first') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('first')) ]); const expectedSecondElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('second') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('second')) ]); - const lastElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('last') - ) + const lastElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ + NodeFactory.expressionStatementNode(NodeFactory.literalNode('last')) ]); let penultimateElement: TNodeWithLexicalScopeStatements | undefined; before(() => { - const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = getStorageInstance(); + const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = + getStorageInstance(); visitedLexicalScopeNodesStackStorage.push(firstElement); visitedLexicalScopeNodesStackStorage.push(expectedSecondElement); @@ -104,15 +95,14 @@ describe('VisitedLexicalScopeNodesStackStorage', () => { describe('Variant #2: one array element', () => { const expectedPenultimateElement: undefined = undefined; const firstElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('first') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('first')) ]); let penultimateElement: TNodeWithLexicalScopeStatements | undefined; before(() => { - const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = getStorageInstance(); + const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = + getStorageInstance(); visitedLexicalScopeNodesStackStorage.push(firstElement); penultimateElement = visitedLexicalScopeNodesStackStorage.getPenultimateElement(); @@ -129,7 +119,8 @@ describe('VisitedLexicalScopeNodesStackStorage', () => { let penultimateElement: TNodeWithLexicalScopeStatements | undefined; before(() => { - const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = getStorageInstance(); + const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = + getStorageInstance(); penultimateElement = visitedLexicalScopeNodesStackStorage.getPenultimateElement(); }); @@ -142,19 +133,12 @@ describe('VisitedLexicalScopeNodesStackStorage', () => { describe('push', () => { const firstElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('first') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('first')) ]); const secondElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('second') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('second')) ]); - const expectedStorage: TNodeWithLexicalScopeStatements[] = [ - firstElement, - secondElement - ]; + const expectedStorage: TNodeWithLexicalScopeStatements[] = [firstElement, secondElement]; let storage: TNodeWithLexicalScopeStatements[]; @@ -174,25 +158,20 @@ describe('VisitedLexicalScopeNodesStackStorage', () => { describe('pop', () => { describe('Variant #1: few elements', () => { const firstElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('first') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('first')) ]); const secondElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('second') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('second')) ]); - const expectedStorage: TNodeWithLexicalScopeStatements[] = [ - firstElement - ]; + const expectedStorage: TNodeWithLexicalScopeStatements[] = [firstElement]; const expectedPoppedElement: TNodeWithLexicalScopeStatements = secondElement; let storage: TNodeWithLexicalScopeStatements[]; let poppedElement: TNodeWithLexicalScopeStatements | undefined; before(() => { - const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = getStorageInstance(); + const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = + getStorageInstance(); visitedLexicalScopeNodesStackStorage.push(firstElement); visitedLexicalScopeNodesStackStorage.push(secondElement); @@ -212,9 +191,7 @@ describe('VisitedLexicalScopeNodesStackStorage', () => { describe('Variant #2: single element', () => { const firstElement: TNodeWithLexicalScopeStatements = NodeFactory.blockStatementNode([ - NodeFactory.expressionStatementNode( - NodeFactory.literalNode('first') - ) + NodeFactory.expressionStatementNode(NodeFactory.literalNode('first')) ]); const expectedStorage: TNodeWithLexicalScopeStatements[] = []; const expectedPoppedElement: TNodeWithLexicalScopeStatements = firstElement; @@ -223,7 +200,8 @@ describe('VisitedLexicalScopeNodesStackStorage', () => { let poppedElement: TNodeWithLexicalScopeStatements | undefined; before(() => { - const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = getStorageInstance(); + const visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage = + getStorageInstance(); visitedLexicalScopeNodesStackStorage.push(firstElement); diff --git a/test/unit-tests/utils/ArrayUtils.spec.ts b/test/unit-tests/utils/ArrayUtils.spec.ts index 0d8d14194..a62cc0319 100644 --- a/test/unit-tests/utils/ArrayUtils.spec.ts +++ b/test/unit-tests/utils/ArrayUtils.spec.ts @@ -71,13 +71,7 @@ describe('ArrayUtils', () => { describe('range length more than 0', () => { const rangeLength: number = 5; - const expectedArray: string[] = [ - 'foo0', - 'foo1', - 'foo2', - 'foo3', - 'foo4', - ]; + const expectedArray: string[] = ['foo0', 'foo1', 'foo2', 'foo3', 'foo4']; let array: string[]; @@ -278,8 +272,7 @@ describe('ArrayUtils', () => { }); describe('rotate', () => { - let array: number[], - rotatedArray: number[]; + let array: number[], rotatedArray: number[]; beforeEach(() => { array = [1, 2, 3, 4, 5, 6]; @@ -306,7 +299,7 @@ describe('ArrayUtils', () => { rotatedArray = arrayUtils.rotate(array, rotateValue); }); - it('shouldn\'t rotate array', () => { + it("shouldn't rotate array", () => { assert.deepEqual(rotatedArray, expectedArray); }); }); diff --git a/test/unit-tests/utils/CryptUtils.spec.ts b/test/unit-tests/utils/CryptUtils.spec.ts index edc2cb604..a4364d590 100644 --- a/test/unit-tests/utils/CryptUtils.spec.ts +++ b/test/unit-tests/utils/CryptUtils.spec.ts @@ -21,33 +21,31 @@ describe('CryptUtils', () => { }); describe('btoa', () => { - describe('Variant #1: basic', () => { - const expectedEncodedString: string = 'c3RyaW5n'; - const expectedDecodedString: string = 'string'; + describe('Variant #1: basic', () => { + const expectedEncodedString: string = 'c3RyaW5n'; + const expectedDecodedString: string = 'string'; - let encodedString: string, - decodedString: string; + let encodedString: string, decodedString: string; - before(() => { - encodedString = cryptUtils.btoa('string'); - decodedString = atob(encodedString); - }); + before(() => { + encodedString = cryptUtils.btoa('string'); + decodedString = atob(encodedString); + }); - it('should create a base-64 encoded string from a given string', () => { - assert.equal(encodedString, expectedEncodedString); - }); + it('should create a base-64 encoded string from a given string', () => { + assert.equal(encodedString, expectedEncodedString); + }); - it('should create encoded string that can be successfully decoded', () => { - assert.equal(decodedString, expectedDecodedString); - }); - }); + it('should create encoded string that can be successfully decoded', () => { + assert.equal(decodedString, expectedDecodedString); + }); + }); describe('Variant #2: padding characters', () => { const expectedEncodedString: string = 'c3RyaQ=='; const expectedDecodedString: string = 'stri'; - let encodedString: string, - decodedString: string; + let encodedString: string, decodedString: string; before(() => { encodedString = cryptUtils.btoa('stri'); @@ -67,8 +65,7 @@ describe('CryptUtils', () => { const expectedEncodedString: string = '0YLQtdGB0YI='; const expectedDecodedString: string = 'тест'; - let encodedString: string, - decodedString: string; + let encodedString: string, decodedString: string; before(() => { encodedString = cryptUtils.btoa('тест'); @@ -89,16 +86,14 @@ describe('CryptUtils', () => { const originalString: string = 'example.com'; const hiddenStringLength: number = 30; - let hiddenString: string, - diffString: string; + let hiddenString: string, diffString: string; before(() => { [hiddenString, diffString] = cryptUtils.hideString(originalString, hiddenStringLength); }); describe('hidden string length check', () => { - let originalStringActualLength: number, - hiddenStringActualLength: number; + let originalStringActualLength: number, hiddenStringActualLength: number; before(() => { originalStringActualLength = originalString.length; @@ -129,8 +124,7 @@ describe('CryptUtils', () => { const string: string = 'test'; const key: string = 'key'; - let encodedString: string, - decodedString: string; + let encodedString: string, decodedString: string; before(() => { encodedString = cryptUtils.rc4(string, key); diff --git a/test/unit-tests/utils/CryptUtilsStringArray.spec.ts b/test/unit-tests/utils/CryptUtilsStringArray.spec.ts index 283b24f71..6b23fa6be 100644 --- a/test/unit-tests/utils/CryptUtilsStringArray.spec.ts +++ b/test/unit-tests/utils/CryptUtilsStringArray.spec.ts @@ -18,8 +18,9 @@ describe('CryptUtilsStringArray', () => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - cryptUtilsStringArray = inversifyContainerFacade - .get(ServiceIdentifiers.ICryptUtilsStringArray); + cryptUtilsStringArray = inversifyContainerFacade.get( + ServiceIdentifiers.ICryptUtilsStringArray + ); }); describe('btoa', () => { @@ -56,8 +57,7 @@ describe('CryptUtilsStringArray', () => { const string: string = 'test'; const key: string = 'key'; - let encodedString: string, - decodedString: string; + let encodedString: string, decodedString: string; before(() => { encodedString = cryptUtilsStringArray.rc4(string, key); diff --git a/test/unit-tests/utils/EscapeSequenceEncoder.spec.ts b/test/unit-tests/utils/EscapeSequenceEncoder.spec.ts index 3a553b9a9..73624cc1c 100644 --- a/test/unit-tests/utils/EscapeSequenceEncoder.spec.ts +++ b/test/unit-tests/utils/EscapeSequenceEncoder.spec.ts @@ -8,7 +8,6 @@ import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers'; import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade'; import { IEscapeSequenceEncoder } from '../../../src/interfaces/utils/IEscapeSequenceEncoder'; - describe('EscapeSequenceEncoder', () => { describe('encode', () => { let escapeSequenceEncoder: IEscapeSequenceEncoder; @@ -17,8 +16,9 @@ describe('EscapeSequenceEncoder', () => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - escapeSequenceEncoder = inversifyContainerFacade - .get(ServiceIdentifiers.IEscapeSequenceEncoder); + escapeSequenceEncoder = inversifyContainerFacade.get( + ServiceIdentifiers.IEscapeSequenceEncoder + ); }); describe('Variant #1: default', () => { @@ -37,7 +37,7 @@ describe('EscapeSequenceEncoder', () => { }); describe('Variant #2: escape `escape sequences`', () => { - const string: string = 'abc\'\\r\\n'; + const string: string = "abc'\\r\\n"; const expectedString: string = 'abc\\x27\\x5cr\\x5cn'; let actualString: string; diff --git a/test/unit-tests/utils/LevelledTopologicalSorter.spec.ts b/test/unit-tests/utils/LevelledTopologicalSorter.spec.ts index f09a12c75..33bdd5a56 100644 --- a/test/unit-tests/utils/LevelledTopologicalSorter.spec.ts +++ b/test/unit-tests/utils/LevelledTopologicalSorter.spec.ts @@ -8,7 +8,6 @@ import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers'; import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade'; import { ILevelledTopologicalSorter } from '../../../src/interfaces/utils/ILevelledTopologicalSorter'; - describe('EscapeSequenceEncoder', () => { describe('encode', () => { let levelledTopologicalSorter: ILevelledTopologicalSorter; @@ -17,8 +16,9 @@ describe('EscapeSequenceEncoder', () => { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); inversifyContainerFacade.load('', '', {}); - levelledTopologicalSorter = inversifyContainerFacade - .get(ServiceIdentifiers.ILevelledTopologicalSorter); + levelledTopologicalSorter = inversifyContainerFacade.get( + ServiceIdentifiers.ILevelledTopologicalSorter + ); }); describe('Base sort', () => { @@ -33,14 +33,7 @@ describe('EscapeSequenceEncoder', () => { }); describe('Variant #1: Base linear sort', () => { - const expectedSortedItems: string[] = [ - 'F', - 'A', - 'C', - 'B', - 'D', - 'E', - ]; + const expectedSortedItems: string[] = ['F', 'A', 'C', 'B', 'D', 'E']; let sortedItems: string[]; @@ -54,11 +47,7 @@ describe('EscapeSequenceEncoder', () => { }); describe('Variant #2: Base sort with grouping', () => { - const expectedSortedItems: string[][] = [ - ['C', 'D', 'F'], - ['A', 'E'], - ['B'] - ]; + const expectedSortedItems: string[][] = [['C', 'D', 'F'], ['A', 'E'], ['B']]; let sortedItems: string[][]; @@ -83,14 +72,7 @@ describe('EscapeSequenceEncoder', () => { }); describe('Variant #1: Should sort items without relations', () => { - const expectedSortedItems: string[] = [ - 'A', - 'B', - 'C', - 'D', - 'E', - 'F' - ]; + const expectedSortedItems: string[] = ['A', 'B', 'C', 'D', 'E', 'F']; let sortedItems: string[]; @@ -104,9 +86,7 @@ describe('EscapeSequenceEncoder', () => { }); describe('Variant #2: Should sort items without relations with grouping', () => { - const expectedSortedItems: string[][] = [ - ['A', 'B', 'C', 'D', 'E', 'F'] - ]; + const expectedSortedItems: string[][] = [['A', 'B', 'C', 'D', 'E', 'F']]; let sortedItems: string[][]; diff --git a/test/unit-tests/utils/NumberUtils.spec.ts b/test/unit-tests/utils/NumberUtils.spec.ts index a87bdbe19..8f230f2ae 100644 --- a/test/unit-tests/utils/NumberUtils.spec.ts +++ b/test/unit-tests/utils/NumberUtils.spec.ts @@ -334,7 +334,7 @@ describe('NumberUtils', function () { describe('Positive number', () => { describe('Variant #1: positive small safe integer', () => { const number: number = 100; - const expectedResult: boolean = false + const expectedResult: boolean = false; let result: boolean; @@ -349,7 +349,7 @@ describe('NumberUtils', function () { describe('Variant #2: positive big safe integer', () => { const number: number = Number.MAX_SAFE_INTEGER; - const expectedResult: boolean = false + const expectedResult: boolean = false; let result: boolean; @@ -364,7 +364,7 @@ describe('NumberUtils', function () { describe('Variant #3: positive unsafe integer', () => { const number: number = Number.MAX_SAFE_INTEGER + 1; - const expectedResult: boolean = true + const expectedResult: boolean = true; let result: boolean; @@ -381,7 +381,7 @@ describe('NumberUtils', function () { describe('Negative number', () => { describe('Variant #1: negative small safe integer', () => { const number: number = -100; - const expectedResult: boolean = false + const expectedResult: boolean = false; let result: boolean; @@ -396,7 +396,7 @@ describe('NumberUtils', function () { describe('Variant #2: negative big safe integer', () => { const number: number = Number.MIN_SAFE_INTEGER; - const expectedResult: boolean = false + const expectedResult: boolean = false; let result: boolean; @@ -411,7 +411,7 @@ describe('NumberUtils', function () { describe('Variant #3: negative unsafe integer', () => { const number: number = Number.MIN_SAFE_INTEGER - 1; - const expectedResult: boolean = true + const expectedResult: boolean = true; let result: boolean; @@ -444,10 +444,7 @@ describe('NumberUtils', function () { describe('Positive numbers', () => { describe('Variant #1: positive number `1`', () => { const number: number = 1; - const expectedFactors: number[] = [ - -1, - 1 - ]; + const expectedFactors: number[] = [-1, 1]; let factors: number[]; @@ -462,12 +459,7 @@ describe('NumberUtils', function () { describe('Variant #2: positive number `2`', () => { const number: number = 2; - const expectedFactors: number[] = [ - -2, - -1, - 1, - 2 - ]; + const expectedFactors: number[] = [-2, -1, 1, 2]; let factors: number[]; @@ -483,24 +475,7 @@ describe('NumberUtils', function () { describe('Variant #3: positive number `100`', () => { const number: number = 100; const expectedFactors: number[] = [ - -100, - -50, - -25, - -20, - -10, - -5, - -4, - -2, - -1, - 1, - 2, - 4, - 5, - 10, - 20, - 25, - 50, - 100 + -100, -50, -25, -20, -10, -5, -4, -2, -1, 1, 2, 4, 5, 10, 20, 25, 50, 100 ]; let factors: number[]; @@ -545,15 +520,12 @@ describe('NumberUtils', function () { assert.deepEqual(factors, expectedFactors); }); }); - }) + }); describe('Negative numbers', () => { describe('Variant #1: negative number `-1`', () => { const number: number = -1; - const expectedFactors: number[] = [ - -1, - 1 - ]; + const expectedFactors: number[] = [-1, 1]; let factors: number[]; @@ -568,12 +540,7 @@ describe('NumberUtils', function () { describe('Variant #2: negative number `-2`', () => { const number: number = -2; - const expectedFactors: number[] = [ - -2, - -1, - 1, - 2 - ]; + const expectedFactors: number[] = [-2, -1, 1, 2]; let factors: number[]; @@ -589,24 +556,7 @@ describe('NumberUtils', function () { describe('Variant #3: negative number `-100`', () => { const number: number = -100; const expectedFactors: number[] = [ - -100, - -50, - -25, - -20, - -10, - -5, - -4, - -2, - -1, - 1, - 2, - 4, - 5, - 10, - 20, - 25, - 50, - 100 + -100, -50, -25, -20, -10, -5, -4, -2, -1, 1, 2, 4, 5, 10, 20, 25, 50, 100 ]; let factors: number[]; @@ -651,7 +601,7 @@ describe('NumberUtils', function () { assert.deepEqual(factors, expectedFactors); }); }); - }) + }); describe('zero number', () => { const number: number = 0; @@ -665,6 +615,6 @@ describe('NumberUtils', function () { it('should throw an error', () => { assert.throw(testFunc, Error); }); - }) + }); }); }); diff --git a/test/unit-tests/utils/ObfuscatedCodeFileUtils.spec.ts b/test/unit-tests/utils/ObfuscatedCodeFileUtils.spec.ts index 29902bc40..5393a8477 100644 --- a/test/unit-tests/utils/ObfuscatedCodeFileUtils.spec.ts +++ b/test/unit-tests/utils/ObfuscatedCodeFileUtils.spec.ts @@ -2,16 +2,16 @@ import { expect } from 'chai'; import { ObfuscatedCodeFileUtils } from '../../../src/cli/utils/ObfuscatedCodeFileUtils'; describe('ObfuscatedCodeFileUtils', () => { - let util: ObfuscatedCodeFileUtils; + let util: ObfuscatedCodeFileUtils; - beforeEach(() => { - util = new ObfuscatedCodeFileUtils('src/cli/', { - output: 'src/cli/dist', + beforeEach(() => { + util = new ObfuscatedCodeFileUtils('src/cli/', { + output: 'src/cli/dist' + }); }); - }); - it('should handle input path ending (or not ending) with forward slash', () => { - const result = util.getOutputCodePath('src/cli/app.js'); - expect(result).equals('src/cli/dist/app.js'); - }); + it('should handle input path ending (or not ending) with forward slash', () => { + const result = util.getOutputCodePath('src/cli/app.js'); + expect(result).equals('src/cli/dist/app.js'); + }); }); diff --git a/test/unit-tests/utils/RandomGenerator.spec.ts b/test/unit-tests/utils/RandomGenerator.spec.ts index 7671f67f8..f2d3fe070 100644 --- a/test/unit-tests/utils/RandomGenerator.spec.ts +++ b/test/unit-tests/utils/RandomGenerator.spec.ts @@ -33,7 +33,11 @@ describe('RandomGenerator', () => { before(() => { for (let i = 0; i < samplesCount; i++) { - const randomInteger = randomGenerator.getRandomIntegerExcluding(minValue, maxValue, valuesToExclude); + const randomInteger = randomGenerator.getRandomIntegerExcluding( + minValue, + maxValue, + valuesToExclude + ); if (!expectedRandomIntegerValues.includes(randomInteger)) { isRandomIntegerInAllowedValuesRange = false; @@ -55,7 +59,7 @@ describe('RandomGenerator', () => { const delta: number = 0.15; - const expectedValueChance: number = 0.2 + const expectedValueChance: number = 0.2; let minValuesCount: number = 0; let maxValuesCount: number = 0; @@ -65,7 +69,11 @@ describe('RandomGenerator', () => { before(() => { for (let i = 0; i < samplesCount; i++) { - const randomInteger: number = randomGenerator.getRandomIntegerExcluding(minValue, maxValue, valuesToExclude); + const randomInteger: number = randomGenerator.getRandomIntegerExcluding( + minValue, + maxValue, + valuesToExclude + ); if (randomInteger === minValue) { minValuesCount += 1; diff --git a/test/unit-tests/utils/StringUtils.spec.ts b/test/unit-tests/utils/StringUtils.spec.ts index fa56eee81..21659e5f8 100644 --- a/test/unit-tests/utils/StringUtils.spec.ts +++ b/test/unit-tests/utils/StringUtils.spec.ts @@ -7,12 +7,12 @@ describe('StringUtils', function () { describe('escapeJsString', () => { describe('Variant #1: single quotes', () => { - const expectedEscapedJsString: string = 'const foo = \\\'Hello World!\\\''; + const expectedEscapedJsString: string = "const foo = \\'Hello World!\\'"; let escapedJsString: string; before(() => { - escapedJsString = StringUtils.escapeJsString('const foo = \'Hello World!\''); + escapedJsString = StringUtils.escapeJsString("const foo = 'Hello World!'"); }); it('should escape js string', () => { diff --git a/test/unit-tests/utils/Utils.spec.ts b/test/unit-tests/utils/Utils.spec.ts index 7f570ba4b..c72bb067a 100644 --- a/test/unit-tests/utils/Utils.spec.ts +++ b/test/unit-tests/utils/Utils.spec.ts @@ -131,10 +131,7 @@ describe('Utils', () => { let identifiersPrefix: string; before(() => { - identifiersPrefix = Utils.getIdentifiersPrefixForMultipleSources( - 'foo', - 1 - ); + identifiersPrefix = Utils.getIdentifiersPrefixForMultipleSources('foo', 1); }); it('should return correct identifiers prefix', () => { @@ -148,10 +145,7 @@ describe('Utils', () => { let identifiersPrefix: string; before(() => { - identifiersPrefix = Utils.getIdentifiersPrefixForMultipleSources( - undefined, - 1 - ); + identifiersPrefix = Utils.getIdentifiersPrefixForMultipleSources(undefined, 1); }); it('should return correct identifiers prefix', () => { diff --git a/yarn.lock b/yarn.lock index 6c1be1ca4..e74bdbc15 100644 --- a/yarn.lock +++ b/yarn.lock @@ -487,6 +487,11 @@ resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.2.tgz#1cf95080bb7072fafaa3cb13b442fab4695c3893" integrity sha512-fdDH1LSGfZdTH2sxdpVMw31BanV28K/Gry0cVFxaNP77neJSkd82mM8ErPNYs9e+0O7SdHBLTDzDgwUuy18RnQ== +"@pkgr/core@^0.2.9": + version "0.2.9" + resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.2.9.tgz#d229a7b7f9dac167a156992ef23c7f023653f53b" + integrity sha512-QNqXyfVS2wm9hweSYD2O7F0G06uurj9kZ96TRQE5Y9hU7+tgdZwIkbAKc5Ocy1HxEY2kuDQa6cQ1WRs/O5LFKA== + "@rtsao/scc@^1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@rtsao/scc/-/scc-1.1.0.tgz#927dd2fae9bc3361403ac2c7a00c32ddce9ad7e8" @@ -2151,6 +2156,11 @@ escape-string-regexp@^4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== +eslint-config-prettier@10.1.8: + version "10.1.8" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-10.1.8.tgz#15734ce4af8c2778cc32f0b01b37b0b5cd1ecb97" + integrity sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w== + eslint-import-resolver-node@^0.3.9: version "0.3.9" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.9.tgz#d4eaac52b8a2e7c3cd1903eb00f7e053356118ac" @@ -2219,6 +2229,14 @@ eslint-plugin-prefer-arrow@1.2.3: resolved "https://registry.npmjs.org/eslint-plugin-prefer-arrow/-/eslint-plugin-prefer-arrow-1.2.3.tgz" integrity sha512-J9I5PKCOJretVuiZRGvPQxCbllxGAV/viI20JO3LYblAodofBxyMnZAJ+WGeClHgANnSJberTNoFWWjrWKBuXQ== +eslint-plugin-prettier@5.5.4: + version "5.5.4" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-5.5.4.tgz#9d61c4ea11de5af704d4edf108c82ccfa7f2e61c" + integrity sha512-swNtI95SToIz05YINMA6Ox5R057IMAmWZ26GqPxusAp1TZzj+IdY9tXNWWD3vkF/wEqydCONcwjTFpxybBqZsg== + dependencies: + prettier-linter-helpers "^1.0.0" + synckit "^0.11.7" + eslint-plugin-unicorn@56.0.1: version "56.0.1" resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-56.0.1.tgz#d10a3df69ba885939075bdc95a65a0c872e940d4" @@ -2402,6 +2420,11 @@ fast-deep-equal@3.1.3, fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz" integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== +fast-diff@^1.1.2: + version "1.3.0" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.3.0.tgz#ece407fa550a64d638536cd727e129c61616e0f0" + integrity sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw== + fast-glob@^3.2.9: version "3.3.3" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.3.tgz#d06d585ce8dba90a16b0505c543c3ccfb3aeb818" @@ -4323,6 +4346,18 @@ prelude-ls@~1.1.2: resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz" integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= +prettier-linter-helpers@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" + integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w== + dependencies: + fast-diff "^1.1.2" + +prettier@3.6.2: + version "3.6.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.6.2.tgz#ccda02a1003ebbb2bfda6f83a074978f608b9393" + integrity sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ== + process-on-spawn@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/process-on-spawn/-/process-on-spawn-1.0.0.tgz" @@ -5024,6 +5059,13 @@ supports-preserve-symlinks-flag@^1.0.0: resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== +synckit@^0.11.7: + version "0.11.11" + resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.11.11.tgz#c0b619cf258a97faa209155d9cd1699b5c998cb0" + integrity sha512-MeQTA1r0litLUf0Rp/iisCaL8761lKAZHaimlbGK4j0HysC4PLfqygQj9srcs0m2RdtDYnF8UuYyKpbjHYp7Jw== + dependencies: + "@pkgr/core" "^0.2.9" + synckit@^0.9.1: version "0.9.3" resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.9.3.tgz#1cfd60d9e61f931e07fb7f56f474b5eb31b826a7" From 64e14ebe2fe83874596c6f80e7a20e2bdf4b6e24 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Thu, 4 Dec 2025 00:27:48 +0400 Subject: [PATCH 23/87] Adjust precommit hook --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index dfc99ba17..f06fd2dc3 100644 --- a/package.json +++ b/package.json @@ -125,8 +125,8 @@ "format": "yarn run prettier && yarn run eslint --fix", "git:addFiles": "git add .", "postinstall": "opencollective-postinstall", - "precommit": "npm run build", - "prepublishOnly": "npm run build && npm run build:typings", + "precommit": "yarn run eslint", + "prepublishOnly": "yarn run build && yarn run build:typings", "prepare": "husky install" }, "author": { From 3bb9b1872fb342f216862b517c2ec4cc3a135855 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Thu, 4 Dec 2025 18:23:22 +0400 Subject: [PATCH 24/87] Downgrade multimatch (#1341) --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- yarn.lock | 28 ++++++++++------------------ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bbe7204f..510fd350d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log +v4.2.1 +--- +* Downgrade `multimatch` version to avoid esm errors + v4.2.0 --- * Dropped support of Node versions 17 and below diff --git a/package.json b/package.json index f06fd2dc3..ebdd473fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "4.2.0", + "version": "4.2.1", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", @@ -36,7 +36,7 @@ "js-string-escape": "1.0.1", "md5": "2.3.0", "mkdirp": "3.0.1", - "multimatch": "7.0.0", + "multimatch": "5.0.0", "opencollective-postinstall": "2.0.3", "process": "0.11.10", "reflect-metadata": "0.2.2", diff --git a/yarn.lock b/yarn.lock index e74bdbc15..93f02ef83 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1172,11 +1172,6 @@ array-differ@^3.0.0: resolved "https://registry.npmjs.org/array-differ/-/array-differ-3.0.0.tgz" integrity sha512-THtfYS6KtME/yIAhKjZ2ul7XI96lQGHRputJQHO80LAWQnuGP4iCIN8vdMRboGbIEYBwU33q8Tch1os2+X0kMg== -array-differ@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/array-differ/-/array-differ-4.0.0.tgz#aa3c891c653523290c880022f45b06a42051b026" - integrity sha512-Q6VPTLMsmXZ47ENG3V+wQyZS1ZxXMxFyYzA+Z/GMrJ6yIutAIEf9wTyroTzmGjNfox9/h3GdGBCVh43GVFx4Uw== - array-filter@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/array-filter/-/array-filter-1.0.0.tgz" @@ -1201,11 +1196,6 @@ array-union@^2.1.0: resolved "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz" integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== -array-union@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/array-union/-/array-union-3.0.1.tgz#da52630d327f8b88cfbfb57728e2af5cd9b6b975" - integrity sha512-1OvF9IbWwaeiM9VhzYXVQacMibxpXOMYVNIvMtKRyX9SImBXpKcFr8XvFDeEslCyuH/t6KRt7HEO94AlP8Iatw== - array.prototype.findlastindex@^1.2.6: version "1.2.6" resolved "https://registry.yarnpkg.com/array.prototype.findlastindex/-/array.prototype.findlastindex-1.2.6.tgz#cfa1065c81dcb64e34557c9b81d012f6a421c564" @@ -3820,7 +3810,7 @@ minimatch@^3.0.5, minimatch@^3.1.2: dependencies: brace-expansion "^1.1.7" -minimatch@^9.0.3, minimatch@^9.0.4, minimatch@^9.0.5: +minimatch@^9.0.4, minimatch@^9.0.5: version "9.0.5" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.5.tgz#d74f9dd6b57d83d8e98cfb82133b03978bc929e5" integrity sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow== @@ -3895,14 +3885,16 @@ multimatch@*: arrify "^2.0.1" minimatch "^3.0.4" -multimatch@7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/multimatch/-/multimatch-7.0.0.tgz#d0a1bf144db9106b8d19e3cb8cabec1a8986c27f" - integrity sha512-SYU3HBAdF4psHEL/+jXDKHO95/m5P2RvboHT2Y0WtTttvJLP4H/2WS9WlQPFvF6C8d6SpLw8vjCnQOnVIVOSJQ== +multimatch@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/multimatch/-/multimatch-5.0.0.tgz#932b800963cea7a31a033328fa1e0c3a1874dbe6" + integrity sha512-ypMKuglUrZUD99Tk2bUQ+xNQj43lPEfAeX2o9cTteAmShXy2VHDJpuwu1o0xqoKCt9jLVAvwyFKdLTPXKAfJyA== dependencies: - array-differ "^4.0.0" - array-union "^3.0.1" - minimatch "^9.0.3" + "@types/minimatch" "^3.0.3" + array-differ "^3.0.0" + array-union "^2.1.0" + arrify "^2.0.1" + minimatch "^3.0.4" natural-compare@^1.4.0: version "1.4.0" From 4f3a45612456f5b209ec9eb63f6568213a0bb4eb Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sun, 7 Dec 2025 00:01:00 +0400 Subject: [PATCH 25/87] Add Async PRO API (#1343) --- .eslintrc.js | 2 +- .github/ISSUE_TEMPLATE.md | 5 +- .github/ISSUE_TEMPLATE/bug_report.md | 5 +- CHANGELOG.md | 4 + README.md | 203 ++++++++ index.ts | 26 +- package.json | 5 +- src/JavaScriptObfuscatorFacade.ts | 34 ++ src/interfaces/pro-api/IProApiClient.ts | 85 ++++ src/pro-api/ApiError.ts | 14 + src/pro-api/ProApiClient.ts | 183 +++++++ src/pro-api/ProApiObfuscationResult.ts | 32 ++ .../pro-api/ProApiClient.spec.ts | 463 ++++++++++++++++++ 13 files changed, 1054 insertions(+), 7 deletions(-) create mode 100644 src/interfaces/pro-api/IProApiClient.ts create mode 100644 src/pro-api/ApiError.ts create mode 100644 src/pro-api/ProApiClient.ts create mode 100644 src/pro-api/ProApiObfuscationResult.ts create mode 100644 test/functional-tests/pro-api/ProApiClient.spec.ts diff --git a/.eslintrc.js b/.eslintrc.js index a18e32d6d..4f327033a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -271,7 +271,7 @@ module.exports = { 'prefer-const': 'error', 'prefer-object-spread': 'error', 'prefer-template': 'error', - 'quote-props': ['error', 'as-needed'], + 'quote-props': ['off', 'as-needed'], 'quotes': 'off', 'radix': 'error', 'space-before-function-paren': 'off', diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index b5c3667ec..6566c0260 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -17,7 +17,10 @@ 1. 2. 3. -4. + +## JavaScript Obfuscator Edition +- JavaScript Obfuscator Open Source +- JavaScript Obfuscator Pro via API or [http://obfuscator.io](http://obfuscator.io]) ## Your Environment diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dbedc7c35..e422999f9 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -24,7 +24,10 @@ assignees: '' 1. 2. 3. -4. + +## JavaScript Obfuscator Edition +- JavaScript Obfuscator Open Source +- JavaScript Obfuscator Pro via API or [http://obfuscator.io](http://obfuscator.io]) ## Your Environment diff --git a/CHANGELOG.md b/CHANGELOG.md index 510fd350d..f7f00f9e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log +v5.0.0 +--- +* Add JavaScript Obfuscator PRO support via calling its API + v4.2.1 --- * Downgrade `multimatch` version to avoid esm errors diff --git a/README.md b/README.md index a1dae1340..04313a8a5 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Huge thanks to all supporters! JavaScript Obfuscator is a powerful free obfuscator for JavaScript, containing a variety of features which provide protection for your source code. **Key features:** +- VM obfuscation (via [JavaScript Obfuscator Pro](https://obfuscator.io/)) - variables renaming - strings extraction and encryption - dead code injection @@ -259,6 +260,103 @@ Returns a map object which keys are identifiers of source codes and values are ` Returns an options object for the passed options preset name. +--- + +## :shield: Pro API Methods (VM Obfuscation) + +The Pro API methods provide access to **VM-based bytecode obfuscation** through the [obfuscator.io](https://obfuscator.io) cloud service. VM obfuscation is the most advanced and secure form of code protection available, transforming your JavaScript functions into custom bytecode that runs on an embedded virtual machine. + +**Why VM Obfuscation?** +- **Strongest protection**: Code is converted to bytecode that cannot be directly understood +- **Anti-decompilation**: No standard JavaScript to reverse engineer +- **Customizable VM**: Each obfuscation generates unique opcodes and VM structure +- **Layered security**: Combine with other obfuscation options for defense in depth + +### Getting an API Token + +To use Pro API methods, you need a valid API token from [obfuscator.io](https://obfuscator.io): + +1. Create an account at [obfuscator.io](https://obfuscator.io) +2. Subscribe to a Pro, Team, or Business plan that includes API access +3. Generate your API token at [obfuscator.io/dashboard](https://obfuscator.io/dashboard) + +### `obfuscatePro(sourceCode, options, proApiConfig, onProgress?)` :new: + +**Async method** that obfuscates code using the Pro API with VM-based bytecode obfuscation. + +```javascript +const JavaScriptObfuscator = require('javascript-obfuscator'); + +const result = await JavaScriptObfuscator.obfuscatePro( + `function hello() { console.log("Hello World"); }`, + { + vmObfuscation: true, // Required! + vmObfuscationThreshold: 1, + compact: true + }, + { + apiToken: 'your_javascript_obfuscator_pro_api_token' + } +); + +console.log(result.getObfuscatedCode()); +``` + +**Parameters:** + +* `sourceCode` (`string`) – source code to obfuscate +* `options` (`Object`) – obfuscation options. **Must include `vmObfuscation: true`** +* `apiConfig` (`Object`) – Pro API configuration: + * `apiToken` (`string`, required) – your API token from obfuscator.io + * `timeout` (`number`, optional) – request timeout in ms (default: `300000` - 5 minutes) +* `onProgress` (`function`, optional) – callback for progress updates during obfuscation + +**Returns:** `Promise` + +**Throws:** `ApiError` if: +- `vmObfuscation` is not enabled in options +- API token is invalid or expired +- API request fails + +### Pro API with Progress Updates + +The API uses streaming mode to provide real-time progress updates during obfuscation: + +```javascript +const result = await JavaScriptObfuscator.obfuscatePro( + sourceCode, + { + vmObfuscation: true, + vmObfuscationThreshold: 1 + }, + { + apiToken: 'your_javascript_obfuscator_pro_api_token' + }, + (message) => { + console.log('Progress:', message); + // Output: "Validating request...", "Authenticating...", "Obfuscating...", etc. + } +); +``` + +### Error Handling + +```javascript +const { ApiError } = require('javascript-obfuscator'); + +try { + const result = await JavaScriptObfuscator.obfuscatePro(sourceCode, options, config); +} catch (error) { + if (error instanceof ApiError) { + console.error(`API Error (${error.statusCode}): ${error.message}`); + } else { + throw error; + } +} +``` + +--- + ## CLI usage See [CLI options](#cli-options). @@ -1640,6 +1738,111 @@ The performance will be at a relatively normal level +## JavaScript Obfuscator Pro VM options + +### `vmObfuscation` +Type: `boolean` Default: `false` + +Enables VM-based bytecode obfuscation. When enabled, JavaScript functions are compiled into custom bytecode that runs on an embedded virtual machine. This provides the highest level of protection as the original code logic is completely transformed. + +**Warning:** This significantly increases code size and may impact performance. Use `vmObfuscationThreshold` to control which root-level functions are transformed. + +### `vmObfuscationThreshold` +Type: `number` Default: `1` + +The probability (from 0 to 1) that a function will be transformed to VM bytecode when `vmObfuscation` is enabled. + +- `0` - no functions will be transformed +- `0.5` - 50% of functions will be transformed +- `1` - all functions will be transformed + +### `vmTargetFunctions` +Type: `string[]` Default: `[]` + +Array of root-level function names to target for VM obfuscation. When specified, only these functions will be transformed (subject to `vmObfuscationThreshold`). Empty array means all functions are candidates. + +### `vmExcludeFunctions` +Type: `string[]` Default: `[]` + +Array of root-level function names to exclude from VM obfuscation. These functions will never be transformed regardless of other settings. + +### `vmOpcodeShuffle` +Type: `boolean` Default: `false` + +Randomizes the opcode mapping for each obfuscation run. Makes static analysis more difficult as opcode meanings change between builds. + +### `vmBytecodeEncoding` +Type: `boolean` Default: `false` + +Encodes the bytecode instructions using XOR encryption. The decoding key is derived at runtime, adding another layer of protection. + +### `vmBytecodeArrayEncoding` +Type: `boolean` Default: `false` + +Applies additional encoding to the bytecode array, making it harder to identify bytecode patterns through static analysis. + +### `vmJumpsEncoding` +Type: `boolean` Default: `false` + +Encodes jump targets and offsets in the bytecode. This obscures control flow and makes it harder to follow program execution. + +### `vmDecoyOpcodes` +Type: `boolean` Default: `false` + +Inserts fake opcodes into the dispatcher that are never executed. Increases code complexity and confuses reverse engineering attempts. + +### `vmDeadCodeInjection` +Type: `boolean` Default: `false` + +Injects dead code sequences into the VM bytecode. These sequences are valid but unreachable, adding noise to analysis. + +### `vmSplitDispatcher` +Type: `boolean` Default: `false` + +Splits the VM dispatcher into multiple smaller dispatchers. Makes the execution flow harder to follow. + +### `vmMacroOps` +Type: `boolean` Default: `false` + +Combines common instruction sequences into single macro opcodes. This creates unique instruction patterns that are harder to recognize. + +### `vmDebugProtection` +Type: `boolean` Default: `false` + +Adds anti-debugging measures to the VM runtime. Detects debugger presence and alters behavior when debugging is detected. + +### `vmRuntimeOpcodeDerivation` +Type: `boolean` Default: `false` + +Derives opcode values at runtime through mathematical operations rather than using static values. Makes static analysis significantly harder. + +### `vmStatefulOpcodes` +Type: `boolean` Default: `false` + +Makes opcode interpretation depend on VM state. The same opcode can have different meanings based on execution history. + +### `vmStackEncoding` +Type: `boolean` Default: `false` + +Encodes values pushed to and popped from the VM stack. Adds protection against memory inspection during execution. + +### `vmRandomizeKeys` +Type: `boolean` Default: `false` + +Randomizes encryption keys and other constants used by the VM. Each build produces unique key values. + +### `vmIndirectDispatch` +Type: `boolean` Default: `false` + +Uses indirect function calls for opcode dispatch instead of direct switch/case. Makes control flow analysis more difficult. + +### `vmBytecodeFormat` +Type: `string` Default: `binary` + +Specifies the format used to embed bytecode in the output: +- `binary` - Compact binary representation (smaller size) +- `json` - JSON format (easier debugging, larger size) + ## Frequently Asked Questions ### What javascript versions are supported? diff --git a/index.ts b/index.ts index 5fad2f096..30b327761 100644 --- a/index.ts +++ b/index.ts @@ -6,13 +6,18 @@ import { TObfuscationResultsObject } from './src/types/TObfuscationResultsObject import { TOptionsPreset } from './src/types/options/TOptionsPreset'; import { IObfuscationResult } from './src/interfaces/source-code/IObfuscationResult'; - -import { JavaScriptObfuscator } from './src/JavaScriptObfuscatorFacade'; +import { IProApiConfig, IProObfuscationResult, TProApiProgressCallback } from './src/interfaces/pro-api/IProApiClient'; +import { JavaScriptObfuscator, ApiError } from './src/JavaScriptObfuscatorFacade'; export type ObfuscatorOptions = TInputOptions; export interface ObfuscationResult extends IObfuscationResult {} +export interface ProObfuscationResult extends IProObfuscationResult {} + +export type { IProApiConfig, TProApiProgressCallback }; +export { ApiError }; + /** * @param {string} sourceCode * @param {ObfuscatorOptions} inputOptions @@ -30,6 +35,23 @@ export declare function obfuscateMultiple ; +/** + * Obfuscate code using the Pro API (obfuscator.io) + * Requires a valid API token and vmObfuscation: true + * + * @param {string} sourceCode - Source code to obfuscate + * @param {ObfuscatorOptions} inputOptions - Obfuscation options (must include vmObfuscation: true) + * @param {IProApiConfig} proApiConfig - Pro API configuration including API token + * @param {TProApiProgressCallback} onProgress - Optional callback for progress updates + * @returns {Promise} - Promise resolving to obfuscation result + */ +export declare function obfuscatePro ( + sourceCode: string, + inputOptions: ObfuscatorOptions, + proApiConfig: IProApiConfig, + onProgress?: TProApiProgressCallback +): Promise; + /** * @param {TOptionsPreset} optionsPreset * @returns {TInputOptions} diff --git a/package.json b/package.json index ebdd473fd..9d7bc9be3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "4.2.1", + "version": "5.0.0", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", @@ -143,5 +143,6 @@ }, "collective": { "url": "https://opencollective.com/javascript-obfuscator" - } + }, + "packageManager": "yarn@1.22.21+sha512.ca75da26c00327d26267ce33536e5790f18ebd53266796fbb664d2a4a5116308042dd8ee7003b276a20eace7d3c5561c3577bdd71bcb67071187af124779620a" } diff --git a/src/JavaScriptObfuscatorFacade.ts b/src/JavaScriptObfuscatorFacade.ts index abc6e2606..d5128d0ee 100644 --- a/src/JavaScriptObfuscatorFacade.ts +++ b/src/JavaScriptObfuscatorFacade.ts @@ -10,10 +10,13 @@ import { TOptionsPreset } from './types/options/TOptionsPreset'; import { IInversifyContainerFacade } from './interfaces/container/IInversifyContainerFacade'; import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator'; import { IObfuscationResult } from './interfaces/source-code/IObfuscationResult'; +import { IProApiConfig, IProObfuscationResult, TProApiProgressCallback } from './interfaces/pro-api/IProApiClient'; +import { ApiError } from './pro-api/ApiError'; import { InversifyContainerFacade } from './container/InversifyContainerFacade'; import { Options } from './options/Options'; import { Utils } from './utils/Utils'; +import { ProApiClient } from './pro-api/ProApiClient'; class JavaScriptObfuscatorFacade { /** @@ -87,6 +90,37 @@ class JavaScriptObfuscatorFacade { public static getOptionsByPreset(optionsPreset: TOptionsPreset): TInputOptions { return Options.getOptionsByPreset(optionsPreset); } + + /** + * Obfuscate code using the Pro API (obfuscator.io) + * This method requires a valid API token from obfuscator.io and only works with VM obfuscation. + * + * @param {string} sourceCode - Source code to obfuscate + * @param {TInputOptions} inputOptions - Obfuscation options (must include vmObfuscation: true) + * @param {IProApiConfig} proApiConfig - Pro API configuration including API token + * @param {TProApiProgressCallback} onProgress - Optional callback for progress updates (streaming mode only) + * @returns {Promise} - Promise resolving to obfuscation result + * @throws {ApiError} - If API returns an error or vmObfuscation is not enabled + */ + public static async obfuscatePro( + sourceCode: string, + inputOptions: TInputOptions, + proApiConfig: IProApiConfig, + onProgress?: TProApiProgressCallback + ): Promise { + if (!inputOptions.vmObfuscation) { + throw new ApiError( + 'obfuscatePro method works only with VM obfuscation. Set vmObfuscation: true in options.', + 400 + ); + } + + const client = new ProApiClient(proApiConfig); + + return client.obfuscate(sourceCode, inputOptions, onProgress); + } } export { JavaScriptObfuscatorFacade as JavaScriptObfuscator }; +export { ApiError } from './pro-api/ApiError'; +export type { IProApiConfig, TProApiProgressCallback } from './interfaces/pro-api/IProApiClient'; diff --git a/src/interfaces/pro-api/IProApiClient.ts b/src/interfaces/pro-api/IProApiClient.ts new file mode 100644 index 000000000..50b55ef69 --- /dev/null +++ b/src/interfaces/pro-api/IProApiClient.ts @@ -0,0 +1,85 @@ +import { TIdentifierNamesCache } from '../../types/TIdentifierNamesCache'; + +/** + * Simplified obfuscation result for Pro API responses + * Does not extend IInitializable since results come from the API + */ +export interface IProObfuscationResult { + /** + * @returns {TIdentifierNamesCache} + */ + getIdentifierNamesCache(): TIdentifierNamesCache; + + /** + * @return {string} + */ + getObfuscatedCode(): string; + + /** + * @return {string} + */ + getSourceMap(): string; + + /** + * @return {string} + */ + toString(): string; +} + +/** + * Configuration for the Pro API client + */ +export interface IProApiConfig { + /** + * API token from obfuscator.io + * Get your token at https://obfuscator.io/dashboard + */ + apiToken: string; + + /** + * Request timeout in milliseconds (default: 300000 - 5 minutes) + */ + timeout?: number; +} + +/** + * Progress callback for streaming responses + */ +export type TProApiProgressCallback = (message: string) => void; + +/** + * Streaming message types from the API + * The API always uses streaming mode (NDJSON format) + */ +export interface IProApiStreamMessage { + /** + * Message type: + * - 'progress': Progress update message + * - 'result': Direct result (non-chunked, for small outputs) + * - 'chunk': Chunked data piece (for large outputs) + * - 'chunk_end': End of chunked data + * - 'error': Error message + */ + type: 'progress' | 'result' | 'chunk' | 'chunk_end' | 'error'; + + /** Progress or error message text */ + message?: string; + + /** Obfuscated code (for 'result' type) */ + code?: string; + + /** Source map (for 'result' or 'chunk_end' type) */ + sourceMap?: string; + + /** Field name for chunk: 'code' or 'sourceMap' (for 'chunk' type) */ + field?: 'code' | 'sourceMap'; + + /** Chunk data (for 'chunk' type) */ + data?: string; + + /** Chunk index (for 'chunk' type) */ + index?: number; + + /** Total number of chunks (for 'chunk' type) */ + total?: number; +} diff --git a/src/pro-api/ApiError.ts b/src/pro-api/ApiError.ts new file mode 100644 index 000000000..b4614a3e2 --- /dev/null +++ b/src/pro-api/ApiError.ts @@ -0,0 +1,14 @@ +/** + * Error thrown by Pro API + */ +export class ApiError extends Error { + public readonly statusCode: number; + public readonly response?: string; + + public constructor(message: string, statusCode: number, response?: string) { + super(message); + this.name = 'ApiError'; + this.statusCode = statusCode; + this.response = response; + } +} diff --git a/src/pro-api/ProApiClient.ts b/src/pro-api/ProApiClient.ts new file mode 100644 index 000000000..2951cda1d --- /dev/null +++ b/src/pro-api/ProApiClient.ts @@ -0,0 +1,183 @@ +import { TInputOptions } from '../types/options/TInputOptions'; +import { + IProApiConfig, + IProApiStreamMessage, + IProObfuscationResult, + TProApiProgressCallback +} from '../interfaces/pro-api/IProApiClient'; +import { ApiError } from './ApiError'; +import { ProApiObfuscationResult } from './ProApiObfuscationResult'; + +/** + * API URL (hardcoded) + */ +const API_URL = 'https://obfuscator.io/api/v1/obfuscate'; + +/** + * Default timeout (5 minutes) + */ +const DEFAULT_TIMEOUT = 300000; + +/** + * Pro API Client + * Handles communication with the obfuscator.io Pro API using streaming mode + */ +export class ProApiClient { + private readonly config: { + apiToken: string; + timeout: number; + }; + + public constructor(config: IProApiConfig) { + this.config = { + apiToken: config.apiToken, + timeout: config.timeout ?? DEFAULT_TIMEOUT + }; + } + + /** + * Obfuscate code using the Pro API (streaming mode) + * @param sourceCode - Source code to obfuscate + * @param options - Obfuscation options + * @param onProgress - Optional progress callback + * @returns Promise resolving to obfuscation result + */ + public async obfuscate( + sourceCode: string, + options: TInputOptions = {}, + onProgress?: TProApiProgressCallback + ): Promise { + // Validate vmObfuscation is enabled + if (!options.vmObfuscation) { + throw new ApiError( + 'obfuscatePro method works only with VM obfuscation. Set vmObfuscation: true in options.', + 400 + ); + } + + // Always use streaming mode + const headers: Record = { + // eslint-disable-next-line @typescript-eslint/naming-convention + 'Content-Type': 'application/json', + // eslint-disable-next-line @typescript-eslint/naming-convention + 'Accept': 'application/x-ndjson', + // eslint-disable-next-line @typescript-eslint/naming-convention + 'Authorization': `Bearer ${this.config.apiToken}` + }; + + const body = JSON.stringify({ + code: sourceCode, + options + }); + + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), this.config.timeout); + + try { + const response = await fetch(API_URL, { + method: 'POST', + headers, + body, + signal: controller.signal + }); + + clearTimeout(timeoutId); + + return this.handleStreamingResponse(response, onProgress); + } catch (error) { + clearTimeout(timeoutId); + + if (error instanceof Error && error.name === 'AbortError') { + throw new ApiError('Request timeout', 408); + } + + throw error; + } + } + + /** + * Handle streaming (NDJSON) response from API + * Supports both direct result and chunked response formats + */ + // eslint-disable-next-line complexity + private async handleStreamingResponse( + response: Response, + onProgress?: TProApiProgressCallback + ): Promise { + const text = await response.text(); + const lines = text.trim().split('\n'); + + const messages: IProApiStreamMessage[] = []; + + for (const line of lines) { + if (!line.trim()) { + continue; + } + + try { + const message: IProApiStreamMessage = JSON.parse(line); + messages.push(message); + + // Call progress callback for progress messages + if (message.type === 'progress' && message.message && onProgress) { + onProgress(message.message); + } + } catch { + // Skip invalid JSON lines + } + } + + // Check for error messages + const errorMessage = messages.find((m) => m.type === 'error'); + if (errorMessage) { + throw new ApiError(errorMessage.message ?? 'Unknown API error', response.status); + } + + // Reassemble the result (handles both chunked and non-chunked responses) + const result = this.reassembleChunkedResponse(messages); + + if (!result.code) { + throw new ApiError('No result received from API', 500); + } + + return new ProApiObfuscationResult(result.code, result.sourceMap || ''); + } + + /** + * Reassemble chunked streaming response + * Handles both chunked format (chunk/chunk_end) and direct result format + */ + // eslint-disable-next-line complexity + private reassembleChunkedResponse(messages: IProApiStreamMessage[]): { code: string; sourceMap: string } { + const codeChunks: string[] = []; + const sourceMapChunks: string[] = []; + let result = { code: '', sourceMap: '' }; + + for (const msg of messages) { + switch (msg.type) { + case 'chunk': + if (msg.field === 'code' && msg.data !== undefined && msg.index !== undefined) { + codeChunks[msg.index] = msg.data; + } else if (msg.field === 'sourceMap' && msg.data !== undefined && msg.index !== undefined) { + sourceMapChunks[msg.index] = msg.data; + } + break; + + case 'chunk_end': + result.code = codeChunks.join(''); + result.sourceMap = (sourceMapChunks.join('') || msg.sourceMap) ?? ''; + break; + + case 'result': + // Direct result (non-chunked) + result = { + code: msg.code ?? '', + sourceMap: msg.sourceMap ?? '' + }; + break; + } + } + + return result; + } +} diff --git a/src/pro-api/ProApiObfuscationResult.ts b/src/pro-api/ProApiObfuscationResult.ts new file mode 100644 index 000000000..82bc89626 --- /dev/null +++ b/src/pro-api/ProApiObfuscationResult.ts @@ -0,0 +1,32 @@ +import { TIdentifierNamesCache } from '../types/TIdentifierNamesCache'; +import { IProObfuscationResult } from '../interfaces/pro-api/IProApiClient'; + +/** + * Pro API Obfuscation Result + * Simplified result type for Pro API responses + */ +export class ProApiObfuscationResult implements IProObfuscationResult { + private readonly obfuscatedCode: string; + private readonly sourceMapValue: string; + + public constructor(code: string, sourceMap: string = '') { + this.obfuscatedCode = code; + this.sourceMapValue = sourceMap; + } + + public getObfuscatedCode(): string { + return this.obfuscatedCode; + } + + public getSourceMap(): string { + return this.sourceMapValue; + } + + public getIdentifierNamesCache(): TIdentifierNamesCache { + return null; + } + + public toString(): string { + return this.obfuscatedCode; + } +} diff --git a/test/functional-tests/pro-api/ProApiClient.spec.ts b/test/functional-tests/pro-api/ProApiClient.spec.ts new file mode 100644 index 000000000..1d75bf8e6 --- /dev/null +++ b/test/functional-tests/pro-api/ProApiClient.spec.ts @@ -0,0 +1,463 @@ +import { assert } from 'chai'; +import * as sinon from 'sinon'; + +import { ProApiClient } from '../../../src/pro-api/ProApiClient'; +import { ApiError } from '../../../src/pro-api/ApiError'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; + +describe('ProApiClient', () => { + let fetchStub: sinon.SinonStub; + + // Helper to create NDJSON streaming response + const createNdjsonResponse = (messages: object[]): string => { + return messages.map((msg) => JSON.stringify(msg)).join('\n'); + }; + + // Mock fetch to redirect to our test server + const mockFetch = (responseBody: string, statusCode: number = 200): void => { + fetchStub = sinon.stub(global, 'fetch').callsFake(async () => { + return { + ok: statusCode >= 200 && statusCode < 300, + status: statusCode, + text: async () => responseBody + } as Response; + }); + }; + + afterEach(() => { + if (fetchStub) { + fetchStub.restore(); + } + }); + + describe('obfuscate', () => { + describe('validation', () => { + it('should throw ApiError when vmObfuscation is not enabled', async () => { + const client = new ProApiClient({ apiToken: 'test-token' }); + + try { + await client.obfuscate('const a = 1;', { vmObfuscation: false }); + assert.fail('Should have thrown an error'); + } catch (error) { + assert.instanceOf(error, ApiError); + assert.include((error as ApiError).message, 'vmObfuscation'); + assert.equal((error as ApiError).statusCode, 400); + } + }); + + it('should throw ApiError when vmObfuscation is undefined', async () => { + const client = new ProApiClient({ apiToken: 'test-token' }); + + try { + await client.obfuscate('const a = 1;', {}); + assert.fail('Should have thrown an error'); + } catch (error) { + assert.instanceOf(error, ApiError); + assert.include((error as ApiError).message, 'vmObfuscation'); + } + }); + }); + + describe('streaming response - direct result', () => { + it('should handle direct result response', async () => { + const obfuscatedCode = 'var _0x1234 = function() { return 1; };'; + const sourceMap = '{"version":3}'; + + const responseBody = createNdjsonResponse([ + { type: 'progress', message: 'Starting obfuscation...' }, + { type: 'progress', message: 'Processing...' }, + { type: 'result', code: obfuscatedCode, sourceMap: sourceMap } + ]); + + mockFetch(responseBody); + + const client = new ProApiClient({ apiToken: 'test-token' }); + const result = await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.equal(result.getObfuscatedCode(), obfuscatedCode); + assert.equal(result.getSourceMap(), sourceMap); + }); + + it('should call progress callback for progress messages', async () => { + const progressMessages: string[] = []; + const obfuscatedCode = 'var _0x1234 = 1;'; + + const responseBody = createNdjsonResponse([ + { type: 'progress', message: 'Step 1: Parsing' }, + { type: 'progress', message: 'Step 2: Transforming' }, + { type: 'progress', message: 'Step 3: Generating' }, + { type: 'result', code: obfuscatedCode, sourceMap: '' } + ]); + + mockFetch(responseBody); + + const client = new ProApiClient({ apiToken: 'test-token' }); + await client.obfuscate('const a = 1;', { vmObfuscation: true }, (msg) => { + progressMessages.push(msg); + }); + + assert.deepEqual(progressMessages, [ + 'Step 1: Parsing', + 'Step 2: Transforming', + 'Step 3: Generating' + ]); + }); + }); + + describe('streaming response - chunked result', () => { + it('should handle chunked code response', async () => { + const chunk1 = 'var _0x1234 = '; + const chunk2 = 'function() { '; + const chunk3 = 'return 1; };'; + const expectedCode = chunk1 + chunk2 + chunk3; + + const responseBody = createNdjsonResponse([ + { type: 'progress', message: 'Processing...' }, + { type: 'chunk', field: 'code', data: chunk1, index: 0, total: 3 }, + { type: 'chunk', field: 'code', data: chunk2, index: 1, total: 3 }, + { type: 'chunk', field: 'code', data: chunk3, index: 2, total: 3 }, + { type: 'chunk_end', sourceMap: '' } + ]); + + mockFetch(responseBody); + + const client = new ProApiClient({ apiToken: 'test-token' }); + const result = await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.equal(result.getObfuscatedCode(), expectedCode); + }); + + it('should handle chunked code and sourceMap response', async () => { + const codeChunk1 = 'var a = 1;'; + const codeChunk2 = 'var b = 2;'; + const mapChunk1 = '{"version":'; + const mapChunk2 = '3}'; + + const responseBody = createNdjsonResponse([ + { type: 'chunk', field: 'code', data: codeChunk1, index: 0, total: 2 }, + { type: 'chunk', field: 'code', data: codeChunk2, index: 1, total: 2 }, + { type: 'chunk', field: 'sourceMap', data: mapChunk1, index: 0, total: 2 }, + { type: 'chunk', field: 'sourceMap', data: mapChunk2, index: 1, total: 2 }, + { type: 'chunk_end' } + ]); + + mockFetch(responseBody); + + const client = new ProApiClient({ apiToken: 'test-token' }); + const result = await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.equal(result.getObfuscatedCode(), codeChunk1 + codeChunk2); + assert.equal(result.getSourceMap(), mapChunk1 + mapChunk2); + }); + + it('should handle out-of-order chunks correctly', async () => { + const chunk0 = 'first'; + const chunk1 = 'second'; + const chunk2 = 'third'; + + const responseBody = createNdjsonResponse([ + { type: 'chunk', field: 'code', data: chunk2, index: 2, total: 3 }, + { type: 'chunk', field: 'code', data: chunk0, index: 0, total: 3 }, + { type: 'chunk', field: 'code', data: chunk1, index: 1, total: 3 }, + { type: 'chunk_end', sourceMap: '' } + ]); + + mockFetch(responseBody); + + const client = new ProApiClient({ apiToken: 'test-token' }); + const result = await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.equal(result.getObfuscatedCode(), chunk0 + chunk1 + chunk2); + }); + }); + + describe('error handling', () => { + it('should throw ApiError when API returns error message', async () => { + const responseBody = createNdjsonResponse([ + { type: 'progress', message: 'Starting...' }, + { type: 'error', message: 'Invalid API token' } + ]); + + mockFetch(responseBody, 401); + + const client = new ProApiClient({ apiToken: 'invalid-token' }); + + try { + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + assert.fail('Should have thrown an error'); + } catch (error) { + assert.instanceOf(error, ApiError); + assert.equal((error as ApiError).message, 'Invalid API token'); + } + }); + + it('should throw ApiError when no result is received', async () => { + const responseBody = createNdjsonResponse([ + { type: 'progress', message: 'Processing...' } + ]); + + mockFetch(responseBody); + + const client = new ProApiClient({ apiToken: 'test-token' }); + + try { + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + assert.fail('Should have thrown an error'); + } catch (error) { + assert.instanceOf(error, ApiError); + assert.include((error as ApiError).message, 'No result received'); + } + }); + + it('should skip invalid JSON lines in response', async () => { + const obfuscatedCode = 'var a = 1;'; + const responseBody = + '{"type":"progress","message":"Step 1"}\n' + + 'invalid json line\n' + + `{"type":"result","code":"${obfuscatedCode}","sourceMap":""}`; + + mockFetch(responseBody); + + const client = new ProApiClient({ apiToken: 'test-token' }); + const result = await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.equal(result.getObfuscatedCode(), obfuscatedCode); + }); + + it('should handle timeout', async () => { + fetchStub = sinon.stub(global, 'fetch').callsFake(async (url, options) => { + // Simulate abort being called + const signal = options?.signal as AbortSignal; + if (signal) { + const error = new Error('The operation was aborted'); + error.name = 'AbortError'; + throw error; + } + return { ok: true, text: async () => '' } as Response; + }); + + const client = new ProApiClient({ apiToken: 'test-token', timeout: 1 }); + + try { + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + assert.fail('Should have thrown an error'); + } catch (error) { + assert.instanceOf(error, ApiError); + assert.equal((error as ApiError).statusCode, 408); + assert.include((error as ApiError).message, 'timeout'); + } + }); + }); + + describe('result interface', () => { + it('should return result implementing IProObfuscationResult', async () => { + const obfuscatedCode = 'var _0x1234 = 1;'; + const sourceMap = '{"version":3}'; + + const responseBody = createNdjsonResponse([ + { type: 'result', code: obfuscatedCode, sourceMap: sourceMap } + ]); + + mockFetch(responseBody); + + const client = new ProApiClient({ apiToken: 'test-token' }); + const result = await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.equal(result.getObfuscatedCode(), obfuscatedCode); + assert.equal(result.getSourceMap(), sourceMap); + assert.isNull(result.getIdentifierNamesCache()); + assert.equal(result.toString(), obfuscatedCode); + }); + }); + }); +}); + +describe('JavaScriptObfuscatorFacade Pro API', () => { + let fetchStub: sinon.SinonStub; + + const createNdjsonResponse = (messages: object[]): string => { + return messages.map((msg) => JSON.stringify(msg)).join('\n'); + }; + + const mockFetch = (responseBody: string, statusCode: number = 200): void => { + fetchStub = sinon.stub(global, 'fetch').callsFake(async () => { + return { + ok: statusCode >= 200 && statusCode < 300, + status: statusCode, + text: async () => responseBody + } as Response; + }); + }; + + afterEach(() => { + if (fetchStub) { + fetchStub.restore(); + } + }); + + describe('obfuscatePro', () => { + it('should throw ApiError when vmObfuscation is not enabled', async () => { + try { + await JavaScriptObfuscator.obfuscatePro('const a = 1;', {}, { apiToken: 'test' }); + assert.fail('Should have thrown an error'); + } catch (error) { + assert.instanceOf(error, ApiError); + assert.include((error as ApiError).message, 'vmObfuscation'); + } + }); + + it('should return obfuscation result on success', async () => { + const obfuscatedCode = 'var _0x1234 = 1;'; + + const responseBody = createNdjsonResponse([ + { type: 'result', code: obfuscatedCode, sourceMap: '' } + ]); + + mockFetch(responseBody); + + const result = await JavaScriptObfuscator.obfuscatePro( + 'const a = 1;', + { vmObfuscation: true }, + { apiToken: 'test-token' } + ); + + assert.equal(result.getObfuscatedCode(), obfuscatedCode); + }); + + it('should forward progress callback', async () => { + const progressMessages: string[] = []; + const obfuscatedCode = 'var a = 1;'; + + const responseBody = createNdjsonResponse([ + { type: 'progress', message: 'Processing...' }, + { type: 'result', code: obfuscatedCode, sourceMap: '' } + ]); + + mockFetch(responseBody); + + await JavaScriptObfuscator.obfuscatePro( + 'const a = 1;', + { vmObfuscation: true }, + { apiToken: 'test-token' }, + (msg) => progressMessages.push(msg) + ); + + assert.deepEqual(progressMessages, ['Processing...']); + }); + }); +}); + +describe('ApiError', () => { + it('should have correct properties', () => { + const error = new ApiError('Test error', 500, '{"error": "details"}'); + + assert.equal(error.message, 'Test error'); + assert.equal(error.statusCode, 500); + assert.equal(error.response, '{"error": "details"}'); + assert.equal(error.name, 'ApiError'); + assert.instanceOf(error, Error); + }); + + it('should work without response parameter', () => { + const error = new ApiError('Test error', 400); + + assert.equal(error.message, 'Test error'); + assert.equal(error.statusCode, 400); + assert.isUndefined(error.response); + }); +}); + +describe('ProApiClient request format', () => { + let fetchStub: sinon.SinonStub; + + afterEach(() => { + if (fetchStub) { + fetchStub.restore(); + } + }); + + it('should send correct headers', async () => { + let capturedHeaders: HeadersInit | undefined; + + fetchStub = sinon.stub(global, 'fetch').callsFake(async (url, options) => { + capturedHeaders = options?.headers; + return { + ok: true, + status: 200, + text: async () => JSON.stringify({ type: 'result', code: 'var a;', sourceMap: '' }) + } as Response; + }); + + const client = new ProApiClient({ apiToken: 'my-api-token' }); + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + const headers = capturedHeaders as Record; + assert.equal(headers['Content-Type'], 'application/json'); + assert.equal(headers['Accept'], 'application/x-ndjson'); + assert.equal(headers['Authorization'], 'Bearer my-api-token'); + }); + + it('should send correct request body', async () => { + let capturedBody: string | undefined; + + fetchStub = sinon.stub(global, 'fetch').callsFake(async (url, options) => { + capturedBody = options?.body as string; + return { + ok: true, + status: 200, + text: async () => JSON.stringify({ type: 'result', code: 'var a;', sourceMap: '' }) + } as Response; + }); + + const client = new ProApiClient({ apiToken: 'test-token' }); + await client.obfuscate('const a = 1;', { + vmObfuscation: true, + compact: true, + stringArray: false + }); + + const body = JSON.parse(capturedBody!); + assert.equal(body.code, 'const a = 1;'); + assert.deepEqual(body.options, { + vmObfuscation: true, + compact: true, + stringArray: false + }); + }); + + it('should use POST method', async () => { + let capturedMethod: string | undefined; + + fetchStub = sinon.stub(global, 'fetch').callsFake(async (url, options) => { + capturedMethod = options?.method; + return { + ok: true, + status: 200, + text: async () => JSON.stringify({ type: 'result', code: 'var a;', sourceMap: '' }) + } as Response; + }); + + const client = new ProApiClient({ apiToken: 'test-token' }); + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.equal(capturedMethod, 'POST'); + }); + + it('should use custom timeout', async () => { + let signalReceived = false; + + fetchStub = sinon.stub(global, 'fetch').callsFake(async (url, options) => { + signalReceived = options?.signal !== undefined; + return { + ok: true, + status: 200, + text: async () => JSON.stringify({ type: 'result', code: 'var a;', sourceMap: '' }) + } as Response; + }); + + const client = new ProApiClient({ apiToken: 'test-token', timeout: 60000 }); + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.isTrue(signalReceived); + }); +}); From d7114b750befa655d60aa8d37fc682c96adb3a0a Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Sun, 7 Dec 2025 00:02:57 +0400 Subject: [PATCH 26/87] Don't run tests on build --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9d7bc9be3..197ba0f58 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,7 @@ "scripts": { "start": "yarn run watch", "webpack:prod": "webpack --config ./webpack/webpack.node.config.js --config ./webpack/webpack.browser.config.js --mode production", - "build": "yarn run webpack:prod && yarn run eslint && yarn test", + "build": "yarn run webpack:prod && yarn run eslint", "build:typings": "rm -rf ./typings && tsc --project src/tsconfig.typings.json", "watch": "webpack --config ./webpack/webpack.node.config.js --mode development --watch", "test:dev": "ts-node --type-check test/dev/dev.ts", From 4ac336812206d92bdcd9542b1b1f88881fce290b Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sun, 7 Dec 2025 12:42:47 +0400 Subject: [PATCH 27/87] Version 5.0.1 (#1344) --- .github/workflows/ci.yml | 5 +- CHANGELOG.md | 4 + CLAUDE.md | 3 +- README.md | 1 - package.json | 12 +- src/JavaScriptObfuscator.ts | 6 + src/enums/logger/LoggingMessage.ts | 6 +- src/interfaces/logger/ILogger.ts | 6 + src/logger/Logger.ts | 7 + src/pro-api/constants.ts | 5 + src/utils/AdvertisementUtils.ts | 228 ++++++++++++++++++ test/index.spec.ts | 1 + .../utils/AdvertisementUtils.spec.ts | 213 ++++++++++++++++ yarn.lock | 102 +++++++- 14 files changed, 576 insertions(+), 23 deletions(-) create mode 100644 src/pro-api/constants.ts create mode 100644 src/utils/AdvertisementUtils.ts create mode 100644 test/unit-tests/utils/AdvertisementUtils.spec.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bb2352bf..635547b33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: JavaScript Obfuscator CI on: push: - branches: [master] + branches: [master, release-**] pull_request: - branches: [master] + branches: [master, release-**] schedule: - cron: '0 1 * * *' @@ -44,6 +44,7 @@ jobs: key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} - run: yarn install - run: yarn run build + - run: yarn run test:mocha-coverage - run: yarn run test:mocha-coverage:report - name: Coveralls uses: coverallsapp/github-action@master diff --git a/CHANGELOG.md b/CHANGELOG.md index f7f00f9e9..359185db7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log +v5.0.1 +--- +* Add JavaScript Obfuscator PRO advertisement message + v5.0.0 --- * Add JavaScript Obfuscator PRO support via calling its API diff --git a/CLAUDE.md b/CLAUDE.md index e55ec6c9c..3236bb57e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -4,7 +4,7 @@ **JavaScript Obfuscator** is a powerful, enterprise-grade code obfuscation tool for JavaScript and Node.js applications. It transforms readable JavaScript code into a protected, difficult-to-understand format while maintaining full functionality. The project is widely used for protecting intellectual property and preventing reverse engineering. -- **Version**: 4.1.1 +- **Version**: 5.0.0 - **Author**: Timofey Kachalov (@sanex3339) - **License**: BSD-2-Clause - **Repository**: https://github.com/javascript-obfuscator/javascript-obfuscator @@ -1423,7 +1423,6 @@ Use [grunt-contrib-obfuscator](https://github.com/javascript-obfuscator/grunt-co - **GitHub Issues**: Bug reports and feature requests - **GitHub Discussions**: Questions and general discussion -- **OpenCollective**: Financial support and sponsorship - **GitHub Sponsors**: Direct sponsorship ## License diff --git a/README.md b/README.md index 04313a8a5..5c2c4a38c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ #### You can support this project by donating: * (Github) https://github.com/sponsors/sanex3339 -* (OpenCollective) https://opencollective.com/javascript-obfuscator Huge thanks to all supporters! diff --git a/package.json b/package.json index 197ba0f58..9e91a042e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "5.0.0", + "version": "5.0.1", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", @@ -29,6 +29,7 @@ "chance": "1.1.13", "class-validator": "0.14.3", "commander": "12.1.0", + "conf": "15.0.2", "eslint-scope": "8.4.0", "eslint-visitor-keys": "4.2.1", "fast-deep-equal": "3.1.3", @@ -37,7 +38,6 @@ "md5": "2.3.0", "mkdirp": "3.0.1", "multimatch": "5.0.0", - "opencollective-postinstall": "2.0.3", "process": "0.11.10", "reflect-metadata": "0.2.2", "source-map-support": "0.5.21", @@ -124,7 +124,6 @@ "prettier:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"", "format": "yarn run prettier && yarn run eslint --fix", "git:addFiles": "git add .", - "postinstall": "opencollective-postinstall", "precommit": "yarn run eslint", "prepublishOnly": "yarn run build && yarn run build:typings", "prepare": "husky install" @@ -137,12 +136,5 @@ "Dmitry Zamotkin (https://github.com/zamotkin)" ], "license": "BSD-2-Clause", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/javascript-obfuscator" - }, - "collective": { - "url": "https://opencollective.com/javascript-obfuscator" - }, "packageManager": "yarn@1.22.21+sha512.ca75da26c00327d26267ce33536e5790f18ebd53266796fbb664d2a4a5116308042dd8ee7003b276a20eace7d3c5561c3577bdd71bcb67071187af124779620a" } diff --git a/src/JavaScriptObfuscator.ts b/src/JavaScriptObfuscator.ts index f6f91a5dd..53381b977 100644 --- a/src/JavaScriptObfuscator.ts +++ b/src/JavaScriptObfuscator.ts @@ -28,6 +28,7 @@ import { ecmaVersion } from './constants/EcmaVersion'; import { ASTParserFacade } from './ASTParserFacade'; import { NodeGuards } from './node/NodeGuards'; import { Utils } from './utils/Utils'; +import { AdvertisementUtils } from './utils/AdvertisementUtils'; @injectable() export class JavaScriptObfuscator implements IJavaScriptObfuscator { @@ -157,6 +158,11 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator { * @returns {IObfuscationResult} */ public obfuscate(sourceCode: string): IObfuscationResult { + if (AdvertisementUtils.shouldShowAdvertisement()) { + this.logger.advertise(LoggingMessage.JavaScriptObfuscatorProAdFirstPart); + this.logger.advertise(LoggingMessage.JavaScriptObfuscatorProAdSecondPart); + } + if (typeof sourceCode !== 'string') { sourceCode = ''; } diff --git a/src/enums/logger/LoggingMessage.ts b/src/enums/logger/LoggingMessage.ts index 2a2ebe6af..1e7eaaa54 100644 --- a/src/enums/logger/LoggingMessage.ts +++ b/src/enums/logger/LoggingMessage.ts @@ -1,3 +1,5 @@ +import { proAdvertiseMessageFirstPart, proAdvertiseMessageSecondPart } from '../../pro-api/constants'; + export enum LoggingMessage { EmptySourceCode = 'Empty source code. Obfuscation canceled...', ObfuscationCompleted = 'Obfuscation completed. Total time: %s sec.', @@ -5,5 +7,7 @@ export enum LoggingMessage { RandomGeneratorSeed = 'Random generator seed: %s...', CodeTransformationStage = 'Code transformation stage: %s...', NodeTransformationStage = 'AST transformation stage: %s...', - Version = 'Version: %s' + Version = 'Version: %s', + JavaScriptObfuscatorProAdFirstPart = proAdvertiseMessageFirstPart, + JavaScriptObfuscatorProAdSecondPart = proAdvertiseMessageSecondPart } diff --git a/src/interfaces/logger/ILogger.ts b/src/interfaces/logger/ILogger.ts index f186f5029..3977ae814 100644 --- a/src/interfaces/logger/ILogger.ts +++ b/src/interfaces/logger/ILogger.ts @@ -18,4 +18,10 @@ export interface ILogger { * @param {string | number} value */ warn(loggingMessage: LoggingMessage, value?: string | number): void; + + /** + * @param {LoggingMessage} loggingMessage + * @param {string | number} value + */ + advertise(loggingMessage: LoggingMessage): void; } diff --git a/src/logger/Logger.ts b/src/logger/Logger.ts index 5b706cb16..31b07ed98 100644 --- a/src/logger/Logger.ts +++ b/src/logger/Logger.ts @@ -90,4 +90,11 @@ export class Logger implements ILogger { Logger.log(Logger.colorWarn, LoggingPrefix.Base, loggingMessage, value); } + + /** + * @param {LoggingMessage} loggingMessage + */ + public advertise(loggingMessage: LoggingMessage): void { + Logger.log(Logger.colorInfo, LoggingPrefix.Base, loggingMessage); + } } diff --git a/src/pro-api/constants.ts b/src/pro-api/constants.ts new file mode 100644 index 000000000..3a69e4f9e --- /dev/null +++ b/src/pro-api/constants.ts @@ -0,0 +1,5 @@ +export const proAdvertiseMessageFirstPart = `🛡️ JavaScript Obfuscator Pro is now available — with powerful Virtual Machine-based obfuscation +(bytecode virtualization, anti-decompilation, unique opcode and VM structure each compilation, and more).`; + +export const proAdvertiseMessageSecondPart = + '👉️ Get your API key at https://obfuscator.io and start using Virtual Machine obfuscation with javascript-obfuscator package.'; diff --git a/src/utils/AdvertisementUtils.ts b/src/utils/AdvertisementUtils.ts new file mode 100644 index 000000000..f9c5c6008 --- /dev/null +++ b/src/utils/AdvertisementUtils.ts @@ -0,0 +1,228 @@ +/** + * Utility class for managing PRO advertisement display + * - Limits display to first N times + * - Skips display in CI environments + * - Only works in Node.js (returns false in browser) + */ +export class AdvertisementUtils { + /** + * Maximum number of times to show the advertisement + */ + private static readonly maxDisplayCount: number = 5; + + /** + * Storage key for the display count + */ + private static readonly storageKey: string = 'adDisplayCount'; + + /** + * Storage key for the timestamp of first display + */ + private static readonly timestampKey: string = 'adFirstDisplayTime'; + + /** + * Reset period in milliseconds (3 days) + */ + private static readonly resetPeriodMs: number = 3 * 24 * 60 * 60 * 1000; + + /** + * Common CI environment variables to detect + */ + private static readonly ciEnvVars: string[] = [ + 'CI', + 'CONTINUOUS_INTEGRATION', + 'GITHUB_ACTIONS', + 'GITLAB_CI', + 'TRAVIS', + 'CIRCLECI', + 'JENKINS_URL', + 'HUDSON_URL', + 'TEAMCITY_VERSION', + 'BUILDKITE', + 'TF_BUILD', // Azure Pipelines + 'BITBUCKET_BUILD_NUMBER', + 'CODEBUILD_BUILD_ID', // AWS CodeBuild + 'DRONE', + 'HEROKU_TEST_RUN_ID', + 'NETLIFY', + 'VERCEL', + 'NOW_BUILDER', // Vercel (legacy) + 'RENDER', + 'CODESANDBOX_SSE', + 'STACKBLITZ' + ]; + + /** + * Cached conf instance + */ + private static config: any = null; + + /** + * Check if running in a CI environment + */ + public static isCI(): boolean { + if (!this.isNodeEnvironment()) { + return false; + } + + return this.ciEnvVars.some((envVar) => { + const value = process.env[envVar]; + + return value !== undefined && value !== '' && value !== '0' && value !== 'false'; + }); + } + + /** + * Check if advertisement should be displayed + * Returns true if: + * - Running in Node.js (not browser) + * - Not in CI environment + * - Display count is less than maxDisplayCount + * + * Also increments the display count if returning true + * + * In browser environments, always returns false + */ + public static shouldShowAdvertisement(): boolean { + // Don't show in browser - only Node.js CLI + if (!this.isNodeEnvironment()) { + return false; + } + + // Don't show in CI environments + if (this.isCI()) { + return false; + } + + if (!process.stdout.isTTY) { + return false; + } + + // Initialize config if needed + const config = this.getConfig(); + + if (!config) { + return false; + } + + // Check if reset period has passed (3 days) + const firstDisplayTime = this.getFirstDisplayTime(config); + const now = Date.now(); + + if (firstDisplayTime && now - firstDisplayTime >= this.resetPeriodMs) { + // Reset counter after 3 days + this.resetDisplayData(config); + } + + // Check display count + const count = this.getDisplayCount(config); + + if (count >= this.maxDisplayCount) { + return false; + } + + // Set first display time if not set + if (!firstDisplayTime || now - firstDisplayTime >= this.resetPeriodMs) { + this.setFirstDisplayTime(config, now); + } + + // Increment count for next time + this.setDisplayCount(config, count + 1); + + return true; + } + + /** + * Check if running in Node.js environment + */ + private static isNodeEnvironment(): boolean { + return typeof process !== 'undefined' && process.versions?.node !== undefined; + } + + /** + * Get or create conf instance + */ + private static getConfig(): any { + if (this.config) { + return this.config; + } + + if (typeof window === 'undefined') { + try { + // Dynamic import to avoid bundling in browser + // eslint-disable-next-line no-eval + const Conf = eval('require')('conf').default; + + this.config = new Conf({ + projectName: 'javascript-obfuscator' + }); + + return this.config; + } catch { + return null; + } + } + + return null; + } + + /** + * Get current display count from config + */ + private static getDisplayCount(config: any): number { + try { + const count = config.get(this.storageKey, 0); + + return typeof count === 'number' ? count : 0; + } catch { + return 0; + } + } + + /** + * Set display count in config + */ + private static setDisplayCount(config: any, count: number): void { + try { + config.set(this.storageKey, count); + } catch { + // Ignore errors + } + } + + /** + * Get first display timestamp from config + */ + private static getFirstDisplayTime(config: any): number | null { + try { + const timestamp = config.get(this.timestampKey, null); + + return typeof timestamp === 'number' ? timestamp : null; + } catch { + return null; + } + } + + /** + * Set first display timestamp in config + */ + private static setFirstDisplayTime(config: any, timestamp: number): void { + try { + config.set(this.timestampKey, timestamp); + } catch { + // Ignore errors + } + } + + /** + * Reset display data (count and timestamp) + */ + private static resetDisplayData(config: any): void { + try { + config.delete(this.storageKey); + config.delete(this.timestampKey); + } catch { + // Ignore errors + } + } +} diff --git a/test/index.spec.ts b/test/index.spec.ts index 4c585766c..f156f832e 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -42,6 +42,7 @@ import './unit-tests/storages/identifier-names-cache/PropertyIdentifierNamesCach import './unit-tests/storages/string-array-transformers/literal-nodes-cache/LiteralNodesCacheStorage.spec'; import './unit-tests/storages/string-array-transformers/string-array/StringArrayStorage.spec'; import './unit-tests/storages/string-array-transformers/visited-lexical-scope-nodes-stack/VisitedLexicalScopeNodesStackStorage.spec'; +import './unit-tests/utils/AdvertisementUtils.spec'; import './unit-tests/utils/ArrayUtils.spec'; import './unit-tests/utils/CryptUtils.spec'; import './unit-tests/utils/CryptUtilsStringArray.spec'; diff --git a/test/unit-tests/utils/AdvertisementUtils.spec.ts b/test/unit-tests/utils/AdvertisementUtils.spec.ts new file mode 100644 index 000000000..b110e2f19 --- /dev/null +++ b/test/unit-tests/utils/AdvertisementUtils.spec.ts @@ -0,0 +1,213 @@ +import { assert } from 'chai'; + +import { AdvertisementUtils } from '../../../src/utils/AdvertisementUtils'; + +describe('AdvertisementUtils', () => { + describe('isCI', () => { + const originalEnv = { ...process.env }; + + afterEach(() => { + // Restore original environment + process.env = { ...originalEnv }; + }); + + describe('Variant #1: CI environment variable set', () => { + it('should return true when CI=true', () => { + process.env.CI = 'true'; + assert.isTrue(AdvertisementUtils.isCI()); + }); + + it('should return true when CI=1', () => { + process.env.CI = '1'; + assert.isTrue(AdvertisementUtils.isCI()); + }); + + it('should return true when GITHUB_ACTIONS is set', () => { + process.env.GITHUB_ACTIONS = 'true'; + assert.isTrue(AdvertisementUtils.isCI()); + }); + + it('should return true when TRAVIS is set', () => { + process.env.TRAVIS = 'true'; + assert.isTrue(AdvertisementUtils.isCI()); + }); + + it('should return true when GITLAB_CI is set', () => { + process.env.GITLAB_CI = 'true'; + assert.isTrue(AdvertisementUtils.isCI()); + }); + + it('should return true when JENKINS_URL is set', () => { + process.env.JENKINS_URL = 'http://jenkins.example.com'; + assert.isTrue(AdvertisementUtils.isCI()); + }); + }); + + describe('Variant #2: CI environment variable not set or false', () => { + beforeEach(() => { + // Clear all CI-related env vars + delete process.env.CI; + delete process.env.CONTINUOUS_INTEGRATION; + delete process.env.GITHUB_ACTIONS; + delete process.env.GITLAB_CI; + delete process.env.TRAVIS; + delete process.env.CIRCLECI; + delete process.env.JENKINS_URL; + delete process.env.BUILDKITE; + delete process.env.TF_BUILD; + }); + + it('should return false when no CI env vars are set', () => { + assert.isFalse(AdvertisementUtils.isCI()); + }); + + it('should return false when CI=false', () => { + process.env.CI = 'false'; + assert.isFalse(AdvertisementUtils.isCI()); + }); + + it('should return false when CI=0', () => { + process.env.CI = '0'; + assert.isFalse(AdvertisementUtils.isCI()); + }); + + it('should return false when CI is empty string', () => { + process.env.CI = ''; + assert.isFalse(AdvertisementUtils.isCI()); + }); + }); + }); + + describe('shouldShowAdvertisement', () => { + const originalEnv = { ...process.env }; + const originalIsTTY = process.stdout.isTTY; + + afterEach(() => { + process.env = { ...originalEnv }; + process.stdout.isTTY = originalIsTTY; + }); + + describe('Variant #1: non-TTY environment', () => { + it('should return false when stdout is not a TTY', () => { + process.stdout.isTTY = false; + // Clear CI env vars + delete process.env.CI; + assert.isFalse(AdvertisementUtils.shouldShowAdvertisement()); + }); + }); + + describe('Variant #2: CI environment', () => { + it('should return false in CI environment', () => { + process.stdout.isTTY = true; + process.env.CI = 'true'; + assert.isFalse(AdvertisementUtils.shouldShowAdvertisement()); + }); + }); + + describe('Variant #3: display counter and reset', () => { + let config: any; + + before(() => { + // Get config instance using eval('require') - same as AdvertisementUtils + // conf is an ES Module, so we need to access .default + // eslint-disable-next-line no-eval + const Conf = eval('require')('conf').default; + config = new Conf({ projectName: 'javascript-obfuscator' }); + }); + + beforeEach(() => { + // Clear ad-related config before each test + config.delete('adDisplayCount'); + config.delete('adFirstDisplayTime'); + // Reset cached config in AdvertisementUtils + (AdvertisementUtils as any).config = null; + // Ensure TTY and non-CI environment + process.stdout.isTTY = true; + delete process.env.CI; + delete process.env.GITHUB_ACTIONS; + delete process.env.TRAVIS; + delete process.env.GITLAB_CI; + }); + + afterEach(() => { + // Clean up + config.delete('adDisplayCount'); + config.delete('adFirstDisplayTime'); + (AdvertisementUtils as any).config = null; + }); + + it('should return true for first 5 calls', () => { + for (let i = 0; i < 5; i++) { + assert.isTrue(AdvertisementUtils.shouldShowAdvertisement(), `Call ${i + 1} should return true`); + } + }); + + it('should return false after 5 calls', () => { + // Exhaust the counter + for (let i = 0; i < 5; i++) { + AdvertisementUtils.shouldShowAdvertisement(); + } + + // 6th call should return false + assert.isFalse(AdvertisementUtils.shouldShowAdvertisement()); + }); + + it('should increment counter on each call', () => { + AdvertisementUtils.shouldShowAdvertisement(); + assert.strictEqual(config.get('adDisplayCount'), 1); + + AdvertisementUtils.shouldShowAdvertisement(); + assert.strictEqual(config.get('adDisplayCount'), 2); + + AdvertisementUtils.shouldShowAdvertisement(); + assert.strictEqual(config.get('adDisplayCount'), 3); + }); + + it('should set first display timestamp on first call', () => { + const beforeTime = Date.now(); + AdvertisementUtils.shouldShowAdvertisement(); + const afterTime = Date.now(); + + const timestamp = config.get('adFirstDisplayTime'); + assert.isNumber(timestamp); + assert.isAtLeast(timestamp, beforeTime); + assert.isAtMost(timestamp, afterTime); + }); + + it('should reset counter after 3 days', () => { + // Exhaust counter + for (let i = 0; i < 5; i++) { + AdvertisementUtils.shouldShowAdvertisement(); + } + assert.isFalse(AdvertisementUtils.shouldShowAdvertisement()); + + // Simulate 3 days passing by setting old timestamp + const threeDaysAgo = Date.now() - 3 * 24 * 60 * 60 * 1000 - 1000; + config.set('adFirstDisplayTime', threeDaysAgo); + // Reset cached config + (AdvertisementUtils as any).config = null; + + // Should return true again after reset + assert.isTrue(AdvertisementUtils.shouldShowAdvertisement()); + // Counter should be reset to 1 + assert.strictEqual(config.get('adDisplayCount'), 1); + }); + + it('should not reset counter before 3 days', () => { + // Exhaust counter + for (let i = 0; i < 5; i++) { + AdvertisementUtils.shouldShowAdvertisement(); + } + + // Simulate 2 days passing (less than 3 days) + const twoDaysAgo = Date.now() - 2 * 24 * 60 * 60 * 1000; + config.set('adFirstDisplayTime', twoDaysAgo); + // Reset cached config + (AdvertisementUtils as any).config = null; + + // Should still return false + assert.isFalse(AdvertisementUtils.shouldShowAdvertisement()); + }); + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index 93f02ef83..c8a36b504 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1053,6 +1053,13 @@ ajv-formats@^2.1.1: dependencies: ajv "^8.0.0" +ajv-formats@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/ajv-formats/-/ajv-formats-3.0.1.tgz#3d5dc762bca17679c3c2ea7e90ad6b7532309578" + integrity sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ== + dependencies: + ajv "^8.0.0" + ajv-keywords@^3.5.2: version "3.5.2" resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" @@ -1085,7 +1092,7 @@ ajv@^8.0.0: require-from-string "^2.0.2" uri-js "^4.2.2" -ajv@^8.9.0: +ajv@^8.17.1, ajv@^8.9.0: version "8.17.1" resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.17.1.tgz#37d9a5c776af6bc92d7f4f9510eba4c0a60d11a6" integrity sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g== @@ -1273,6 +1280,14 @@ atob@^2.1.2: resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== +atomically@^2.0.3: + version "2.1.0" + resolved "https://registry.yarnpkg.com/atomically/-/atomically-2.1.0.tgz#5a3ce8ea5ab57b65df589a3b63ef7b753cc0af07" + integrity sha512-+gDffFXRW6sl/HCwbta7zK4uNqbPjv4YJEAdz7Vu+FLQHe77eZ4bvbJGi4hE0QPeJlMYMA3piXEr1UL3dAwx7Q== + dependencies: + stubborn-fs "^2.0.0" + when-exit "^2.1.4" + available-typed-arrays@^1.0.0, available-typed-arrays@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.2.tgz" @@ -1622,6 +1637,21 @@ concat-map@0.0.1: resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz" integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= +conf@15.0.2: + version "15.0.2" + resolved "https://registry.yarnpkg.com/conf/-/conf-15.0.2.tgz#b983be81227a304b9f885fde6c86c7fe5902dc9d" + integrity sha512-JBSrutapCafTrddF9dH3lc7+T2tBycGF4uPkI4Js+g4vLLEhG6RZcFi3aJd5zntdf5tQxAejJt8dihkoQ/eSJw== + dependencies: + ajv "^8.17.1" + ajv-formats "^3.0.1" + atomically "^2.0.3" + debounce-fn "^6.0.0" + dot-prop "^10.0.0" + env-paths "^3.0.0" + json-schema-typed "^8.0.1" + semver "^7.7.2" + uint8array-extras "^1.5.0" + config-chain@^1.1.13: version "1.1.13" resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.13.tgz#fad0795aa6a6cdaff9ed1b68e9dff94372c232f4" @@ -1740,6 +1770,13 @@ data-view-byte-offset@^1.0.1: es-errors "^1.3.0" is-data-view "^1.0.1" +debounce-fn@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/debounce-fn/-/debounce-fn-6.0.0.tgz#558169aed853eb3cf3a17c0a2438e1a91a7ba44f" + integrity sha512-rBMW+F2TXryBwB54Q0d8drNEI+TfoS9JpNTAoVpukbWEhjXQq4rySFYLaqXMFXwdv61Zb2OHtj5bviSoimqxRQ== + dependencies: + mimic-function "^5.0.0" + debug@^3.2.7: version "3.2.7" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a" @@ -1885,6 +1922,13 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" +dot-prop@^10.0.0: + version "10.1.0" + resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-10.1.0.tgz#91dbeb6771a9d2c31eab11ade3fdb1d83c4376c4" + integrity sha512-MVUtAugQMOff5RnBy2d9N31iG0lNwg1qAoAOn7pOK5wf94WIaE3My2p3uwTQuvS2AcqchkcR3bHByjaM0mmi7Q== + dependencies: + type-fest "^5.0.0" + dunder-proto@^1.0.0, dunder-proto@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/dunder-proto/-/dunder-proto-1.0.1.tgz#d7ae667e1dc83482f8b70fd0f6eefc50da30f58a" @@ -1940,6 +1984,11 @@ enhanced-resolve@^5.17.3: graceful-fs "^4.2.4" tapable "^2.2.0" +env-paths@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-3.0.0.tgz#2f1e89c2f6dbd3408e1b1711dd82d62e317f58da" + integrity sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A== + envinfo@^7.14.0: version "7.19.0" resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.19.0.tgz#b4b4507a27e9900b0175f556167fd3a95f8623f1" @@ -3576,6 +3625,11 @@ json-schema-traverse@^1.0.0: resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug== +json-schema-typed@^8.0.1: + version "8.0.2" + resolved "https://registry.yarnpkg.com/json-schema-typed/-/json-schema-typed-8.0.2.tgz#e98ee7b1899ff4a184534d1f167c288c66bbeff4" + integrity sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA== + json-stable-stringify-without-jsonify@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz" @@ -3777,6 +3831,11 @@ mime-types@^2.1.27: dependencies: mime-db "1.44.0" +mimic-function@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/mimic-function/-/mimic-function-5.0.1.tgz#acbe2b3349f99b9deaca7fb70e48b83e94e67076" + integrity sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA== + min-indent@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869" @@ -4112,11 +4171,6 @@ once@^1.3.0: dependencies: wrappy "1" -opencollective-postinstall@2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259" - integrity sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q== - optionator@^0.8.1: version "0.8.3" resolved "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz" @@ -4634,7 +4688,7 @@ semver@^7.3.5: dependencies: lru-cache "^6.0.0" -semver@^7.5.3, semver@^7.5.4, semver@^7.6.0, semver@^7.6.3: +semver@^7.5.3, semver@^7.5.4, semver@^7.6.0, semver@^7.6.3, semver@^7.7.2: version "7.7.3" resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.3.tgz#4b5f4143d007633a8dc671cd0a6ef9147b8bb946" integrity sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q== @@ -5018,6 +5072,18 @@ strip-json-comments@^3.1.1: resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== +stubborn-fs@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/stubborn-fs/-/stubborn-fs-2.0.0.tgz#628750f81c51c44c04ef50fc70ed4d1caea4f1e9" + integrity sha512-Y0AvSwDw8y+nlSNFXMm2g6L51rBGdAQT20J3YSOqxC53Lo3bjWRtr2BKcfYoAf352WYpsZSTURrA0tqhfgudPA== + dependencies: + stubborn-utils "^1.0.1" + +stubborn-utils@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/stubborn-utils/-/stubborn-utils-1.0.2.tgz#0d9c58ab550f40936235056c7ea6febd925c4d41" + integrity sha512-zOh9jPYI+xrNOyisSelgym4tolKTJCQd5GBhK0+0xJvcYDcwlOoxF/rnFKQ2KRZknXSG9jWAp66fwP6AxN9STg== + supports-color@^5.3.0: version "5.5.0" resolved "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz" @@ -5066,6 +5132,11 @@ synckit@^0.9.1: "@pkgr/core" "^0.1.0" tslib "^2.6.2" +tagged-tag@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/tagged-tag/-/tagged-tag-1.0.0.tgz#a0b5917c2864cba54841495abfa3f6b13edcf4d6" + integrity sha512-yEFYrVhod+hdNyx7g5Bnkkb0G6si8HJurOoOEgC8B/O0uXLHlaey/65KRv6cuWBNhBgHKAROVpc7QyYqE5gFng== + tapable@^2.2.0: version "2.2.0" resolved "https://registry.npmjs.org/tapable/-/tapable-2.2.0.tgz" @@ -5236,6 +5307,13 @@ type-fest@^0.8.0, type-fest@^0.8.1: resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== +type-fest@^5.0.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-5.3.0.tgz#9422125b3094b1087d8446ba151b72fb9f39411a" + integrity sha512-d9CwU93nN0IA1QL+GSNDdwLAu1Ew5ZjTwupvedwg3WdfoH6pIDvYQ2hV0Uc2nKBLPq7NB5apCx57MLS5qlmO5g== + dependencies: + tagged-tag "^1.0.0" + typed-array-buffer@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/typed-array-buffer/-/typed-array-buffer-1.0.3.tgz#a72395450a4869ec033fd549371b47af3a2ee536" @@ -5293,6 +5371,11 @@ typescript@5.9.3: resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.9.3.tgz#5b4f59e15310ab17a216f5d6cf53ee476ede670f" integrity sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw== +uint8array-extras@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/uint8array-extras/-/uint8array-extras-1.5.0.tgz#10d2a85213de3ada304fea1c454f635c73839e86" + integrity sha512-rvKSBiC5zqCCiDZ9kAOszZcDvdAHwwIKJG33Ykj43OKcWsnmcBRL09YTU4nOeHZ8Y2a7l1MgTd08SBe9A8Qj6A== + unbox-primitive@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.1.0.tgz#8d9d2c9edeea8460c7f35033a88867944934d1e2" @@ -5449,6 +5532,11 @@ webpack@5.102.1: watchpack "^2.4.4" webpack-sources "^3.3.3" +when-exit@^2.1.4: + version "2.1.5" + resolved "https://registry.yarnpkg.com/when-exit/-/when-exit-2.1.5.tgz#53fa4ffa2ba4c792213fb6617eb7d08f0dcb1a9f" + integrity sha512-VGkKJ564kzt6Ms1dbgPP/yuIoQCrsFAnRbptpC5wOEsDaNsbCB2bnfnaA8i/vRs5tjUSEOtIuvl9/MyVsvQZCg== + which-boxed-primitive@^1.1.0, which-boxed-primitive@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.1.1.tgz#d76ec27df7fa165f18d5808374a5fe23c29b176e" From 6866396e9a74dd1d5d8c38f169a40889802907da Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Sat, 13 Dec 2025 18:43:52 +0400 Subject: [PATCH 28/87] Add `version` parameter to the `apiConfig` to use different versions of JavaScript Obfuscator Pro via API (#1353) --- CHANGELOG.md | 4 + README.md | 19 ++ package.json | 2 +- src/interfaces/pro-api/IProApiClient.ts | 6 + src/pro-api/ProApiClient.ts | 13 +- test/index.spec.ts | 1 + test/unit-tests/pro-api/ProApiClient.spec.ts | 254 +++++++++++++++++++ 7 files changed, 296 insertions(+), 3 deletions(-) create mode 100644 test/unit-tests/pro-api/ProApiClient.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 359185db7..f0f9804bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log +v5.1.0 +--- +* Add `version` parameter to the `apiConfig` to use different versions JavaScript Obfuscator Pro via API + v5.0.1 --- * Add JavaScript Obfuscator PRO advertisement message diff --git a/README.md b/README.md index 5c2c4a38c..048be086f 100644 --- a/README.md +++ b/README.md @@ -308,6 +308,7 @@ console.log(result.getObfuscatedCode()); * `apiConfig` (`Object`) – Pro API configuration: * `apiToken` (`string`, required) – your API token from obfuscator.io * `timeout` (`number`, optional) – request timeout in ms (default: `300000` - 5 minutes) + * `version` (`string`, optional) – JavaScript Obfuscator Pro version to use (e.g., `'5.0.0-beta.20'`). Defaults to latest version if not specified. * `onProgress` (`function`, optional) – callback for progress updates during obfuscation **Returns:** `Promise` @@ -317,6 +318,24 @@ console.log(result.getObfuscatedCode()); - API token is invalid or expired - API request fails +### Pro API with Specific Version + +You can specify which obfuscator version to use via the `version` option: + +```javascript +const result = await JavaScriptObfuscator.obfuscatePro( + sourceCode, + { + vmObfuscation: true, + vmObfuscationThreshold: 1 + }, + { + apiToken: 'your_javascript_obfuscator_pro_api_token', + version: '5.0.0-beta.20' // Use specific version + } +); +``` + ### Pro API with Progress Updates The API uses streaming mode to provide real-time progress updates during obfuscation: diff --git a/package.json b/package.json index 9e91a042e..ba8f9d0fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "5.0.1", + "version": "5.1.0", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", diff --git a/src/interfaces/pro-api/IProApiClient.ts b/src/interfaces/pro-api/IProApiClient.ts index 50b55ef69..46712c03e 100644 --- a/src/interfaces/pro-api/IProApiClient.ts +++ b/src/interfaces/pro-api/IProApiClient.ts @@ -40,6 +40,12 @@ export interface IProApiConfig { * Request timeout in milliseconds (default: 300000 - 5 minutes) */ timeout?: number; + + /** + * Obfuscator version to use (e.g., '5.0.0-beta.20') + * Defaults to latest version if not specified + */ + version?: string; } /** diff --git a/src/pro-api/ProApiClient.ts b/src/pro-api/ProApiClient.ts index 2951cda1d..54edd4d04 100644 --- a/src/pro-api/ProApiClient.ts +++ b/src/pro-api/ProApiClient.ts @@ -26,12 +26,14 @@ export class ProApiClient { private readonly config: { apiToken: string; timeout: number; + version?: string; }; public constructor(config: IProApiConfig) { this.config = { apiToken: config.apiToken, - timeout: config.timeout ?? DEFAULT_TIMEOUT + timeout: config.timeout ?? DEFAULT_TIMEOUT, + version: config.version }; } @@ -73,8 +75,15 @@ export class ProApiClient { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), this.config.timeout); + // Build URL with optional version parameter + let url = API_URL; + + if (this.config.version) { + url = `${API_URL}?version=${encodeURIComponent(this.config.version)}`; + } + try { - const response = await fetch(API_URL, { + const response = await fetch(url, { method: 'POST', headers, body, diff --git a/test/index.spec.ts b/test/index.spec.ts index f156f832e..72d2887ba 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -33,6 +33,7 @@ import './unit-tests/node/node-utils/NodeUtils.spec'; import './unit-tests/node/numerical-expression-data-to-node-converter/NumericalExpressionDataToNodeConverter.spec'; import './unit-tests/options/Options.spec'; import './unit-tests/options/ValidationErrorsFormatter.spec'; +import './unit-tests/pro-api/ProApiClient.spec'; import './unit-tests/source-code/ObfuscationResult.spec'; import './unit-tests/source-code/SourceCode.spec'; import './unit-tests/storages/ArrayStorage.spec'; diff --git a/test/unit-tests/pro-api/ProApiClient.spec.ts b/test/unit-tests/pro-api/ProApiClient.spec.ts new file mode 100644 index 000000000..470222ee7 --- /dev/null +++ b/test/unit-tests/pro-api/ProApiClient.spec.ts @@ -0,0 +1,254 @@ +import 'reflect-metadata'; + +import { assert } from 'chai'; +import * as sinon from 'sinon'; + +import { ProApiClient } from '../../../src/pro-api/ProApiClient'; +import { IProApiConfig } from '../../../src/interfaces/pro-api/IProApiClient'; +import { ApiError } from '../../../src/pro-api/ApiError'; + +describe('ProApiClient', () => { + const API_URL = 'https://obfuscator.io/api/v1/obfuscate'; + + let fetchStub: sinon.SinonStub; + + beforeEach(() => { + fetchStub = sinon.stub(global, 'fetch'); + }); + + afterEach(() => { + fetchStub.restore(); + }); + + describe('constructor', () => { + describe('Variant #1: basic configuration', () => { + it('should create client with required apiToken', () => { + const config: IProApiConfig = { + apiToken: 'test-token' + }; + + const client = new ProApiClient(config); + + assert.isDefined(client); + }); + }); + + describe('Variant #2: configuration with all options', () => { + it('should create client with all configuration options', () => { + const config: IProApiConfig = { + apiToken: 'test-token', + timeout: 60000, + version: '5.0.0-beta.20' + }; + + const client = new ProApiClient(config); + + assert.isDefined(client); + }); + }); + }); + + describe('obfuscate', () => { + describe('Variant #1: vmObfuscation validation', () => { + it('should throw ApiError when vmObfuscation is not enabled', async () => { + const config: IProApiConfig = { + apiToken: 'test-token' + }; + const client = new ProApiClient(config); + + try { + await client.obfuscate('const a = 1;', { compact: true }); + assert.fail('Should have thrown ApiError'); + } catch (error) { + assert.instanceOf(error, ApiError); + assert.include((error as ApiError).message, 'vmObfuscation'); + } + }); + }); + + describe('Variant #2: URL without version parameter', () => { + it('should call API without version query parameter when version is not specified', async () => { + const config: IProApiConfig = { + apiToken: 'test-token' + }; + const client = new ProApiClient(config); + + const mockResponse = new Response( + JSON.stringify({ type: 'result', code: 'obfuscated', sourceMap: '' }), + { status: 200 } + ); + fetchStub.resolves(mockResponse); + + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.isTrue(fetchStub.calledOnce); + const calledUrl = fetchStub.firstCall.args[0]; + assert.strictEqual(calledUrl, API_URL); + }); + }); + + describe('Variant #3: URL with version parameter', () => { + it('should call API with version query parameter when version is specified', async () => { + const config: IProApiConfig = { + apiToken: 'test-token', + version: '5.0.0-beta.20' + }; + const client = new ProApiClient(config); + + const mockResponse = new Response( + JSON.stringify({ type: 'result', code: 'obfuscated', sourceMap: '' }), + { status: 200 } + ); + fetchStub.resolves(mockResponse); + + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.isTrue(fetchStub.calledOnce); + const calledUrl = fetchStub.firstCall.args[0]; + assert.strictEqual(calledUrl, `${API_URL}?version=5.0.0-beta.20`); + }); + }); + + describe('Variant #4: version parameter encoding', () => { + it('should properly encode version parameter in URL', async () => { + const config: IProApiConfig = { + apiToken: 'test-token', + version: '5.0.0-beta.22' + }; + const client = new ProApiClient(config); + + const mockResponse = new Response( + JSON.stringify({ type: 'result', code: 'obfuscated', sourceMap: '' }), + { status: 200 } + ); + fetchStub.resolves(mockResponse); + + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.isTrue(fetchStub.calledOnce); + const calledUrl = fetchStub.firstCall.args[0]; + // encodeURIComponent('5.0.0-beta.22') === '5.0.0-beta.22' (no special chars) + assert.strictEqual(calledUrl, `${API_URL}?version=5.0.0-beta.22`); + }); + }); + + describe('Variant #5: authorization header', () => { + it('should include Authorization header with Bearer token', async () => { + const config: IProApiConfig = { + apiToken: 'my-secret-token', + version: '5.0.0-beta.15' + }; + const client = new ProApiClient(config); + + const mockResponse = new Response( + JSON.stringify({ type: 'result', code: 'obfuscated', sourceMap: '' }), + { status: 200 } + ); + fetchStub.resolves(mockResponse); + + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.isTrue(fetchStub.calledOnce); + const calledOptions = fetchStub.firstCall.args[1]; + assert.strictEqual(calledOptions.headers['Authorization'], 'Bearer my-secret-token'); + }); + }); + + describe('Variant #6: successful obfuscation result', () => { + it('should return obfuscation result with code and sourceMap', async () => { + const config: IProApiConfig = { + apiToken: 'test-token', + version: '5.0.0-beta.20' + }; + const client = new ProApiClient(config); + + const mockResponse = new Response( + JSON.stringify({ type: 'result', code: 'var _0x123=1;', sourceMap: '{"version":3}' }), + { status: 200 } + ); + fetchStub.resolves(mockResponse); + + const result = await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.strictEqual(result.getObfuscatedCode(), 'var _0x123=1;'); + assert.strictEqual(result.getSourceMap(), '{"version":3}'); + }); + }); + + describe('Variant #7: chunked response', () => { + it('should reassemble chunked response correctly', async () => { + const config: IProApiConfig = { + apiToken: 'test-token', + version: '5.0.0-beta.10' + }; + const client = new ProApiClient(config); + + const chunks = [ + JSON.stringify({ type: 'progress', message: 'Processing...' }), + JSON.stringify({ type: 'chunk', field: 'code', data: 'var _0x', index: 0, total: 2 }), + JSON.stringify({ type: 'chunk', field: 'code', data: '123=1;', index: 1, total: 2 }), + JSON.stringify({ type: 'chunk_end', sourceMap: '' }) + ].join('\n'); + + const mockResponse = new Response(chunks, { status: 200 }); + fetchStub.resolves(mockResponse); + + const result = await client.obfuscate('const a = 1;', { vmObfuscation: true }); + + assert.strictEqual(result.getObfuscatedCode(), 'var _0x123=1;'); + }); + }); + + describe('Variant #8: API error response', () => { + it('should throw ApiError when API returns error message', async () => { + const config: IProApiConfig = { + apiToken: 'invalid-token', + version: '5.0.0-beta.20' + }; + const client = new ProApiClient(config); + + const mockResponse = new Response( + JSON.stringify({ type: 'error', message: 'Invalid API token' }), + { status: 401 } + ); + fetchStub.resolves(mockResponse); + + try { + await client.obfuscate('const a = 1;', { vmObfuscation: true }); + assert.fail('Should have thrown ApiError'); + } catch (error) { + assert.instanceOf(error, ApiError); + assert.include((error as ApiError).message, 'Invalid API token'); + } + }); + }); + + describe('Variant #9: progress callback', () => { + it('should call progress callback for progress messages', async () => { + const config: IProApiConfig = { + apiToken: 'test-token', + version: '5.0.0-beta.20' + }; + const client = new ProApiClient(config); + + const progressMessages: string[] = []; + const onProgress = (message: string) => { + progressMessages.push(message); + }; + + const chunks = [ + JSON.stringify({ type: 'progress', message: 'Validating...' }), + JSON.stringify({ type: 'progress', message: 'Obfuscating...' }), + JSON.stringify({ type: 'result', code: 'var a=1;', sourceMap: '' }) + ].join('\n'); + + const mockResponse = new Response(chunks, { status: 200 }); + fetchStub.resolves(mockResponse); + + await client.obfuscate('const a = 1;', { vmObfuscation: true }, onProgress); + + assert.deepEqual(progressMessages, ['Validating...', 'Obfuscating...']); + }); + }); + }); +}); From 12aff3cfd491c54abe3672b1aa6344ac86c54bad Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Tue, 16 Dec 2025 23:02:58 +0400 Subject: [PATCH 29/87] Optimize performance (#1355) --- .../BlockStatementControlFlowTransformer.ts | 15 +- .../AbstractControlFlowReplacer.ts | 26 ++- .../ClassFieldTransformer.ts | 8 +- .../ObjectExpressionKeysTransformer.ts | 173 +++++++----------- .../SplitStringTransformer.ts | 23 ++- .../TemplateLiteralTransformer.ts | 41 +++-- .../BasePropertiesExtractor.ts | 4 +- .../DirectivePlacementTransformer.ts | 18 +- ...StringArrayScopeCallsWrapperTransformer.ts | 7 +- .../StringArrayTransformer.ts | 26 ++- .../StringArrayStorage.ts | 61 +++--- src/utils/ArrayUtils.ts | 21 +-- src/utils/EscapeSequenceEncoder.ts | 8 +- 13 files changed, 208 insertions(+), 223 deletions(-) diff --git a/src/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.ts b/src/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.ts index 54a9356cd..9a09ca261 100644 --- a/src/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.ts +++ b/src/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.ts @@ -77,6 +77,10 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme * @returns {boolean} */ private static canTransformBlockStatementNode(blockStatementNode: ESTree.BlockStatement): boolean { + if (blockStatementNode.body.length <= 4) { + return false; + } + let canTransform: boolean = true; estraverse.traverse(blockStatementNode, { @@ -91,10 +95,6 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme } }); - if (blockStatementNode.body.length <= 4) { - canTransform = false; - } - return canTransform; } @@ -138,8 +138,11 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme const blockStatementBody: ESTree.Statement[] = blockStatementNode.body; const originalKeys: number[] = this.arrayUtils.createWithRange(blockStatementBody.length); const shuffledKeys: number[] = this.arrayUtils.shuffle(originalKeys); - const originalKeysIndexesInShuffledArray: number[] = originalKeys.map((key: number) => - shuffledKeys.indexOf(key) + const shuffledKeyToIndex: Map = new Map( + shuffledKeys.map((key: number, index: number) => [key, index]) + ); + const originalKeysIndexesInShuffledArray: number[] = originalKeys.map( + (key: number) => shuffledKeyToIndex.get(key)! ); const blockStatementControlFlowFlatteningCustomNode: ICustomNode< TInitialData diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts index e26e2fee1..f19f20be2 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts @@ -68,10 +68,10 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace * @returns {string} */ public generateStorageKey(controlFlowStorage: IControlFlowStorage): string { - const key: string = this.randomGenerator.getRandomString(5); + let key: string = this.randomGenerator.getRandomString(5); - if (controlFlowStorage.has(key)) { - return this.generateStorageKey(controlFlowStorage); + while (controlFlowStorage.has(key)) { + key = this.randomGenerator.getRandomString(5); } return key; @@ -91,9 +91,21 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace usingExistingIdentifierChance: number ): string { const controlFlowStorageId: string = controlFlowStorage.getStorageId(); - const storageKeysById: Map = - this.replacerDataByControlFlowStorageId.get(controlFlowStorageId) ?? new Map(); - const storageKeysForCurrentId: string[] = storageKeysById.get(replacerId) ?? []; + + let storageKeysById: Map | undefined = + this.replacerDataByControlFlowStorageId.get(controlFlowStorageId); + + if (!storageKeysById) { + storageKeysById = new Map(); + this.replacerDataByControlFlowStorageId.set(controlFlowStorageId, storageKeysById); + } + + let storageKeysForCurrentId: string[] | undefined = storageKeysById.get(replacerId); + + if (!storageKeysForCurrentId) { + storageKeysForCurrentId = []; + storageKeysById.set(replacerId, storageKeysForCurrentId); + } const shouldPickFromStorageKeysById = this.randomGenerator.getMathRandom() < usingExistingIdentifierChance && storageKeysForCurrentId.length; @@ -105,8 +117,6 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace const storageKey: string = this.generateStorageKey(controlFlowStorage); storageKeysForCurrentId.push(storageKey); - storageKeysById.set(replacerId, storageKeysForCurrentId); - this.replacerDataByControlFlowStorageId.set(controlFlowStorageId, storageKeysById); controlFlowStorage.set(storageKey, customNode); return storageKey; diff --git a/src/node-transformers/converting-transformers/ClassFieldTransformer.ts b/src/node-transformers/converting-transformers/ClassFieldTransformer.ts index a8ef3ac58..f19ca4e96 100644 --- a/src/node-transformers/converting-transformers/ClassFieldTransformer.ts +++ b/src/node-transformers/converting-transformers/ClassFieldTransformer.ts @@ -31,9 +31,9 @@ import { NodeGuards } from '../../node/NodeGuards'; @injectable() export class ClassFieldTransformer extends AbstractNodeTransformer { /** - * @type {string[]} + * @type {string} */ - private static readonly ignoredNames: string[] = ['constructor']; + private static readonly ignoredName: string = 'constructor'; /** * @param {IRandomGenerator} randomGenerator @@ -98,7 +98,7 @@ export class ClassFieldTransformer extends AbstractNodeTransformer { classFieldNode: ESTree.MethodDefinition | ESTree.PropertyDefinition, keyNode: ESTree.Identifier ): ESTree.MethodDefinition | ESTree.PropertyDefinition { - if (!ClassFieldTransformer.ignoredNames.includes(keyNode.name) && !classFieldNode.computed) { + if (keyNode.name !== ClassFieldTransformer.ignoredName && !classFieldNode.computed) { classFieldNode.computed = true; classFieldNode.key = NodeFactory.literalNode(keyNode.name); } @@ -117,7 +117,7 @@ export class ClassFieldTransformer extends AbstractNodeTransformer { ): ESTree.MethodDefinition | ESTree.PropertyDefinition { if ( typeof keyNode.value === 'string' && - !ClassFieldTransformer.ignoredNames.includes(keyNode.value) && + keyNode.value !== ClassFieldTransformer.ignoredName && !classFieldNode.computed ) { classFieldNode.computed = true; diff --git a/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts b/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts index 15ac0ae2b..e0addf21f 100644 --- a/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts +++ b/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts @@ -54,136 +54,105 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { } /** - * @param {ObjectExpression} objectExpressionNode - * @param {Node} objectExpressionParentNode - * @param {Statement} objectExpressionHostStatement - * @returns {boolean} + * Combined prohibition check result */ - private static isProhibitedObjectExpressionNode( - objectExpressionNode: ESTree.ObjectExpression, - objectExpressionParentNode: ESTree.Node, - objectExpressionHostStatement: ESTree.Statement - ): boolean { - return ( - ObjectExpressionKeysTransformer.isReferencedIdentifierName( - objectExpressionNode, - objectExpressionHostStatement - ) || - ObjectExpressionKeysTransformer.isProhibitedArrowFunctionExpression( - objectExpressionNode, - objectExpressionParentNode - ) || - ObjectExpressionKeysTransformer.isObjectExpressionWithCallExpression(objectExpressionNode) || - ObjectExpressionKeysTransformer.isProhibitedSequenceExpression( - objectExpressionNode, - objectExpressionHostStatement - ) - ); - } - - /** - * @param {Identifier | ThisExpression} node - * @returns {string} - */ - private static getReferencedIdentifierName(node: ESTree.Identifier | ESTree.ThisExpression): string { - if (NodeGuards.isIdentifierNode(node)) { - return node.name; - } else { - return ObjectExpressionKeysTransformer.thisIdentifierName; - } - } - - /** - * @param {ObjectExpression} objectExpressionNode - * @param {Node} objectExpressionHostNode - * @returns {boolean} - */ - private static isReferencedIdentifierName( + private static checkProhibitedPatterns( objectExpressionNode: ESTree.ObjectExpression, objectExpressionHostNode: ESTree.Node - ): boolean { + ): { hasReferencedIdentifier: boolean; hasCallExpression: boolean } { const identifierNamesSet: Set = new Set(); - let isReferencedIdentifierName: boolean = false; - let isCurrentNode: boolean = false; + let hasReferencedIdentifier: boolean = false; + let hasCallExpression: boolean = false; + let isInsideObjectExpression: boolean = false; - // should mark node as prohibited if identifier of node is referenced somewhere inside other nodes estraverse.traverse(objectExpressionHostNode, { + // eslint-disable-next-line complexity enter: (node: ESTree.Node): void | estraverse.VisitorOption => { if (node === objectExpressionNode) { - isCurrentNode = true; + isInsideObjectExpression = true; } - if (!NodeGuards.isIdentifierNode(node) && !NodeGuards.isThisExpressionNode(node)) { - return; + if (isInsideObjectExpression && !hasCallExpression) { + if (NodeGuards.isCallExpressionNode(node) || NodeGuards.isNewExpressionNode(node)) { + hasCallExpression = true; + } } - if (!isCurrentNode) { - identifierNamesSet.add(ObjectExpressionKeysTransformer.getReferencedIdentifierName(node)); + if (NodeGuards.isIdentifierNode(node) || NodeGuards.isThisExpressionNode(node)) { + const identifierName: string = NodeGuards.isIdentifierNode(node) + ? node.name + : ObjectExpressionKeysTransformer.thisIdentifierName; - return; + if (!isInsideObjectExpression) { + identifierNamesSet.add(identifierName); + } else if (identifierNamesSet.has(identifierName)) { + hasReferencedIdentifier = true; + } } - const hasReferencedIdentifierName: boolean = identifierNamesSet.has( - ObjectExpressionKeysTransformer.getReferencedIdentifierName(node) - ); - - if (hasReferencedIdentifierName) { - isReferencedIdentifierName = true; - + if (hasReferencedIdentifier && hasCallExpression) { return estraverse.VisitorOption.Break; } }, leave: (node: ESTree.Node): void | estraverse.VisitorOption => { if (node === objectExpressionNode) { - isCurrentNode = false; - - return estraverse.VisitorOption.Break; + isInsideObjectExpression = false; + if (hasReferencedIdentifier || hasCallExpression) { + return estraverse.VisitorOption.Break; + } } } }); - return isReferencedIdentifierName; + return { hasReferencedIdentifier, hasCallExpression }; } /** * @param {ObjectExpression} objectExpressionNode - * @param {Node} objectExpressionNodeParentNode + * @param {Node} objectExpressionParentNode + * @param {Statement} objectExpressionHostStatement * @returns {boolean} */ - private static isProhibitedArrowFunctionExpression( + private static isProhibitedObjectExpressionNode( objectExpressionNode: ESTree.ObjectExpression, - objectExpressionNodeParentNode: ESTree.Node + objectExpressionParentNode: ESTree.Node, + objectExpressionHostStatement: ESTree.Statement ): boolean { - return ( - NodeGuards.isArrowFunctionExpressionNode(objectExpressionNodeParentNode) && - objectExpressionNodeParentNode.body === objectExpressionNode + if ( + ObjectExpressionKeysTransformer.isProhibitedArrowFunctionExpression( + objectExpressionNode, + objectExpressionParentNode + ) || + ObjectExpressionKeysTransformer.isProhibitedSequenceExpression( + objectExpressionNode, + objectExpressionHostStatement + ) + ) { + return true; + } + + const { hasReferencedIdentifier, hasCallExpression } = ObjectExpressionKeysTransformer.checkProhibitedPatterns( + objectExpressionNode, + objectExpressionHostStatement ); + + return hasReferencedIdentifier || hasCallExpression; } /** * @param {ObjectExpression} objectExpressionNode + * @param {Node} objectExpressionNodeParentNode * @returns {boolean} */ - private static isObjectExpressionWithCallExpression(objectExpressionNode: ESTree.ObjectExpression): boolean { - let isCallExpressionLikeNodeFound: boolean = false; - - estraverse.traverse(objectExpressionNode, { - enter: (node: ESTree.Node): void | estraverse.VisitorOption => { - const isCallExpressionLikeNode = - NodeGuards.isCallExpressionNode(node) || NodeGuards.isNewExpressionNode(node); - - if (!isCallExpressionLikeNode) { - return; - } - - isCallExpressionLikeNodeFound = true; - - return estraverse.VisitorOption.Break; - } - }); - - return isCallExpressionLikeNodeFound; + private static isProhibitedArrowFunctionExpression( + objectExpressionNode: ESTree.ObjectExpression, + objectExpressionNodeParentNode: ESTree.Node + ): boolean { + return ( + NodeGuards.isArrowFunctionExpressionNode(objectExpressionNodeParentNode) && + objectExpressionNodeParentNode.body === objectExpressionNode + ); } /** @@ -263,32 +232,28 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { return objectExpressionNode; } - return this.applyObjectExpressionKeysExtractorsRecursive( - ObjectExpressionKeysTransformer.objectExpressionExtractorNames, - objectExpressionNode, - hostStatement - ); + return this.applyObjectExpressionKeysExtractorsRecursive(objectExpressionNode, hostStatement, 0); } /** - * @param {ObjectExpressionExtractor[]} objectExpressionExtractorNames * @param {ObjectExpression} objectExpressionNode * @param {Statement} hostStatement + * @param {number} extractorIndex * @returns {Node} */ private applyObjectExpressionKeysExtractorsRecursive( - objectExpressionExtractorNames: ObjectExpressionExtractor[], objectExpressionNode: ESTree.ObjectExpression, - hostStatement: ESTree.Statement + hostStatement: ESTree.Statement, + extractorIndex: number ): ESTree.Node { - const newObjectExpressionExtractorNames: ObjectExpressionExtractor[] = [...objectExpressionExtractorNames]; - const objectExpressionExtractor: ObjectExpressionExtractor | undefined = - newObjectExpressionExtractorNames.shift(); + const objectExpressionExtractorNames = ObjectExpressionKeysTransformer.objectExpressionExtractorNames; - if (!objectExpressionExtractor) { + if (extractorIndex >= objectExpressionExtractorNames.length) { return objectExpressionNode; } + const objectExpressionExtractor: ObjectExpressionExtractor = objectExpressionExtractorNames[extractorIndex]; + const { nodeToReplace, objectExpressionHostStatement: newObjectExpressionHostStatement, @@ -299,9 +264,9 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { ); this.applyObjectExpressionKeysExtractorsRecursive( - newObjectExpressionExtractorNames, newObjectExpressionNode, - newObjectExpressionHostStatement + newObjectExpressionHostStatement, + extractorIndex + 1 ); return nodeToReplace; diff --git a/src/node-transformers/converting-transformers/SplitStringTransformer.ts b/src/node-transformers/converting-transformers/SplitStringTransformer.ts index 2481cd35f..3ab4de010 100644 --- a/src/node-transformers/converting-transformers/SplitStringTransformer.ts +++ b/src/node-transformers/converting-transformers/SplitStringTransformer.ts @@ -152,26 +152,25 @@ export class SplitStringTransformer extends AbstractNodeTransformer { * @returns {BinaryExpression} */ private transformStringChunksToBinaryExpressionNode(chunks: string[]): ESTree.BinaryExpression { - const firstChunk: string | undefined = chunks.shift(); - const secondChunk: string | undefined = chunks.shift(); + const chunksLength: number = chunks.length; - if (!firstChunk || !secondChunk) { + if (chunksLength < 2) { throw new Error('First and second chunks values should not be empty'); } const initialBinaryExpressionNode: ESTree.BinaryExpression = NodeFactory.binaryExpressionNode( '+', - NodeFactory.literalNode(firstChunk), - NodeFactory.literalNode(secondChunk) + NodeFactory.literalNode(chunks[0]), + NodeFactory.literalNode(chunks[1]) ); - return chunks.reduce( - (binaryExpressionNode: ESTree.BinaryExpression, chunk: string) => { - const chunkLiteralNode: ESTree.Literal = NodeFactory.literalNode(chunk); + let result: ESTree.BinaryExpression = initialBinaryExpressionNode; - return NodeFactory.binaryExpressionNode('+', binaryExpressionNode, chunkLiteralNode); - }, - initialBinaryExpressionNode - ); + // Start from index 2 since we already used 0 and 1 + for (let i: number = 2; i < chunksLength; i++) { + result = NodeFactory.binaryExpressionNode('+', result, NodeFactory.literalNode(chunks[i])); + } + + return result; } } diff --git a/src/node-transformers/converting-transformers/TemplateLiteralTransformer.ts b/src/node-transformers/converting-transformers/TemplateLiteralTransformer.ts index ae684a594..9de8392a2 100644 --- a/src/node-transformers/converting-transformers/TemplateLiteralTransformer.ts +++ b/src/node-transformers/converting-transformers/TemplateLiteralTransformer.ts @@ -83,53 +83,60 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer { ): ESTree.Expression { const templateLiteralExpressions: ESTree.Expression[] = templateLiteralNode.expressions; - let nodes: ESTree.Expression[] = []; + const nodes: ESTree.Expression[] = []; + + const quasis: ESTree.TemplateElement[] = templateLiteralNode.quasis; + const quasisLength: number = quasis.length; + + for (let i: number = 0; i < quasisLength; i++) { + const templateElement: ESTree.TemplateElement = quasis[i]; - templateLiteralNode.quasis.forEach((templateElement: ESTree.TemplateElement) => { if (templateElement.value.cooked === undefined || templateElement.value.cooked === null) { - return; + continue; } nodes.push(NodeFactory.literalNode(templateElement.value.cooked)); - const expression: ESTree.Expression | undefined = templateLiteralExpressions.shift(); + const expression: ESTree.Expression | undefined = templateLiteralExpressions[i]; if (!expression) { - return; + continue; } nodes.push(expression); - }); + } - nodes = nodes.filter((node: ESTree.Literal | ESTree.Expression) => { + const filteredNodes: ESTree.Expression[] = nodes.filter((node: ESTree.Literal | ESTree.Expression) => { return !(NodeGuards.isLiteralNode(node) && node.value === ''); }); // since `+` is left-to-right associative // ensure the first node is a string if first/second isn't if ( - !TemplateLiteralTransformer.isLiteralNodeWithStringValue(nodes[0]) && - !TemplateLiteralTransformer.isLiteralNodeWithStringValue(nodes[1]) + !TemplateLiteralTransformer.isLiteralNodeWithStringValue(filteredNodes[0]) && + !TemplateLiteralTransformer.isLiteralNodeWithStringValue(filteredNodes[1]) ) { - nodes.unshift(NodeFactory.literalNode('')); + filteredNodes.unshift(NodeFactory.literalNode('')); } let transformedNode: ESTree.Node; - if (nodes.length > 1) { + if (filteredNodes.length > 1) { let root: ESTree.BinaryExpression = NodeFactory.binaryExpressionNode( '+', - nodes.shift(), - nodes.shift() + filteredNodes[0], + filteredNodes[1] ); - nodes.forEach((node: ESTree.Literal | ESTree.Expression) => { - root = NodeFactory.binaryExpressionNode('+', root, node); - }); + // Start from index 2 since we already used 0 and 1 + const filteredNodesLength: number = filteredNodes.length; + for (let i: number = 2; i < filteredNodesLength; i++) { + root = NodeFactory.binaryExpressionNode('+', root, filteredNodes[i]); + } transformedNode = root; } else { - transformedNode = nodes[0]; + transformedNode = filteredNodes[0]; } NodeUtils.parentizeAst(transformedNode); diff --git a/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts b/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts index 4eea6ae2e..b4c90440d 100644 --- a/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts +++ b/src/node-transformers/converting-transformers/object-expression-extractors/BasePropertiesExtractor.ts @@ -216,8 +216,10 @@ export class BasePropertiesExtractor implements IObjectExpressionExtractor { objectExpressionNode: ESTree.ObjectExpression, removablePropertyIds: number[] ): void { + const removablePropertyIdsSet: Set = new Set(removablePropertyIds); + objectExpressionNode.properties = objectExpressionNode.properties.filter( - (property: ESTree.Property | ESTree.SpreadElement, index: number) => !removablePropertyIds.includes(index) + (property: ESTree.Property | ESTree.SpreadElement, index: number) => !removablePropertyIdsSet.has(index) ); } } diff --git a/src/node-transformers/finalizing-transformers/DirectivePlacementTransformer.ts b/src/node-transformers/finalizing-transformers/DirectivePlacementTransformer.ts index 63f414774..8d25c0f93 100644 --- a/src/node-transformers/finalizing-transformers/DirectivePlacementTransformer.ts +++ b/src/node-transformers/finalizing-transformers/DirectivePlacementTransformer.ts @@ -127,21 +127,9 @@ export class DirectivePlacementTransformer extends AbstractNodeTransformer { // append new directive node at the top of lexical scope statements NodeAppender.prepend(nodeWithLexicalScopeStatements, [newDirectiveNode]); - // remove found directive node - let isDirectiveNodeRemoved: boolean = false; - estraverse.replace(nodeWithLexicalScopeStatements, { - enter: (node: ESTree.Node): estraverse.VisitorOption | undefined => { - if (isDirectiveNodeRemoved) { - return estraverse.VisitorOption.Break; - } - - if (node === directiveNode) { - isDirectiveNodeRemoved = true; - - return estraverse.VisitorOption.Remove; - } - } - }); + nodeWithLexicalScopeStatements.body = nodeWithLexicalScopeStatements.body.filter( + (node) => node !== directiveNode + ); } return nodeWithLexicalScopeStatements; diff --git a/src/node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer.ts b/src/node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer.ts index 68a7eb3ec..5aa19210a 100644 --- a/src/node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer.ts +++ b/src/node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer.ts @@ -140,15 +140,16 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo const { scopeCallsWrappersData } = stringArrayScopeCallsWrappersData; const scopeCallsWrappersDataLength: number = scopeCallsWrappersData.length; + const upperStringArrayCallsWrapperData = this.getUpperStringArrayCallsWrapperData( + stringArrayScopeCallsWrappersData + ); + /** * Iterates over each name of scope wrapper name * Reverse iteration appends wrappers at index `0` at the correct order */ for (let i = scopeCallsWrappersDataLength - 1; i >= 0; i--) { const stringArrayScopeCallsWrapperData = scopeCallsWrappersData[i]; - const upperStringArrayCallsWrapperData = this.getUpperStringArrayCallsWrapperData( - stringArrayScopeCallsWrappersData - ); this.getAndAppendStringArrayScopeCallsWrapperNode( lexicalScopeBodyNode, diff --git a/src/node-transformers/string-array-transformers/StringArrayTransformer.ts b/src/node-transformers/string-array-transformers/StringArrayTransformer.ts index 6c80f5733..6993f1f9c 100644 --- a/src/node-transformers/string-array-transformers/StringArrayTransformer.ts +++ b/src/node-transformers/string-array-transformers/StringArrayTransformer.ts @@ -328,18 +328,24 @@ export class StringArrayTransformer extends AbstractNodeTransformer { const nextScopeCallsWrapperParameterIndexesData: IStringArrayScopeCallsWrapperParameterIndexesData | null = this.getStringArrayCallsWrapperParameterIndexesData(); - stringArrayScopeCallsWrappersDataByEncoding[encoding] = { - encoding, - scopeCallsWrappersData: [ - ...stringArrayScopeCallsWrappersData, - { - name: nextScopeCallsWrapperName, - index: nextScopeCallsWrapperShiftedIndex, - parameterIndexesData: nextScopeCallsWrapperParameterIndexesData - } - ] + const newWrapperData: IStringArrayScopeCallsWrapperData = { + name: nextScopeCallsWrapperName, + index: nextScopeCallsWrapperShiftedIndex, + parameterIndexesData: nextScopeCallsWrapperParameterIndexesData }; + let encodingData = stringArrayScopeCallsWrappersDataByEncoding[encoding]; + + if (!encodingData) { + encodingData = { + encoding, + scopeCallsWrappersData: [newWrapperData] + }; + stringArrayScopeCallsWrappersDataByEncoding[encoding] = encodingData; + } else { + encodingData.scopeCallsWrappersData.push(newWrapperData); + } + this.stringArrayScopeCallsWrappersDataStorage.set( currentLexicalScopeBodyNode, stringArrayScopeCallsWrappersDataByEncoding diff --git a/src/storages/string-array-transformers/StringArrayStorage.ts b/src/storages/string-array-transformers/StringArrayStorage.ts index ebdd04075..d58c8586d 100644 --- a/src/storages/string-array-transformers/StringArrayStorage.ts +++ b/src/storages/string-array-transformers/StringArrayStorage.ts @@ -78,9 +78,9 @@ export class StringArrayStorage private readonly rc4Keys: string[]; /** - * @type {Map} + * @type {Map>} */ - private readonly rc4EncodedValuesSourcesCache: Map = new Map(); + private readonly rc4EncodedValuesSourcesCache: Map> = new Map(); /** * @type {number} @@ -224,19 +224,13 @@ export class StringArrayStorage this.storage = new Map( this.arrayUtils .shuffle(Array.from(this.storage.entries())) - .map<[`${string}-${TStringArrayEncoding}`, IStringArrayStorageItemData]>( - ([value, stringArrayStorageItemData], index: number) => { - stringArrayStorageItemData.index = index; + .map< + [`${string}-${TStringArrayEncoding}`, IStringArrayStorageItemData] + >(([value, stringArrayStorageItemData], index: number) => { + stringArrayStorageItemData.index = index; - return [value, stringArrayStorageItemData]; - } - ) - .sort( - ( - [, stringArrayStorageItemDataA]: [string, IStringArrayStorageItemData], - [, stringArrayStorageItemDataB]: [string, IStringArrayStorageItemData] - ) => stringArrayStorageItemDataA.index - stringArrayStorageItemDataB.index - ) + return [value, stringArrayStorageItemData]; + }) ); } @@ -296,29 +290,36 @@ export class StringArrayStorage * if collision will happen, just try to encode value again */ case StringArrayEncoding.Rc4: { - const decodeKey: string = this.randomGenerator.getRandomGenerator().pickone(this.rc4Keys); - const encodedValue: string = this.cryptUtilsStringArray.btoa( - this.cryptUtilsStringArray.rc4(value, decodeKey) - ); + const maxRetryAttempts: number = 50; - const encodedValueSources: string[] = this.rc4EncodedValuesSourcesCache.get(encodedValue) ?? []; - let encodedValueSourcesLength: number = encodedValueSources.length; + for (let attempt: number = 0; attempt < maxRetryAttempts; attempt++) { + const decodeKey: string = this.randomGenerator.getRandomGenerator().pickone(this.rc4Keys); + const encodedValue: string = this.cryptUtilsStringArray.btoa( + this.cryptUtilsStringArray.rc4(value, decodeKey) + ); - const shouldAddValueToSourcesCache: boolean = - !encodedValueSourcesLength || !encodedValueSources.includes(value); + const encodedValueSources: Set = + this.rc4EncodedValuesSourcesCache.get(encodedValue) ?? new Set(); - if (shouldAddValueToSourcesCache) { - encodedValueSources.push(value); - encodedValueSourcesLength++; - } + const shouldAddValueToSourcesCache: boolean = + encodedValueSources.size === 0 || !encodedValueSources.has(value); + + if (shouldAddValueToSourcesCache) { + encodedValueSources.add(value); + } - this.rc4EncodedValuesSourcesCache.set(encodedValue, encodedValueSources); + this.rc4EncodedValuesSourcesCache.set(encodedValue, encodedValueSources); - if (encodedValueSourcesLength > 1) { - return this.getEncodedValue(value); + if (encodedValueSources.size <= 1) { + return { encodedValue, encoding, decodeKey }; + } } - return { encodedValue, encoding, decodeKey }; + return { + encodedValue: this.cryptUtilsStringArray.btoa(value), + encoding: StringArrayEncoding.Base64, + decodeKey: null + }; } case StringArrayEncoding.Base64: { diff --git a/src/utils/ArrayUtils.ts b/src/utils/ArrayUtils.ts index 718ee2298..4c1c25577 100644 --- a/src/utils/ArrayUtils.ts +++ b/src/utils/ArrayUtils.ts @@ -103,7 +103,9 @@ export class ArrayUtils implements IArrayUtils { * @returns {T[]} */ public rotate(array: T[], times: number): T[] { - if (!array.length) { + const arrayLength: number = array.length; + + if (!arrayLength) { throw new ReferenceError('Cannot rotate empty array.'); } @@ -111,19 +113,16 @@ export class ArrayUtils implements IArrayUtils { return array; } - const newArray: T[] = array; + // Normalize rotation amount to avoid unnecessary full rotations + // O(N) algorithm using slice instead of O(N*R) with pop/unshift + const normalizedTimes: number = times % arrayLength; - let temp: T | undefined; - - while (times--) { - temp = newArray.pop(); - - if (temp) { - newArray.unshift(temp); - } + if (normalizedTimes === 0) { + return [...array]; } - return newArray; + // Right rotation: take last `normalizedTimes` elements and put them at the front + return [...array.slice(-normalizedTimes), ...array.slice(0, -normalizedTimes)]; } /** diff --git a/src/utils/EscapeSequenceEncoder.ts b/src/utils/EscapeSequenceEncoder.ts index 6db012ab3..75511d7c3 100644 --- a/src/utils/EscapeSequenceEncoder.ts +++ b/src/utils/EscapeSequenceEncoder.ts @@ -19,6 +19,11 @@ export class EscapeSequenceEncoder implements IEscapeSequenceEncoder { */ private static readonly forceEscapeCharactersRegExp: RegExp = /[\x00-\x1F\x7F-\x9F'"\\\s]/; + /** + * @type {RegExp} + */ + private static readonly replaceRegExp: RegExp = /[\s\S]/g; + /** * @type {Map} */ @@ -37,12 +42,11 @@ export class EscapeSequenceEncoder implements IEscapeSequenceEncoder { } const radix: number = 16; - const replaceRegExp: RegExp = new RegExp('[\\s\\S]', 'g'); let prefix: string; let template: string; - const result: string = string.replace(replaceRegExp, (character: string): string => { + const result: string = string.replace(EscapeSequenceEncoder.replaceRegExp, (character: string): string => { const shouldEncodeCharacter: boolean = encodeAllSymbols || EscapeSequenceEncoder.forceEscapeCharactersRegExp.test(character); From 1c2d8bd9d096aa7fd8cf7b245dc82189df1eacce Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Mon, 22 Dec 2025 09:29:21 +0400 Subject: [PATCH 30/87] Update readme --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 048be086f..b423e107e 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,20 @@ Huge thanks to all supporters! ![logo](https://raw.githubusercontent.com/javascript-obfuscator/javascript-obfuscator/master/images/logo.png) +--- + +### :rocket: JavaScript Obfuscator Pro with VM Obfuscation is out! + +**[JavaScript Obfuscator Pro](https://obfuscator.io/)** now features **VM-based bytecode obfuscation** — the most advanced code protection available. Your JavaScript functions are transformed into custom bytecode running on an embedded virtual machine, making reverse engineering extremely difficult. + +:star: **[Try it at obfuscator.io](https://obfuscator.io)** — user-friendly interface, cloud-based obfuscation, and Pro API access. + +--- + JavaScript Obfuscator is a powerful free obfuscator for JavaScript, containing a variety of features which provide protection for your source code. **Key features:** -- VM obfuscation (via [JavaScript Obfuscator Pro](https://obfuscator.io/)) +- VM bytecode obfuscation (via [JavaScript Obfuscator Pro](https://obfuscator.io/)) - variables renaming - strings extraction and encryption - dead code injection From a86314da5952154f63897d1f82ef2f151f89b825 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Mon, 22 Dec 2025 09:34:13 +0400 Subject: [PATCH 31/87] Update readme #2 --- README.md | 195 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 166 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index b423e107e..2fa197d00 100644 --- a/README.md +++ b/README.md @@ -1766,73 +1766,211 @@ The performance will be at a relatively normal level -## JavaScript Obfuscator Pro VM options +## JavaScript Obfuscator Pro Options + +> :warning: **The following VM obfuscation options are available only via the [JavaScript Obfuscator Pro API](https://obfuscator.io/).** +> +> To use these options, you need a Pro API token from [obfuscator.io](https://obfuscator.io) and must call the `obfuscatePro()` method instead of `obfuscate()`. See the [Pro API Methods](#shield-pro-api-methods-vm-obfuscation) section for details. ### `vmObfuscation` Type: `boolean` Default: `false` Enables VM-based bytecode obfuscation. When enabled, JavaScript functions are compiled into custom bytecode that runs on an embedded virtual machine. This provides the highest level of protection as the original code logic is completely transformed. -**Warning:** This significantly increases code size and may impact performance. Use `vmObfuscationThreshold` to control which root-level functions are transformed. +**Example:** +Your readable code like `return qty * price` becomes a list of numbers like `[0x15,0x03,0x17,...]` that only the embedded VM interpreter can execute. The original logic is no longer visible as JavaScript. ### `vmObfuscationThreshold` Type: `number` Default: `1` -The probability (from 0 to 1) that a function will be transformed to VM bytecode when `vmObfuscation` is enabled. - -- `0` - no functions will be transformed -- `0.5` - 50% of functions will be transformed -- `1` - all functions will be transformed +Controls what percentage of your root-level functions get VM protection. ### `vmTargetFunctions` Type: `string[]` Default: `[]` -Array of root-level function names to target for VM obfuscation. When specified, only these functions will be transformed (subject to `vmObfuscationThreshold`). Empty array means all functions are candidates. +Specify exactly which root-level functions should get VM protection by name. + +**Example:** +```javascript +{ + vmObfuscation: true, + vmTargetFunctions: ['someFunctionName'] +} +``` + +**Result:** Only these three functions get VM-protected. Everything else stays as regular (but still obfuscated) JavaScript. Perfect for protecting sensitive license checks or authentication logic while keeping the rest of your code lean. ### `vmExcludeFunctions` Type: `string[]` Default: `[]` -Array of root-level function names to exclude from VM obfuscation. These functions will never be transformed regardless of other settings. +Specify root-level functions that should never get VM protection. Takes precedence over other settings. + +**Example:** +```javascript +{ + vmObfuscation: true, + vmExcludeFunctions: ['someFunctionName'] +} +``` + +**When to use:** Performance-critical root-level functions (animation loops, real-time data processing) can be excluded to avoid VM overhead while still protecting everything else. + +### `vmTargetFunctionsMode` +Type: `string` Default: `root` + +Controls how functions/methods are selected for VM obfuscation. + +| Mode | Description | +|------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `root` | Default behavior. Only root-level functions are considered for VM obfuscation. Uses `vmTargetFunctions` allow-list and `vmExcludeFunctions` deny-list to filter. | +| `comment` | Only functions/methods decorated with `/* javascript-obfuscator:vm */` comment are VM-obfuscated. Works with functions/methods at **any nesting level**. | + +**Example - Comment mode:** +```javascript +// Source code +function regularFunction() { + return 'not virtualized'; +} + +/* javascript-obfuscator:vm */ +function sensitiveFunction() { + return 'this will be VM-protected'; +} + +function outer() { + /* javascript-obfuscator:vm */ + function nestedSensitive() { + return 'nested but still VM-protected'; + } + return nestedSensitive(); +} +``` + +```javascript +// Obfuscator options +{ + vmObfuscation: true, + vmTargetFunctionsMode: 'comment' +} +``` + +**When to use:** When you need surgical control over exactly which functions get VM protection, especially nested functions that contain sensitive logic. Unlike `vmTargetFunctions` which only works with root-level named functions, comment mode lets you protect any function anywhere in your code. + +### `vmWrapTopLevelInitializers` +Type: `boolean` Default: `false` + +Wraps some top-level variable initializers in IIFEs (Immediately Invoked Function Expressions) so they can be VM-obfuscated. + +**What it does:** +Without this option, top-level constants and variables remain visible in the output: +```javascript +// Input +const MY_STRING = "my-string"; + +// Output (without vmWrapTopLevelInitializers) +const MY_STRING = "my-string"; // String is visible! +``` + +With this option enabled, the initializer is wrapped in an IIFE that gets VM-obfuscated: +```javascript +// Input +const MY_STRING = "my-string"; + +// Output (with vmWrapTopLevelInitializers: true) +const MY_STRING = (() => { return /* VM bytecode call */ })(); // String hidden in bytecode +``` + +**Note:** This option only works when `vmTargetFunctionsMode` is `'root'` (the default). + +### `vmDynamicOpcodes` +Type: `boolean` Default: `false` + +Makes the VM interpreter smaller and unique for each build. + +**What it does:** +1. **Filters unused instructions** - If your code doesn't use classes, class-related instructions are removed entirely +2. **Randomizes structure** - The order of instruction handlers is shuffled each build + +As the result - smaller output and each build looks different. ### `vmOpcodeShuffle` Type: `boolean` Default: `false` -Randomizes the opcode mapping for each obfuscation run. Makes static analysis more difficult as opcode meanings change between builds. +Randomizes the numeric values assigned to each opcode. For example, the `LOAD` instruction might be `1` in one build and `47` in another. ### `vmBytecodeEncoding` Type: `boolean` Default: `false` -Encodes the bytecode instructions using XOR encryption. The decoding key is derived at runtime, adding another layer of protection. +Encodes each bytecode instruction. Instructions are decoded one at a time during execution. ### `vmBytecodeArrayEncoding` Type: `boolean` Default: `false` -Applies additional encoding to the bytecode array, making it harder to identify bytecode patterns through static analysis. +Encodes the entire bytecode array as a single block. The array is decoded once at startup before execution begins. Use together with `vmBytecodeEncoding` for two layers of protection. ### `vmJumpsEncoding` Type: `boolean` Default: `false` -Encodes jump targets and offsets in the bytecode. This obscures control flow and makes it harder to follow program execution. +Encodes jump targets in the bytecode. Jump offsets are calculated at runtime, hiding the control flow structure (`if`/`else`, loops, etc.) from static analysis. ### `vmDecoyOpcodes` Type: `boolean` Default: `false` -Inserts fake opcodes into the dispatcher that are never executed. Increases code complexity and confuses reverse engineering attempts. +Adds fake opcode handlers to the VM dispatcher that are never called. For example, if the VM uses 20 real opcodes, this might add 30 fake handlers, making the interpreter appear more complex than it really is. ### `vmDeadCodeInjection` Type: `boolean` Default: `false` -Injects dead code sequences into the VM bytecode. These sequences are valid but unreachable, adding noise to analysis. +Injects fake bytecode sequences that are never executed. These look like real instructions but are skipped during runtime, confusing analysis tools that process them. ### `vmSplitDispatcher` Type: `boolean` Default: `false` -Splits the VM dispatcher into multiple smaller dispatchers. Makes the execution flow harder to follow. +Splits the VM dispatcher into multiple smaller switch statements organized by opcode category, instead of one large monolithic switch. Each category (stack, arithmetic, control flow, etc.) gets its own switch, routed by if/else range checks. + +This option supports `vmDynamicOpcodes` in both modes: `true` (shuffle first, then split into groups) and `false`. + +> :warning: When `vmIndirectDispatch` is enabled, this option is ignored. Prefer `vmIndirectDispatch` as it provides better obfuscation with similar performance. + +### `vmIndirectDispatch` +Type: `boolean` Default: `false` + +Uses compile-time generated handler functions for opcode dispatch instead of switch statements. Handlers are generated at compile-time with inlined opcode logic and shuffled positions. + +Instead of: +```javascript +switch(op) { + case 0: /* handle opcode 0 */ break; + case 1: /* handle opcode 1 */ break; +} +``` + +It generates: +```javascript +var _hm = {0:42, 1:17, ...}; // opcode → handler index mapping +var _h = [handler0, handler1, ...]; // shuffled handler array +_h[_hm[op]](arg); // single lookup + function call +``` + +This option supports `vmDynamicOpcodes` in both modes. + +> :warning: When enabled, this takes priority over `vmSplitDispatcher`. Both options cannot be active simultaneously. + +### `vmCompactDispatcher` +Type: `boolean` Default: `false` + +Uses a single unified dispatcher (generator-based) for both sync and async/generator code execution. By default (`false`), the VM generates two separate dispatchers: a non-generator version for sync code (faster) and a generator version for async/generator code. When enabled, only the generator-based dispatcher is used for all execution. + +**Trade-offs:** +- `false` (default): Larger code size due to dual dispatchers, but faster sync execution (no generator overhead) +- `true`: Smaller code size with single dispatcher, but sync code has generator protocol overhead + +Use this when code size is more important than sync execution speed. ### `vmMacroOps` Type: `boolean` Default: `false` -Combines common instruction sequences into single macro opcodes. This creates unique instruction patterns that are harder to recognize. +Combines common instruction sequences into single "macro" opcodes. For example, `LOAD + ADD + STORE` might become a single `MACRO_ADD_TO_VAR` instruction. This breaks pattern recognition and can improve performance. ### `vmDebugProtection` Type: `boolean` Default: `false` @@ -1842,34 +1980,33 @@ Adds anti-debugging measures to the VM runtime. Detects debugger presence and al ### `vmRuntimeOpcodeDerivation` Type: `boolean` Default: `false` -Derives opcode values at runtime through mathematical operations rather than using static values. Makes static analysis significantly harder. +Derives the opcode mapping table at runtime from a seed value instead of hardcoding it. The seed is stored in the bytecode and used to generate the opcode-to-handler mapping via Fisher-Yates shuffle during execution. ### `vmStatefulOpcodes` Type: `boolean` Default: `false` -Makes opcode interpretation depend on VM state. The same opcode can have different meanings based on execution history. +Makes opcode meanings depend on position in the bytecode. Each position has a different opcode-to-handler mapping derived from a seed, so the same opcode number performs different operations at different positions. ### `vmStackEncoding` Type: `boolean` Default: `false` -Encodes values pushed to and popped from the VM stack. Adds protection against memory inspection during execution. +Encrypts values on the VM stack during execution. Values are encoded when pushed and decoded when popped, so memory inspection shows encrypted data instead of actual values. -### `vmRandomizeKeys` -Type: `boolean` Default: `false` +This option heavily affects performance. -Randomizes encryption keys and other constants used by the VM. Each build produces unique key values. - -### `vmIndirectDispatch` +### `vmRandomizeKeys` Type: `boolean` Default: `false` -Uses indirect function calls for opcode dispatch instead of direct switch/case. Makes control flow analysis more difficult. +Randomizes the property key names used in bytecode objects. Standard keys like `i` (instructions), `c` (constants) become random 2-character identifiers, making the bytecode structure different for each build. ### `vmBytecodeFormat` Type: `string` Default: `binary` -Specifies the format used to embed bytecode in the output: -- `binary` - Compact binary representation (smaller size) -- `json` - JSON format (easier debugging, larger size) +Controls how bytecode is stored in the output. + +**Options:** +- `binary` - Compact binary format. Smaller size, recommended for production. +- `json` - Human-readable JSON format. Larger size, useful for debugging. ## Frequently Asked Questions From 90362a255593be2cd7668cb09e6007732dce569f Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Mon, 22 Dec 2025 09:49:51 +0400 Subject: [PATCH 32/87] Update readme #3 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2fa197d00..31138b95c 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ Huge thanks to all supporters! ### :rocket: JavaScript Obfuscator Pro with VM Obfuscation is out! -**[JavaScript Obfuscator Pro](https://obfuscator.io/)** now features **VM-based bytecode obfuscation** — the most advanced code protection available. Your JavaScript functions are transformed into custom bytecode running on an embedded virtual machine, making reverse engineering extremely difficult. +**JavaScript Obfuscator Pro** features **VM-based bytecode obfuscation** — the most advanced code protection available. Your JavaScript functions are transformed into custom bytecode running on an embedded virtual machine, making reverse engineering extremely difficult. -:star: **[Try it at obfuscator.io](https://obfuscator.io)** — user-friendly interface, cloud-based obfuscation, and Pro API access. +[Try it at obfuscator.io](https://obfuscator.io) --- From c844f97cfc8200447d49540b5ff127f11c87a589 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Tue, 6 Jan 2026 23:37:42 +0400 Subject: [PATCH 33/87] Ignore transformation of `process.env.*` (#1367) --- .gitignore | 1 + .npmignore | 1 + CHANGELOG.md | 4 ++ CLAUDE.md | 4 +- CODE_OF_CONDUCT.md | 2 +- README.md | 4 +- package.json | 9 +-- .../PreparingTransformersModule.ts | 6 ++ .../obfuscating-guards/ObfuscatingGuard.ts | 1 + .../ObfuscatingGuardsTransformer.ts | 1 + .../ProcessEnvObfuscationGuard.ts | 66 +++++++++++++++++++ .../JavaScriptObfuscator.spec.ts | 18 +++++ .../fixtures/process-env.js | 1 + webpack/utils/WebpackUtils.js | 2 +- webpack/webpack.browser.config.js | 13 ++++ webpack/webpack.node.config.js | 13 ++++ 16 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 src/node-transformers/preparing-transformers/obfuscating-guards/ProcessEnvObfuscationGuard.ts create mode 100644 test/functional-tests/javascript-obfuscator/fixtures/process-env.js diff --git a/.gitignore b/.gitignore index cfe4fd231..ac8242982 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ npm-debug.log /test/benchmark/**/** *dockerfile /test*.js +/reproductions diff --git a/.npmignore b/.npmignore index e7fb7148d..2157c5a98 100644 --- a/.npmignore +++ b/.npmignore @@ -12,3 +12,4 @@ /test*.js index.ts index.cli.ts +/reproductions \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f0f9804bf..013df5696 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log +v5.2.0 +--- +* Skip obfuscation of `process.env.*` + v5.1.0 --- * Add `version` parameter to the `apiConfig` to use different versions JavaScript Obfuscator Pro via API diff --git a/CLAUDE.md b/CLAUDE.md index 3236bb57e..03d0777fb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -5,7 +5,7 @@ **JavaScript Obfuscator** is a powerful, enterprise-grade code obfuscation tool for JavaScript and Node.js applications. It transforms readable JavaScript code into a protected, difficult-to-understand format while maintaining full functionality. The project is widely used for protecting intellectual property and preventing reverse engineering. - **Version**: 5.0.0 -- **Author**: Timofey Kachalov (@sanex3339) +- **Author**: Timofei Kachalov (@sanex3339) - **License**: BSD-2-Clause - **Repository**: https://github.com/javascript-obfuscator/javascript-obfuscator - **Homepage**: https://obfuscator.io/ @@ -1429,7 +1429,7 @@ Use [grunt-contrib-obfuscator](https://github.com/javascript-obfuscator/grunt-co **BSD-2-Clause License** -Copyright (C) 2016-2024 Timofey Kachalov +Copyright (C) 2016-2026 Timofei Kachalov See `LICENSE.BSD` for full license text. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index c2a51b853..14aa477fa 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -34,7 +34,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at sanex3339@yandex.ru. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at support@obfuscator.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. diff --git a/README.md b/README.md index 31138b95c..8bd9ebe6c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ #### You can support this project by donating: @@ -2101,7 +2101,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s ## License [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjavascript-obfuscator%2Fjavascript-obfuscator.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjavascript-obfuscator%2Fjavascript-obfuscator?ref=badge_large) -Copyright (C) 2016-2024 [Timofey Kachalov](http://github.com/sanex3339). +Copyright (C) 2016-2026 [Timofei Kachalov](http://github.com/sanex3339). Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/package.json b/package.json index ba8f9d0fe..7bb02fa54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "5.1.0", + "version": "5.2.0", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", @@ -129,12 +129,9 @@ "prepare": "husky install" }, "author": { - "name": "Timofey Kachalov" + "name": "Timofei Kachalov" }, - "contributors": [ - "Timofey Kachalov (https://github.com/sanex3339)", - "Dmitry Zamotkin (https://github.com/zamotkin)" - ], + "contributors": ["Timofei Kachalov (https://github.com/sanex3339)", "Dmitry Zamotkin (https://github.com/zamotkin)"], "license": "BSD-2-Clause", "packageManager": "yarn@1.22.21+sha512.ca75da26c00327d26267ce33536e5790f18ebd53266796fbb664d2a4a5116308042dd8ee7003b276a20eace7d3c5561c3577bdd71bcb67071187af124779620a" } diff --git a/src/container/modules/node-transformers/PreparingTransformersModule.ts b/src/container/modules/node-transformers/PreparingTransformersModule.ts index da19c7a6a..296b632f3 100644 --- a/src/container/modules/node-transformers/PreparingTransformersModule.ts +++ b/src/container/modules/node-transformers/PreparingTransformersModule.ts @@ -15,6 +15,7 @@ import { EvalCallExpressionTransformer } from '../../../node-transformers/prepar import { ForceTransformStringObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ForceTransformStringObfuscatingGuard'; import { IgnoredImportObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/IgnoredImportObfuscatingGuard'; import { ImportMetaObfuscationGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard'; +import { ProcessEnvObfuscationGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ProcessEnvObfuscationGuard'; import { MetadataTransformer } from '../../../node-transformers/preparing-transformers/MetadataTransformer'; import { ObfuscatingGuardsTransformer } from '../../../node-transformers/preparing-transformers/ObfuscatingGuardsTransformer'; import { ParentificationTransformer } from '../../../node-transformers/preparing-transformers/ParentificationTransformer'; @@ -73,6 +74,11 @@ export const preparingTransformersModule: interfaces.ContainerModule = new Conta .inSingletonScope() .whenTargetNamed(ObfuscatingGuard.ImportMetaObfuscationGuard); + bind(ServiceIdentifiers.INodeGuard) + .to(ProcessEnvObfuscationGuard) + .inSingletonScope() + .whenTargetNamed(ObfuscatingGuard.ProcessEnvObfuscationGuard); + bind(ServiceIdentifiers.INodeGuard) .to(ReservedStringObfuscatingGuard) .inSingletonScope() diff --git a/src/enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard.ts b/src/enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard.ts index 3da243455..50dd66c8b 100644 --- a/src/enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard.ts +++ b/src/enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard.ts @@ -4,5 +4,6 @@ export enum ObfuscatingGuard { ForceTransformStringObfuscatingGuard = 'ForceTransformStringObfuscatingGuard', IgnoredImportObfuscatingGuard = 'IgnoredImportObfuscatingGuard', ImportMetaObfuscationGuard = 'ImportMetaObfuscationGuard', + ProcessEnvObfuscationGuard = 'ProcessEnvObfuscationGuard', ReservedStringObfuscatingGuard = 'ReservedStringObfuscatingGuard' } diff --git a/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts b/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts index c05f019b2..8d10290c8 100644 --- a/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts +++ b/src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts @@ -33,6 +33,7 @@ export class ObfuscatingGuardsTransformer extends AbstractNodeTransformer { ObfuscatingGuard.ForceTransformStringObfuscatingGuard, ObfuscatingGuard.IgnoredImportObfuscatingGuard, ObfuscatingGuard.ImportMetaObfuscationGuard, + ObfuscatingGuard.ProcessEnvObfuscationGuard, ObfuscatingGuard.ReservedStringObfuscatingGuard ]; diff --git a/src/node-transformers/preparing-transformers/obfuscating-guards/ProcessEnvObfuscationGuard.ts b/src/node-transformers/preparing-transformers/obfuscating-guards/ProcessEnvObfuscationGuard.ts new file mode 100644 index 000000000..efbd23e1d --- /dev/null +++ b/src/node-transformers/preparing-transformers/obfuscating-guards/ProcessEnvObfuscationGuard.ts @@ -0,0 +1,66 @@ +import { injectable } from 'inversify'; + +import * as ESTree from 'estree'; + +import { IObfuscatingGuard } from '../../../interfaces/node-transformers/preparing-transformers/obfuscating-guards/IObfuscatingGuard'; + +import { ObfuscatingGuardResult } from '../../../enums/node/ObfuscatingGuardResult'; + +import { NodeGuards } from '../../../node/NodeGuards'; + +@injectable() +export class ProcessEnvObfuscationGuard implements IObfuscatingGuard { + /** + * @param {Node} node + * @return {boolean} + * @private + */ + private static isProcessEnvMemberExpression(node: ESTree.Node): boolean { + if (!NodeGuards.isMemberExpressionNode(node)) { + return false; + } + + return ( + NodeGuards.isIdentifierNode(node.object) && + node.object.name === 'process' && + NodeGuards.isIdentifierNode(node.property) && + node.property.name === 'env' && + !node.computed + ); + } + + /** + * @param {Node} node + * @return {boolean} + * @private + */ + private static isPartOfProcessEnvChain(node: ESTree.Node): boolean { + if (ProcessEnvObfuscationGuard.isProcessEnvMemberExpression(node)) { + return true; + } + + const parentNode = node.parentNode; + + if (parentNode && NodeGuards.isMemberExpressionNode(parentNode)) { + if (ProcessEnvObfuscationGuard.isProcessEnvMemberExpression(parentNode.object)) { + return true; + } + + if (ProcessEnvObfuscationGuard.isProcessEnvMemberExpression(parentNode)) { + return true; + } + } + + return false; + } + + /** + * @param {Node} node + * @returns {ObfuscatingGuardResult} + */ + public check(node: ESTree.Node): ObfuscatingGuardResult { + return ProcessEnvObfuscationGuard.isPartOfProcessEnvChain(node) + ? ObfuscatingGuardResult.Ignore + : ObfuscatingGuardResult.Transform; + } +} diff --git a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts index 6a12c7ab2..4955b44d8 100644 --- a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts +++ b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts @@ -721,6 +721,24 @@ describe('JavaScriptObfuscator', () => { }); }); + describe('process.env.* support', () => { + const regExp: RegExp = /console\['log']\(process\.env\.FOO\);/; + + let obfuscatedCode: string; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/process-env.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); + }); + + it('should not obfuscate `process.env.*`', () => { + assert.match(obfuscatedCode, regExp); + }); + }); + /** * https://github.com/javascript-obfuscator/javascript-obfuscator/issues/710 */ diff --git a/test/functional-tests/javascript-obfuscator/fixtures/process-env.js b/test/functional-tests/javascript-obfuscator/fixtures/process-env.js new file mode 100644 index 000000000..d375f0d17 --- /dev/null +++ b/test/functional-tests/javascript-obfuscator/fixtures/process-env.js @@ -0,0 +1 @@ +console.log(process.env.FOO); diff --git a/webpack/utils/WebpackUtils.js b/webpack/utils/WebpackUtils.js index 572e41051..811923509 100644 --- a/webpack/utils/WebpackUtils.js +++ b/webpack/utils/WebpackUtils.js @@ -1,6 +1,6 @@ const fs = require('fs'); -const copyright = 'Copyright (C) 2016-2024 Timofey Kachalov '; +const copyright = 'Copyright (C) 2016-2026 Timofei Kachalov '; const sourceMapSupportRequire = 'require("source-map-support").install();'; class WebpackUtils { diff --git a/webpack/webpack.browser.config.js b/webpack/webpack.browser.config.js index 1a7ed3fb1..f6df3bfb6 100644 --- a/webpack/webpack.browser.config.js +++ b/webpack/webpack.browser.config.js @@ -1,6 +1,7 @@ 'use strict'; const webpack = require('webpack'); +const TerserPlugin = require('terser-webpack-plugin'); const packageJson = require('pjson'); const WebpackUtils = require('./utils/WebpackUtils').WebpackUtils; @@ -41,6 +42,18 @@ module.exports = { process: ['process'] }) ], + optimization: { + minimizer: [ + new TerserPlugin({ + extractComments: false, + terserOptions: { + format: { + comments: /^!/ // Keep comments starting with ! + } + } + }) + ] + }, output: { libraryTarget: 'umd', library: 'JavaScriptObfuscator', diff --git a/webpack/webpack.node.config.js b/webpack/webpack.node.config.js index 5761bad6b..3da2d2da5 100644 --- a/webpack/webpack.node.config.js +++ b/webpack/webpack.node.config.js @@ -4,6 +4,7 @@ const path = require('path'); const nodeExternals = require('webpack-node-externals'); const webpack = require('webpack'); +const TerserPlugin = require('terser-webpack-plugin'); const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); const ForkTsCheckerNotifierWebpackPlugin = require('fork-ts-checker-notifier-webpack-plugin'); const ESLintPlugin = require('eslint-webpack-plugin'); @@ -70,6 +71,18 @@ module.exports = { skipFirstNotification: true }) ], + optimization: { + minimizer: [ + new TerserPlugin({ + extractComments: false, + terserOptions: { + format: { + comments: /^!/ // Keep comments starting with ! + } + } + }) + ] + }, output: { libraryTarget: 'commonjs2' }, From 311799e3e7c8a0c057d54808b6e700a583531a68 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Sun, 25 Jan 2026 23:21:42 +0400 Subject: [PATCH 34/87] Add vmPreprocessIdentifiers to the readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 8bd9ebe6c..93afd65d1 100644 --- a/README.md +++ b/README.md @@ -1785,6 +1785,13 @@ Type: `number` Default: `1` Controls what percentage of your root-level functions get VM protection. +### `vmPreprocessIdentifiers` +Type: `boolean` Default: `true` + +Renames all non-global identifiers to unique hexadecimal names before VM obfuscation. This eliminates variable shadowing that can cause scope resolution issues in the VM bytecode. + +**When to disable:** Only disable this if you encounter specific compatibility issues. The preprocessing step ensures correct variable resolution in complex nested scopes. + ### `vmTargetFunctions` Type: `string[]` Default: `[]` From 2be70353c734cc423353bdb48c22e44f16b97fe1 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Sun, 25 Jan 2026 23:22:53 +0400 Subject: [PATCH 35/87] Add strictMode to the readme --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93afd65d1..128eaba72 100644 --- a/README.md +++ b/README.md @@ -1768,7 +1768,7 @@ The performance will be at a relatively normal level ## JavaScript Obfuscator Pro Options -> :warning: **The following VM obfuscation options are available only via the [JavaScript Obfuscator Pro API](https://obfuscator.io/).** +> :warning: **The following VM obfuscation/Pro options are available only via the [JavaScript Obfuscator Pro API](https://obfuscator.io/).** > > To use these options, you need a Pro API token from [obfuscator.io](https://obfuscator.io) and must call the `obfuscatePro()` method instead of `obfuscate()`. See the [Pro API Methods](#shield-pro-api-methods-vm-obfuscation) section for details. @@ -2015,6 +2015,16 @@ Controls how bytecode is stored in the output. - `binary` - Compact binary format. Smaller size, recommended for production. - `json` - Human-readable JSON format. Larger size, useful for debugging. +### `strictMode` +Type: `boolean | null` Default: `null` + +Allows to specify how the obfuscator should treat code regarding JavaScript strict mode. + +Available values: +* `null` (default) - auto-detect strict mode from the code. If the code has explicit `'use strict'` directive, ES module syntax, or class methods, it's treated as strict mode. Otherwise, sloppy mode is assumed. +* `true` - force strict mode treatment for all code, even without explicit `'use strict'` directive. Use this when your code will run in strict mode context (e.g., in ES modules, bundlers, or modern frameworks). +* `false` - only explicit strict mode indicators (`'use strict'`, ES modules, class methods) are treated as strict. Parent scope inheritance still applies per JS spec. + ## Frequently Asked Questions ### What javascript versions are supported? From 99c635a6d2f87541e03ce4ef5dfa0026c050aba6 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Tue, 27 Jan 2026 14:04:39 +0400 Subject: [PATCH 36/87] Fixed `controlFlowFlattening` breaking short-circuit evaluation with spread operator and conditional objects (#1373) --- CHANGELOG.md | 1 + .../LogicalExpressionControlFlowReplacer.ts | 31 +++++++ .../issues/fixtures/issue1372.js | 15 ++++ .../functional-tests/issues/issue1372.spec.ts | 90 +++++++++++++++++++ ...ConditionalCommentObfuscatingGuard.spec.ts | 6 +- 5 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 test/functional-tests/issues/fixtures/issue1372.js create mode 100644 test/functional-tests/issues/issue1372.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 013df5696..c289cddab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Change Log v5.2.0 --- * Skip obfuscation of `process.env.*` +* Fixed `controlFlowFlattening` breaking short-circuit evaluation with spread operator and conditional objects. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1372 v5.1.0 --- diff --git a/src/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.ts b/src/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.ts index d77f1c60d..d4f5d6265 100644 --- a/src/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.ts +++ b/src/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.ts @@ -2,6 +2,7 @@ import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; +import * as estraverse from '@javascript-obfuscator/estraverse'; import { TControlFlowCustomNodeFactory } from '../../../types/container/custom-nodes/TControlFlowCustomNodeFactory'; import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory'; @@ -88,6 +89,10 @@ export class LogicalExpressionControlFlowReplacer extends ExpressionWithOperator leftExpression: ESTree.Expression, rightExpression: ESTree.Expression ): boolean { + if (this.expressionContainsProhibitedNodes(rightExpression)) { + return true; + } + return [leftExpression, rightExpression].some((expressionNode: ESTree.Node | ESTree.Expression): boolean => { let nodeForCheck: ESTree.Node | ESTree.Expression; @@ -105,4 +110,30 @@ export class LogicalExpressionControlFlowReplacer extends ExpressionWithOperator ); }); } + + /** + * @param {Expression} expression + * @returns {boolean} + */ + private expressionContainsProhibitedNodes(expression: ESTree.Expression): boolean { + let hasProhibitedNode = false; + + estraverse.traverse(expression, { + enter: (node: ESTree.Node): estraverse.VisitorOption | void => { + if (NodeGuards.isMemberExpressionNode(node) && node.computed) { + hasProhibitedNode = true; + + return estraverse.VisitorOption.Break; + } + + if (NodeGuards.isCallExpressionNode(node)) { + hasProhibitedNode = true; + + return estraverse.VisitorOption.Break; + } + } + }); + + return hasProhibitedNode; + } } diff --git a/test/functional-tests/issues/fixtures/issue1372.js b/test/functional-tests/issues/fixtures/issue1372.js new file mode 100644 index 000000000..cc1dfb95f --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1372.js @@ -0,0 +1,15 @@ +function test(hasColor) +{ + const accent = hasColor ? "primary" : undefined; + const theme = { palette: { primary: { main: "ok" } }}; + + const obj = + { + bgcolor: "test", + ...(accent && { color: theme.palette[accent].main }) + } + + return obj; +} + +module.exports = { test }; diff --git a/test/functional-tests/issues/issue1372.spec.ts b/test/functional-tests/issues/issue1372.spec.ts new file mode 100644 index 000000000..9b5da5f38 --- /dev/null +++ b/test/functional-tests/issues/issue1372.spec.ts @@ -0,0 +1,90 @@ +import { assert } from 'chai'; +import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../helpers/readFileAsString'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; + +// +// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1372 +// +describe('Issue #1372', () => { + describe('Spread operator with conditional object should work correctly', () => { + const samplesCount = 50; + + let obfuscatedCode: string; + + it('does not break on run with controlFlowFlattening enabled', () => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1372.js'); + + for (let i = 0; i < samplesCount; i++) { + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); + + const result = eval(` + ${obfuscatedCode} + module.exports; + `); + + const resultTrue = result.test(true); + assert.deepEqual(resultTrue, { bgcolor: 'test', color: 'ok' }); + + const resultFalse = result.test(false); + assert.deepEqual(resultFalse, { bgcolor: 'test' }); + } + }); + + it('does not break on run with transformObjectKeys enabled', () => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1372.js'); + + for (let i = 0; i < samplesCount; i++) { + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); + + const result = eval(` + ${obfuscatedCode} + module.exports; + `); + + const resultTrue = result.test(true); + assert.deepEqual(resultTrue, { bgcolor: 'test', color: 'ok' }); + + const resultFalse = result.test(false); + assert.deepEqual(resultFalse, { bgcolor: 'test' }); + } + }); + + it('does not break on run with both controlFlowFlattening and transformObjectKeys enabled', () => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1372.js'); + + for (let i = 0; i < samplesCount; i++) { + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + transformObjectKeys: true, + stringArray: true, + stringArrayThreshold: 1 + }).getObfuscatedCode(); + + const result = eval(` + ${obfuscatedCode} + module.exports; + `); + + const resultTrue = result.test(true); + assert.deepEqual(resultTrue, { bgcolor: 'test', color: 'ok' }); + + const resultFalse = result.test(false); + assert.deepEqual(resultFalse, { bgcolor: 'test' }); + } + }); + }); +}); diff --git a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts index c8822dfb0..bb4edbdbe 100644 --- a/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts +++ b/test/functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts @@ -134,11 +134,11 @@ describe('ConditionalCommentObfuscatingGuard', () => { const ignoredFunctionExpression1RegExp: RegExp = /var bar *= *function *\(a, *b, *c\) *{/; const ignoredFunctionExpression2RegExp: RegExp = /var baz *= *function *\(a, *b, *c\) *{/; - const obfuscatedFunctionCallRegExp: RegExp = /_0x([a-f0-9]){5,6}\( *\);/g; + const obfuscatedFunctionCallRegExp: RegExp = /_0x([a-f0-9]){5,6}\( *\)[,;]/g; const expectedObfuscatedFunctionCallsLength: number = 3; - const ignoredFunctionCall1RegExp: RegExp = /bar\( *\);/; - const ignoredFunctionCall2RegExp: RegExp = /baz\( *\);/; + const ignoredFunctionCall1RegExp: RegExp = /bar\( *\)[,;]/; + const ignoredFunctionCall2RegExp: RegExp = /baz\( *\)[,;]/; let obfuscatedCode: string, obfuscatedFunctionExpressionMatchesLength: number, From 3848bca7941ed86d62e6a7108b960201613d2172 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Tue, 27 Jan 2026 17:20:23 +0400 Subject: [PATCH 37/87] Backport some fixes from Pro version (#1374) --- CHANGELOG.md | 2 + src/analyzers/scope-analyzer/ScopeAnalyzer.ts | 114 ++++++++++++++++++ src/node/NodeUtils.ts | 5 + .../scope-analyzer/ScopeAnalyzer.spec.ts | 78 ++++++++++++ .../fixtures/annex-b-function-hoisting.js | 39 ++++++ .../fixtures/annex-b-let-const-shadowing.js | 9 ++ .../fixtures/annex-b-strict-mode.js | 11 ++ ...ObjectPatternPropertiesTransformer.spec.ts | 59 +++++++++ .../destructuring-default-outer-var.js | 8 ++ .../nested-destructuring-default-outer-var.js | 8 ++ .../simple-default-param-outer-var.js | 8 ++ test/helpers/evalLocal.ts | 9 ++ 12 files changed, 350 insertions(+) create mode 100644 test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-function-hoisting.js create mode 100644 test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-let-const-shadowing.js create mode 100644 test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-strict-mode.js create mode 100644 test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/destructuring-default-outer-var.js create mode 100644 test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/nested-destructuring-default-outer-var.js create mode 100644 test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/simple-default-param-outer-var.js create mode 100644 test/helpers/evalLocal.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index c289cddab..8fbbaf6f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ v5.2.0 --- * Skip obfuscation of `process.env.*` * Fixed `controlFlowFlattening` breaking short-circuit evaluation with spread operator and conditional objects. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1372 +* Fix Annex B function hoisting: block-scoped function declarations are now correctly linked to references outside the block in non-strict mode +* Fixed `NodeUtils.cloneRecursive` corrupting `range` property when cloning AST nodes, causing scope analysis to incorrectly resolve destructuring default parameter references v5.1.0 --- diff --git a/src/analyzers/scope-analyzer/ScopeAnalyzer.ts b/src/analyzers/scope-analyzer/ScopeAnalyzer.ts index 169e33397..b4001cf6d 100644 --- a/src/analyzers/scope-analyzer/ScopeAnalyzer.ts +++ b/src/analyzers/scope-analyzer/ScopeAnalyzer.ts @@ -84,6 +84,11 @@ export class ScopeAnalyzer implements IScopeAnalyzer { sourceType: ScopeAnalyzer.sourceTypes[i] }); + // Fix Annex B function hoisting references + // eslint-scope doesn't implement Annex B semantics where function declarations + // in blocks also create a var-hoisted binding in the enclosing function scope + this.fixAnnexBFunctionHoisting(); + return; } catch (error) { if (i < sourceTypeLength - 1) { @@ -117,6 +122,101 @@ export class ScopeAnalyzer implements IScopeAnalyzer { return scope; } + /** + * Fix Annex B function hoisting references. + * + * In non-strict mode, function declarations in blocks have dual binding: + * 1. A block-scoped binding (handled by eslint-scope) + * 2. A var-hoisted binding in the enclosing function scope (NOT handled by eslint-scope) + * + * This method merges block-scoped function declarations into the enclosing + * function scope and links unresolved references. + */ + private fixAnnexBFunctionHoisting(): void { + if (!this.scopeManager) { + return; + } + + this.walkScopes(this.scopeManager.globalScope, (scope: eslintScope.Scope) => { + if (scope.type !== 'block' && scope.type !== 'switch') { + return; + } + + // Skip strict mode scopes - Annex B doesn't apply + if (scope.isStrict) { + return; + } + + const functionScope = scope.variableScope; + + if (!functionScope) { + return; + } + + for (let i = scope.variables.length - 1; i >= 0; i--) { + const variable = scope.variables[i]; + + const isFunctionDeclaration = variable.defs.some( + (def) => def.type === 'FunctionName' && def.node?.type === 'FunctionDeclaration' + ); + + if (!isFunctionDeclaration) { + continue; + } + + // Find existing variable with the same name in function scope (shadowing case) + const outerVariable = functionScope.variables.find((v) => v.name === variable.name && v !== variable); + + // Per Annex B.3.3, hoisting only applies if outer binding is var/function (not let/const) + const isOuterLetOrConst = outerVariable?.defs.some( + (def) => def.type === 'Variable' && (def.parent?.kind === 'let' || def.parent?.kind === 'const') + ); + + // Skip Annex B hoisting if there's a let/const with the same name + if (isOuterLetOrConst) { + continue; + } + + const targetVariable = outerVariable ?? variable; + + if (outerVariable) { + // Merge inner function's identifiers and references into outer + outerVariable.identifiers.push(...variable.identifiers); + outerVariable.references.push(...variable.references); + } else { + // Move variable to function scope so references can find it + functionScope.variables.push(variable); + } + + // Remove from block scope + scope.variables.splice(i, 1); + + // Link "through" references with matching name to the target variable + this.linkThroughReferences(variable.name, functionScope, targetVariable); + } + }); + } + + /** + * Link unresolved "through" references to a variable. + * + * @param {string} name - The variable name to match + * @param {Scope} scope - The scope to start searching from + * @param {Variable} targetVariable - The variable to link references to + */ + private linkThroughReferences(name: string, scope: eslintScope.Scope, targetVariable: eslintScope.Variable): void { + for (let i = scope.through.length - 1; i >= 0; i--) { + if (scope.through[i].identifier.name === name) { + targetVariable.references.push(scope.through[i]); + scope.through.splice(i, 1); + } + } + + for (const childScope of scope.childScopes) { + this.linkThroughReferences(name, childScope, targetVariable); + } + } + /** * @param {Scope} scope */ @@ -150,4 +250,18 @@ export class ScopeAnalyzer implements IScopeAnalyzer { this.sanitizeScopes(childScope); } } + + /** + * Walk through all scopes in the scope tree + * + * @param {Scope} scope - Starting scope + * @param {Function} callback - Function to call for each scope + */ + private walkScopes(scope: eslintScope.Scope, callback: (scope: eslintScope.Scope) => void): void { + callback(scope); + + for (const childScope of scope.childScopes) { + this.walkScopes(childScope, callback); + } + } } diff --git a/src/node/NodeUtils.ts b/src/node/NodeUtils.ts index 2834fb661..11cf6f305 100644 --- a/src/node/NodeUtils.ts +++ b/src/node/NodeUtils.ts @@ -122,6 +122,11 @@ export class NodeUtils { return node; } + // Handle primitives directly - don't try to clone them as objects + if (typeof node !== 'object') { + return node; + } + const copy: Partial = {}; const nodeKeys: (keyof T)[] = <(keyof T)[]>Object.keys(node); diff --git a/test/functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts b/test/functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts index b0f82d724..188f6d0cc 100644 --- a/test/functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts +++ b/test/functional-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec.ts @@ -2,6 +2,7 @@ import 'reflect-metadata'; import { assert } from 'chai'; +import { evalLocal } from '../../../helpers/evalLocal'; import { readFileAsString } from '../../../helpers/readFileAsString'; import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade'; @@ -43,5 +44,82 @@ describe('ScopeAnalyzer', () => { assert.equal(error, null); }); }); + + describe('Variant #2: Annex B function hoisting', () => { + describe('Variant #1: basic block-scoped function hoisting', () => { + const samplesCount: number = 50; + + let testFunc: () => void; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/annex-b-function-hoisting.js'); + + testFunc = () => { + for (let i = 0; i < samplesCount; i++) { + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + seed: i + }).getObfuscatedCode(); + + const result = evalLocal(obfuscatedCode); + + if (result.test1 !== 'foo') { + throw new Error('test1 failed: expected foo, got ' + result.test1); + } + + if (result.test2 !== 'bar') { + throw new Error('test2 failed: expected bar, got ' + result.test2); + } + } + }; + }); + + it('should correctly handle Annex B function hoisting references', () => { + assert.doesNotThrow(testFunc); + }); + }); + + describe('Variant #2: strict mode should not apply Annex B hoisting', () => { + let testFunc: () => void; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/annex-b-strict-mode.js'); + + testFunc = () => { + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + seed: 12345 + }).getObfuscatedCode(); + + eval(obfuscatedCode); + }; + }); + + it('should correctly handle strict mode block-scoped functions', () => { + assert.doesNotThrow(testFunc); + }); + }); + + describe('Variant #3: let/const shadowing should prevent Annex B hoisting', () => { + let testFunc: () => void; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/annex-b-let-const-shadowing.js'); + + testFunc = () => { + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + seed: 12345 + }).getObfuscatedCode(); + + const result = eval(obfuscatedCode); + if (result !== 'outer') { + throw new Error('Expected outer, got: ' + result); + } + }; + }); + + it('should not hoist when let/const shadows the function name', () => { + assert.doesNotThrow(testFunc); + }); + }); + }); }); }); diff --git a/test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-function-hoisting.js b/test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-function-hoisting.js new file mode 100644 index 000000000..0dc18de10 --- /dev/null +++ b/test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-function-hoisting.js @@ -0,0 +1,39 @@ +// Basic Annex B case: function in block referenced after block +function test1() { + if (true) { + function foo() { + return 'foo'; + } + } + return foo(); +} + +// Function in switch case +function test2(x) { + switch (x) { + case 1: + function bar() { + return 'bar'; + } + break; + } + return bar(); +} + +// Multiple blocks with same function name +function test3() { + if (true) { + function baz() { + return 'first'; + } + } + if (false) { + function baz() { + return 'second'; + } + } + return baz(); +} + +// Return results for testing +({ test1: test1(), test2: test2(1) }); diff --git a/test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-let-const-shadowing.js b/test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-let-const-shadowing.js new file mode 100644 index 000000000..fee0550b8 --- /dev/null +++ b/test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-let-const-shadowing.js @@ -0,0 +1,9 @@ +function test() { + let foo = 'outer'; + if (true) { + function foo() { return 'inner'; } + foo(); // block-scoped foo + } + return foo; // should be 'outer', not the function +} +test(); diff --git a/test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-strict-mode.js b/test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-strict-mode.js new file mode 100644 index 000000000..6bff144bf --- /dev/null +++ b/test/functional-tests/analyzers/scope-analyzer/fixtures/annex-b-strict-mode.js @@ -0,0 +1,11 @@ +'use strict'; +function test() { + let foo; + if (true) { + function foo() { return 'inner'; } + foo(); // This refers to block-scoped foo + } + // foo here is the outer let, which is undefined + return typeof foo; +} +test(); diff --git a/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/ObjectPatternPropertiesTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/ObjectPatternPropertiesTransformer.spec.ts index 69a870363..dd43acb1d 100644 --- a/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/ObjectPatternPropertiesTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/ObjectPatternPropertiesTransformer.spec.ts @@ -3,6 +3,7 @@ import { assert } from 'chai'; import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; import { readFileAsString } from '../../../../helpers/readFileAsString'; +import { evalLocal } from '../../../../helpers/evalLocal'; import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade'; @@ -142,4 +143,62 @@ describe('ObjectPatternPropertiesTransformer', () => { }); }); }); + + describe('Variant #3: destructuring default parameter with var shadowing', () => { + describe('Variant #1: destructuring default should reference outer var, not inner var', () => { + let code: string; + let obfuscatedCode: string; + + before(() => { + code = readFileAsString(__dirname + '/fixtures/destructuring-default-outer-var.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); + }); + + it('should correctly resolve destructuring default to outer variable', () => { + // Default parameter `a = x` should use outer 'x' value ('outer'), + // NOT the inner var x = 'inner' which is in the function body scope + assert.equal(evalLocal(code), 'outer'); + assert.equal(evalLocal(obfuscatedCode), evalLocal(code)); + }); + }); + + describe('Variant #2: nested destructuring default should reference outer var', () => { + let code: string; + let obfuscatedCode: string; + + before(() => { + code = readFileAsString(__dirname + '/fixtures/nested-destructuring-default-outer-var.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); + }); + + it('should correctly resolve nested destructuring default to outer variable', () => { + assert.equal(evalLocal(code), 'outer'); + assert.equal(evalLocal(obfuscatedCode), evalLocal(code)); + }); + }); + + describe('Variant #3: simple default param with var shadow', () => { + let code: string; + let obfuscatedCode: string; + + before(() => { + code = readFileAsString(__dirname + '/fixtures/simple-default-param-outer-var.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); + }); + + it('should correctly resolve default param to outer variable', () => { + assert.equal(evalLocal(code), 'outer'); + assert.equal(evalLocal(obfuscatedCode), evalLocal(code)); + }); + }); + }); }); diff --git a/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/destructuring-default-outer-var.js b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/destructuring-default-outer-var.js new file mode 100644 index 000000000..614804148 --- /dev/null +++ b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/destructuring-default-outer-var.js @@ -0,0 +1,8 @@ +(function() { + var x = 'outer'; + function f({ a = x } = {}) { + var x = 'inner'; + return a; + } + return f(); +})(); diff --git a/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/nested-destructuring-default-outer-var.js b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/nested-destructuring-default-outer-var.js new file mode 100644 index 000000000..bf8d3fa64 --- /dev/null +++ b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/nested-destructuring-default-outer-var.js @@ -0,0 +1,8 @@ +(function() { + var x = 'outer'; + function f({ a: { b = x } } = { a: {} }) { + var x = 'inner'; + return b; + } + return f(); +})(); diff --git a/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/simple-default-param-outer-var.js b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/simple-default-param-outer-var.js new file mode 100644 index 000000000..926fe3fec --- /dev/null +++ b/test/functional-tests/node-transformers/converting-transformers/object-pattern-properties-transformer/fixtures/simple-default-param-outer-var.js @@ -0,0 +1,8 @@ +(function() { + var x = 'outer'; + function f(a = x) { + var x = 'inner'; + return a; + } + return f(); +})(); diff --git a/test/helpers/evalLocal.ts b/test/helpers/evalLocal.ts new file mode 100644 index 000000000..237c669ac --- /dev/null +++ b/test/helpers/evalLocal.ts @@ -0,0 +1,9 @@ +/** + * Evaluates code using indirect eval. + * Indirect eval runs in global scope without inheriting strict mode from the calling context. + * This is needed for testing features like Annex B function hoisting. + * + * @param {string} code + * @returns {any} + */ +export const evalLocal = (code: string): any => (0, eval)(code); From 44028a147f90704d5cbb40ee13e6248b3f83e413 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Tue, 27 Jan 2026 22:19:27 +0400 Subject: [PATCH 38/87] Fixed `transformObjectKeys` incorrectly hoisting object literal outsie of loop (#1375) --- CHANGELOG.md | 4 + package.json | 2 +- .../ObjectExpressionKeysTransformer.ts | 36 ++++++++- src/node/NodeGuards.ts | 21 +++++ .../issues/fixtures/issue1300-do-while.js | 9 +++ .../issues/fixtures/issue1300-for-in.js | 8 ++ .../issues/fixtures/issue1300-for-of.js | 7 ++ .../issues/fixtures/issue1300-while.js | 8 ++ .../issues/fixtures/issue1300.js | 8 ++ .../functional-tests/issues/issue1300.spec.ts | 79 +++++++++++++++++++ .../ObjectExpressionKeysTransformer.spec.ts | 24 +++--- 11 files changed, 192 insertions(+), 14 deletions(-) create mode 100644 test/functional-tests/issues/fixtures/issue1300-do-while.js create mode 100644 test/functional-tests/issues/fixtures/issue1300-for-in.js create mode 100644 test/functional-tests/issues/fixtures/issue1300-for-of.js create mode 100644 test/functional-tests/issues/fixtures/issue1300-while.js create mode 100644 test/functional-tests/issues/fixtures/issue1300.js create mode 100644 test/functional-tests/issues/issue1300.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fbbaf6f5..f64fba88e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log +v5.2.1 +--- +* Fixed `transformObjectKeys` incorrectly hoisting object literal outside of loop when loop body is a single statement without braces, causing all iterations to share the same object reference. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1300 + v5.2.0 --- * Skip obfuscation of `process.env.*` diff --git a/package.json b/package.json index 7bb02fa54..4baf28c3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "5.2.0", + "version": "5.2.1", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", diff --git a/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts b/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts index e0addf21f..05bc0af6c 100644 --- a/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts +++ b/src/node-transformers/converting-transformers/ObjectExpressionKeysTransformer.ts @@ -127,7 +127,8 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { ObjectExpressionKeysTransformer.isProhibitedSequenceExpression( objectExpressionNode, objectExpressionHostStatement - ) + ) || + ObjectExpressionKeysTransformer.isProhibitedLoopBody(objectExpressionNode) ) { return true; } @@ -140,6 +141,39 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer { return hasReferencedIdentifier || hasCallExpression; } + /** + * @param {ObjectExpression} objectExpressionNode + * @returns {boolean} + */ + private static isProhibitedLoopBody(objectExpressionNode: ESTree.ObjectExpression): boolean { + let currentNode: ESTree.Node | undefined = objectExpressionNode; + + while (currentNode) { + const parentNode: ESTree.Node | undefined = currentNode.parentNode; + + if (!parentNode || parentNode === currentNode) { + break; + } + + const isNonBlockLoopBody: boolean = + NodeGuards.isLoopStatementNode(parentNode) && + parentNode.body === currentNode && + !NodeGuards.isBlockStatementNode(currentNode); + + if (isNonBlockLoopBody) { + return true; + } + + if (NodeGuards.isFunctionNode(parentNode) || NodeGuards.isProgramNode(parentNode)) { + break; + } + + currentNode = parentNode; + } + + return false; + } + /** * @param {ObjectExpression} objectExpressionNode * @param {Node} objectExpressionNodeParentNode diff --git a/src/node/NodeGuards.ts b/src/node/NodeGuards.ts index b34962a39..da88ffecd 100644 --- a/src/node/NodeGuards.ts +++ b/src/node/NodeGuards.ts @@ -330,6 +330,27 @@ export class NodeGuards { return node.type === NodeType.LogicalExpression; } + /** + * @param {Node} node + * @returns {boolean} + */ + public static isLoopStatementNode( + node: ESTree.Node + ): node is + | ESTree.ForStatement + | ESTree.ForInStatement + | ESTree.ForOfStatement + | ESTree.WhileStatement + | ESTree.DoWhileStatement { + return ( + NodeGuards.isForStatementNode(node) || + NodeGuards.isForInStatementNode(node) || + NodeGuards.isForOfStatementNode(node) || + NodeGuards.isWhileStatementNode(node) || + NodeGuards.isDoWhileStatementNode(node) + ); + } + /** * @param {Node} node * @returns {boolean} diff --git a/test/functional-tests/issues/fixtures/issue1300-do-while.js b/test/functional-tests/issues/fixtures/issue1300-do-while.js new file mode 100644 index 000000000..ddb2f0380 --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1300-do-while.js @@ -0,0 +1,9 @@ +(function() { + let arr = []; + let i = 0; + do + arr.push({value: 0}); + while (++i < 3); + arr[0].value = 1; + return arr[0] === arr[1]; +})(); diff --git a/test/functional-tests/issues/fixtures/issue1300-for-in.js b/test/functional-tests/issues/fixtures/issue1300-for-in.js new file mode 100644 index 000000000..162f0e7c1 --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1300-for-in.js @@ -0,0 +1,8 @@ +(function() { + let arr = []; + let obj = {a: 1, b: 2, c: 3}; + for (let key in obj) + arr.push({value: 0}); + arr[0].value = 1; + return arr[0] === arr[1]; +})(); diff --git a/test/functional-tests/issues/fixtures/issue1300-for-of.js b/test/functional-tests/issues/fixtures/issue1300-for-of.js new file mode 100644 index 000000000..01c3d6d67 --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1300-for-of.js @@ -0,0 +1,7 @@ +(function() { + let arr = []; + for (let x of [1, 2, 3]) + arr.push({value: 0}); + arr[0].value = 1; + return arr[0] === arr[1]; +})(); diff --git a/test/functional-tests/issues/fixtures/issue1300-while.js b/test/functional-tests/issues/fixtures/issue1300-while.js new file mode 100644 index 000000000..e64e93267 --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1300-while.js @@ -0,0 +1,8 @@ +(function() { + let arr = []; + let i = 0; + while (i++ < 3) + arr.push({value: 0}); + arr[0].value = 1; + return arr[0] === arr[1]; +})(); diff --git a/test/functional-tests/issues/fixtures/issue1300.js b/test/functional-tests/issues/fixtures/issue1300.js new file mode 100644 index 000000000..7d9fdc1c9 --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1300.js @@ -0,0 +1,8 @@ +// Object inside for loop should create new object each iteration +(function() { + let arr = []; + for (let i = 0; i < 3; i++) + arr.push({value: 0}); + arr[0].value = 1; + return arr[0] === arr[1]; // should be false +})(); diff --git a/test/functional-tests/issues/issue1300.spec.ts b/test/functional-tests/issues/issue1300.spec.ts new file mode 100644 index 000000000..612be091a --- /dev/null +++ b/test/functional-tests/issues/issue1300.spec.ts @@ -0,0 +1,79 @@ +import { assert } from 'chai'; +import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../helpers/readFileAsString'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; + +// +// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1300 +// +describe('Issue #1300', () => { + describe('Object inside loop should create new object each iteration', () => { + const samplesCount = 50; + + it('does not break object creation semantics with transformObjectKeys', () => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1300.js'); + + for (let i = 0; i < samplesCount; i++) { + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true, + seed: i + }).getObfuscatedCode(); + + const originalResult = eval(code); + const obfuscatedResult = eval(obfuscatedCode); + + assert.equal(originalResult, false, 'Original code should return false'); + assert.equal(obfuscatedResult, false, `Obfuscated code should return false (seed: ${i})`); + } + }); + + it('does not break with for-in loop', () => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1300-for-in.js'); + + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); + + assert.equal(eval(code), false); + assert.equal(eval(obfuscatedCode), false); + }); + + it('does not break with for-of loop', () => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1300-for-of.js'); + + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); + + assert.equal(eval(code), false); + assert.equal(eval(obfuscatedCode), false); + }); + + it('does not break with while loop', () => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1300-while.js'); + + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); + + assert.equal(eval(code), false); + assert.equal(eval(obfuscatedCode), false); + }); + + it('does not break with do-while loop', () => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1300-do-while.js'); + + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + }).getObfuscatedCode(); + + assert.equal(eval(code), false); + assert.equal(eval(obfuscatedCode), false); + }); + }); +}); diff --git a/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts index d261014a1..41b4e9eb9 100644 --- a/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts @@ -1092,13 +1092,13 @@ describe('ObjectExpressionKeysTransformer', () => { }); describe('Variant #2: without block statement', () => { + // Object should NOT be transformed when inside loop without block statement + // to prevent all iterations sharing the same object reference (issue #1300) const match: string = `` + `var ${variableMatch};` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['bar'] *= *'bar';` + `for *\\(var ${variableMatch} *= *0x0; *${variableMatch} *< *0xa; *${variableMatch}\\+\\+\\) *` + - `${variableMatch} *= *${variableMatch};` + + `${variableMatch} *= *\\{'bar': *'bar'\\};` + ``; const regExp: RegExp = new RegExp(match); @@ -1151,13 +1151,13 @@ describe('ObjectExpressionKeysTransformer', () => { }); describe('Variant #2: without block statement', () => { + // Object should NOT be transformed when inside loop without block statement + // to prevent all iterations sharing the same object reference (issue #1300) const match: string = `` + `var ${variableMatch} *= *{};` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['bar'] *= *'bar';` + `for *\\(var ${variableMatch} in *${variableMatch}\\) *` + - `${variableMatch} *= *${variableMatch};` + + `${variableMatch} *= *\\{'bar': *'bar'\\};` + ``; const regExp: RegExp = new RegExp(match); @@ -1210,13 +1210,13 @@ describe('ObjectExpressionKeysTransformer', () => { }); describe('Variant #2: without block statement', () => { + // Object should NOT be transformed when inside loop without block statement + // to prevent all iterations sharing the same object reference (issue #1300) const match: string = `` + `var ${variableMatch} *= *\\[];` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['bar'] *= *'bar';` + `for *\\(var ${variableMatch} of *${variableMatch}\\) *` + - `${variableMatch} *= *${variableMatch};` + + `${variableMatch} *= *\\{'bar': *'bar'\\};` + ``; const regExp: RegExp = new RegExp(match); @@ -1268,13 +1268,13 @@ describe('ObjectExpressionKeysTransformer', () => { }); describe('Variant #2: without block statement', () => { + // Object should NOT be transformed when inside loop without block statement + // to prevent all iterations sharing the same object reference (issue #1300) const match: string = `` + `var ${variableMatch};` + - `var ${variableMatch} *= *{};` + - `${variableMatch}\\['bar'] *= *'bar';` + `while *\\(!!\\[]\\)` + - `${variableMatch} *= *${variableMatch};` + + `${variableMatch} *= *\\{'bar': *'bar'\\};` + ``; const regExp: RegExp = new RegExp(match); From ccece3fef175f2589b347e6811ec13429652e279 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Tue, 27 Jan 2026 22:59:28 +0400 Subject: [PATCH 39/87] Fixed parsing error when `await` is used as an identifier in non-async context (#1376) --- CHANGELOG.md | 1 + src/ASTParserFacade.ts | 6 ++- .../fixtures/issue1127-top-level-await.js | 2 + .../issues/fixtures/issue1127.js | 1 + .../functional-tests/issues/issue1127.spec.ts | 43 +++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/functional-tests/issues/fixtures/issue1127-top-level-await.js create mode 100644 test/functional-tests/issues/fixtures/issue1127.js create mode 100644 test/functional-tests/issues/issue1127.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f64fba88e..517c85999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Change Log v5.2.1 --- * Fixed `transformObjectKeys` incorrectly hoisting object literal outside of loop when loop body is a single statement without braces, causing all iterations to share the same object reference. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1300 +* Fixed parsing error when `await` is used as an identifier in non-async context. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1127 v5.2.0 --- diff --git a/src/ASTParserFacade.ts b/src/ASTParserFacade.ts index 796f2ad8b..8e3c27bfb 100644 --- a/src/ASTParserFacade.ts +++ b/src/ASTParserFacade.ts @@ -58,7 +58,11 @@ export class ASTParserFacade { const comments: ESTree.Comment[] = []; const config: acorn.Options = { ...inputConfig, - allowAwaitOutsideFunction: true, + allowAwaitOutsideFunction: false, + allowReserved: true, + allowImportExportEverywhere: true, + allowReturnOutsideFunction: true, + allowSuperOutsideMethod: true, onComment: comments, sourceType }; diff --git a/test/functional-tests/issues/fixtures/issue1127-top-level-await.js b/test/functional-tests/issues/fixtures/issue1127-top-level-await.js new file mode 100644 index 000000000..9425538e2 --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1127-top-level-await.js @@ -0,0 +1,2 @@ +const x = await Promise.resolve(1); +console.log(x); diff --git a/test/functional-tests/issues/fixtures/issue1127.js b/test/functional-tests/issues/fixtures/issue1127.js new file mode 100644 index 000000000..302fcad13 --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1127.js @@ -0,0 +1 @@ +try { await; } catch { console.log('caught'); } diff --git a/test/functional-tests/issues/issue1127.spec.ts b/test/functional-tests/issues/issue1127.spec.ts new file mode 100644 index 000000000..bc95dba2a --- /dev/null +++ b/test/functional-tests/issues/issue1127.spec.ts @@ -0,0 +1,43 @@ +import { assert } from 'chai'; +import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../helpers/readFileAsString'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; + +// +// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1127 +// +describe('Issue #1127', () => { + describe('`await` used as identifier should not crash', () => { + let testFunc: () => string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1127.js'); + + testFunc = () => + JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); + }); + + it('does not crash on obfuscating', () => { + assert.doesNotThrow(testFunc); + }); + }); + + describe('top-level await should still work', () => { + let testFunc: () => string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1127-top-level-await.js'); + + testFunc = () => + JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); + }); + + it('does not crash on obfuscating', () => { + assert.doesNotThrow(testFunc); + }); + }); +}); From 05aacd9dfe593c706a6af3a19a2701ce7369161c Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Tue, 27 Jan 2026 23:34:22 +0400 Subject: [PATCH 40/87] Fixed `deadCodeInjection` causing SyntaxError when `arguments` from collected block statements was injected into class field initializers or static initialization blocks (#1377) --- CHANGELOG.md | 1 + .../DeadCodeInjectionTransformer.ts | 5 +- .../issues/fixtures/issue1166-static-block.js | 33 ++++++++++++ .../issues/fixtures/issue1166.js | 33 ++++++++++++ .../functional-tests/issues/issue1166.spec.ts | 53 +++++++++++++++++++ 5 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 test/functional-tests/issues/fixtures/issue1166-static-block.js create mode 100644 test/functional-tests/issues/fixtures/issue1166.js create mode 100644 test/functional-tests/issues/issue1166.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 517c85999..52c7bb10e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ v5.2.1 --- * Fixed `transformObjectKeys` incorrectly hoisting object literal outside of loop when loop body is a single statement without braces, causing all iterations to share the same object reference. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1300 * Fixed parsing error when `await` is used as an identifier in non-async context. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1127 +* Fixed `deadCodeInjection` causing SyntaxError when `arguments` from collected block statements was injected into class field initializers or static initialization blocks. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1166 v5.2.0 --- diff --git a/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts b/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts index d9508e327..cb706d338 100644 --- a/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts +++ b/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts @@ -101,6 +101,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { * @param {Node} targetNode * @returns {boolean} */ + // eslint-disable-next-line complexity private static isProhibitedNodeInsideCollectedBlockStatement(targetNode: ESTree.Node): boolean { return ( NodeGuards.isFunctionDeclarationNode(targetNode) || // can break code on strict mode @@ -110,7 +111,9 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer { NodeGuards.isYieldExpressionNode(targetNode) || NodeGuards.isSuperNode(targetNode) || (NodeGuards.isForOfStatementNode(targetNode) && targetNode.await) || - NodeGuards.isPrivateIdentifierNode(targetNode) + NodeGuards.isPrivateIdentifierNode(targetNode) || + // `arguments` is not allowed in class field initializers or static initialization blocks + (NodeGuards.isIdentifierNode(targetNode) && targetNode.name === 'arguments') ); } diff --git a/test/functional-tests/issues/fixtures/issue1166-static-block.js b/test/functional-tests/issues/fixtures/issue1166-static-block.js new file mode 100644 index 000000000..02f37b467 --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1166-static-block.js @@ -0,0 +1,33 @@ +// Function that uses `arguments` - this block can be collected for dead code injection +function logArgs() { + console.log(arguments); + console.log(arguments.length); +} + +function foo() { + console.log(arguments[0]); +} + +function bar() { + var args = arguments; + return args; +} + +// Class with static initialization block - dead code should NOT be injected here with `arguments` +class MyClass { + static value; + + static { + console.log('static block'); + MyClass.value = 42; + } + + method() { + console.log('method'); + } +} + +console.log(MyClass.value); +logArgs(1, 2, 3); +foo('test'); +bar('a', 'b'); diff --git a/test/functional-tests/issues/fixtures/issue1166.js b/test/functional-tests/issues/fixtures/issue1166.js new file mode 100644 index 000000000..572f89d87 --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1166.js @@ -0,0 +1,33 @@ +// Function that uses `arguments` - this block can be collected for dead code injection +function logArgs() { + console.log(arguments); + console.log(arguments.length); +} + +function foo() { + console.log(arguments[0]); +} + +function bar() { + var args = arguments; + return args; +} + +// Class with field initializers - dead code should NOT be injected here with `arguments` +class MyClass { + field1 = (() => { + console.log('initializer'); + return 1; + })(); + + field2 = 2; + + method() { + console.log('method'); + } +} + +new MyClass(); +logArgs(1, 2, 3); +foo('test'); +bar('a', 'b'); diff --git a/test/functional-tests/issues/issue1166.spec.ts b/test/functional-tests/issues/issue1166.spec.ts new file mode 100644 index 000000000..dad424c73 --- /dev/null +++ b/test/functional-tests/issues/issue1166.spec.ts @@ -0,0 +1,53 @@ +import { assert } from 'chai'; +import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../helpers/readFileAsString'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; + +// +// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1166 +// +describe('Issue #1166', () => { + describe('`arguments` in collected block statement should not be injected into class field initializer', () => { + let testFunc: () => string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1166.js'); + + testFunc = () => + JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1 + }).getObfuscatedCode(); + }); + + it('does not crash on obfuscating', () => { + // Run multiple times to increase chance of triggering the bug + for (let i = 0; i < 50; i++) { + assert.doesNotThrow(testFunc); + } + }); + }); + + describe('`arguments` in collected block statement should not be injected into static block', () => { + let testFunc: () => string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1166-static-block.js'); + + testFunc = () => + JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + deadCodeInjection: true, + deadCodeInjectionThreshold: 1 + }).getObfuscatedCode(); + }); + + it('does not crash on obfuscating', () => { + // Run multiple times to increase chance of triggering the bug + for (let i = 0; i < 50; i++) { + assert.doesNotThrow(testFunc); + } + }); + }); +}); From 999e93c084fe4477e026dab6762dace2dd8ccbbc Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Tue, 27 Jan 2026 23:34:05 +0400 Subject: [PATCH 41/87] Fixed `transformObjectKeys` with `mangled` identifier generator causing variable shadowing when extracted object variable name matched an existing inner scope variable --- CHANGELOG.md | 1 + .../AbstractIdentifierNamesGenerator.ts | 24 ++++++++++++++ .../DictionaryIdentifierNamesGenerator.ts | 2 +- .../HexadecimalIdentifierNamesGenerator.ts | 2 +- .../MangledIdentifierNamesGenerator.ts | 2 +- .../issues/fixtures/issue1232.js | 1 + .../functional-tests/issues/issue1232.spec.ts | 32 +++++++++++++++++++ 7 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 test/functional-tests/issues/fixtures/issue1232.js create mode 100644 test/functional-tests/issues/issue1232.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 52c7bb10e..670232a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ v5.2.1 * Fixed `transformObjectKeys` incorrectly hoisting object literal outside of loop when loop body is a single statement without braces, causing all iterations to share the same object reference. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1300 * Fixed parsing error when `await` is used as an identifier in non-async context. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1127 * Fixed `deadCodeInjection` causing SyntaxError when `arguments` from collected block statements was injected into class field initializers or static initialization blocks. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1166 +* Fixed `transformObjectKeys` with `mangled` identifier generator causing variable shadowing when extracted object variable name matched an existing inner scope variable. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1232 v5.2.0 --- diff --git a/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts index 9779d6af7..161f1cc62 100644 --- a/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts @@ -31,6 +31,11 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam */ protected readonly lexicalScopesPreservedNamesMap: WeakMap> = new WeakMap(); + /** + * @type {Set} + */ + protected readonly allLexicalScopePreservedNames: Set = new Set(); + /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options @@ -72,6 +77,8 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam preservedNamesForLexicalScopeSet.add(name); this.lexicalScopesPreservedNamesMap.set(lexicalScopeNode, preservedNamesForLexicalScopeSet); + + this.allLexicalScopePreservedNames.add(name); } /** @@ -108,6 +115,23 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam return true; } + /** + * Checks if the name is valid and not preserved in any scope (global or lexical). + * This is used for global scope name generation to avoid conflicts with + * variables in any lexical scope that might shadow the global variable. + * + * @param {string} name + * @returns {boolean} + */ + public isValidIdentifierNameInAllScopes(name: string): boolean { + if (!this.isValidIdentifierName(name)) { + return false; + } + + // Check if the name is preserved in any lexical scope + return !this.allLexicalScopePreservedNames.has(name); + } + /** * @param {string} name * @returns {boolean} diff --git a/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts index da6195a57..7d8b75a7e 100644 --- a/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts @@ -86,7 +86,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG const identifierName: string = this.generateNewDictionaryName((newIdentifierName: string) => { const identifierNameWithPrefix: string = `${prefix}${newIdentifierName}`; - return this.isValidIdentifierName(identifierNameWithPrefix); + return this.isValidIdentifierNameInAllScopes(identifierNameWithPrefix); }); const identifierNameWithPrefix = `${prefix}${identifierName}`; diff --git a/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts index b47629013..c6f87933e 100644 --- a/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts @@ -43,7 +43,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames const baseIdentifierName: string = hexadecimalNumber.slice(0, baseNameLength); const identifierName: string = `_${baseIdentifierName}`; - if (!this.isValidIdentifierName(identifierName)) { + if (!this.isValidIdentifierNameInAllScopes(identifierName)) { return this.generateNext(nameLength); } diff --git a/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts index 1c011bda3..c5ca35c87 100644 --- a/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts @@ -103,7 +103,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene (newIdentifierName: string) => { const identifierNameWithPrefix: string = `${prefix}${newIdentifierName}`; - return this.isValidIdentifierName(identifierNameWithPrefix); + return this.isValidIdentifierNameInAllScopes(identifierNameWithPrefix); } ); const identifierNameWithPrefix: string = `${prefix}${identifierName}`; diff --git a/test/functional-tests/issues/fixtures/issue1232.js b/test/functional-tests/issues/fixtures/issue1232.js new file mode 100644 index 000000000..45c0f819e --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1232.js @@ -0,0 +1 @@ +[].forEach(a => a === { a: 1 }); diff --git a/test/functional-tests/issues/issue1232.spec.ts b/test/functional-tests/issues/issue1232.spec.ts new file mode 100644 index 000000000..3b1375e86 --- /dev/null +++ b/test/functional-tests/issues/issue1232.spec.ts @@ -0,0 +1,32 @@ +import { assert } from 'chai'; +import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../helpers/readFileAsString'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; + +// +// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1232 +// +describe('Issue #1232', () => { + describe('transformObjectKeys should not cause variable shadowing with mangled identifiers', () => { + let obfuscatedCode: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1232.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + identifierNamesGenerator: 'mangled', + transformObjectKeys: true + }).getObfuscatedCode(); + }); + + it('should not rename extracted object variable to same name as function parameter', () => { + const shadowingPattern = /(\w+)\s*===\s*\1[)\s;,]/; + + assert.isFalse( + shadowingPattern.test(obfuscatedCode), + `Variable shadowing detected in obfuscated code: ${obfuscatedCode}` + ); + }); + }); +}); From 6864328c0334e03513a449f703f8b0482e765510 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Wed, 28 Jan 2026 01:04:40 +0400 Subject: [PATCH 42/87] Fix identifiers generation (#1378) --- ...ctExpressionVariableDeclarationHostNode.ts | 4 +- .../AbstractIdentifierNamesGenerator.ts | 6 ++ .../DictionaryIdentifierNamesGenerator.ts | 37 +++++++--- .../HexadecimalIdentifierNamesGenerator.ts | 67 +++++++++++++------ .../MangledIdentifierNamesGenerator.ts | 46 ++++++++----- .../IIdentifierNamesGenerator.ts | 12 ++++ 6 files changed, 126 insertions(+), 46 deletions(-) diff --git a/src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts b/src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts index 3bb223c95..dfdd1a152 100644 --- a/src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts +++ b/src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts @@ -58,8 +58,10 @@ export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomN * @returns {TStatement[]} */ protected getNodeStructure(): TStatement[] { + // Use generateForGlobalScopeWithAllScopesValidation when in global scope + // to avoid shadowing variables in inner lexical scopes const variableDeclarationName: string = NodeGuards.isProgramNode(this.lexicalScopeNode) - ? this.identifierNamesGenerator.generateForGlobalScope() + ? this.identifierNamesGenerator.generateForGlobalScopeWithAllScopesValidation() : this.identifierNamesGenerator.generateForLexicalScope(this.lexicalScopeNode); const structure: TStatement = NodeFactory.variableDeclarationNode( diff --git a/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts index 161f1cc62..a9655ad1f 100644 --- a/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts @@ -150,6 +150,12 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam */ public abstract generateForGlobalScope(nameLength?: number): string; + /** + * @param {number} nameLength + * @returns {string} + */ + public abstract generateForGlobalScopeWithAllScopesValidation(nameLength?: number): string; + /** * @param {TNodeWithLexicalScope} lexicalScopeNode * @param {number} nameLength diff --git a/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts index 7d8b75a7e..4db36fccd 100644 --- a/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts @@ -81,18 +81,14 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG * @returns {string} */ public generateForGlobalScope(): string { - const prefix: string = this.options.identifiersPrefix ? `${this.options.identifiersPrefix}` : ''; - - const identifierName: string = this.generateNewDictionaryName((newIdentifierName: string) => { - const identifierNameWithPrefix: string = `${prefix}${newIdentifierName}`; - - return this.isValidIdentifierNameInAllScopes(identifierNameWithPrefix); - }); - const identifierNameWithPrefix = `${prefix}${identifierName}`; - - this.preserveName(identifierNameWithPrefix); + return this.generateForGlobalScopeInternal((name) => this.isValidIdentifierName(name)); + } - return identifierNameWithPrefix; + /** + * @returns {string} + */ + public generateForGlobalScopeWithAllScopesValidation(): string { + return this.generateForGlobalScopeInternal((name) => this.isValidIdentifierNameInAllScopes(name)); } /** @@ -121,6 +117,25 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG return this.generateNewDictionaryName(); } + /** + * @param {(name: string) => boolean} validationFn + * @returns {string} + */ + private generateForGlobalScopeInternal(validationFn: (name: string) => boolean): string { + const prefix: string = this.options.identifiersPrefix ? `${this.options.identifiersPrefix}` : ''; + + const identifierName: string = this.generateNewDictionaryName((newIdentifierName: string) => { + const identifierNameWithPrefix: string = `${prefix}${newIdentifierName}`; + + return validationFn(identifierNameWithPrefix); + }); + const identifierNameWithPrefix = `${prefix}${identifierName}`; + + this.preserveName(identifierNameWithPrefix); + + return identifierNameWithPrefix; + } + /** * @param {(newIdentifierName: string) => boolean} validationFunction * @returns {string} diff --git a/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts index c6f87933e..59df523e5 100644 --- a/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts @@ -33,23 +33,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames * @returns {string} */ public generateNext(nameLength?: number): string { - const rangeMinInteger: number = 10000; - const rangeMaxInteger: number = 99_999_999; - const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger); - const hexadecimalNumber: string = NumberUtils.toHex(randomInteger); - const prefixLength: number = Utils.hexadecimalPrefix.length; - const baseNameLength: number = - (nameLength ?? HexadecimalIdentifierNamesGenerator.baseIdentifierNameLength) + prefixLength; - const baseIdentifierName: string = hexadecimalNumber.slice(0, baseNameLength); - const identifierName: string = `_${baseIdentifierName}`; - - if (!this.isValidIdentifierNameInAllScopes(identifierName)) { - return this.generateNext(nameLength); - } - - this.preserveName(identifierName); - - return identifierName; + return this.generateNextName(nameLength, (name) => this.isValidIdentifierName(name)); } /** @@ -57,9 +41,15 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames * @returns {string} */ public generateForGlobalScope(nameLength?: number): string { - const identifierName: string = this.generateNext(nameLength); + return this.generateForGlobalScopeInternal(nameLength, (name) => this.isValidIdentifierName(name)); + } - return `${this.options.identifiersPrefix}${identifierName}`.replace('__', '_'); + /** + * @param {number} nameLength + * @returns {string} + */ + public generateForGlobalScopeWithAllScopesValidation(nameLength?: number): string { + return this.generateForGlobalScopeInternal(nameLength, (name) => this.isValidIdentifierNameInAllScopes(name)); } /** @@ -79,4 +69,43 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames public generateForLabel(label: string, nameLength?: number): string { return this.generateNext(nameLength); } + + /** + * @param {number} nameLength + * @param {(name: string) => boolean} validationFn + * @returns {string} + */ + private generateForGlobalScopeInternal( + nameLength: number | undefined, + validationFn: (name: string) => boolean + ): string { + const identifierName: string = this.generateNextName(nameLength, validationFn); + + return `${this.options.identifiersPrefix}${identifierName}`.replace('__', '_'); + } + + /** + * @param {number} nameLength + * @param {(name: string) => boolean} validationFn + * @returns {string} + */ + private generateNextName(nameLength: number | undefined, validationFn: (name: string) => boolean): string { + const rangeMinInteger: number = 10000; + const rangeMaxInteger: number = 99_999_999; + const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger); + const hexadecimalNumber: string = NumberUtils.toHex(randomInteger); + const prefixLength: number = Utils.hexadecimalPrefix.length; + const baseNameLength: number = + (nameLength ?? HexadecimalIdentifierNamesGenerator.baseIdentifierNameLength) + prefixLength; + const baseIdentifierName: string = hexadecimalNumber.slice(0, baseNameLength); + const identifierName: string = `_${baseIdentifierName}`; + + if (!validationFn(identifierName)) { + return this.generateNextName(nameLength, validationFn); + } + + this.preserveName(identifierName); + + return identifierName; + } } diff --git a/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts b/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts index c5ca35c87..96d6c3371 100644 --- a/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts +++ b/src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts @@ -96,22 +96,15 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene * @returns {string} */ public generateForGlobalScope(nameLength?: number): string { - const prefix: string = this.options.identifiersPrefix ? `${this.options.identifiersPrefix}` : ''; - - const identifierName: string = this.generateNewMangledName( - this.lastMangledName, - (newIdentifierName: string) => { - const identifierNameWithPrefix: string = `${prefix}${newIdentifierName}`; - - return this.isValidIdentifierNameInAllScopes(identifierNameWithPrefix); - } - ); - const identifierNameWithPrefix: string = `${prefix}${identifierName}`; - - this.updatePreviousMangledName(identifierName); - this.preserveName(identifierNameWithPrefix); + return this.generateForGlobalScopeInternal((name) => this.isValidIdentifierName(name)); + } - return identifierNameWithPrefix; + /** + * @param {number} nameLength + * @returns {string} + */ + public generateForGlobalScopeWithAllScopesValidation(nameLength?: number): string { + return this.generateForGlobalScopeInternal((name) => this.isValidIdentifierNameInAllScopes(name)); } /** @@ -299,6 +292,29 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene return identifierName; } + /** + * @param {(name: string) => boolean} validationFn + * @returns {string} + */ + private generateForGlobalScopeInternal(validationFn: (name: string) => boolean): string { + const prefix: string = this.options.identifiersPrefix ? `${this.options.identifiersPrefix}` : ''; + + const identifierName: string = this.generateNewMangledName( + this.lastMangledName, + (newIdentifierName: string) => { + const identifierNameWithPrefix: string = `${prefix}${newIdentifierName}`; + + return validationFn(identifierNameWithPrefix); + } + ); + const identifierNameWithPrefix: string = `${prefix}${identifierName}`; + + this.updatePreviousMangledName(identifierName); + this.preserveName(identifierNameWithPrefix); + + return identifierNameWithPrefix; + } + /** * @param {TNodeWithLexicalScope[]} lexicalScopeNodes * @returns {string} diff --git a/src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts b/src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts index a5164d74a..11dad39eb 100644 --- a/src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts +++ b/src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts @@ -47,6 +47,18 @@ export interface IIdentifierNamesGenerator { */ isValidIdentifierNameInLexicalScopes(identifierName: string, lexicalScopeNodes: TNodeWithLexicalScope[]): boolean; + /** + * @param {string} identifierName + * @returns {boolean} + */ + isValidIdentifierNameInAllScopes(identifierName: string): boolean; + + /** + * @param {number} nameLength + * @returns {string} + */ + generateForGlobalScopeWithAllScopesValidation(nameLength?: number): string; + /** * @param {string} identifierName */ From 25427bcc0b8058de04fc9f434066a922e8bf5e38 Mon Sep 17 00:00:00 2001 From: Timofey Kachalov Date: Tue, 3 Feb 2026 20:22:11 +0400 Subject: [PATCH 43/87] Add Pro API support to CLI including support for large files obfuscation (#1381) --- CHANGELOG.md | 5 + README.md | 222 +++++- bin/javascript-obfuscator | 5 +- package.json | 3 +- src/JavaScriptObfuscatorCLIFacade.ts | 5 +- src/JavaScriptObfuscatorFacade.ts | 15 +- src/cli/JavaScriptObfuscatorCLI.ts | 215 +++++- src/cli/sanitizers/StrictModeSanitizer.ts | 13 + src/interfaces/options/ICLIOptions.ts | 2 + src/interfaces/pro-api/IProApiClient.ts | 8 + src/pro-api/ProApiClient.ts | 272 ++++++-- src/pro-api/enums/VMBytecodeFormat.ts | 9 + src/pro-api/enums/VMTargetFunctionsMode.ts | 9 + .../cli/JavaScriptObfuscatorCLI.spec.ts | 368 +++++++--- .../pro-api/ProApiClient.spec.ts | 652 +++++++++--------- test/index.spec.ts | 1 + test/unit-tests/pro-api/ProApiClient.spec.ts | 183 ++++- yarn.lock | 43 ++ 18 files changed, 1523 insertions(+), 507 deletions(-) create mode 100644 src/cli/sanitizers/StrictModeSanitizer.ts create mode 100644 src/pro-api/enums/VMBytecodeFormat.ts create mode 100644 src/pro-api/enums/VMTargetFunctionsMode.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 670232a2f..35118b467 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ Change Log +v5.3.0 +--- +* Add Pro API support to CLI +* Add large files upload support to Pro API + v5.2.1 --- * Fixed `transformObjectKeys` incorrectly hoisting object literal outside of loop when loop body is a single statement without braces, causing all iterations to share the same object reference. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1300 diff --git a/README.md b/README.md index 128eaba72..fe9b9759a 100644 --- a/README.md +++ b/README.md @@ -15,18 +15,20 @@ Huge thanks to all supporters! --- -### :rocket: JavaScript Obfuscator Pro with VM Obfuscation is out! +### :rocket: Obfuscator.io with VM Obfuscation is out! -**JavaScript Obfuscator Pro** features **VM-based bytecode obfuscation** — the most advanced code protection available. Your JavaScript functions are transformed into custom bytecode running on an embedded virtual machine, making reverse engineering extremely difficult. +**Obfuscator.io** features **VM-based bytecode obfuscation** — the most advanced code protection available. Your JavaScript functions are transformed into custom bytecode running on an embedded virtual machine, making reverse engineering extremely difficult. [Try it at obfuscator.io](https://obfuscator.io) +This package provides access to Obfuscator.io Pro API via CLI and Node.js API. + --- JavaScript Obfuscator is a powerful free obfuscator for JavaScript, containing a variety of features which provide protection for your source code. **Key features:** -- VM bytecode obfuscation (via [JavaScript Obfuscator Pro](https://obfuscator.io/)) +- VM bytecode obfuscation (via [Obfuscator.io](https://obfuscator.io/)) - variables renaming - strings extraction and encryption - dead code injection @@ -314,17 +316,17 @@ console.log(result.getObfuscatedCode()); **Parameters:** * `sourceCode` (`string`) – source code to obfuscate -* `options` (`Object`) – obfuscation options. **Must include `vmObfuscation: true`** +* `options` (`Object`) – obfuscation options. **Must include at least one Pro feature: `vmObfuscation: true` or `parseHtml: true`** * `apiConfig` (`Object`) – Pro API configuration: * `apiToken` (`string`, required) – your API token from obfuscator.io * `timeout` (`number`, optional) – request timeout in ms (default: `300000` - 5 minutes) - * `version` (`string`, optional) – JavaScript Obfuscator Pro version to use (e.g., `'5.0.0-beta.20'`). Defaults to latest version if not specified. + * `version` (`string`, optional) – Obfuscator.io version to use (e.g., `'5.0.3'`). Defaults to latest version if not specified. * `onProgress` (`function`, optional) – callback for progress updates during obfuscation **Returns:** `Promise` **Throws:** `ApiError` if: -- `vmObfuscation` is not enabled in options +- No Pro features (`vmObfuscation` or `parseHtml`) are enabled in options - API token is invalid or expired - API request fails @@ -341,7 +343,7 @@ const result = await JavaScriptObfuscator.obfuscatePro( }, { apiToken: 'your_javascript_obfuscator_pro_api_token', - version: '5.0.0-beta.20' // Use specific version + version: '5.0.3' // Use specific version } ); ``` @@ -367,6 +369,28 @@ const result = await JavaScriptObfuscator.obfuscatePro( ); ``` +### Checking for Pro Features + +Use `ProApiClient.hasProFeatures()` to check if options require the Pro API: + +```javascript +const { ProApiClient } = require('javascript-obfuscator'); + +const options = { vmObfuscation: true, compact: true }; + +if (ProApiClient.hasProFeatures(options)) { + // Use obfuscatePro() - requires API token + const result = await JavaScriptObfuscator.obfuscatePro(sourceCode, options, { apiToken }); +} else { + // Use regular obfuscate() - no API token needed + const result = JavaScriptObfuscator.obfuscate(sourceCode, options); +} +``` + +Pro features include: +- `vmObfuscation: true` – VM-based bytecode obfuscation +- `parseHtml: true` – HTML parsing with inline JavaScript obfuscation + ### Error Handling ```javascript @@ -383,6 +407,36 @@ try { } ``` +### CLI Usage with Pro API + +You can also use Pro API features directly from the CLI by providing your API token: + +```sh +javascript-obfuscator input.js --pro-api-token YOUR_API_TOKEN --vm-obfuscation true -o output.js +``` + +With a specific obfuscator version: + +```sh +javascript-obfuscator input.js --pro-api-token YOUR_API_TOKEN --pro-api-version 5.0.3 --vm-obfuscation true -o output.js +``` + +**CLI Options:** +- `--pro-api-token ` – Your API token from [obfuscator.io](https://obfuscator.io) +- `--pro-api-version ` – Obfuscator.io version to use (optional, defaults to latest) + +The CLI automatically detects when Pro features (`vmObfuscation` or `parseHtml`) are enabled and routes the request through the Pro API. + +### Large File Uploads + +For files larger than ~4MB, the Pro API uses client-side uploads to Vercel Blob storage. To enable this feature, install the optional `@vercel/blob` package: + +```sh +npm install @vercel/blob +``` + +Without this package, large file obfuscation will fail with an error message prompting you to install it. + --- ## CLI usage @@ -583,6 +637,37 @@ Following options are available for the JS Obfuscator: --target [browser, browser-no-eval, node] --transform-object-keys --unicode-escape-sequence + --pro-api-token + --pro-api-version + --vm-obfuscation + --vm-obfuscation-threshold + --vm-preprocess-identifiers + --vm-dynamic-opcodes + --vm-target-functions '' (comma separated) + --vm-exclude-functions '' (comma separated) + --vm-target-functions-mode [root, comment] + --vm-wrap-top-level-initializers + --vm-opcode-shuffle + --vm-bytecode-encoding + --vm-bytecode-array-encoding + --vm-bytecode-array-encoding-key + --vm-bytecode-array-encoding-key-getter + --vm-instruction-shuffle + --vm-jumps-encoding + --vm-decoy-opcodes + --vm-dead-code-injection + --vm-split-dispatcher + --vm-macro-ops + --vm-debug-protection + --vm-runtime-opcode-derivation + --vm-stateful-opcodes + --vm-stack-encoding + --vm-randomize-keys + --vm-indirect-dispatch + --vm-compact-dispatcher + --vm-bytecode-format [binary, json] + --parse-html + --strict-mode ``` @@ -1766,9 +1851,9 @@ The performance will be at a relatively normal level -## JavaScript Obfuscator Pro Options +## Obfuscator.io Pro Options -> :warning: **The following VM obfuscation/Pro options are available only via the [JavaScript Obfuscator Pro API](https://obfuscator.io/).** +> :warning: **The following VM obfuscation/Pro options are available only via the [Obfuscator.io Pro API](https://obfuscator.io/).** > > To use these options, you need a Pro API token from [obfuscator.io](https://obfuscator.io) and must call the `obfuscatePro()` method instead of `obfuscate()`. See the [Pro API Methods](#shield-pro-api-methods-vm-obfuscation) section for details. @@ -1785,6 +1870,8 @@ Type: `number` Default: `1` Controls what percentage of your root-level functions get VM protection. +> **Warning:** Values other than `1` may cause runtime bugs when VM-obfuscated and non-VM-obfuscated code share top-level variables. A value of `1` is strongly recommended. For selective function obfuscation, use `vmTargetFunctionsMode: 'comment'` with the `// javascript-obfuscator:vm` directive instead. + ### `vmPreprocessIdentifiers` Type: `boolean` Default: `true` @@ -1915,6 +2002,56 @@ Type: `boolean` Default: `false` Encodes the entire bytecode array as a single block. The array is decoded once at startup before execution begins. Use together with `vmBytecodeEncoding` for two layers of protection. +### `vmBytecodeArrayEncodingKey` +Type: `string` Default: `''` + +Custom encryption key for bytecode array encoding. When set, this key is used instead of the default environment-derived key. The key must be provided at runtime via `vmBytecodeArrayEncodingKeyGetter`. + +This option externalizes the encryption key - it's not embedded in the obfuscated code itself. While the key is still accessible at runtime (and thus not truly secret), this separation prevents static analysis tools from finding the key by examining the code alone. + +**Important:** The key must be available **synchronously** when the obfuscated code loads. Use synchronous storage like cookies, localStorage, sessionStorage, global variables, or DOM elements (e.g., server-injected meta tags). Async methods like `fetch()` cannot be used directly in the key getter expression. + +### `vmBytecodeArrayEncodingKeyGetter` +Type: `string` Default: `''` + +**Synchronous** JavaScript expression that **returns** the encryption key at runtime. This expression is evaluated when the obfuscated code loads, and must return the same key that was provided in `vmBytecodeArrayEncodingKey`. + +**The obfuscated code will only work when the key getter returns exactly the same key that was used during obfuscation.** If the keys don't match, decryption will fail and the code will produce garbage or errors. If the key getter returns `undefined`, `null`, or an empty string, the code will throw an error: "VM decryption key not available". + +**Important:** The key should NOT be defined in the same JavaScript file/script as the obfuscated code. Doing so defeats the purpose of key externalization, as static analysis could still find the key. Store the key in a separate source: server-set cookies, localStorage populated by another script, server-injected HTML meta tags, or a global variable set by a different script that loads before the obfuscated code. + +Examples: +```ts +// From cookie +vmBytecodeArrayEncodingKeyGetter: "document.cookie.match(/vmKey=([^;]+)/)?.[1]" + +// From localStorage +vmBytecodeArrayEncodingKeyGetter: "localStorage.getItem('vmKey')" + +// From global variable +vmBytecodeArrayEncodingKeyGetter: "window.__VM_KEY__" + +// From meta tag (server-injected) +vmBytecodeArrayEncodingKeyGetter: "document.querySelector('meta[name=\"vm-key\"]').content" + +// From nested object +vmBytecodeArrayEncodingKeyGetter: "window.config.encryption.key" +``` + +**Usage example:** +```ts +// Build time +JavaScriptObfuscator.obfuscate(code, { + vmObfuscation: true, + vmBytecodeArrayEncoding: true, + vmBytecodeArrayEncodingKey: 'mySecretKey123', + vmBytecodeArrayEncodingKeyGetter: 'window.__VM_KEY__' +}); + +// Runtime - key must be set before obfuscated code runs +window.__VM_KEY__ = 'mySecretKey123'; +``` + ### `vmJumpsEncoding` Type: `boolean` Default: `false` @@ -2001,6 +2138,17 @@ Encrypts values on the VM stack during execution. Values are encoded when pushed This option heavily affects performance. +### `vmInstructionShuffle` +Type: `boolean` Default: `false` + +Randomizes the bytecode instruction layout per function. Each function can have a different instruction array format: +- Layout 0: `[op, arg, op, arg, ...]` (interleaved - default) +- Layout 1: `[arg, op, arg, op, ...]` (swapped interleaved) +- Layout 2: `[op0, op1, ..., arg0, arg1, ...]` (opcodes first, then arguments) +- Layout 3: `[arg0, arg1, ..., op0, op1, ...]` (arguments first, then opcodes) + +This makes pattern recognition across functions harder during analysis. + ### `vmRandomizeKeys` Type: `boolean` Default: `false` @@ -2025,6 +2173,62 @@ Available values: * `true` - force strict mode treatment for all code, even without explicit `'use strict'` directive. Use this when your code will run in strict mode context (e.g., in ES modules, bundlers, or modern frameworks). * `false` - only explicit strict mode indicators (`'use strict'`, ES modules, class methods) are treated as strict. Parent scope inheritance still applies per JS spec. +### `parseHtml` +Type: `boolean` Default: `false` + +Enables obfuscation of JavaScript within HTML ` + + + + +`; + +JavaScriptObfuscator.obfuscate(html, { + parseHtml: true, + stringArray: true +}); + +// output: HTML with only the marked script obfuscated +``` + ## Frequently Asked Questions ### What javascript versions are supported? diff --git a/bin/javascript-obfuscator b/bin/javascript-obfuscator index 0946b4521..144f7b8ad 100755 --- a/bin/javascript-obfuscator +++ b/bin/javascript-obfuscator @@ -1,3 +1,6 @@ #!/usr/bin/env node -require('../dist/index.cli').obfuscate(process.argv); \ No newline at end of file +require('../dist/index.cli').obfuscate(process.argv).catch((error) => { + console.error(error.message); + process.exit(1); +}); \ No newline at end of file diff --git a/package.json b/package.json index 4baf28c3f..2519534eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "5.2.1", + "version": "5.3.0", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", @@ -23,6 +23,7 @@ "dependencies": { "@javascript-obfuscator/escodegen": "2.3.1", "@javascript-obfuscator/estraverse": "5.4.0", + "@vercel/blob": ">=0.23.0", "acorn": "8.15.0", "assert": "2.1.0", "chalk": "4.1.2", diff --git a/src/JavaScriptObfuscatorCLIFacade.ts b/src/JavaScriptObfuscatorCLIFacade.ts index 09a66604b..075f21be5 100644 --- a/src/JavaScriptObfuscatorCLIFacade.ts +++ b/src/JavaScriptObfuscatorCLIFacade.ts @@ -6,11 +6,12 @@ class JavaScriptObfuscatorCLIFacade { /** * @param {string[]} argv */ - public static obfuscate(argv: string[]): void { + public static async obfuscate(argv: string[]): Promise { const javaScriptObfuscatorCLI: JavaScriptObfuscatorCLI = new JavaScriptObfuscatorCLI(argv); javaScriptObfuscatorCLI.initialize(); - javaScriptObfuscatorCLI.run(); + + return javaScriptObfuscatorCLI.run(); } } diff --git a/src/JavaScriptObfuscatorFacade.ts b/src/JavaScriptObfuscatorFacade.ts index d5128d0ee..91356e7c3 100644 --- a/src/JavaScriptObfuscatorFacade.ts +++ b/src/JavaScriptObfuscatorFacade.ts @@ -11,12 +11,10 @@ import { IInversifyContainerFacade } from './interfaces/container/IInversifyCont import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator'; import { IObfuscationResult } from './interfaces/source-code/IObfuscationResult'; import { IProApiConfig, IProObfuscationResult, TProApiProgressCallback } from './interfaces/pro-api/IProApiClient'; -import { ApiError } from './pro-api/ApiError'; import { InversifyContainerFacade } from './container/InversifyContainerFacade'; import { Options } from './options/Options'; import { Utils } from './utils/Utils'; -import { ProApiClient } from './pro-api/ProApiClient'; class JavaScriptObfuscatorFacade { /** @@ -94,6 +92,7 @@ class JavaScriptObfuscatorFacade { /** * Obfuscate code using the Pro API (obfuscator.io) * This method requires a valid API token from obfuscator.io and only works with VM obfuscation. + * Only available in Node.js environment. * * @param {string} sourceCode - Source code to obfuscate * @param {TInputOptions} inputOptions - Obfuscation options (must include vmObfuscation: true) @@ -108,13 +107,13 @@ class JavaScriptObfuscatorFacade { proApiConfig: IProApiConfig, onProgress?: TProApiProgressCallback ): Promise { - if (!inputOptions.vmObfuscation) { - throw new ApiError( - 'obfuscatePro method works only with VM obfuscation. Set vmObfuscation: true in options.', - 400 - ); + if (typeof window !== 'undefined') { + const { ApiError } = await import('./pro-api/ApiError'); + + throw new ApiError('obfuscatePro is only available in Node.js environment', 500); } + const { ProApiClient } = await import('./pro-api/ProApiClient'); const client = new ProApiClient(proApiConfig); return client.obfuscate(sourceCode, inputOptions, onProgress); @@ -123,4 +122,4 @@ class JavaScriptObfuscatorFacade { export { JavaScriptObfuscatorFacade as JavaScriptObfuscator }; export { ApiError } from './pro-api/ApiError'; -export type { IProApiConfig, TProApiProgressCallback } from './interfaces/pro-api/IProApiClient'; +export type { IProApiConfig, IProObfuscationResult, TProApiProgressCallback } from './interfaces/pro-api/IProApiClient'; diff --git a/src/cli/JavaScriptObfuscatorCLI.ts b/src/cli/JavaScriptObfuscatorCLI.ts index 9d905accd..99b16d53a 100644 --- a/src/cli/JavaScriptObfuscatorCLI.ts +++ b/src/cli/JavaScriptObfuscatorCLI.ts @@ -8,6 +8,8 @@ import { TInputOptions } from '../types/options/TInputOptions'; import { IFileData } from '../interfaces/cli/IFileData'; import { IInitializable } from '../interfaces/IInitializable'; import { IObfuscationResult } from '../interfaces/source-code/IObfuscationResult'; +import { ProApiClient } from '../pro-api/ProApiClient'; +import { IProObfuscationResult } from '../interfaces/pro-api/IProApiClient'; import { initializable } from '../decorators/Initializable'; @@ -34,6 +36,9 @@ import { Logger } from '../logger/Logger'; import { ObfuscatedCodeFileUtils } from './utils/ObfuscatedCodeFileUtils'; import { SourceCodeFileUtils } from './utils/SourceCodeFileUtils'; import { Utils } from '../utils/Utils'; +import { VMTargetFunctionsMode } from '../pro-api/enums/VMTargetFunctionsMode'; +import { VMBytecodeFormat } from '../pro-api/enums/VMBytecodeFormat'; +import { StrictModeSanitizer } from './sanitizers/StrictModeSanitizer'; export class JavaScriptObfuscatorCLI implements IInitializable { /** @@ -155,7 +160,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { ); } - public run(): void { + public async run(): Promise { const canShowHelp: boolean = !this.arguments.length || this.arguments.includes('--help'); if (canShowHelp) { @@ -166,7 +171,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { const sourceCodeData: IFileData[] = this.sourceCodeFileUtils.readSourceCode(); - this.processSourceCodeData(sourceCodeData); + await this.processSourceCodeData(sourceCodeData); } private configureCommands(): void { @@ -210,7 +215,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable { ) .option( '--domain-lock-redirect-url ', - 'Allows the browser to be redirected to a passed URL if the source code isn\'t run on the domains specified by --domain-lock' + "Allows the browser to be redirected to a passed URL if the source code isn't run on the domains specified by --domain-lock" ) .option( '--exclude (comma separated, without whitespaces)', @@ -390,6 +395,153 @@ export class JavaScriptObfuscatorCLI implements IInitializable { 'Allows to enable/disable string conversion to unicode escape sequence', BooleanSanitizer ) + .option( + '--pro-api-token ', + 'API token for Pro obfuscation via obfuscator.io (enables VM obfuscation via cloud API)' + ) + .option('--pro-api-version ', 'Obfuscator version to use with Pro API (e.g., "5.0.0")') + .option( + '--vm-obfuscation ', + 'Enables VM-based bytecode obfuscation for functions', + BooleanSanitizer + ) + .option( + '--vm-obfuscation-threshold ', + 'The probability that VM obfuscation will be applied to a function (Default: 1, Min: 0, Max: 1)', + parseFloat + ) + .option( + '--vm-preprocess-identifiers ', + 'Preprocesses identifiers before VM transformation (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-dynamic-opcodes ', + 'Dynamically assembles VM dispatcher with shuffled case order and filters unused opcodes based on code analysis', + BooleanSanitizer + ) + .option( + '--vm-target-functions (comma separated, without whitespaces)', + 'List of specific function names to apply VM obfuscation to (comma separated)', + ArraySanitizer + ) + .option( + '--vm-exclude-functions (comma separated, without whitespaces)', + 'List of function names to exclude from VM obfuscation (comma separated)', + ArraySanitizer + ) + .option( + '--vm-target-functions-mode ', + 'Controls how functions are selected for VM obfuscation. ' + + `Values: ${CLIUtils.stringifyOptionAvailableValues(VMTargetFunctionsMode)}. ` + + `Default: ${VMTargetFunctionsMode.Root}` + ) + .option( + '--vm-wrap-top-level-initializers ', + 'Wraps top-level variable initializers in IIFEs so they can be VM-obfuscated (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-opcode-shuffle ', + 'Randomizes the numeric values assigned to each opcode (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-bytecode-encoding ', + 'Enables bytecode encryption with per-function keys (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-bytecode-array-encoding ', + 'Enables encrypted bytecode array with lazy decryption (Default: false)', + BooleanSanitizer + ) + .option('--vm-bytecode-array-encoding-key ', 'Custom static key for bytecode array encoding') + .option( + '--vm-bytecode-array-encoding-key-getter ', + 'Custom key getter function code for bytecode array encoding' + ) + .option( + '--vm-instruction-shuffle ', + 'Shuffles instruction order within basic blocks (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-jumps-encoding ', + 'Enables jump target encoding to prevent CFG reconstruction (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-decoy-opcodes ', + 'Enables insertion of decoy opcodes and dead instructions (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-dead-code-injection ', + 'Enables dead code injection with opaque predicates in bytecode (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-split-dispatcher ', + 'Splits the VM interpreter into multiple category-based dispatchers (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-macro-ops ', + 'Enables macro-op fusion to combine common instruction sequences (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-debug-protection ', + 'Enables anti-debugging measures with state corruption (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-runtime-opcode-derivation ', + 'Enables runtime opcode derivation from seeds instead of static mappings (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-stateful-opcodes ', + 'Enables position-based stateful opcode decoding to prevent pattern matching (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-stack-encoding ', + 'Enables stack value encoding to prevent stack inspection (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-randomize-keys ', + 'Randomizes bytecode property keys to prevent pattern matching (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-indirect-dispatch ', + 'Uses indirect dispatch via handler function table instead of switch statement (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-compact-dispatcher ', + 'Uses a single unified dispatcher for both sync and generator execution, reducing code size (Default: false)', + BooleanSanitizer + ) + .option( + '--vm-bytecode-format ', + 'Sets the bytecode storage format. ' + + `Values: ${CLIUtils.stringifyOptionAvailableValues(VMBytecodeFormat)}. ` + + `Default: ${VMBytecodeFormat.Binary}` + ) + .option( + '--parse-html ', + 'Enables obfuscation of JavaScript within HTML