public class NameBasedDefinitionProvider extends Object implements CompilerPass
DefinitionProvider
.
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 Map<Node,com.google.javascript.jscomp.DefinitionSite> |
definitionNodeByDefinitionSite |
protected Set<Node> |
definitionNodes |
protected boolean |
hasProcessBeenRun |
protected com.google.common.collect.Multimap<String,com.google.javascript.jscomp.DefinitionsRemover.Definition> |
nameDefinitionMultimap |
Constructor and Description |
---|
NameBasedDefinitionProvider(AbstractCompiler compiler,
boolean allowComplexFunctionDefs) |
Modifier and Type | Method and Description |
---|---|
com.google.javascript.jscomp.DefinitionSite |
getDefinitionForFunction(Node function) |
Collection<com.google.javascript.jscomp.DefinitionSite> |
getDefinitionSites()
Returns the collection of definition sites found during traversal.
|
Collection<com.google.javascript.jscomp.DefinitionsRemover.Definition> |
getDefinitionsReferencedAt(Node useSite)
Returns a collection of definitions that characterize the
possible values of a variable or property.
|
protected static String |
getSimplifiedName(Node node)
Extract a name from a node.
|
void |
process(Node externs,
Node source)
Process the JS with root node root.
|
protected final com.google.common.collect.Multimap<String,com.google.javascript.jscomp.DefinitionsRemover.Definition> nameDefinitionMultimap
protected final Map<Node,com.google.javascript.jscomp.DefinitionSite> definitionNodeByDefinitionSite
protected final AbstractCompiler compiler
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 Collection<com.google.javascript.jscomp.DefinitionsRemover.Definition> getDefinitionsReferencedAt(Node useSite)
protected static 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 Collection<com.google.javascript.jscomp.DefinitionSite> getDefinitionSites()
public com.google.javascript.jscomp.DefinitionSite getDefinitionForFunction(Node function)
Copyright © 2009-2017 Google. All Rights Reserved.