Skip to content

Commit

Permalink
Allow window.Math to be folded to just Math
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124744949
  • Loading branch information
kevinoconnor7 authored and blickly committed Jun 13, 2016
1 parent e29bcdb commit fbfd639
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -118,11 +118,12 @@ public Node optimizeSubtree(Node node) {
} }
} }


private static final ImmutableSet<String> BUILTIN_TYPES = ImmutableSet.of( private static final ImmutableSet<String> BUILTIN_EXTERNS = ImmutableSet.of(
"Object", "Object",
"Array", "Array",
"Error", "Error",
"RegExp"); "RegExp",
"Math");


private Node tryMinimizeWindowRefs(Node node) { private Node tryMinimizeWindowRefs(Node node) {
// Normalization needs to be done to ensure there's no shadowing. The window prefix is also // Normalization needs to be done to ensure there's no shadowing. The window prefix is also
Expand All @@ -139,7 +140,7 @@ private Node tryMinimizeWindowRefs(Node node) {


// Since normalization has run we know we're referring to the global window. // Since normalization has run we know we're referring to the global window.
if ("window".equals(nameNode.getString()) if ("window".equals(nameNode.getString())
&& BUILTIN_TYPES.contains(stringNode.getString())) { && BUILTIN_EXTERNS.contains(stringNode.getString())) {
Node newNameNode = IR.name(stringNode.getString()); Node newNameNode = IR.name(stringNode.getString());
Node parentNode = node.getParent(); Node parentNode = node.getParent();


Expand Down
Expand Up @@ -261,6 +261,7 @@ public void testRemoveWindowRefs() {
fold("x = window.Array", "x = Array"); fold("x = window.Array", "x = Array");
fold("x = window.Error", "x = Error"); fold("x = window.Error", "x = Error");
fold("x = window.RegExp", "x = RegExp"); fold("x = window.RegExp", "x = RegExp");
fold("x = window.Math", "x = Math");


// Not currently handled by the pass but should be folded in the future. // Not currently handled by the pass but should be folded in the future.
foldSame("x = window.String"); foldSame("x = window.String");
Expand Down

0 comments on commit fbfd639

Please sign in to comment.