Class Node
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classIterator to go up the ancestor tree.static final classA helper class for getting and setting invocation side-effect flags. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final intMAX_COLUMN_NUMBER represents the maximum column number that can be represented.static final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Propstatic final com.google.javascript.rhino.Node.Prop -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddChildrenAfter(@Nullable Node children, @Nullable Node node) Add all children after 'node'.final voidaddChildrenToBack(Node children) final voidaddChildrenToFront(@Nullable Node children) Add all children to the front of this node.final voidaddChildToBack(Node child) final voidaddChildToFront(Node child) final voidappendJsonTree(Appendable appendable) final voidappendStringTree(Appendable appendable) children()Deprecated.final Objectclone()final NodeReturns a detached clone of the Node, specifically excluding its children.final NodeclonePropsFrom(Node other) Clone the properties from the provided node without copying the property object.final NodeReturns a detached clone of the Node and all its children.final NodecloneTree(boolean cloneTypeExprs) final NodecopyTypeFrom(Node other) Copies a nodes JSType or Color (if present)final voiddeserializeProperties(long propSet) final Nodedetach()Removes this node from its parent, but retains its subtree.final voidRemoves all children from this node and isolates the children from each other.final @Nullable NodegetAncestor(int level) Gets the ancestor node relative to this.final Node.AncestorIterableIterates all of the node's ancestors excluding itself.final BigIntegerfinal booleangetBooleanProp(com.google.javascript.rhino.Node.Prop propType) final intReturns the time of the last change for this nodefinal intfinal NodegetChildAtIndex(int i) Gets the ith child, note that this is O(N) where N is the number of children.final intfinal @Nullable Nodefinal @Nullable ColorgetColor()Returns the compiled inferred type on this node.final @Nullable Stringfinal @Nullable NodeReturns the syntactical type specified on this node.final doublefinal @Nullable Nodefinal @Nullable NodeGet the first child of the first child.final @Nullable Nodefinal intgetIndexOfChild(Node child) Gets the index of a child, note that this is O(N) where N is the number of children.@Nullable InputIdReturns the Id of the CompilerInput associated with this Node.final booleanCheck whether node was inside original source-level parentheses.final @Nullable JSDocInfoGet theJSDocInfoattached to this node.final @Nullable JSTypeReturns the compiler inferred type on this node.final @Nullable JSTypeReturns the type of this node before casting.final JSTypeReturns the compiled inferred type on this node, or throws an NPE if there isn't one.final @Nullable Nodefinal intfinal intfinal Stringfinal @Nullable NodegetNext()final NonJSDocCommentfinal StringGet the NonJSDoc comment string attached to this node.final Nodefinal @Nullable StringDeprecated."original name" is poorly defined.final @Nullable StringDeprecated."original name" is poorly defined.final @Nullable Nodefinal @Nullable Nodefinal @Nullable ObjectgetProp(com.google.javascript.rhino.Node.Prop propType) final @Nullable StringThis function takes a set of GETPROP nodes and produces a string that is each property separated by dots.final @Nullable QualifiedNamefinal Stringfinal @Nullable Nodefinal intReturns the side effects flags for this node.@Nullable Stringintfinal int@Nullable StaticSourceFileReturns the source file associated with this input.final Stringfinal TokengetToken()final NonJSDocCommentfinal Stringfinal JSTypeIf this node represents a typedef declaration, the associated JSTypestatic final booleanhasBitSet(long bitset, int bit) final booleanfinal booleanfinal booleanCheck for more than one child more efficiently than by iterating over all the children as is done with Node.getChildCount().final booleanCheck for one child more efficiently than by iterating over all the children as is done with Node.getChildCount().final booleanfinal booleanReturns true if there was a trailing comma in the orginal codefinal booleanCheck for two children more efficiently thangetChildCount() == 2final booleanhasXChildren(int x) Check for has exactly the number of specified children.final booleanCheck for zero or one child more efficiently than by iterating over all the children as is done with Node.getChildCount().final voidinsertAfter(Node existing) final voidinsertBefore(Node existing) final booleanisAdd()AST type check methodsfinal booleanReturns whether this is an added block that should not be considered a real source block.final booleanisAnd()final booleanfinal booleanfinal booleanReturns whether this node is a arrow function node.final booleanisAssign()final booleanfinal booleanfinal booleanfinal booleanfinal booleanfinal booleanReturns whether this is an async function node.final booleanReturns whether this is an async generator function node.final booleanisAwait()final booleanisBigInt()final booleanisBitNot()final booleanisBlock()final booleanisBreak()final booleanisCall()final booleanfinal booleanisCase()final booleanisCast()final booleanisCatch()final booleanisClass()final booleanfinal booleanIndicates that this node is for source that was written without any understanding of the compiler's various type-checking or optimization limitations, and should be optimized very cautiously by the compiler.final booleanIndicates that this node's color comes from a type assertion.final booleanisComma()final booleanfinal booleanfinal booleanisConst()final booleanfinal booleanfinal booleanisDec()final booleanfinal booleanReturns whether this variable is declared as a constant.final booleanfinal booleanfinal booleanfinal booleanfinal booleanisDescendantOf(Node node) Is this Node the same asnodeor a descendant ofnode?final booleanfinal booleanfinal booleanisDo()final booleanisEmpty()final booleanisEQ()final booleanisEquivalentTo(Node node) Returns true if this node is equivalent semantically to anotherbooleanisEquivalentTo(Node node, boolean compareType, boolean recurse, boolean jsDoc, boolean sideEffect) Returns whether this node is equivalent semantically to the provided node.final booleanisEquivalentToShallow(Node node) Checks equivalence without going into child nodesfinal booleanisEquivalentToTyped(Node node) Returns true if this node is equivalent semantically to another and the types are equivalent.final booleanReturns true if this node is equivalent semantically to another including side effects.final booleanReturns true if this node is equivalent semantically to another including side effects.final booleanfinal booleanisExport()final booleanfinal booleanfinal booleanfinal booleanisFalse()final booleanisFirstChildOf(Node possibleParent) final booleanfinal booleanisForIn()final booleanisForOf()final booleanfinal booleanfinal booleanReturns whether this node is a generator function node.final booleanReturns whether this node was marked as containing YIELD nodes.final booleanUsed when translating ES6 generators.final booleanfinal booleanfinal booleanfinal booleanisHook()final booleanisIf()final booleanisImport()final booleanfinal booleanfinal booleanfinal booleanfinal booleanisIn()final booleanisInc()final booleanWhether this node should be indexed by static analysis / code indexing tools.final booleanfinal booleanReturns whether this variable is inferred to be constant.final booleanfinal booleanfinal booleanfinal booleanisLabel()final booleanfinal booleanisLet()final booleanfinal booleanfinal booleanfinal booleanfinal booleanisName()final booleanisNE()final booleanisNeg()final booleanisNew()final booleanfinal booleanReturns true if this node is a function or constructor call that has no side effects.final booleanisNot()final booleanisNull()final booleanfinal booleanisNumber()final booleanfinal booleanfinal booleanfinal booleanisOnlyChildOf(Node possibleParent) final booleanReturns whether the only side-effect is "modifies arguments" or there are no side effects.final booleanReturns whether the only side-effect is "modifies this" or there are no side effects.final booleanfinal booleanfinal booleanfinal booleanReturns whether this node is an optional chaining node.final booleanReturns whether this node is an optional node in the ES6 Typed syntax.final booleanisOr()final booleanfinal booleanfinal booleanReturns whether a node corresponds to a simple or a qualified name, such asxora.b.corthis.a.final booleanfinal booleanfinal booleanisRegExp()final booleanisRest()final booleanisReturn()final booleanisRoot()final booleanisScript()final booleanisSecondChildOf(Node possibleParent) final booleanfinal booleanisSHEQ()final booleanisSHNE()final booleanWhether this {x:x} property was originally parsed as {x}.final booleanisSpread()final booleanReturns whether this node is a static member node.final booleanisString()final booleanfinal booleanfinal booleanisSub()final booleanisSuper()final booleanisSwitch()final booleanfinal booleanfinal booleanReturns whether this is a synthetic block that should not be considered a real source block.final booleanfinal booleanfinal booleanfinal booleanfinal booleanisThis()final booleanisThrow()final booleanisTrue()final booleanisTry()final booleanisTypeOf()final booleanReturns whether a node corresponds to a simple or a qualified name without a "this" reference, such asa.b.c, but notthis.a.final booleanIs this node an unused function parameter declaration?final booleanReturns whether this node contained the "use strict" directive.final booleanfinal booleanfinal booleanisVar()final booleanisVoid()final booleanisWhile()final booleanisWith()final booleanisYield()final booleanReturns whether this node is a generator node.final voidfinal voidfinal booleanmatchesName(Node n) Check that if two NAME node match, returns false if either node is not a NAME node.final booleanmatchesName(String name) Returns whether a node matches a simple name, such asx, returns false if this is not a NAME node.final booleanReturns whether a node matches a simple or a qualified name, such asxora.b.corthis.a.final booleanmatchesQualifiedName(String name) Returns whether a node matches a simple or a qualified name, such asxora.b.corthis.a.final booleanReturns true if this is a new/call that may mutate its arguments.final booleanReturns true if this is a new/call that may mutate global state or throw.static NodenewBigInt(BigInteger bigint) static NodenewNumber(double number) static NodenewString(Token token, RhinoStringPool.LazyInternedStringList stringPool, int offset) static Nodestatic Nodestatic NodenewTemplateLitString(RhinoStringPool.LazyInternedStringList stringPool, int cookedOffsetOrNegativeOne, int rawOffset) static NodenewTemplateLitString(String cooked, String raw) final voidputBooleanProp(com.google.javascript.rhino.Node.Prop propType, boolean value) final voidputIntProp(com.google.javascript.rhino.Node.Prop prop, int value) final voidfinal @Nullable NodeRemove all children, but leave them linked to each other.final @Nullable NodeRemoves the first child of Node.final voidreplaceWith(Node replacement) Swaps `replacement` and its subtree into the position of `this`.final longfinal voidsetBigInt(BigInteger number) final voidsetChangeTime(int time) This node was last changed attimefinal voidsetClosureUnawareShadow(@Nullable Node shadowRoot) final Nodefinal voidIndicate that this node's color comes from a type assertion.final voidsetDeclaredConstantVar(boolean value) Sets this variable to be a declared constant.final voidsetDeclaredTypeExpression(Node typeExpression) Sets the syntactical type specified on this node.final voidsetDeleted(boolean deleted) final voidsetDouble(double x) final voidsetGeneratorMarker(boolean isGeneratorMarker) Sets whether this node subtree contains YIELD nodes.final voidsetGeneratorSafe(boolean isGeneratorSafe) Set the value for isGeneratorSafe()final voidsetInferredConstantVar(boolean value) Sets this variable to be an inferred constant.voidsetInputId(InputId inputId) Sets the ID of the input this Node came from.final voidsetIsAddedBlock(boolean val) Sets whether this is an added block that should not be considered a real source block.final voidsetIsArrowFunction(boolean isArrow) Sets whether this node is a arrow function node.voidsetIsAsyncFunction(boolean isAsync) Sets whether this node is an async function node.final voidsetIsGeneratorFunction(boolean isGenerator) Sets whether this node is a generator node.final voidsetIsOptionalChainStart(boolean isOptionalChainStart) Sets whether this node is the start of an optional chain.final voidsetIsParenthesized(boolean b) Sets whether this node was inside original source-level parentheses.final voidsetIsSynthesizedUnfulfilledNameDeclaration(boolean val) final voidsetIsSyntheticBlock(boolean val) Sets whether this is a synthetic block that should not be considered a real source block.final NodesetJSDocInfo(JSDocInfo info) Sets theJSDocInfoattached to this node.final Nodefinal voidsetJSTypeBeforeCast(JSType type) Sets the type of this node before casting.final voidsetLength(int length) final NodesetLinenoCharno(int lineno, int charno) Merges the line number and character number in one integer.final NodesetNonJSDocComment(NonJSDocComment comment) Sets the NonJSDoc comment attached to this node.final voidfinal voidsetOriginalNameFromName(Node name) final voidsetOriginalNameFromStringPool(RhinoStringPool.LazyInternedStringList stringPool, int offset) final voidfinal voidfinal voidsetShorthandProperty(boolean shorthand) Sets the isShorthandProperty annotation.final voidsetSideEffectFlags(int flags) Marks this function or constructor call's side effect flags.final voidfinal voidSets the source file to a non-extern file of the given name.final voidsetStaticMember(boolean isStatic) Sets whether this node is a static member node.final NodesetStaticSourceFile(@Nullable StaticSourceFile file) final voidsetStaticSourceFileFrom(Node other) final voidfinal voidfinal voidsetTrailingComma(boolean hasTrailingComma) Indicates that there was a trailing comma in this listfinal Nodefinal voidsetTypedefTypeProp(JSType type) If this node represents a typedef declaration, the associated JSTypefinal voidsetUnusedParameter(boolean unused) Sets the value for isUnusedParameter()final voidsetUseStrict(boolean x) Sets whether this node contained the "use strict" directive.final voidsetYieldAll(boolean isGenerator) Sets whether this node is a generator node.final NodeCopy the source info from `other` onto `this`.final NodesrcrefIfMissing(Node other) Iff source info is not set on `this`, copy the source info from `other`.final NodesrcrefTree(Node other) For all Nodes in the subtree of `this`, copy the source info from `other`.final NodesrcrefTreeIfMissing(Node other) For all Nodes in the subtree of `this`, iff source info is not set, copy the source info from `other`.final StringtoString()final StringtoString(boolean printSource, boolean printAnnotations, boolean printType) final StringvoidvalidateProperties(Consumer<String> violationMessageConsumer) Checks for invalid or missing properties and feeds error messages for any violations to the given `Consumer`.
-
Field Details
-
INCRDECR_PROP
public static final com.google.javascript.rhino.Node.Prop INCRDECR_PROP -
QUOTED_PROP
public static final com.google.javascript.rhino.Node.Prop QUOTED_PROP -
IS_CONSTANT_NAME
public static final com.google.javascript.rhino.Node.Prop IS_CONSTANT_NAME -
IS_NAMESPACE
public static final com.google.javascript.rhino.Node.Prop IS_NAMESPACE -
DIRECT_EVAL
public static final com.google.javascript.rhino.Node.Prop DIRECT_EVAL -
FREE_CALL
public static final com.google.javascript.rhino.Node.Prop FREE_CALL -
REFLECTED_OBJECT
public static final com.google.javascript.rhino.Node.Prop REFLECTED_OBJECT -
STATIC_MEMBER
public static final com.google.javascript.rhino.Node.Prop STATIC_MEMBER -
GENERATOR_FN
public static final com.google.javascript.rhino.Node.Prop GENERATOR_FN -
YIELD_ALL
public static final com.google.javascript.rhino.Node.Prop YIELD_ALL -
EXPORT_DEFAULT
public static final com.google.javascript.rhino.Node.Prop EXPORT_DEFAULT -
EXPORT_ALL_FROM
public static final com.google.javascript.rhino.Node.Prop EXPORT_ALL_FROM -
COMPUTED_PROP_METHOD
public static final com.google.javascript.rhino.Node.Prop COMPUTED_PROP_METHOD -
COMPUTED_PROP_GETTER
public static final com.google.javascript.rhino.Node.Prop COMPUTED_PROP_GETTER -
COMPUTED_PROP_SETTER
public static final com.google.javascript.rhino.Node.Prop COMPUTED_PROP_SETTER -
COMPUTED_PROP_VARIABLE
public static final com.google.javascript.rhino.Node.Prop COMPUTED_PROP_VARIABLE -
OPT_ES6_TYPED
public static final com.google.javascript.rhino.Node.Prop OPT_ES6_TYPED -
GENERIC_TYPE_LIST
public static final com.google.javascript.rhino.Node.Prop GENERIC_TYPE_LIST -
IMPLEMENTS
public static final com.google.javascript.rhino.Node.Prop IMPLEMENTS -
CONSTRUCT_SIGNATURE
public static final com.google.javascript.rhino.Node.Prop CONSTRUCT_SIGNATURE -
ACCESS_MODIFIER
public static final com.google.javascript.rhino.Node.Prop ACCESS_MODIFIER -
GOOG_MODULE
public static final com.google.javascript.rhino.Node.Prop GOOG_MODULE -
FEATURE_SET
public static final com.google.javascript.rhino.Node.Prop FEATURE_SET -
IS_TYPESCRIPT_ABSTRACT
public static final com.google.javascript.rhino.Node.Prop IS_TYPESCRIPT_ABSTRACT -
MODULE_ALIAS
public static final com.google.javascript.rhino.Node.Prop MODULE_ALIAS -
MODULE_EXPORT
public static final com.google.javascript.rhino.Node.Prop MODULE_EXPORT -
IS_SHORTHAND_PROPERTY
public static final com.google.javascript.rhino.Node.Prop IS_SHORTHAND_PROPERTY -
ES6_MODULE
public static final com.google.javascript.rhino.Node.Prop ES6_MODULE -
MAX_COLUMN_NUMBER
public static final int MAX_COLUMN_NUMBERMAX_COLUMN_NUMBER represents the maximum column number that can be represented. JSCompiler's modifications to Rhino cause all tokens located beyond the maximum column to MAX_COLUMN_NUMBER.- See Also:
-
-
Constructor Details
-
Node
-
Node
-
Node
-
Node
-
-
Method Details
-
getNonJSDocCommentString
Get the NonJSDoc comment string attached to this node.- Returns:
- the information or empty string if no nonJSDoc is attached to this node
-
getNonJSDocComment
-
getTrailingNonJSDocCommentString
-
getTrailingNonJSDocComment
-
setNonJSDocComment
Sets the NonJSDoc comment attached to this node. -
setTrailingNonJSDocComment
-
setIsParenthesized
public final void setIsParenthesized(boolean b) Sets whether this node was inside original source-level parentheses. -
getIsParenthesized
public final boolean getIsParenthesized()Check whether node was inside original source-level parentheses. -
newNumber
-
newBigInt
-
newString
-
newString
-
newString
public static Node newString(Token token, RhinoStringPool.LazyInternedStringList stringPool, int offset) -
newTemplateLitString
-
newTemplateLitString
public static Node newTemplateLitString(RhinoStringPool.LazyInternedStringList stringPool, int cookedOffsetOrNegativeOne, int rawOffset) -
getToken
-
setToken
-
hasChildren
public final boolean hasChildren() -
getOnlyChild
-
getFirstChild
-
getFirstFirstChild
Get the first child of the first child. This method assumes that the first child exists.- Returns:
- The first child of the first child.
-
getSecondChild
-
getLastChild
-
getNext
-
getPrevious
-
setClosureUnawareShadow
-
getClosureUnawareShadow
-
getChildAtIndex
Gets the ith child, note that this is O(N) where N is the number of children.- Parameters:
i- The index- Returns:
- The ith child
-
getIndexOfChild
Gets the index of a child, note that this is O(N) where N is the number of children.- Parameters:
child- The child- Returns:
- The index of the child
-
addChildToFront
-
addChildToBack
-
addChildrenToFront
Add all children to the front of this node.- Parameters:
children- first of a list of sibling nodes who have no parent. NOTE: Usually you would get this argument from a removeChildren() call. A single detached node will not work because its sibling pointers will not be correctly initialized.
-
addChildrenToBack
-
insertAfter
-
insertBefore
-
addChildrenAfter
Add all children after 'node'. If 'node' is null, add them to the front of this node.- Parameters:
children- first of a list of sibling nodes who have no parent. NOTE: Usually you would get this argument from a removeChildren() call. A single detached node will not work because its sibling pointers will not be correctly initialized.
-
replaceWith
Swaps `replacement` and its subtree into the position of `this`. -
detach
Removes this node from its parent, but retains its subtree. -
removeFirstChild
Removes the first child of Node. Equivalent to: node.removeChild(node.getFirstChild());- Returns:
- The removed Node.
-
removeChildren
Remove all children, but leave them linked to each other.- Returns:
- The first child node
-
detachChildren
public final void detachChildren()Removes all children from this node and isolates the children from each other. -
clonePropsFrom
Clone the properties from the provided node without copying the property object. The receiving node may not have any existing properties.- Parameters:
other- The node to clone properties from.- Returns:
- this node.
-
validateProperties
Checks for invalid or missing properties and feeds error messages for any violations to the given `Consumer`.We use a `Consumer` to avoid the cost of building a usually-empty list every time this method is called.
-
getProp
-
getBooleanProp
public final boolean getBooleanProp(com.google.javascript.rhino.Node.Prop propType) -
putProp
-
putBooleanProp
public final void putBooleanProp(com.google.javascript.rhino.Node.Prop propType, boolean value) -
putIntProp
public final void putIntProp(com.google.javascript.rhino.Node.Prop prop, int value) -
hasBitSet
public static final boolean hasBitSet(long bitset, int bit) -
serializeProperties
public final long serializeProperties() -
deserializeProperties
public final void deserializeProperties(long propSet) -
setDeclaredTypeExpression
Sets the syntactical type specified on this node. -
getDeclaredTypeExpression
Returns the syntactical type specified on this node. Not to be confused withgetJSType()which returns the compiler-inferred type. -
setJSTypeBeforeCast
Sets the type of this node before casting. -
getJSTypeBeforeCast
Returns the type of this node before casting. This annotation will only exist on the first child of a CAST node after type checking. -
setColorFromTypeCast
public final void setColorFromTypeCast()Indicate that this node's color comes from a type assertion. Only set when colors are present; when JSTypes are on the AST we instead preserve the actual JSType before the type assertion. -
isColorFromTypeCast
public final boolean isColorFromTypeCast()Indicates that this node's color comes from a type assertion. Only set when colors are present. -
getDouble
public final double getDouble() -
setDouble
public final void setDouble(double x) -
getBigInt
-
setBigInt
-
getString
-
setString
-
getRawString
-
getCookedString
-
toString
-
toString
-
toStringTree
-
appendStringTree
- Throws:
IOException
-
appendJsonTree
- Throws:
IOException
-
setStaticSourceFileFrom
-
setStaticSourceFile
-
setSourceFileForTesting
Sets the source file to a non-extern file of the given name. -
getSourceFileName
-
getStaticSourceFile
Returns the source file associated with this input. -
setInputId
Sets the ID of the input this Node came from. -
getInputId
Returns the Id of the CompilerInput associated with this Node. -
getOriginalName
Deprecated."original name" is poorly defined.The original name of this node, if the node has been renamed.Do not use original name to make optimization decisions. The original intent was to preserve some naming for lightly optimized code to put into source maps. It is not rigorously defined and is not a suitable replacement for a canonical identifier. "Original name" is not associated with any scope and easily transfers to unrelated values. Its existance and use beyond its original purpose has delayed creating useful more precise alternatives.
-
setOriginalName
-
setOriginalNameFromStringPool
public final void setOriginalNameFromStringPool(RhinoStringPool.LazyInternedStringList stringPool, int offset) -
setOriginalNameFromName
-
isIndexable
public final boolean isIndexable()Whether this node should be indexed by static analysis / code indexing tools. -
makeNonIndexable
public final void makeNonIndexable() -
makeNonIndexableRecursive
public final void makeNonIndexableRecursive() -
isFromExterns
public final boolean isFromExterns() -
isClosureUnawareCode
public final boolean isClosureUnawareCode()Indicates that this node is for source that was written without any understanding of the compiler's various type-checking or optimization limitations, and should be optimized very cautiously by the compiler.This attribute is per source file, not per node / subset of an source file's AST.
-
getLength
public final int getLength() -
setLength
public final void setLength(int length) -
getLineno
public final int getLineno() -
getCharno
public final int getCharno() -
getLocation
-
getSourceOffset
public int getSourceOffset() -
getSourcePosition
public final int getSourcePosition() -
setLinenoCharno
Merges the line number and character number in one integer.The charno takes the first 12 bits and the line number takes the rest. If the charno is greater than (2^12)-1 it is adjusted to (2^12)-1
-
children
Deprecated.Return an iterable object that iterates over this node's children. The iterator does not support the optional operationIterator.remove().To iterate over a node's children, one can write
Node n = ...; for (Node child : n.children()) { ...NOTE: Do not use 'children' for recursive descent of the AST. The overhead of using iterators rather then getFirstChild()/getNext() is very significant. We have deprecated it as it is easy to misuse. -
getParent
-
hasParent
public final boolean hasParent() -
getGrandparent
-
getAncestor
Gets the ancestor node relative to this.- Parameters:
level- 0 = this, 1 = the parent, etc.
-
isDescendantOf
Is this Node the same asnodeor a descendant ofnode? -
isOnlyChildOf
-
isFirstChildOf
-
isSecondChildOf
-
getAncestors
Iterates all of the node's ancestors excluding itself. -
hasOneChild
public final boolean hasOneChild()Check for one child more efficiently than by iterating over all the children as is done with Node.getChildCount().- Returns:
- Whether the node has exactly one child.
-
hasTwoChildren
public final boolean hasTwoChildren()Check for two children more efficiently thangetChildCount() == 2- Returns:
- Whether the node has exactly two children.
-
hasZeroOrOneChild
public final boolean hasZeroOrOneChild()Check for zero or one child more efficiently than by iterating over all the children as is done with Node.getChildCount().- Returns:
- Whether the node has no children or exactly one child.
-
hasMoreThanOneChild
public final boolean hasMoreThanOneChild()Check for more than one child more efficiently than by iterating over all the children as is done with Node.getChildCount().- Returns:
- Whether the node more than one child.
-
hasXChildren
public final boolean hasXChildren(int x) Check for has exactly the number of specified children.- Returns:
- Whether the node has exactly the number of children specified.
-
getChildCount
public final int getChildCount() -
hasChild
-
isEquivalentToShallow
Checks equivalence without going into child nodes -
isEquivalentWithSideEffectsTo
Returns true if this node is equivalent semantically to another including side effects. -
isEquivalentWithSideEffectsToShallow
Returns true if this node is equivalent semantically to another including side effects. -
isEquivalentToTyped
Returns true if this node is equivalent semantically to another and the types are equivalent. -
isEquivalentTo
Returns true if this node is equivalent semantically to another -
isEquivalentTo
public boolean isEquivalentTo(Node node, boolean compareType, boolean recurse, boolean jsDoc, boolean sideEffect) Returns whether this node is equivalent semantically to the provided node.- Parameters:
compareType- Whether to compare the JSTypes of the nodes.recurse- Whether to compare the children of the current node. If not, only the count of the children are compared.jsDoc- Whether to check that the JsDoc of the nodes are equivalent.sideEffect- Whether to check that the side-effect flags of the nodes are equivalent.
-
getQualifiedName
This function takes a set of GETPROP nodes and produces a string that is each property separated by dots. If the node ultimately under the left sub-tree is not a simple name, this is not a valid qualified name.- Returns:
- a null if this is not a qualified name, or a dot-separated string of the name and properties.
-
getQualifiedNameObject
-
getOriginalQualifiedName
Deprecated."original name" is poorly defined. See #getOriginalNameThis function takes a set of GETPROP nodes and produces a string that is each property separated by dots. If the node ultimately under the left sub-tree is not a simple name, this is not a valid qualified name. This method returns the original name of each segment rather than the renamed version.- Returns:
- a null if this is not a qualified name, or a dot-separated string of the name and properties.
-
isQualifiedName
public final boolean isQualifiedName()Returns whether a node corresponds to a simple or a qualified name, such asxora.b.corthis.a. -
matchesName
Returns whether a node matches a simple name, such asx, returns false if this is not a NAME node. -
matchesName
Check that if two NAME node match, returns false if either node is not a NAME node. As a empty string is not considered a valid Name (it is an AST placeholder), empty strings are never considered to be matches. -
matchesQualifiedName
Returns whether a node matches a simple or a qualified name, such asxora.b.corthis.a. -
matchesQualifiedName
Returns whether a node matches a simple or a qualified name, such asxora.b.corthis.a. -
isUnscopedQualifiedName
public final boolean isUnscopedQualifiedName()Returns whether a node corresponds to a simple or a qualified name without a "this" reference, such asa.b.c, but notthis.a. -
isValidAssignmentTarget
public final boolean isValidAssignmentTarget() -
clone
-
cloneNode
Returns a detached clone of the Node, specifically excluding its children. -
cloneTree
Returns a detached clone of the Node and all its children. -
cloneTree
-
srcref
Copy the source info from `other` onto `this`. -
srcrefTree
For all Nodes in the subtree of `this`, copy the source info from `other`. -
srcrefIfMissing
Iff source info is not set on `this`, copy the source info from `other`. -
srcrefTreeIfMissing
For all Nodes in the subtree of `this`, iff source info is not set, copy the source info from `other`. -
getJSType
Returns the compiler inferred type on this node. Not to be confused withgetDeclaredTypeExpression()which returns the syntactically specified type. -
getJSTypeRequired
Returns the compiled inferred type on this node, or throws an NPE if there isn't one. -
setJSType
-
getColor
Returns the compiled inferred type on this node. Not to be confused withgetDeclaredTypeExpression()which returns the syntactically specified type. -
setColor
-
copyTypeFrom
Copies a nodes JSType or Color (if present) -
getJSDocInfo
Get theJSDocInfoattached to this node.- Returns:
- the information or
nullif no JSDoc is attached to this node
-
setJSDocInfo
Sets theJSDocInfoattached to this node. -
setChangeTime
public final void setChangeTime(int time) This node was last changed attime -
getChangeTime
public final int getChangeTime()Returns the time of the last change for this node -
setDeleted
public final void setDeleted(boolean deleted) -
isDeleted
public final boolean isDeleted() -
setTypedefTypeProp
If this node represents a typedef declaration, the associated JSType -
getTypedefTypeProp
If this node represents a typedef declaration, the associated JSType -
setUnusedParameter
public final void setUnusedParameter(boolean unused) Sets the value for isUnusedParameter() -
isUnusedParameter
public final boolean isUnusedParameter()Is this node an unused function parameter declaration?Set by RemoveUnusedVars
-
setShorthandProperty
public final void setShorthandProperty(boolean shorthand) Sets the isShorthandProperty annotation. -
isShorthandProperty
public final boolean isShorthandProperty()Whether this {x:x} property was originally parsed as {x}. -
isOptionalEs6Typed
public final boolean isOptionalEs6Typed()Returns whether this node is an optional node in the ES6 Typed syntax. -
setIsSyntheticBlock
public final void setIsSyntheticBlock(boolean val) Sets whether this is a synthetic block that should not be considered a real source block. -
isSyntheticBlock
public final boolean isSyntheticBlock()Returns whether this is a synthetic block that should not be considered a real source block. -
setIsSynthesizedUnfulfilledNameDeclaration
public final void setIsSynthesizedUnfulfilledNameDeclaration(boolean val) -
isSynthesizedUnfulfilledNameDeclaration
public final boolean isSynthesizedUnfulfilledNameDeclaration() -
setUseStrict
public final void setUseStrict(boolean x) Sets whether this node contained the "use strict" directive. -
isUseStrict
public final boolean isUseStrict()Returns whether this node contained the "use strict" directive. -
setIsAddedBlock
public final void setIsAddedBlock(boolean val) Sets whether this is an added block that should not be considered a real source block. Eg: In "if (true) x;", the "x;" is put under an added block in the AST. -
isAddedBlock
public final boolean isAddedBlock()Returns whether this is an added block that should not be considered a real source block. -
setStaticMember
public final void setStaticMember(boolean isStatic) Sets whether this node is a static member node. This method is meaningful only onToken.GETTER_DEF,Token.SETTER_DEForToken.MEMBER_FUNCTION_DEFnodes contained withinToken.CLASS. -
isStaticMember
public final boolean isStaticMember()Returns whether this node is a static member node. This method is meaningful only onToken.GETTER_DEF,Token.SETTER_DEForToken.MEMBER_FUNCTION_DEFnodes contained withinToken.CLASS. -
setIsGeneratorFunction
public final void setIsGeneratorFunction(boolean isGenerator) Sets whether this node is a generator node. This method is meaningful only onToken.FUNCTIONorToken.MEMBER_FUNCTION_DEFnodes. -
isGeneratorFunction
public final boolean isGeneratorFunction()Returns whether this node is a generator function node. -
setGeneratorMarker
public final void setGeneratorMarker(boolean isGeneratorMarker) Sets whether this node subtree contains YIELD nodes.It's used in the translation of generators.
-
isGeneratorMarker
public final boolean isGeneratorMarker()Returns whether this node was marked as containing YIELD nodes.It's used in the translation of generators.
-
setGeneratorSafe
public final void setGeneratorSafe(boolean isGeneratorSafe) Set the value for isGeneratorSafe() -
isGeneratorSafe
public final boolean isGeneratorSafe()Used when translating ES6 generators. If this returns true, this Node was generated by the compiler, and it is safe to copy this node to the transpiled output with no further changes. -
setIsOptionalChainStart
public final void setIsOptionalChainStart(boolean isOptionalChainStart) Sets whether this node is the start of an optional chain. This method is meaningful only onToken.OPTCHAIN_GETELEM,Token.OPTCHAIN_GETPROP,Token.OPTCHAIN_CALL -
isOptionalChainStart
public final boolean isOptionalChainStart()Returns whether this node is an optional chaining node. -
setIsArrowFunction
public final void setIsArrowFunction(boolean isArrow) Sets whether this node is a arrow function node. This method is meaningful only onToken.FUNCTION -
isArrowFunction
public final boolean isArrowFunction()Returns whether this node is a arrow function node. -
setIsAsyncFunction
public void setIsAsyncFunction(boolean isAsync) Sets whether this node is an async function node. This method is meaningful only onToken.FUNCTION -
isAsyncFunction
public final boolean isAsyncFunction()Returns whether this is an async function node. -
isAsyncGeneratorFunction
public final boolean isAsyncGeneratorFunction()Returns whether this is an async generator function node. -
setYieldAll
public final void setYieldAll(boolean isGenerator) Sets whether this node is a generator node. This method is meaningful only onToken.FUNCTIONorToken.MEMBER_FUNCTION_DEFnodes. -
isYieldAll
public final boolean isYieldAll()Returns whether this node is a generator node. This method is meaningful only onToken.FUNCTIONorToken.MEMBER_FUNCTION_DEFnodes. -
setTrailingComma
public final void setTrailingComma(boolean hasTrailingComma) Indicates that there was a trailing comma in this list -
hasTrailingComma
public final boolean hasTrailingComma()Returns true if there was a trailing comma in the orginal code -
setSideEffectFlags
public final void setSideEffectFlags(int flags) Marks this function or constructor call's side effect flags. This property is only meaningful forToken.CALLandToken.NEWnodes. -
setSideEffectFlags
-
getSideEffectFlags
public final int getSideEffectFlags()Returns the side effects flags for this node. -
isOnlyModifiesThisCall
public final boolean isOnlyModifiesThisCall()Returns whether the only side-effect is "modifies this" or there are no side effects. -
isOnlyModifiesArgumentsCall
public final boolean isOnlyModifiesArgumentsCall()Returns whether the only side-effect is "modifies arguments" or there are no side effects. -
isNoSideEffectsCall
public final boolean isNoSideEffectsCall()Returns true if this node is a function or constructor call that has no side effects. -
mayMutateArguments
public final boolean mayMutateArguments()Returns true if this is a new/call that may mutate its arguments. -
mayMutateGlobalStateOrThrow
public final boolean mayMutateGlobalStateOrThrow()Returns true if this is a new/call that may mutate global state or throw. -
isDeclaredConstantVar
public final boolean isDeclaredConstantVar()Returns whether this variable is declared as a constant.The compiler considers a variable to be declared if:
- it is declared with the
constkeyword, or - It is declared with a jsdoc
@constannotation, or - The current coding convention considers it to be a constant.
Only valid to call on a name node.
- it is declared with the
-
setDeclaredConstantVar
public final void setDeclaredConstantVar(boolean value) Sets this variable to be a declared constant.See
isDeclaredConstantVar()for the rules. -
isInferredConstantVar
public final boolean isInferredConstantVar()Returns whether this variable is inferred to be constant.The compiler infers a variable to be a constant if:
- It is assigned at its declaration site, and
- It is never reassigned during its lifetime, and
- It is not defined by an extern.
Only valid to call on a name node.
-
setInferredConstantVar
public final void setInferredConstantVar(boolean value) Sets this variable to be an inferred constant. *See
isInferredConstantVar()for the rules. -
isQuotedStringKey
public final boolean isQuotedStringKey() -
setQuotedStringKey
public final void setQuotedStringKey() -
isPrivateIdentifier
public final boolean isPrivateIdentifier() -
setPrivateIdentifier
public final void setPrivateIdentifier() -
isAdd
public final boolean isAdd()AST type check methods -
isSub
public final boolean isSub() -
isAnd
public final boolean isAnd() -
isAssignAnd
public final boolean isAssignAnd() -
isArrayLit
public final boolean isArrayLit() -
isArrayPattern
public final boolean isArrayPattern() -
isAssign
public final boolean isAssign() -
isAssignAdd
public final boolean isAssignAdd() -
isNormalBlock
public final boolean isNormalBlock() -
isBlock
public final boolean isBlock() -
isRoot
public final boolean isRoot() -
isAwait
public final boolean isAwait() -
isBigInt
public final boolean isBigInt() -
isBitNot
public final boolean isBitNot() -
isBreak
public final boolean isBreak() -
isCall
public final boolean isCall() -
isCase
public final boolean isCase() -
isCast
public final boolean isCast() -
isCatch
public final boolean isCatch() -
isClass
public final boolean isClass() -
isClassMembers
public final boolean isClassMembers() -
isComma
public final boolean isComma() -
isComputedProp
public final boolean isComputedProp() -
isContinue
public final boolean isContinue() -
isConst
public final boolean isConst() -
isDebugger
public final boolean isDebugger() -
isDec
public final boolean isDec() -
isDefaultCase
public final boolean isDefaultCase() -
isDefaultValue
public final boolean isDefaultValue() -
isDelProp
public final boolean isDelProp() -
isDestructuringLhs
public final boolean isDestructuringLhs() -
isDestructuringPattern
public final boolean isDestructuringPattern() -
isDo
public final boolean isDo() -
isEmpty
public final boolean isEmpty() -
isExponent
public final boolean isExponent() -
isAssignExponent
public final boolean isAssignExponent() -
isExport
public final boolean isExport() -
isExportSpec
public final boolean isExportSpec() -
isExportSpecs
public final boolean isExportSpecs() -
isExprResult
public final boolean isExprResult() -
isFalse
public final boolean isFalse() -
isVanillaFor
public final boolean isVanillaFor() -
isForIn
public final boolean isForIn() -
isForOf
public final boolean isForOf() -
isForAwaitOf
public final boolean isForAwaitOf() -
isFunction
public final boolean isFunction() -
isGetterDef
public final boolean isGetterDef() -
isGetElem
public final boolean isGetElem() -
isGetProp
public final boolean isGetProp() -
isHook
public final boolean isHook() -
isIf
public final boolean isIf() -
isImport
public final boolean isImport() -
isImportMeta
public final boolean isImportMeta() -
isImportStar
public final boolean isImportStar() -
isImportSpec
public final boolean isImportSpec() -
isImportSpecs
public final boolean isImportSpecs() -
isIn
public final boolean isIn() -
isInc
public final boolean isInc() -
isInstanceOf
public final boolean isInstanceOf() -
isInterface
public final boolean isInterface() -
isInterfaceMembers
public final boolean isInterfaceMembers() -
isRecordType
public final boolean isRecordType() -
isCallSignature
public final boolean isCallSignature() -
isIndexSignature
public final boolean isIndexSignature() -
isLabel
public final boolean isLabel() -
isLabelName
public final boolean isLabelName() -
isLet
public final boolean isLet() -
isMemberFunctionDef
public final boolean isMemberFunctionDef() -
isMemberVariableDef
public final boolean isMemberVariableDef() -
isMemberFieldDef
public final boolean isMemberFieldDef() -
isComputedFieldDef
public final boolean isComputedFieldDef() -
isModuleBody
public final boolean isModuleBody() -
isName
public final boolean isName() -
isNE
public final boolean isNE() -
isSHNE
public final boolean isSHNE() -
isEQ
public final boolean isEQ() -
isSHEQ
public final boolean isSHEQ() -
isNeg
public final boolean isNeg() -
isNew
public final boolean isNew() -
isNot
public final boolean isNot() -
isNull
public final boolean isNull() -
isNullishCoalesce
public final boolean isNullishCoalesce() -
isAssignNullishCoalesce
public final boolean isAssignNullishCoalesce() -
isNumber
public final boolean isNumber() -
isObjectLit
public final boolean isObjectLit() -
isObjectPattern
public final boolean isObjectPattern() -
isOptChainCall
public final boolean isOptChainCall() -
isOptChainGetElem
public final boolean isOptChainGetElem() -
isOptChainGetProp
public final boolean isOptChainGetProp() -
isOr
public final boolean isOr() -
isAssignOr
public final boolean isAssignOr() -
isParamList
public final boolean isParamList() -
isRegExp
public final boolean isRegExp() -
isRest
public final boolean isRest() -
isObjectRest
public final boolean isObjectRest() -
isReturn
public final boolean isReturn() -
isScript
public final boolean isScript() -
isSetterDef
public final boolean isSetterDef() -
isSpread
public final boolean isSpread() -
isString
public final boolean isString() -
isStringKey
public final boolean isStringKey() -
isStringLit
public final boolean isStringLit() -
isSuper
public final boolean isSuper() -
isSwitch
public final boolean isSwitch() -
isSwitchBody
public final boolean isSwitchBody() -
isTaggedTemplateLit
public final boolean isTaggedTemplateLit() -
isTemplateLit
public final boolean isTemplateLit() -
isTemplateLitString
public final boolean isTemplateLitString() -
isTemplateLitSub
public final boolean isTemplateLitSub() -
isThis
public final boolean isThis() -
isThrow
public final boolean isThrow() -
isTrue
public final boolean isTrue() -
isTry
public final boolean isTry() -
isTypeOf
public final boolean isTypeOf() -
isVar
public final boolean isVar() -
isVoid
public final boolean isVoid() -
isWhile
public final boolean isWhile() -
isWith
public final boolean isWith() -
isYield
public final boolean isYield() -
isDeclare
public final boolean isDeclare()
-