public final class NodeUtil extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
NodeUtil.Visitor
Interface for use with the visit method.
|
Modifier and Type | Method and Description |
---|---|
static Node |
getAssignedValue(Node n)
For an assignment or variable declaration get the assigned value.
|
static JSDocInfo |
getBestJSDocInfo(Node n)
Find the best JSDoc for the given node.
|
static Node |
getEnclosingBlock(Node n)
Finds the block containing the given node.
|
static Node |
getEnclosingFunction(Node n)
Finds the function containing the given node.
|
static Node |
getEnclosingNode(Node n,
com.google.common.base.Predicate<Node> pred) |
static Node |
getEnclosingScript(Node n)
Finds the script containing the given node.
|
static Node |
getEnclosingStatement(Node n) |
static Node |
getFunctionParameters(Node fnNode) |
static InputId |
getInputId(Node n) |
static String |
getName(Node n) |
static String |
getNearestFunctionName(Node n)
Gets the function's name.
|
static StaticSourceFile |
getSourceFile(Node n) |
static String |
getSourceName(Node n) |
static boolean |
isAssignmentOp(Node n) |
static boolean |
isClassDeclaration(Node n)
|
static boolean |
isForIn(Node n) |
static boolean |
isFunctionDeclaration(Node n)
Is this node a function declaration? A function declaration is a function
that has a name that is added to the current scope (i.e.
|
static boolean |
isHoistedFunctionDeclaration(Node n)
Is this node a hoisted function declaration? A function declaration in the
scope root is hoisted to the top of the scope.
|
static boolean |
isInFunction(Node n) |
static boolean |
isLhsByDestructuring(Node n) |
static boolean |
isLValue(Node n)
Determines whether this node is used as an L-value.
|
static boolean |
isNameDeclaration(Node n)
Is this node a name declaration?
|
static boolean |
isPrototypePropertyDeclaration(Node n) |
static boolean |
isStatement(Node n) |
static boolean |
isValidQualifiedName(CompilerOptions.LanguageMode mode,
String name)
Determines whether the given name is a valid qualified name.
|
static boolean |
isValidQualifiedName(String name)
Deprecated.
|
static Map<Node,Node> |
mapMainToClone(Node main,
Node clone)
Given an AST and its copy, map the root node of each scope of main to the
corresponding root node of clone
|
static boolean |
mayHaveSideEffects(Node n)
Returns true if the node which may have side effects when executed.
|
static boolean |
mayHaveSideEffects(Node n,
AbstractCompiler compiler) |
static Node |
newPropertyAccess(AbstractCompiler compiler,
Node context,
String name)
Creates a property access on the
context tree. |
static Node |
newQName(AbstractCompiler compiler,
String name)
Creates a node representing a qualified name.
|
static Node |
newQNameDeclaration(AbstractCompiler compiler,
String name,
Node value,
JSDocInfo info)
Creates a node representing a qualified name.
|
static String |
opToStr(int operator)
Converts an operator's token value (see
Token ) to a string
representation. |
static void |
verifyScopeChanges(Map<Node,Node> map,
Node main,
boolean verifyUnchangedNodes,
AbstractCompiler compiler)
Checks that the scope roots marked as changed have indeed changed
|
static void |
visitPreOrder(Node node,
NodeUtil.Visitor visitor,
com.google.common.base.Predicate<Node> traverseChildrenPred)
A pre-order traversal, calling Visitor.visit for each child matching
the predicate.
|
public static String getName(Node n)
n
- A function or class node.public static String getNearestFunctionName(Node n)
{'name': function() ...}
{name: function() ...}
function name() ...
var name = function() ...
var obj = {name() {} ...}
qualified.name = function() ...
var name2 = function name1() ...
qualified.name2 = function name1() ...
n
- a node whose type is Token.FUNCTION
null
if it has no namepublic static boolean mayHaveSideEffects(Node n)
public static boolean mayHaveSideEffects(Node n, AbstractCompiler compiler)
public static boolean isAssignmentOp(Node n)
public static Node getEnclosingFunction(Node n)
public static Node getEnclosingScript(Node n)
public static Node getEnclosingBlock(Node n)
public static boolean isInFunction(Node n)
public static Node getEnclosingNode(Node n, com.google.common.base.Predicate<Node> pred)
public static boolean isNameDeclaration(Node n)
n
- The noden
is VAR, LET or CONSTpublic static Node getAssignedValue(Node n)
public static boolean isForIn(Node n)
public static boolean isStatement(Node n)
public static boolean isFunctionDeclaration(Node n)
isFunctionExpression(com.google.javascript.rhino.Node)
).public static boolean isClassDeclaration(Node n)
public static boolean isHoistedFunctionDeclaration(Node n)
isFunctionDeclaration(com.google.javascript.rhino.Node)
).public static boolean isLValue(Node n)
We treat "var x;" and "let x;" as an L-value because it's syntactically similar to "var x = undefined", even though it's technically not an L-value. But it kind of makes sense if you treat it as "assignment to 'undefined' at the top of the scope".
n
- The nodepublic static boolean isLhsByDestructuring(Node n)
public static String opToStr(int operator)
Token
) to a string
representation.operator
- the operator's token value to convertnull
if the token value is
not an operatorpublic static Node newQName(AbstractCompiler compiler, String name)
name
- A qualified name (e.g. "foo" or "foo.bar.baz")public static Node newPropertyAccess(AbstractCompiler compiler, Node context, String name)
context
tree.public static Node newQNameDeclaration(AbstractCompiler compiler, String name, Node value, JSDocInfo info)
name
- A qualified name (e.g. "foo" or "foo.bar.baz")@Deprecated public static boolean isValidQualifiedName(String name)
public static boolean isValidQualifiedName(CompilerOptions.LanguageMode mode, String name)
public static boolean isPrototypePropertyDeclaration(Node n)
true
if the node an assignment to a prototype property of
some constructor.public static void visitPreOrder(Node node, NodeUtil.Visitor visitor, com.google.common.base.Predicate<Node> traverseChildrenPred)
public static Node getFunctionParameters(Node fnNode)
fnNode
- The function.public static String getSourceName(Node n)
n
- The node.public static StaticSourceFile getSourceFile(Node n)
n
- The node.public static InputId getInputId(Node n)
n
- The node.@Nullable public static JSDocInfo getBestJSDocInfo(Node n)
public static Map<Node,Node> mapMainToClone(Node main, Node clone)
public static void verifyScopeChanges(Map<Node,Node> map, Node main, boolean verifyUnchangedNodes, AbstractCompiler compiler)
Copyright © 2009-2016 Google. All Rights Reserved.