Reference Source Test
import ASTUtil from 'esdoc2/out/src/Util/ASTUtil.js'
public class | source

ASTUtil

Utility for AST.

Static Method Summary

Static Public Methods
public static

create VariableDeclaration node which has NewExpression.

public static

findClassDeclarationNode(name: string, ast: AST): {classNode: ASTNode|null, exported: boolean|null}

find ClassDeclaration node.

public static

find FunctionDeclaration node.

public static

find file path in import declaration by name.

public static

find VariableDeclaration node which has NewExpression.

public static

find VariableDeclaration node.

public static

sanitize(node: ASTNode)

sanitize node.

public static

traverse(ast: AST, callback: function(node: Object, parent: Object, path: Object))

traverse ast nodes.

Static Public Methods

public static createVariableDeclarationAndNewExpressionNode(name: string, className: string, loc: Object): ASTNode source

create VariableDeclaration node which has NewExpression.

Params:

NameTypeAttributeDescription
name string

variable name.

className string

class name.

loc Object

location.

Return:

ASTNode

created node.

public static findClassDeclarationNode(name: string, ast: AST): {classNode: ASTNode|null, exported: boolean|null} source

find ClassDeclaration node.

Params:

NameTypeAttributeDescription
name string

class name.

ast AST

find in this ast.

Return:

{classNode: ASTNode|null, exported: boolean|null}

found ast node.

public static findFunctionDeclarationNode(name: string, ast: AST): ASTNode | null source

find FunctionDeclaration node.

Params:

NameTypeAttributeDescription
name string

function name.

ast AST

find in this ast.

Return:

ASTNode | null

found ast node.

public static findPathInImportDeclaration(ast: AST, name: string): string | null source

find file path in import declaration by name. e.g. can find ./foo/bar.js from import Bar from './foo/bar.js' by Bar.

Params:

NameTypeAttributeDescription
ast AST

target AST.

name string

identifier name.

Return:

string | null

file path.

public static findVariableDeclarationAndNewExpressionNode(name: string, ast: AST): ASTNode | null source

find VariableDeclaration node which has NewExpression.

Params:

NameTypeAttributeDescription
name string

variable name.

ast AST

find in this ast.

Return:

ASTNode | null

found ast node.

public static findVariableDeclarationNode(name: string, ast: AST): ASTNode | null source

find VariableDeclaration node.

Params:

NameTypeAttributeDescription
name string

variable name.

ast AST

find in this ast.

Return:

ASTNode | null

found ast node.

public static sanitize(node: ASTNode) source

sanitize node. change node type to Identifier and empty comment.

Params:

NameTypeAttributeDescription
node ASTNode

target node.

public static traverse(ast: AST, callback: function(node: Object, parent: Object, path: Object)) source

traverse ast nodes.

Params:

NameTypeAttributeDescription
ast AST

target AST.

callback function(node: Object, parent: Object, path: Object)

this is called with each node.