javascript-obfuscator 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/.eslintrc.js +1 -1
  2. package/.mocharc.json +1 -1
  3. package/CHANGELOG.md +20 -1
  4. package/CLAUDE.md +1478 -0
  5. package/README.md +7 -3
  6. package/dist/index.browser.js +1 -1
  7. package/dist/index.browser.js.LICENSE.txt +1 -8
  8. package/dist/index.browser.js.map +1 -1
  9. package/dist/index.cli.js +1 -1
  10. package/dist/index.cli.js.LICENSE.txt +1 -1
  11. package/dist/index.cli.js.map +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.js.LICENSE.txt +1 -1
  14. package/dist/index.js.map +1 -1
  15. package/package.json +55 -54
  16. package/typings/src/cli/JavaScriptObfuscatorCLI.d.ts +0 -1
  17. package/typings/src/constants/EcmaVersion.d.ts +2 -1
  18. package/typings/src/custom-code-helpers/common/templates/GlobalVariableServiceWorkerTemplate.d.ts +1 -0
  19. package/typings/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.d.ts +2 -1
  20. package/typings/src/enums/ObfuscationTarget.d.ts +1 -0
  21. package/typings/src/enums/node/NodeType.d.ts +1 -0
  22. package/typings/src/enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard.d.ts +1 -0
  23. package/typings/src/interfaces/node-transformers/INodeTransformer.d.ts +0 -1
  24. package/typings/src/interfaces/node-transformers/IVisitor.d.ts +0 -1
  25. package/typings/src/interfaces/utils/IRandomGenerator.d.ts +0 -1
  26. package/typings/src/node/NodeFactory.d.ts +2 -1
  27. package/typings/src/node/NodeGuards.d.ts +2 -0
  28. package/typings/src/node-transformers/AbstractNodeTransformer.d.ts +0 -1
  29. package/typings/src/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.d.ts +0 -1
  30. package/typings/src/node-transformers/control-flow-transformers/StringArrayControlFlowTransformer.d.ts +0 -1
  31. package/typings/src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.d.ts +0 -1
  32. package/typings/src/node-transformers/preparing-transformers/obfuscating-guards/ImportMetaObfuscationGuard.d.ts +6 -0
  33. package/typings/src/node-transformers/simplifying-transformers/ExpressionStatementsMergeTransformer.d.ts +0 -1
  34. package/typings/src/node-transformers/simplifying-transformers/VariableDeclarationsMergeTransformer.d.ts +0 -1
  35. package/typings/src/types/node-transformers/TVisitorResult.d.ts +0 -1
  36. package/typings/src/utils/RandomGenerator.d.ts +0 -1
  37. package/index.cli.ts +0 -5
  38. package/index.ts +0 -44
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-obfuscator",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "JavaScript obfuscator",
5
5
  "keywords": [
6
6
  "obfuscator",
@@ -12,7 +12,7 @@
12
12
  "js obfuscator"
13
13
  ],
14
14
  "engines": {
15
- "node": "^12.22.0 || ^14.0.0 || ^16.0.0 || ^17.0.0 || >=18.0.0"
15
+ "node": ">=18.0.0"
16
16
  },
17
17
  "main": "dist/index.js",
18
18
  "browser": "dist/index.browser.js",
@@ -21,79 +21,79 @@
21
21
  },
22
22
  "types": "typings/index.d.ts",
