class VarCheck extends NodeTraversal.AbstractPostOrderCallback implements HotSwapCompilerPass
Modifier and Type | Class and Description |
---|---|
private class |
VarCheck.NameRefInExternsCheck
A check for name references in the externs inputs.
|
private class |
VarCheck.RedeclarationCheckHandler
The handler for duplicate declarations.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ARGUMENTS |
private AbstractCompiler |
compiler |
(package private) static DiagnosticType |
LET_CONST_MULTIPLY_DECLARED_ERROR |
(package private) static DiagnosticType |
MISSING_MODULE_DEP_ERROR |
(package private) static DiagnosticType |
NAME_REFERENCE_IN_EXTERNS_ERROR |
private boolean |
sanityCheck |
(package private) static DiagnosticType |
STRICT_MODULE_DEP_ERROR |
private boolean |
strictExternCheck |
(package private) static DiagnosticType |
UNDEFINED_EXTERN_VAR_ERROR |
(package private) static DiagnosticType |
UNDEFINED_VAR_ERROR |
(package private) static DiagnosticType |
VAR_ARGUMENTS_SHADOWED_ERROR |
(package private) static DiagnosticType |
VAR_MULTIPLY_DECLARED_ERROR |
private java.util.Set<java.lang.String> |
varsToDeclareInExterns |
(package private) static DiagnosticType |
VIOLATED_MODULE_DEP_ERROR |
Constructor and Description |
---|
VarCheck(AbstractCompiler compiler) |
VarCheck(AbstractCompiler compiler,
boolean sanityCheck) |
Modifier and Type | Method and Description |
---|---|
private ScopeCreator |
createScopeCreator()
Create a SyntacticScopeCreator.
|
private void |
createSynthesizedExternVar(java.lang.String varName)
Create a new variable in a synthetic script.
|
private Node |
getSynthesizedExternsRoot()
Lazily create a "new" externs root for undeclared variables.
|
(package private) static boolean |
hasDuplicateDeclarationSuppression(Node n,
Var origVar) |
void |
hotSwapScript(Node scriptRoot,
Node originalRoot)
Process the JS with root node root.
|
private static boolean |
isExternNamespace(Node n) |
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
shouldTraverse
static final DiagnosticType UNDEFINED_VAR_ERROR
static final DiagnosticType VIOLATED_MODULE_DEP_ERROR
static final DiagnosticType MISSING_MODULE_DEP_ERROR
static final DiagnosticType STRICT_MODULE_DEP_ERROR
static final DiagnosticType NAME_REFERENCE_IN_EXTERNS_ERROR
static final DiagnosticType UNDEFINED_EXTERN_VAR_ERROR
static final DiagnosticType VAR_MULTIPLY_DECLARED_ERROR
static final DiagnosticType VAR_ARGUMENTS_SHADOWED_ERROR
static final DiagnosticType LET_CONST_MULTIPLY_DECLARED_ERROR
private static final java.lang.String ARGUMENTS
private final java.util.Set<java.lang.String> varsToDeclareInExterns
private final AbstractCompiler compiler
private final boolean sanityCheck
private final boolean strictExternCheck
VarCheck(AbstractCompiler compiler)
VarCheck(AbstractCompiler compiler, boolean sanityCheck)
private ScopeCreator createScopeCreator()
VarCheck.RedeclarationCheckHandler
to check var redeclarations.public void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treepublic void hotSwapScript(Node scriptRoot, Node originalRoot)
HotSwapCompilerPass
hotSwapScript
in interface HotSwapCompilerPass
scriptRoot
- Root node corresponding to the file that is modified,
should be of type Token.SCRIPT
.originalRoot
- Root node corresponding to the original version of the
file that is modified. Should be of type token.SCRIPT
.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
private void createSynthesizedExternVar(java.lang.String varName)
static boolean hasDuplicateDeclarationSuppression(Node n, Var origVar)
n
- The name node to check.origVar
- The associated Var.private static boolean isExternNamespace(Node n)
private Node getSynthesizedExternsRoot()