private class ProcessCommonJSModules.ProcessCommonJsModulesCallback extends NodeTraversal.AbstractPostOrderCallback
Modifier and Type | Field and Description |
---|---|
private boolean |
allowFullRewrite |
private java.util.List<Node> |
exportRefs |
private java.util.List<Node> |
moduleExportRefs |
(package private) com.google.common.collect.Multiset<java.lang.String> |
propertyExportRefCount |
private int |
scriptNodeCount |
Constructor and Description |
---|
ProcessCommonJsModulesCallback(boolean allowFullRewrite) |
Modifier and Type | Method and Description |
---|---|
private void |
addConstToObjLitKeys(Node n)
Add an @const annotation to each key of an object literal
|
private Node |
getBaseQualifiedNameNode(Node n) |
private Node |
getCurrentScriptNode(Node n)
Returns next script node in parents.
|
private boolean |
hasExportLValues()
Recognize the opposite of export pattern [2] (see above).
|
private boolean |
hasOneTopLevelModuleExportAssign()
Recognize export pattern [1] (see above).
|
private boolean |
isTopLevelAssignLhs(Node n) |
private void |
maybeAddReferenceCount(Node n) |
private void |
processExports(Node script,
java.lang.String moduleName)
Process all references to module.exports and exports.
|
private void |
replaceIfStatementWithBranch(Node ifStatement,
Node branch) |
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
private void |
visitAMDIfStatement(Node n)
Rewrites AMD part of UMD pattern by removing the if-condition and the
then-branch and adds the else-branch directly to the current parent node.
|
private void |
visitCommonJSIfStatement(Node n)
Rewrites CommonJS part of UMD pattern by removing the if-condition and the
else-branch and adds the then-branch directly to the current parent node.
|
private void |
visitRequireCall(NodeTraversal t,
Node require,
Node parent)
Visit require calls.
|
private void |
visitScript(NodeTraversal t,
Node script)
Emit goog.provide and add suffix to all global vars to avoid conflicts
with other modules.
|
shouldTraverse
private int scriptNodeCount
private java.util.List<Node> moduleExportRefs
private java.util.List<Node> exportRefs
com.google.common.collect.Multiset<java.lang.String> propertyExportRefCount
private final boolean allowFullRewrite
public ProcessCommonJsModulesCallback(boolean allowFullRewrite)
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).
private void maybeAddReferenceCount(Node n)
private void visitRequireCall(NodeTraversal t, Node require, Node parent)
private void visitScript(NodeTraversal t, Node script)
private void visitCommonJSIfStatement(Node n)
private void visitAMDIfStatement(Node n)
private void replaceIfStatementWithBranch(Node ifStatement, Node branch)
private void processExports(Node script, java.lang.String moduleName)
private void addConstToObjLitKeys(Node n)
private boolean hasOneTopLevelModuleExportAssign()
private boolean isTopLevelAssignLhs(Node n)
private boolean hasExportLValues()