Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Externs inner namespaces fix #4069

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/com/google/javascript/jscomp/TypedScopeCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,9 @@ private void defineObjectLiteral(Node objectLit) {
}

if (type == null) {
type = typeRegistry.createAnonymousObjectType(info);
boolean isExterns = NodeUtil.getSourceFile(objectLit).isExtern();
boolean fromEmptyObjLit = objectLit.getFirstChild() == null;
type = typeRegistry.createAnonymousObjectType(info, isExterns && fromEmptyObjLit);
}

setDeferredType(objectLit, type);
Expand Down
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
11 changes: 10 additions & 1 deletion 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 @@ -1782,6 +1782,15 @@ public ObjectType createAnonymousObjectType(@Nullable JSDocInfo info) {
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;
}

/**
* Set the implicit prototype if it's possible to do so. There are a few different reasons why
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;
}
}