FunctionNode

open class FunctionNode(pos: Int = -1, name: Name? = null) : ScriptNode

A JavaScript function declaration or expression. Node type is Token.FUNCTION.

FunctionDeclaration : function Identifier ( FormalParameterList? ) { FunctionBody }
FunctionExpression : function Identifier? ( FormalParameterList? ) { FunctionBody }

JavaScript 1.8 also allows a "function closure" of the form function ([params]) Expression. Such a node has no body but does have an expression.

Constructors

Link copied to clipboard
constructor(pos: Int = -1, name: Name? = null)

Types

Link copied to clipboard
object Companion
Link copied to clipboard

How the function was written: a plain function, an accessor, or a method.

Properties

Link copied to clipboard

The absolute document position, computed by adding this node's relative position to the relative positions of all its parents.

Link copied to clipboard

The AstRoot at the top of this node's parent chain, or null if there is none.

Link copied to clipboard

Base (starting) line number for this script or function. Setting it is a one-time operation and fails if the line number is already set.

Link copied to clipboard
open var bigInt: KBigInt?

Only valid when type == Token.BIGINT.

Link copied to clipboard

The function body: normally a Block, or a plain AstNode for a function closure. Null only when the AST is malformed.

Link copied to clipboard

The scopes whose parent is this scope, or null if there are none.

Link copied to clipboard
open val column: Int

The column where this node is defined in source, one-based. -1 means it was never initialized. May be overridden by subclasses.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val defaultParams: List<Any?>?
Link copied to clipboard
Link copied to clipboard
open override val destructuringRvalues: List<Array<Node>>?
Link copied to clipboard

Only valid when type == Token.NUMBER.

Link copied to clipboard

The innermost enclosing function, or null. The search begins with the parent.

Link copied to clipboard

The innermost enclosing Scope, or null. The search begins with the parent. This is not the same as the defining scope for a Name.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Sets the function name and reparents it to this node. Null means an anonymous function.

Link copied to clipboard
Link copied to clipboard

The function type: statement, expression, or expression statement.

Link copied to clipboard

IR block for default parameter init in generators.

Link copied to clipboard
open override var hasRestParameter: Boolean
Link copied to clipboard

Comments on the same line as the statement, for example the trailing comment in if (x == 2) // note.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override var isShorthand: Boolean
Link copied to clipboard

The JsDoc comment string attached to this node, or null.

Link copied to clipboard

The JsDoc Comment attached to this node, or null.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var length: Int

Number of characters spanned by this node in the source text.

Link copied to clipboard
open override val lineno: Int

The line number recorded for this node. If none was recorded, searches the parent chain and returns -1 when nothing is found.

Link copied to clipboard
Link copied to clipboard
var loop: Jump?
Link copied to clipboard
var lp: Int

Left paren position, -1 if missing.

Link copied to clipboard

Rhino supports a nonstandard extension letting you write function a.b.c(arg) {...}, rewritten at codegen time to a.b.c = function(arg) {...}. When the parser sees an expression other than a simple Name where the function name belongs, it records that expression here. Enabled by the allowMemberExprAsFunctionName compiler option.

Link copied to clipboard

The function name as a string, or "" if anonymous.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Number of parameters, counted as Token.LP symbols arrive.

Link copied to clipboard

The parameter list, or an empty list if there are no parameters.

Link copied to clipboard

The node parent, or null. Setting it adjusts this node's start position to be relative to the new parent.

Link copied to clipboard
Link copied to clipboard

Relative position in the parent.

Link copied to clipboard

The raw source, or null if it was not recorded. Used by the code generator.

Link copied to clipboard

End offset of the raw source. Only valid when rawSource is non-null.

Link copied to clipboard

Start offset of the raw source. Only valid when rawSource is non-null.

Link copied to clipboard
Link copied to clipboard

True when this function requires an Ecma-262 Activation object. The activation is expensive to create, so the interpreter uses a plain call frame when it can. A lexical closure is one of several situations that force one.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var rp: Int

Right paren position, -1 if missing.

Link copied to clipboard
open var scope: Scope?

Only valid when the node has String context.

Link copied to clipboard

The URI, path or descriptive text naming the origin of this script's source.

Link copied to clipboard

A copy of the child list, with each child cast to an AstNode. Throws once the code generator has begun the tree transformation and non-AstNode children appear.

Link copied to clipboard

Only valid when the node has String context.

Link copied to clipboard

Every symbol in this script or function, in declaration order.

Link copied to clipboard

Insertion-ordered so that iteration follows declaration order.

Link copied to clipboard
var target: Node?
Link copied to clipboard
Link copied to clipboard

The current script or function scope.

Link copied to clipboard
open var type: Int

The node type, e.g. Token.NAME.

Functions

Link copied to clipboard
fun addChild(kid: AstNode)

Adds a child to the end of the block. Sets the child's parent to this node, rewrites the child position to be relative, and grows this node to include the child.

Link copied to clipboard
fun addChildAfter(newChild: Node, node: Node)

Add newChild after node.

Link copied to clipboard
fun addChildBefore(newChild: Node, node: Node)

Add newChild before node.

