Skip to content

Commit

Permalink
Rollback "Fix AggressiveInlineAliases bug with class static properties."
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178309275
  • Loading branch information
brad4d authored and blickly committed Dec 8, 2017
1 parent a76c1c6 commit d45edd5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/com/google/javascript/jscomp/AggressiveInlineAliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ private void rewriteAliasProp(Node value, int depth, Set<AstChange> newNodes, Na
prop.removeRef(ref);
// Rescan the expression root.
newNodes.add(new AstChange(ref.module, ref.scope, ref.node));
codeChanged = true;
}
}

Expand Down Expand Up @@ -197,9 +196,7 @@ private void inlineAliases(GlobalNamespace namespace) {

// Check if {@code name} has any aliases left after the
// local-alias-inlining above.
if ((name.type == Name.Type.OBJECTLIT
|| name.type == Name.Type.FUNCTION
|| name.type == Name.Type.CLASS)
if ((name.type == Name.Type.OBJECTLIT || name.type == Name.Type.FUNCTION)
&& name.aliasingGets == 0
&& name.props != null) {
// All of {@code name}'s children meet condition (a), so they can be
Expand Down Expand Up @@ -313,13 +310,16 @@ private boolean inlineAliasIfPossible(Name name, Ref alias, GlobalNamespace name

Var aliasVar = alias.scope.getVar(aliasVarName);
checkState(aliasVar != null, "Expected variable to be defined in scope", aliasVarName);
Node aliasDeclarationParent = aliasVar.getParentNode();
Scope scope =
aliasDeclarationParent.isVar() ? alias.scope.getClosestHoistScope() : alias.scope;
ReferenceCollectingCallback collector =
new ReferenceCollectingCallback(
compiler,
ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR,
new Es6SyntacticScopeCreator(compiler),
Predicates.equalTo(aliasVar));
collector.processScope(aliasVar.getScope());
collector.processScope(scope);

ReferenceCollection aliasRefs = collector.getReferences(aliasVar);
Set<AstChange> newNodes = new LinkedHashSet<>();
Expand Down
20 changes: 3 additions & 17 deletions test/com/google/javascript/jscomp/AggressiveInlineAliasesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1285,23 +1285,9 @@ public void testAliasForSuperclass_withStaticInheritance() {
"use(Foo.baz);"));
}

public void testStaticInheritance_superclassIsStaticProperty() {
test(
lines(
"class Foo {}",
"Foo.Builder = class {}",
"Foo.Builder.baz = 3;",
"var Bar = class extends Foo.Builder {}",
"use(Bar.baz);"),
lines(
"class Foo {}",
"Foo.Builder = class {}",
"Foo.Builder.baz = 3;",
"var Bar = class extends Foo.Builder {}",
"use(Foo.Builder.baz);"));
}

public void testAliasForSuperclassNamespace_withStaticInheritance() {
// TODO(lharker): The last line should be "use(Foo.baz);"
// Make sure GlobalNamespace correctly handles aliases for superclasses.
test(
lines(
"var ns = {};",
Expand All @@ -1318,6 +1304,6 @@ public void testAliasForSuperclassNamespace_withStaticInheritance() {
"Foo.Builder.baz = 3;",
"ns.clazz = null;",
"var Bar = class extends Foo.Builder {}",
"use(Foo.Builder.baz);"));
"use(Bar.baz);"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ public void testAliasForSuperclassNamespace() {
}

public void testAliasForSuperclassNamespace_withStaticInheritance() {
// TODO(lharker): The last line should be "use(Foo$Builder$baz);".
test(
lines(
"var ns = {};",
Expand All @@ -1250,7 +1251,7 @@ public void testAliasForSuperclassNamespace_withStaticInheritance() {
"var Foo$Builder$baz = 3;",
"var ns$clazz = null;",
"var Bar = class extends Foo$Builder {}",
"use(Foo$Builder$baz);"));
"use(Bar.baz);"));
}

public void testDestructuringAlias1() {
Expand Down

0 comments on commit d45edd5

Please sign in to comment.