23
23
  "dependencies": {
24
- "@javascript-obfuscator/escodegen": "2.3.0",
24
+ "@javascript-obfuscator/escodegen": "2.3.1",
25
25
  "@javascript-obfuscator/estraverse": "5.4.0",
26
- "acorn": "8.8.2",
27
- "assert": "2.0.0",
26
+ "acorn": "8.15.0",
27
+ "assert": "2.1.0",
28
28
  "chalk": "4.1.2",
29
- "chance": "1.1.9",
30
- "class-validator": "0.14.0",
31
- "commander": "10.0.0",
32
- "eslint-scope": "7.1.1",
33
- "eslint-visitor-keys": "3.3.0",
29
+ "chance": "1.1.13",
30
+ "class-validator": "0.14.3",
31
+ "commander": "12.1.0",
32
+ "eslint-scope": "8.4.0",
33
+ "eslint-visitor-keys": "4.2.1",
34
34
  "fast-deep-equal": "3.1.3",
35
- "inversify": "6.0.1",
35
+ "inversify": "6.1.4",
36
36
  "js-string-escape": "1.0.1",
37
37
  "md5": "2.3.0",
38
- "mkdirp": "2.1.3",
39
- "multimatch": "5.0.0",
38
+ "mkdirp": "3.0.1",
39
+ "multimatch": "7.0.0",
40
40
  "opencollective-postinstall": "2.0.3",
41
41
  "process": "0.11.10",
42
- "reflect-metadata": "0.1.13",
42
+ "reflect-metadata": "0.2.2",
43
43
  "source-map-support": "0.5.21",
44
44
  "string-template": "1.0.0",
45
45
  "stringz": "2.1.0",
46
- "tslib": "2.5.0"
46
+ "tslib": "2.8.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@istanbuljs/nyc-config-typescript": "1.0.2",
50
- "@types/chai": "4.3.4",
51
- "@types/chance": "1.1.3",
52
- "@types/escodegen": "0.0.7",
53
- "@types/eslint-scope": "3.7.4",
50
+ "@types/chai": "4.3.20",
51
+ "@types/chance": "1.1.7",
52
+ "@types/escodegen": "0.0.10",
53
+ "@types/eslint-scope": "3.7.7",
54
54
  "@types/eslint-visitor-keys": "1.0.0",
55
- "@types/estraverse": "5.1.2",
55
+ "@types/estraverse": "5.1.7",
56
56
  "@types/estree": "0.0.51",
57
- "@types/js-beautify": "1.13.3",
58
- "@types/js-string-escape": "1.0.1",
59
- "@types/md5": "2.3.2",
57
+ "@types/js-beautify": "1.14.3",
58
+ "@types/js-string-escape": "1.0.3",
59
+ "@types/md5": "2.3.6",
60
60
  "@types/mkdirp": "1.0.2",
61
- "@types/mocha": "10.0.1",
61
+ "@types/mocha": "10.0.10",
62
62
  "@types/multimatch": "4.0.0",
63
- "@types/node": "18.13.0",
63
+ "@types/node": "22.10.2",
64
64
  "@types/rimraf": "3.0.2",
65
- "@types/sinon": "10.0.13",
66
- "@types/string-template": "1.0.2",
67
- "@types/webpack-env": "1.18.0",
68
- "@typescript-eslint/eslint-plugin": "5.51.0",
69
- "@typescript-eslint/parser": "5.51.0",
70
- "chai": "4.3.7",
71
- "chai-exclude": "2.1.0",
72
- "cross-env": "7.0.3",
73
- "eslint": "8.34.0",
74
- "eslint-plugin-import": "2.27.5",
75
- "eslint-plugin-jsdoc": "40.0.0",
65
+ "@types/sinon": "17.0.4",
66
+ "@types/string-template": "1.0.7",
67
+ "@types/webpack-env": "1.18.8",
68
+ "@typescript-eslint/eslint-plugin": "7.18.0",
69
+ "@typescript-eslint/parser": "7.18.0",
70
+ "chai": "4.5.0",
71
+ "chai-exclude": "3.0.1",
72
+ "cross-env": "10.1.0",
73
+ "eslint": "8.57.1",
74
+ "eslint-plugin-import": "2.32.0",
75
+ "eslint-plugin-jsdoc": "50.6.3",
76
76
  "eslint-plugin-no-null": "1.0.2",
77
77
  "eslint-plugin-prefer-arrow": "1.2.3",
78
- "eslint-plugin-unicorn": "45.0.2",
79
- "eslint-webpack-plugin": "4.0.0",
80
- "fork-ts-checker-notifier-webpack-plugin": "6.0.0",
81
- "fork-ts-checker-webpack-plugin": "7.3.0",
82
- "husky": "8.0.3",
83
- "js-beautify": "1.14.7",
84
- "mocha": "10.2.0",
85
- "nyc": "15.1.0",
78
+ "eslint-plugin-unicorn": "56.0.1",
79
+ "eslint-webpack-plugin": "4.2.0",
80
+ "fork-ts-checker-notifier-webpack-plugin": "9.0.0",
81
+ "fork-ts-checker-webpack-plugin": "9.1.0",
82
+ "husky": "9.1.7",
83
+ "js-beautify": "1.15.4",
84
+ "mocha": "11.7.4",
85
+ "nyc": "17.1.0",
86
86
  "pjson": "1.0.9",
87
- "rimraf": "4.1.2",
88
- "sinon": "15.0.1",
87
+ "rimraf": "6.0.1",
88
+ "sinon": "19.0.2",
89
89
  "source-map-resolve": "0.6.0",
90
- "terser": "5.16.3",
90
+ "terser": "5.44.0",
91
91
  "threads": "1.7.0",
92
- "ts-loader": "9.4.2",
93
- "ts-node": "10.9.1",
94
- "typescript": "4.9.5",
95
- "webpack": "5.75.0",
96
- "webpack-cli": "5.0.1",
92
+ "ts-loader": "9.5.4",
93
+ "ts-node": "10.9.2",
94
+ "typescript": "5.9.3",
95
+ "webpack": "5.102.1",
96
+ "webpack-cli": "6.0.1",
97
97
  "webpack-node-externals": "3.0.0"
98
98
  },
