Browse Source

fixed empty controlFlowStorageCustomNode append

sanex3339 8 years ago
parent
commit
9ff3403a68

File diff suppressed because it is too large
+ 340 - 297
dist/index.js


+ 4 - 3
src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts

@@ -20,7 +20,6 @@ import { ControlFlowStorageNode } from '../../custom-nodes/control-flow-storage-
 import { Node } from '../../node/Node';
 import { NodeAppender } from '../../node/NodeAppender';
 import { Utils } from '../../Utils';
-import { NodeUtils } from '../../node/NodeUtils';
 
 @injectable()
 export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
@@ -60,8 +59,6 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
         const controlFlowStorage: IStorage <ICustomNode> = new ControlFlowStorage();
         const controlFlowStorageCustomNodeName: string = Utils.getRandomVariableName(6);
 
-        console.log(NodeUtils.getNodeBlockScopeDepth(functionNode.body));
-
         estraverse.replace(functionNode.body, {
             enter: (node: ESTree.Node, parentNode: ESTree.Node): any => {
                 const controlFlowReplacer: TControlFlowReplacer | undefined = FunctionControlFlowTransformer
@@ -94,6 +91,10 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
             }
         });
 
+        if (!controlFlowStorage.getLength()) {
+            return;
+        }
+
         const controlFlowStorageCustomNode: ICustomNode = new ControlFlowStorageNode(
             controlFlowStorage,
             controlFlowStorageCustomNodeName,

+ 4 - 0
src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts

@@ -59,6 +59,10 @@ export class IdentifierReplacer extends AbstractReplacer {
      * @param nodeName
      */
     public storeNames (nodeName: string): void {
+        if (!this.uniquePrefix) {
+            throw new Error('`uniquePrefix` is `undefined`. Set it before `storeNames`');
+        }
+
         if (!this.isReservedName(nodeName)) {
             this.namesMap.set(`${nodeName}-${this.uniquePrefix}`, Utils.getRandomVariableName());
         }

Some files were not shown because too many files changed in this diff