Class VarNode

All Implemented Interfaces:
Assignment<IdentNode>, Terminal, Cloneable

public final class VarNode extends Statement implements Assignment<IdentNode>
Node represents a var/let declaration.
  • Field Details

    • IS_LET

      public static final int IS_LET
      Flag for ES6 LET declaration
      See Also:
    • IS_CONST

      public static final int IS_CONST
      Flag for ES6 CONST declaration
      See Also:
    • IS_LAST_FUNCTION_DECLARATION

      public static final int IS_LAST_FUNCTION_DECLARATION
      Flag that determines if this is the last function declaration in a function This is used to micro optimize the placement of return value assignments for a program node
      See Also:
    • IS_EXPORT

      public static final int IS_EXPORT
      Flag synthetic export var node
      See Also:
    • IS_DESTRUCTURING

      public static final int IS_DESTRUCTURING
      Flag synthetic destructuring var node
      See Also:
    • IS_ANNEXB_BLOCK_TO_FUNCTION_TRANSFER

      public static final int IS_ANNEXB_BLOCK_TO_FUNCTION_TRANSFER
      Block-scope function declarations are hoisted into the front of the block and later (when the corresponding function declaration is evaluated at its original position) transferred into the function scope. This flag corresponds to this transfer.
      See Also:
  • Constructor Details

    • VarNode

      public VarNode(int lineNumber, long token, int finish, IdentNode name, Expression init)
      Constructor
      Parameters:
      lineNumber - line number
      token - token
      finish - finish
      name - name of variable
      init - init node or null if just a declaration
    • VarNode

      public VarNode(int lineNumber, long token, int finish, IdentNode name, Expression init, int flags)
      Constructor
      Parameters:
      lineNumber - line number
      token - token
      finish - finish
      name - name of variable
      init - init node or null if just a declaration
      flags - flags
    • VarNode

      public VarNode(int lineNumber, long token, int sourceOrder, int finish, IdentNode name, Expression init, int flags)
      Constructor
      Parameters:
      lineNumber - line number
      token - token
      sourceOrder - source order
      finish - finish
      name - name of variable
      init - init node or null if just a declaration
      flags - flags
    • VarNode

      public VarNode(int lineNumber, long token, int sourceOrder, int start, int finish, IdentNode name, Expression init, int flags)
      Constructor
      Parameters:
      lineNumber - line number
      token - token
      sourceOrder - source order
      start - start
      finish - finish
      name - name of variable
      init - init node or null if just a declaration
      flags - flags
  • Method Details

    • getSourceOrder

      public int getSourceOrder()
      Description copied from class: Node
      Integer to sort nodes in source order. This order is used by parser API to sort statements in correct order. By default, this is the start position of this node.
      Overrides:
      getSourceOrder in class Node
      Returns:
      int code to sort this node.
    • isAssignment

      public boolean isAssignment()
      Description copied from class: Node
      Is this an assignment node - for example a var node with an init or a binary node that writes to a destination
      Overrides:
      isAssignment in class Node
      Returns:
      true if assignment
    • getAssignmentDest

      public IdentNode getAssignmentDest()
      Description copied from interface: Assignment
      Get assignment destination.
      Specified by:
      getAssignmentDest in interface Assignment<IdentNode>
      Returns:
      the assignment destination node
    • getAssignmentSource

      public Expression getAssignmentSource()
      Description copied from interface: Assignment
      Get the assignment source.
      Specified by:
      getAssignmentSource in interface Assignment<IdentNode>
      Returns:
      the assignment source node
    • isBlockScoped

      public boolean isBlockScoped()
      Is this a VAR node block scoped? This returns true for ECMAScript 6 LET and CONST nodes.
      Returns:
      true if an ES6 LET or CONST node
    • isLet

      public boolean isLet()
      Is this an ECMAScript 6 LET node?
      Returns:
      true if LET node
    • isConst

      public boolean isConst()
      Is this an ECMAScript 6 CONST node?
      Returns:
      true if CONST node
    • getSymbolFlags

      public int getSymbolFlags()
      Return the flags to use for symbols for this declaration.
      Returns:
      the symbol flags
    • hasInit

      public boolean hasInit()
      Does this variable declaration have an init value
      Returns:
      true if an init exists, false otherwise
    • accept

      public Node accept(NodeVisitor<? extends LexicalContext> visitor)
      Assist in IR navigation.
      Specified by:
      accept in class Node
      Parameters:
      visitor - IR navigating visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • accept

      public <R> R accept(TranslatorNodeVisitor<? extends LexicalContext, R> visitor)
      Description copied from class: Node
      Provides a means to navigate the IR.
      Specified by:
      accept in class Node
      Parameters:
      visitor - Node visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • toString

      public void toString(StringBuilder sb, boolean printType)
      Description copied from class: Node
      Print logic that decides whether to show the optimistic type or not - for example it should not be printed after just parse, when it hasn't been computed, or has been set to a trivially provable value
      Specified by:
      toString in class Node
      Parameters:
      sb - string builder
      printType - print type?
    • getInit

      public Expression getInit()
      If this is an assignment of the form var x = init;, get the init part.
      Returns:
      the expression to initialize the variable to, null if just a declaration
    • getName

      public IdentNode getName()
      Get the identifier for the variable
      Returns:
      IdentNode representing the variable being set or declared
    • getFlag

      public boolean getFlag(int flag)
      Check if a flag is set for this var node
      Parameters:
      flag - flag
      Returns:
      true if flag is set
    • setFlag

      public VarNode setFlag(int flag)
      Set a flag for this var node
      Parameters:
      flag - flag
      Returns:
      new node if flags changed, same otherwise
    • isHoistableDeclaration

      public boolean isHoistableDeclaration()
      Returns true if this is a HoistableDeclaration (i.e., FunctionDeclaration, GeneratorDeclaration, AsyncFunctionDeclaration, or AsyncGeneratorDeclaration).
      Returns:
      true if this is a HoistableDeclaration
    • isFunctionDeclaration

      public boolean isFunctionDeclaration()
      Returns true if this is a FunctionDeclaration.
      Returns:
      true if this is a FunctionDeclaration
    • isExport

      public boolean isExport()
    • isDestructuring

      public boolean isDestructuring()
    • isClassDeclaration

      public boolean isClassDeclaration()
      Returns true if this is a Class declaration.
      Returns:
      true if this is a Class declaration.