merge with master

This commit is contained in:
Vladimir Matveev
2015-10-01 14:05:10 -07:00
311 changed files with 5842 additions and 2976 deletions

View File

@@ -0,0 +1,10 @@
// @module: amd
// @filename: external.d.ts
export var x: number
// @filename: main.ts
declare module "M" {
export {x} from "external"
}

View File

@@ -0,0 +1,10 @@
// @module: amd
// @filename: external.d.ts
export default class C {}
// @filename: main.ts
declare module "M" {
export * from "external"
}

View File

@@ -0,0 +1,10 @@
// @module: amd
// @filename: external.d.ts
export var x: number
// @filename: main.ts
declare module "M" {
import {x} from "external"
}

View File

@@ -0,0 +1,10 @@
// @module: amd
// @filename: external.d.ts
export default class C {}
// @filename: main.ts
declare module "M" {
import C from "external"
}

View File

@@ -0,0 +1,10 @@
// @module: amd
// @filename: external.d.ts
export default class C {}
// @filename: main.ts
declare module "M" {
import C = require("external");
}

View File

@@ -0,0 +1,11 @@
//@module: commonjs
//@filename: foo.ts
export function foo() { }
//@filename: bar.ts
import { foo } from './foo';
// These should emit identically
<any>foo;
(foo as any);

View File

@@ -0,0 +1,8 @@
//@filename: file.tsx
//@jsx: preserve
declare module JSX {
interface Element { }
interface IntrinsicElements { div; span; }
}
var x = </**/div></div>;

View File

@@ -0,0 +1,14 @@
interface X {
a: (p: this) => this;
}
interface Y extends X {
}
var x: Y = {
a(p) {
return p;
}
}
var y = x.a(x);

View File

@@ -0,0 +1,48 @@
// @declaration: true
class C1 {
x: this;
f(x: this): this { return undefined; }
constructor(x: this) { }
}
class C2 {
[x: string]: this;
}
interface Foo<T> {
x: T;
y: this;
}
class C3 {
a: this[];
b: [this, this];
c: this | Date;
d: this & Date;
e: (((this)));
f: (x: this) => this;
g: new (x: this) => this;
h: Foo<this>;
i: Foo<this | (() => this)>;
j: (x: any) => x is this;
}
class C4 {
x1 = { a: this };
x2 = [this];
x3 = [{ a: this }];
x4 = () => this;
f1() {
return { a: this };
}
f2() {
return [this];
}
f3() {
return [{ a: this }];
}
f4() {
return () => this;
}
}

View File

@@ -0,0 +1,17 @@
class A {
foo() {
return this;
}
}
class B extends A {
bar() {
return this;
}
}
class C extends B {
baz() {
return this;
}
}
var c: C;
var z = c.foo().bar().baz(); // Fluent pattern

View File

@@ -0,0 +1,11 @@
interface A {
foo(): this;
}
interface B extends A {
bar(): this;
}
interface C extends B {
baz(): this;
}
var c: C;
var z = c.foo().bar().baz(); // Fluent pattern

View File

@@ -0,0 +1,55 @@
var x1: this;
var x2: { a: this };
var x3: this[];
function f1(x: this): this {
var y: this;
return this;
}
interface I1 {
a: { x: this };
b: { (): this };
c: { new (): this };
d: { [x: string]: this };
e: { f(x: this): this };
}
class C1 {
a: { x: this };
b: { (): this };
c: { new (): this };
d: { [x: string]: this };
e: { f(x: this): this };
}
class C2 {
static x: this;
static y = <this>undefined;
static foo(x: this): this {
return undefined;
}
}
namespace N1 {
export var x: this;
export var y = this;
}
class C3 {
x1 = {
g(x: this): this {
return undefined;
}
}
f() {
function g(x: this): this {
return undefined;
}
let x2 = {
h(x: this): this {
return undefined;
}
}
}
}

View File

@@ -0,0 +1,50 @@
class C1 {
x: this;
f(x: this): this { return undefined; }
constructor(x: this) { }
}
class C2 {
[x: string]: this;
}
interface Foo<T> {
x: T;
y: this;
}
class C3 {
a: this[];
b: [this, this];
c: this | Date;
d: this & Date;
e: (((this)));
f: (x: this) => this;
g: new (x: this) => this;
h: Foo<this>;
i: Foo<this | (() => this)>;
j: (x: any) => x is this;
}
declare class C4 {
x: this;
f(x: this): this;
}
class C5 {
foo() {
let f1 = (x: this): this => this;
let f2 = (x: this) => this;
let f3 = (x: this) => (y: this) => this;
let f4 = (x: this) => {
let g = (y: this) => {
return () => this;
}
return g(this);
}
}
bar() {
let x1 = <this>undefined;
let x2 = undefined as this;
}
}

View File

@@ -0,0 +1,28 @@
interface I1 {
x: this;
f(x: this): this;
}
interface I2 {
(x: this): this;
new (x: this): this;
[x: string]: this;
}
interface Foo<T> {
x: T;
y: this;
}
interface I3 {
a: this[];
b: [this, this];
c: this | Date;
d: this & Date;
e: (((this)));
f: (x: this) => this;
g: new (x: this) => this;
h: Foo<this>;
i: Foo<this | (() => this)>;
j: (x: any) => x is this;
}

View File

@@ -0,0 +1,8 @@
interface Array<T> {
slice(): this;
}
let t: [number, string] = [42, "hello"];
let a = t.slice();
let b = t.slice(1);
let c = t.slice(0, 1);

View File

@@ -0,0 +1,39 @@
class C {
self = this;
c = new C();
foo() {
return this;
}
f1() {
this.c = this.self;
this.self = this.c; // Error
}
f2() {
var a: C[];
var a = [this, this.c]; // C[] since this is subtype of C
var b: this[];
var b = [this, this.self, null, undefined];
}
f3(b: boolean) {
return b ? this.c : this.self; // Should be C
}
}
class D extends C {
self1 = this;
self2 = this.self;
self3 = this.foo();
d = new D();
bar() {
this.self = this.self1;
this.self = this.self2;
this.self = this.self3;
this.self1 = this.self;
this.self2 = this.self;
this.self3 = this.self;
this.d = this.self;
this.d = this.c; // Error
this.self = this.d; // Error
this.c = this.d;
}
}

View File

@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />
//// type T = number;
//// var x;
//// var y = x as /**/
goTo.marker();
verify.completionListContains('T');

View File

