瀏覽代碼

generateCode() now not static

sanex3339 8 年之前
父節點
當前提交
1346570151
共有 3 個文件被更改,包括 24 次插入24 次删除
  1. 19 18
      dist/index.js
  2. 4 6
      src/JavaScriptObfuscatorInternal.ts
  3. 1 0
      src/Obfuscator.ts

+ 19 - 18
dist/index.js

@@ -88,7 +88,7 @@ module.exports =
 /******/ 	__webpack_require__.p = "";
 /******/
 /******/ 	// Load entry module and return exports
-/******/ 	return __webpack_require__(__webpack_require__.s = 107);
+/******/ 	return __webpack_require__(__webpack_require__.s = 108);
 /******/ })
 /************************************************************************/
 /******/ ([
@@ -1591,6 +1591,21 @@ var JavaScriptObfuscatorInternal = function () {
     }
 
     _createClass(JavaScriptObfuscatorInternal, [{
+        key: 'generateCode',
+        value: function generateCode(sourceCode, astTree) {
+            var escodegenParams = Object.assign({}, JavaScriptObfuscatorInternal.escodegenParams);
+            if (this.options.sourceMap) {
+                escodegenParams.sourceMap = 'sourceMap';
+                escodegenParams.sourceContent = sourceCode;
+            }
+            escodegenParams.format = {
+                compact: this.options.compact
+            };
+            var generatorOutput = escodegen.generate(astTree, escodegenParams);
+            generatorOutput.map = generatorOutput.map ? generatorOutput.map.toString() : '';
+            return generatorOutput;
+        }
+    }, {
         key: 'getObfuscationResult',
         value: function getObfuscationResult(generatorOutput) {
             return new SourceMapCorrector_1.SourceMapCorrector(new ObfuscationResult_1.ObfuscationResult(generatorOutput.code, generatorOutput.map), this.options.sourceMapBaseUrl + this.options.sourceMapFileName, this.options.sourceMapMode).correct();
@@ -1603,24 +1618,9 @@ var JavaScriptObfuscatorInternal = function () {
             }
             var astTree = esprima.parse(sourceCode, JavaScriptObfuscatorInternal.esprimaParams);
             var obfuscatedAstTree = new Obfuscator_1.Obfuscator(new ObfuscationEventEmitter_1.ObfuscationEventEmitter(), new StackTraceAnalyzer_1.StackTraceAnalyzer(), new CustomNodesStorage_1.CustomNodesStorage(this.options), this.options).obfuscateAstTree(astTree);
-            var generatorOutput = JavaScriptObfuscatorInternal.generateCode(sourceCode, obfuscatedAstTree, this.options);
+            var generatorOutput = this.generateCode(sourceCode, obfuscatedAstTree);
             return this.getObfuscationResult(generatorOutput);
         }
-    }], [{
-        key: 'generateCode',
-        value: function generateCode(sourceCode, astTree, options) {
-            var escodegenParams = Object.assign({}, JavaScriptObfuscatorInternal.escodegenParams);
-            if (options.sourceMap) {
-                escodegenParams.sourceMap = 'sourceMap';
-                escodegenParams.sourceContent = sourceCode;
-            }
-            escodegenParams.format = {
-                compact: options.compact
-            };
-            var generatorOutput = escodegen.generate(astTree, escodegenParams);
-            generatorOutput.map = generatorOutput.map ? generatorOutput.map.toString() : '';
-            return generatorOutput;
-        }
     }]);
 
     return JavaScriptObfuscatorInternal;
@@ -5178,7 +5178,8 @@ module.exports = require("is-equal");
 module.exports = require("mkdirp");
 
 /***/ },
-/* 107 */
+/* 107 */,
+/* 108 */
 /***/ function(module, exports, __webpack_require__) {
 
 "use strict";

+ 4 - 6
src/JavaScriptObfuscatorInternal.ts

@@ -47,21 +47,20 @@ export class JavaScriptObfuscatorInternal {
     /**
      * @param sourceCode
      * @param astTree
-     * @param options
      */
-    private static generateCode (sourceCode: string, astTree: ESTree.Program, options: IOptions): IGeneratorOutput {
+    private generateCode (sourceCode: string, astTree: ESTree.Program): IGeneratorOutput {
         const escodegenParams: escodegen.GenerateOptions = Object.assign(
             {},
             JavaScriptObfuscatorInternal.escodegenParams
         );
 
-        if (options.sourceMap) {
+        if (this.options.sourceMap) {
             escodegenParams.sourceMap = 'sourceMap';
             escodegenParams.sourceContent = sourceCode;
         }
 
         escodegenParams.format = {
-            compact: options.compact
+            compact: this.options.compact
         };
 
         const generatorOutput: IGeneratorOutput = escodegen.generate(astTree, escodegenParams);
@@ -107,8 +106,7 @@ export class JavaScriptObfuscatorInternal {
         ).obfuscateAstTree(astTree);
 
         // generate code
-        const generatorOutput: IGeneratorOutput = JavaScriptObfuscatorInternal
-            .generateCode(sourceCode, obfuscatedAstTree, this.options);
+        const generatorOutput: IGeneratorOutput = this.generateCode(sourceCode, obfuscatedAstTree);
 
         return this.getObfuscationResult(generatorOutput);
     }

+ 1 - 0
src/Obfuscator.ts

@@ -26,6 +26,7 @@ export class Obfuscator implements IObfuscator {
      * @type {IStorage<ICustomNode>}
      */
     private readonly customNodesStorage: IStorage<ICustomNode>;
+
     /**
      * @type {IObfuscationEventEmitter}
      */