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 pre order (before visiting its children) and decides
whether this node's 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
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed. If children are
traversed, they will be visited by
NodeTraversal.Callback.visit(NodeTraversal, Node, Node)
in postorder.
Implementations can have side effects (e.g. modifying the parse tree).
shouldTraverse
in interface NodeTraversal.Callback
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-2019 Google. All Rights Reserved.