Link copied to clipboard
fun addChildrenToBack(children: Node)
Link copied to clipboard
fun addChildrenToFront(children: Node)
Link copied to clipboard
fun addChildScope(child: Scope)

Adds a scope to the child list and sets the child's parent scope to this scope.

Link copied to clipboard
fun addChildToBack(child: Node)
Link copied to clipboard
fun addChildToFront(child: Node)
Link copied to clipboard
open override fun addFunction(fnNode: FunctionNode): Int

Adds a FunctionNode to the functions table for codegen. Does not set the parent of the node.

Link copied to clipboard
fun addLiveLocals(node: Node, locals: IntArray)
Link copied to clipboard
fun addParam(param: AstNode)

Adds a parameter and reparents it to this node.

Link copied to clipboard

Called by IRFactory to add a RegExp to the regexp table.

Link copied to clipboard
Link copied to clipboard
fun addTemplateLiteral(templateLiteral: TemplateLiteral)

Called by IRFactory to add a template literal to the table.

Link copied to clipboard

Used only for code generation.

Link copied to clipboard
open operator override fun compareTo(other: AstNode): Int

Sorts by start position, then by length, then arbitrarily by hash code. Lets Comment and error nodes be mixed into a sorted collection of other AST nodes.

Link copied to clipboard
open fun debugPrint(): String

A debugging representation of the parse tree starting at this node. Each line reads abs-pos name position length [identifier].

Link copied to clipboard
fun depth(): Int

The depth of this node. The root is depth 0, its children depth 1, and so on.

Link copied to clipboard
fun flattenSymbolTable(flattenAllTables: Boolean)

Assigns every symbol a unique integer index and builds the name and constness arrays that can be indexed by it.

Link copied to clipboard
fun getChildBefore(child: Node): Node?
Link copied to clipboard

The scope in which name is defined: this scope, one of its parents, or null when the name is not defined anywhere in this scope chain.

Link copied to clipboard
fun getExistingIntProp(propType: Int): Int
Link copied to clipboard
Link copied to clipboard
fun getIndexForNameNode(nameNode: Node): Int
Link copied to clipboard
fun getIntProp(propType: Int, defaultValue: Int): Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun getProp(propType: Int): Any?
Link copied to clipboard
fun getRegexpFlags(index: Int): String?
Link copied to clipboard
fun getRegexpString(index: Int): String?
Link copied to clipboard
fun getSymbol(name: String): Symbol?

Looks up a symbol in this scope, or null if it is not there.

Link copied to clipboard
Link copied to clipboard

Checks that every return usage in a function body is consistent with strict mode. See the END_* flags for what the analysis reports.

Link copied to clipboard
open override fun hasSideEffects(): Boolean
Link copied to clipboard
fun isParam(node: AstNode): Boolean

True when node is a parameter of this function. Lets a traversal tell the function name node apart from the parameter nodes.

Link copied to clipboard
open operator override fun iterator(): MutableIterator<Node>
Link copied to clipboard
fun labelId(): Int
fun labelId(labelId: Int)
Link copied to clipboard
fun makeIndent(indent: Int): String

Constructs an indentation string of indent steps.

Link copied to clipboard
fun putDefaultParams(left: Any?, right: Any?)
Link copied to clipboard
open override fun putDestructuringRvalues(left: Node, right: Node)
Link copied to clipboard
fun putIntProp(propType: Int, prop: Int)
Link copied to clipboard
fun putProp(propType: Int, prop: Any?)
Link copied to clipboard
fun putSymbol(symbol: Symbol)

Enters a symbol into this scope.

Link copied to clipboard
fun removeChild(child: Node)
Link copied to clipboard
Link copied to clipboard
fun removeProp(propType: Int)
Link copied to clipboard
fun replaceChild(child: Node, newChild: Node)
Link copied to clipboard
fun replaceChildAfter(prevChild: Node, newChild: Node)
Link copied to clipboard
fun replaceWith(newScope: Scope)

Used by the parser. Repoints this scope's child scopes at newScope and copies this scope's symbols into it.

Link copied to clipboard

Recursively unlabel every TARGET or YIELD node in the tree. Used only for inlining finally blocks where jsr instructions used to be.

Link copied to clipboard
fun setBounds(position: Int, end: Int)

Sets the start and end positions; the length becomes end - position.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun setLineColumnNumber(lineno: Int, column: Int)
Link copied to clipboard
fun setParams(params: List<AstNode>?)

Sets the parameter list and reparents every element. Null means no parameters.

Link copied to clipboard
fun setParens(lp: Int, rp: Int)

Sets both paren positions.

Link copied to clipboard
fun setRawSourceBounds(start: Int, end: Int)

Used by the code generator.

Link copied to clipboard
fun setRelative(parentPosition: Int)

Makes this node's position relative to a parent. The current position is assumed to be absolute and is decremented by parentPosition.

Link copied to clipboard

A short, descriptive name for the node, such as "ArrayComprehension".

Link copied to clipboard
open override fun toSource(depth: Int = 0): String

Jumps are only used during code generation and cannot render source.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
Link copied to clipboard
open override fun visit(visitor: NodeVisitor)

Visits this node, the function name if present, the parameters and the body. A member-expr node is visited last.