Skip to content

Commit

Permalink
Rollback
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=156746868
  • Loading branch information
jeffcon authored and blickly committed May 22, 2017
1 parent b604ecf commit c870136
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 38 deletions.
8 changes: 6 additions & 2 deletions src/com/google/javascript/jscomp/newtypes/JSType.java
Expand Up @@ -1892,10 +1892,14 @@ public final Node getPropertyDefSite(String propertyName) {
return this.getObjTypeIfSingletonObj().getPropertyDefSite(propertyName);
}

/** Returns the names of all the properties directly on this type. */
@Override
public final Set<String> getOwnPropertyNames() {
public final Iterable<String> getOwnPropertyNames() {
Preconditions.checkState(this.isSingletonObj());
return getObjTypeIfSingletonObj().getOwnPropertyNames();
// TODO(aravindpg): this might need to also include the extra properties as stored in the
// ObjectType::props. If so, demonstrate a test case that needs it and fix this.
Set<String> props = getNominalTypeIfSingletonObj().getAllOwnClassProps();
return props;
}

@Override
Expand Down
Expand Up @@ -352,11 +352,9 @@ private boolean isUnionWithUndefined(Node n) {
return false;
}
for (Node child : n.children()) {
if (child.getToken() == Token.VOID) {
return true;
}
if (child.getToken() == Token.STRING
&& (child.getString().equals("void") || child.getString().equals("undefined"))) {
if (child.getToken() == Token.VOID
|| child.getToken() == Token.STRING
&& (child.getString().equals("void") || child.getString().equals("undefined"))) {
return true;
}
}
Expand Down Expand Up @@ -489,11 +487,6 @@ public void resolveTypedef(Typedef td, DeclaredTypeRegistry registry) {
tdType = this.commonTypes.UNKNOWN;
} else {
tdType = getTypeFromJSTypeExpression(texp, registry, null);
if (tdType.isSingletonObj()) {
for (String pname : tdType.getOwnPropertyNames()) {
this.recordPropertyName.apply(pname);
}
}
}
td.resolveTypedef(tdType);
}
Expand Down Expand Up @@ -854,7 +847,7 @@ private DeclaredFunctionType getFunTypeFromTypicalFunctionJsdoc(
return builder.buildDeclaration();
} else if (jsdoc.isConstructor()) {
handleConstructorAnnotation(functionName, funNode, constructorType,
parentClass, implementedIntfs, builder);
parentClass, implementedIntfs, registry, builder);
} else if (jsdoc.isInterface()) {
handleInterfaceAnnotation(jsdoc, functionName, funNode, constructorType,
implementedIntfs, typeParameters, registry, builder);
Expand Down Expand Up @@ -1009,7 +1002,7 @@ private NominalType getMaybeHigherOrderParentClass(Node docNode, String function
private void handleConstructorAnnotation(
String functionName, Node funNode, RawNominalType constructorType,
NominalType parentClass, ImmutableSet<NominalType> implementedIntfs,
FunctionTypeBuilder builder) {
DeclaredTypeRegistry registry, FunctionTypeBuilder builder) {
String className = constructorType.toString();
NominalType builtinObject = this.commonTypes.getObjectType();
if (parentClass == null && !functionName.equals("Object")) {
Expand Down
7 changes: 0 additions & 7 deletions src/com/google/javascript/jscomp/newtypes/ObjectType.java
Expand Up @@ -1197,13 +1197,6 @@ Node getPropertyDefSiteHelper(String propertyName, boolean ownProp) {
return p == null ? null : p.getDefSite();
}

Set<String> getOwnPropertyNames() {
ImmutableSet.Builder<String> s = ImmutableSet.builder();
s.addAll(this.nominalType.getAllOwnClassProps());
s.addAll(this.props.keySet());
return s.build();
}

@Override
public boolean mayHaveProp(QualifiedName qname) {
Property p = getLeftmostProp(qname);
Expand Down
8 changes: 1 addition & 7 deletions src/com/google/javascript/rhino/ObjectTypeI.java
Expand Up @@ -41,7 +41,6 @@

import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.Set;

/**
* @author blickly@google.com (Ben Lickly)
Expand Down Expand Up @@ -103,12 +102,7 @@ public interface ObjectTypeI extends TypeI {

boolean hasOwnProperty(String propertyName);

/**
* Returns the names of all properties defined on the instance: properties that exist on
* all instances of this type plus any extras that exist only on this instance.
* Does not return prototype properties, or properties of ancestor types.
*/
Set<String> getOwnPropertyNames();
Iterable<String> getOwnPropertyNames();

/**
* Works around the OTI distinction between prototype-object types and other objects.
Expand Down
10 changes: 0 additions & 10 deletions test/com/google/javascript/jscomp/NewTypeInferenceTest.java
Expand Up @@ -20399,14 +20399,4 @@ public void testLocalWindowDontCrash() {
" };",
"}"));
}

public void testRegisterPropertyOfTypedef() {
typeCheck(LINE_JOINER.join(
"/** @typedef {{p1: number}} */",
"var MyType;",
"function f(x) {",
" x = /** @type {MyType} */ (x);",
" return x.p1;",
"}"));
}
}

0 comments on commit c870136

Please sign in to comment.