Browse Source

refactoring

sanex3339 8 years ago
parent
commit
c72f8d44d6

+ 17 - 35
dist/index.js

@@ -1009,7 +1009,7 @@ var OptionsNormalizer = function () {
     }
 
     _createClass(OptionsNormalizer, null, [{
-        key: 'normalizeOptionsPreset',
+        key: "normalizeOptionsPreset",
         value: function normalizeOptionsPreset(options) {
             var normalizedOptions = Object.assign({}, options);
             normalizedOptions = OptionsNormalizer.unicodeArrayRule(normalizedOptions);
@@ -1018,27 +1018,27 @@ var OptionsNormalizer = function () {
             return normalizedOptions;
         }
     }, {
-        key: 'selfDefendingRule',
+        key: "selfDefendingRule",
         value: function selfDefendingRule(options) {
-            if (options['selfDefending']) {
+            if (options.selfDefending) {
                 Object.assign(options, OptionsNormalizer.SELF_DEFENDING_OPTIONS);
             }
             return options;
         }
     }, {
-        key: 'unicodeArrayRule',
+        key: "unicodeArrayRule",
         value: function unicodeArrayRule(options) {
-            if (!options['unicodeArray']) {
+            if (!options.unicodeArray) {
                 Object.assign(options, OptionsNormalizer.DISABLED_UNICODE_ARRAY_OPTIONS);
             }
             return options;
         }
     }, {
-        key: 'unicodeArrayThresholdRule',
+        key: "unicodeArrayThresholdRule",
         value: function unicodeArrayThresholdRule(options) {
             var minValue = 0,
                 maxValue = 1;
-            options['unicodeArrayThreshold'] = Math.min(Math.max(options['unicodeArrayThreshold'], minValue), maxValue);
+            options.unicodeArrayThreshold = Math.min(Math.max(options.unicodeArrayThreshold, minValue), maxValue);
             return options;
         }
     }]);
@@ -2285,8 +2285,6 @@ exports.LiteralObfuscator = LiteralObfuscator;
 "use strict";
 "use strict";
 
-var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
-
 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -2350,18 +2348,11 @@ var MemberExpressionObfuscator = function (_NodeObfuscator_1$Nod) {
     }, {
         key: 'obfuscateLiteralProperty',
         value: function obfuscateLiteralProperty(node) {
-            switch (_typeof(node.value)) {
-                case 'string':
-                    if (node['x-verbatim-property']) {
-                        break;
-                    }
-                    node['x-verbatim-property'] = {
-                        content: this.replaceLiteralValueWithUnicodeValue(node.value),
-                        precedence: escodegen.Precedence.Primary
-                    };
-                    break;
-                default:
-                    break;
+            if (typeof node.value === 'string' && !node['x-verbatim-property']) {
+                node['x-verbatim-property'] = {
+                    content: this.replaceLiteralValueWithUnicodeValue(node.value),
+                    precedence: escodegen.Precedence.Primary
+                };
             }
         }
     }]);
@@ -2444,8 +2435,6 @@ exports.MethodDefinitionObfuscator = MethodDefinitionObfuscator;
 "use strict";
 "use strict";
 
-var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
-
 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -2492,18 +2481,11 @@ var ObjectExpressionObfuscator = function (_NodeObfuscator_1$Nod) {
     }, {
         key: 'obfuscateLiteralPropertyKey',
         value: function obfuscateLiteralPropertyKey(node) {
-            switch (_typeof(node.value)) {
-                case 'string':
-                    if (node['x-verbatim-property']) {
-                        break;
-                    }
-                    node['x-verbatim-property'] = {
-                        content: Utils_1.Utils.stringToUnicode(node.value),
-                        precedence: escodegen.Precedence.Primary
-                    };
-                    break;
-                default:
-                    break;
+            if (typeof node.value === 'string' && !node['x-verbatim-property']) {
+                node['x-verbatim-property'] = {
+                    content: Utils_1.Utils.stringToUnicode(node.value),
+                    precedence: escodegen.Precedence.Primary
+                };
             }
         }
     }, {

+ 4 - 4
src/OptionsNormalizer.ts

@@ -39,7 +39,7 @@ export class OptionsNormalizer {
      * @returns {IOptionsPreset}
      */
     private static selfDefendingRule (options: IOptionsPreset): IOptionsPreset {
-        if (options['selfDefending']) {
+        if (options.selfDefending) {
             Object.assign(options, OptionsNormalizer.SELF_DEFENDING_OPTIONS);
         }
 
@@ -51,7 +51,7 @@ export class OptionsNormalizer {
      * @returns {IOptionsPreset}
      */
     private static unicodeArrayRule (options: IOptionsPreset): IOptionsPreset {
-        if (!options['unicodeArray']) {
+        if (!options.unicodeArray) {
             Object.assign(options, OptionsNormalizer.DISABLED_UNICODE_ARRAY_OPTIONS);
         }
 
@@ -66,9 +66,9 @@ export class OptionsNormalizer {
         const minValue: number = 0,
             maxValue: number = 1;
 
-        options['unicodeArrayThreshold'] = Math.min(
+        options.unicodeArrayThreshold = Math.min(
             Math.max(
-                options['unicodeArrayThreshold'],
+                options.unicodeArrayThreshold,
                 minValue
             ),
             maxValue

+ 5 - 15
src/node-obfuscators/MemberExpressionObfuscator.ts

@@ -75,21 +75,11 @@ export class MemberExpressionObfuscator extends NodeObfuscator {
      * @param node
      */
     private obfuscateLiteralProperty (node: ILiteralNode): void {
-        switch (typeof node.value) {
-            case 'string':
-                if (node['x-verbatim-property']) {
-                    break;
-                }
-
-                node['x-verbatim-property'] = {
-                    content : this.replaceLiteralValueWithUnicodeValue(<string>node.value),
-                    precedence: escodegen.Precedence.Primary
-                };
-
-                break;
-
-            default:
-                break;
+        if (typeof node.value === 'string' && !node['x-verbatim-property']) {
+            node['x-verbatim-property'] = {
+                content : this.replaceLiteralValueWithUnicodeValue(node.value),
+                precedence: escodegen.Precedence.Primary
+            };
         }
     }
 }

+ 5 - 15
src/node-obfuscators/ObjectExpressionObfuscator.ts

@@ -50,21 +50,11 @@ export class ObjectExpressionObfuscator extends NodeObfuscator {
      * @param node
      */
     private obfuscateLiteralPropertyKey (node: ILiteralNode): void {
-        switch (typeof node.value) {
-            case 'string':
-                if (node['x-verbatim-property']) {
-                    break;
-                }
-
-                node['x-verbatim-property'] = {
-                    content : Utils.stringToUnicode(<string>node.value),
-                    precedence: escodegen.Precedence.Primary
-                };
-
-                break;
-
-            default:
-                break;
+        if (typeof node.value === 'string' && !node['x-verbatim-property']) {
+            node['x-verbatim-property'] = {
+                content : Utils.stringToUnicode(node.value),
+                precedence: escodegen.Precedence.Primary
+            };
         }
     }