Przeglądaj źródła

Added tests for prohibited single FunctionDeclaration

sanex3339 4 lat temu
rodzic
commit
0467620a08

Plik diff jest za duży
+ 0 - 0
dist/index.cli.js


Plik diff jest za duży
+ 0 - 0
dist/index.js


+ 29 - 0
test/functional-tests/node-transformers/minification-transformers/if-statement-simplify-transformer/IfStatementSimplifyTransformer.spec.ts

@@ -780,6 +780,35 @@ describe('IfStatementSimplifyTransformer', () => {
                     assert.match(obfuscatedCode, regExp);
                 });
             });
+
+            describe('Variant #2: `FunctionDeclaration` as prohibited single statement', () => {
+                const regExp: RegExp = new RegExp(
+                    'if *\\(!!\\[]\\) *{ *' +
+                        'function _0x([a-f0-9]){4,6} *\\(\\) *{} *' +
+                    '} *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');
+
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        code,
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            minify: true
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('should not simplify if statement', () => {
+                    assert.match(obfuscatedCode, regExp);
+                });
+            });
         });
     });
 });

+ 7 - 0
test/functional-tests/node-transformers/minification-transformers/if-statement-simplify-transformer/fixtures/function-declaration-as-prohibited-single-statement.js

@@ -0,0 +1,7 @@
+function foo() {
+    if (true) {
+        function foo() {}
+    } else {
+        function bar() {}
+    }
+}

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików