This mapping has 7 all-to-all groups: every node on one side corresponds to every node on the other, and none is deleted or inserted. Each member carries an all N:M badge; selecting one highlights all of its counterparts, in the tree and in the code view alike.

Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–351 unchanged (351 lines)
352 private void findAliases(NodeTraversal t) {
353 Scope scope = t.getScope();
354 for (Var v : scope.getVarIterable()) {
355 Node n = v.getNode();
356 Node parent = n.getParent();
357 boolean isVar = parent.isVar();
358 if (isVar && n.getFirstChild() != null && n.getFirstChild().isQualifiedName()) {
359 recordAlias(v);
360 } else if (v.isBleedingFunction()) {
361 // Bleeding functions already get a BAD_PARAMETERS error, so just
362 // do nothing.
363 } else if (parent.getType() == Token.LP) {
364 // Parameters of the scope function also get a BAD_PARAMETERS
365 // error.
366 } else if (isVar) {
367 Node grandparent = parent.getParent();
368 Node value = n.hasChildren() ?
369 v.getInitialValue().detachFromParent() :
370 null;
371 Node varNode = parent;
372
373 String name = n.getString();
374 int nameCount = scopedAliasNames.count(name);
375 scopedAliasNames.add(name);
376 String globalName =
377 "$jscomp.scope." + name + (nameCount == 0 ? "" : ("$" + nameCount));
378
379 compiler.ensureLibraryInjected("base");
380
381 // First, we need to free up the function expression (EXPR)
382 // to be used in another expression.
383 // Replace "function NAME() { ... }" with "var NAME;".
384
385 // We can't keep the local name on the function expression,
386 // because IE is buggy and will leak the name into the global
387 // scope. This is covered in more detail here:
388 // http://wiki.ecmascript.org/lib/exe/fetch.php?id=resources:resources&cache=cache&media=resources:jscriptdeviationsfromes3.pdf
389 //
390 // This will only cause problems if this is a hoisted, recursive
391 // function, and the programmer is using the hoisting.
392
393 // If this is a VAR, we can just detach the expression and
394 // the tree will still be valid.
395
396 // Add $jscomp.scope.name = EXPR;
397 // Make sure we copy over all the jsdoc and debug info.
398 if (value != null || v.getJSDocInfo() != null) {
399 Node newDecl = NodeUtil.newQualifiedNameNodeDeclaration(
400 compiler.getCodingConvention(),
401 globalName,
402 value,
403 v.getJSDocInfo())
404 .useSourceInfoIfMissingFromForTree(n);
405 NodeUtil.setDebugInformation(
406 newDecl.getFirstChild().getFirstChild(), n, name);
407
408 grandparent.addChildBefore(newDecl, varNode);
409 }
410
411 // Rewrite "var name = EXPR;" to "var name = $jscomp.scope.name;"
412 v.getNameNode().addChildToFront(
413 NodeUtil.newQualifiedNameNode(
414 compiler.getCodingConvention(), globalName, n, name));
415
…lines 416–587 unchanged (172 lines)

After

…lines 1–351 unchanged (351 lines)
352 private void findAliases(NodeTraversal t) {
353 Scope scope = t.getScope();
354 for (Var v : scope.getVarIterable()) {
355 Node n = v.getNode();
356 Node parent = n.getParent();
357 boolean isVar = parent.isVar();
358 boolean isFunctionDecl = NodeUtil.isFunctionDeclaration(parent);
359 if (isVar && n.getFirstChild() != null && n.getFirstChild().isQualifiedName()) {
360 recordAlias(v);
361 } else if (v.isBleedingFunction()) {
362 // Bleeding functions already get a BAD_PARAMETERS error, so just
363 // do nothing.
364 } else if (parent.getType() == Token.LP) {
365 // Parameters of the scope function also get a BAD_PARAMETERS
366 // error.
367 } else if (isVar || isFunctionDecl) {
368 boolean isHoisted = NodeUtil.isHoistedFunctionDeclaration(parent);
369 Node grandparent = parent.getParent();
370 Node value = v.getInitialValue() != null ?
371 v.getInitialValue() :
372 null;
373 Node varNode = null;
374
375 String name = n.getString();
376 int nameCount = scopedAliasNames.count(name);
377 scopedAliasNames.add(name);
378 String globalName =
379 "$jscomp.scope." + name + (nameCount == 0 ? "" : ("$" + nameCount));
380
381 compiler.ensureLibraryInjected("base");
382
383 // First, we need to free up the function expression (EXPR)
384 // to be used in another expression.
385 if (isFunctionDecl) {
386 // Replace "function NAME() { ... }" with "var NAME;".
387 Node existingName = v.getNameNode();
388
389 // We can't keep the local name on the function expression,
390 // because IE is buggy and will leak the name into the global
391 // scope. This is covered in more detail here:
392 // http://wiki.ecmascript.org/lib/exe/fetch.php?id=resources:resources&cache=cache&media=resources:jscriptdeviationsfromes3.pdf
393 //
394 // This will only cause problems if this is a hoisted, recursive
395 // function, and the programmer is using the hoisting.
396 Node newName = IR.name("").useSourceInfoFrom(existingName);
397 value.replaceChild(existingName, newName);
398
399 varNode = IR.var(existingName).useSourceInfoFrom(existingName);
400 grandparent.replaceChild(parent, varNode);
401 } else {
402 if (value != null) {
403 // If this is a VAR, we can just detach the expression and
404 // the tree will still be valid.
405 value.detachFromParent();
406 }
407 varNode = parent;
408 }
409
410 // Add $jscomp.scope.name = EXPR;
411 // Make sure we copy over all the jsdoc and debug info.
412 if (value != null || v.getJSDocInfo() != null) {
413 Node newDecl = NodeUtil.newQualifiedNameNodeDeclaration(
414 compiler.getCodingConvention(),
415 globalName,
416 value,
417 v.getJSDocInfo())
418 .useSourceInfoIfMissingFromForTree(n);
419 NodeUtil.setDebugInformation(
420 newDecl.getFirstChild().getFirstChild(), n, name);
421
422 if (isHoisted) {
423 grandparent.addChildToFront(newDecl);
424 } else {
425 grandparent.addChildBefore(newDecl, varNode);
426 }
427 }
428
429 // Rewrite "var name = EXPR;" to "var name = $jscomp.scope.name;"
430 v.getNameNode().addChildToFront(
431 NodeUtil.newQualifiedNameNode(
432 compiler.getCodingConvention(), globalName, n, name));
…lines 433–605 unchanged (173 lines)

Before

program
block_comment "/*\n * Copyright 2010 The Closure Compiler Authors.\n *\n * Lic"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "base"
. "."
identifier "Preconditions"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "HashMultiset"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "Lists"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "Maps"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "Multiset"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "Sets"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "CompilerOptions"
. "."
identifier "AliasTransformation"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "CompilerOptions"
. "."
identifier "AliasTransformationHandler"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "Scope"
. "."
identifier "Var"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "IR"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "JSDocInfo"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "Node"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "SourcePosition"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "Token"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Collection"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "List"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Map"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Set"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "javax"
. "."
identifier "annotation"
. "."
identifier "Nullable"
; ";"
block_comment "/**\n * Process aliases in goog.scope blocks.\n *\n * goog.scop"...
class_declaration
class "class"
identifier "ScopedAliases"
super_interfaces
implements "implements"
type_list
type_identifier "HotSwapCompilerPass"
class_body
{ "{"
block_comment "/** Name used to denote an scoped function block used for al"...
field_declaration
modifiers
static "static"
final "final"
type_identifier "String"
variable_declarator
identifier "SCOPING_METHOD_NAME"
= "="
string_literal
" "\""
string_fragment "goog.scope"
" "\""
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "AbstractCompiler"
variable_declarator
identifier "compiler"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "PreprocessorSymbolTable"
variable_declarator
identifier "preprocessorSymbolTable"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "AliasTransformationHandler"
variable_declarator
identifier "transformationHandler"
; ";"
line_comment "// Errors"
field_declaration (+25 nodes collapsed)
field_declaration (+31 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration
modifiers
private "private"
generic_type
type_identifier "Multiset"
type_arguments
< "<"
type_identifier "String"
> ">"
variable_declarator
identifier "scopedAliasNames"
= "="
method_invocation
identifier "HashMultiset"
. "."
identifier "create"
argument_list
( "("
) ")"
; ";"
constructor_declaration (+50 nodes collapsed)
method_declaration (+31 nodes collapsed)
method_declaration (+500 nodes collapsed)
class_declaration (+138 nodes collapsed)
class_declaration (+86 nodes collapsed)
class_declaration (+144 nodes collapsed)
class_declaration
modifiers
private "private"
class "class"
identifier "Traversal"
super_interfaces
implements "implements"
type_list
scoped_type_identifier
type_identifier "NodeTraversal"
. "."
type_identifier "ScopedCallback"
class_body
{ "{"
line_comment "// The job of this class is to collect these three data sets"...
line_comment "// The order of this list determines the order that aliases "...
field_declaration (+21 nodes collapsed)
field_declaration (+21 nodes collapsed)
field_declaration (+21 nodes collapsed)
line_comment "// This map is temporary and cleared for each scope."
field_declaration (+23 nodes collapsed)
line_comment "// Suppose you create an alias."
line_comment "// var x = goog.x;"
line_comment "// As a side-effect, this means you can shadow the namespace"...
line_comment "// in inner scopes. When we inline the namespaces, we have t"...
line_comment "// these shadows."
line_comment "//"
line_comment "// Fortunately, we already have a name uniquifier that runs "...
line_comment "// normalization (before optimizations). We run it here on a"...
line_comment "// set of variables, but only as a last resort (because this"...
line_comment "// up warning messages downstream)."
field_declaration (+25 nodes collapsed)
field_declaration
modifiers
private "private"
boolean_type "boolean"
variable_declarator
identifier "hasNamespaceShadows"
= "="
false "false"
; ";"
field_declaration
modifiers
private "private"
boolean_type "boolean"
variable_declarator
identifier "hasErrors"
= "="
false "false"
; ";"
field_declaration
modifiers
private "private"
type_identifier "AliasTransformation"
variable_declarator
identifier "transformation"
= "="
null_literal "null"
; ";"
method_declaration
generic_type
type_identifier "Collection"
type_arguments
< "<"
type_identifier "Node"
> ">"
identifier "getAliasDefinitionsInOrder"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "aliasDefinitionsInOrder"
; ";"
} "}"
method_declaration
modifiers
private "private"
generic_type
type_identifier "List"
type_arguments
< "<"
type_identifier "AliasUsage"
> ">"
identifier "getAliasUsages"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "aliasUsages"
; ";"
} "}"
method_declaration
generic_type
type_identifier "List"
type_arguments
< "<"
type_identifier "Node"
> ">"
identifier "getScopeCalls"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "scopeCalls"
; ";"
} "}"
method_declaration
boolean_type "boolean"
identifier "hasErrors"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "hasErrors"
; ";"
} "}"
method_declaration (+46 nodes collapsed)
method_declaration (+90 nodes collapsed)
method_declaration (+99 nodes collapsed)
method_declaration (+81 nodes collapsed)
method_declaration (+186 nodes collapsed)
method_declaration (+55 nodes collapsed)
method_declaration
modifiers
private "private"
void_type "void"
identifier "findAliases"
formal_parameters
( "("
formal_parameter
type_identifier "NodeTraversal"
identifier "t"
) ")"
block
{ "{"
local_variable_declaration
type_identifier "Scope"
variable_declarator
identifier "scope"
= "="
method_invocation
identifier "t"
. "."
identifier "getScope"
argument_list
( "("
) ")"
; ";"
enhanced_for_statement
for "for"
( "("
type_identifier "Var"
identifier "v"
: ":"
method_invocation
identifier "scope"
. "."
identifier "getVarIterable"
argument_list
( "("
) ")"
) ")"
block
{ "{"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "n"
= "="
method_invocation
identifier "v"
. "."
identifier "getNode"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "parent"
= "="
method_invocation
identifier "n"
. "."
identifier "getParent"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "isVar"
= "="
method_invocation
identifier "parent"
. "."
identifier "isVar"
argument_list
( "("
) ")"
; ";"
if_statement
if "if"
parenthesized_expression (+31 nodes collapsed)
block
{ "{"
expression_statement
method_invocation
identifier "recordAlias"
argument_list
( "("
identifier "v"
) ")"
; ";"
} "}"
else "else"
if_statement
if "if"
parenthesized_expression
( "("
method_invocation
identifier "v"
. "."
identifier "isBleedingFunction"
argument_list
( "("
) ")"
) ")"
block
{ "{"
line_comment "// Bleeding functions already get a BAD_PARAMETERS error, so"...
line_comment "// do nothing."
} "}"
else "else"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
method_invocation
identifier "parent"
. "."
identifier "getType"
argument_list
( "("
) ")"
== "=="
field_access
identifier "Token"
. "."
identifier "LP"
) ")"
block
{ "{"
line_comment "// Parameters of the scope function also get a BAD_PARAMETER"...
line_comment "// error."
} "}"
else "else"
if_statement
if "if"
parenthesized_expression
( "("
identifier "isVar"
) ")"
block
{ "{"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "grandparent"
= "="
method_invocation
identifier "parent"
. "."
identifier "getParent"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "value"
= "="
ternary_expression
method_invocation
identifier "n"
. "."
identifier "hasChildren"
argument_list
( "("
) ")"
? "?"
method_invocation
method_invocation all 1:2
identifier "v" all 1:2
. "." all 1:2
identifier "getInitialValue" all 1:2
argument_list all 1:2
( "(" all 1:2
) ")" all 1:2
. "."
identifier "detachFromParent"
argument_list
( "("
) ")"
: ":"
null_literal "null"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "varNode"
= "="
identifier "parent"
; ";"
local_variable_declaration
type_identifier "String"
variable_declarator
identifier "name"
= "="
method_invocation
identifier "n"
. "."
identifier "getString"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "nameCount"
= "="
method_invocation
identifier "scopedAliasNames"
. "."
identifier "count"
argument_list
( "("
identifier "name"
) ")"
; ";"
expression_statement
method_invocation
identifier "scopedAliasNames"
. "."
identifier "add"
argument_list
( "("
identifier "name"
) ")"
; ";"
local_variable_declaration (+38 nodes collapsed)
expression_statement
method_invocation
identifier "compiler"
. "."
identifier "ensureLibraryInjected"
argument_list
( "("
string_literal
" "\""
string_fragment "base"
" "\""
) ")"
; ";"
line_comment "// First, we need to free up the function expression (EXPR)"
line_comment "// to be used in another expression."
line_comment "// Replace \"function NAME() { ... }\" with \"var NAME;\"."
line_comment "// We can't keep the local name on the function expression,"
line_comment "// because IE is buggy and will leak the name into the globa"...
line_comment "// scope. This is covered in more detail here:"
line_comment "// http://wiki.ecmascript.org/lib/exe/fetch.php?id=resources"...
line_comment "//"
line_comment "// This will only cause problems if this is a hoisted, recur"...
line_comment "// function, and the programmer is using the hoisting."
line_comment "// If this is a VAR, we can just detach the expression and"
line_comment "// the tree will still be valid."
line_comment "// Add $jscomp.scope.name = EXPR;"
line_comment "// Make sure we copy over all the jsdoc and debug info."
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
binary_expression
identifier "value"
!= "!="
null_literal "null"
|| "||"
binary_expression
method_invocation
identifier "v"
. "."
identifier "getJSDocInfo"
argument_list
( "("
) ")"
!= "!="
null_literal "null"
) ")"
block
{ "{"
local_variable_declaration (+39 nodes collapsed)
expression_statement (+26 nodes collapsed)
expression_statement
method_invocation
identifier "grandparent"
. "."
identifier "addChildBefore"
argument_list
( "("
identifier "newDecl"
, ","
identifier "varNode"
) ")"
; ";"
} "}"
line_comment "// Rewrite \"var name = EXPR;\" to \"var name = $jscomp.scope.n"...
expression_statement (+35 nodes collapsed)
expression_statement
method_invocation
identifier "recordAlias"
argument_list
( "("
identifier "v"
) ")"
; ";"
} "}"
else "else"
block (+24 nodes collapsed)
} "}"
} "}"
method_declaration (+146 nodes collapsed)
block_comment "/** Find out if there are any local shadows of namespaces. *"...
method_declaration (+87 nodes collapsed)
block_comment "/**\n * Rename any local shadows of namespaces.\n * Th"...
method_declaration (+106 nodes collapsed)
method_declaration (+201 nodes collapsed)
method_declaration (+472 nodes collapsed)
method_declaration (+186 nodes collapsed)
} "}"
} "}"

After

program
block_comment "/*\n * Copyright 2010 The Closure Compiler Authors.\n *\n * Lic"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "base"
. "."
identifier "Preconditions"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "HashMultiset"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "Lists"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "Maps"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "Multiset"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "collect"
. "."
identifier "Sets"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "CompilerOptions"
. "."
identifier "AliasTransformation"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "CompilerOptions"
. "."
identifier "AliasTransformationHandler"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "Scope"
. "."
identifier "Var"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "IR"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "JSDocInfo"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "Node"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "SourcePosition"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "Token"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Collection"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "List"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Map"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Set"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "javax"
. "."
identifier "annotation"
. "."
identifier "Nullable"
; ";"
block_comment "/**\n * Process aliases in goog.scope blocks.\n *\n * goog.scop"...
class_declaration
class "class"
identifier "ScopedAliases"
super_interfaces
implements "implements"
type_list
type_identifier "HotSwapCompilerPass"
class_body
{ "{"
block_comment "/** Name used to denote an scoped function block used for al"...
field_declaration
modifiers
static "static"
final "final"
type_identifier "String"
variable_declarator
identifier "SCOPING_METHOD_NAME"
= "="
string_literal
" "\""
string_fragment "goog.scope"
" "\""
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "AbstractCompiler"
variable_declarator
identifier "compiler"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "PreprocessorSymbolTable"
variable_declarator
identifier "preprocessorSymbolTable"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "AliasTransformationHandler"
variable_declarator
identifier "transformationHandler"
; ";"
line_comment "// Errors"
field_declaration (+25 nodes collapsed)
field_declaration (+31 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration
modifiers
private "private"
generic_type
type_identifier "Multiset"
type_arguments
< "<"
type_identifier "String"
> ">"
variable_declarator
identifier "scopedAliasNames"
= "="
method_invocation
identifier "HashMultiset"
. "."
identifier "create"
argument_list
( "("
) ")"
; ";"
constructor_declaration (+50 nodes collapsed)
method_declaration (+31 nodes collapsed)
method_declaration (+500 nodes collapsed)
class_declaration (+138 nodes collapsed)
class_declaration (+86 nodes collapsed)
class_declaration (+144 nodes collapsed)
class_declaration
modifiers
private "private"
class "class"
identifier "Traversal"
super_interfaces
implements "implements"
type_list
scoped_type_identifier
type_identifier "NodeTraversal"
. "."
type_identifier "ScopedCallback"
class_body
{ "{"
line_comment "// The job of this class is to collect these three data sets"...
line_comment "// The order of this list determines the order that aliases "...
field_declaration (+21 nodes collapsed)
field_declaration (+21 nodes collapsed)
field_declaration (+21 nodes collapsed)
line_comment "// This map is temporary and cleared for each scope."
field_declaration (+23 nodes collapsed)
line_comment "// Suppose you create an alias."
line_comment "// var x = goog.x;"
line_comment "// As a side-effect, this means you can shadow the namespace"...
line_comment "// in inner scopes. When we inline the namespaces, we have t"...
line_comment "// these shadows."
line_comment "//"
line_comment "// Fortunately, we already have a name uniquifier that runs "...
line_comment "// normalization (before optimizations). We run it here on a"...
line_comment "// set of variables, but only as a last resort (because this"...
line_comment "// up warning messages downstream)."
field_declaration (+25 nodes collapsed)
field_declaration
modifiers
private "private"
boolean_type "boolean"
variable_declarator
identifier "hasNamespaceShadows"
= "="
false "false"
; ";"
field_declaration
modifiers
private "private"
boolean_type "boolean"
variable_declarator
identifier "hasErrors"
= "="
false "false"
; ";"
field_declaration
modifiers
private "private"
type_identifier "AliasTransformation"
variable_declarator
identifier "transformation"
= "="
null_literal "null"
; ";"
method_declaration
generic_type
type_identifier "Collection"
type_arguments
< "<"
type_identifier "Node"
> ">"
identifier "getAliasDefinitionsInOrder"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "aliasDefinitionsInOrder"
; ";"
} "}"
method_declaration
modifiers
private "private"
generic_type
type_identifier "List"
type_arguments
< "<"
type_identifier "AliasUsage"
> ">"
identifier "getAliasUsages"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "aliasUsages"
; ";"
} "}"
method_declaration
generic_type
type_identifier "List"
type_arguments
< "<"
type_identifier "Node"
> ">"
identifier "getScopeCalls"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "scopeCalls"
; ";"
} "}"
method_declaration
boolean_type "boolean"
identifier "hasErrors"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "hasErrors"
; ";"
} "}"
method_declaration (+46 nodes collapsed)
method_declaration (+90 nodes collapsed)
method_declaration (+99 nodes collapsed)
method_declaration (+81 nodes collapsed)
method_declaration (+186 nodes collapsed)
method_declaration (+55 nodes collapsed)
method_declaration
modifiers
private "private"
void_type "void"
identifier "findAliases"
formal_parameters
( "("
formal_parameter
type_identifier "NodeTraversal"
identifier "t"
) ")"
block
{ "{"
local_variable_declaration
type_identifier "Scope"
variable_declarator
identifier "scope"
= "="
method_invocation
identifier "t"
. "."
identifier "getScope"
argument_list
( "("
) ")"
; ";"
enhanced_for_statement
for "for"
( "("
type_identifier "Var"
identifier "v"
: ":"
method_invocation
identifier "scope"
. "."
identifier "getVarIterable"
argument_list
( "("
) ")"
) ")"
block
{ "{"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "n"
= "="
method_invocation
identifier "v"
. "."
identifier "getNode"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "parent"
= "="
method_invocation
identifier "n"
. "."
identifier "getParent"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "isVar"
= "="
method_invocation
identifier "parent"
. "."
identifier "isVar"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "isFunctionDecl"
= "="
method_invocation
identifier "NodeUtil"
. "."
identifier "isFunctionDeclaration"
argument_list
( "("
identifier "parent"
) ")"
; ";"
if_statement
if "if"
parenthesized_expression (+31 nodes collapsed)
block
{ "{"
expression_statement
method_invocation
identifier "recordAlias"
argument_list
( "("
identifier "v"
) ")"
; ";"
} "}"
else "else"
if_statement
if "if"
parenthesized_expression
( "("
method_invocation
identifier "v"
. "."
identifier "isBleedingFunction"
argument_list
( "("
) ")"
) ")"
block
{ "{"
line_comment "// Bleeding functions already get a BAD_PARAMETERS error, so"...
line_comment "// do nothing."
} "}"
else "else"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
method_invocation
identifier "parent"
. "."
identifier "getType"
argument_list
( "("
) ")"
== "=="
field_access
identifier "Token"
. "."
identifier "LP"
) ")"
block
{ "{"
line_comment "// Parameters of the scope function also get a BAD_PARAMETER"...
line_comment "// error."
} "}"
else "else"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "isVar"
|| "||"
identifier "isFunctionDecl"
) ")"
block
{ "{"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "isHoisted"
= "="
method_invocation
identifier "NodeUtil"
. "."
identifier "isHoistedFunctionDeclaration"
argument_list
( "("
identifier "parent"
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "grandparent"
= "="
method_invocation
identifier "parent"
. "."
identifier "getParent"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "value"
= "="
ternary_expression
binary_expression
method_invocation all 1:2
identifier "v" all 1:2
. "." all 1:2
identifier "getInitialValue" all 1:2
argument_list all 1:2
( "(" all 1:2
) ")" all 1:2
!= "!="
null_literal "null"
? "?"
method_invocation all 1:2
identifier "v" all 1:2
. "." all 1:2
identifier "getInitialValue" all 1:2
argument_list all 1:2
( "(" all 1:2
) ")" all 1:2
: ":"
null_literal "null"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "varNode"
= "="
null_literal "null"
; ";"
local_variable_declaration
type_identifier "String"
variable_declarator
identifier "name"
= "="
method_invocation
identifier "n"
. "."
identifier "getString"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "nameCount"
= "="
method_invocation
identifier "scopedAliasNames"
. "."
identifier "count"
argument_list
( "("
identifier "name"
) ")"
; ";"
expression_statement
method_invocation
identifier "scopedAliasNames"
. "."
identifier "add"
argument_list
( "("
identifier "name"
) ")"
; ";"
local_variable_declaration (+38 nodes collapsed)
expression_statement
method_invocation
identifier "compiler"
. "."
identifier "ensureLibraryInjected"
argument_list
( "("
string_literal
" "\""
string_fragment "base"
" "\""
) ")"
; ";"
line_comment "// First, we need to free up the function expression (EXPR)"
line_comment "// to be used in another expression."
if_statement
if "if"
parenthesized_expression
( "("
identifier "isFunctionDecl"
) ")"
block
{ "{"
line_comment "// Replace \"function NAME() { ... }\" with \"var NAME;\"."
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "existingName"
= "="
method_invocation
identifier "v"
. "."
identifier "getNameNode"
argument_list
( "("
) ")"
; ";"
line_comment "// We can't keep the local name on the function expression,"
line_comment "// because IE is buggy and will leak the name into the globa"...
line_comment "// scope. This is covered in more detail here:"
line_comment "// http://wiki.ecmascript.org/lib/exe/fetch.php?id=resources"...
line_comment "//"
line_comment "// This will only cause problems if this is a hoisted, recur"...
line_comment "// function, and the programmer is using the hoisting."
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "newName"
= "="
method_invocation
method_invocation
identifier "IR"
. "."
identifier "name"
argument_list
( "("
string_literal
" "\""
" "\""
) ")"
. "."
identifier "useSourceInfoFrom"
argument_list
( "("
identifier "existingName"
) ")"
; ";"
expression_statement
method_invocation
identifier "value"
. "."
identifier "replaceChild"
argument_list
( "("
identifier "existingName"
, ","
identifier "newName"
) ")"
; ";"
expression_statement
assignment_expression
identifier "varNode"
= "="
method_invocation
method_invocation
identifier "IR"
. "."
identifier "var"
argument_list
( "("
identifier "existingName"
) ")"
. "."
identifier "useSourceInfoFrom"
argument_list
( "("
identifier "existingName"
) ")"
; ";"
expression_statement
method_invocation
identifier "grandparent"
. "."
identifier "replaceChild"
argument_list
( "("
identifier "parent"
, ","
identifier "varNode"
) ")"
; ";"
} "}"
else "else"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "value"
!= "!="
null_literal "null"
) ")"
block
{ "{"
line_comment "// If this is a VAR, we can just detach the expression and"
line_comment "// the tree will still be valid."
expression_statement
method_invocation
identifier "value"
. "."
identifier "detachFromParent"
argument_list
( "("
) ")"
; ";"
} "}"
expression_statement
assignment_expression
identifier "varNode"
= "="
identifier "parent"
; ";"
} "}"
line_comment "// Add $jscomp.scope.name = EXPR;"
line_comment "// Make sure we copy over all the jsdoc and debug info."
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
binary_expression
identifier "value"
!= "!="
null_literal "null"
|| "||"
binary_expression
method_invocation
identifier "v"
. "."
identifier "getJSDocInfo"
argument_list
( "("
) ")"
!= "!="
null_literal "null"
) ")"
block
{ "{"
local_variable_declaration (+39 nodes collapsed)
expression_statement (+26 nodes collapsed)
if_statement
if "if"
parenthesized_expression
( "("
identifier "isHoisted"
) ")"
block
{ "{"
expression_statement
method_invocation
identifier "grandparent"
. "."
identifier "addChildToFront"
argument_list
( "("
identifier "newDecl"
) ")"
; ";"
} "}"
else "else"
block
{ "{"
expression_statement
method_invocation
identifier "grandparent"
. "."
identifier "addChildBefore"
argument_list
( "("
identifier "newDecl"
, ","
identifier "varNode"
) ")"
; ";"
} "}"
} "}"
line_comment "// Rewrite \"var name = EXPR;\" to \"var name = $jscomp.scope.n"...
expression_statement (+35 nodes collapsed)
expression_statement
method_invocation
identifier "recordAlias"
argument_list
( "("
identifier "v"
) ")"
; ";"
} "}"
else "else"
block (+24 nodes collapsed)
} "}"
} "}"
method_declaration (+146 nodes collapsed)
block_comment "/** Find out if there are any local shadows of namespaces. *"...
method_declaration (+87 nodes collapsed)
block_comment "/**\n * Rename any local shadows of namespaces.\n * Th"...
method_declaration (+106 nodes collapsed)
method_declaration (+201 nodes collapsed)
method_declaration (+472 nodes collapsed)
method_declaration (+186 nodes collapsed)
} "}"
} "}"