Skip to content

Commit

Permalink
[NTI] Support JSTypeCreatorFromJSDoc accessing local namespaces post …
Browse files Browse the repository at this point in the history
…finalization.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130323403
  • Loading branch information
aravind-pg authored and blickly committed Aug 15, 2016
1 parent d359ff8 commit 74c0c3d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/com/google/javascript/jscomp/NTIScope.java
Expand Up @@ -35,7 +35,6 @@
import com.google.javascript.jscomp.newtypes.Typedef;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.Node;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -592,8 +591,15 @@ private Declaration getLocalDeclaration(String name, boolean includeTypes) {
} else if (externs.containsKey(name)) {
type = externs.get(name);
}
Namespace ns = null;
if (localNamespaces.containsKey(name)) {
ns = localNamespaces.get(name);
} else if (preservedNamespaces != null) {
ns = preservedNamespaces.get(name);
}

return new Declaration(type, localTypedefs.get(name),
localNamespaces.get(name), localFunDefs.get(name), isTypeVar,
ns, localFunDefs.get(name), isTypeVar,
constVars.contains(name));
}

Expand Down
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/newtypes/Declaration.java
Expand Up @@ -47,7 +47,7 @@ public Declaration(JSType simpleType, Typedef typedef, Namespace ns,

private void checkValid() {
if (this.simpleType != null) {
Preconditions.checkState(this.typedef == null && this.ns == null);
Preconditions.checkState(this.typedef == null);
}
if (this.typedef != null) {
Preconditions.checkState(
Expand All @@ -56,7 +56,7 @@ private void checkValid() {
if (this.ns != null) {
// Note: Non-null nominal with null function is allowed,
// e.g., /** @constructor */ var Bar = Foo;
Preconditions.checkState(this.simpleType == null && this.typedef == null);
Preconditions.checkState(this.typedef == null);
}
if (this.funScope != null) {
Preconditions.checkState(this.typedef == null);
Expand Down
5 changes: 0 additions & 5 deletions test/com/google/javascript/jscomp/CheckConformanceTest.java
Expand Up @@ -867,9 +867,6 @@ public void testRestrictedMethodCallThisType() {
+ "var maybeB = cond ? new Base() : null;\n"
+ "var maybeS = cond ? new Sub() : null;\n";

// TODO(aravindpg): Fix in NTI. Make "function(this:Sub)" parse to `function(this:Sub)`
// instead of `function(this:?)`.
this.mode = TypeInferenceMode.OTI_ONLY;
testSame(code + "b.m(1)", CheckConformance.CONFORMANCE_VIOLATION);
testSame(code + "maybeB.m(1)", CheckConformance.CONFORMANCE_VIOLATION);
testSame(code + "s.m(1)");
Expand All @@ -894,8 +891,6 @@ public void testRestrictedMethodCallUsingCallThisType() {
+ "var maybeB = cond ? new Base() : null;\n"
+ "var maybeS = cond ? new Sub() : null;";

// TODO(aravindpg): Fix in NTI.
this.mode = TypeInferenceMode.OTI_ONLY;
testSame(code + "b.m.call(b, 1)", CheckConformance.CONFORMANCE_VIOLATION);
testSame(code + "b.m.call(maybeB, 1)", CheckConformance.CONFORMANCE_VIOLATION);
testSame(code + "b.m.call(s, 1)");
Expand Down

0 comments on commit 74c0c3d

Please sign in to comment.