Ver Fonte

Added `optional-chaining` support

sanex3339 há 4 anos atrás
pai
commit
971c02aed2

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@ Change Log
 
 v1.10.0
 ---
+* **Feature:** Optional chaining support!
 * Improved `disableConsoleOutput` template. https://github.com/javascript-obfuscator/javascript-obfuscator/issues/691
 
 v1.9.0

+ 1 - 1
README.md

@@ -1089,7 +1089,7 @@ Performance will slightly slower than without obfuscation
 
 ### What javascript versions are supported?
 
-`es3`, `es5`, `es2015`, `es2016` and `es2017`
+`es3`, `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019` and partially `es2020`
 
 ### I want to use feature that described in `README.md` but it's not working!
 

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/index.browser.js


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/index.cli.js


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/index.js


+ 3 - 0
package.json

@@ -43,6 +43,9 @@
     "string-template": "1.0.0",
     "tslib": "2.0.0"
   },
+  "resolutions": {
+    "eslint-scope/esrecurse/estraverse": "5.2.0"
+  },
   "devDependencies": {
     "@types/chai": "4.2.12",
     "@types/chance": "1.1.0",

+ 26 - 0
test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts

@@ -682,6 +682,32 @@ describe('JavaScriptObfuscator', () => {
             });
         });
 
+        describe('Optional chaining support', () => {
+            const regExp: RegExp = new RegExp(
+                'const _0x(\\w){4,6} *= *{ *' +
+                    '\'bar\': *\\(\\) *=> *{} *' +
+                '}; *' +
+                '_0x(\\w){4,6}\\?\\.\\[\'bar\']\\?\\.\\(\\);'
+            );
+
+            let obfuscatedCode: string;
+
+            beforeEach(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/optional-chaining-support.js');
+
+                obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET
+                    }
+                ).getObfuscatedCode();
+            });
+
+            it('should support optional chaining', () => {
+                assert.match(obfuscatedCode, regExp);
+            });
+        });
+
         describe('mangled identifier names generator', () => {
             const regExp: RegExp = /var c *= *0x1/;
 

+ 7 - 0
test/functional-tests/javascript-obfuscator/fixtures/optional-chaining-support.js

@@ -0,0 +1,7 @@
+function test() {
+    const foo = {
+        bar: () => {}
+    };
+
+    foo?.bar?.();
+}

+ 2 - 2
yarn.lock

@@ -2145,12 +2145,12 @@ esrecurse@^4.1.0:
   dependencies:
     estraverse "^4.1.0"
 
[email protected], estraverse@^5.2.0:
[email protected], estraverse@^4.1.0, estraverse@^5.2.0:
   version "5.2.0"
   resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.2.0.tgz#307df42547e6cc7324d3cf03c155d5cdb8c53880"
   integrity sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==
 
-estraverse@^4.1.0, estraverse@^4.1.1:
+estraverse@^4.1.1:
   version "4.3.0"
   resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d"
   integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff