merge with extendsExpressions

This commit is contained in:
Arthur Ozga
2015-06-16 13:33:03 -07:00
155 changed files with 1751 additions and 875 deletions

View File

@@ -0,0 +1,10 @@
class C1 extends Object { }
class C2 extends Function { }
class C3 extends String { }
class C4 extends Boolean { }
class C5 extends Number { }
class C6 extends Date { }
class C7 extends RegExp { }
class C8 extends Error { }
class C9 extends Array { }
class C10 extends Array<number> { }

View File

@@ -0,0 +1,57 @@
interface Base<T, U> {
x: T;
y: U;
}
// Error, no Base constructor function
class D0 extends Base<string, string> {
}
interface BaseConstructor {
new (x: string, y: string): Base<string, string>;
new <T>(x: T): Base<T, T>;
new <T>(x: T, y: T): Base<T, T>;
new <T, U>(x: T, y: U): Base<T, U>;
}
declare function getBase(): BaseConstructor;
class D1 extends getBase() {
constructor() {
super("abc", "def");
this.x = "x";
this.y = "y";
}
}
class D2 extends getBase() <number> {
constructor() {
super(10);
super(10, 20);
this.x = 1;
this.y = 2;
}
}
class D3 extends getBase() <string, number> {
constructor() {
super("abc", 42);
this.x = "x";
this.y = 2;
}
}
// Error, no constructors with three type arguments
class D4 extends getBase() <string, string, string> {
}
interface BadBaseConstructor {
new (x: string): Base<string, string>;
new (x: number): Base<number, number>;
}
declare function getBadBase(): BadBaseConstructor;
// Error, constructor return types differ
class D5 extends getBadBase() {
}

View File

@@ -0,0 +1,13 @@
var x: {};
function foo() {
this.x = 1;
}
class C1 extends undefined { }
class C2 extends true { }
class C3 extends false { }
class C4 extends 42 { }
class C5 extends "hello" { }
class C6 extends x { }
class C7 extends foo { }

View File

@@ -0,0 +1,2 @@
class C1 extends null { }
class C2 extends (null) { }

View File

@@ -252,11 +252,6 @@ module ts {
});
it('Strict mode 1',() => {
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
//
// Note: in this test we don't actually add 'use strict'. This is so we can compare
// reuse with/without a strict mode change.
var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();";
var oldText = ScriptSnapshot.fromString(source);
@@ -266,23 +261,15 @@ module ts {
});
it('Strict mode 2',() => {
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();";
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withInsert(oldText, 0, "'use strict';\r\n");
// Note the decreased reuse of nodes compared to 'Strict mode 1'
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 9);
});
it('Strict mode 3',() => {
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
//
// Note: in this test we don't actually remove 'use strict'. This is so we can compare
// reuse with/without a strict mode change.
var source = "'strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();";
var index = source.indexOf('f');
@@ -293,16 +280,13 @@ module ts {
});
it('Strict mode 4',() => {
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
var source = "'use strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();";
var index = source.indexOf('f');
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withDelete(oldText, 0, index);
// Note the decreased reuse of nodes compared to testStrictMode3
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 9);
});
it('Strict mode 5',() => {
@@ -312,7 +296,7 @@ module ts {
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, index, 6, "strict");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 27);
});
it('Strict mode 6',() => {
@@ -322,7 +306,7 @@ module ts {
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, index, 6, "blahhh");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 27);
});
it('Strict mode 7',() => {
@@ -492,7 +476,6 @@ module ts {
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, index, ": Foo<Bar<".length, "= ");
// Note the decreased reuse of nodes compared to testStrictMode3
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});
@@ -545,7 +528,7 @@ module ts {
var index = source.lastIndexOf(";");
var newTextAndChange = withDelete(oldText, index, 1);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 11);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 14);
});
it('Edit after empty type parameter list',() => {
@@ -555,7 +538,7 @@ module ts {
var index = source.length;
var newTextAndChange = withInsert(oldText, index, "var x;");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 2);
});
it('Delete parameter after comment',() => {
@@ -595,7 +578,7 @@ constructor(name) { }\
var index = source.indexOf("100");
var newTextAndChange = withInsert(oldText, index, "'1', ");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 5);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 7);
});
it('Insert declare modifier before module',() => {
@@ -718,7 +701,7 @@ module m3 { }\
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code.
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4);
});
it('Moving methods from object literal to class in strict mode', () => {
@@ -736,7 +719,7 @@ module m3 { }\
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "class".length, "interface");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code.
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18);
});
it('Moving index signatures from class to interface in strict mode', () => {
@@ -754,7 +737,7 @@ module m3 { }\
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "interface".length, "class");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code.
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18);
});
@@ -782,7 +765,7 @@ module m3 { }\
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code.
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4);
});