Skip to content

Commit

Permalink
Add special case for prototype in AmbiguateProperties
Browse files Browse the repository at this point in the history
Closes #2885
Closes #2888

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=193225397
  • Loading branch information
Yannic authored and blickly committed Apr 17, 2018
1 parent 63428a2 commit 5823a05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/com/google/javascript/jscomp/AmbiguateProperties.java
Expand Up @@ -87,7 +87,7 @@ class AmbiguateProperties implements CompilerPass {
private final Map<String, Property> propertyMap = new HashMap<>();

/** Property names that don't get renamed */
private final Set<String> externedNames;
private final ImmutableSet<String> externedNames;

/** Names to which properties shouldn't be renamed, to avoid name conflicts */
private final Set<String> quotedNames = new HashSet<>();
Expand Down Expand Up @@ -140,7 +140,11 @@ public int compare(Property p1, Property p2) {
.addAllTypeMismatches(compiler.getImplicitInterfaceUses())
.build();

this.externedNames = compiler.getExternProperties();
this.externedNames =
ImmutableSet.<String>builder()
.add("prototype")
.addAll(compiler.getExternProperties())
.build();
}

static AmbiguateProperties makePassForTesting(
Expand Down
18 changes: 18 additions & 0 deletions test/com/google/javascript/jscomp/AmbiguatePropertiesTest.java
Expand Up @@ -1144,4 +1144,22 @@ public void testDontInvalidateParameterizedObjectTypes() {
this.mode = TypeInferenceMode.NTI_ONLY;
test(js, output);
}

public void testDontRenamePrototypeWithoutExterns() {
String js = lines(
"/** @interface */",
"function Foo() {}",
"/** @return {!Foo} */",
"Foo.prototype.foo = function() {};");

String output = lines(
"/** @interface */",
"function Foo() {}",
"/** @return {!Foo} */",
"Foo.prototype.a = function() {};");

// NTI reqires at least the MINIMAL_EXTERNS.
this.mode = TypeInferenceMode.OTI_ONLY;
test(externs(""), srcs(js), expected(output));
}
}

0 comments on commit 5823a05

Please sign in to comment.