Class RewriteGoogJsImports
- java.lang.Object
-
- com.google.javascript.jscomp.RewriteGoogJsImports
-
- All Implemented Interfaces:
CompilerPass
public class RewriteGoogJsImports extends java.lang.Object implements CompilerPass
Looks for references to Closure's goog.js file and globalizes. The goog.js file is an ES6 module that forwards some symbols on goog from Closure's base.js file, like require.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 Classes Modifier and Type Class Description static class
RewriteGoogJsImports.Mode
Possible traversal modes - either linting or linting+rewriting.
-
Constructor Summary
Constructors Constructor Description RewriteGoogJsImports(AbstractCompiler compiler, RewriteGoogJsImports.Mode mode, ModuleMap moduleMap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
process(Node externs, Node root)
Process the JS with root node root.
-
-
-
Constructor Detail
-
RewriteGoogJsImports
public RewriteGoogJsImports(AbstractCompiler compiler, RewriteGoogJsImports.Mode mode, ModuleMap moduleMap)
-
-
Method Detail
-
process
public void process(Node externs, Node root)
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
-
-