NodeUtils
Static Method Summary
Static Public Methods | ||
public static |
getBFSTraversal(node: Node, n: int): Node[] Returns an array of nodes in the passed AST, traversed using BFS. |
|
public static |
getChildren(The: Node): Node[] Returns a given node's children as an array of nodes. Designed for use with ESTree/Babylon spec ASTs. |
|
public static |
getDFSTraversal(node: Node, n: int): Node[] Returns an array of nodes in the passed AST, traversed using DFS. |
|
public static |
identifiersMatch(nodes: Node[]): boolean Returns whether or not all nodes have the same identifier. |
|
public static |
Returns whether or not the nodes are part of an AMD require or define expression. |
|
public static |
Returns whether or not the first node appears before the second, by comparing both their starting lines and columns. |
|
public static |
isCommonJS(nodes: Node[]): boolean Returns whether or not the nodes are part of a CommonJS require statement. |
|
public static |
isES6ClassBoilerplate(nodes: Node[]): boolean Returns whether or not the nodes belong to class boilerplate. |
|
public static |
isES6ModuleImport(nodes: Node[]): boolean Returns whether or not the nodes are part of an ES6 module import. |
|
public static |
literalsMatch(nodes: Node[]): boolean Returns whether or not all nodes have the same literal value. |
|
public static |
typesMatch(nodes: Node[]): boolean Returns whether or not all nodes are of the same type. |
|
public static |
walkSubtrees(root: Node, fn: function) Walks a root node's subtrees using DFS, invoking the passed callback with three args: node, parent, and ancestors. The root node, presumably Program, is ignored. |
Static Public Methods
public static getBFSTraversal(node: Node, n: int): Node[] source
Returns an array of nodes in the passed AST, traversed using BFS. Accepts an optional maximum number, n, of nodes to return. The returned array always begins with the root node.
Params:
Name | Type | Attribute | Description |
node | Node | The root node of the AST to traverse |
|
n | int |
|
Optional max number of nodes to return |
Return:
Node[] |
public static getChildren(The: Node): Node[] source
Returns a given node's children as an array of nodes. Designed for use with ESTree/Babylon spec ASTs.
Params:
Name | Type | Attribute | Description |
The | Node | node for which to retrieve its children |
Return:
Node[] | An array of child nodes |
public static getDFSTraversal(node: Node, n: int): Node[] source
Returns an array of nodes in the passed AST, traversed using DFS. Accepts an optional maximum number, n, of nodes to return. The returned array always begins with the root node.
Params:
Name | Type | Attribute | Description |
node | Node | The root node of the AST to traverse |
|
n | int |
|
Optional max number of nodes to return |
Return:
Node[] |
public static identifiersMatch(nodes: Node[]): boolean source
Returns whether or not all nodes have the same identifier.
Params:
Name | Type | Attribute | Description |
nodes | Node[] |
public static isAMD(nodes: Node[]): boolean source
Returns whether or not the nodes are part of an AMD require or define expression.
Params:
Name | Type | Attribute | Description |
nodes | Node[] |
public static isBefore(a: object, b: object): bool source
Returns whether or not the first node appears before the second, by comparing both their starting lines and columns.
Return:
bool |
public static isCommonJS(nodes: Node[]): boolean source
Returns whether or not the nodes are part of a CommonJS require statement.
Params:
Name | Type | Attribute | Description |
nodes | Node[] |
public static isES6ClassBoilerplate(nodes: Node[]): boolean source
Returns whether or not the nodes belong to class boilerplate.
Params:
Name | Type | Attribute | Description |
nodes | Node[] |
public static isES6ModuleImport(nodes: Node[]): boolean source
Returns whether or not the nodes are part of an ES6 module import.
Params:
Name | Type | Attribute | Description |
nodes | Node[] |
public static literalsMatch(nodes: Node[]): boolean source
Returns whether or not all nodes have the same literal value.
Params:
Name | Type | Attribute | Description |
nodes | Node[] |
public static typesMatch(nodes: Node[]): boolean source
Returns whether or not all nodes are of the same type.
Params:
Name | Type | Attribute | Description |
nodes | Node[] |
public static walkSubtrees(root: Node, fn: function) source
Walks a root node's subtrees using DFS, invoking the passed callback with three args: node, parent, and ancestors. The root node, presumably Program, is ignored.
Params:
Name | Type | Attribute | Description |
root | Node | The root node of the AST to traverse |
|
fn | function | Callback to invoke |