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) |
static java.lang.String |
getCommonJsImportPath(Node requireCall) |
static java.lang.String |
getModuleName(CompilerInput input) |
static java.lang.String |
getModuleName(ModuleLoader.ModulePath input) |
static boolean |
isCommonJsExport(NodeTraversal t,
Node export)
Recognize if a node is a module export.
|
static boolean |
isCommonJsImport(Node requireCall)
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.
|
visitpublic 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)
CompilerPassprocess in interface CompilerPassexterns - Top of external JS treeroot - Top of JS treepublic boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
NodeTraversal.CallbackVisits 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.Callbackpublic 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 static boolean isCommonJsImport(Node requireCall)
public static java.lang.String getCommonJsImportPath(Node requireCall)
public static boolean isCommonJsExport(NodeTraversal t, Node export)
In addition, we only recognize an export if the base export object is not defined or is defined in externs.
Copyright © 2009-2017 Google. All Rights Reserved.