Merge branch 'master' of https://github.com/Microsoft/TypeScript into esSymbols

Conflicts:
	src/compiler/diagnosticInformationMap.generated.ts
This commit is contained in:
Jason Freeman
2015-02-10 16:20:32 -08:00
69 changed files with 2234 additions and 954 deletions
@@ -0,0 +1,12 @@
// @target: es6
{
let let = 1; // should error
for (let let in []) { } // should error
}
{
const let = 1; // should error
}
{
function let() { // should be ok
}
}
@@ -0,0 +1,52 @@
interface X {
foo(x: number, y: number, ...z: string[]);
}
function foo(x: number, y: number, ...z: string[]) {
}
var a: string[];
var z: number[];
var obj: X;
var xa: X[];
foo(1, 2, "abc");
foo(1, 2, ...a);
foo(1, 2, ...a, "abc");
obj.foo(1, 2, "abc");
obj.foo(1, 2, ...a);
obj.foo(1, 2, ...a, "abc");
(obj.foo)(1, 2, "abc");
(obj.foo)(1, 2, ...a);
(obj.foo)(1, 2, ...a, "abc");
xa[1].foo(1, 2, "abc");
xa[1].foo(1, 2, ...a);
xa[1].foo(1, 2, ...a, "abc");
(<Function>xa[1].foo)(...[1, 2, "abc"]);
class C {
constructor(x: number, y: number, ...z: string[]) {
this.foo(x, y);
this.foo(x, y, ...z);
}
foo(x: number, y: number, ...z: string[]) {
}
}
class D extends C {
constructor() {
super(1, 2);
super(1, 2, ...a);
}
foo() {
super.foo(1, 2);
super.foo(1, 2, ...a);
}
}
// Only supported in when target is ES6
var c = new C(1, 2, ...a);
@@ -0,0 +1,54 @@
// @target: ES6
interface X {
foo(x: number, y: number, ...z: string[]);
}
function foo(x: number, y: number, ...z: string[]) {
}
var a: string[];
var z: number[];
var obj: X;
var xa: X[];
foo(1, 2, "abc");
foo(1, 2, ...a);
foo(1, 2, ...a, "abc");
obj.foo(1, 2, "abc");
obj.foo(1, 2, ...a);
obj.foo(1, 2, ...a, "abc");
(obj.foo)(1, 2, "abc");
(obj.foo)(1, 2, ...a);
(obj.foo)(1, 2, ...a, "abc");
xa[1].foo(1, 2, "abc");
xa[1].foo(1, 2, ...a);
xa[1].foo(1, 2, ...a, "abc");
(<Function>xa[1].foo)(...[1, 2, "abc"]);
class C {
constructor(x: number, y: number, ...z: string[]) {
this.foo(x, y);
this.foo(x, y, ...z);
}
foo(x: number, y: number, ...z: string[]) {
}
}
class D extends C {
constructor() {
super(1, 2);
super(1, 2, ...a);
}
foo() {
super.foo(1, 2);
super.foo(1, 2, ...a);
}
}
// Only supported in when target is ES6
var c = new C(1, 2, ...a);
@@ -12,4 +12,3 @@ edit.disableFormatting();
goTo.marker('1');
edit.insert(" compareTo(): number;\n");
diagnostics.validateTypesAtPositions(168,84,53,118,22);
@@ -14,4 +14,3 @@ edit.disableFormatting();
goTo.marker('1');
edit.insert(", 'world'");
diagnostics.validateTypesAtPositions(78);
@@ -23,5 +23,4 @@ goTo.marker('2');
edit.deleteAtCaret(7);
goTo.marker('4');
diagnostics.validateTypesAtPositions(43);
@@ -1,31 +0,0 @@
/// <reference path="../fourslash.ts" />
//// interface Iterator<T> {
//// (value: T, index: any): U;
//// }
////
//// interface WrappedArray<T> {
//// map<U>(iterator: Iterator<T, U>): U[];
//// }
////
//// interface Underscore {
//// <T>(list: T[]): WrappedArray<T>;
//// map<T, U>(list: T[], iterator: Iterator<T, U>, context?: any): U[];
//// }
////
//// declare var _: Underscore;
////
//// var a: string[];
//// var b = _.map(a, x => x.length); // Type any[], should be number[]
//// var c = _(a).map();
//// var d = a.map(x => x.length);
//// var bb = _.map(aa, x => x.length);
//// var cc = _(aa).map(x => x.length); // Error, could not select overload
//// var dd = aa.map(x => x.length); // Error, could not select overload
////
////
////
////
edit.disableFormatting();
diagnostics.validateTypesAtPositions(364);
@@ -1,7 +0,0 @@
/// <reference path="fourslash.ts" />
//// function foo2<T>(test);
//// function foo2<T>() { }
//// /**/foo2<>("");
goTo.marker();
diagnostics.validateTypeAtCurrentPosition();
+2 -14
View File
@@ -80,16 +80,6 @@ module FourSlashInterface {
}
}
export class diagnostics {
public validateTypeAtCurrentPosition() {
return this.validateTypesAtPositions(FourSlash.currentTestState.currentCaretPosition);
}
public validateTypesAtPositions(...positions: number[]) {
return FourSlash.currentTestState.verifyTypesAgainstFullCheckAtPositions(positions);
}
}
export class goTo {
// Moves the caret to the specified marker,
// or the anonymous marker ('/**/') if no name
@@ -565,11 +555,11 @@ module FourSlashInterface {
export class cancellation {
public resetCancelled() {
FourSlash.currentTestState.cancellationToken.resetCancelled();
FourSlash.currentTestState.resetCancelled();
}
public setCancelled(numberOfCalls: number = 0) {
FourSlash.currentTestState.cancellationToken.setCancelled(numberOfCalls);
FourSlash.currentTestState.setCancelled(numberOfCalls);
}
}
@@ -651,7 +641,6 @@ module fs {
export var edit = new FourSlashInterface.edit();
export var debug = new FourSlashInterface.debug();
export var format = new FourSlashInterface.format();
export var diagnostics = new FourSlashInterface.diagnostics();
export var cancellation = new FourSlashInterface.cancellation();
}
module ts {
@@ -670,6 +659,5 @@ var verify = new FourSlashInterface.verify();
var edit = new FourSlashInterface.edit();
var debug = new FourSlashInterface.debug();
var format = new FourSlashInterface.format();
var diagnostics = new FourSlashInterface.diagnostics();
var cancellation = new FourSlashInterface.cancellation();
var classification = FourSlashInterface.classification;
@@ -1,12 +0,0 @@
/// <reference path="fourslash.ts" />
////declare module A.B {
//// export class C { }
////}
////
////import ab = A.B;
////
////class D extends ab.C/**/{ }
goTo.marker();
diagnostics.validateTypesAtPositions(FourSlash.currentTestState.currentCaretPosition);
+1 -1
View File
@@ -179,5 +179,5 @@
////{| "indent": 0 |}
test.markers().forEach((marker) => {
verify.indentationAtPositionIs('tests/cases/fourslash/indentation.ts', marker.position, marker.data.indent);
verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent);
});
@@ -1,8 +0,0 @@
/// <reference path="fourslash.ts" />
//// var x: Number;
//// var y: Number;
//// var z = x ;
edit.disableFormatting();
diagnostics.validateTypesAtPositions(28);
@@ -1,29 +0,0 @@
/// <reference path="fourslash.ts" />
//// class A<T, U extends T> { }
//// class B<T extends Object, U extends T> {
//// data: A<Object, Object>;
//// }
////
//// // Below 2 should compile without error
//// var x: A< { }, { b: number }>;
//// var y: B< { a: string }, { }>;
////
////
//// // Below should be in error
//// var x1: A<{ a: string;}>;
//// var x2: A<{ a: number }>;
//// var x3: B<{ a: string;}, { b: string }>;
//// var x4: B<{ a: string;}>;
//// var x5: A<{ a: string; b: number }, { a: string }>;
//// var x6: B<>;
////
//// interface I1 {
//// a: string;
//// }
//// var x8: B<I2, I1>;
////
edit.disableFormatting();
diagnostics.validateTypesAtPositions(34);
@@ -1,12 +0,0 @@
/// <reference path="fourslash.ts" />
//// function f18(a?:string, ...b){}
////
//// function f19(a?:string, b?){}
////
//// function f20(a:string, b?:string, ...c:number[]){}
////
//// function f21(a:string, b?:string, ...d:number[]){}
edit.disableFormatting();
diagnostics.validateTypesAtPositions(133);
@@ -0,0 +1,38 @@
/// <reference path="fourslash.ts" />
//@Filename: findAllRefsOnDefinition-import.ts
////export class Test{
////
//// constructor(){
////
//// }
////
//// public /*1*/start(){
//// return this;
//// }
////
//// public stop(){
//// return this;
//// }
////}
//@Filename: findAllRefsOnDefinition.ts
////import Second = require("findAllRefsOnDefinition-import");
////
////var second = new Second.Test()
////second.start();
////second.stop();
goTo.file("findAllRefsOnDefinition-import.ts");
goTo.marker("1");
verify.referencesCountIs(2);
cancellation.setCancelled();
goTo.marker("1");
verifyOperationIsCancelled(() => verify.referencesCountIs(0) );
// verify that internal state is still correct
cancellation.resetCancelled();
goTo.marker("1");
verify.referencesCountIs(2);
@@ -0,0 +1,43 @@
/// <reference path="fourslash.ts"/>
//////curly braces
////module Foo [|{
//// class Bar [|{
//// private f() [|{
//// }|]
////
//// private f2() [|{
//// if (true) [|{ }|] [|{ }|];
//// }|]
//// }|]
////}|]
////
//////parenthesis
////class FooBar {
//// private f[|()|] {
//// return [|([|(1 + 1)|])|];
//// }
////
//// private f2[|()|] {
//// if [|(true)|] { }
//// }
////}
////
//////square brackets
////class Baz {
//// private f() {
//// var a: any[|[]|] = [|[[|[1, 2]|], [|[3, 4]|], 5]|];
//// }
////}
////
////// angular brackets
////class TemplateTest [|<T1, T2 extends Array>|] {
//// public foo(a, b) {
//// return [|<any>|] a;
//// }
////}
test.ranges().forEach((range) => {
verify.matchingBracePositionInCurrentFile(range.start, range.end - 1);
verify.matchingBracePositionInCurrentFile(range.end - 1, range.start);
});
@@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
// @BaselineFile: getBreakpointStatementAtPosition.baseline
// @Filename: getBreakpointStatementAtPosition.ts
////while (true) {
//// break;
////}
////y: while (true) {
//// break y;
////}
////while (true) {
//// continue;
////}
////z: while (true) {
//// continue z;
////}
verify.baselineCurrentFileBreakpointLocations();
@@ -0,0 +1,20 @@
/// <reference path='fourslash.ts'/>
////function foo(strOrNum: string | number) {
//// /*1*/
//// if (typeof strOrNum === "number") {
//// /*2*/
//// }
//// else {
//// /*3*/
//// }
////}
goTo.marker('1');
verify.completionListContains("strOrNum", "(parameter) strOrNum: string | number");
goTo.marker('2');
verify.completionListContains("strOrNum", "(parameter) strOrNum: number");
goTo.marker('3');
verify.completionListContains("strOrNum", "(parameter) strOrNum: string");
@@ -0,0 +1,29 @@
/// <reference path='fourslash.ts' />
// @Filename: goToDefinitionDifferentFile_Definition.ts
////var /*remoteVariableDefinition*/remoteVariable;
/////*remoteFunctionDefinition*/function remoteFunction() { }
/////*remoteClassDefinition*/class remoteClass { }
/////*remoteInterfaceDefinition*/interface remoteInterface{ }
/////*remoteModuleDefinition*/module remoteModule{ export var foo = 1;}
// @Filename: goToDefinitionDifferentFile_Consumption.ts
/////*remoteVariableReference*/remoteVariable = 1;
/////*remoteFunctionReference*/remoteFunction();
////var foo = new /*remoteClassReference*/remoteClass();
////class fooCls implements /*remoteInterfaceReference*/remoteInterface { }
////var fooVar = /*remoteModuleReference*/remoteModule.foo;
var markerList = [
"remoteVariable",
"remoteFunction",
"remoteClass",
"remoteInterface",
"remoteModule",
];
markerList.forEach((marker) => {
goTo.marker(marker + 'Reference');
goTo.definition();
verify.caretAtMarker(marker + 'Definition');
});
@@ -0,0 +1,22 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutput.baseline
// @declaration: true
// @Filename: inputFile1.ts
// @emitThisFile: true
//// var x: number = 5;
//// class Bar {
//// x : string;
//// y : number
//// }
// @Filename: inputFile2.ts
// @emitThisFile: true
//// var x1: string = "hello world";
//// class Foo{
//// x : string;
//// y : number;
//// }
verify.baselineGetEmitOutput();
@@ -0,0 +1,21 @@
/// <reference path='fourslash.ts'/>
////class Bar {
//// {| "indentation": 4|}
//// private foo: string = "";
//// {| "indentation": 4|}
//// private f() {
//// var a: any[] = [[1, 2], [3, 4], 5];
//// {| "indentation": 8|}
//// return ((1 + 1));
//// }
//// {| "indentation": 4|}
//// private f2() {
//// if (true) { } { };
//// }
////}
////{| "indentation": 0|}
test.markers().forEach((marker) => {
verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indentation);
});
@@ -0,0 +1,27 @@
/// <reference path="fourslash.ts"/>
/////// Module
////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes {
////
//// // Class
//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point {
//// // Instance member
//// {| "itemName": "origin", "kind": "property", "parentName": "Point", "matchKind": "exact"|}private origin = 0.0;
////
//// {| "itemName": "distFromZero", "kind": "property", "parentName": "Point", "matchKind": "exact"|}private distFromZero = 0.0;
////
//// // Getter
//// {| "itemName": "distance", "kind": "getter", "parentName": "Point", "matchKind": "exact" |}get distance(): number { return 0; }
//// }
////}
////
////// Local variables
////{| "itemName": "point", "kind": "var", "parentName": "", "matchKind": "exact"|}var point = new Shapes.Point();
//// Testing for exact matching of navigationItems
test.markers().forEach((marker) => {
if (marker.data) {
verify.navigationItemsListContains(marker.data.itemName, marker.data.kind, marker.data.itemName, marker.data.matchKind, marker.fileName, marker.data.parentName);
}
});
@@ -0,0 +1,13 @@
/// <reference path="fourslash.ts" />
//// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0;
test.markers().forEach(marker => {
verify.getScriptLexicalStructureListContains(
marker.data.itemName,
marker.data.kind,
marker.fileName,
marker.data.parentName,
marker.data.isAdditionalRange,
marker.position);
});
@@ -0,0 +1,18 @@
/// <reference path='fourslash.ts'/>
/////*0*/
////interface A {
//// foo: string;
////}
////function foo(x: A) {
//// x.f/*1*/oo
////}
goTo.marker("1");
verify.occurrencesAtPositionCount(2);
goTo.marker("0");
edit.insert("\r\n");
goTo.marker("1");
verify.occurrencesAtPositionCount(2);
@@ -0,0 +1,113 @@
/// <reference path="fourslash.ts"/>
////// interface
////interface IFoo[| {
//// getDist(): number;
////}|]
////
////// class members
////class Foo[| {
//// constructor()[| {
//// }|]
////
//// public foo(): number[| {
//// return 0;
//// }|]
////
//// public get X()[| {
//// return 1;
//// }|]
////
//// public set X(v: number)[| {
//// }|]
////
//// public member = function f()[| {
////
//// }|]
////}|]
////switch(1)[| {
//// case 1: break;
////}|]
////
////var array =[| [
//// 1,
//// 2
////]|]
////
////// modules
////module m1[| {
//// module m2[| { }|]
//// module m3[| {
//// function foo()[| {
////
//// }|]
////
//// interface IFoo2[| {
////
//// }|]
////
//// class foo2 implements IFoo2[| {
////
//// }|]
//// }|]
////}|]
////
////// function declaration
////function foo(): number[| {
//// return 0;
////}|]
////
////// function expressions
////(function f()[| {
////
////}|])
////
////// trivia handeling
////class ClassFooWithTrivia[| /* some comments */
//// /* more trivia */ {
////
////
//// /*some trailing trivia */
////}|] /* even more */
////
////// object literals
////var x =[|{
//// a:1,
//// b:2,
//// get foo()[| {
//// return 1;
//// }|]
////}|]
//////outline with deep nesting
////module m1[|{
//// module m2[| {
//// module m3[| {
//// module m4[| {
//// module m5[| {
//// module m6[| {
//// module m7[| {
//// module m8[| {
//// module m9[| {
//// module m10[| {
//// module m11 {
//// module m12 {
//// export interface IFoo {
//// }
//// }
//// }
//// }|]
//// }|]
//// }|]
//// }|]
//// }|]
//// }|]
//// }|]
//// }|]
//// }|]
////}|]
////
//////outline after a deeply nested node
////class AfterNestedNodes[| {
////}|]
verify.outliningSpansInCurrentFile(test.ranges());
@@ -0,0 +1,32 @@
/// <reference path="fourslash.ts" />
// @Filename: refFile1.ts
//// class D { }
// @Filename: refFile2.ts
//// export class E {}
// @Filename: main.ts
// @ResolveReference: true
//// ///<reference path="refFile1.ts" />
//// /*1*////<reference path = "NotExistRef.ts" />/*2*/
//// /*3*////<reference path "invalidRefFile1.ts" />/*4*/
//// import ref2 = require("refFile2");
//// import noExistref2 = require(/*5*/"NotExistRefFile2"/*6*/);
//// import invalidRef1 /*7*/require/*8*/("refFile2");
//// /*9*/import invalidRef2 = requi/*10*/("refFile2");
//// var obj: /*11*/C/*12*/;
//// var obj1: D;
//// var obj2: ref2.E;
goTo.file("main.ts");
verify.numberOfErrorsInCurrentFile(7);
verify.errorExistsBetweenMarkers("1", "2");
verify.errorExistsBetweenMarkers("3", "4");
verify.errorExistsBetweenMarkers("5", "6");
verify.errorExistsBetweenMarkers("7", "8");
verify.errorExistsBetweenMarkers("9", "10"); // At this position, there are two diagnostic messages: ';' expected, Cannot find name 'requi'
verify.errorExistsBetweenMarkers("11", "12");
@@ -0,0 +1,16 @@
/// <reference path='fourslash.ts'/>
////class SS<T>{}
////
////var x/*1*/1 = new SS<number>();
////var x/*2*/2 = new SS();
////var x/*3*/3 = new SS;
goTo.marker('1');
verify.quickInfoIs('(var) x1: SS<number>');
goTo.marker('2');
verify.quickInfoIs('(var) x2: SS<{}>');
goTo.marker('3');
verify.quickInfoIs('(var) x3: SS<{}>');
@@ -0,0 +1,29 @@
/// <reference path="fourslash.ts" />
//@Filename: findAllRefsOnDefinition-import.ts
////export class Test{
////
//// constructor(){
////
//// }
////
//// public /*1*/start(){
//// return this;
//// }
////
//// public stop(){
//// return this;
//// }
////}
//@Filename: findAllRefsOnDefinition.ts
////import Second = require("findAllRefsOnDefinition-import");
////
////var second = new Second.Test()
////second.start();
////second.stop();
goTo.file("findAllRefsOnDefinition-import.ts");
goTo.marker("1");
verify.referencesCountIs(2);
@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />
///////<reference path="./Bar.ts" />
////function /**/[|Bar|]() {
//// // This is a reference to Bar in a comment.
//// "this is a reference to Bar in a string"
////}
goTo.marker();
verify.renameLocations(/*findInStrings:*/ false, /*findInComments:*/ false);
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts"/>
//// module /*0*/M {
//// export interface /*1*/I {
//// }
//// }
//// interface /*2*/X extends /*3*/M./*4*/I { }
var c = classification;
verify.semanticClassificationsAre(
c.moduleName("M", test.marker("0").position),
c.interfaceName("I", test.marker("1").position),
c.interfaceName("X", test.marker("2").position),
c.moduleName("M", test.marker("3").position),
c.interfaceName("I", test.marker("4").position));
@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />
// @module: CommonJS
// @declaration: true
//// interface privateInterface {}
//// export class Bar implements /*1*/privateInterface/*2*/{ }
verify.errorExistsBetweenMarkers("1", "2");
verify.numberOfErrorsInCurrentFile(1);
@@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />
// @Filename: signatureHelpInFunctionCallOnFunctionDeclarationInMultipleFiles_file0.ts
////declare function fn(x: string, y: number);
// @Filename: signatureHelpInFunctionCallOnFunctionDeclarationInMultipleFiles_file1.ts
////declare function fn(x: string);
// @Filename: signatureHelpInFunctionCallOnFunctionDeclarationInMultipleFiles_file2.ts
////fn(/*1*/
goTo.marker('1');
verify.signatureHelpCountIs(2);
@@ -0,0 +1,35 @@
/// <reference path="fourslash.ts"/>
//// // comment
//// module M {
//// var v = 0 + 1;
//// var s = "string";
////
//// class C<T> {
//// }
////
//// enum E {
//// }
////
//// interface I {
//// }
////
//// module M1.M2 {
//// }
//// }
var c = classification;
verify.syntacticClassificationsAre(
c.comment("// comment"),
c.keyword("module"), c.moduleName("M"), c.punctuation("{"),
c.keyword("var"), c.text("v"), c.operator("="), c.numericLiteral("0"), c.operator("+"), c.numericLiteral("1"), c.punctuation(";"),
c.keyword("var"), c.text("s"), c.operator("="), c.stringLiteral('"string"'), c.punctuation(";"),
c.keyword("class"), c.className("C"), c.punctuation("<"), c.typeParameterName("T"), c.punctuation(">"), c.punctuation("{"),
c.punctuation("}"),
c.keyword("enum"), c.enumName("E"), c.punctuation("{"),
c.punctuation("}"),
c.keyword("interface"), c.interfaceName("I"), c.punctuation("{"),
c.punctuation("}"),
c.keyword("module"), c.moduleName("M1"), c.punctuation("."), c.moduleName("M2"), c.punctuation("{"),
c.punctuation("}"),
c.punctuation("}"));
@@ -0,0 +1,3 @@
//// // [|TODO|]
verify.todoCommentsInCurrentFile(["TODO"]);
@@ -0,0 +1,76 @@
/// <reference path='fourslash.ts'/>
////var /*1*/a = 10;
////function foo() {
//// var /*2*/b = /*3*/a;
////}
////module m {
//// var /*4*/c = 10;
//// export var /*5*/d = 10;
////}
////var /*6*/f: () => number;
////var /*7*/g = /*8*/f;
/////*9*/f();
////var /*10*/h: { (a: string): number; (a: number): string; };
////var /*11*/i = /*12*/h;
/////*13*/h(10);
/////*14*/h("hello");
var marker = 0;
function verifyVar(name: string, isLocal: boolean, typeDisplay: ts.SymbolDisplayPart[], optionalNameDisplay?: ts.SymbolDisplayPart[], optionalKindModifiers?: string) {
marker++;
goTo.marker(marker.toString());
var kind = isLocal ? "local var" : "var";
verify.verifyQuickInfoDisplayParts(kind, optionalKindModifiers || "", { start: test.markerByName(marker.toString()).position, length: name.length },
[{ text: "(", kind: "punctuation" }, { text: kind, kind: "text" }, { text: ")", kind: "punctuation" },
{ text: " ", kind: "space" }].concat(optionalNameDisplay || [{ text: name, kind: "localName" }]).concat(
{ text: ":", kind: "punctuation" }, { text: " ", kind: "space" }).concat(typeDisplay),
[]);
}
var numberTypeDisplay: ts.SymbolDisplayPart[] = [{ text: "number", kind: "keyword" }];
verifyVar("a", /*isLocal*/false, numberTypeDisplay);
verifyVar("b", /*isLocal*/true, numberTypeDisplay);
verifyVar("a", /*isLocal*/false, numberTypeDisplay);
verifyVar("c", /*isLocal*/false, numberTypeDisplay);
verifyVar("d", /*isLocal*/false, numberTypeDisplay, [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "d", kind: "localName" }], "export");
var functionTypeReturningNumber: ts.SymbolDisplayPart[] = [{ text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" },
{ text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "number", kind: "keyword" }];
verifyVar("f", /*isLocal*/ false, functionTypeReturningNumber);
verifyVar("g", /*isLocal*/ false, functionTypeReturningNumber);
verifyVar("f", /*isLocal*/ false, functionTypeReturningNumber);
verifyVar("f", /*isLocal*/ false, functionTypeReturningNumber);
function getFunctionType(parametertype: string, returnType: string, isArrow?: boolean): ts.SymbolDisplayPart[] {
var functionTypeDisplay = [{ text: "(", kind: "punctuation" }, { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" },
{ text: " ", kind: "space" }, { text: parametertype, kind: "keyword" }, { text: ")", kind: "punctuation" }];
if (isArrow) {
functionTypeDisplay = functionTypeDisplay.concat({ text: " ", kind: "space" }, { text: "=>", kind: "punctuation" });
}
else {
functionTypeDisplay = functionTypeDisplay.concat({ text: ":", kind: "punctuation" });
}
return functionTypeDisplay.concat({ text: " ", kind: "space" }, { text: returnType, kind: "keyword" });
}
var typeLiteralWithOverloadCall: ts.SymbolDisplayPart[] = [{ text: "{", kind: "punctuation" }, { text: "\n", kind: "lineBreak" },
{ text: " ", kind: "space" }].concat(getFunctionType("string", "number")).concat(
{ text: ";", kind: "punctuation" }, { text: "\n", kind: "lineBreak" },
{ text: " ", kind: "space" }).concat(getFunctionType("number", "string")).concat(
{ text: ";", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, { text: "}", kind: "punctuation" });
verifyVar("h", /*isLocal*/ false, typeLiteralWithOverloadCall);
verifyVar("i", /*isLocal*/ false, typeLiteralWithOverloadCall);
verifyVar("h", /*isLocal*/ false, typeLiteralWithOverloadCall);
var overloadDisplay: ts.SymbolDisplayPart[] = [{ text: " ", kind: "space" }, { text: "(", kind: "punctuation" },
{ text: "+", kind: "operator" }, { text: "1", kind: "numericLiteral" },
{ text: " ", kind: "space" }, { text: "overload", kind: "text" }, { text: ")", kind: "punctuation" }];
verifyVar("h", /*isLocal*/ false, getFunctionType("number", "string", /*isArrow*/true).concat(overloadDisplay));
verifyVar("h", /*isLocal*/ false, getFunctionType("string", "number", /*isArrow*/true).concat(overloadDisplay));
@@ -20,5 +20,3 @@ edit.insert(", X");
goTo.marker('addTypeParam');
edit.insert(", X");
diagnostics.validateTypesAtPositions(91, 163);
@@ -1,27 +0,0 @@
/// <reference path="fourslash.ts" />
//// class Point {
////
//// constructor(public x: number) {
////
//// }
//// getDist() {
//// }
//// static origin = new Point(0);
//// }
////
//// class Point3D {
////
//// constructor(x: number, y: number, private z) {
//// super(x, y);
//// }
////
//// getDist() {
//// return Math.sqrt(this.x*this.x + this.z*this.m);
//// }
//// }
////
////
edit.disableFormatting();
diagnostics.validateTypesAtPositions(258);
@@ -1,12 +0,0 @@
/// <reference path="fourslash.ts" />
//// interface Sequence<T> {
//// each(iterator: (value: T) => void): void;
//// filter(): Sequence<T>;
//// groupBy<K>(keySelector: () => K): Sequence<{ items: T/**/[]; }>;
//// }
goTo.file(0);
// Marker in above file is placed at position 154
diagnostics.validateTypesAtPositions(154);
@@ -1,11 +0,0 @@
/// <reference path="fourslash.ts" />
//// function method() {
//// var dictionary = <{ [index: string]: string; }>{};
//// }
////
edit.disableFormatting(); // Disregard, just here to keep Fourslash happy
diagnostics.validateTypesAtPositions(44);
@@ -1,40 +0,0 @@
/// <reference path="fourslash.ts" />
//// // @sourcemap: true
//// module Foo.Bar {
//// "use strict";
////
//// class Greeter {
//// constructor(public greeting: string) {
//// }
////
//// greet() {
//// }
//// }
////
////
//// function foo(greeting: string): Foo.Bar.Greeter {
//// return new Greeter(greeting);
//// }
////
//// var greeter = new Greeter("Hello, world!");
//// var str = greeter.greet();
////
//// function foo2(greeting: string, ...restGreetings) {
//// var greeters: Greeter[] = [];
//// new Greeter(greeting);
//// for (var i = 0; restGreetings.length; i++) {
//// greeters.push(new Greeter(restGreetings[i]));
//// }
////
//// return greeters;
//// }
////
//// var b = foo2("Hello", "World");
//// for (var j = 0; j < b.length; j++) {
//// b[j].greet();
//// }
//// }
edit.disableFormatting();
diagnostics.validateTypesAtPositions(705);
+26 -65
View File
@@ -1,84 +1,47 @@
/// <reference path="..\..\..\..\src\harness\external\mocha.d.ts" />
/// <reference path="..\..\..\..\src\harness\harnessLanguageService.ts" />
interface Classification {
position: number;
length: number;
class: ts.TokenClass;
}
interface ClassiferResult {
tuples: Classification[];
finalEndOfLineState: ts.EndOfLineState;
}
interface ClassificationEntry {
value: any;
class: ts.TokenClass;
classification: ts.TokenClass;
}
describe('Colorization', function () {
var mytypescriptLS = new Harness.LanguageService.TypeScriptLS();
var myclassifier = mytypescriptLS.getClassifier();
// Use the shim adapter to ensure test coverage of the shim layer for the classifier
var languageServiceAdabtor = new Harness.LanguageService.ShimLanugageServiceAdapter();
var classifier = languageServiceAdabtor.getClassifier();
function getLexicalClassifications(code: string, initialEndOfLineState: ts.EndOfLineState = ts.EndOfLineState.Start): ClassiferResult {
var classResult = myclassifier.getClassificationsForLine(code, initialEndOfLineState).split('\n');
var tuples: Classification[] = [];
var i = 0;
var position = 0;
for (; i < classResult.length - 1; i += 2) {
var t = tuples[i / 2] = {
position: position,
length: parseInt(classResult[i]),
class: parseInt(classResult[i + 1])
};
assert.isTrue(t.length > 0, "Result length should be greater than 0, got :" + t.length);
position += t.length;
}
var finalEndOfLineState = classResult[classResult.length - 1];
assert.equal(position, code.length, "Expected cumulative length of all entries to match the length of the source. expected: " + code.length + ", but got: " + position);
return {
tuples: tuples,
finalEndOfLineState: parseInt(finalEndOfLineState)
};
}
function verifyClassification(classification: Classification, expectedLength: number, expectedClass: number) {
assert.isNotNull(classification);
assert.equal(classification.length, expectedLength, "Classification length does not match expected. Expected: " + expectedLength + ", Actual: " + classification.length);
assert.equal(classification.class, expectedClass, "Classification class does not match expected. Expected: " + ts.TokenClass[expectedClass] + ", Actual: " + ts.TokenClass[classification.class]);
}
function getEntryAtPosistion(result: ClassiferResult, position: number) {
for (var i = 0, n = result.tuples.length; i < n; i++) {
if (result.tuples[i].position === position) return result.tuples[i];
function getEntryAtPosistion(result: ts.ClassificationResult, position: number) {
var entryPosition = 0;
for (var i = 0, n = result.entries.length; i < n; i++) {
var entry = result.entries[i];
if (entryPosition === position) {
return entry;
}
entryPosition += entry.length;
}
return undefined;
}
function punctuation(text: string) { return { value: text, class: ts.TokenClass.Punctuation }; }
function keyword(text: string) { return { value: text, class: ts.TokenClass.Keyword }; }
function operator(text: string) { return { value: text, class: ts.TokenClass.Operator }; }
function comment(text: string) { return { value: text, class: ts.TokenClass.Comment }; }
function whitespace(text: string) { return { value: text, class: ts.TokenClass.Whitespace }; }
function identifier(text: string) { return { value: text, class: ts.TokenClass.Identifier }; }
function numberLiteral(text: string) { return { value: text, class: ts.TokenClass.NumberLiteral }; }
function stringLiteral(text: string) { return { value: text, class: ts.TokenClass.StringLiteral }; }
function regExpLiteral(text: string) { return { value: text, class: ts.TokenClass.RegExpLiteral }; }
function finalEndOfLineState(value: number) { return { value: value, class: <ts.TokenClass>undefined }; }
function punctuation(text: string): ClassificationEntry { return { value: text, classification: ts.TokenClass.Punctuation }; }
function keyword(text: string): ClassificationEntry { return { value: text, classification: ts.TokenClass.Keyword }; }
function operator(text: string): ClassificationEntry { return { value: text, classification: ts.TokenClass.Operator }; }
function comment(text: string): ClassificationEntry { return { value: text, classification: ts.TokenClass.Comment }; }
function whitespace(text: string): ClassificationEntry { return { value: text, classification: ts.TokenClass.Whitespace }; }
function identifier(text: string): ClassificationEntry { return { value: text, classification: ts.TokenClass.Identifier }; }
function numberLiteral(text: string): ClassificationEntry { return { value: text, classification: ts.TokenClass.NumberLiteral }; }
function stringLiteral(text: string): ClassificationEntry { return { value: text, classification: ts.TokenClass.StringLiteral }; }
function regExpLiteral(text: string): ClassificationEntry { return { value: text, classification: ts.TokenClass.RegExpLiteral }; }
function finalEndOfLineState(value: number): ClassificationEntry { return { value: value, classification: <ts.TokenClass>undefined }; }
function testLexicalClassification(text: string, initialEndOfLineState: ts.EndOfLineState, ...expectedEntries: ClassificationEntry[]): void {
var result = getLexicalClassifications(text, initialEndOfLineState);
var result = classifier.getClassificationsForLine(text, initialEndOfLineState);
for (var i = 0, n = expectedEntries.length; i < n; i++) {
var expectedEntry = expectedEntries[i];
if (expectedEntry.class === undefined) {
assert.equal(result.finalEndOfLineState, expectedEntry.value, "final endOfLineState does not match expected.");
if (expectedEntry.classification === undefined) {
assert.equal(result.finalLexState, expectedEntry.value, "final endOfLineState does not match expected.");
}
else {
var actualEntryPosition = text.indexOf(expectedEntry.value);
@@ -87,7 +50,7 @@ describe('Colorization', function () {
var actualEntry = getEntryAtPosistion(result, actualEntryPosition);
assert(actualEntry, "Could not find classification entry for '" + expectedEntry.value + "' at position: " + actualEntryPosition);
assert.equal(actualEntry.class, expectedEntry.class, "Classification class does not match expected. Expected: " + ts.TokenClass[expectedEntry.class] + ", Actual: " + ts.TokenClass[actualEntry.class]);
assert.equal(actualEntry.classification, expectedEntry.classification, "Classification class does not match expected. Expected: " + ts.TokenClass[expectedEntry.classification] + ", Actual: " + ts.TokenClass[actualEntry.classification]);
assert.equal(actualEntry.length, expectedEntry.value.length, "Classification length does not match expected. Expected: " + ts.TokenClass[expectedEntry.value.length] + ", Actual: " + ts.TokenClass[actualEntry.length]);
}
}
@@ -320,8 +283,6 @@ describe('Colorization', function () {
});
it("LexicallyClassifiesConflictTokens", () => {
debugger;
// Test conflict markers.
testLexicalClassification(
"class C {\r\n\