Skip to content

Commit

Permalink
Add tests to repro issues around interface properties declared in ES6…
Browse files Browse the repository at this point in the history
… class constructor.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=246273225
  • Loading branch information
gkdn authored and brad4d committed May 2, 2019
1 parent 92541e5 commit f65e40c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/com/google/javascript/jscomp/DisambiguatePropertiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.TreeMap;
import java.util.TreeSet;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -1314,6 +1315,34 @@ public void testInterface() {
testSets(js, "{a=[[Foo.prototype, I.prototype]]}");
}

// TODO(b/131257037): Support ES6 style instance properties on interfaces.
@Ignore
@Test
public void testInterface_es6() {
testSets(
lines(
"/** @interface */ class I { constructor(){ this.a; } };",
"/** @implements {I} */ class Foo {};",
"Foo.prototype.a;",
"/** @type {I} */",
"var f = new Foo;",
"var x = f.a;"),
"{a=[[Foo.prototype, I.prototype]]}");
}

@Test
public void testInterface_es6withTypeDeclaration() {
testSets(
lines(
"/** @interface */ class I { constructor(){ /** @type {number} */ this.a; } };",
"/** @implements {I} */ class Foo {};",
"Foo.prototype.a;",
"/** @type {I} */",
"var f = new Foo;",
"var x = f.a;"),
"{a=[[Foo.prototype, I.prototype]]}");
}

@Test
public void testInterface_noDirectImplementors() {
String js = ""
Expand Down
44 changes: 44 additions & 0 deletions test/com/google/javascript/jscomp/TypeCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6171,6 +6171,50 @@ public void testGetprop4() {
"required: Object");
}

@Test
public void testGetrop_interfaceWithoutTypeDeclaration() {
testTypes(
lines(
"/** @interface */var I = function() {};",
// Note that we didn't declare the type but we still expect JsCompiler to recognize the
// property.
"I.prototype.foo;",
"var v = /** @type {I} */ (null); ",
"v.foo = 5;"));
}

@Test
public void testGetrop_interfaceEs6WithoutTypeDeclaration() {
testTypes(
lines(
"/** @interface */",
"class I {",
" constructor() {",
" this.foo;",
" }",
"}",
"var v = /** @type {I} */ (null); ",
"v.foo = 5;"),
// TODO(b/131257037): Support ES6 style instance properties on interfaces.
new String[] {
"Property foo never defined on I", ILLEGAL_PROPERTY_CREATION_MESSAGE,
});
}

@Test
public void testGetrop_interfaceEs6WithTypeDeclaration() {
testTypes(
lines(
"/** @interface */",
"class I {",
" constructor() {",
" /** @type {number} */ this.foo;",
" }",
"}",
"var v = /** @type {I} */ (null); ",
"v.foo = 5;"));
}

@Test
public void testSetprop1() {
// Create property on struct in the constructor
Expand Down

0 comments on commit f65e40c

Please sign in to comment.