Skip to content

Commit fe34746

Browse files
committed
externs inner namespaces fix
1 parent e61082a commit fe34746

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/com/google/javascript/rhino/jstype/JSType.java

+4
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ public boolean isBigIntValueType() {
210210
return false;
211211
}
212212

213+
public boolean isFromEmptyObjLitExtern() {
214+
return false;
215+
}
216+
213217
/** Whether this is the prototype of a function. */
214218
// TODO(sdh): consider renaming this to isPrototypeObject.
215219
public boolean isFunctionPrototypeType() {

src/com/google/javascript/rhino/jstype/JSTypeRegistry.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ private void registerNativeType(JSTypeNative typeId, JSType type) {
11101110
// we don't need to store these properties in the propertyIndex separately.
11111111
private static boolean isObjectLiteralThatCanBeSkipped(JSType t) {
11121112
t = t.restrictByNotNullOrUndefined();
1113-
return t.isRecordType() || t.isLiteralObject();
1113+
return (t.isRecordType() || t.isLiteralObject()) && !t.isFromEmptyObjLitExtern();
11141114
}
11151115

11161116
void registerDroppedPropertiesInUnion(RecordType subtype, RecordType supertype) {
@@ -1777,7 +1777,16 @@ public ObjectType createObjectType(String name, ObjectType implicitPrototype) {
17771777
* @param info Used to mark object literals as structs; can be {@code null}
17781778
*/
17791779
public ObjectType createAnonymousObjectType(@Nullable JSDocInfo info) {
1780-
PrototypeObjectType type = PrototypeObjectType.builder(this).setAnonymous(true).build();
1780+
PrototypeObjectType type = PrototypeObjectType.builder(this).setAnonymous(true).build();
1781+
type.setPrettyPrint(true);
1782+
type.setJSDocInfo(info);
1783+
return type;
1784+
}
1785+
public ObjectType createAnonymousObjectType(@Nullable JSDocInfo info, boolean fromExternsEmptyObjLit) {
1786+
PrototypeObjectType type = PrototypeObjectType.builder(this)
1787+
.setAnonymous(true)
1788+
.setFromExternsEmptyObjectLit(fromExternsEmptyObjLit)
1789+
.build();
17811790
type.setPrettyPrint(true);
17821791
type.setJSDocInfo(info);
17831792
return type;

src/com/google/javascript/rhino/jstype/PrototypeObjectType.java

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class PrototypeObjectType extends ObjectType {
7676
private final PropertyMap properties = new PropertyMap();
7777
private final boolean nativeType;
7878
private final boolean anonymousType;
79+
private boolean fromEmptyObjLitExtern;
7980

8081
// NOTE(nicksantos): The implicit prototype can change over time.
8182
// Modeling this is a bear. Always call getImplicitPrototype(), because
@@ -104,6 +105,7 @@ public class PrototypeObjectType extends ObjectType {
104105
this.templateParamCount = builder.templateParamCount;
105106
this.nativeType = builder.nativeType;
106107
this.anonymousType = builder.anonymousType;
108+
this.fromEmptyObjLitExtern = builder.externsEmptyObjLit;
107109

108110
this.properties.setParentSource(this);
109111

@@ -136,6 +138,7 @@ static class Builder<T extends Builder<T>> {
136138

137139
private boolean nativeType;
138140
private boolean anonymousType;
141+
private boolean externsEmptyObjLit;
139142

140143
private TemplateTypeMap templateTypeMap;
141144
private int templateParamCount;
@@ -166,6 +169,11 @@ final T setAnonymous(boolean x) {
166169
return castThis();
167170
}
168171

172+
final T setFromExternsEmptyObjectLit(boolean x) {
173+
this.externsEmptyObjLit = x;
174+
return castThis();
175+
}
176+
169177
final T setTemplateTypeMap(TemplateTypeMap x) {
170178
this.templateTypeMap = x;
171179
return castThis();
@@ -495,4 +503,8 @@ int recursionUnsafeHashCode() {
495503
return System.identityHashCode(this);
496504
}
497505
}
506+
507+
public boolean isFromEmptyObjLitExtern() {
508+
return fromEmptyObjLitExtern;
509+
}
498510
}

0 commit comments

Comments
 (0)