js-confuser 1.5.5 → 1.5.7

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.
@@ -301,9 +301,9 @@ test("Variant #15: Removing implied 'return'", async () => {
301
301
  });
302
302
 
303
303
  // https://github.com/MichaelXF/js-confuser/issues/43
304
- test("Variant #16: Handle deconstructuring in for loop", async ()=>{
305
- // Valid
306
- var output = await JsConfuser(
304
+ test("Variant #16: Handle deconstructuring in for loop", async () => {
305
+ // Valid
306
+ var output = await JsConfuser(
307
307
  `
308
308
  for(const [a] of [[1]]) {
309
309
  input(a);
@@ -313,11 +313,56 @@ var output = await JsConfuser(
313
313
  );
314
314
 
315
315
  var value;
316
- function input(valueIn){
316
+ function input(valueIn) {
317
317
  value = valueIn;
318
318
  }
319
319
 
320
320
  eval(output);
321
321
 
322
322
  expect(value).toStrictEqual(1);
323
- })
323
+ });
324
+
325
+ test("Variant #17: Remove unreachable code following a return statement", async () => {
326
+ var output = await JsConfuser(
327
+ `
328
+ function myFunction(){
329
+ return;
330
+ unreachableStmt;
331
+ }
332
+ `,
333
+ { target: "node", minify: true }
334
+ );
335
+
336
+ expect(output).not.toContain("unreachableStmt");
337
+ });
338
+
339
+ test("Variant #18: Remove unreachable code following a continue or break statement", async () => {
340
+ var output = await JsConfuser(
341
+ `
342
+ for(var i =0; i < 10; i++){
343
+ continue;
344
+ unreachableStmt
345
+ }
346
+
347
+ while(true){
348
+ break;
349
+ unreachableStmt
350
+ }
351
+ `,
352
+ { target: "node", minify: true }
353
+ );
354
+
355
+ expect(output).not.toContain("unreachableStmt");
356
+ });
357
+
358
+ test("Variant #19: Remove unreachable code following a throw statement", async () => {
359
+ var output = await JsConfuser(
360
+ `
361
+ throw new Error("No more code to run");
362
+ unreachableStmt;
363
+ `,
364
+ { target: "node", minify: true }
365
+ );
366
+
367
+ expect(output).not.toContain("unreachableStmt");
368
+ });
@@ -154,6 +154,140 @@ input(console.log, result)
154
154
  eval(output);
155
155
  expect(value).toStrictEqual(60);
156
156
  });
157
+
158
+ // https://github.com/MichaelXF/js-confuser/issues/64
159
+ it("should work on Arrow Functions", async () => {
160
+ var output = await JsConfuser.obfuscate(
161
+ `
162
+ var double = (num)=>num*2;
163
+ TEST_VALUE = double(10);
164
+ `,
165
+ {
166
+ target: "node",
167
+ rgf: true,
168
+ }
169
+ );
170
+
171
+ expect(output).toContain("new Function");
172
+
173
+ var TEST_VALUE;
174
+
175
+ eval(output);
176
+ expect(TEST_VALUE).toStrictEqual(20);
177
+ });
178
+
179
+ it("should work on Function Expressions", async () => {
180
+ var output = await JsConfuser.obfuscate(
181
+ `
182
+ var double = function(num){
183
+ return num * 2
184
+ };
185
+ TEST_VALUE = double(10);
186
+ `,
187
+ {
188
+ target: "node",
189
+ rgf: true,
190
+ }
191
+ );
192
+
193
+ expect(output).toContain("new Function");
194
+
195
+ var TEST_VALUE;
196
+
197
+ eval(output);
198
+ expect(TEST_VALUE).toStrictEqual(20);
199
+ });
200
+
201
+ it("should work on re-assigned functions", async () => {
202
+ var output = await JsConfuser.obfuscate(
203
+ `
204
+ var fn1 = ()=>{
205
+ return "FN1";
206
+ }
207
+ var fn2 = ()=>{
208
+ fn1 = ()=>{
209
+ return "FN1 - Modified"
210
+ }
211
+ }
212
+ fn2();
213
+ TEST_VALUE = fn1();
214
+ `,
215
+ {
216
+ target: "node",
217
+ rgf: true,
218
+ }
219
+ );
220
+
221
+ expect(output).toContain("new Function");
222
+
223
+ var TEST_VALUE;
224
+
225
+ eval(output);
226
+ expect(TEST_VALUE).toStrictEqual("FN1 - Modified");
227
+ });
228
+
229
+ it("should work on re-assigned functions to non-function values", async () => {
230
+ var output = await JsConfuser.obfuscate(
231
+ `
232
+ var fn1 = ()=>{
233
+ return "FN1";
234
+ }
235
+ var fn2 = ()=>{
236
+ fn1 = undefined;
237
+ }
238
+ fn2();
239
+ TEST_VALUE = typeof fn1;
240
+ `,
241
+ {
242
+ target: "node",
243
+ rgf: true,
244
+ }
245
+ );
246
+
247
+ expect(output).toContain("new Function");
248
+
249
+ var TEST_VALUE;
250
+
251
+ eval(output);
252
+ expect(TEST_VALUE).toStrictEqual("undefined");
253
+ });
254
+
255
+ it("should not apply to functions that reference their parent scope in the parameters", async () => {
256
+ var output = await JsConfuser.obfuscate(
257
+ `
258
+ var outsideVar = 0;
259
+ function myFunction(insideVar = outsideVar){
260
+ }
261
+ `,
262
+ {
263
+ target: "node",
264
+ rgf: true,
265
+ }
266
+ );
267
+
268
+ expect(output).not.toContain("new Function");
269
+ });
270
+
271
+ it("should not apply to functions that reference their parent scope in previously defined names", async () => {
272
+ var output = await JsConfuser.obfuscate(
273
+ `
274
+ var outsideVar = 0;
275
+ function myFunction(){
276
+ (function (){
277
+ var outsideVar;
278
+ })();
279
+
280
+ console.log(outsideVar);
281
+ }
282
+ `,
283
+ {
284
+ target: "node",
285
+ rgf: true,
286
+ }
287
+ );
288
+
289
+ expect(output).not.toContain("new Function");
290
+ });
157
291
  });
158
292
 
159
293
  describe("RGF with the 'all' mode", () => {