Switched from escodegen to escodegen-wallaby

This commit is contained in:
sanex3339
2017-06-10 17:30:17 +03:00
parent c7a3a2b71e
commit 735bbb4b3c
82 changed files with 3635 additions and 2040 deletions
+35
View File
@@ -40,6 +40,41 @@ export class NodeUtils {
return astTree;
}
/**
* @param astTree
* @return {ESTree.Node}
*/
public static clone <T extends ESTree.Node> (astTree: T): T {
const cloneRecursive: (node: T) => T = (node: T) => {
const copy: {[key: string]: any} = {};
Object
.keys(node)
.filter((property: string) => property !== 'parentNode')
.forEach((property: string): void => {
const value: any = (<{[key: string]: any}>node)[property];
let clonedValue: any | null;
if (value === null || value instanceof RegExp) {
clonedValue = value;
} else if (Array.isArray(value)) {
clonedValue = value.map(cloneRecursive);
} else if (typeof value === 'object') {
clonedValue = cloneRecursive(value);
} else {
clonedValue = value;
}
copy[property] = clonedValue;
});
return <T>copy;
};
return NodeUtils.parentize(cloneRecursive(astTree));
}
/**
* @param code
* @returns {TStatement[]}
+7 -1
View File
@@ -189,13 +189,19 @@ export class Nodes {
/**
* @param test
* @param consequent
* @param alternate
* @returns {ESTree.IfStatement}
*/
public static getIfStatementNode (test: ESTree.Expression, consequent: ESTree.BlockStatement): ESTree.IfStatement {
public static getIfStatementNode (
test: ESTree.Expression,
consequent: ESTree.BlockStatement,
alternate?: ESTree.BlockStatement
): ESTree.IfStatement {
return {
type: NodeType.IfStatement,
test,
consequent,
...alternate && {alternate},
obfuscatedNode: false
};
}