class ScopedAliases extends java.lang.Object implements HotSwapCompilerPass
goog.scope(function() { var dom = goog.dom; var DIV = dom.TagName.DIV; dom.createElement(DIV); });should become
goog.dom.createElement(goog.dom.TagName.DIV);The advantage of using goog.scope is that the compiler will *guarantee* the anonymous function will be inlined, even if it can't prove that it's semantically correct to do so. For example, consider this case:
goog.scope(function() { goog.getBar = function () { return alias; }; ... var alias = foo.bar; })
In theory, the compiler can't inline 'alias' unless it can prove that goog.getBar is called only after 'alias' is defined. In practice, the compiler will inline 'alias' anyway, at the risk of 'fixing' bad code.
Modifier and Type | Class and Description |
---|---|
private static class |
ScopedAliases.AliasedNode |
private static class |
ScopedAliases.AliasedTypeNode |
private static class |
ScopedAliases.AliasUsage |
private class |
ScopedAliases.Traversal |
Constructor and Description |
---|
ScopedAliases(AbstractCompiler compiler,
PreprocessorSymbolTable preprocessorSymbolTable,
CompilerOptions.AliasTransformationHandler transformationHandler) |
Modifier and Type | Method and Description |
---|---|
void |
hotSwapScript(Node root,
Node originalRoot)
Process the JS with root node root.
|
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
static final java.lang.String SCOPING_METHOD_NAME
private final AbstractCompiler compiler
private final PreprocessorSymbolTable preprocessorSymbolTable
private final CompilerOptions.AliasTransformationHandler transformationHandler
static final DiagnosticType GOOG_SCOPE_MUST_BE_ALONE
static final DiagnosticType GOOG_SCOPE_MUST_BE_IN_GLOBAL_SCOPE
static final DiagnosticType GOOG_SCOPE_HAS_BAD_PARAMETERS
static final DiagnosticType GOOG_SCOPE_REFERENCES_THIS
static final DiagnosticType GOOG_SCOPE_USES_RETURN
static final DiagnosticType GOOG_SCOPE_USES_THROW
static final DiagnosticType GOOG_SCOPE_ALIAS_REDEFINED
static final DiagnosticType GOOG_SCOPE_ALIAS_CYCLE
static final DiagnosticType GOOG_SCOPE_NON_ALIAS_LOCAL
static final DiagnosticType GOOG_SCOPE_INVALID_VARIABLE
private com.google.common.collect.Multiset<java.lang.String> scopedAliasNames
ScopedAliases(AbstractCompiler compiler, @Nullable PreprocessorSymbolTable preprocessorSymbolTable, CompilerOptions.AliasTransformationHandler transformationHandler)
public void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treepublic void hotSwapScript(Node root, Node originalRoot)
HotSwapCompilerPass
hotSwapScript
in interface HotSwapCompilerPass
root
- 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
.