public class NameBasedDefinitionProvider extends java.lang.Object implements CompilerPass
It treats all variable writes as happening in the global scope and treats all objects as capable of having the same set of properties. The current implementation only handles definitions whose right hand side is an immutable value or function expression. All complex definitions are treated as unknowns.
This definition simply uses the variable name to determine a new definition site so potentially it could return multiple definition sites for a single variable. Although we could use the type system to make this more accurate, in practice after disambiguate properties has run, names are unique enough that this works well enough to accept the performance gain.
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowComplexFunctionDefs |
protected AbstractCompiler |
compiler |
protected java.util.Set<Node> |
definitionNodes |
protected com.google.common.collect.Multimap<java.lang.String,com.google.javascript.jscomp.DefinitionsRemover.Definition> |
definitionsByName |
protected java.util.Map<Node,com.google.javascript.jscomp.DefinitionSite> |
definitionSitesByDefinitionSiteNode |
protected com.google.common.collect.Multimap<Node,com.google.javascript.jscomp.DefinitionSite> |
definitionSitesByScopeNode |
protected boolean |
hasProcessBeenRun |
Constructor and Description |
---|
NameBasedDefinitionProvider(AbstractCompiler compiler,
boolean allowComplexFunctionDefs) |
Modifier and Type | Method and Description |
---|---|
com.google.javascript.jscomp.DefinitionSite |
getDefinitionForFunction(Node function) |
java.util.Collection<com.google.javascript.jscomp.DefinitionSite> |
getDefinitionSites()
Returns the collection of definition sites found during traversal.
|
java.util.Collection<com.google.javascript.jscomp.DefinitionsRemover.Definition> |
getDefinitionsReferencedAt(Node useSiteNode)
Returns a collection of definitions that characterize the possible values of a variable or
property.
|
static java.lang.String |
getSimplifiedName(Node node)
Extract a name from a node.
|
void |
process(Node externs,
Node source)
Process the JS with root node root.
|
void |
rebuildScopeRoots(java.util.List<Node> changedScopeRoots,
java.util.List<Node> deletedScopeRoots) |
protected final AbstractCompiler compiler
protected final com.google.common.collect.Multimap<java.lang.String,com.google.javascript.jscomp.DefinitionsRemover.Definition> definitionsByName
protected final java.util.Map<Node,com.google.javascript.jscomp.DefinitionSite> definitionSitesByDefinitionSiteNode
protected final com.google.common.collect.Multimap<Node,com.google.javascript.jscomp.DefinitionSite> definitionSitesByScopeNode
protected final java.util.Set<Node> definitionNodes
protected final boolean allowComplexFunctionDefs
protected boolean hasProcessBeenRun
public NameBasedDefinitionProvider(AbstractCompiler compiler, boolean allowComplexFunctionDefs)
public void process(Node externs, Node source)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treesource
- Top of JS treepublic void rebuildScopeRoots(java.util.List<Node> changedScopeRoots, java.util.List<Node> deletedScopeRoots)
public java.util.Collection<com.google.javascript.jscomp.DefinitionsRemover.Definition> getDefinitionsReferencedAt(Node useSiteNode)
@Nullable public static java.lang.String getSimplifiedName(Node node)
TODO(user) revisit. it would be helpful to at least use fully qualified names in the case of
namespaces. Might not matter as much if this pass runs after CollapseProperties
.
public java.util.Collection<com.google.javascript.jscomp.DefinitionSite> getDefinitionSites()
public com.google.javascript.jscomp.DefinitionSite getDefinitionForFunction(Node function)
Copyright © 2009-2017 Google. All Rights Reserved.