private class GlobalNamespace.BuildGlobalNamespace extends java.lang.Object implements NodeTraversal.Callback
Constructor and Description |
---|
BuildGlobalNamespace() |
Modifier and Type | Method and Description |
---|---|
void |
collect(JSModule module,
Scope scope,
Node n) |
(package private) GlobalNamespace.Ref.Type |
determineGetTypeForHookOrBooleanExpr(JSModule module,
Scope scope,
Node parent,
java.lang.String name)
Determines whether the result of a hook (x?y:z) or boolean expression
(x||y) or (x&&y) is assigned to a specific global name.
|
(package private) java.lang.String |
getNameForClassMembers(Node n)
Gets the fully qualified name corresponding to an class member function,
as long as it and its prefix property names are valid JavaScript
identifiers.
|
(package private) java.lang.String |
getNameForObjLitKey(Node n)
Gets the fully qualified name corresponding to an object literal key,
as long as it and its prefix property names are valid JavaScript
identifiers.
|
(package private) GlobalNamespace.Name |
getOrCreateName(java.lang.String name)
Gets a
GlobalNamespace.Name instance for a global name. |
(package private) GlobalNamespace.Name.Type |
getValueType(Node n)
Gets the type of a value or simple expression.
|
(package private) void |
handleGet(JSModule module,
Scope scope,
Node n,
Node parent,
java.lang.String name)
Updates our representation of the global namespace to reflect a read
of a global name.
|
(package private) void |
handleGet(JSModule module,
Scope scope,
Node n,
Node parent,
java.lang.String name,
GlobalNamespace.Ref.Type type)
Updates our representation of the global namespace to reflect a read
of a global name.
|
(package private) void |
handleSetFromGlobal(JSModule module,
Scope scope,
Node n,
Node parent,
java.lang.String name,
boolean isPropAssign,
GlobalNamespace.Name.Type type)
Updates our representation of the global namespace to reflect an
assignment to a global name in global scope.
|
(package private) void |
handleSetFromLocal(JSModule module,
Scope scope,
Node n,
Node parent,
java.lang.String name)
Updates our representation of the global namespace to reflect an
assignment to a global name in a local scope.
|
private boolean |
isClassDefiningCall(Node callNode) |
(package private) boolean |
isNestedAssign(Node parent)
Determines whether an assignment is nested (i.e.
|
private boolean |
isTypeDeclaration(Node n)
Determines whether a set operation is a constructor or enumeration
or interface declaration.
|
(package private) boolean |
maybeHandlePrototypePrefix(JSModule module,
Scope scope,
Node n,
Node parent,
java.lang.String name)
Updates our representation of the global namespace to reflect a read
of a global name's longest prefix before the "prototype" property if the
name includes the "prototype" property.
|
boolean |
shouldTraverse(NodeTraversal t,
Node n,
Node parent)
Collect the references in pre-order.
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
public void visit(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in postorder (after its children have been visited).
A node is visited only if all its parents should be traversed
(NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
).
Implementations can have side effects (e.g. modifying the parse tree).
visit
in interface NodeTraversal.Callback
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
shouldTraverse
in interface NodeTraversal.Callback
java.lang.String getNameForObjLitKey(Node n)
n
representing "z" in any of
the following expressions, the result would be "w.x.y.z":
var w = {x: {y: {z: 0}}};
w.x = {y: {z: 0}};
w.x.y = {'a': 0, 'z': 0};
n
- A child of an OBJLIT noden
doesn't correspond to the
key of an object literal that can be namedjava.lang.String getNameForClassMembers(Node n)
n
representing "y" in any of
the following expressions, the result would be "x.y":
class x{y(){}};
var x = class{y(){}};
var x; x = class{y(){}};
n
- A child of an CLASS_MEMBERS noden
doesn't correspond to
a class member function that can be namedGlobalNamespace.Name.Type getValueType(Node n)
n
- An r-value in an assignment or variable declaration (not null)GlobalNamespace.Name.Type
void handleSetFromGlobal(JSModule module, Scope scope, Node n, Node parent, java.lang.String name, boolean isPropAssign, GlobalNamespace.Name.Type type)
module
- the current modulescope
- the current scopen
- The node currently being visitedparent
- n
's parentname
- The global name (e.g. "a" or "a.b.c.d")isPropAssign
- Whether this set corresponds to a property
assignment of the form a.b.c = ...;
type
- The type of the value that the name is being assignedprivate boolean isTypeDeclaration(Node n)
n
- The node that represents the name being setvoid handleSetFromLocal(JSModule module, Scope scope, Node n, Node parent, java.lang.String name)
module
- The current modulescope
- The current scopen
- The node currently being visitedparent
- n
's parentname
- The global name (e.g. "a" or "a.b.c.d")void handleGet(JSModule module, Scope scope, Node n, Node parent, java.lang.String name)
module
- The current modulescope
- The current scopen
- The node currently being visitedparent
- n
's parentname
- The global name (e.g. "a" or "a.b.c.d")private boolean isClassDefiningCall(Node callNode)
GlobalNamespace.Ref.Type determineGetTypeForHookOrBooleanExpr(JSModule module, Scope scope, Node parent, java.lang.String name)
module
- The current modulescope
- The current scopeparent
- The parent of the current node in the traversal. This node
should already be known to be a HOOK, AND, or OR node.name
- A name that is already known to be global in the current
scope (e.g. "a" or "a.b.c.d")GlobalNamespace.Ref.Type.DIRECT_GET
or
GlobalNamespace.Ref.Type.ALIASING_GET
void handleGet(JSModule module, Scope scope, Node n, Node parent, java.lang.String name, GlobalNamespace.Ref.Type type)
module
- The current modulescope
- The current scopen
- The node currently being visitedparent
- n
's parentname
- The global name (e.g. "a" or "a.b.c.d")type
- The reference typeboolean maybeHandlePrototypePrefix(JSModule module, Scope scope, Node n, Node parent, java.lang.String name)
module
- The current modulescope
- The current scopen
- The node currently being visitedparent
- n
's parentname
- The global name (e.g. "a" or "a.b.c.d")boolean isNestedAssign(Node parent)
parent
- The parent of the current traversal node (not null)GlobalNamespace.Name getOrCreateName(java.lang.String name)
GlobalNamespace.Name
instance for a global name. Creates it if necessary,
as well as instances for any of its prefixes that are not yet defined.name
- A global name (e.g. "a", "a.b.c.d")GlobalNamespace.Name
instance for name