public class RewriteGoogJsImports extends java.lang.Object implements HotSwapCompilerPass
This pass scans the goog.js file to find what keys are exported. When rewriting imports only those in the goog.js file are globalized; if there is a reference to something not in the goog.js file it is rewritten in such a way to cause an error later at type checking.
This is a separate pass that needs to run before Es6RewriteModules which will remove import statements.
This pass enforces the following so that later compiler passes and regex based tools can correctly recognize references to these properties of goog (like goog.require):
import * as goog
goog
export from
is never used on goog.js
Example:
import * as goog from 'path/to/closure/goog.js'; const myNamespace =
goog.require('my.namespace');
Will be rewritten to:
import 'path/to/closure/goog.js'; const myNamespace = goog.require('my.namespace');
Modifier and Type | Class and Description |
---|---|
static class |
RewriteGoogJsImports.Mode
Possible traversal modes - either linting or linting+rewriting.
|
Constructor and Description |
---|
RewriteGoogJsImports(AbstractCompiler compiler,
RewriteGoogJsImports.Mode mode,
ModuleMap moduleMap) |
Modifier and Type | Method and Description |
---|---|
void |
hotSwapScript(Node scriptRoot,
Node originalRoot)
Process the JS with root node root.
|
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
public RewriteGoogJsImports(AbstractCompiler compiler, RewriteGoogJsImports.Mode mode, ModuleMap moduleMap)
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 process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treeCopyright © 2009-2020 Google. All Rights Reserved.