99
99
  "repository": {
@@ -111,15 +111,16 @@
111
111
  "test:devCompilePerformance": "ts-node test/dev/dev-compile-performance.ts",
112
112
  "test:devRuntimePerformance": "ts-node test/dev/dev-runtime-performance.ts",
113
113
  "test:full": "yarn run test:dev && yarn run test:mocha-coverage && yarn run test:mocha-memory-performance",
114
- "test:mocha": "mocha --require source-map-support/register test/index.spec.ts --exit",
114
+ "test:mocha": "mocha --require ts-node/register --require source-map-support/register test/index.spec.ts --exit",
115
115
  "test:mocha-coverage": "cross-env NODE_OPTIONS=--max-old-space-size=4096 nyc --reporter text-summary --no-clean yarn run test:mocha",
116
116
  "test:mocha-coverage:report": "nyc report --reporter=lcov",
117
- "test:mocha-memory-performance": "cross-env NODE_OPTIONS=--max-old-space-size=280 mocha test/performance-tests/JavaScriptObfuscatorMemory.spec.ts",
117
+ "test:mocha-memory-performance": "cross-env NODE_OPTIONS=--max-old-space-size=280 mocha --require ts-node/register test/performance-tests/JavaScriptObfuscatorMemory.spec.ts",
118
118
  "test": "yarn run test:full",
119
119
  "eslint": "eslint src/**/*.ts",
120
120
  "git:addFiles": "git add .",
121
121
  "postinstall": "opencollective-postinstall",
122
122
  "precommit": "npm run build",
123
+ "prepublishOnly": "npm run build && npm run build:typings",
123
124
  "prepare": "husky install"
124
125
  },
