Class RewriteGoogJsImports
- All Implemented Interfaces:
CompilerPass
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):
- No other file is named goog.js
- The file is always imported as
import * as goog
- No other module level variable is named
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');
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Possible traversal modes - either linting or linting+rewriting. -
Constructor Summary
ConstructorsConstructorDescriptionRewriteGoogJsImports
(AbstractCompiler compiler, RewriteGoogJsImports.Mode mode, ModuleMap moduleMap) -
Method Summary
-
Constructor Details
-
RewriteGoogJsImports
public RewriteGoogJsImports(AbstractCompiler compiler, RewriteGoogJsImports.Mode mode, ModuleMap moduleMap)
-
-
Method Details
-
process
Description copied from interface:CompilerPass
Process the JS with root node root. Can modify the contents of each Node tree- Specified by:
process
in interfaceCompilerPass
- Parameters:
externs
- Top of external JS treeroot
- Top of JS tree
-