Skip to content

Commit

Permalink
externs inner namespaces fix
Browse files Browse the repository at this point in the history
  • Loading branch information
paidsource committed Mar 14, 2023
1 parent e61082a commit fe34746
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/com/google/javascript/rhino/jstype/JSType.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public boolean isBigIntValueType() {
return false;
}

public boolean isFromEmptyObjLitExtern() {
return false;
}

/** Whether this is the prototype of a function. */
// TODO(sdh): consider renaming this to isPrototypeObject.
public boolean isFunctionPrototypeType() {
Expand Down
13 changes: 11 additions & 2 deletions src/com/google/javascript/rhino/jstype/JSTypeRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ private void registerNativeType(JSTypeNative typeId, JSType type) {
// we don't need to store these properties in the propertyIndex separately.
private static boolean isObjectLiteralThatCanBeSkipped(JSType t) {
t = t.restrictByNotNullOrUndefined();
return t.isRecordType() || t.isLiteralObject();
return (t.isRecordType() || t.isLiteralObject()) && !t.isFromEmptyObjLitExtern();
}

void registerDroppedPropertiesInUnion(RecordType subtype, RecordType supertype) {
Expand Down Expand Up @@ -1777,7 +1777,16 @@ public ObjectType createObjectType(String name, ObjectType implicitPrototype) {
* @param info Used to mark object literals as structs; can be {@code null}
*/
public ObjectType createAnonymousObjectType(@Nullable JSDocInfo info) {
PrototypeObjectType type = PrototypeObjectType.builder(this).setAnonymous(true).build();
PrototypeObjectType type = PrototypeObjectType.builder(this).setAnonymous(true).build();
type.setPrettyPrint(true);
type.setJSDocInfo(info);
return type;
}
public ObjectType createAnonymousObjectType(@Nullable JSDocInfo info, boolean fromExternsEmptyObjLit) {
PrototypeObjectType type = PrototypeObjectType.builder(this)
.setAnonymous(true)
.setFromExternsEmptyObjectLit(fromExternsEmptyObjLit)
.build();
type.setPrettyPrint(true);
type.setJSDocInfo(info);
return type;
Expand Down
12 changes: 12 additions & 0 deletions src/com/google/javascript/rhino/jstype/PrototypeObjectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class PrototypeObjectType extends ObjectType {
private final PropertyMap properties = new PropertyMap();
private final boolean nativeType;
private final boolean anonymousType;
private boolean fromEmptyObjLitExtern;

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

this.properties.setParentSource(this);

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

private boolean nativeType;
private boolean anonymousType;
private boolean externsEmptyObjLit;

private TemplateTypeMap templateTypeMap;
private int templateParamCount;
Expand Down Expand Up @@ -166,6 +169,11 @@ final T setAnonymous(boolean x) {
return castThis();
}

final T setFromExternsEmptyObjectLit(boolean x) {
this.externsEmptyObjLit = x;
return castThis();
}

final T setTemplateTypeMap(TemplateTypeMap x) {
this.templateTypeMap = x;
return castThis();
Expand Down Expand Up @@ -495,4 +503,8 @@ int recursionUnsafeHashCode() {
return System.identityHashCode(this);
}
}

public boolean isFromEmptyObjLitExtern() {
return fromEmptyObjLitExtern;
}
}

0 comments on commit fe34746

Please sign in to comment.