js-confuser 2.0.0-alpha.5 → 2.0.1

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 (113) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +43 -43
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
  3. package/.github/workflows/node.js.yml +28 -28
  4. package/.prettierrc +4 -4
  5. package/CHANGELOG.md +1015 -989
  6. package/CODE_OF_CONDUCT.md +131 -131
  7. package/CONTRIBUTING.md +52 -52
  8. package/LICENSE +21 -21
  9. package/Migration.md +72 -71
  10. package/README.md +86 -78
  11. package/dist/constants.js +43 -43
  12. package/dist/index.js +14 -23
  13. package/dist/obfuscator.js +31 -25
  14. package/dist/order.js +4 -4
  15. package/dist/presets.js +31 -31
  16. package/dist/templates/integrityTemplate.js +4 -4
  17. package/dist/templates/template.js +1 -2
  18. package/dist/transforms/astScrambler.js +1 -2
  19. package/dist/transforms/calculator.js +1 -2
  20. package/dist/transforms/controlFlowFlattening.js +93 -63
  21. package/dist/transforms/deadCode.js +1 -2
  22. package/dist/transforms/dispatcher.js +4 -5
  23. package/dist/transforms/extraction/duplicateLiteralsRemoval.js +1 -2
  24. package/dist/transforms/extraction/objectExtraction.js +1 -2
  25. package/dist/transforms/finalizer.js +1 -2
  26. package/dist/transforms/flatten.js +1 -2
  27. package/dist/transforms/identifier/globalConcealing.js +15 -2
  28. package/dist/transforms/identifier/movedDeclarations.js +8 -7
  29. package/dist/transforms/identifier/renameVariables.js +7 -7
  30. package/dist/transforms/lock/integrity.js +11 -10
  31. package/dist/transforms/lock/lock.js +2 -3
  32. package/dist/transforms/minify.js +11 -29
  33. package/dist/transforms/opaquePredicates.js +1 -2
  34. package/dist/transforms/pack.js +5 -2
  35. package/dist/transforms/plugin.js +18 -19
  36. package/dist/transforms/preparation.js +16 -16
  37. package/dist/transforms/renameLabels.js +1 -2
  38. package/dist/transforms/rgf.js +8 -9
  39. package/dist/transforms/shuffle.js +1 -2
  40. package/dist/transforms/string/encoding.js +1 -2
  41. package/dist/transforms/string/stringCompression.js +3 -4
  42. package/dist/transforms/string/stringConcealing.js +8 -3
  43. package/dist/transforms/string/stringEncoding.js +1 -2
  44. package/dist/transforms/variableMasking.js +1 -2
  45. package/dist/utils/NameGen.js +2 -2
  46. package/dist/utils/PredicateGen.js +1 -2
  47. package/dist/utils/ast-utils.js +87 -88
  48. package/dist/utils/function-utils.js +8 -8
  49. package/dist/utils/node.js +5 -6
  50. package/dist/utils/object-utils.js +4 -4
  51. package/dist/utils/random-utils.js +20 -20
  52. package/dist/utils/static-utils.js +1 -2
  53. package/dist/validateOptions.js +4 -7
  54. package/index.d.ts +17 -17
  55. package/package.json +61 -59
  56. package/src/constants.ts +168 -168
  57. package/src/index.ts +118 -118
  58. package/src/obfuscationResult.ts +49 -49
  59. package/src/obfuscator.ts +501 -497
  60. package/src/options.ts +407 -407
  61. package/src/order.ts +54 -54
  62. package/src/presets.ts +125 -125
  63. package/src/templates/bufferToStringTemplate.ts +57 -57
  64. package/src/templates/deadCodeTemplates.ts +1185 -1185
  65. package/src/templates/getGlobalTemplate.ts +76 -76
  66. package/src/templates/integrityTemplate.ts +64 -64
  67. package/src/templates/setFunctionLengthTemplate.ts +11 -11
  68. package/src/templates/stringCompressionTemplate.ts +20 -20
  69. package/src/templates/tamperProtectionTemplates.ts +120 -120
  70. package/src/templates/template.ts +224 -224
  71. package/src/transforms/astScrambler.ts +99 -99
  72. package/src/transforms/calculator.ts +99 -99
  73. package/src/transforms/controlFlowFlattening.ts +1716 -1664
  74. package/src/transforms/deadCode.ts +82 -82
  75. package/src/transforms/dispatcher.ts +450 -450
  76. package/src/transforms/extraction/duplicateLiteralsRemoval.ts +156 -158
  77. package/src/transforms/extraction/objectExtraction.ts +186 -186
  78. package/src/transforms/finalizer.ts +74 -74
  79. package/src/transforms/flatten.ts +421 -420
  80. package/src/transforms/identifier/globalConcealing.ts +315 -295
  81. package/src/transforms/identifier/movedDeclarations.ts +252 -251
  82. package/src/transforms/identifier/renameVariables.ts +328 -321
  83. package/src/transforms/lock/integrity.ts +117 -114
  84. package/src/transforms/lock/lock.ts +418 -425
  85. package/src/transforms/minify.ts +615 -629
  86. package/src/transforms/opaquePredicates.ts +100 -100
  87. package/src/transforms/pack.ts +239 -231
  88. package/src/transforms/plugin.ts +173 -173
  89. package/src/transforms/preparation.ts +349 -347
  90. package/src/transforms/renameLabels.ts +175 -175
  91. package/src/transforms/rgf.ts +322 -322
  92. package/src/transforms/shuffle.ts +82 -82
  93. package/src/transforms/string/encoding.ts +144 -144
  94. package/src/transforms/string/stringCompression.ts +128 -128
  95. package/src/transforms/string/stringConcealing.ts +312 -298
  96. package/src/transforms/string/stringEncoding.ts +80 -80
  97. package/src/transforms/string/stringSplitting.ts +77 -77
  98. package/src/transforms/variableMasking.ts +257 -257
  99. package/src/utils/IntGen.ts +33 -33
  100. package/src/utils/NameGen.ts +116 -116
  101. package/src/utils/PredicateGen.ts +61 -61
  102. package/src/utils/ast-utils.ts +663 -663
  103. package/src/utils/function-utils.ts +50 -50
  104. package/src/utils/gen-utils.ts +48 -48
  105. package/src/utils/node.ts +78 -78
  106. package/src/utils/object-utils.ts +21 -21
  107. package/src/utils/random-utils.ts +93 -93
  108. package/src/utils/static-utils.ts +66 -66
  109. package/src/validateOptions.ts +256 -259
  110. package/tsconfig.json +13 -14
  111. package/dist/probability.js +0 -1
  112. package/dist/transforms/functionOutlining.js +0 -230
  113. package/dist/utils/ControlObject.js +0 -125
