public final class ProcessCommonJSModules extends NodeTraversal.AbstractPreOrderCallback implements CompilerPass
Modifier and Type | Field and Description |
---|---|
static DiagnosticType |
SUSPICIOUS_EXPORTS_ASSIGNMENT |
static DiagnosticType |
UNKNOWN_REQUIRE_ENSURE |
Constructor and Description |
---|
ProcessCommonJSModules(AbstractCompiler compiler)
Creates a new ProcessCommonJSModules instance which can be used to rewrite CommonJS modules to
a concatenable form.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getBasePropertyImport(java.lang.String moduleName) |
java.lang.String |
getCommonJsImportPath(Node requireCall) |
static java.lang.String |
getCommonJsImportPath(Node requireCall,
ModuleLoader.ResolutionMode resolutionMode) |
static java.lang.String |
getModuleName(CompilerInput input) |
static java.lang.String |
getModuleName(ModuleLoader.ModulePath input) |
static boolean |
isCommonJsDynamicImportCallback(Node n,
ModuleLoader.ResolutionMode resolutionMode)
Recognize if a node is a dynamic module import.
|
static boolean |
isCommonJsExport(NodeTraversal t,
Node export,
ModuleLoader.ResolutionMode resolutionMode)
Recognize if a node is a module export.
|
boolean |
isCommonJsImport(Node requireCall) |
static boolean |
isCommonJsImport(Node requireCall,
ModuleLoader.ResolutionMode resolutionMode)
Recognize if a node is a module import.
|
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
boolean |
shouldTraverse(NodeTraversal t,
Node n,
Node parent)
Visits a node in preorder (before its children) and decides whether its children should be
traversed.
|
visit
public static final DiagnosticType UNKNOWN_REQUIRE_ENSURE
public static final DiagnosticType SUSPICIOUS_EXPORTS_ASSIGNMENT
public ProcessCommonJSModules(AbstractCompiler compiler)
compiler
- The compilerpublic void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treepublic boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
in preorder and by NodeTraversal.Callback.visit(NodeTraversal,
Node, Node)
in postorder.
Siblings are always visited left-to-right.
Implementations can have side-effects (e.g. modify the parse tree). Removing the current node is legal, but removing or reordering nodes above the current node may cause nodes to be visited twice or not at all.
shouldTraverse
in interface NodeTraversal.Callback
t
- The current traversal.n
- The current node.parent
- The parent of the current node.public static java.lang.String getModuleName(CompilerInput input)
public static java.lang.String getModuleName(ModuleLoader.ModulePath input)
public java.lang.String getBasePropertyImport(java.lang.String moduleName)
public boolean isCommonJsImport(Node requireCall)
public static boolean isCommonJsImport(Node requireCall, ModuleLoader.ResolutionMode resolutionMode)
public java.lang.String getCommonJsImportPath(Node requireCall)
public static java.lang.String getCommonJsImportPath(Node requireCall, ModuleLoader.ResolutionMode resolutionMode)
public static boolean isCommonJsExport(NodeTraversal t, Node export, ModuleLoader.ResolutionMode resolutionMode)
In addition, we only recognize an export if the base export object is not defined or is defined in externs.
public static boolean isCommonJsDynamicImportCallback(Node n, ModuleLoader.ResolutionMode resolutionMode)
Copyright © 2009-2020 Google. All Rights Reserved.