@@ -482,8 +482,8 @@ verify.quickInfoIs("(method) c.prop1(a: number): number (+1 overload)", "");
goTo.marker('46');
verify.currentSignatureHelpDocCommentIs("");
verify.currentParameterHelpArgumentDocCommentIs("");
goTo.marker('46q');
verify.quickInfoIs("(method) c.prop1(b: string): number (+1 overload)", "");
//goTo.marker('46q');
//verify.quickInfoIs("(method) c.prop1(b: string): number (+1 overload)", "");
goTo.marker('47');
verify.currentSignatureHelpDocCommentIs("prop2 1");
@@ -494,8 +494,8 @@ verify.quickInfoIs("(method) c.prop2(a: number): number (+1 overload)", "prop2 1
goTo.marker('48');
verify.currentSignatureHelpDocCommentIs("");
verify.currentParameterHelpArgumentDocCommentIs("");
goTo.marker('48q');
verify.quickInfoIs("(method) c.prop2(b: string): number (+1 overload)", "");
//goTo.marker('48q');
//verify.quickInfoIs("(method) c.prop2(b: string): number (+1 overload)", "");
goTo.marker('49');
verify.currentSignatureHelpDocCommentIs("");
@@ -506,8 +506,8 @@ verify.quickInfoIs("(method) c.prop3(a: number): number (+1 overload)", "");
goTo.marker('50');
verify.currentSignatureHelpDocCommentIs("prop3 2");
verify.currentParameterHelpArgumentDocCommentIs("");
goTo.marker('50q');
verify.quickInfoIs("(method) c.prop3(b: string): number (+1 overload)", "prop3 2");
//goTo.marker('50q');
//verify.quickInfoIs("(method) c.prop3(b: string): number (+1 overload)", "prop3 2");
goTo.marker('51');
verify.currentSignatureHelpDocCommentIs("prop4 1");
@@ -518,8 +518,8 @@ verify.quickInfoIs("(method) c.prop4(a: number): number (+1 overload)", "prop4 1
goTo.marker('52');
verify.currentSignatureHelpDocCommentIs("prop4 2");
verify.currentParameterHelpArgumentDocCommentIs("");
goTo.marker('52q');
verify.quickInfoIs("(method) c.prop4(b: string): number (+1 overload)", "prop4 2");
//goTo.marker('52q');
//verify.quickInfoIs("(method) c.prop4(b: string): number (+1 overload)", "prop4 2");
goTo.marker('53');
verify.currentSignatureHelpDocCommentIs("prop5 1");
@@ -530,8 +530,8 @@ verify.quickInfoIs("(method) c.prop5(a: number): number (+1 overload)", "prop5 1
goTo.marker('54');
verify.currentSignatureHelpDocCommentIs("prop5 2");
verify.currentParameterHelpArgumentDocCommentIs("");
goTo.marker('54q');
verify.quickInfoIs("(method) c.prop5(b: string): number (+1 overload)", "prop5 2");
//goTo.marker('54q');
//verify.quickInfoIs("(method) c.prop5(b: string): number (+1 overload)", "prop5 2");
goTo.marker('55');
verify.currentSignatureHelpDocCommentIs("");

View File

@@ -31,15 +31,15 @@
// Same class, everything is visible
goTo.marker("1");
verify.memberListContains('privateMethod');
verify.memberListContains('privateProperty');
verify.memberListContains('protectedMethod');
verify.memberListContains('protectedProperty');
verify.memberListContains('publicMethod');
verify.memberListContains('publicProperty');
verify.memberListContains('protectedOverriddenMethod');
verify.memberListContains('protectedOverriddenProperty');
//goTo.marker("1");
//verify.memberListContains('privateMethod');
//verify.memberListContains('privateProperty');
//verify.memberListContains('protectedMethod');
//verify.memberListContains('protectedProperty');
//verify.memberListContains('publicMethod');
//verify.memberListContains('publicProperty');
//verify.memberListContains('protectedOverriddenMethod');
//verify.memberListContains('protectedOverriddenProperty');
goTo.marker("2");
verify.memberListContains('privateMethod');

View File

@@ -32,15 +32,15 @@
// Same class, everything is visible
goTo.marker("1");
verify.not.memberListContains('privateMethod');
verify.not.memberListContains('privateProperty');
verify.memberListContains('protectedMethod');
verify.memberListContains('protectedProperty');
verify.memberListContains('publicMethod');
verify.memberListContains('publicProperty');
verify.memberListContains('protectedOverriddenMethod');
verify.memberListContains('protectedOverriddenProperty');
//goTo.marker("1");
//verify.not.memberListContains('privateMethod');
//verify.not.memberListContains('privateProperty');
//verify.memberListContains('protectedMethod');
//verify.memberListContains('protectedProperty');
//verify.memberListContains('publicMethod');
//verify.memberListContains('publicProperty');
//verify.memberListContains('protectedOverriddenMethod');
//verify.memberListContains('protectedOverriddenProperty');
// Can not access properties on super
goTo.marker("2");

View File

@@ -18,25 +18,25 @@
////var b: Base;
////f./*5*/
goTo.marker("1");
verify.memberListContains("y");
verify.memberListContains("x");
verify.not.memberListContains("z");
//goTo.marker("1");
//verify.memberListContains("y");
//verify.memberListContains("x");
//verify.not.memberListContains("z");
goTo.marker("2");
verify.memberListContains("y");
verify.memberListContains("x");
verify.memberListContains("z");
//goTo.marker("2");
//verify.memberListContains("y");
//verify.memberListContains("x");
//verify.memberListContains("z");
goTo.marker("3");
verify.memberListContains("y");
verify.memberListContains("x");
verify.not.memberListContains("z");
//goTo.marker("3");
//verify.memberListContains("y");
//verify.memberListContains("x");
//verify.not.memberListContains("z");
goTo.marker("4");
verify.memberListContains("y");
verify.memberListContains("x");
verify.memberListContains("z");
//goTo.marker("4");
//verify.memberListContains("y");
//verify.memberListContains("x");
//verify.memberListContains("z");
goTo.marker("5");
verify.not.memberListContains("x");

View File

@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts"/>
////var [|Base|] = class { };
////class C extends [|Base|] { }
let ranges = test.ranges();
for (let range of ranges) {
goTo.position(range.start);
verify.referencesCountIs(ranges.length);
for (let expectedReference of ranges) {
verify.referencesAtPositionContains(expectedReference);
}
}

View File

@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts"/>
////interface [|Base|] { }
////namespace n {
//// var Base = class { };
//// interface I extends [|Base|] { }
////}
let ranges = test.ranges();
for (let range of ranges) {
goTo.position(range.start);
verify.referencesCountIs(ranges.length);
for (let expectedReference of ranges) {
verify.referencesAtPositionContains(expectedReference);
}
}

View File

@@ -0,0 +1,10 @@
/// <reference path="fourslash.ts"/>
////var Base = class { };
////class C extends Base implements [|Base|] { }
let ranges = test.ranges();
for (let range of ranges) {
verify.referencesCountIs(0);
}

View File

@@ -0,0 +1,35 @@
/// <reference path="fourslash.ts"/>
////let t: number;
////t
/////*nextlineWithEqual*/=2+2;
////t=
/////*nextlineWithoutEqual*/2
/////*nextline2*/+2;
////t
/////*addition*/+= 22
/////*nextlineSemicolon*/;
////t
////=t
/////*chained*/=t+ 4;
format.document();
goTo.marker("nextlineWithEqual");
verify.indentationIs(4);
verify.currentLineContentIs(" = 2 + 2;");
goTo.marker("nextlineWithoutEqual");
verify.indentationIs(4);
verify.currentLineContentIs(" 2");
goTo.marker("nextline2");
verify.indentationIs(4);
verify.currentLineContentIs(" + 2;");
goTo.marker("addition");
verify.indentationIs(4);
verify.currentLineContentIs(" += 22");
goTo.marker("nextlineSemicolon");
verify.indentationIs(4);
verify.currentLineContentIs(" ;");
goTo.marker("chained");
verify.indentationIs(4);
verify.currentLineContentIs(" = t + 4;");

View File

@@ -155,7 +155,7 @@ verify.currentLineContentIs(" else");
goTo.marker("61");
verify.currentLineContentIs(" x += 2");
goTo.marker("62");
verify.currentLineContentIs(" ;");
verify.currentLineContentIs(" ;");
goTo.marker("63");
verify.currentLineContentIs("do do do do");
goTo.marker("64");

View File

@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
//@Filename: file.tsx
//// declare module JSX {
//// interface Element { }
//// interface IntrinsicElements {
//// div: { ONE: string; TWO: number; }
//// }
//// }
//// var x = <div /*1*/ autoComplete /*2*/ />;
goTo.marker('1');
verify.completionListContains("ONE");
verify.not.completionListAllowsNewIdentifier();
goTo.marker('2');
verify.completionListContains("ONE");
verify.not.completionListAllowsNewIdentifier();

View File

@@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />
////let noSubTemplate = `/* /*1*/`;
////let templateHead = `/* /*2*/${1 + 2}`;
////let templateMiddle = `/* ${1 + 2 /*3*/}`;
////let templateTail = `/* ${1 + 2} /*4*/`;
goTo.marker('1');
edit.insert("\n");
goTo.marker('2');
edit.insert("\n");
goTo.marker('3');
edit.insert("\n");
goTo.marker('4');
edit.insert("\n");
verify.currentFileContentIs("let noSubTemplate = `/* \n`;\nlet templateHead = `/* \n${1 + 2}`;\nlet templateMiddle = `/* ${1 + 2\n }`;\nlet templateTail = `/* ${1 + 2} \n`;");

View File

@@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />
////let t = "foo \
////bar \
////"/*1*/
goTo.marker('1');
edit.insert(";");
verify.currentFileContentIs("let t = \"foo \\\nbar \\ \n\";");

View File

@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />
////var re = /\w+ /*1*//;
goTo.marker('1');
edit.insert("\n");
verify.currentFileContentIs("var re = /\\w+ \n /;");

View File

@@ -163,4 +163,70 @@ module ts {
]);
});
});
describe("Module resolution - relative imports", () => {
it("should find all modules", () => {
const options: CompilerOptions = { module: ModuleKind.CommonJS };
const files: Map<string> = {
"/a/b/c/first/shared.ts": `
class A {}
export = A`,
"/a/b/c/first/second/class_a.ts": `
import Shared = require('../shared');
import C = require('../../third/class_c');
class B {}
export = B;`,
"/a/b/c/third/class_c.ts":`
import Shared = require('../first/shared');
class C {}
export = C;
`
};
const currentDirectory = "/a/b/c/first/second";
const host: CompilerHost = {
getSourceFile: (fileName: string, languageVersion: ScriptTarget) => {
let path = normalizePath(combinePaths(currentDirectory, fileName));
return hasProperty(files, path) ? createSourceFile(fileName, files[path], languageVersion) : undefined;
},
getDefaultLibFileName: () => "lib.d.ts",
writeFile: (fileName, content): void => { throw new Error("NotImplemented"); },
getCurrentDirectory: () => currentDirectory,
getCanonicalFileName: fileName => fileName.toLowerCase(),
getNewLine: () => "\r\n",
useCaseSensitiveFileNames: () => false,
fileExists: fileName => {
let path = normalizePath(combinePaths(currentDirectory, fileName));
return hasProperty(files, path);
},
readFile: (fileName): string => { throw new Error("NotImplemented"); }
};
const program = createProgram(["class_a.ts"], options, host);
assert.equal(program.getSourceFiles().length, 3);
const syntacticDiagnostics = program.getSyntacticDiagnostics();
assert.equal(syntacticDiagnostics.length, 0, `expect no syntactic diagnostics, got: ${JSON.stringify(syntacticDiagnostics.map(diagnosticToString))}`);
const semanticDiagnostics = program.getSemanticDiagnostics();
assert.equal(semanticDiagnostics.length, 0, `expect no semantic diagnostics, got: ${JSON.stringify(semanticDiagnostics.map(diagnosticToString))}`);
// try to get file using a relative name
const fileC = program.getSourceFile("../../../c/third/class_c.ts");
assert.isTrue(fileC !== undefined, `expected to get file by relative name, got ${fileC}`);
});
function diagnosticToString(diagnostic: Diagnostic) {
let output = "";
if (diagnostic.file) {
let loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
output += `${ diagnostic.file.fileName }(${ loc.line + 1 },${ loc.character + 1 }): `;
}
let category = DiagnosticCategory[diagnostic.category].toLowerCase();
output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }${ sys.newLine }`;
return output;
}
});
}