Home Reference Source Test
public class | source

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

isAMD(nodes: Node[]): boolean

Returns whether or not the nodes are part of an AMD require or define expression.

public static

isBefore(a: object, b: object): bool

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:

NameTypeAttributeDescription
node Node

The root node of the AST to traverse

n int
  • optional

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
node Node

The root node of the AST to traverse

n int
  • optional

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:

NameTypeAttributeDescription
nodes Node[]

Return:

boolean

public static isAMD(nodes: Node[]): boolean source

Returns whether or not the nodes are part of an AMD require or define expression.

Params:

NameTypeAttributeDescription
nodes Node[]

Return:

boolean

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.

Params:

NameTypeAttributeDescription
a object
b object

Return:

bool

public static isCommonJS(nodes: Node[]): boolean source

Returns whether or not the nodes are part of a CommonJS require statement.

Params:

NameTypeAttributeDescription
nodes Node[]

Return:

boolean

public static isES6ClassBoilerplate(nodes: Node[]): boolean source

Returns whether or not the nodes belong to class boilerplate.

Params:

NameTypeAttributeDescription
nodes Node[]

Return:

boolean

public static isES6ModuleImport(nodes: Node[]): boolean source

Returns whether or not the nodes are part of an ES6 module import.

Params:

NameTypeAttributeDescription
nodes Node[]

Return:

boolean

public static literalsMatch(nodes: Node[]): boolean source

Returns whether or not all nodes have the same literal value.

Params:

NameTypeAttributeDescription
nodes Node[]

Return:

boolean

public static typesMatch(nodes: Node[]): boolean source

Returns whether or not all nodes are of the same type.

Params:

NameTypeAttributeDescription
nodes Node[]

Return:

boolean

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:

NameTypeAttributeDescription
root Node

The root node of the AST to traverse

fn function

Callback to invoke