class ProcessClosurePrimitives extends NodeTraversal.AbstractPostOrderCallback implements HotSwapCompilerPass
Modifier and Type | Class and Description |
---|---|
private class |
ProcessClosurePrimitives.ProvidedName
Information required to replace a goog.provide call later in the traversal.
|
private static class |
ProcessClosurePrimitives.UnrecognizedRequire
Information required to create a
MISSING_PROVIDE_ERROR warning. |
Constructor and Description |
---|
ProcessClosurePrimitives(AbstractCompiler compiler,
PreprocessorSymbolTable preprocessorSymbolTable,
CheckLevel requiresLevel,
boolean preserveGoogRequires) |
Modifier and Type | Method and Description |
---|---|
private boolean |
baseUsedInClass(Node n)
Verify if goog.base call is used in a class
|
private static Node |
getEnclosingDeclNameNode(Node n)
Returns the qualified name node of the function whose scope we're in,
or null if it cannot be found.
|
(package private) java.util.Set<java.lang.String> |
getExportedVariableNames() |
private void |
handleCandidateProvideDefinition(NodeTraversal t,
Node n,
Node parent)
Handles a candidate definition for a goog.provided name.
|
private void |
handleClosureDefinesValues(NodeTraversal t,
Node n) |
private void |
handleTypedefDefinition(NodeTraversal t,
Node n)
Handles a typedef definition for a goog.provided name.
|
void |
hotSwapScript(Node scriptRoot,
Node originalRoot)
Process the JS with root node root.
|
private static boolean |
isNamespacePlaceholder(Node n) |
(package private) static boolean |
isValidDefineValue(Node val) |
private void |
maybeAddStringNodeToSymbolTable(Node n)
The string in
n is a reference name. |
private void |
maybeAddToSymbolTable(Node n)
Add the given qualified name node to the symbol table.
|
private void |
maybeProcessClassBaseCall(NodeTraversal t,
Node n) |
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
private void |
processAddDependency(Node n,
Node parent)
Process a goog.addDependency() call and record any forward declarations.
|
private void |
processBaseClassCall(NodeTraversal t,
Node n)
Processes the base class call.
|
private void |
processDefineCall(NodeTraversal t,
Node n,
Node parent)
Handles a goog.define call.
|
private void |
processForwardDeclare(NodeTraversal t,
Node n,
Node parent)
Process a goog.forwardDeclare() call and record the specified forward
declaration.
|
private void |
processInheritsCall(Node n)
Processes the goog.inherits call.
|
private void |
processProvideCall(NodeTraversal t,
Node n,
Node parent)
Handles a goog.provide call.
|
private void |
processProvideFromPreviousPass(NodeTraversal t,
java.lang.String name,
Node parent)
Processes the output of processed-provide from a previous pass.
|
private void |
processRequireCall(NodeTraversal t,
Node n,
Node parent)
Handles a goog.require call.
|
private void |
processSetCssNameMapping(NodeTraversal t,
Node n,
Node parent)
Processes a call to goog.setCssNameMapping().
|
private void |
registerAnyProvidedPrefixes(java.lang.String ns,
Node node,
JSModule module)
Registers ProvidedNames for prefix namespaces if they haven't
already been defined.
|
private void |
replaceGoogDefines(Node n) |
private void |
reportBadBaseMethodUse(NodeTraversal t,
Node n,
java.lang.String className,
java.lang.String extraMessage)
Reports an incorrect use of super-method calling.
|
private void |
reportBadClosureCommonDefinesDefinition(NodeTraversal t,
Node n)
Reports an incorrect CLOSURE_DEFINES definition.
|
private void |
reportBadGoogBaseUse(NodeTraversal t,
Node n,
java.lang.String extraMessage)
Reports an incorrect use of super-method calling.
|
private boolean |
validPrimitiveCall(NodeTraversal t,
Node n) |
private boolean |
verifyDefine(NodeTraversal t,
Node expr,
Node methodName,
Node args)
Verifies that a provide method call has exactly one argument,
and that it's a string literal and that the contents of the string are
valid JS tokens.
|
private boolean |
verifyIsLast(NodeTraversal t,
Node methodName,
Node arg) |
private boolean |
verifyLastArgumentIsString(NodeTraversal t,
Node methodName,
Node arg)
Verifies that a method call has exactly one argument, and that it's a
string literal.
|
private boolean |
verifyNotNull(NodeTraversal t,
Node methodName,
Node arg) |
private boolean |
verifyOfType(NodeTraversal t,
Node methodName,
Node arg,
int desiredType) |
private boolean |
verifyProvide(NodeTraversal t,
Node methodName,
Node arg)
Verifies that a provide method call has exactly one argument,
and that it's a string literal and that the contents of the string are
valid JS tokens.
|
private boolean |
verifySetCssNameMapping(NodeTraversal t,
Node methodName,
Node firstArg)
Verifies that setCssNameMapping is called with the correct methods.
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
shouldTraverse
static final DiagnosticType NULL_ARGUMENT_ERROR
static final DiagnosticType EXPECTED_OBJECTLIT_ERROR
static final DiagnosticType EXPECTED_STRING_ERROR
static final DiagnosticType INVALID_ARGUMENT_ERROR
static final DiagnosticType INVALID_STYLE_ERROR
static final DiagnosticType TOO_MANY_ARGUMENTS_ERROR
static final DiagnosticType DUPLICATE_NAMESPACE_ERROR
static final DiagnosticType WEAK_NAMESPACE_TYPE
static final DiagnosticType CLASS_NAMESPACE_ERROR
static final DiagnosticType FUNCTION_NAMESPACE_ERROR
static final DiagnosticType MISSING_PROVIDE_ERROR
static final DiagnosticType LATE_PROVIDE_ERROR
static final DiagnosticType INVALID_PROVIDE_ERROR
static final DiagnosticType INVALID_DEFINE_NAME_ERROR
static final DiagnosticType MISSING_DEFINE_ANNOTATION
static final DiagnosticType XMODULE_REQUIRE_ERROR
static final DiagnosticType INVALID_CLOSURE_CALL_ERROR
static final DiagnosticType NON_STRING_PASSED_TO_SET_CSS_NAME_MAPPING_ERROR
static final DiagnosticType INVALID_CSS_RENAMING_MAP
static final DiagnosticType GOOG_BASE_CLASS_ERROR
static final DiagnosticType BASE_CLASS_ERROR
static final DiagnosticType CLOSURE_DEFINES_ERROR
static final DiagnosticType INVALID_FORWARD_DECLARE
static final DiagnosticType USE_OF_GOOG_BASE
static final java.lang.String GOOG
private final AbstractCompiler compiler
private final JSModuleGraph moduleGraph
private final java.util.Map<java.lang.String,ProcessClosurePrimitives.ProvidedName> providedNames
private final java.util.Set<java.lang.String> knownClosureSubclasses
private final java.util.List<ProcessClosurePrimitives.UnrecognizedRequire> unrecognizedRequires
private final java.util.Set<java.lang.String> exportedVariables
private final CheckLevel requiresLevel
private final PreprocessorSymbolTable preprocessorSymbolTable
private final java.util.List<Node> defineCalls
private final boolean preserveGoogRequires
private final java.util.List<Node> requiresToBeRemoved
ProcessClosurePrimitives(AbstractCompiler compiler, @Nullable PreprocessorSymbolTable preprocessorSymbolTable, CheckLevel requiresLevel, boolean preserveGoogRequires)
java.util.Set<java.lang.String> getExportedVariableNames()
public void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treeprivate void replaceGoogDefines(Node n)
n
- public 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 boolean validPrimitiveCall(NodeTraversal t, Node n)
private void handleClosureDefinesValues(NodeTraversal t, Node n)
static boolean isValidDefineValue(Node val)
private void processRequireCall(NodeTraversal t, Node n, Node parent)
private void processProvideCall(NodeTraversal t, Node n, Node parent)
private void processDefineCall(NodeTraversal t, Node n, Node parent)
private void handleTypedefDefinition(NodeTraversal t, Node n)
n
- EXPR_RESULT node.private void handleCandidateProvideDefinition(NodeTraversal t, Node n, Node parent)
private void processBaseClassCall(NodeTraversal t, Node n)
private void maybeProcessClassBaseCall(NodeTraversal t, Node n)
private void processInheritsCall(Node n)
private static Node getEnclosingDeclNameNode(Node n)
private boolean baseUsedInClass(Node n)
private void reportBadGoogBaseUse(NodeTraversal t, Node n, java.lang.String extraMessage)
private void reportBadBaseMethodUse(NodeTraversal t, Node n, java.lang.String className, java.lang.String extraMessage)
private void reportBadClosureCommonDefinesDefinition(NodeTraversal t, Node n)
private void processProvideFromPreviousPass(NodeTraversal t, java.lang.String name, Node parent)
private void processSetCssNameMapping(NodeTraversal t, Node n, Node parent)
visit(NodeTraversal, Node, Node)
private boolean verifyProvide(NodeTraversal t, Node methodName, Node arg)
private boolean verifyDefine(NodeTraversal t, Node expr, Node methodName, Node args)
private void processAddDependency(Node n, Node parent)
private void processForwardDeclare(NodeTraversal t, Node n, Node parent)
private boolean verifyLastArgumentIsString(NodeTraversal t, Node methodName, Node arg)
private boolean verifyNotNull(NodeTraversal t, Node methodName, Node arg)
private boolean verifyOfType(NodeTraversal t, Node methodName, Node arg, int desiredType)
private boolean verifyIsLast(NodeTraversal t, Node methodName, Node arg)
private boolean verifySetCssNameMapping(NodeTraversal t, Node methodName, Node firstArg)
private void registerAnyProvidedPrefixes(java.lang.String ns, Node node, JSModule module)
ns
- The namespace whose prefixes may need to be provided.node
- The EXPR of the provide call.module
- The current module.private static boolean isNamespacePlaceholder(Node n)
private void maybeAddStringNodeToSymbolTable(Node n)
n
is a reference name. Create a synthetic
node for it with all the proper source info, and add it to the symbol
table.private void maybeAddToSymbolTable(Node n)