fixed empty controlFlowStorageCustomNode append

This commit is contained in:
sanex3339
2016-11-29 21:59:59 +03:00
parent 129dd25388
commit 9ff3403a68
3 changed files with 816 additions and 805 deletions
+808 -802
View File
File diff suppressed because it is too large Load Diff
@@ -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,
@@ -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());
}