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–448 unchanged (448 lines)
449 * @param alias The flattened name for {@code n}
450 */
451 private void collapseDeclarationOfNameAndDescendants(Name n, String alias) {
452 boolean canCollapseChildNames = n.canCollapseUnannotatedChildNames();
453
454 // Handle this name first so that nested object literals get unrolled.
455 if (n.canCollapse() && canCollapseChildNames) {
456 updateObjLitOrFunctionDeclaration(n, alias);
457 }
458
459 if (n.props != null) {
460 for (Name p : n.props) {
461 // Recurse first so that saved node ancestries are intact when needed.
462 collapseDeclarationOfNameAndDescendants(
…lines 463–567 unchanged (105 lines)
568 * @param n An object representing a global name (e.g. "a", "a.b.c")
569 * @param alias The flattened name for {@code n} (e.g. "a", "a$b$c")
570 * @param canCollapseChildNames Whether it's possible to collapse children of
571 * this name. (This is mostly passed for convenience; it's equivalent to
572 * n.canCollapseChildNames()).
573 */
574 private void updateObjLitOrFunctionDeclaration(Name n, String alias) {
575 if (n.declaration == null) {
576 // Some names do not have declarations, because they
577 // are only defined in local scopes.
578 return;
579 }
580
581 if (n.declaration.getTwin() != null) {
582 // Twin declarations will get handled when normal references
583 // are handled.
584 return;
585 }
586
587 switch (n.declaration.node.getParent().getType()) {
588 case Token.ASSIGN:
589 updateObjLitOrFunctionDeclarationAtAssignNode(n, alias);
590 break;
591 case Token.VAR:
592 updateObjLitOrFunctionDeclarationAtVarNode(n);
593 break;
594 case Token.FUNCTION:
595 updateFunctionDeclarationAtFunctionNode(n);
596 break;
597 }
598 }
599
600 /**
601 * Updates the first initialization (a.k.a "declaration") of a global name
602 * that occurs at an ASSIGN node. See comment for
603 * {@link #updateObjLitOrFunctionDeclaration}.
604 *
605 * @param n An object representing a global name (e.g. "a", "a.b.c")
606 * @param alias The flattened name for {@code n} (e.g. "a", "a$b$c")
607 */
608 private void updateObjLitOrFunctionDeclarationAtAssignNode(
609 Name n, String alias) {
610 // NOTE: It's important that we don't add additional nodes
611 // (e.g. a var node before the exprstmt) because the exprstmt might be
612 // the child of an if statement that's not inside a block).
613
614 Ref ref = n.declaration;
615 Node rvalue = ref.node.getNext();
…lines 616–645 unchanged (30 lines)
646 varParent.replaceChild(gramps, varNode);
647
648 // Update the node ancestry stored in the reference.
649 ref.node = nameNode;
650 insertedVarNode = true;
651 }
652
653 if (isObjLit) {
654 declareVarsForObjLitValues(
655 n, alias, rvalue,
656 varNode, varParent.getChildBefore(varNode), varParent);
657
658 }
659 addStubsForUndeclaredProperties(n, alias, varParent, varNode);
660
661 if (insertedVarNode) {
662 if (!varNode.hasChildren()) {
663 varParent.removeChild(varNode);
664 }
665 compiler.reportCodeChange();
666 }
…lines 667–692 unchanged (26 lines)
693 * Updates the first initialization (a.k.a "declaration") of a global name
694 * that occurs at a VAR node. See comment for
695 * {@link #updateObjLitOrFunctionDeclaration}.
696 *
697 * @param n An object representing a global name (e.g. "a")
698 */
699 private void updateObjLitOrFunctionDeclarationAtVarNode(Name n) {
700
701 Ref ref = n.declaration;
702 String name = ref.node.getString();
703 Node rvalue = ref.node.getFirstChild();
704 Node varNode = ref.node.getParent();
705 Node gramps = varNode.getParent();
…lines 706–735 unchanged (30 lines)
736 * Updates the first initialization (a.k.a "declaration") of a global name
737 * that occurs at a FUNCTION node. See comment for
738 * {@link #updateObjLitOrFunctionDeclaration}.
739 *
740 * @param n An object representing a global name (e.g. "a")
741 */
742 private void updateFunctionDeclarationAtFunctionNode(Name n) {
743
744 Ref ref = n.declaration;
745 String fnName = ref.node.getString();
746 addStubsForUndeclaredProperties(
747 n, fnName, ref.node.getAncestor(2), ref.node.getParent());
748 }
…lines 749–901 unchanged (153 lines)

After

…lines 1–448 unchanged (448 lines)
449 * @param alias The flattened name for {@code n}
450 */
451 private void collapseDeclarationOfNameAndDescendants(Name n, String alias) {
452 boolean canCollapseChildNames = n.canCollapseUnannotatedChildNames();
453
454 // Handle this name first so that nested object literals get unrolled.
455 if (n.canCollapse()) {
456 updateObjLitOrFunctionDeclaration(n, alias, canCollapseChildNames);
457 }
458
459 if (n.props != null) {
460 for (Name p : n.props) {
461 // Recurse first so that saved node ancestries are intact when needed.
462 collapseDeclarationOfNameAndDescendants(
…lines 463–568 unchanged (106 lines)
569 * @param alias The flattened name for {@code n} (e.g. "a", "a$b$c")
570 * @param canCollapseChildNames Whether it's possible to collapse children of
571 * this name. (This is mostly passed for convenience; it's equivalent to
572 * n.canCollapseChildNames()).
573 */
574 private void updateObjLitOrFunctionDeclaration(
575 Name n, String alias, boolean canCollapseChildNames) {
576 if (n.declaration == null) {
577 // Some names do not have declarations, because they
578 // are only defined in local scopes.
579 return;
580 }
581
582 if (n.declaration.getTwin() != null) {
583 // Twin declarations will get handled when normal references
584 // are handled.
585 return;
586 }
587
588 switch (n.declaration.node.getParent().getType()) {
589 case Token.ASSIGN:
590 updateObjLitOrFunctionDeclarationAtAssignNode(
591 n, alias, canCollapseChildNames);
592 break;
593 case Token.VAR:
594 updateObjLitOrFunctionDeclarationAtVarNode(n, canCollapseChildNames);
595 break;
596 case Token.FUNCTION:
597 updateFunctionDeclarationAtFunctionNode(n, canCollapseChildNames);
598 break;
599 }
600 }
601
602 /**
603 * Updates the first initialization (a.k.a "declaration") of a global name
604 * that occurs at an ASSIGN node. See comment for
605 * {@link #updateObjLitOrFunctionDeclaration}.
606 *
607 * @param n An object representing a global name (e.g. "a", "a.b.c")
608 * @param alias The flattened name for {@code n} (e.g. "a", "a$b$c")
609 */
610 private void updateObjLitOrFunctionDeclarationAtAssignNode(
611 Name n, String alias, boolean canCollapseChildNames) {
612 // NOTE: It's important that we don't add additional nodes
613 // (e.g. a var node before the exprstmt) because the exprstmt might be
614 // the child of an if statement that's not inside a block).
615
616 Ref ref = n.declaration;
617 Node rvalue = ref.node.getNext();
…lines 618–648 unchanged (31 lines)
649
650 // Update the node ancestry stored in the reference.
651 ref.node = nameNode;
652 insertedVarNode = true;
653 }
654
655 if (canCollapseChildNames) {
656 if (isObjLit) {
657 declareVarsForObjLitValues(
658 n, alias, rvalue,
659 varNode, varParent.getChildBefore(varNode), varParent);
660 }
661
662 addStubsForUndeclaredProperties(n, alias, varParent, varNode);
663 }
664
665 if (insertedVarNode) {
666 if (!varNode.hasChildren()) {
667 varParent.removeChild(varNode);
668 }
669 compiler.reportCodeChange();
…lines 670–697 unchanged (28 lines)
698 * that occurs at a VAR node. See comment for
699 * {@link #updateObjLitOrFunctionDeclaration}.
700 *
701 * @param n An object representing a global name (e.g. "a")
702 */
703 private void updateObjLitOrFunctionDeclarationAtVarNode(
704 Name n, boolean canCollapseChildNames) {
705 if (!canCollapseChildNames) {
706 return;
707 }
708
709 Ref ref = n.declaration;
710 String name = ref.node.getString();
711 Node rvalue = ref.node.getFirstChild();
712 Node varNode = ref.node.getParent();
713 Node gramps = varNode.getParent();
…lines 714–744 unchanged (31 lines)
745 * that occurs at a FUNCTION node. See comment for
746 * {@link #updateObjLitOrFunctionDeclaration}.
747 *
748 * @param n An object representing a global name (e.g. "a")
749 */
750 private void updateFunctionDeclarationAtFunctionNode(
751 Name n, boolean canCollapseChildNames) {
752 if (!canCollapseChildNames) {
753 return;
754 }
755
756 Ref ref = n.declaration;
757 String fnName = ref.node.getString();
758 addStubsForUndeclaredProperties(
759 n, fnName, ref.node.getAncestor(2), ref.node.getParent());
760 }
…lines 761–913 unchanged (153 lines)

Before

program
block_comment "/*\n * Copyright 2006 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 "base"
. "."
identifier "Predicates"
; ";"
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 "Sets"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "GlobalNamespace"
. "."
identifier "Name"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "GlobalNamespace"
. "."
identifier "Ref"
; ";"
import_declaration (+22 nodes collapsed)
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "ReferenceCollectingCallback"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "ReferenceCollectingCallback"
. "."
identifier "ReferenceCollection"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "Scope"
; ";"
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 "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 "Token"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "TokenStream"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "JSType"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "ArrayDeque"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Deque"
; ";"
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"
; ";"
block_comment "/**\n * Flattens global objects/namespaces by replacing each "...
class_declaration
class "class"
identifier "CollapseProperties"
super_interfaces
implements "implements"
type_list
type_identifier "CompilerPass"
class_body
{ "{"
line_comment "// Warnings"
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration
modifiers
private "private"
type_identifier "AbstractCompiler"
variable_declarator
identifier "compiler"
; ";"
block_comment "/** Global namespace tree */"
field_declaration
modifiers
private "private"
generic_type
type_identifier "List"
type_arguments
< "<"
type_identifier "Name"
> ">"
variable_declarator
identifier "globalNames"
; ";"
block_comment "/** Maps names (e.g. \"a.b.c\") to nodes in the global namespa"...
field_declaration
modifiers
private "private"
generic_type
type_identifier "Map"
type_arguments
< "<"
type_identifier "String"
, ","
type_identifier "Name"
> ">"
variable_declarator
identifier "nameMap"
; ";"
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "collapsePropertiesOnExternTypes"
; ";"
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "inlineAliases"
; ";"
block_comment "/**\n * Creates an instance.\n *\n * @param compiler The "...
constructor_declaration (+46 nodes collapsed)
method_declaration (+168 nodes collapsed)
block_comment "/**\n * For each qualified name N in the global scope, we c"...
method_declaration (+313 nodes collapsed)
method_declaration (+381 nodes collapsed)
block_comment "/**\n * Runs through all namespaces (prefixes of classes an"...
method_declaration (+199 nodes collapsed)
block_comment "/**\n * Reports a warning because a namespace was aliased.\n"...
method_declaration (+53 nodes collapsed)
block_comment "/**\n * Reports a warning because a namespace was redefined"...
method_declaration (+53 nodes collapsed)
block_comment "/**\n * Flattens all references to collapsible properties o"...
method_declaration (+99 nodes collapsed)
block_comment "/**\n * Flattens all references to a collapsible property o"...
method_declaration (+189 nodes collapsed)
block_comment "/**\n * Flattens all occurrences of a name as a prefix of s"...
method_declaration (+225 nodes collapsed)
block_comment "/**\n * Flattens a particular prefix of a single name refer"...
method_declaration (+189 nodes collapsed)
block_comment "/**\n * Replaces a GETPROP a.b.c with a NAME a$b$c.\n *\n "...
method_declaration (+134 nodes collapsed)
block_comment "/**\n * Collapses definitions of the collapsible properties"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "collapseDeclarationOfNameAndDescendants"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
, ","
formal_parameter
type_identifier "String"
identifier "alias"
) ")"
block
{ "{"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "canCollapseChildNames"
= "="
method_invocation
identifier "n"
. "."
identifier "canCollapseUnannotatedChildNames"
argument_list
( "("
) ")"
; ";"
line_comment "// Handle this name first so that nested object literals get"...
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
method_invocation
identifier "n"
. "."
identifier "canCollapse"
argument_list
( "("
) ")"
&& "&&"
identifier "canCollapseChildNames"
) ")"
block
{ "{"
expression_statement
method_invocation
identifier "updateObjLitOrFunctionDeclaration"
argument_list
( "("
identifier "n"
, ","
identifier "alias"
) ")"
; ";"
} "}"
if_statement (+158 nodes collapsed)
} "}"
block_comment "/**\n * Updates the initial assignment to a collapsible pro"...
method_declaration (+448 nodes collapsed)
block_comment "/**\n * Updates the first initialization (a.k.a \"declaratio"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "updateObjLitOrFunctionDeclaration"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
, ","
formal_parameter
type_identifier "String"
identifier "alias"
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
field_access
identifier "n"
. "."
identifier "declaration"
== "=="
null_literal "null"
) ")"
block
{ "{"
line_comment "// Some names do not have declarations, because they"
line_comment "// are only defined in local scopes."
return_statement
return "return"
; ";"
} "}"
if_statement (+26 nodes collapsed)
switch_expression
switch "switch"
parenthesized_expression (+22 nodes collapsed)
switch_block
{ "{"
switch_block_statement_group
switch_label
case "case"
field_access
identifier "Token"
. "."
identifier "ASSIGN"
: ":"
expression_statement
method_invocation
identifier "updateObjLitOrFunctionDeclarationAtAssignNode"
argument_list
( "("
identifier "n"
, ","
identifier "alias"
) ")"
; ";"
break_statement
break "break"
; ";"
switch_block_statement_group
switch_label
case "case"
field_access
identifier "Token"
. "."
identifier "VAR"
: ":"
expression_statement
method_invocation
identifier "updateObjLitOrFunctionDeclarationAtVarNode"
argument_list
( "("
identifier "n"
) ")"
; ";"
break_statement
break "break"
; ";"
switch_block_statement_group
switch_label
case "case"
field_access
identifier "Token"
. "."
identifier "FUNCTION"
: ":"
expression_statement
method_invocation
identifier "updateFunctionDeclarationAtFunctionNode"
argument_list
( "("
identifier "n"
) ")"
; ";"
break_statement
break "break"
; ";"
} "}"
} "}"
block_comment "/**\n * Updates the first initialization (a.k.a \"declaratio"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "updateObjLitOrFunctionDeclarationAtAssignNode"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
, ","
formal_parameter
type_identifier "String"
identifier "alias"
) ")"
block
{ "{"
line_comment "// NOTE: It's important that we don't add additional nodes"
line_comment "// (e.g. a var node before the exprstmt) because the exprstm"...
line_comment "// the child of an if statement that's not inside a block)."
local_variable_declaration
type_identifier "Ref"
variable_declarator
identifier "ref"
= "="
field_access
identifier "n"
. "."
identifier "declaration"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "rvalue"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getNext"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "varNode"
= "="
object_creation_expression
new "new"
type_identifier "Node"
argument_list
( "("
field_access
identifier "Token"
. "."
identifier "VAR"
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "varParent"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getAncestor"
argument_list
( "("
decimal_integer_literal "3"
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "gramps"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getAncestor"
argument_list
( "("
decimal_integer_literal "2"
) ")"
; ";"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "isObjLit"
= "="
binary_expression
method_invocation
identifier "rvalue"
. "."
identifier "getType"
argument_list
( "("
) ")"
== "=="
field_access
identifier "Token"
. "."
identifier "OBJECTLIT"
; ";"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "insertedVarNode"
= "="
false "false"
; ";"
if_statement (+253 nodes collapsed)
if_statement (+34 nodes collapsed)
expression_statement
method_invocation
identifier "addStubsForUndeclaredProperties"
argument_list
( "("
identifier "n"
, ","
identifier "alias"
, ","
identifier "varParent"
, ","
identifier "varNode"
) ")"
; ";"
if_statement (+45 nodes collapsed)
} "}"
block_comment "/**\n * Warns about any references to \"this\" in the given F"...
method_declaration (+172 nodes collapsed)
block_comment "/**\n * Updates the first initialization (a.k.a \"declaratio"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "updateObjLitOrFunctionDeclarationAtVarNode"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
) ")"
block
{ "{"
local_variable_declaration
type_identifier "Ref"
variable_declarator
identifier "ref"
= "="
field_access
identifier "n"
. "."
identifier "declaration"
; ";"
local_variable_declaration
type_identifier "String"
variable_declarator
identifier "name"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getString"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "rvalue"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getFirstChild"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "varNode"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getParent"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "gramps"
= "="
method_invocation
identifier "varNode"
. "."
identifier "getParent"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "isObjLit"
= "="
binary_expression
method_invocation
identifier "rvalue"
. "."
identifier "getType"
argument_list
( "("
) ")"
== "=="
field_access
identifier "Token"
. "."
identifier "OBJECTLIT"
; ";"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "numChanges"
= "="
decimal_integer_literal "0"
; ";"
if_statement (+37 nodes collapsed)
expression_statement
assignment_expression
identifier "numChanges"
+= "+="
method_invocation
identifier "addStubsForUndeclaredProperties"
argument_list
( "("
identifier "n"
, ","
identifier "name"
, ","
identifier "gramps"
, ","
identifier "varNode"
) ")"
; ";"
if_statement (+74 nodes collapsed)
if_statement (+21 nodes collapsed)
} "}"
block_comment "/**\n * Updates the first initialization (a.k.a \"declaratio"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "updateFunctionDeclarationAtFunctionNode"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
) ")"
block
{ "{"
local_variable_declaration
type_identifier "Ref"
variable_declarator
identifier "ref"
= "="
field_access
identifier "n"
. "."
identifier "declaration"
; ";"
local_variable_declaration
type_identifier "String"
variable_declarator
identifier "fnName"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getString"
argument_list
( "("
) ")"
; ";"
expression_statement (+33 nodes collapsed)
} "}"
block_comment "/**\n * Declares global variables to serve as aliases for t"...
method_declaration (+662 nodes collapsed)
block_comment "/**\n * Adds global variable \"stubs\" for any properties of "...
method_declaration (+274 nodes collapsed)
method_declaration (+76 nodes collapsed)
} "}"

After

program
block_comment "/*\n * Copyright 2006 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 "base"
. "."
identifier "Predicates"
; ";"
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 "Sets"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "GlobalNamespace"
. "."
identifier "Name"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "GlobalNamespace"
. "."
identifier "Ref"
; ";"
import_declaration (+22 nodes collapsed)
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "ReferenceCollectingCallback"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "ReferenceCollectingCallback"
. "."
identifier "ReferenceCollection"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
. "."
identifier "Scope"
; ";"
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 "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 "Token"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "TokenStream"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "JSType"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "ArrayDeque"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Deque"
; ";"
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"
; ";"
block_comment "/**\n * Flattens global objects/namespaces by replacing each "...
class_declaration
class "class"
identifier "CollapseProperties"
super_interfaces
implements "implements"
type_list
type_identifier "CompilerPass"
class_body
{ "{"
line_comment "// Warnings"
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration (+25 nodes collapsed)
field_declaration
modifiers
private "private"
type_identifier "AbstractCompiler"
variable_declarator
identifier "compiler"
; ";"
block_comment "/** Global namespace tree */"
field_declaration
modifiers
private "private"
generic_type
type_identifier "List"
type_arguments
< "<"
type_identifier "Name"
> ">"
variable_declarator
identifier "globalNames"
; ";"
block_comment "/** Maps names (e.g. \"a.b.c\") to nodes in the global namespa"...
field_declaration
modifiers
private "private"
generic_type
type_identifier "Map"
type_arguments
< "<"
type_identifier "String"
, ","
type_identifier "Name"
> ">"
variable_declarator
identifier "nameMap"
; ";"
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "collapsePropertiesOnExternTypes"
; ";"
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "inlineAliases"
; ";"
block_comment "/**\n * Creates an instance.\n *\n * @param compiler The "...
constructor_declaration (+46 nodes collapsed)
method_declaration (+168 nodes collapsed)
block_comment "/**\n * For each qualified name N in the global scope, we c"...
method_declaration (+313 nodes collapsed)
method_declaration (+381 nodes collapsed)
block_comment "/**\n * Runs through all namespaces (prefixes of classes an"...
method_declaration (+199 nodes collapsed)
block_comment "/**\n * Reports a warning because a namespace was aliased.\n"...
method_declaration (+53 nodes collapsed)
block_comment "/**\n * Reports a warning because a namespace was redefined"...
method_declaration (+53 nodes collapsed)
block_comment "/**\n * Flattens all references to collapsible properties o"...
method_declaration (+99 nodes collapsed)
block_comment "/**\n * Flattens all references to a collapsible property o"...
method_declaration (+189 nodes collapsed)
block_comment "/**\n * Flattens all occurrences of a name as a prefix of s"...
method_declaration (+225 nodes collapsed)
block_comment "/**\n * Flattens a particular prefix of a single name refer"...
method_declaration (+189 nodes collapsed)
block_comment "/**\n * Replaces a GETPROP a.b.c with a NAME a$b$c.\n *\n "...
method_declaration (+134 nodes collapsed)
block_comment "/**\n * Collapses definitions of the collapsible properties"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "collapseDeclarationOfNameAndDescendants"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
, ","
formal_parameter
type_identifier "String"
identifier "alias"
) ")"
block
{ "{"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "canCollapseChildNames"
= "="
method_invocation
identifier "n"
. "."
identifier "canCollapseUnannotatedChildNames"
argument_list
( "("
) ")"
; ";"
line_comment "// Handle this name first so that nested object literals get"...
if_statement
if "if"
parenthesized_expression
( "("
method_invocation
identifier "n"
. "."
identifier "canCollapse"
argument_list
( "("
) ")"
) ")"
block
{ "{"
expression_statement
method_invocation
identifier "updateObjLitOrFunctionDeclaration"
argument_list
( "("
identifier "n"
, ","
identifier "alias"
, ","
identifier "canCollapseChildNames"
) ")"
; ";"
} "}"
if_statement (+158 nodes collapsed)
} "}"
block_comment "/**\n * Updates the initial assignment to a collapsible pro"...
method_declaration (+448 nodes collapsed)
block_comment "/**\n * Updates the first initialization (a.k.a \"declaratio"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "updateObjLitOrFunctionDeclaration"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
, ","
formal_parameter
type_identifier "String"
identifier "alias"
, ","
formal_parameter
boolean_type "boolean"
identifier "canCollapseChildNames"
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
field_access
identifier "n"
. "."
identifier "declaration"
== "=="
null_literal "null"
) ")"
block
{ "{"
line_comment "// Some names do not have declarations, because they"
line_comment "// are only defined in local scopes."
return_statement
return "return"
; ";"
} "}"
if_statement (+26 nodes collapsed)
switch_expression
switch "switch"
parenthesized_expression (+22 nodes collapsed)
switch_block
{ "{"
switch_block_statement_group
switch_label
case "case"
field_access
identifier "Token"
. "."
identifier "ASSIGN"
: ":"
expression_statement
method_invocation
identifier "updateObjLitOrFunctionDeclarationAtAssignNode"
argument_list
( "("
identifier "n"
, ","
identifier "alias"
, ","
identifier "canCollapseChildNames"
) ")"
; ";"
break_statement
break "break"
; ";"
switch_block_statement_group
switch_label
case "case"
field_access
identifier "Token"
. "."
identifier "VAR"
: ":"
expression_statement
method_invocation
identifier "updateObjLitOrFunctionDeclarationAtVarNode"
argument_list
( "("
identifier "n"
, ","
identifier "canCollapseChildNames"
) ")"
; ";"
break_statement
break "break"
; ";"
switch_block_statement_group
switch_label
case "case"
field_access
identifier "Token"
. "."
identifier "FUNCTION"
: ":"
expression_statement
method_invocation
identifier "updateFunctionDeclarationAtFunctionNode"
argument_list
( "("
identifier "n"
, ","
identifier "canCollapseChildNames"
) ")"
; ";"
break_statement
break "break"
; ";"
} "}"
} "}"
block_comment "/**\n * Updates the first initialization (a.k.a \"declaratio"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "updateObjLitOrFunctionDeclarationAtAssignNode"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
, ","
formal_parameter
type_identifier "String"
identifier "alias"
, ","
formal_parameter
boolean_type "boolean"
identifier "canCollapseChildNames"
) ")"
block
{ "{"
line_comment "// NOTE: It's important that we don't add additional nodes"
line_comment "// (e.g. a var node before the exprstmt) because the exprstm"...
line_comment "// the child of an if statement that's not inside a block)."
local_variable_declaration
type_identifier "Ref"
variable_declarator
identifier "ref"
= "="
field_access
identifier "n"
. "."
identifier "declaration"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "rvalue"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getNext"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "varNode"
= "="
object_creation_expression
new "new"
type_identifier "Node"
argument_list
( "("
field_access
identifier "Token"
. "."
identifier "VAR"
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "varParent"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getAncestor"
argument_list
( "("
decimal_integer_literal "3"
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "gramps"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getAncestor"
argument_list
( "("
decimal_integer_literal "2"
) ")"
; ";"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "isObjLit"
= "="
binary_expression
method_invocation
identifier "rvalue"
. "."
identifier "getType"
argument_list
( "("
) ")"
== "=="
field_access
identifier "Token"
. "."
identifier "OBJECTLIT"
; ";"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "insertedVarNode"
= "="
false "false"
; ";"
if_statement (+253 nodes collapsed)
if_statement
if "if"
parenthesized_expression
( "("
identifier "canCollapseChildNames"
) ")"
block
{ "{"
if_statement (+34 nodes collapsed)
expression_statement
method_invocation
identifier "addStubsForUndeclaredProperties"
argument_list
( "("
identifier "n"
, ","
identifier "alias"
, ","
identifier "varParent"
, ","
identifier "varNode"
) ")"
; ";"
} "}"
if_statement (+45 nodes collapsed)
} "}"
block_comment "/**\n * Warns about any references to \"this\" in the given F"...
method_declaration (+172 nodes collapsed)
block_comment "/**\n * Updates the first initialization (a.k.a \"declaratio"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "updateObjLitOrFunctionDeclarationAtVarNode"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
, ","
formal_parameter
boolean_type "boolean"
identifier "canCollapseChildNames"
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
unary_expression
! "!"
identifier "canCollapseChildNames"
) ")"
block
{ "{"
return_statement
return "return"
; ";"
} "}"
local_variable_declaration
type_identifier "Ref"
variable_declarator
identifier "ref"
= "="
field_access
identifier "n"
. "."
identifier "declaration"
; ";"
local_variable_declaration
type_identifier "String"
variable_declarator
identifier "name"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getString"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "rvalue"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getFirstChild"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "varNode"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getParent"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
type_identifier "Node"
variable_declarator
identifier "gramps"
= "="
method_invocation
identifier "varNode"
. "."
identifier "getParent"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
boolean_type "boolean"
variable_declarator
identifier "isObjLit"
= "="
binary_expression
method_invocation
identifier "rvalue"
. "."
identifier "getType"
argument_list
( "("
) ")"
== "=="
field_access
identifier "Token"
. "."
identifier "OBJECTLIT"
; ";"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "numChanges"
= "="
decimal_integer_literal "0"
; ";"
if_statement (+37 nodes collapsed)
expression_statement
assignment_expression
identifier "numChanges"
+= "+="
method_invocation
identifier "addStubsForUndeclaredProperties"
argument_list
( "("
identifier "n"
, ","
identifier "name"
, ","
identifier "gramps"
, ","
identifier "varNode"
) ")"
; ";"
if_statement (+74 nodes collapsed)
if_statement (+21 nodes collapsed)
} "}"
block_comment "/**\n * Updates the first initialization (a.k.a \"declaratio"...
method_declaration
modifiers
private "private"
void_type "void"
identifier "updateFunctionDeclarationAtFunctionNode"
formal_parameters
( "("
formal_parameter
type_identifier "Name"
identifier "n"
, ","
formal_parameter
boolean_type "boolean"
identifier "canCollapseChildNames"
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
unary_expression
! "!"
identifier "canCollapseChildNames"
) ")"
block
{ "{"
return_statement
return "return"
; ";"
} "}"
local_variable_declaration
type_identifier "Ref"
variable_declarator
identifier "ref"
= "="
field_access
identifier "n"
. "."
identifier "declaration"
; ";"
local_variable_declaration
type_identifier "String"
variable_declarator
identifier "fnName"
= "="
method_invocation
field_access
identifier "ref"
. "."
identifier "node"
. "."
identifier "getString"
argument_list
( "("
) ")"
; ";"
expression_statement (+33 nodes collapsed)
} "}"
block_comment "/**\n * Declares global variables to serve as aliases for t"...
method_declaration (+662 nodes collapsed)
block_comment "/**\n * Adds global variable \"stubs\" for any properties of "...
method_declaration (+274 nodes collapsed)
method_declaration (+76 nodes collapsed)
} "}"