125
126
  "author": {
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IInitializable } from '../interfaces/IInitializable';
3
2
  export declare class JavaScriptObfuscatorCLI implements IInitializable {
4
3
  static readonly availableInputExtensions: string[];
@@ -1 +1,2 @@
1
- export declare const ecmaVersion: 10 | 3 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023;
1
+ import * as acorn from 'acorn';
2
+ export declare const ecmaVersion: acorn.Options["ecmaVersion"] & number;
@@ -0,0 +1 @@
1
+ export declare function GlobalVariableServiceWorkerTemplate(): string;
@@ -7,7 +7,8 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
7
7
  import { AbstractCustomNode } from '../AbstractCustomNode';
8
8
  export declare class CallExpressionFunctionNode extends AbstractCustomNode {
9
9
  private expressionArguments;
10
+ private isChainExpressionParent;
10
11
  constructor(identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, customCodeHelperFormatter: ICustomCodeHelperFormatter, randomGenerator: IRandomGenerator, options: IOptions);
11
- initialize(expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[]): void;
12
+ initialize(expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[], isChainExpressionParent: boolean): void;
12
13
  protected getNodeStructure(): TStatement[];
13
14
  }
@@ -2,4 +2,5 @@ export declare const ObfuscationTarget: Readonly<{
2
2
  Browser: 'browser';
3
3
  BrowserNoEval: 'browser-no-eval';
4
4
  Node: 'node';
5
+ ServiceWorker: 'service-worker';
5
6
  }>;
@@ -36,6 +36,7 @@ export declare enum NodeType {
36
36
  Literal = "Literal",
37
37
  LogicalExpression = "LogicalExpression",
38
38
  MemberExpression = "MemberExpression",
39
+ MetaProperty = "MetaProperty",
39
40
  MethodDefinition = "MethodDefinition",
40
41
  NewExpression = "NewExpression",
41
42
  ObjectExpression = "ObjectExpression",
@@ -3,5 +3,6 @@ export declare enum ObfuscatingGuard {
3
3
  ConditionalCommentObfuscatingGuard = "ConditionalCommentObfuscatingGuard",
4
4
  ForceTransformStringObfuscatingGuard = "ForceTransformStringObfuscatingGuard",
5
5
  IgnoredImportObfuscatingGuard = "IgnoredImportObfuscatingGuard",
6
+ ImportMetaObfuscationGuard = "ImportMetaObfuscationGuard",
6
7
  ReservedStringObfuscatingGuard = "ReservedStringObfuscatingGuard"
7
8
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="estraverse" />
2
1
  import * as estraverse from '@javascript-obfuscator/estraverse';
3
2
  import * as ESTree from 'estree';
4
3
  import { ITransformer } from '../ITransformer';
@@ -1,4 +1,3 @@
1
- /// <reference types="estraverse" />
2
1
  import * as estraverse from '@javascript-obfuscator/estraverse';
3
2
  import * as ESTree from 'estree';
4
3
  export interface IVisitor<T extends ESTree.Node = ESTree.Node> {
@@ -1,4 +1,3 @@
1
- /// <reference types="chance" />
2
1
  export interface IRandomGenerator {
3
2
  getMathRandom(): number;
4
3
  getRandomGenerator(): Chance.Chance;
@@ -8,6 +8,7 @@ export declare class NodeFactory {
8
8
  static blockStatementNode(body?: ESTree.Statement[]): ESTree.BlockStatement;
9
9
  static breakStatement(label?: ESTree.Identifier): ESTree.BreakStatement;
10
10
  static callExpressionNode(callee: ESTree.Expression, args?: (ESTree.Expression | ESTree.SpreadElement)[], optional?: boolean): ESTree.CallExpression;
11
+ static chainExpressionNode(expression: ESTree.ChainElement): ESTree.ChainExpression;
11
12
  static conditionalExpressionNode(test: ESTree.Expression, consequent: ESTree.Expression, alternate: ESTree.Expression): ESTree.ConditionalExpression;
12
13
  static continueStatement(label?: ESTree.Identifier): ESTree.ContinueStatement;
13
14
  static directiveNode(expression: ESTree.Literal, directive: string): ESTree.Directive;
@@ -17,7 +18,7 @@ export declare class NodeFactory {
17
18
  static expressionStatementNode(expression: ESTree.Expression): ESTree.ExpressionStatement;
18
19
  static forStatementNode(init: ESTree.VariableDeclaration | ESTree.Expression | null, test: ESTree.Expression | null, update: ESTree.Expression | null, body: ESTree.Statement): ESTree.ForStatement;
19
20
  static forInStatementNode(left: ESTree.VariableDeclaration | ESTree.Pattern, right: ESTree.Expression, body: ESTree.Statement): ESTree.ForInStatement;
20
- static forOfStatementNode(await: boolean, left: ESTree.VariableDeclaration | ESTree.Pattern, right: ESTree.Expression, body: ESTree.Statement): ESTree.ForOfStatement;
21
+ static forOfStatementNode(asAwait: boolean, left: ESTree.VariableDeclaration | ESTree.Pattern, right: ESTree.Expression, body: ESTree.Statement): ESTree.ForOfStatement;
21
22
  static functionDeclarationNode(functionName: string, params: ESTree.Identifier[], body: ESTree.BlockStatement): ESTree.FunctionDeclaration;
22
23
  static functionExpressionNode(params: ESTree.Pattern[], body: ESTree.BlockStatement): ESTree.FunctionExpression;
23
24
  static ifStatementNode(test: ESTree.Expression, consequent: ESTree.Statement, alternate?: ESTree.Statement | null): ESTree.IfStatement;
@@ -14,6 +14,7 @@ export declare class NodeGuards {
14
14
  static isBlockStatementNode(node: ESTree.Node): node is ESTree.BlockStatement;
15
15
  static isBreakStatementNode(node: ESTree.Node): node is ESTree.BreakStatement;
16
16
  static isCallExpressionNode(node: ESTree.Node): node is ESTree.CallExpression;
17
+ static isChainExpressionNode(node: ESTree.Node): node is ESTree.ChainExpression;
17
18
  static isClassBodyNode(node: ESTree.Node): node is ESTree.ClassBody;
18
19
  static isClassDeclarationNode(node: ESTree.Node): node is ESTree.ClassDeclaration & {
19
20
  id: ESTree.Identifier;
@@ -45,6 +46,7 @@ export declare class NodeGuards {
45
46
  static isLiteralNode(node: ESTree.Node): node is ESTree.Literal;
46
47
  static isLogicalExpressionNode(node: ESTree.Node): node is ESTree.LogicalExpression;
47
48
  static isMemberExpressionNode(node: ESTree.Node): node is ESTree.MemberExpression;
49
+ static isMetaPropertyNode(node: ESTree.Node): node is ESTree.MetaProperty;
48
50
  static isMethodDefinitionNode(node: ESTree.Node): node is ESTree.MethodDefinition;
49
51
  static isNewExpressionNode(node: ESTree.Node): node is ESTree.NewExpression;
50
52
  static isNode(object: Object & {
@@ -1,4 +1,3 @@
1
- /// <reference types="estraverse" />
2
1
  import * as estraverse from '@javascript-obfuscator/estraverse';
3
2
  import * as ESTree from 'estree';
4
3
  import { INodeTransformer } from '../interfaces/node-transformers/INodeTransformer';
@@ -1,4 +1,3 @@
1
- /// <reference types="estraverse" />
2
1
  import * as estraverse from '@javascript-obfuscator/estraverse';
3
2
  import * as ESTree from 'estree';
4
3
  import { TControlFlowCustomNodeFactory } from '../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
@@ -1,4 +1,3 @@
1
- /// <reference types="estraverse" />
2
1
  import * as estraverse from '@javascript-obfuscator/estraverse';
3
2
  import * as ESTree from 'estree';
4
3
  import { TControlFlowCustomNodeFactory } from '../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
@@ -1,4 +1,3 @@
1
- /// <reference types="estraverse" />
2
1
  import * as estraverse from '@javascript-obfuscator/estraverse';
3
2
  import * as ESTree from 'estree';
4
3
  import { TDeadNodeInjectionCustomNodeFactory } from '../../types/container/custom-nodes/TDeadNodeInjectionCustomNodeFactory';
@@ -0,0 +1,6 @@
1
+ import * as ESTree from 'estree';
2
+ import { IObfuscatingGuard } from '../../../interfaces/node-transformers/preparing-transformers/obfuscating-guards/IObfuscatingGuard';
3
+ import { ObfuscatingGuardResult } from '../../../enums/node/ObfuscatingGuardResult';
4
+ export declare class ImportMetaObfuscationGuard implements IObfuscatingGuard {
5
+ check(node: ESTree.Node): ObfuscatingGuardResult;
6
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="estraverse" />
2
1
  import * as estraverse from '@javascript-obfuscator/estraverse';
3
2
  import * as ESTree from 'estree';
4
3
  import { IOptions } from '../../interfaces/options/IOptions';
@@ -1,4 +1,3 @@
1
- /// <reference types="estraverse" />
2
1
  import * as estraverse from '@javascript-obfuscator/estraverse';
3
2
  import * as ESTree from 'estree';
4
3
  import { IOptions } from '../../interfaces/options/IOptions';
@@ -1,4 +1,3 @@
1
- /// <reference types="estraverse" />
2
1
  import * as estraverse from '@javascript-obfuscator/estraverse';
3
2
  import * as ESTree from 'estree';
4
3
  export type TVisitorResult = ESTree.Node | estraverse.VisitorOption | void;
@@ -1,4 +1,3 @@
1
- /// <reference types="chance" />
2
1
  import { IInitializable } from '../interfaces/IInitializable';
3
2
  import { IOptions } from '../interfaces/options/IOptions';
4
3
  import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
package/index.cli.ts DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- import { JavaScriptObfuscatorCLI } from './src/JavaScriptObfuscatorCLIFacade';
4
-
5
- module.exports = JavaScriptObfuscatorCLI;
package/index.ts DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- import { TDictionary } from './src/types/TDictionary';
4
- import { TInputOptions } from './src/types/options/TInputOptions';
5
- import { TObfuscationResultsObject } from './src/types/TObfuscationResultsObject';
6
- import { TOptionsPreset } from './src/types/options/TOptionsPreset';
7
-
8
- import { IObfuscationResult } from './src/interfaces/source-code/IObfuscationResult';
9
-
10
- import { JavaScriptObfuscator } from './src/JavaScriptObfuscatorFacade';
11
-
12
- export type ObfuscatorOptions = TInputOptions;
13
-
14
- export interface ObfuscationResult extends IObfuscationResult {}
15
-
16
- /**
17
- * @param {string} sourceCode
18
- * @param {ObfuscatorOptions} inputOptions
19
- * @returns {ObfuscatedCode}
20
- */
21
- export declare function obfuscate (sourceCode: string, inputOptions?: ObfuscatorOptions): ObfuscationResult;
22
-
23
- /**
24
- * @param {TSourceCodesObject} sourceCodesObject
25
- * @param {TInputOptions} inputOptions
26
- * @returns {TObfuscationResultsObject<TSourceCodesObject>}
27
- */
28
- export declare function obfuscateMultiple <TSourceCodesObject extends TDictionary<string>> (
29
- sourceCodesObject: TSourceCodesObject,
30
- inputOptions?: TInputOptions
31
- ): TObfuscationResultsObject<TSourceCodesObject>;
32
-
33
- /**
34
- * @param {TOptionsPreset} optionsPreset
35
- * @returns {TInputOptions}
36
- */
37
- export declare function getOptionsByPreset (optionsPreset: TOptionsPreset): TInputOptions;
38
-
39
- /**
40
- * @type {string}
41
- */
42
- export declare const version: string;
43
-
44
- module.exports = JavaScriptObfuscator;