@@ -1,66 +1,66 @@
1
- import * as t from "@babel/types";
2
-
3
- // Function to check if a node is a static value
4
- export function isStaticValue(node: t.Node): boolean {
5
- // Check for literals which are considered static
6
- if (
7
- t.isStringLiteral(node) ||
8
- t.isNumericLiteral(node) ||
9
- t.isBooleanLiteral(node) ||
10
- t.isNullLiteral(node)
11
- ) {
12
- if (t.isDirectiveLiteral(node)) return false;
13
-
14
- return true;
15
- }
16
-
17
- // Handle unary expressions like -42
18
- if (t.isUnaryExpression(node)) {
19
- // Only consider certain operators as static (e.g., -, +)
20
- if (["-", "+", "!", "~", "void"].includes(node.operator)) {
21
- return isStaticValue(node.argument);
22
- }
23
- return false;
24
- }
25
-
26
- // Handle binary expressions with static values only
27
- if (t.isBinaryExpression(node)) {
28
- return isStaticValue(node.left) && isStaticValue(node.right);
29
- }
30
-
31
- // Handle logical expressions (&&, ||) with static values only
32
- if (t.isLogicalExpression(node)) {
33
- return isStaticValue(node.left) && isStaticValue(node.right);
34
- }
35
-
36
- // Handle conditional (ternary) expressions with static values
37
- if (t.isConditionalExpression(node)) {
38
- return (
39
- isStaticValue(node.test) &&
40
- isStaticValue(node.consequent) &&
41
- isStaticValue(node.alternate)
42
- );
43
- }
44
-
45
- // Handle array expressions where all elements are static
46
- if (t.isArrayExpression(node)) {
47
- return node.elements.every(
48
- (element) => element !== null && isStaticValue(element)
49
- );
50
- }
51
-
52
- // Handle object expressions where all properties are static
53
- if (t.isObjectExpression(node)) {
54
- return node.properties.every((prop) => {
55
- if (t.isObjectProperty(prop)) {
56
- return isStaticValue(prop.key) && isStaticValue(prop.value);
57
- } else if (t.isSpreadElement(prop)) {
58
- return isStaticValue(prop.argument);
59
- }
60
- return false;
61
- });
62
- }
63
-
64
- // Add more cases as needed, depending on what you consider "static"
65
- return false;
66
- }
1
+ import * as t from "@babel/types";
2
+
3
+ // Function to check if a node is a static value
4
+ export function isStaticValue(node: t.Node): boolean {
5
+ // Check for literals which are considered static
6
+ if (
7
+ t.isStringLiteral(node) ||
8
+ t.isNumericLiteral(node) ||
9
+ t.isBooleanLiteral(node) ||
10
+ t.isNullLiteral(node)
11
+ ) {
12
+ if (t.isDirectiveLiteral(node)) return false;
13
+
14
+ return true;
15
+ }
16
+
17
+ // Handle unary expressions like -42
18
+ if (t.isUnaryExpression(node)) {
19
+ // Only consider certain operators as static (e.g., -, +)
20
+ if (["-", "+", "!", "~", "void"].includes(node.operator)) {
21
+ return isStaticValue(node.argument);
22
+ }
23
+ return false;
24
+ }
25
+
26
+ // Handle binary expressions with static values only
27
+ if (t.isBinaryExpression(node)) {
28
+ return isStaticValue(node.left) && isStaticValue(node.right);
29
+ }
30
+
31
+ // Handle logical expressions (&&, ||) with static values only
32
+ if (t.isLogicalExpression(node)) {
33
+ return isStaticValue(node.left) && isStaticValue(node.right);
34
+ }
35
+
36
+ // Handle conditional (ternary) expressions with static values
37
+ if (t.isConditionalExpression(node)) {
38
+ return (
39
+ isStaticValue(node.test) &&
40
+ isStaticValue(node.consequent) &&
41
+ isStaticValue(node.alternate)
42
+ );
43
+ }
44
+
45
+ // Handle array expressions where all elements are static
46
+ if (t.isArrayExpression(node)) {
47
+ return node.elements.every(
48
+ (element) => element !== null && isStaticValue(element)
49
+ );
50
+ }
51
+
52
+ // Handle object expressions where all properties are static
53
+ if (t.isObjectExpression(node)) {
54
+ return node.properties.every((prop) => {
55
+ if (t.isObjectProperty(prop)) {
56
+ return isStaticValue(prop.key) && isStaticValue(prop.value);
57
+ } else if (t.isSpreadElement(prop)) {
58
+ return isStaticValue(prop.argument);
59
+ }
60
+ return false;
61
+ });
62
+ }
63
+
64
+ // Add more cases as needed, depending on what you consider "static"
65
+ return false;
66
+ }
@@ -1,259 +1,256 @@
1
- import { ok } from "assert";
2
- import { ObfuscateOptions } from "./options";
3
- import presets from "./presets";
4
-
5
- const validProperties = new Set([
6
- "preset",
7
- "target",
8
- "compact",
9
- "hexadecimalNumbers",
10
- "minify",
11
- "renameVariables",
12
- "renameGlobals",
13
- "renameLabels",
14
- "identifierGenerator",
15
- "controlFlowFlattening",
16
- "globalConcealing",
17
- "stringCompression",
18
- "stringConcealing",
19
- "stringEncoding",
20
- "stringSplitting",
21
- "duplicateLiteralsRemoval",
22
- "dispatcher",
23
- "rgf",
24
- "objectExtraction",
25
- "flatten",
26
- "deadCode",
27
- "calculator",
28
- "lock",
29
- "movedDeclarations",
30
- "opaquePredicates",
31
- "shuffle",
32
- "variableMasking",
33
- "verbose",
34
- "globalVariables",
35
- "debugComments",
36
- "preserveFunctionLength",
37
- "astScrambler",
38
- "customStringEncodings",
39
- "functionOutlining",
40
- "pack",
41
- ]);
42
-
43
- const validLockProperties = new Set([
44
- "selfDefending",
45
- "antiDebug",
46
- "tamperProtection",
47
- "startDate",
48
- "endDate",
49
- "domainLock",
50
- "integrity",
51
- "countermeasures",
52
- "customLocks",
53
- ]);
54
-
55
- export function validateOptions(options: ObfuscateOptions) {
56
- if (!options || Object.keys(options).length <= 1) {
57
- /**
58
- * Give a welcoming introduction to those who skipped the documentation.
59
- */
60
- var line = `You provided zero obfuscation options. By default everything is disabled.\nYou can use a preset with:\n\n> {target: '${
61
- options.target || "node"
62
- }', preset: 'high' | 'medium' | 'low'}.\n\n\nView all settings here:\nhttps://github.com/MichaelXF/js-confuser#options`;
63
- throw new Error(
64
- `\n\n` +
65
- line
66
- .split("\n")
67
- .map((x) => `\t${x}`)
68
- .join("\n") +
69
- `\n\n`
70
- );
71
- }
72
-
73
- ok(options, "options cannot be null");
74
- ok(
75
- options.target,
76
- "Missing options.target option (required, must one the following: 'browser' or 'node')"
77
- );
78
-
79
- ok(
80
- ["browser", "node"].includes(options.target),
81
- `'${options.target}' is not a valid target mode`
82
- );
83
-
84
- Object.keys(options).forEach((key) => {
85
- if (!validProperties.has(key)) {
86
- throw new TypeError("Invalid option: '" + key + "'");
87
- }
88
- });
89
-
90
- if (options.lock) {
91
- ok(typeof options.lock === "object", "options.lock must be an object");
92
- Object.keys(options.lock).forEach((key) => {
93
- if (!validLockProperties.has(key)) {
94
- throw new TypeError("Invalid lock option: '" + key + "'");
95
- }
96
- });
97
-
98
- // Validate domain-lock option
99
- if (
100
- options.lock.domainLock &&
101
- typeof options.lock.domainLock !== "undefined"
102
- ) {
103
- ok(Array.isArray(options.lock.domainLock), "domainLock must be an array");
104
- }
105
-
106
- // Validate start-date option
107
- if (
108
- typeof options.lock.startDate !== "undefined" &&
109
- options.lock.startDate
110
- ) {
111
- ok(
112
- typeof options.lock.startDate === "number" ||
113
- options.lock.startDate instanceof Date,
114
- "startDate must be Date object or number"
115
- );
116
- }
117
-
118
- // Validate end-date option
119
- if (typeof options.lock.endDate !== "undefined" && options.lock.endDate) {
120
- ok(
121
- typeof options.lock.endDate === "number" ||
122
- options.lock.endDate instanceof Date,
123
- "endDate must be Date object or number"
124
- );
125
- }
126
- }
127
-
128
- if (options.preset) {
129
- if (!presets[options.preset]) {
130
- throw new TypeError("Unknown preset of '" + options.preset + "'");
131
- }
132
- }
133
- }
134
-
135
- /**
136
- * Sets the default values and validates the configuration.
137
- */
138
- export function applyDefaultsToOptions(
139
- options: ObfuscateOptions
140
- ): ObfuscateOptions {
141
- if (options.preset) {
142
- // Clone and allow overriding
143
- options = Object.assign({}, presets[options.preset], options);
144
- }
145
-
146
- if (!options.hasOwnProperty("compact")) {
147
- options.compact = true; // Compact is on by default
148
- }
149
- if (!options.hasOwnProperty("renameGlobals")) {
150
- options.renameGlobals = true; // RenameGlobals is on by default
151
- }
152
- if (!options.hasOwnProperty("preserveFunctionLength")) {
153
- options.preserveFunctionLength = true; // preserveFunctionLength is on by default
154
- }
155
- if (!options.hasOwnProperty("renameLabels")) {
156
- options.renameLabels = true; // RenameLabels is on by default
157
- }
158
-
159
- if (options.lock) {
160
- ok(typeof options.lock === "object", "options.lock must be an object");
161
-
162
- if (options.lock.selfDefending) {
163
- options.compact = true; // self defending forcibly enables this
164
- }
165
-
166
- if (!options.lock.customLocks) {
167
- options.lock.customLocks = [];
168
- }
169
-
170
- // Convert 'startDate' and 'endDate' to Dates
171
- if (typeof options.lock.startDate === "number") {
172
- options.lock.startDate = new Date(options.lock.startDate);
173
- }
174
-
175
- if (typeof options.lock.endDate === "number") {
176
- options.lock.endDate = new Date(options.lock.endDate);
177
- }
178
- }
179
-
180
- // options.globalVariables outlines generic globals that should be present in the execution context
181
- if (!options.hasOwnProperty("globalVariables")) {
182
- options.globalVariables = new Set([]);
183
-
184
- if (options.target == "browser") {
185
- // browser
186
- [
187
- "window",
188
- "document",
189
- "postMessage",
190
- "alert",
191
- "confirm",
192
- "location",
193
- ].forEach((x) => options.globalVariables.add(x));
194
- } else {
195
- // node
196
- [
197
- "global",
198
- "Buffer",
199
- "require",
200
- "process",
201
- "exports",
202
- "module",
203
- "__dirname",
204
- "__filename",
205
- ].forEach((x) => options.globalVariables.add(x));
206
- }
207
-
208
- [
209
- "globalThis",
210
- "console",
211
- "parseInt",
212
- "parseFloat",
213
- "Math",
214
- "JSON",
215
- "RegExp",
216
- "Promise",
217
- "String",
218
- "Boolean",
219
- "Function",
220
- "Object",
221
- "Array",
222
- "Proxy",
223
- "Error",
224
- "TypeError",
225
- "ReferenceError",
226
- "RangeError",
227
- "EvalError",
228
- "setTimeout",
229
- "clearTimeout",
230
- "setInterval",
231
- "clearInterval",
232
- "setImmediate",
233
- "clearImmediate",
234
- "queueMicrotask",
235
- "isNaN",
236
- "isFinite",
237
- "Set",
238
- "Map",
239
- "WeakSet",
240
- "WeakMap",
241
- "Symbol",
242
- "TextDecoder",
243
- "TextEncoder",
244
- "Uint8Array",
245
- "Uint16Array",
246
- "Uint32Array",
247
- "Int8Array",
248
- "Int16Array",
249
- "Int32Array",
250
- "ArrayBuffer",
251
- "btoa",
252
- "atob",
253
- "unescape",
254
- "encodeURIComponent",
255
- ].forEach((x) => options.globalVariables.add(x));
256
- }
257
-
258
- return options;
259
- }
1
+ import { ok } from "assert";
2
+ import { ObfuscateOptions } from "./options";
3
+ import presets from "./presets";
4
+
5
+ const validProperties = new Set([
6
+ "preset",
7
+ "target",
8
+ "compact",
9
+ "hexadecimalNumbers",
10
+ "minify",
11
+ "renameVariables",
12
+ "renameGlobals",
13
+ "renameLabels",
14
+ "identifierGenerator",
15
+ "controlFlowFlattening",
16
+ "globalConcealing",
17
+ "stringCompression",
18
+ "stringConcealing",
19
+ "stringEncoding",
20
+ "stringSplitting",
21
+ "duplicateLiteralsRemoval",
22
+ "dispatcher",
23
+ "rgf",
24
+ "objectExtraction",
25
+ "flatten",
26
+ "deadCode",
27
+ "calculator",
28
+ "lock",
29
+ "movedDeclarations",
30
+ "opaquePredicates",
31
+ "shuffle",
32
+ "variableMasking",
33
+ "verbose",
34
+ "globalVariables",
35
+ "debugComments",
36
+ "preserveFunctionLength",
37
+ "astScrambler",
38
+ "customStringEncodings",
39
+ "functionOutlining",
40
+ "pack",
41
+ ]);
42
+
43
+ const validLockProperties = new Set([
44
+ "selfDefending",
45
+ "antiDebug",
46
+ "tamperProtection",
47
+ "startDate",
48
+ "endDate",
49
+ "domainLock",
50
+ "integrity",
51
+ "countermeasures",
52
+ "customLocks",
53
+ ]);
54
+
55
+ export function validateOptions(options: ObfuscateOptions) {
56
+ if (!options || Object.keys(options).length <= 1) {
57
+ /**
58
+ * Give a welcoming introduction to those who skipped the documentation.
59
+ */
60
+ var line = `You provided zero obfuscation options. By default everything is disabled.\nYou can use a preset with:\n\n> {target: '${
61
+ options.target || "node"
62
+ }', preset: 'high' | 'medium' | 'low'}.\n\n\nView all settings here:\nhttps://github.com/MichaelXF/js-confuser#options`;
63
+ throw new Error(
64
+ `\n\n` +
65
+ line
66
+ .split("\n")
67
+ .map((x) => `\t${x}`)
68
+ .join("\n") +
69
+ `\n\n`
70
+ );
71
+ }
72
+
73
+ ok(options, "options cannot be null");
74
+ ok(
75
+ options.target,
76
+ "Missing options.target option (required, must one the following: 'browser' or 'node')"
77
+ );
78
+
79
+ ok(
80
+ ["browser", "node"].includes(options.target),
81
+ `'${options.target}' is not a valid target mode`
82
+ );
83
+
84
+ Object.keys(options).forEach((key) => {
85
+ if (!validProperties.has(key)) {
86
+ throw new TypeError("Invalid option: '" + key + "'");
87
+ }
88
+ });
89
+
90
+ if (options.lock) {
91
+ ok(typeof options.lock === "object", "options.lock must be an object");
92
+ Object.keys(options.lock).forEach((key) => {
93
+ if (!validLockProperties.has(key)) {
94
+ throw new TypeError("Invalid lock option: '" + key + "'");
95
+ }
96
+ });
97
+
98
+ // Validate domain-lock option
99
+ if (
100
+ options.lock.domainLock &&
101
+ typeof options.lock.domainLock !== "undefined"
102
+ ) {
103
+ ok(Array.isArray(options.lock.domainLock), "domainLock must be an array");
104
+ }
105
+
106
+ // Validate start-date option
107
+ if (
108
+ typeof options.lock.startDate !== "undefined" &&
109
+ options.lock.startDate
110
+ ) {
111
+ ok(
112
+ typeof options.lock.startDate === "number" ||
113
+ options.lock.startDate instanceof Date,
114
+ "startDate must be Date object or number"
115
+ );
116
+ }
117
+
118
+ // Validate end-date option
119
+ if (typeof options.lock.endDate !== "undefined" && options.lock.endDate) {
120
+ ok(
121
+ typeof options.lock.endDate === "number" ||
122
+ options.lock.endDate instanceof Date,
123
+ "endDate must be Date object or number"
124
+ );
125
+ }
126
+ }
127
+
128
+ if (options.preset) {
129
+ if (!presets[options.preset]) {
130
+ throw new TypeError("Unknown preset of '" + options.preset + "'");
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Sets the default values and validates the configuration.
137
+ */
138
+ export function applyDefaultsToOptions(
139
+ options: ObfuscateOptions
140
+ ): ObfuscateOptions {
141
+ if (options.preset) {
142
+ // Clone and allow overriding
143
+ options = Object.assign({}, presets[options.preset], options);
144
+ }
145
+
146
+ if (!options.hasOwnProperty("compact")) {
147
+ options.compact = true; // Compact is on by default
148
+ }
149
+ if (!options.hasOwnProperty("renameGlobals")) {
150
+ options.renameGlobals = true; // RenameGlobals is on by default
151
+ }
152
+ if (!options.hasOwnProperty("renameLabels")) {
153
+ options.renameLabels = true; // RenameLabels is on by default
154
+ }
155
+
156
+ if (options.lock) {
157
+ ok(typeof options.lock === "object", "options.lock must be an object");
158
+
159
+ if (options.lock.selfDefending) {
160
+ options.compact = true; // self defending forcibly enables this
161
+ }
162
+
163
+ if (!options.lock.customLocks) {
164
+ options.lock.customLocks = [];
165
+ }
166
+
167
+ // Convert 'startDate' and 'endDate' to Dates
168
+ if (typeof options.lock.startDate === "number") {
169
+ options.lock.startDate = new Date(options.lock.startDate);
170
+ }
171
+
172
+ if (typeof options.lock.endDate === "number") {
173
+ options.lock.endDate = new Date(options.lock.endDate);
174
+ }
175
+ }
176
+
177
+ // options.globalVariables outlines generic globals that should be present in the execution context
178
+ if (!options.hasOwnProperty("globalVariables")) {
179
+ options.globalVariables = new Set([]);
180
+
181
+ if (options.target == "browser") {
182
+ // browser
183
+ [
184
+ "window",
185
+ "document",
186
+ "postMessage",
187
+ "alert",
188
+ "confirm",
189
+ "location",
190
+ ].forEach((x) => options.globalVariables.add(x));
191
+ } else {
192
+ // node
193
+ [
194
+ "global",
195
+ "Buffer",
196
+ "require",
197
+ "process",
198
+ "exports",
199
+ "module",
200
+ "__dirname",
201
+ "__filename",
202
+ ].forEach((x) => options.globalVariables.add(x));
203
+ }
204
+
205
+ [
206
+ "globalThis",
207
+ "console",
208
+ "parseInt",
209
+ "parseFloat",
210
+ "Math",
211
+ "JSON",
212
+ "RegExp",
213
+ "Promise",
214
+ "String",
215
+ "Boolean",
216
+ "Function",
217
+ "Object",
218
+ "Array",
219
+ "Proxy",
220
+ "Error",
221
+ "TypeError",
222
+ "ReferenceError",
223
+ "RangeError",
224
+ "EvalError",
225
+ "setTimeout",
226
+ "clearTimeout",
227
+ "setInterval",
228
+ "clearInterval",
229
+ "setImmediate",
230
+ "clearImmediate",
231
+ "queueMicrotask",
232
+ "isNaN",
233
+ "isFinite",
234
+ "Set",
235
+ "Map",
236
+ "WeakSet",
237
+ "WeakMap",
238
+ "Symbol",
239
+ "TextDecoder",
240
+ "TextEncoder",
241
+ "Uint8Array",
242
+ "Uint16Array",
243
+ "Uint32Array",
244
+ "Int8Array",
245
+ "Int16Array",
246
+ "Int32Array",
247
+ "ArrayBuffer",
248
+ "btoa",
249
+ "atob",
250
+ "unescape",
251
+ "encodeURIComponent",
252
+ ].forEach((x) => options.globalVariables.add(x));
253
+ }
254
+
255
+ return options;
256
+ }