From 307e28a8a1b78cbe1b5394aa033bf18b621949de Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 13 Oct 2014 14:38:18 -0700 Subject: [PATCH 01/39] Enable infrastructure to test the symbol display parts returned by quickInfo --- src/harness/fourslash.ts | 17 +++++++- src/services/services.ts | 5 ++- tests/cases/fourslash/fourslash.ts | 12 +++++- .../fourslash/quicklInfoDisplayPartsClass.ts | 39 +++++++++++++++++++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/quicklInfoDisplayPartsClass.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 6a4e13b22e3..e6bca42ea64 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -765,7 +765,7 @@ module FourSlash { return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue; } - public verifyQuickInfo(negative: boolean, expectedText?: string, expectedDocumentation?: string) { + public quickInfoIs(negative: boolean, expectedText?: string, expectedDocumentation?: string) { [expectedText, expectedDocumentation].forEach(str => { if (str) { this.scenarioActions.push(''); @@ -794,6 +794,21 @@ module FourSlash { } } + + public verifyQuickInfo(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, + displayParts: { text: string; kind: string; }[], + documentation: { text: string; kind: string; }[]) { + this.scenarioActions.push(''); + this.scenarioActions.push(''); + + var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); + assert.equal(actualQuickInfo.kind, kind, this.messageAtLastKnownMarker("QuickInfo kind")); + assert.equal(actualQuickInfo.kindModifiers, kindModifiers, this.messageAtLastKnownMarker("QuickInfo kindModifiers")); + assert.equal(JSON.stringify(actualQuickInfo.textSpan), JSON.stringify(textSpan), this.messageAtLastKnownMarker("QuickInfo textSpan")); + assert.equal(JSON.stringify(actualQuickInfo.displayParts), JSON.stringify(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts")); + assert.equal(JSON.stringify(actualQuickInfo.documentation), JSON.stringify(documentation), this.messageAtLastKnownMarker("QuickInfo documentation")); + } + public verifyRenameLocations(findInStrings: boolean, findInComments: boolean) { var renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition); if (renameInfo.canRename) { diff --git a/src/services/services.ts b/src/services/services.ts index 618026408fe..237c0ca9f1c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1317,7 +1317,10 @@ module ts { function writeIndent() { if (lineStart) { - displayParts.push(displayPart(getIndentString(indent), SymbolDisplayPartKind.space)); + var indentString = getIndentString(indent); + if (indentString) { + displayParts.push(displayPart(indentString, SymbolDisplayPartKind.space)); + } lineStart = false; } } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 7be7dd63c92..eef259065ca 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -83,6 +83,10 @@ module FourSlashInterface { public ranges(): Range[] { return FourSlash.currentTestState.getRanges(); } + + public markerByName(s: string): Marker { + return FourSlash.currentTestState.getMarkerByName(s); + } } export class diagnostics { @@ -223,7 +227,7 @@ module FourSlashInterface { } public quickInfoIs(expectedText?: string, expectedDocumentation?: string) { - FourSlash.currentTestState.verifyQuickInfo(this.negative, expectedText, expectedDocumentation); + FourSlash.currentTestState.quickInfoIs(this.negative, expectedText, expectedDocumentation); } public quickInfoExists() { @@ -420,6 +424,12 @@ module FourSlashInterface { public renameLocations(findInStrings: boolean, findInComments: boolean) { FourSlash.currentTestState.verifyRenameLocations(findInStrings, findInComments); } + + public verifyQuickInfo(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, + displayParts: { text: string; kind: string; }[], + documentation: { text: string; kind: string; }[]) { + FourSlash.currentTestState.verifyQuickInfo(kind, kindModifiers, textSpan, displayParts, documentation); + } } export class edit { diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClass.ts b/tests/cases/fourslash/quicklInfoDisplayPartsClass.ts new file mode 100644 index 00000000000..8e4dc346cbc --- /dev/null +++ b/tests/cases/fourslash/quicklInfoDisplayPartsClass.ts @@ -0,0 +1,39 @@ +/// + +////class /*1*/c { +////} +////var /*2*/cInstance = new /*3*/c(); +////var /*4*/cVal = /*5*/c; + +goTo.marker('1'); +verify.verifyQuickInfo("class", "", { start: test.markerByName("1").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('2'); +verify.verifyQuickInfo("var", "", { start: test.markerByName("2").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('3'); +verify.verifyQuickInfo("constructor", "", { start: test.markerByName("3").position, length: "c".length }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('4'); +verify.verifyQuickInfo("var", "", { start: test.markerByName("4").position, length: "cVal".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cVal", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('5'); +verify.verifyQuickInfo("class", "", { start: test.markerByName("5").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); \ No newline at end of file From 2b2ebf596045b04b77b97f578bd84a9788abcee7 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 13 Oct 2014 15:01:31 -0700 Subject: [PATCH 02/39] Test cases for class property display parts --- src/compiler/emitter.ts | 35 +++----- .../quicklInfoDisplayPartsClassProperty.ts | 85 +++++++++++++++++++ 2 files changed, 99 insertions(+), 21 deletions(-) create mode 100644 tests/cases/fourslash/quicklInfoDisplayPartsClassProperty.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c038cf39868..48fb5bc0ece 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2428,32 +2428,25 @@ module ts { } function emitDeclarationFlags(node: Declaration) { + if (node.flags & NodeFlags.Private) { + write("private "); + } + else if (node.flags & NodeFlags.Protected) { + write("protected "); + } + if (node.flags & NodeFlags.Static) { - if (node.flags & NodeFlags.Private) { - write("private "); - } - else if (node.flags & NodeFlags.Protected) { - write("protected "); - } write("static "); } - else { - if (node.flags & NodeFlags.Private) { - write("private "); + // If the node is parented in the current source file we need to emit export declare or just export + else if (node.parent === currentSourceFile) { + // If the node is exported + if (node.flags & NodeFlags.Export) { + write("export "); } - else if (node.flags & NodeFlags.Protected) { - write("protected "); - } - // If the node is parented in the current source file we need to emit export declare or just export - else if (node.parent === currentSourceFile) { - // If the node is exported - if (node.flags & NodeFlags.Export) { - write("export "); - } - if (node.kind !== SyntaxKind.InterfaceDeclaration) { - write("declare "); - } + if (node.kind !== SyntaxKind.InterfaceDeclaration) { + write("declare "); } } } diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClassProperty.ts b/tests/cases/fourslash/quicklInfoDisplayPartsClassProperty.ts new file mode 100644 index 00000000000..9f5360ce410 --- /dev/null +++ b/tests/cases/fourslash/quicklInfoDisplayPartsClassProperty.ts @@ -0,0 +1,85 @@ +/// + +////class c { +//// public /*1*/publicProperty: string; +//// private /*2*/privateProperty: string; +//// protected /*21*/protectedProperty: string; +//// static /*3*/staticProperty: string; +//// private static /*4*/privateStaticProperty: string; +//// protected static /*41*/protectedStaticProperty: string; +//// method() { +//// this./*5*/publicProperty; +//// this./*6*/privateProperty; +//// this./*61*/protectedProperty; +//// c./*7*/staticProperty; +//// c./*8*/privateStaticProperty; +//// c./*81*/protectedStaticProperty; +//// } +////} +////var cInstance = new c(); +/////*9*/cInstance./*10*/publicProperty; +/////*11*/c./*12*/staticProperty; + +function verifyClassProperty(markerName: string, kindModifiers: string, propertyName: string) { + goTo.marker(markerName); + verify.verifyQuickInfo("property", kindModifiers, { start: test.markerByName(markerName).position, length: propertyName.length }, + [{ text: "(", kind: "punctuation" }, { text: "property", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "c", kind: "className" }, { text: ".", kind: "punctuation" }, { text: propertyName, kind: "propertyName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); +} + +function verifyPublicProperty(markerName: string) { + verifyClassProperty(markerName, "public", "publicProperty"); +} + +function verifyPrivateProperty(markerName: string) { + verifyClassProperty(markerName, "private", "privateProperty"); +} + +function verifyProtectedProperty(markerName: string) { + verifyClassProperty(markerName, "protected", "protectedProperty"); +} + +function verifyStaticProperty(markerName: string) { + verifyClassProperty(markerName, "static", "staticProperty"); +} + +function verifyPrivateStaticProperty(markerName: string) { + verifyClassProperty(markerName, "private,static", "privateStaticProperty"); +} + +function verifyProtectedStaticProperty(markerName: string) { + verifyClassProperty(markerName, "protected,static", "protectedStaticProperty"); +} + +verifyPublicProperty('1'); +verifyPrivateProperty('2'); +verifyProtectedProperty('21'); +verifyStaticProperty('3'); +verifyPrivateStaticProperty('4'); +verifyProtectedStaticProperty('41'); + +verifyPublicProperty('5'); +verifyPrivateProperty('6'); +verifyProtectedProperty('61'); +verifyStaticProperty('7'); +verifyPrivateStaticProperty('8'); +verifyProtectedStaticProperty('81'); + +goTo.marker('9'); +verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyPublicProperty('10'); + +goTo.marker('11'); +verify.verifyQuickInfo("class", "", { start: test.markerByName("11").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyStaticProperty('12'); \ No newline at end of file From f06ce79c79e7a27c06833903090fbce26ed13a6d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 13 Oct 2014 15:22:39 -0700 Subject: [PATCH 03/39] Test cases for class methods --- .../quicklInfoDisplayPartsClassMethod.ts | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/cases/fourslash/quicklInfoDisplayPartsClassMethod.ts diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClassMethod.ts b/tests/cases/fourslash/quicklInfoDisplayPartsClassMethod.ts new file mode 100644 index 00000000000..5e261bc36a5 --- /dev/null +++ b/tests/cases/fourslash/quicklInfoDisplayPartsClassMethod.ts @@ -0,0 +1,86 @@ +/// + +////class c { +//// public /*1*/publicMethod() { } +//// private /*2*/privateMethod() { } +//// protected /*21*/protectedMethod() { } +//// static /*3*/staticMethod() { } +//// private static /*4*/privateStaticMethod() { } +//// protected static /*41*/protectedStaticMethod() { } +//// method() { +//// this./*5*/publicMethod(); +//// this./*6*/privateMethod(); +//// this./*61*/protectedMethod(); +//// c./*7*/staticMethod(); +//// c./*8*/privateStaticMethod(); +//// c./*81*/protectedStaticMethod(); +//// } +////} +////var cInstance = new c(); +/////*9*/cInstance./*10*/publicMethod(); +/////*11*/c./*12*/staticMethod(); + +function verifyClassMethod(markerName: string, kindModifiers: string, methodName: string) { + goTo.marker(markerName); + verify.verifyQuickInfo("method", kindModifiers, { start: test.markerByName(markerName).position, length: methodName.length }, + [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "c", kind: "className" }, { text: ".", kind: "punctuation" }, { text: methodName, kind: "methodName" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyPublicMethod(markerName: string) { + verifyClassMethod(markerName, "public", "publicMethod"); +} + +function verifyPrivateMethod(markerName: string) { + verifyClassMethod(markerName, "private", "privateMethod"); +} + +function verifyProtectedMethod(markerName: string) { + verifyClassMethod(markerName, "protected", "protectedMethod"); +} + +function verifyStaticMethod(markerName: string) { + verifyClassMethod(markerName, "static", "staticMethod"); +} + +function verifyPrivateStaticMethod(markerName: string) { + verifyClassMethod(markerName, "private,static", "privateStaticMethod"); +} + +function verifyProtectedStaticMethod(markerName: string) { + verifyClassMethod(markerName, "protected,static", "protectedStaticMethod"); +} + +verifyPublicMethod('1'); +verifyPrivateMethod('2'); +verifyProtectedMethod('21'); +verifyStaticMethod('3'); +verifyPrivateStaticMethod('4'); +verifyProtectedStaticMethod('41'); + +verifyPublicMethod('5'); +verifyPrivateMethod('6'); +verifyProtectedMethod('61'); +verifyStaticMethod('7'); +verifyPrivateStaticMethod('8'); +verifyProtectedStaticMethod('81'); + +goTo.marker('9'); +verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyPublicMethod('10'); + +goTo.marker('11'); +verify.verifyQuickInfo("class", "", { start: test.markerByName("11").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyStaticMethod('12'); \ No newline at end of file From 532245c1c277aa27e408ce8bc8d5d33e801fb155 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 13 Oct 2014 15:43:42 -0700 Subject: [PATCH 04/39] Test cases and fix for symbol display part kind of class accessors --- src/services/services.ts | 2 + .../quicklInfoDisplayPartsClassAccessors.ts | 129 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 tests/cases/fourslash/quicklInfoDisplayPartsClassAccessors.ts diff --git a/src/services/services.ts b/src/services/services.ts index 237c0ca9f1c..963fbe299bb 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1420,6 +1420,8 @@ module ts { return isFirstDeclarationOfSymbolParameter(symbol) ? SymbolDisplayPartKind.parameterName : SymbolDisplayPartKind.localName; } else if (flags & SymbolFlags.Property) { return SymbolDisplayPartKind.propertyName; } + else if (flags & SymbolFlags.GetAccessor) { return SymbolDisplayPartKind.propertyName; } + else if (flags & SymbolFlags.SetAccessor) { return SymbolDisplayPartKind.propertyName; } else if (flags & SymbolFlags.EnumMember) { return SymbolDisplayPartKind.enumMemberName; } else if (flags & SymbolFlags.Function) { return SymbolDisplayPartKind.functionName; } else if (flags & SymbolFlags.Class) { return SymbolDisplayPartKind.className; } diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClassAccessors.ts b/tests/cases/fourslash/quicklInfoDisplayPartsClassAccessors.ts new file mode 100644 index 00000000000..7b93177076a --- /dev/null +++ b/tests/cases/fourslash/quicklInfoDisplayPartsClassAccessors.ts @@ -0,0 +1,129 @@ +/// + +////class c { +//// public get /*1*/publicProperty() { return ""; } +//// public set /*1s*/publicProperty(x: string) { } +//// private get /*2*/privateProperty() { return ""; } +//// private set /*2s*/privateProperty(x: string) { } +//// protected get /*21*/protectedProperty() { return ""; } +//// protected set /*21s*/protectedProperty(x: string) { } +//// static get /*3*/staticProperty() { return ""; } +//// static set /*3s*/staticProperty(x: string) { } +//// private static get /*4*/privateStaticProperty() { return ""; } +//// private static set /*4s*/privateStaticProperty(x: string) { } +//// protected static get /*41*/protectedStaticProperty() { return ""; } +//// protected static set /*41s*/protectedStaticProperty(x: string) { } +//// method() { +//// var x : string; +//// x = this./*5*/publicProperty; +//// x = this./*6*/privateProperty; +//// x = this./*61*/protectedProperty; +//// x = c./*7*/staticProperty; +//// x = c./*8*/privateStaticProperty; +//// x = c./*81*/protectedStaticProperty; +//// this./*5s*/publicProperty = ""; +//// this./*6s*/privateProperty = ""; +//// this./*61s*/protectedProperty = ""; +//// c./*7s*/staticProperty = ""; +//// c./*8s*/privateStaticProperty = ""; +//// c./*81s*/protectedStaticProperty = ""; +//// } +////} +////var cInstance = new c(); +////var y: string; +////y = /*9*/cInstance./*10*/publicProperty; +////y = /*11*/c./*12*/staticProperty; +/////*9s*/cInstance./*10s*/publicProperty = y; +/////*11s*/c./*12s*/staticProperty = y; + +function verifyClassProperty(markerName: string, kindModifiers: string, propertyName: string) { + goTo.marker(markerName); + verify.verifyQuickInfo("property", kindModifiers, { start: test.markerByName(markerName).position, length: propertyName.length }, + [{ text: "(", kind: "punctuation" }, { text: "property", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "c", kind: "className" }, { text: ".", kind: "punctuation" }, { text: propertyName, kind: "propertyName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); +} + +function verifyPublicProperty(markerName: string) { + verifyClassProperty(markerName, "public", "publicProperty"); +} + +function verifyPrivateProperty(markerName: string) { + verifyClassProperty(markerName, "private", "privateProperty"); +} + +function verifyProtectedProperty(markerName: string) { + verifyClassProperty(markerName, "protected", "protectedProperty"); +} + +function verifyStaticProperty(markerName: string) { + verifyClassProperty(markerName, "static", "staticProperty"); +} + +function verifyPrivateStaticProperty(markerName: string) { + verifyClassProperty(markerName, "private,static", "privateStaticProperty"); +} + +function verifyProtectedStaticProperty(markerName: string) { + verifyClassProperty(markerName, "protected,static", "protectedStaticProperty"); +} + +verifyPublicProperty('1'); +verifyPublicProperty('1s'); +verifyPrivateProperty('2'); +verifyPrivateProperty('2s'); +verifyProtectedProperty('21'); +verifyProtectedProperty('21s'); +verifyStaticProperty('3'); +verifyStaticProperty('3s'); +verifyPrivateStaticProperty('4'); +verifyPrivateStaticProperty('4s'); +verifyProtectedStaticProperty('41'); +verifyProtectedStaticProperty('41s'); + +verifyPublicProperty('5'); +verifyPublicProperty('5s'); +verifyPrivateProperty('6'); +verifyPrivateProperty('6s'); +verifyProtectedProperty('61'); +verifyProtectedProperty('61s'); +verifyStaticProperty('7'); +verifyStaticProperty('7s'); +verifyPrivateStaticProperty('8'); +verifyPrivateStaticProperty('8s'); +verifyProtectedStaticProperty('81'); +verifyProtectedStaticProperty('81s'); + +goTo.marker('9'); +verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyPublicProperty('10'); + +goTo.marker('11'); +verify.verifyQuickInfo("class", "", { start: test.markerByName("11").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyStaticProperty('12'); + +goTo.marker('9s'); +verify.verifyQuickInfo("var", "", { start: test.markerByName("9s").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyPublicProperty('10s'); + +goTo.marker('11s'); +verify.verifyQuickInfo("class", "", { start: test.markerByName("11s").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyStaticProperty('12s'); \ No newline at end of file From 9bd2fa16aaebd55610bbc7cbe3363a4b4ef3dff4 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 13 Oct 2014 16:58:52 -0700 Subject: [PATCH 05/39] Test cases for constructor quickInfo display parts kind --- src/services/services.ts | 3 +- .../quicklInfoDisplayPartsClassConstructor.ts | 126 ++++++++++++++++++ 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/quicklInfoDisplayPartsClassConstructor.ts diff --git a/src/services/services.ts b/src/services/services.ts index 963fbe299bb..c67b85d0b36 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2852,7 +2852,8 @@ module ts { if (functionDeclaration.kind === SyntaxKind.Constructor) { // show (constructor) Type(...) signature - addPrefixForAnyFunctionOrVar(type.symbol, ScriptElementKind.constructorImplementationElement); + symbolKind = ScriptElementKind.constructorImplementationElement; + addPrefixForAnyFunctionOrVar(type.symbol, symbolKind); } else { // (function/method) symbol(..signature) diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClassConstructor.ts b/tests/cases/fourslash/quicklInfoDisplayPartsClassConstructor.ts new file mode 100644 index 00000000000..b71a7aeab9e --- /dev/null +++ b/tests/cases/fourslash/quicklInfoDisplayPartsClassConstructor.ts @@ -0,0 +1,126 @@ +/// + +////class c { +//// /*1*/constructor() { +//// } +////} +////var /*2*/cInstance = new /*3*/c(); +////var /*4*/cVal = /*5*/c; +////class cWithOverloads { +//// /*6*/constructor(x: string); +//// /*7*/constructor(x: number); +//// /*8*/constructor(x: any) { +//// } +////} +////var /*9*/cWithOverloadsInstance = new /*10*/cWithOverloads("hello"); +////var /*11*/cWithOverloadsInstance2 = new /*12*/cWithOverloads(10); +////var /*13*/cWithOverloadsVal = /*14*/cWithOverloads; +////class cWithMultipleOverloads { +//// /*15*/constructor(x: string); +//// /*16*/constructor(x: number); +//// /*17*/constructor(x: boolean); +//// /*18*/constructor(x: any) { +//// } +////} +////var /*19*/cWithMultipleOverloadsInstance = new /*20*/cWithMultipleOverloads("hello"); +////var /*21*/cWithMultipleOverloadsInstance2 = new /*22*/cWithMultipleOverloads(10); +////var /*23*/cWithMultipleOverloadsInstance3 = new /*24*/cWithMultipleOverloads(true); +////var /*25*/cWithMultipleOverloadsVal = /*26*/cWithMultipleOverloads; + +function verifyNonOverloadSignature(marker: string, textSpanLength: number) { + goTo.marker(marker); + verify.verifyQuickInfo("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); +} + +function verifyClassInstance(markerName: string, instanceName: string, className: string) { + goTo.marker(markerName); + verify.verifyQuickInfo("var", "", { start: test.markerByName(markerName).position, length: instanceName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: className, kind: "className" }], + []); +} + +function verifyClass(markerName: string, className: string) { + goTo.marker(markerName); + verify.verifyQuickInfo("class", "", { start: test.markerByName(markerName).position, length: className.length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: className, kind: "className" }], + []); +} + +function verifyTypeOfClass(markerName: string, typeOfVarName: string, className: string) { + goTo.marker(markerName); + verify.verifyQuickInfo("var", "", { start: test.markerByName(markerName).position, length: typeOfVarName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: typeOfVarName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: className, kind: "className" }], + []); +} + +function verifySingleOverloadSignature(marker: string, textSpanLength: number, parameterType: string) { + goTo.marker(marker); + verify.verifyQuickInfo("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cWithOverloads", kind: "className" }, { text: "(", kind: "punctuation" }, + { text: "x", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: parameterType, kind: "keyword" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cWithOverloads", kind: "className" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, + { text: "+", kind: "operator" }, { text: "1", kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: "overload", kind: "text" }, + { text: ")", kind: "punctuation" }], + []); +} + +function verifyMultipleOverloadSignature(marker: string, textSpanLength: number, parameterType: string) { + goTo.marker(marker); + verify.verifyQuickInfo("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cWithMultipleOverloads", kind: "className" }, { text: "(", kind: "punctuation" }, + { text: "x", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: parameterType, kind: "keyword" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cWithMultipleOverloads", kind: "className" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, + { text: "+", kind: "operator" }, { text: "2", kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: "overloads", kind: "text" }, + { text: ")", kind: "punctuation" }], + []); +} + + +verifyNonOverloadSignature("1", "constructor".length); +verifyClassInstance("2", "cInstance", "c"); +verifyNonOverloadSignature("3", "c".length); +verifyTypeOfClass("4", "cVal", "c"); +verifyClass("5", "c"); + +verifySingleOverloadSignature("6", "constructor".length, "string"); +verifySingleOverloadSignature("7", "constructor".length, "number"); +verifySingleOverloadSignature("8", "constructor".length, "string"); +verifyClassInstance("9", "cWithOverloadsInstance", "cWithOverloads"); +verifySingleOverloadSignature("10", "cWithOverloads".length, "string"); +verifyClassInstance("11", "cWithOverloadsInstance2", "cWithOverloads"); +verifySingleOverloadSignature("12", "cWithOverloads".length, "number"); +verifyTypeOfClass("13", "cWithOverloadsVal", "cWithOverloads"); +verifyClass("14", "cWithOverloads"); + +verifyMultipleOverloadSignature("15", "constructor".length, "string"); +verifyMultipleOverloadSignature("16", "constructor".length, "number"); +verifyMultipleOverloadSignature("17", "constructor".length, "boolean"); +verifyMultipleOverloadSignature("18", "constructor".length, "string"); +verifyClassInstance("19", "cWithMultipleOverloadsInstance", "cWithMultipleOverloads"); +verifyMultipleOverloadSignature("20", "cWithMultipleOverloads".length, "string"); +verifyClassInstance("21", "cWithMultipleOverloadsInstance2", "cWithMultipleOverloads"); +verifyMultipleOverloadSignature("22", "cWithMultipleOverloads".length, "number"); +verifyClassInstance("23", "cWithMultipleOverloadsInstance3", "cWithMultipleOverloads"); +verifyMultipleOverloadSignature("24", "cWithMultipleOverloads".length, "boolean"); +verifyTypeOfClass("25", "cWithMultipleOverloadsVal", "cWithMultipleOverloads"); +verifyClass("26", "cWithMultipleOverloads"); \ No newline at end of file From bd39fc72c6ea8304c00f7b469635b5bbbeeb1d17 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 13 Oct 2014 16:59:10 -0700 Subject: [PATCH 06/39] Test case for interface display parts --- .../quicklInfoDisplayPartsInterface.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/cases/fourslash/quicklInfoDisplayPartsInterface.ts diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsInterface.ts b/tests/cases/fourslash/quicklInfoDisplayPartsInterface.ts new file mode 100644 index 00000000000..0e3e4d01181 --- /dev/null +++ b/tests/cases/fourslash/quicklInfoDisplayPartsInterface.ts @@ -0,0 +1,22 @@ +/// + +////interface /*1*/i { +////} +////var /*2*/iInstance: /*3*/i; + +goTo.marker('1'); +verify.verifyQuickInfo("interface", "", { start: test.markerByName("1").position, length: "i".length }, + [{ text: "interface", kind: "keyword" }, { text: " ", kind: "space" }, { text: "i", kind: "interfaceName" }], + []); + +goTo.marker('2'); +verify.verifyQuickInfo("var", "", { start: test.markerByName("2").position, length: "iInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "iInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "i", kind: "interfaceName" }], + []); + +goTo.marker('3'); +verify.verifyQuickInfo("interface", "", { start: test.markerByName("3").position, length: "i".length }, + [{ text: "interface", kind: "keyword" }, { text: " ", kind: "space" }, { text: "i", kind: "interfaceName" }], + []); \ No newline at end of file From 1f0ef0292493f3a8571cf37fab1f4a9eb560e9a8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 13 Oct 2014 17:21:58 -0700 Subject: [PATCH 07/39] Test case for interface members --- .../quicklInfoDisplayPartsInterfaceMembers.ts | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/cases/fourslash/quicklInfoDisplayPartsInterfaceMembers.ts diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsInterfaceMembers.ts b/tests/cases/fourslash/quicklInfoDisplayPartsInterfaceMembers.ts new file mode 100644 index 00000000000..e12bc81a7be --- /dev/null +++ b/tests/cases/fourslash/quicklInfoDisplayPartsInterfaceMembers.ts @@ -0,0 +1,75 @@ +/// + +////interface I { +//// /*1*/property: string; +//// /*2*/method(): string; +//// (): string; +//// new (): I; +////} +////var iInstance: I; +/////*3*/iInstance./*4*/property = /*5*/iInstance./*6*/method(); +/////*7*/iInstance(); +////var /*8*/anotherInstance = new /*9*/iInstance(); + +function verifyInterfaceProperty(markerName: string) { + goTo.marker(markerName); + verify.verifyQuickInfo("property", "", { start: test.markerByName(markerName).position, length: "property".length }, + [{ text: "(", kind: "punctuation" }, { text: "property", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "I", kind: "interfaceName" }, { text: ".", kind: "punctuation" }, { text: "property", kind: "propertyName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); +} + +function verifyInterfaceMethod(markerName: string) { + goTo.marker(markerName); + verify.verifyQuickInfo("method", "", { start: test.markerByName(markerName).position, length: "method".length }, + [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "I", kind: "interfaceName" }, { text: ".", kind: "punctuation" }, { text: "method", kind: "methodName" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); +} + +function verifyInterfaceInstanceVar(markerName: string, instanceName: string) { + goTo.marker(markerName); + verify.verifyQuickInfo("var", "", { start: test.markerByName(markerName).position, length: instanceName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }], + []); +} + +verifyInterfaceProperty('1'); +verifyInterfaceMethod("2"); + +verifyInterfaceInstanceVar("3", "iInstance"); +verifyInterfaceProperty("4"); +verifyInterfaceInstanceVar("5", "iInstance"); +verifyInterfaceMethod("6"); + +// Call signature +goTo.marker("7"); +verify.verifyQuickInfo("var", "", { start: test.markerByName("7").position, length: "iInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "iInstance", kind: "localName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); + +verifyInterfaceInstanceVar("8", "anotherInstance"); + +// Cosntruct signature +goTo.marker("9"); +verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, length: "iInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "iInstance", kind: "localName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "new", kind: "keyword" }, { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }], + []); \ No newline at end of file From 3b2dee1329ceecc1be20ebfdd9d41a319cdd369e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 20 Nov 2014 22:36:27 -0800 Subject: [PATCH 08/39] Rename functions as per code review feedback --- src/harness/fourslash.ts | 4 ++-- tests/cases/fourslash/fourslash.ts | 6 +++--- ...ayPartsClass.ts => quickInfoDisplayPartsClass.ts} | 10 +++++----- ...ors.ts => quickInfoDisplayPartsClassAccessors.ts} | 10 +++++----- ...r.ts => quickInfoDisplayPartsClassConstructor.ts} | 12 ++++++------ ...Method.ts => quickInfoDisplayPartsClassMethod.ts} | 6 +++--- ...erty.ts => quickInfoDisplayPartsClassProperty.ts} | 6 +++--- ...nterface.ts => quickInfoDisplayPartsInterface.ts} | 6 +++--- ...s.ts => quickInfoDisplayPartsInterfaceMembers.ts} | 10 +++++----- 9 files changed, 35 insertions(+), 35 deletions(-) rename tests/cases/fourslash/{quicklInfoDisplayPartsClass.ts => quickInfoDisplayPartsClass.ts} (71%) rename tests/cases/fourslash/{quicklInfoDisplayPartsClassAccessors.ts => quickInfoDisplayPartsClassAccessors.ts} (86%) rename tests/cases/fourslash/{quicklInfoDisplayPartsClassConstructor.ts => quickInfoDisplayPartsClassConstructor.ts} (87%) rename tests/cases/fourslash/{quicklInfoDisplayPartsClassMethod.ts => quickInfoDisplayPartsClassMethod.ts} (86%) rename tests/cases/fourslash/{quicklInfoDisplayPartsClassProperty.ts => quickInfoDisplayPartsClassProperty.ts} (86%) rename tests/cases/fourslash/{quicklInfoDisplayPartsInterface.ts => quickInfoDisplayPartsInterface.ts} (65%) rename tests/cases/fourslash/{quicklInfoDisplayPartsInterfaceMembers.ts => quickInfoDisplayPartsInterfaceMembers.ts} (82%) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index e30b956285d..7f6e3473346 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -769,7 +769,7 @@ module FourSlash { return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue; } - public quickInfoIs(negative: boolean, expectedText?: string, expectedDocumentation?: string) { + public verifyQuickInfoString(negative: boolean, expectedText?: string, expectedDocumentation?: string) { [expectedText, expectedDocumentation].forEach(str => { if (str) { this.scenarioActions.push(''); @@ -799,7 +799,7 @@ module FourSlash { } - public verifyQuickInfo(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, + public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, displayParts: { text: string; kind: string; }[], documentation: { text: string; kind: string; }[]) { this.scenarioActions.push(''); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 2e110f0d8cc..f61180567df 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -231,7 +231,7 @@ module FourSlashInterface { } public quickInfoIs(expectedText?: string, expectedDocumentation?: string) { - FourSlash.currentTestState.quickInfoIs(this.negative, expectedText, expectedDocumentation); + FourSlash.currentTestState.verifyQuickInfoString(this.negative, expectedText, expectedDocumentation); } public quickInfoExists() { @@ -435,10 +435,10 @@ module FourSlashInterface { FourSlash.currentTestState.verifyRenameLocations(findInStrings, findInComments); } - public verifyQuickInfo(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, + public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, displayParts: { text: string; kind: string; }[], documentation: { text: string; kind: string; }[]) { - FourSlash.currentTestState.verifyQuickInfo(kind, kindModifiers, textSpan, displayParts, documentation); + FourSlash.currentTestState.verifyQuickInfoDisplayParts(kind, kindModifiers, textSpan, displayParts, documentation); } } diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClass.ts b/tests/cases/fourslash/quickInfoDisplayPartsClass.ts similarity index 71% rename from tests/cases/fourslash/quicklInfoDisplayPartsClass.ts rename to tests/cases/fourslash/quickInfoDisplayPartsClass.ts index 8e4dc346cbc..ee38c717922 100644 --- a/tests/cases/fourslash/quicklInfoDisplayPartsClass.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsClass.ts @@ -6,19 +6,19 @@ ////var /*4*/cVal = /*5*/c; goTo.marker('1'); -verify.verifyQuickInfo("class", "", { start: test.markerByName("1").position, length: "c".length }, +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("1").position, length: "c".length }, [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], []); goTo.marker('2'); -verify.verifyQuickInfo("var", "", { start: test.markerByName("2").position, length: "cInstance".length }, +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("2").position, length: "cInstance".length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], []); goTo.marker('3'); -verify.verifyQuickInfo("constructor", "", { start: test.markerByName("3").position, length: "c".length }, +verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName("3").position, length: "c".length }, [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }, { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, @@ -26,7 +26,7 @@ verify.verifyQuickInfo("constructor", "", { start: test.markerByName("3").positi []); goTo.marker('4'); -verify.verifyQuickInfo("var", "", { start: test.markerByName("4").position, length: "cVal".length }, +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("4").position, length: "cVal".length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "cVal", kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, @@ -34,6 +34,6 @@ verify.verifyQuickInfo("var", "", { start: test.markerByName("4").position, leng []); goTo.marker('5'); -verify.verifyQuickInfo("class", "", { start: test.markerByName("5").position, length: "c".length }, +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("5").position, length: "c".length }, [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], []); \ No newline at end of file diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClassAccessors.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassAccessors.ts similarity index 86% rename from tests/cases/fourslash/quicklInfoDisplayPartsClassAccessors.ts rename to tests/cases/fourslash/quickInfoDisplayPartsClassAccessors.ts index 7b93177076a..f3a0f90ea33 100644 --- a/tests/cases/fourslash/quicklInfoDisplayPartsClassAccessors.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassAccessors.ts @@ -38,7 +38,7 @@ function verifyClassProperty(markerName: string, kindModifiers: string, propertyName: string) { goTo.marker(markerName); - verify.verifyQuickInfo("property", kindModifiers, { start: test.markerByName(markerName).position, length: propertyName.length }, + verify.verifyQuickInfoDisplayParts("property", kindModifiers, { start: test.markerByName(markerName).position, length: propertyName.length }, [{ text: "(", kind: "punctuation" }, { text: "property", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }, { text: ".", kind: "punctuation" }, { text: propertyName, kind: "propertyName" }, @@ -97,7 +97,7 @@ verifyProtectedStaticProperty('81'); verifyProtectedStaticProperty('81s'); goTo.marker('9'); -verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], @@ -106,14 +106,14 @@ verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, leng verifyPublicProperty('10'); goTo.marker('11'); -verify.verifyQuickInfo("class", "", { start: test.markerByName("11").position, length: "c".length }, +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("11").position, length: "c".length }, [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], []); verifyStaticProperty('12'); goTo.marker('9s'); -verify.verifyQuickInfo("var", "", { start: test.markerByName("9s").position, length: "cInstance".length }, +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9s").position, length: "cInstance".length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], @@ -122,7 +122,7 @@ verify.verifyQuickInfo("var", "", { start: test.markerByName("9s").position, len verifyPublicProperty('10s'); goTo.marker('11s'); -verify.verifyQuickInfo("class", "", { start: test.markerByName("11s").position, length: "c".length }, +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("11s").position, length: "c".length }, [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], []); diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClassConstructor.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassConstructor.ts similarity index 87% rename from tests/cases/fourslash/quicklInfoDisplayPartsClassConstructor.ts rename to tests/cases/fourslash/quickInfoDisplayPartsClassConstructor.ts index b71a7aeab9e..1145e43e1da 100644 --- a/tests/cases/fourslash/quicklInfoDisplayPartsClassConstructor.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassConstructor.ts @@ -29,7 +29,7 @@ function verifyNonOverloadSignature(marker: string, textSpanLength: number) { goTo.marker(marker); - verify.verifyQuickInfo("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, + verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }, { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, @@ -39,7 +39,7 @@ function verifyNonOverloadSignature(marker: string, textSpanLength: number) { function verifyClassInstance(markerName: string, instanceName: string, className: string) { goTo.marker(markerName); - verify.verifyQuickInfo("var", "", { start: test.markerByName(markerName).position, length: instanceName.length }, + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: instanceName.length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: className, kind: "className" }], @@ -48,14 +48,14 @@ function verifyClassInstance(markerName: string, instanceName: string, className function verifyClass(markerName: string, className: string) { goTo.marker(markerName); - verify.verifyQuickInfo("class", "", { start: test.markerByName(markerName).position, length: className.length }, + verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName(markerName).position, length: className.length }, [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: className, kind: "className" }], []); } function verifyTypeOfClass(markerName: string, typeOfVarName: string, className: string) { goTo.marker(markerName); - verify.verifyQuickInfo("var", "", { start: test.markerByName(markerName).position, length: typeOfVarName.length }, + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: typeOfVarName.length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: typeOfVarName, kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, @@ -65,7 +65,7 @@ function verifyTypeOfClass(markerName: string, typeOfVarName: string, className: function verifySingleOverloadSignature(marker: string, textSpanLength: number, parameterType: string) { goTo.marker(marker); - verify.verifyQuickInfo("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, + verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "cWithOverloads", kind: "className" }, { text: "(", kind: "punctuation" }, { text: "x", kind: "parameterName" }, { text: ":", kind: "punctuation" }, @@ -81,7 +81,7 @@ function verifySingleOverloadSignature(marker: string, textSpanLength: number, p function verifyMultipleOverloadSignature(marker: string, textSpanLength: number, parameterType: string) { goTo.marker(marker); - verify.verifyQuickInfo("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, + verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "cWithMultipleOverloads", kind: "className" }, { text: "(", kind: "punctuation" }, { text: "x", kind: "parameterName" }, { text: ":", kind: "punctuation" }, diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClassMethod.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassMethod.ts similarity index 86% rename from tests/cases/fourslash/quicklInfoDisplayPartsClassMethod.ts rename to tests/cases/fourslash/quickInfoDisplayPartsClassMethod.ts index 5e261bc36a5..dbe225aa124 100644 --- a/tests/cases/fourslash/quicklInfoDisplayPartsClassMethod.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassMethod.ts @@ -22,7 +22,7 @@ function verifyClassMethod(markerName: string, kindModifiers: string, methodName: string) { goTo.marker(markerName); - verify.verifyQuickInfo("method", kindModifiers, { start: test.markerByName(markerName).position, length: methodName.length }, + verify.verifyQuickInfoDisplayParts("method", kindModifiers, { start: test.markerByName(markerName).position, length: methodName.length }, [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }, { text: ".", kind: "punctuation" }, { text: methodName, kind: "methodName" }, @@ -70,7 +70,7 @@ verifyPrivateStaticMethod('8'); verifyProtectedStaticMethod('81'); goTo.marker('9'); -verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], @@ -79,7 +79,7 @@ verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, leng verifyPublicMethod('10'); goTo.marker('11'); -verify.verifyQuickInfo("class", "", { start: test.markerByName("11").position, length: "c".length }, +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("11").position, length: "c".length }, [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], []); diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClassProperty.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassProperty.ts similarity index 86% rename from tests/cases/fourslash/quicklInfoDisplayPartsClassProperty.ts rename to tests/cases/fourslash/quickInfoDisplayPartsClassProperty.ts index 9f5360ce410..a03bc3cd42b 100644 --- a/tests/cases/fourslash/quicklInfoDisplayPartsClassProperty.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassProperty.ts @@ -22,7 +22,7 @@ function verifyClassProperty(markerName: string, kindModifiers: string, propertyName: string) { goTo.marker(markerName); - verify.verifyQuickInfo("property", kindModifiers, { start: test.markerByName(markerName).position, length: propertyName.length }, + verify.verifyQuickInfoDisplayParts("property", kindModifiers, { start: test.markerByName(markerName).position, length: propertyName.length }, [{ text: "(", kind: "punctuation" }, { text: "property", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }, { text: ".", kind: "punctuation" }, { text: propertyName, kind: "propertyName" }, @@ -69,7 +69,7 @@ verifyPrivateStaticProperty('8'); verifyProtectedStaticProperty('81'); goTo.marker('9'); -verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], @@ -78,7 +78,7 @@ verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, leng verifyPublicProperty('10'); goTo.marker('11'); -verify.verifyQuickInfo("class", "", { start: test.markerByName("11").position, length: "c".length }, +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("11").position, length: "c".length }, [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], []); diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsInterface.ts b/tests/cases/fourslash/quickInfoDisplayPartsInterface.ts similarity index 65% rename from tests/cases/fourslash/quicklInfoDisplayPartsInterface.ts rename to tests/cases/fourslash/quickInfoDisplayPartsInterface.ts index 0e3e4d01181..410d45d32a1 100644 --- a/tests/cases/fourslash/quicklInfoDisplayPartsInterface.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsInterface.ts @@ -5,18 +5,18 @@ ////var /*2*/iInstance: /*3*/i; goTo.marker('1'); -verify.verifyQuickInfo("interface", "", { start: test.markerByName("1").position, length: "i".length }, +verify.verifyQuickInfoDisplayParts("interface", "", { start: test.markerByName("1").position, length: "i".length }, [{ text: "interface", kind: "keyword" }, { text: " ", kind: "space" }, { text: "i", kind: "interfaceName" }], []); goTo.marker('2'); -verify.verifyQuickInfo("var", "", { start: test.markerByName("2").position, length: "iInstance".length }, +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("2").position, length: "iInstance".length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "iInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "i", kind: "interfaceName" }], []); goTo.marker('3'); -verify.verifyQuickInfo("interface", "", { start: test.markerByName("3").position, length: "i".length }, +verify.verifyQuickInfoDisplayParts("interface", "", { start: test.markerByName("3").position, length: "i".length }, [{ text: "interface", kind: "keyword" }, { text: " ", kind: "space" }, { text: "i", kind: "interfaceName" }], []); \ No newline at end of file diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsInterfaceMembers.ts b/tests/cases/fourslash/quickInfoDisplayPartsInterfaceMembers.ts similarity index 82% rename from tests/cases/fourslash/quicklInfoDisplayPartsInterfaceMembers.ts rename to tests/cases/fourslash/quickInfoDisplayPartsInterfaceMembers.ts index e12bc81a7be..1b7fdad23aa 100644 --- a/tests/cases/fourslash/quicklInfoDisplayPartsInterfaceMembers.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsInterfaceMembers.ts @@ -13,7 +13,7 @@ function verifyInterfaceProperty(markerName: string) { goTo.marker(markerName); - verify.verifyQuickInfo("property", "", { start: test.markerByName(markerName).position, length: "property".length }, + verify.verifyQuickInfoDisplayParts("property", "", { start: test.markerByName(markerName).position, length: "property".length }, [{ text: "(", kind: "punctuation" }, { text: "property", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }, { text: ".", kind: "punctuation" }, { text: "property", kind: "propertyName" }, @@ -23,7 +23,7 @@ function verifyInterfaceProperty(markerName: string) { function verifyInterfaceMethod(markerName: string) { goTo.marker(markerName); - verify.verifyQuickInfo("method", "", { start: test.markerByName(markerName).position, length: "method".length }, + verify.verifyQuickInfoDisplayParts("method", "", { start: test.markerByName(markerName).position, length: "method".length }, [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }, { text: ".", kind: "punctuation" }, { text: "method", kind: "methodName" }, @@ -34,7 +34,7 @@ function verifyInterfaceMethod(markerName: string) { function verifyInterfaceInstanceVar(markerName: string, instanceName: string) { goTo.marker(markerName); - verify.verifyQuickInfo("var", "", { start: test.markerByName(markerName).position, length: instanceName.length }, + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: instanceName.length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }], @@ -51,7 +51,7 @@ verifyInterfaceMethod("6"); // Call signature goTo.marker("7"); -verify.verifyQuickInfo("var", "", { start: test.markerByName("7").position, length: "iInstance".length }, +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("7").position, length: "iInstance".length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "iInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }, @@ -64,7 +64,7 @@ verifyInterfaceInstanceVar("8", "anotherInstance"); // Cosntruct signature goTo.marker("9"); -verify.verifyQuickInfo("var", "", { start: test.markerByName("9").position, length: "iInstance".length }, +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9").position, length: "iInstance".length }, [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "iInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, From 8f04914b1591e5a4ac484d534661697643de0e33 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 20 Nov 2014 23:19:50 -0800 Subject: [PATCH 09/39] Test cases for enum and enum members --- .../fourslash/quickInfoDisplayPartsEnum.ts | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsEnum.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsEnum.ts b/tests/cases/fourslash/quickInfoDisplayPartsEnum.ts new file mode 100644 index 00000000000..405f9db936e --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsEnum.ts @@ -0,0 +1,76 @@ +/// + +////enum /*1*/E { +//// /*2*/e1, +//// /*3*/e2 = 10, +//// /*4*/e3 +////} +////var /*5*/eInstance: /*6*/E; +/////*7*/eInstance = /*8*/E./*9*/e1; +/////*10*/eInstance = /*11*/E./*12*/e2; +/////*13*/eInstance = /*14*/E./*15*/e3; +////const enum /*16*/constE { +//// /*17*/e1, +//// /*18*/e2 = 10, +//// /*19*/e3 +////} +////var /*20*/eInstance1: /*21*/constE; +/////*22*/eInstance1 = /*23*/constE./*24*/e1; +/////*25*/eInstance1 = /*26*/constE./*27*/e2; +/////*28*/eInstance1 = /*29*/constE./*30*/e3; + +var marker = 0; +function verifyEnumDeclaration(enumName: string, instanceName: string, isConst?: boolean) { + verifyEnumDisplay(); + + verifyEnumMemberDisplay("e1", 0); + verifyEnumMemberDisplay("e2", 10); + verifyEnumMemberDisplay("e3", 11); + + verifyInstance(); + verifyEnumDisplay(); + + verifyInstance(); + verifyEnumDisplay(); + verifyEnumMemberDisplay("e1", 0); + + verifyInstance(); + verifyEnumDisplay(); + verifyEnumMemberDisplay("e2", 10); + + verifyInstance(); + verifyEnumDisplay(); + verifyEnumMemberDisplay("e3", 11); + + function verifyEnumDisplay() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("enum", "", { start: test.markerByName(marker.toString()).position, length: enumName.length }, + (isConst ? [{ text: "const", kind: "keyword" }, { text: " ", kind: "space" }] : []).concat( + [{ text: "enum", kind: "keyword" }, { text: " ", kind: "space" }, { text: enumName, kind: "enumName" }]), + []);; + } + + function verifyEnumMemberDisplay(enumMemberName: string, initializer: number) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(marker.toString()).position, length: enumMemberName.length }, + [{ text: "(", kind: "punctuation" }, { text: "enum member", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: enumName, kind: "enumName" }, { text: ".", kind: "punctuation" }, { text: enumMemberName, kind: "enumMemberName" }, + { text: " ", kind: "space" }, { text: "=", kind: "operator" }, { text: " ", kind: "space" }, { text: initializer.toString(), kind: "numericLiteral" }], + []); + } + + function verifyInstance() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(marker.toString()).position, length: instanceName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: enumName, kind: "enumName" }], + []); + } +} + +verifyEnumDeclaration("E", "eInstance"); +verifyEnumDeclaration("constE", "eInstance1", /*isConst*/ true); From 5c796ec6f57f264ff98d7e203659926da3aa9cf2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 00:10:06 -0800 Subject: [PATCH 10/39] Fix and add test case for display parts for type aliases --- src/services/services.ts | 9 ++-- .../quickInfoDisplayPartsTypeAlias.ts | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsTypeAlias.ts diff --git a/src/services/services.ts b/src/services/services.ts index 306d679eceb..99135f9ea27 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1464,6 +1464,9 @@ module ts { else if (flags & SymbolFlags.Module) { return SymbolDisplayPartKind.moduleName; } else if (flags & SymbolFlags.Method) { return SymbolDisplayPartKind.methodName; } else if (flags & SymbolFlags.TypeParameter) { return SymbolDisplayPartKind.typeParameterName; } + else if (flags & SymbolFlags.TypeAlias) { return SymbolDisplayPartKind.aliasName; } + else if (flags & SymbolFlags.Import) { return SymbolDisplayPartKind.aliasName; } + return SymbolDisplayPartKind.text; } @@ -3012,7 +3015,7 @@ module ts { displayParts.push(spacePart()); addFullSymbolName(symbol); displayParts.push(spacePart()); - displayParts.push(punctuationPart(SyntaxKind.EqualsToken)); + displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); displayParts.push.apply(displayParts, typeToDisplayParts(typeResolver, typeResolver.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } @@ -3084,7 +3087,7 @@ module ts { var importDeclaration = declaration; if (importDeclaration.externalModuleName) { displayParts.push(spacePart()); - displayParts.push(punctuationPart(SyntaxKind.EqualsToken)); + displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); displayParts.push(keywordPart(SyntaxKind.RequireKeyword)); displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); @@ -3095,7 +3098,7 @@ module ts { var internalAliasSymbol = typeResolver.getSymbolInfo(importDeclaration.entityName); if (internalAliasSymbol) { displayParts.push(spacePart()); - displayParts.push(punctuationPart(SyntaxKind.EqualsToken)); + displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); addFullSymbolName(internalAliasSymbol, enclosingDeclaration); } diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeAlias.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeAlias.ts new file mode 100644 index 00000000000..5441ca35364 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsTypeAlias.ts @@ -0,0 +1,42 @@ +/// + +////class /*1*/c { +////} +////type /*2*/t1 = /*3*/c; +////var /*4*/cInstance: /*5*/t1 = new /*6*/c(); + +function verifyClassDisplay(markerName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName(markerName).position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); +} + +function verifyTypeAliasDisplay(markerName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("type", "", { start: test.markerByName(markerName).position, length: "t1".length }, + [{ text: "type", kind: "keyword" }, { text: " ", kind: "space" }, { text: "t1", kind: "aliasName" }, + { text: " ", kind: "space" }, { text: "=", kind: "operator" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); +} + +verifyClassDisplay('1'); +verifyTypeAliasDisplay('2'); +verifyClassDisplay('3'); + +goTo.marker('4'); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("4").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyTypeAliasDisplay('5'); + +goTo.marker('6'); +verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName("6").position, length: "c".length }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); \ No newline at end of file From 1d8637630426496e653f4e394288be9c78a7077c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 00:48:30 -0800 Subject: [PATCH 11/39] Test for parmaeters --- .../quickInfoDisplayPartsParameters.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsParameters.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsParameters.ts b/tests/cases/fourslash/quickInfoDisplayPartsParameters.ts new file mode 100644 index 00000000000..a825030c987 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsParameters.ts @@ -0,0 +1,45 @@ +/// + +////function /*1*/foo(/*2*/param: string, /*3*/optionalParam?: string, /*4*/paramWithInitializer = "hello", .../*5*/restParam: string[]) { +//// /*6*/param = "Hello"; +//// /*7*/optionalParam = "World"; +//// /*8*/paramWithInitializer = "Hello"; +//// /*9*/restParam[0] = "World"; +////} + +goTo.marker("1"); +verify.verifyQuickInfoDisplayParts("function", "", { start: test.markerByName('1').position, length: "foo".length }, + [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "foo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "param", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "optionalParam", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "paramWithInitializer", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "...", kind: "punctuation" }, { text: "restParam", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "string", kind: "keyword" } , { text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); + +var marker = 1; +function verifyParam(parameterName: string, isRest: boolean) { + marker++; + goTo.marker(marker.toString()); + var displayParts = [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: parameterName, kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }]; + if (isRest) { + displayParts.push({ text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }); + } + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(marker.toString()).position, length: parameterName.length }, displayParts, []); +} + +verifyParam('param', /*isRest*/false); +verifyParam('optionalParam', /*isRest*/false); +verifyParam('paramWithInitializer', /*isRest*/false); +verifyParam('restParam', /*isRest*/true); + +verifyParam('param', /*isRest*/false); +verifyParam('optionalParam', /*isRest*/false); +verifyParam('paramWithInitializer', /*isRest*/false); +verifyParam('restParam', /*isRest*/true); From 3493e5f319fef4829b58b73172cf3bf3e9d519be Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 01:17:45 -0800 Subject: [PATCH 12/39] Tests for function display parts --- .../quickInfoDisplayPartsFunction.ts | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsFunction.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsFunction.ts b/tests/cases/fourslash/quickInfoDisplayPartsFunction.ts new file mode 100644 index 00000000000..a3c94a511b9 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsFunction.ts @@ -0,0 +1,76 @@ +/// + +////function /*1*/foo(param: string, optionalParam?: string, paramWithInitializer = "hello", ...restParam: string[]) { +////} +////function /*2*/foowithoverload(a: string): string; +////function /*3*/foowithoverload(a: number): number; +////function /*4*/foowithoverload(a: any): any { +//// return a; +////} +////function /*5*/foowith3overload(a: string): string; +////function /*6*/foowith3overload(a: number): number; +////function /*7*/foowith3overload(a: boolean): boolean; +////function /*8*/foowith3overload(a: any): any { +//// return a; +////} +/////*9*/foo("hello"); +/////*10*/foowithoverload("hello"); +/////*11*/foowithoverload(10); +/////*12*/foowith3overload("hello"); +/////*13*/foowith3overload(10); +/////*14*/foowith3overload(true); + +var marker = 0; +function verifyFunctionWithoutOverload() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("function", "", { start: test.markerByName(marker.toString()).position, length: "foo".length }, + [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "foo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "param", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "optionalParam", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "paramWithInitializer", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "...", kind: "punctuation" }, { text: "restParam", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, { text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyFunctionWithOverload(functionName: string, type: string, overloadCount: number) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("function", "", { start: test.markerByName(marker.toString()).position, length: functionName.length }, + [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: functionName, kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, { text: "+", kind: "operator" }, { text: overloadCount.toString(), kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: overloadCount === 1 ? "overload" : "overloads", kind: "text" }, { text: ")", kind: "punctuation" }], + []); +} + + +// Declarations +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); +verifyFunctionWithOverload("foowithoverload", "string", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); +verifyFunctionWithOverload("foowith3overload", "string", 2); + +// Calls +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); \ No newline at end of file From aa3c176aa6215d49ec8f9fb8525f45b5df2d2e4b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 12:24:58 -0800 Subject: [PATCH 13/39] Tests for local function --- .../quickInfoDisplayPartsLocalFunction.ts | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts b/tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts new file mode 100644 index 00000000000..b9578c7f522 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts @@ -0,0 +1,92 @@ +/// + +////function /*1*/outerFoo() { +//// function /*2*/foo(param: string, optionalParam?: string, paramWithInitializer = "hello", ...restParam: string[]) { +//// } +//// function /*3*/foowithoverload(a: string): string; +//// function /*4*/foowithoverload(a: number): number; +//// function /*5*/foowithoverload(a: any): any { +//// return a; +//// } +//// function /*6*/foowith3overload(a: string): string; +//// function /*7*/foowith3overload(a: number): number; +//// function /*8*/foowith3overload(a: boolean): boolean; +//// function /*9*/foowith3overload(a: any): any { +//// return a; +//// } +//// /*10*/foo("hello"); +//// /*11*/foowithoverload("hello"); +//// /*12*/foowithoverload(10); +//// /*13*/foowith3overload("hello"); +//// /*14*/foowith3overload(10); +//// /*15*/foowith3overload(true); +////} +/////*16*/outerFoo(); + +var marker = 0; +function verifyOuterFunction() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("function", "", { start: test.markerByName(marker.toString()).position, length: "outerFoo".length }, + [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "outerFoo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyFunctionWithoutOverload() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("local function", "", { start: test.markerByName(marker.toString()).position, length: "foo".length }, + [{ text: "(", kind: "punctuation" }, { text: "local function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "foo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "param", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "optionalParam", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "paramWithInitializer", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "...", kind: "punctuation" }, { text: "restParam", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, { text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyFunctionWithOverload(functionName: string, type: string, overloadCount: number) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("local function", "", { start: test.markerByName(marker.toString()).position, length: functionName.length }, + [{ text: "(", kind: "punctuation" }, { text: "local function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: functionName, kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, { text: "+", kind: "operator" }, { text: overloadCount.toString(), kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: overloadCount === 1 ? "overload" : "overloads", kind: "text" }, { text: ")", kind: "punctuation" }], + []); +} + + +// Declarations +verifyOuterFunction(); + +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); +verifyFunctionWithOverload("foowithoverload", "string", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); +verifyFunctionWithOverload("foowith3overload", "string", 2); + +// Calls +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); +verifyOuterFunction(); From f83f54acdcda2da7e3f3627ff20e38911dd8dffc Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 12:43:24 -0800 Subject: [PATCH 14/39] Tests for function expression --- ...quickInfoDisplayPartsFunctionExpression.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsFunctionExpression.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsFunctionExpression.ts b/tests/cases/fourslash/quickInfoDisplayPartsFunctionExpression.ts new file mode 100644 index 00000000000..2b88812d60d --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsFunctionExpression.ts @@ -0,0 +1,45 @@ +/// + +////var /*1*/x = function /*2*/foo() { +//// /*3*/foo(); +////}; +////var /*4*/y = function () { +////}; +////(function /*5*/foo1() { +//// /*6*/foo1(); +////})(); + +var marker = 0; +function verifyInstance(instanceName: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(marker.toString()).position, length: instanceName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyNamedFunctionExpression(functionName: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("local function", "", { start: test.markerByName(marker.toString()).position, length: functionName.length }, + [{ text: "(", kind: "punctuation" }, { text: "local function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: functionName, kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +verifyInstance("x"); +// Declaration +verifyNamedFunctionExpression("foo"); +// Call +verifyNamedFunctionExpression("foo"); + +verifyInstance("y"); + +// Declaration +verifyNamedFunctionExpression("foo1"); +// Call +verifyNamedFunctionExpression("foo1"); From d0d8c94377e18aacdbe8d881c509164c9dc049f0 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 12:52:10 -0800 Subject: [PATCH 15/39] Tests for arrow function expression --- ...InfoDisplayPartsArrowFunctionExpression.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts b/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts new file mode 100644 index 00000000000..24978cd44e1 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts @@ -0,0 +1,50 @@ +/// + +////var /*1*/x = /*5*/a => 10; +////var /*2*/y = (/*6*/a, /*7*/b) => 10; +////var /*3*/z = (/*8*/a: number) => 10; +////var /*4*/z2 = () => 10; + +var marker = 0; +function verifyInstance(instanceName: string, paramCount: number, type: string) { + marker++; + goTo.marker(marker.toString()); + var displayParts = [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }]; + + for (var i = 0; i < paramCount; i++) { + if (i) { + displayParts.push({ text: ",", kind: "punctuation" }, { text: " ", kind: "space" }); + } + displayParts.push({ text: i ? "a" : "b", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: type, kind: "keyword" }); + } + displayParts.push({ text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "=>", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "number", kind: "keyword" }); + + + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(marker.toString()).position, length: instanceName.length }, + displayParts, []); +} + +function verifyParameter(parameterName: string, type: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(marker.toString()).position, length: parameterName.length }, + [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: parameterName, kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: type, kind: "keyword" }], + []); +} + +verifyInstance("x", 1, "any"); +verifyInstance("y", 2, "any"); +verifyInstance("z", 1, "number"); +verifyInstance("z2", 0, "any"); + +verifyParameter("a", "any"); +verifyParameter("a", "any"); +verifyParameter("b", "any"); +verifyParameter("a", "number"); From 60c2d63987f9f094060a919ae4db49f5edf1233e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 13:02:53 -0800 Subject: [PATCH 16/39] Test cases for arrow function expression --- .../fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts b/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts index 24978cd44e1..3d996ae53ca 100644 --- a/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts @@ -17,7 +17,7 @@ function verifyInstance(instanceName: string, paramCount: number, type: string) if (i) { displayParts.push({ text: ",", kind: "punctuation" }, { text: " ", kind: "space" }); } - displayParts.push({ text: i ? "a" : "b", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + displayParts.push({ text: !i ? "a" : "b", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }); } displayParts.push({ text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, From 24d1d8d756409ef6f41f344e7677602fd9efc088 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 17:42:27 -0800 Subject: [PATCH 17/39] Tests for type parameters in class --- src/harness/fourslash.ts | 14 +- tests/cases/fourslash/fourslash.ts | 9 +- ...ickInfoDisplayPartsTypeParameterInClass.ts | 239 ++++++++++++++++++ 3 files changed, 255 insertions(+), 7 deletions(-) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInClass.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 7f6e3473346..f37dd8db902 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -800,17 +800,21 @@ module FourSlash { public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, - displayParts: { text: string; kind: string; }[], - documentation: { text: string; kind: string; }[]) { + displayParts: ts.SymbolDisplayPart[], + documentation: ts.SymbolDisplayPart[]) { this.scenarioActions.push(''); this.scenarioActions.push(''); + function getJsonString(object: any) { + return (JSON.stringify(object, /*replacer*/undefined, " ")); + } + var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); assert.equal(actualQuickInfo.kind, kind, this.messageAtLastKnownMarker("QuickInfo kind")); assert.equal(actualQuickInfo.kindModifiers, kindModifiers, this.messageAtLastKnownMarker("QuickInfo kindModifiers")); - assert.equal(JSON.stringify(actualQuickInfo.textSpan), JSON.stringify(textSpan), this.messageAtLastKnownMarker("QuickInfo textSpan")); - assert.equal(JSON.stringify(actualQuickInfo.displayParts), JSON.stringify(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts")); - assert.equal(JSON.stringify(actualQuickInfo.documentation), JSON.stringify(documentation), this.messageAtLastKnownMarker("QuickInfo documentation")); + assert.equal(getJsonString(actualQuickInfo.textSpan), getJsonString(textSpan), this.messageAtLastKnownMarker("QuickInfo textSpan")); + assert.equal(getJsonString(actualQuickInfo.displayParts), getJsonString(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts")); + assert.equal(getJsonString(actualQuickInfo.documentation), getJsonString(documentation), this.messageAtLastKnownMarker("QuickInfo documentation")); } public verifyRenameLocations(findInStrings: boolean, findInComments: boolean) { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index f61180567df..a093c2f3bf4 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -436,8 +436,7 @@ module FourSlashInterface { } public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, - displayParts: { text: string; kind: string; }[], - documentation: { text: string; kind: string; }[]) { + displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[]) { FourSlash.currentTestState.verifyQuickInfoDisplayParts(kind, kindModifiers, textSpan, displayParts, documentation); } } @@ -660,6 +659,12 @@ module fs { export var diagnostics = new FourSlashInterface.diagnostics(); export var cancellation = new FourSlashInterface.cancellation(); } +module ts { + export interface SymbolDisplayPart { + text: string; + kind: string; + } +} function verifyOperationIsCancelled(f) { FourSlash.verifyOperationIsCancelled(f); } diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInClass.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInClass.ts new file mode 100644 index 00000000000..dd32c8b236a --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInClass.ts @@ -0,0 +1,239 @@ +/// + +////class /*1*/c { +//// /*3*/constructor(/*4*/a: /*5*/T) { +//// } +//// /*6*/method(/*8*/a: /*9*/U, /*10*/b: /*11*/T) { +//// return /*12*/a; +//// } +////} +////var /*13*/cInstance = new /*14*/c("Hello"); +////var /*15*/cVal = /*16*/c; +/////*17*/cInstance./*18*/method("hello", "cello"); +////class /*19*/c2> { +//// /*22*/constructor(/*23*/a: /*24*/T) { +//// } +//// /*25*/method>(/*28*/a: /*29*/U, /*30*/b: /*31*/T) { +//// return /*32*/a; +//// } +////} +////var /*33*/cInstance1 = new /*34*/c2(/*35*/cInstance); +////var /*36*/cVal2 = /*37*/c2; +/////*38*/cInstance1./*39*/method(/*40*/cInstance, /*41*/cInstance); + +var marker = 0; +var markerName: string; + +function goToMarker() { + marker++; + markerName = marker.toString(); + goTo.marker(markerName); +} + +function getTypeParameterDisplay(instanceType: ts.SymbolDisplayPart[], + name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + return instanceType || + function () { + var typeParameterDisplay = [{ text: name, kind: "typeParameterName" }]; + if (optionalExtends) { + typeParameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + typeParameterDisplay = typeParameterDisplay.concat(optionalExtends); + } + return typeParameterDisplay + } (); +} + +function getClassDisplay(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + var classDisplay = [{ text: name, kind: "className" }, { text: "<", kind: "punctuation" }]; + classDisplay = classDisplay.concat(getTypeParameterDisplay(optionalInstanceType, "T", optionalExtends)); + classDisplay.push({ text: ">", kind: "punctuation" }); + return classDisplay; +} + +function verifyClassDisplay(name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + + verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }].concat( + getClassDisplay(name, undefined, optionalExtends)), []); +} + +function verifyTypeParameter(name: string, inDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + + var typeParameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "type parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "typeParameterName" }, + { text: " ", kind: "space" }, { text: "in", kind: "keyword" }, { text: " ", kind: "space" }]; + typeParameterDisplay = typeParameterDisplay.concat(inDisplay); + + verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + typeParameterDisplay, []); +} + +function verifyConstructor(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var constructorDisplay = [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }]; + constructorDisplay = constructorDisplay.concat(getClassDisplay(name, optionalInstanceType, optionalExtends)); + + constructorDisplay.push({ text: "(", kind: "punctuation" }, { text: "a", kind: "parameterName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + + constructorDisplay = constructorDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "T")); + + constructorDisplay.push({ text: ")", kind: "punctuation" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + + constructorDisplay = constructorDisplay.concat(getClassDisplay(name, optionalInstanceType)); + + verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName(markerName).position, length: optionalInstanceType ? name.length : "constructor".length }, + constructorDisplay, []); +} + +function verifyParameter(name: string, type: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var parameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: type, kind: "typeParameterName" }]; + if (optionalExtends) { + parameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + parameterDisplay = parameterDisplay.concat(optionalExtends); + } + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + parameterDisplay, []); +} + +function getMethodDisplay(name: string, className: string, + optionalInstanceType?: ts.SymbolDisplayPart[], optionalExtends?: ts.SymbolDisplayPart[]) { + var functionDisplay = getClassDisplay(className, optionalInstanceType, optionalExtends); + + functionDisplay.push({ text: ".", kind: "punctuation" }, { text: name, kind: "methodName" }, + { text: "<", kind: "punctuation" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U", optionalExtends)); + + functionDisplay.push({ text: ">", kind: "punctuation" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }); + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + functionDisplay.push({ text: ",", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "b", kind: "parameterName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "T")); + + functionDisplay.push({ text: ")", kind: "punctuation" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + + return functionDisplay; +} + +function verifyMethodDisplay(name: string, className: string, + optionalInstanceType?: ts.SymbolDisplayPart[], optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var functionDisplay = [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, + { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }].concat( + getMethodDisplay(name, className, optionalInstanceType, optionalExtends)); + + verify.verifyQuickInfoDisplayParts("method", "", + { start: test.markerByName(markerName).position, length: name.length }, + functionDisplay, []); +} + +function verifyClassInstance(name: string, typeDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(typeDisplay), + []); +} + +function verifyVarTypeOf(name: string, typeOfSymbol: ts.SymbolDisplayPart) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "typeof", kind: "keyword" }, + { text: " ", kind: "space" }].concat(typeOfSymbol), + []); +} + +var stringTypeDisplay = [{ text: "string", kind: "keyword" }]; +var extendsTypeDisplay = getClassDisplay("c", stringTypeDisplay); + +// Declaration +verifyClassDisplay("c"); +verifyTypeParameter("T", getClassDisplay("c")); + +// Constructor declaration +verifyConstructor("c"); +verifyParameter("a", "T"); +verifyTypeParameter("T", getClassDisplay("c")); + +// Method declaration +verifyMethodDisplay("method", "c"); +verifyTypeParameter("U", getMethodDisplay("method", "c")); +verifyParameter("a", "U"); +verifyTypeParameter("U", getMethodDisplay("method", "c")); +verifyParameter("b", "T"); +verifyTypeParameter("T", getClassDisplay("c")); +verifyParameter("a", "U"); + +// Instance creation +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); +verifyConstructor("c", stringTypeDisplay); + +// typeof assignment +verifyVarTypeOf("cVal", { text: "c", kind: "className" }); +verifyClassDisplay("c"); + +// Method call +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); +verifyMethodDisplay("method", "c", stringTypeDisplay); + +// With constraint +// Declaration +verifyClassDisplay("c2", getClassDisplay("c", stringTypeDisplay)); +verifyTypeParameter("T", getClassDisplay("c2", /*instanceType*/undefined, extendsTypeDisplay)); +verifyClassDisplay("c"); + +// Constructor declaration +verifyConstructor("c2", /*instanceType*/undefined, extendsTypeDisplay); +verifyParameter("a", "T", extendsTypeDisplay); +verifyTypeParameter("T", getClassDisplay("c2", /*instanceType*/undefined, extendsTypeDisplay)); + +// Method declaration +verifyMethodDisplay("method", "c2", /*instance*/undefined, extendsTypeDisplay); +verifyTypeParameter("U", getMethodDisplay("method", "c2", /*instance*/undefined, extendsTypeDisplay)); +verifyClassDisplay("c"); +verifyParameter("a", "U", extendsTypeDisplay); +verifyTypeParameter("U", getMethodDisplay("method", "c2", /*instance*/undefined, extendsTypeDisplay)); +verifyParameter("b", "T", extendsTypeDisplay); +verifyTypeParameter("T", getClassDisplay("c2", /*instanceType*/undefined, extendsTypeDisplay)); +verifyParameter("a", "U", extendsTypeDisplay); + +// Instance creation +verifyClassInstance("cInstance1", getClassDisplay("c2", extendsTypeDisplay)); +verifyConstructor("c2", extendsTypeDisplay); +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); + +// typeof assignment +verifyVarTypeOf("cVal2", { text: "c2", kind: "className" }); +verifyClassDisplay("c2", getClassDisplay("c", stringTypeDisplay)); + +// Method call +verifyClassInstance("cInstance1", getClassDisplay("c2", extendsTypeDisplay)); +verifyMethodDisplay("method", "c2", extendsTypeDisplay); +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); \ No newline at end of file From eeb5e0f8b20f24b824c8178e216a32c6ba667ba7 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 18:46:57 -0800 Subject: [PATCH 18/39] Type Parameters in interface --- src/harness/fourslash.ts | 24 +- ...nfoDisplayPartsTypeParameterInInterface.ts | 263 ++++++++++++++++++ 2 files changed, 282 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInInterface.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index f37dd8db902..c63791c90eb 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -805,16 +805,30 @@ module FourSlash { this.scenarioActions.push(''); this.scenarioActions.push(''); - function getJsonString(object: any) { - return (JSON.stringify(object, /*replacer*/undefined, " ")); + function getDisplayPartsJson(displayParts: ts.SymbolDisplayPart[]) { + var result = ""; + ts.forEach(displayParts, part => { + if (result) { + result += ",\n "; + } + else { + result = "[\n "; + } + result += JSON.stringify(part); + }); + if (result) { + result += "\n]"; + } + + return result; } var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); assert.equal(actualQuickInfo.kind, kind, this.messageAtLastKnownMarker("QuickInfo kind")); assert.equal(actualQuickInfo.kindModifiers, kindModifiers, this.messageAtLastKnownMarker("QuickInfo kindModifiers")); - assert.equal(getJsonString(actualQuickInfo.textSpan), getJsonString(textSpan), this.messageAtLastKnownMarker("QuickInfo textSpan")); - assert.equal(getJsonString(actualQuickInfo.displayParts), getJsonString(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts")); - assert.equal(getJsonString(actualQuickInfo.documentation), getJsonString(documentation), this.messageAtLastKnownMarker("QuickInfo documentation")); + assert.equal(JSON.stringify(actualQuickInfo.textSpan), JSON.stringify(textSpan), this.messageAtLastKnownMarker("QuickInfo textSpan")); + assert.equal(getDisplayPartsJson(actualQuickInfo.displayParts), getDisplayPartsJson(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts")); + assert.equal(getDisplayPartsJson(actualQuickInfo.documentation), getDisplayPartsJson(documentation), this.messageAtLastKnownMarker("QuickInfo documentation")); } public verifyRenameLocations(findInStrings: boolean, findInComments: boolean) { diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInInterface.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInInterface.ts new file mode 100644 index 00000000000..95797166ea2 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInInterface.ts @@ -0,0 +1,263 @@ +/// + +////interface /*1*/I { +//// new (/*4*/a: /*5*/U, /*6*/b: /*7*/T): /*8*/U; +//// (/*10*/a: /*11*/U, /*12*/b: /*13*/T): /*14*/U; +//// /*15*/method(/*17*/a: /*18*/U, /*19*/b: /*20*/T): /*21*/U; +////} +////var /*22*/iVal: /*23*/I; +////new /*24*/iVal("hello", "hello"); +/////*25*/iVal("hello", "hello"); +/////*26*/iVal./*27*/method("hello", "hello"); +////interface /*28*/I1> { +//// new >(/*33*/a: /*34*/U, /*35*/b: /*36*/T): /*37*/U; +//// >(/*40*/a: /*41*/U, /*42*/b: /*43*/T): /*44*/U; +//// /*45*/method>(/*48*/a: /*49*/U, /*50*/b: /*51*/T): /*52*/U; +////} +////var /*53*/iVal1: /*54*/I1>; +////new /*56*/iVal1(/*57*/iVal, /*58*/iVal); +/////*59*/iVal1(/*60*/iVal, /*61*/iVal); +/////*62*/iVal1./*63*/method(/*64*/iVal, /*65*/iVal); + +var marker = 0; +var markerName: string; + +function goToMarker() { + marker++; + markerName = marker.toString(); + goTo.marker(markerName); +} + +function getTypeParameterDisplay(instanceType: ts.SymbolDisplayPart[], + name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + return instanceType || + function () { + var typeParameterDisplay = [{ text: name, kind: "typeParameterName" }]; + if (optionalExtends) { + typeParameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + typeParameterDisplay = typeParameterDisplay.concat(optionalExtends); + } + return typeParameterDisplay + } (); +} + +function getInterfaceDisplay(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + var interfaceDisplay = [{ text: name, kind: "interfaceName" }, { text: "<", kind: "punctuation" }]; + interfaceDisplay = interfaceDisplay.concat(getTypeParameterDisplay(optionalInstanceType, "T", optionalExtends)); + interfaceDisplay.push({ text: ">", kind: "punctuation" }); + return interfaceDisplay; +} + +function verifyInterfaceDisplay(name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + + verify.verifyQuickInfoDisplayParts("interface", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "interface", kind: "keyword" }, { text: " ", kind: "space" }].concat( + getInterfaceDisplay(name, undefined, optionalExtends)), []); +} + +function verifyTypeParameter(name: string, inDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + + var typeParameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "type parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "typeParameterName" }, + { text: " ", kind: "space" }, { text: "in", kind: "keyword" }, { text: " ", kind: "space" }]; + typeParameterDisplay = typeParameterDisplay.concat(inDisplay); + + verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + typeParameterDisplay, []); +} + +function verifyParameter(name: string, typeParameterName: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var parameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: typeParameterName, kind: "typeParameterName" }]; + if (optionalExtends) { + parameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + parameterDisplay = parameterDisplay.concat(optionalExtends); + } + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + parameterDisplay, []); +} + +function getSignatureDisplay(isArrow: boolean, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + var functionDisplay: ts.SymbolDisplayPart[] = []; + + functionDisplay.push({ text: "<", kind: "punctuation" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U", optionalExtends)); + + functionDisplay.push({ text: ">", kind: "punctuation" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }); + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + functionDisplay.push({ text: ",", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "b", kind: "parameterName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "T")); + + functionDisplay.push({ text: ")", kind: "punctuation" }); + if (isArrow) { + functionDisplay.push({ text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }); + } + else { + functionDisplay.push({ text: ":", kind: "punctuation" }); + } + functionDisplay.push({ text: " ", kind: "space" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + + return functionDisplay; +} + +function getMethodDisplay(name: string, interfaceName: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + return getInterfaceDisplay(interfaceName, optionalInstanceType, optionalExtends).concat( + { text: ".", kind: "punctuation" }, { text: name, kind: "methodName" }).concat( + getSignatureDisplay(/*isArrow*/ false, optionalInstanceType, optionalExtends)); +} + +function getCallOrNewSignatureDisplay(isNew: boolean, isArrow: boolean, interfaceName?: string, + optionalInstanceType?: ts.SymbolDisplayPart[], optionalExtends?: ts.SymbolDisplayPart[]) { + var result: ts.SymbolDisplayPart[] = []; + if (isNew) { + result.push({ text: "new", kind: "keyword" }, { text: " ", kind: "space" }); + } + if (interfaceName) { + result.push({ text: interfaceName, kind: "interfaceName" }); + } + + return result.concat(getSignatureDisplay(isArrow, optionalInstanceType, optionalExtends)); +} + +function verifyMethodDisplay(name: string, interfaceName: string, + optionalInstanceType?: ts.SymbolDisplayPart[], optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var functionDisplay = [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, + { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }].concat( + getMethodDisplay(name, interfaceName, optionalInstanceType, optionalExtends)); + + verify.verifyQuickInfoDisplayParts("method", "", + { start: test.markerByName(markerName).position, length: name.length }, + functionDisplay, []); +} + +function verifyInterfaceVar(name: string, typeDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(typeDisplay), + []); +} + +var stringTypeDisplay = [{ text: "string", kind: "keyword" }]; +var extendsTypeDisplay = getInterfaceDisplay("I", stringTypeDisplay); + + +// Declaration +verifyInterfaceDisplay("I"); +verifyTypeParameter("T", getInterfaceDisplay("I")); + +// New declaration +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false)); +verifyParameter("a", "U"); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false)); +verifyParameter("b", "T"); +verifyTypeParameter("T", getInterfaceDisplay("I")); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false)); + +// Call declaration +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false)); +verifyParameter("a", "U"); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false)); +verifyParameter("b", "T"); +verifyTypeParameter("T", getInterfaceDisplay("I")); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false)); + +// Method declaration +verifyMethodDisplay("method", "I"); +verifyTypeParameter("U", getMethodDisplay("method", "I")); +verifyParameter("a", "U"); +verifyTypeParameter("U", getMethodDisplay("method", "I")); +verifyParameter("b", "T"); +verifyTypeParameter("T", getInterfaceDisplay("I")); +verifyTypeParameter("U", getMethodDisplay("method", "I")); + +// Instance +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyInterfaceDisplay("I"); + +// new +verifyInterfaceVar("iVal", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ true, "I", stringTypeDisplay)); + +// call +verifyInterfaceVar("iVal", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ true, "I", stringTypeDisplay)); + +// Method call +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyMethodDisplay("method", "I", stringTypeDisplay); + +// With constraint +// Declaration +verifyInterfaceDisplay("I1", extendsTypeDisplay); +verifyTypeParameter("T", getInterfaceDisplay("I1", /*instance*/undefined, extendsTypeDisplay)); +verifyInterfaceDisplay("I"); + +// New declaration +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); +verifyInterfaceDisplay("I"); +verifyParameter("a", "U", extendsTypeDisplay); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); +verifyParameter("b", "T", extendsTypeDisplay); +verifyTypeParameter("T", getInterfaceDisplay("I1", /*instance*/undefined, extendsTypeDisplay)); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); + +// Call declaration +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); +verifyInterfaceDisplay("I"); +verifyParameter("a", "U", extendsTypeDisplay); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); +verifyParameter("b", "T", extendsTypeDisplay); +verifyTypeParameter("T", getInterfaceDisplay("I1", /*instance*/undefined, extendsTypeDisplay)); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); + +// Method declaration +verifyMethodDisplay("method", "I1", /*instance*/ undefined, extendsTypeDisplay); +verifyTypeParameter("U", getMethodDisplay("method", "I1", /*instance*/ undefined, extendsTypeDisplay)); +verifyInterfaceDisplay("I"); +verifyParameter("a", "U", extendsTypeDisplay); +verifyTypeParameter("U", getMethodDisplay("method", "I1", /*instance*/ undefined, extendsTypeDisplay)); +verifyParameter("b", "T", extendsTypeDisplay); +verifyTypeParameter("T", getInterfaceDisplay("I1", /*instance*/undefined, extendsTypeDisplay)); +verifyTypeParameter("U", getMethodDisplay("method", "I1", /*instance*/ undefined, extendsTypeDisplay)); + +// Instance +verifyInterfaceVar("iVal1", getInterfaceDisplay("I1", extendsTypeDisplay)); +verifyInterfaceDisplay("I1", extendsTypeDisplay); +verifyInterfaceDisplay("I"); + +// new +verifyInterfaceVar("iVal1", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ true, "I1", extendsTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); + +// call +verifyInterfaceVar("iVal1", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ true, "I1", extendsTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); + +// Method call +verifyInterfaceVar("iVal1", getInterfaceDisplay("I1", extendsTypeDisplay)); +verifyMethodDisplay("method", "I1", extendsTypeDisplay); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); From d74568f999d561d77e09d5c54addff0046d6309c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 18:58:54 -0800 Subject: [PATCH 19/39] Tests for type parameter of function --- ...InfoDisplayPartsTypeParameterInFunction.ts | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts new file mode 100644 index 00000000000..0daabd43ad7 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts @@ -0,0 +1,118 @@ +/// + + +////function /*1*/foo(/*3*/a: /*4*/U) { +//// return /*5*/a; +////} +/////*6*/foo("Hello"); +////function /*7*/foo2(/*9*/a: /*10*/U) { +//// return /*11*/a; +////} +/////*12*/foo2("hello"); + +var marker = 0; +var markerName: string; + +function goToMarker() { + marker++; + markerName = marker.toString(); + goTo.marker(markerName); +} + +function getTypeParameterDisplay(instanceType: ts.SymbolDisplayPart[], + name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + return instanceType || + function () { + var typeParameterDisplay = [{ text: name, kind: "typeParameterName" }]; + if (optionalExtends) { + typeParameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + typeParameterDisplay = typeParameterDisplay.concat(optionalExtends); + } + return typeParameterDisplay + } (); +} + +function verifyTypeParameter(name: string, inDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + + var typeParameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "type parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "typeParameterName" }, + { text: " ", kind: "space" }, { text: "in", kind: "keyword" }, { text: " ", kind: "space" }]; + typeParameterDisplay = typeParameterDisplay.concat(inDisplay); + + verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + typeParameterDisplay, []); +} + +function verifyParameter(name: string, typeParameterName: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var parameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: typeParameterName, kind: "typeParameterName" }]; + if (optionalExtends) { + parameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + parameterDisplay = parameterDisplay.concat(optionalExtends); + } + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + parameterDisplay, []); +} + +function getFunctionDisplay(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + var functionDisplay = [{ text: name, kind: "functionName" }, { text: "<", kind: "punctuation" }]; + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U", optionalExtends)); + + functionDisplay.push({ text: ">", kind: "punctuation" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + + functionDisplay.push({ text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + + return functionDisplay; +} + +function verifyFunctionDisplay(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var functionDisplay = [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, + { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }].concat( + getFunctionDisplay(name, optionalInstanceType, optionalExtends)); + + verify.verifyQuickInfoDisplayParts("function", "", + { start: test.markerByName(markerName).position, length: name.length }, + functionDisplay, []); +} + +var stringTypeDisplay = [{ text: "string", kind: "keyword" }]; + +// Declaration +verifyFunctionDisplay("foo"); +verifyTypeParameter("U", getFunctionDisplay("foo")); +verifyParameter("a", "U"); +verifyTypeParameter("U", getFunctionDisplay("foo")); +verifyParameter("a", "U"); + +// Call +verifyFunctionDisplay("foo", stringTypeDisplay); + +// With constraint +// Declaration +verifyFunctionDisplay("foo2", /*instance*/ undefined, stringTypeDisplay); +verifyTypeParameter("U", getFunctionDisplay("foo2", /*instance*/ undefined, stringTypeDisplay)); +verifyParameter("a", "U", stringTypeDisplay); +verifyTypeParameter("U", getFunctionDisplay("foo2", /*instance*/ undefined, stringTypeDisplay)); +verifyParameter("a", "U", stringTypeDisplay); + +// Call +verifyFunctionDisplay("foo2", stringTypeDisplay); \ No newline at end of file From f2605e0c08afecf95fef00649f2e2edd3b415183 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Sun, 30 Nov 2014 23:02:56 -0800 Subject: [PATCH 20/39] Tests for var --- .../fourslash/quickInfoDisplayPartsVar.ts | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsVar.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsVar.ts b/tests/cases/fourslash/quickInfoDisplayPartsVar.ts new file mode 100644 index 00000000000..56ccceb3ab3 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsVar.ts @@ -0,0 +1,76 @@ +/// + +////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)); \ No newline at end of file From 62e9f082d6c5ce2a05542d3b169c14649a82b101 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Sun, 30 Nov 2014 23:16:22 -0800 Subject: [PATCH 21/39] Tests and fix symbol display for let --- src/services/services.ts | 1 + .../fourslash/quickInfoDisplayPartsLet.ts | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsLet.ts diff --git a/src/services/services.ts b/src/services/services.ts index 99135f9ea27..c768ffa6055 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2945,6 +2945,7 @@ module ts { case ScriptElementKind.memberVariableElement: case ScriptElementKind.variableElement: case ScriptElementKind.constElement: + case ScriptElementKind.letElement: case ScriptElementKind.parameterElement: case ScriptElementKind.localVariableElement: // If it is call or construct signature of lambda's write type name diff --git a/tests/cases/fourslash/quickInfoDisplayPartsLet.ts b/tests/cases/fourslash/quickInfoDisplayPartsLet.ts new file mode 100644 index 00000000000..b54617faa0e --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsLet.ts @@ -0,0 +1,83 @@ +/// + +////let /*1*/a = 10; +////function foo() { +//// let /*2*/b = /*3*/a; +//// if (b) { +//// let /*4*/b1 = 10; +//// } +////} +////module m { +//// let /*5*/c = 10; +//// export let /*6*/d = 10; +//// if (c) { +//// let /*7*/e = 10; +//// } +////} +////let /*8*/f: () => number; +////let /*9*/g = /*10*/f; +/////*11*/f(); +////let /*12*/h: { (a: string): number; (a: number): string; }; +////let /*13*/i = /*14*/h; +/////*15*/h(10); +/////*16*/h("hello"); + +var marker = 0; +function verifyVar(name: string, typeDisplay: ts.SymbolDisplayPart[], optionalNameDisplay?: ts.SymbolDisplayPart[], optionalKindModifiers?: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("let", optionalKindModifiers || "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "let", 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", numberTypeDisplay); +verifyVar("b", numberTypeDisplay); +verifyVar("a", numberTypeDisplay); +verifyVar("b1", numberTypeDisplay); +verifyVar("c", numberTypeDisplay); +verifyVar("d", numberTypeDisplay, [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "d", kind: "localName" }], "export"); +verifyVar("e", numberTypeDisplay); + +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", functionTypeReturningNumber); +verifyVar("g", functionTypeReturningNumber); +verifyVar("f", functionTypeReturningNumber); +verifyVar("f", 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", typeLiteralWithOverloadCall); +verifyVar("i", typeLiteralWithOverloadCall); +verifyVar("h", 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", getFunctionType("number", "string", /*isArrow*/true).concat(overloadDisplay)); +verifyVar("h", getFunctionType("string", "number", /*isArrow*/true).concat(overloadDisplay)); \ No newline at end of file From f7e7dc7101914b8383a08c2ab64e514e9c9fb753 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Sun, 30 Nov 2014 23:21:30 -0800 Subject: [PATCH 22/39] Tests for const --- .../fourslash/quickInfoDisplayPartsConst.ts | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsConst.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsConst.ts b/tests/cases/fourslash/quickInfoDisplayPartsConst.ts new file mode 100644 index 00000000000..62295017dfc --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsConst.ts @@ -0,0 +1,83 @@ +/// + +////const /*1*/a = 10; +////function foo() { +//// const /*2*/b = /*3*/a; +//// if (b) { +//// const /*4*/b1 = 10; +//// } +////} +////module m { +//// const /*5*/c = 10; +//// export const /*6*/d = 10; +//// if (c) { +//// const /*7*/e = 10; +//// } +////} +////const /*8*/f: () => number = () => 10; +////const /*9*/g = /*10*/f; +/////*11*/f(); +////const /*12*/h: { (a: string): number; (a: number): string; } = a => a; +////const /*13*/i = /*14*/h; +/////*15*/h(10); +/////*16*/h("hello"); + +var marker = 0; +function verifyConst(name: string, typeDisplay: ts.SymbolDisplayPart[], optionalNameDisplay?: ts.SymbolDisplayPart[], optionalKindModifiers?: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("const", optionalKindModifiers || "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "const", 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" }]; + +verifyConst("a", numberTypeDisplay); +verifyConst("b", numberTypeDisplay); +verifyConst("a", numberTypeDisplay); +verifyConst("b1", numberTypeDisplay); +verifyConst("c", numberTypeDisplay); +verifyConst("d", numberTypeDisplay, [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "d", kind: "localName" }], "export"); +verifyConst("e", numberTypeDisplay); + +var functionTypeReturningNumber: ts.SymbolDisplayPart[] = [{ text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "number", kind: "keyword" }]; +verifyConst("f", functionTypeReturningNumber); +verifyConst("g", functionTypeReturningNumber); +verifyConst("f", functionTypeReturningNumber); +verifyConst("f", 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" }); + +verifyConst("h", typeLiteralWithOverloadCall); +verifyConst("i", typeLiteralWithOverloadCall); +verifyConst("h", 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" }]; + +verifyConst("h", getFunctionType("number", "string", /*isArrow*/true).concat(overloadDisplay)); +verifyConst("h", getFunctionType("string", "number", /*isArrow*/true).concat(overloadDisplay)); \ No newline at end of file From 948fc209a09df2609eb5c216217d627cb739fead Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Sun, 30 Nov 2014 23:51:38 -0800 Subject: [PATCH 23/39] Tests for modules --- src/services/services.ts | 1 + .../fourslash/quickInfoDisplayPartsModules.ts | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsModules.ts diff --git a/src/services/services.ts b/src/services/services.ts index c768ffa6055..5422b7de15d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2764,6 +2764,7 @@ module ts { if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; if (flags & SymbolFlags.EnumMember) return ScriptElementKind.variableElement; if (flags & SymbolFlags.Import) return ScriptElementKind.alias; + if (flags & SymbolFlags.Module) return ScriptElementKind.moduleElement; } return result; diff --git a/tests/cases/fourslash/quickInfoDisplayPartsModules.ts b/tests/cases/fourslash/quickInfoDisplayPartsModules.ts new file mode 100644 index 00000000000..c86bce474ff --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsModules.ts @@ -0,0 +1,63 @@ +/// + +////module /*1*/m { +//// var /*2*/moduleElemWithoutExport = 10; +//// export var /*3*/moduleElemWithExport = 10; +////} +////var /*4*/a = /*5*/m; +////var /*6*/b: typeof /*7*/m; +////module /*8*/m1./*9*/m2 { +//// var /*10*/moduleElemWithoutExport = 10; +//// export var /*11*/moduleElemWithExport = 10; +////} +////var /*12*/x = /*13*/m1./*14*/m2; +////var /*15*/y: typeof /*16*/m1./*17*/m2; + +var marker = 0; +function goToMarker() { + marker++; + goTo.marker(marker.toString()); +} + +function verifyModule(name: string, optionalParentName?: string) { + goToMarker(); + var moduleNameDisplay = [{ text: name, kind: "moduleName" }]; + if (optionalParentName) { + moduleNameDisplay = [{ text: optionalParentName, kind: "moduleName" }, { text: ".", kind: "punctuation" }].concat(moduleNameDisplay); + } + verify.verifyQuickInfoDisplayParts("module", optionalParentName ? "export" : "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "module", kind: "keyword" }, { text: " ", kind: "space" }].concat(moduleNameDisplay), + []); +} + +function verifyVar(name: string, optionalFullName?: ts.SymbolDisplayPart[], typeDisplay: ts.SymbolDisplayPart[]= [{ text: "number", kind: "keyword" }]) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", optionalFullName ? "export" : "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(optionalFullName || [{ text: name, kind: "localName" }]).concat( + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }).concat(typeDisplay), + []); +} + +verifyModule("m"); +verifyVar("moduleElemWithoutExport"); +verifyVar("moduleElemWithExport", [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "moduleElemWithExport", kind: "localName" }]); + +verifyVar("a", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "m", kind: "moduleName" }]); +verifyModule("m"); +verifyVar("b", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "m", kind: "moduleName" }]); +verifyModule("m"); + +verifyModule("m1"); +verifyModule("m2", "m1"); +verifyVar("moduleElemWithoutExport"); +verifyVar("moduleElemWithExport", [{ text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, + { text: "m2", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "moduleElemWithExport", kind: "localName" }]); +verifyVar("x", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, + { text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "m2", kind: "moduleName" }]); +verifyModule("m1"); +verifyModule("m2", "m1"); +verifyVar("y", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, + { text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "m2", kind: "moduleName" }]); +verifyModule("m1"); +verifyModule("m2", "m1"); From 136a8a725a2e945d41e2200b9aae0d30a0c05ef8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 1 Dec 2014 00:04:28 -0800 Subject: [PATCH 24/39] Tests for external modules --- .../quickInfoDisplayPartsExternalModules.ts | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsExternalModules.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsExternalModules.ts b/tests/cases/fourslash/quickInfoDisplayPartsExternalModules.ts new file mode 100644 index 00000000000..5a2f5e76d7f --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsExternalModules.ts @@ -0,0 +1,63 @@ +/// + +////export module /*1*/m { +//// var /*2*/moduleElemWithoutExport = 10; +//// export var /*3*/moduleElemWithExport = 10; +////} +////export var /*4*/a = /*5*/m; +////export var /*6*/b: typeof /*7*/m; +////export module /*8*/m1./*9*/m2 { +//// var /*10*/moduleElemWithoutExport = 10; +//// export var /*11*/moduleElemWithExport = 10; +////} +////export var /*12*/x = /*13*/m1./*14*/m2; +////export var /*15*/y: typeof /*16*/m1./*17*/m2; + +var marker = 0; +function goToMarker() { + marker++; + goTo.marker(marker.toString()); +} + +function verifyModule(name: string, optionalParentName?: string) { + goToMarker(); + var moduleNameDisplay = [{ text: name, kind: "moduleName" }]; + if (optionalParentName) { + moduleNameDisplay = [{ text: optionalParentName, kind: "moduleName" }, { text: ".", kind: "punctuation" }].concat(moduleNameDisplay); + } + verify.verifyQuickInfoDisplayParts("module", "export", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "module", kind: "keyword" }, { text: " ", kind: "space" }].concat(moduleNameDisplay), + []); +} + +function verifyVar(name: string, optionalFullName?: ts.SymbolDisplayPart[], typeDisplay: ts.SymbolDisplayPart[]= [{ text: "number", kind: "keyword" }]) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", name === "moduleElemWithoutExport" ? "" : "export", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(optionalFullName || [{ text: name, kind: "localName" }]).concat( + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }).concat(typeDisplay), + []); +} + +verifyModule("m"); +verifyVar("moduleElemWithoutExport"); +verifyVar("moduleElemWithExport", [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "moduleElemWithExport", kind: "localName" }]); + +verifyVar("a", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "m", kind: "moduleName" }]); +verifyModule("m"); +verifyVar("b", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "m", kind: "moduleName" }]); +verifyModule("m"); + +verifyModule("m1"); +verifyModule("m2", "m1"); +verifyVar("moduleElemWithoutExport"); +verifyVar("moduleElemWithExport", [{ text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, + { text: "m2", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "moduleElemWithExport", kind: "localName" }]); +verifyVar("x", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, + { text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "m2", kind: "moduleName" }]); +verifyModule("m1"); +verifyModule("m2", "m1"); +verifyVar("y", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, + { text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "m2", kind: "moduleName" }]); +verifyModule("m1"); +verifyModule("m2", "m1"); From 7108215da8e60736a754684cef7409fbf162542c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 1 Dec 2014 00:17:26 -0800 Subject: [PATCH 25/39] tests for internal alias --- ...uickInfoDisplayPartsInternalModuleAlias.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsInternalModuleAlias.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsInternalModuleAlias.ts b/tests/cases/fourslash/quickInfoDisplayPartsInternalModuleAlias.ts new file mode 100644 index 00000000000..335544a62db --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsInternalModuleAlias.ts @@ -0,0 +1,47 @@ +/// + +////module m.m1 { +//// export class c { +//// } +////} +////module m2 { +//// import /*1*/a1 = m; +//// new /*2*/a1.m1.c(); +//// import /*3*/a2 = m.m1; +//// new /*4*/a2.c(); +//// export import /*5*/a3 = m; +//// new /*6*/a3.m1.c(); +//// export import /*7*/a4 = m.m1; +//// new /*8*/a4.c(); +////} + +var marker = 0; +function goToMarker() { + marker++; + goTo.marker(marker.toString()); +} + +function verifyImport(name: string, assigningDisplay:ts.SymbolDisplayPart[], optionalParentName?: string) { + goToMarker(); + var moduleNameDisplay = [{ text: name, kind: "aliasName" }]; + if (optionalParentName) { + moduleNameDisplay = [{ text: optionalParentName, kind: "moduleName" }, { text: ".", kind: "punctuation" }].concat(moduleNameDisplay); + } + verify.verifyQuickInfoDisplayParts("alias", optionalParentName ? "export" : "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "import", kind: "keyword" }, { text: " ", kind: "space" }].concat(moduleNameDisplay).concat( + { text: " ", kind: "space" }, { text: "=", kind: "operator" }, { text: " ", kind: "space" }).concat(assigningDisplay), + []); +} + +var moduleMDisplay = [{ text: "m", kind: "moduleName" }]; +var moduleMDotM1Display = moduleMDisplay.concat({ text: ".", kind: "punctuation" }, { text: "m1", kind: "moduleName" }); + +verifyImport("a1", moduleMDisplay); +verifyImport("a1", moduleMDisplay); +verifyImport("a2", moduleMDotM1Display); +verifyImport("a2", moduleMDotM1Display); + +verifyImport("a3", moduleMDisplay, "m2"); +verifyImport("a3", moduleMDisplay, "m2"); +verifyImport("a4", moduleMDotM1Display, "m2"); +verifyImport("a4", moduleMDotM1Display, "m2"); \ No newline at end of file From 7edd253307d165398ef29203fdf7c49053159bfb Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 1 Dec 2014 00:26:26 -0800 Subject: [PATCH 26/39] Tests for external alias --- ...uickInfoDisplayPartsExternalModuleAlias.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts b/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts new file mode 100644 index 00000000000..a9e0be3fa02 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts @@ -0,0 +1,34 @@ +/// + +// @Filename: quickInfoDisplayPartsExternalModuleAlias_file0.ts +////export module m1 { +//// export class c { +//// } +////} + +// @Filename: quickInfoDisplayPartsExternalModuleAlias_file1.ts +////import /*1*/a1 = require("quickInfoDisplayPartsExternalModuleAlias_file0"); +////new /*2*/a1.m1.c(); +////export import /*3*/a2 = require("quickInfoDisplayPartsExternalModuleAlias_file0"); +////new /*4*/a2.m1.c(); + +var marker = 0; +function goToMarker() { + marker++; + goTo.marker(marker.toString()); +} + +function verifyImport(name: string, isExported: boolean) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("alias", isExported ? "export" : "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "import", kind: "keyword" }, { text: " ", kind: "space" }, { text: name, kind: "aliasName" }, + { text: " ", kind: "space" }, { text: "=", kind: "operator" }, { text: " ", kind: "space" }, + { text: "require", kind: "keyword" }, { text: "(", kind: "punctuation" }, + { text: "\"quickInfoDisplayPartsExternalModuleAlias_file0\"", kind: "stringLiteral" }, + { text: ")", kind: "punctuation" }], + []); +} +verifyImport("a1", /*isExported*/false); +verifyImport("a1", /*isExported*/false); +verifyImport("a2", /*isExported*/true); +verifyImport("a2", /*isExported*/true); \ No newline at end of file From a8badd921e9ee036f2d03eb10667a2355bd456c1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 2 Dec 2014 22:01:52 -0800 Subject: [PATCH 27/39] Update the name of 'PropertyAssignment' to 'LonghandPropertyAssignment'. 'PropertyAssignment' is now the name of the super interface brand we use for all thigns that can be members of an object literal. --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 12 ++++---- src/compiler/emitter.ts | 12 ++++---- src/compiler/parser.ts | 58 ++++++++++++++++++------------------- src/compiler/types.ts | 24 +++++++++++---- src/services/breakpoints.ts | 4 +-- src/services/services.ts | 8 ++--- 7 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a45561e7ed6..5051e771a29 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -397,7 +397,7 @@ module ts { } break; case SyntaxKind.Property: - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); break; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0e428b4a4e0..cdb0babd587 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1697,7 +1697,7 @@ module ts { if (declaration.initializer) { var type = checkAndMarkExpression(declaration.initializer); // Widening of property assignments is handled by checkObjectLiteral, exclude them here - if (declaration.kind !== SyntaxKind.PropertyAssignment) { + if (declaration.kind !== SyntaxKind.LonghandPropertyAssignment) { var unwidenedType = type; type = getWidenedType(type); if (type !== unwidenedType) { @@ -3247,7 +3247,7 @@ module ts { return !(node).typeParameters && !forEach((node).parameters, p => p.type); case SyntaxKind.ObjectLiteralExpression: return forEach((node).properties, p => - p.kind === SyntaxKind.PropertyAssignment && isContextSensitiveExpression((p).initializer)); + p.kind === SyntaxKind.LonghandPropertyAssignment && isContextSensitiveExpression((p).initializer)); case SyntaxKind.ArrayLiteralExpression: return forEach((node).elements, e => isContextSensitiveExpression(e)); case SyntaxKind.ConditionalExpression: @@ -4949,7 +4949,7 @@ module ts { return getTypeFromTypeNode((parent).type); case SyntaxKind.BinaryExpression: return getContextualTypeForBinaryOperand(node); - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: return getContextualTypeForPropertyExpression(node); case SyntaxKind.ArrayLiteralExpression: return getContextualTypeForElementExpression(node); @@ -5085,7 +5085,7 @@ module ts { if (member.flags & SymbolFlags.Property) { var memberDecl = member.declarations[0]; var type: Type; - if (memberDecl.kind === SyntaxKind.PropertyAssignment) { + if (memberDecl.kind === SyntaxKind.LonghandPropertyAssignment) { type = checkExpression(memberDecl.initializer, contextualMapper); } else { @@ -8573,7 +8573,7 @@ module ts { case SyntaxKind.Property: case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: case SyntaxKind.CallExpression: @@ -9022,7 +9022,7 @@ module ts { // This is necessary as an identifier in short-hand property assignment can contains two meaning: // property name and property value. if (location && location.kind === SyntaxKind.ShorthandPropertyAssignment) { - return resolveEntityName(location, (location).name, SymbolFlags.Value); + return resolveEntityName(location, (location).name, SymbolFlags.Value); } return undefined; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7193523bf96..38cd18aea07 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2122,7 +2122,7 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: @@ -2236,7 +2236,7 @@ module ts { emitTrailingComments(node); } - function emitDownlevelShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) { + function emitDownlevelShorthandPropertyAssignment(node: ShorthandPropertyAssignment) { emitLeadingComments(node); // Emit identifier as an identifier emit(node.name); @@ -2247,7 +2247,7 @@ module ts { emitTrailingComments(node); } - function emitShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) { + function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) { // If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example: // module m { // export var y; @@ -3525,7 +3525,7 @@ module ts { return emitArrayLiteral(node); case SyntaxKind.ObjectLiteralExpression: return emitObjectLiteral(node); - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: return emitPropertyAssignment(node); case SyntaxKind.ComputedPropertyName: return emitComputedPropertyName(node); @@ -3628,7 +3628,7 @@ module ts { // Emit node down-level switch (node.kind) { case SyntaxKind.ShorthandPropertyAssignment: - return emitDownlevelShorthandPropertyAssignment(node); + return emitDownlevelShorthandPropertyAssignment(node); } } else { @@ -3636,7 +3636,7 @@ module ts { Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Invalid ScriptTarget. We should emit as ES6 or above"); switch (node.kind) { case SyntaxKind.ShorthandPropertyAssignment: - return emitShorthandPropertyAssignment(node); + return emitShorthandPropertyAssignment(node); } } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b36ded65dc4..6f578433beb 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -223,7 +223,7 @@ module ts { child((node).type) || child((node).initializer); case SyntaxKind.Property: - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: return children(node.modifiers) || child((node).name) || @@ -583,7 +583,7 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.Property: case SyntaxKind.EnumMember: - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: return (parent).initializer === node; case SyntaxKind.ExpressionStatement: case SyntaxKind.IfStatement: @@ -641,7 +641,7 @@ module ts { case SyntaxKind.Method: return (node).questionToken !== undefined; case SyntaxKind.ShorthandPropertyAssignment: - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: case SyntaxKind.Property: return (node).questionToken !== undefined; } @@ -680,7 +680,7 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: @@ -3166,16 +3166,16 @@ module ts { return finishNode(node); } - function parsePropertyAssignment(): Declaration { + function parseShortOrLonghandPropertyAssignment(): PropertyAssignment { var nodePos = scanner.getStartPos(); + var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); var tokenIsIdentifier = isIdentifier(); var nameToken = token; var propertyName = parsePropertyName(); - var node: Declaration; if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - node = createNode(SyntaxKind.PropertyAssignment, nodePos); - node.name = propertyName; + var longhandDeclaration = createNode(SyntaxKind.LonghandPropertyAssignment, nodePos); + longhandDeclaration.name = propertyName; var sig = parseSignature(/*yieldAndGeneratorParameterContext:*/ !!asteriskToken); var body = parseFunctionBlock(!!asteriskToken, /* ignoreMissingOpenBrace */ false); @@ -3184,8 +3184,8 @@ module ts { // var x = 1; // var y = { x() { } } // otherwise this will bring y.x into the scope of x which is incorrect - (node).initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, asteriskToken, undefined, sig, body); - return finishNode(node); + longhandDeclaration.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, longhandDeclaration.pos, asteriskToken, undefined, sig, body); + return finishNode(longhandDeclaration); } // Disallowing of optional property assignments happens in the grammar checker. @@ -3193,29 +3193,29 @@ module ts { // Parse to check if it is short-hand property assignment or normal property assignment if ((token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBraceToken) && tokenIsIdentifier) { - var shorthandDeclaration = createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos); + var shorthandDeclaration = createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos); shorthandDeclaration.name = propertyName; shorthandDeclaration.questionToken = questionToken; return finishNode(shorthandDeclaration); } else { - var propertyDeclaration = createNode(SyntaxKind.PropertyAssignment, nodePos); - propertyDeclaration.name = propertyName; - propertyDeclaration.questionToken = questionToken; + var longhandDeclaration = createNode(SyntaxKind.LonghandPropertyAssignment, nodePos); + longhandDeclaration.name = propertyName; + longhandDeclaration.questionToken = questionToken; parseExpected(SyntaxKind.ColonToken); - propertyDeclaration.initializer = allowInAnd(parseAssignmentExpressionOrHigher); - return finishNode(propertyDeclaration); + longhandDeclaration.initializer = allowInAnd(parseAssignmentExpressionOrHigher); + return finishNode(longhandDeclaration); } } - function parseObjectLiteralMember(): Declaration { + function parsePropertyAssignment(): PropertyAssignment { var initialPos = getNodePos(); var initialToken = token; if (parseContextualModifier(SyntaxKind.GetKeyword) || parseContextualModifier(SyntaxKind.SetKeyword)) { var kind = initialToken === SyntaxKind.GetKeyword ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; - return parseMemberAccessorDeclaration(kind, initialPos, /*modifiers*/ undefined); + return parseAccessorDeclaration(kind, initialPos, /*modifiers*/ undefined); } - return parsePropertyAssignment(); + return parseShortOrLonghandPropertyAssignment(); } function parseObjectLiteralExpression(): ObjectLiteralExpression { @@ -3225,7 +3225,7 @@ module ts { node.flags |= NodeFlags.MultiLine; } - node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralMember); + node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parsePropertyAssignment); parseExpected(SyntaxKind.CloseBraceToken); return finishNode(node); } @@ -3772,8 +3772,8 @@ module ts { return parseInitializer(/*inParameter*/ false); } - function parseMemberAccessorDeclaration(kind: SyntaxKind, fullStart: number, modifiers: ModifiersArray): MethodDeclaration { - var node = createNode(kind, fullStart); + function parseAccessorDeclaration(kind: SyntaxKind, fullStart: number, modifiers: ModifiersArray): AccessorDeclaration { + var node = createNode(kind, fullStart); setModifiers(node, modifiers); node.name = parsePropertyName(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, node); @@ -3864,10 +3864,10 @@ module ts { var fullStart = getNodePos(); var modifiers = parseModifiers(); if (parseContextualModifier(SyntaxKind.GetKeyword)) { - return parseMemberAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, modifiers); } if (parseContextualModifier(SyntaxKind.SetKeyword)) { - return parseMemberAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, modifiers); } if (token === SyntaxKind.ConstructorKeyword) { return parseConstructorDeclaration(fullStart, modifiers); @@ -4435,6 +4435,7 @@ module ts { case SyntaxKind.IndexSignature: return checkIndexSignature(node); case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(node); case SyntaxKind.LabeledStatement: return checkLabeledStatement(node); + case SyntaxKind.LonghandPropertyAssignment: return checkLonghandPropertyAssignment(node); case SyntaxKind.Method: return checkMethod(node); case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(node); case SyntaxKind.ObjectLiteralExpression: return checkObjectLiteralExpression(node); @@ -4443,11 +4444,10 @@ module ts { case SyntaxKind.PostfixUnaryExpression: return checkPostfixUnaryExpression(node); case SyntaxKind.PrefixUnaryExpression: return checkPrefixUnaryExpression(node); case SyntaxKind.Property: return checkProperty(node); - case SyntaxKind.PropertyAssignment: return checkPropertyAssignment(node); case SyntaxKind.ReturnStatement: return checkReturnStatement(node); case SyntaxKind.SetAccessor: return checkSetAccessor(node); case SyntaxKind.SourceFile: return checkSourceFile(node); - case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(node); + case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(node); case SyntaxKind.SwitchStatement: return checkSwitchStatement(node); case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(node); case SyntaxKind.ThrowStatement: return checkThrowStatement(node); @@ -5060,7 +5060,7 @@ module ts { // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields var currentKind: number; - if (prop.kind === SyntaxKind.PropertyAssignment) { + if (prop.kind === SyntaxKind.LonghandPropertyAssignment) { currentKind = Property; } else if (prop.kind === SyntaxKind.ShorthandPropertyAssignment) { @@ -5364,7 +5364,7 @@ module ts { } } - function checkPropertyAssignment(node: PropertyDeclaration) { + function checkLonghandPropertyAssignment(node: LonghandPropertyAssignment) { return checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); } @@ -5464,7 +5464,7 @@ module ts { return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); } - function checkShorthandPropertyAssignment(node: ShorthandPropertyDeclaration): boolean { + function checkShorthandPropertyAssignment(node: ShorthandPropertyAssignment): boolean { return checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index edf052a8876..aa8a98db902 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -232,8 +232,9 @@ module ts { CatchClause, // Property assignments - PropertyAssignment, + LonghandPropertyAssignment, ShorthandPropertyAssignment, + // Enum EnumMember, // Top-level nodes @@ -378,6 +379,7 @@ module ts { } export interface PropertyDeclaration extends Declaration, ClassElement { + _propertyDeclarationBrand: any; questionToken?: Node; type?: TypeNode; initializer?: Expression; @@ -386,11 +388,22 @@ module ts { export type VariableOrParameterDeclaration = VariableDeclaration | ParameterDeclaration; export type VariableOrParameterOrPropertyDeclaration = VariableOrParameterDeclaration | PropertyDeclaration; - export interface ShorthandPropertyDeclaration extends Declaration { + export interface PropertyAssignment extends Declaration { + _propertyAssignmentBrand: any; + } + + export interface ShorthandPropertyAssignment extends PropertyAssignment { name: Identifier; questionToken?: Node; } + export interface LonghandPropertyAssignment extends PropertyAssignment { + _longhandPropertyAssignmentBrand: any; + name: DeclarationName; + questionToken?: Node; + initializer: Expression; + } + /** * Several node kinds share function-like features such as a signature, * a name, and a body. These nodes should extend FunctionLikeDeclaration. @@ -420,8 +433,9 @@ module ts { body?: Block; } - export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement { - body?: Block; + export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, PropertyAssignment { + _accessorDeclarationBrand: any; + body: Block; } export interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement { @@ -576,7 +590,7 @@ module ts { // An ObjectLiteralExpression is the declaration node for an anonymous symbol. export interface ObjectLiteralExpression extends PrimaryExpression, Declaration { - properties: NodeArray; + properties: NodeArray; } export interface PropertyAccessExpression extends MemberExpression { diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index a67a89dd82f..d70884e5d87 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -239,7 +239,7 @@ module ts.BreakpointResolver { default: // If this is name of property assignment, set breakpoint in the initializer - if (node.parent.kind === SyntaxKind.PropertyAssignment && (node.parent).name === node) { + if (node.parent.kind === SyntaxKind.LonghandPropertyAssignment && (node.parent).name === node) { return spanInNode((node.parent).initializer); } @@ -477,7 +477,7 @@ module ts.BreakpointResolver { function spanInColonToken(node: Node): TextSpan { // Is this : specifying return annotation of the function declaration - if (isAnyFunction(node.parent) || node.parent.kind === SyntaxKind.PropertyAssignment) { + if (isAnyFunction(node.parent) || node.parent.kind === SyntaxKind.LonghandPropertyAssignment) { return spanInPreviousNode(node); } diff --git a/src/services/services.ts b/src/services/services.ts index 44c587974df..a04c85071e2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1968,14 +1968,14 @@ module ts { /** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */ function isNameOfPropertyAssignment(node: Node): boolean { return (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) && - (node.parent.kind === SyntaxKind.PropertyAssignment || node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) && (node.parent).name === node; + (node.parent.kind === SyntaxKind.LonghandPropertyAssignment || node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) && (node.parent).name === node; } function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean { if (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) { switch (node.parent.kind) { case SyntaxKind.Property: - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: case SyntaxKind.GetAccessor: @@ -2642,7 +2642,7 @@ module ts { var existingMemberNames: Map = {}; forEach(existingMembers, m => { - if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) { + if (m.kind !== SyntaxKind.LonghandPropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) { // Ignore omitted expressions for missing members in the object literal return; } @@ -4703,7 +4703,7 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: - case SyntaxKind.PropertyAssignment: + case SyntaxKind.LonghandPropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: From ff328b0d5411c34b7507a6a5b405f4bcfabc077e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 2 Dec 2014 22:12:50 -0800 Subject: [PATCH 28/39] Merge property assignment parsing code. --- src/compiler/parser.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6f578433beb..615f472aaa5 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3166,8 +3166,14 @@ module ts { return finishNode(node); } - function parseShortOrLonghandPropertyAssignment(): PropertyAssignment { + function parsePropertyAssignment(): PropertyAssignment { var nodePos = scanner.getStartPos(); + var initialToken = token; + + if (parseContextualModifier(SyntaxKind.GetKeyword) || parseContextualModifier(SyntaxKind.SetKeyword)) { + var kind = initialToken === SyntaxKind.GetKeyword ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; + return parseAccessorDeclaration(kind, nodePos, /*modifiers*/undefined); + } var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); var tokenIsIdentifier = isIdentifier(); @@ -3208,16 +3214,6 @@ module ts { } } - function parsePropertyAssignment(): PropertyAssignment { - var initialPos = getNodePos(); - var initialToken = token; - if (parseContextualModifier(SyntaxKind.GetKeyword) || parseContextualModifier(SyntaxKind.SetKeyword)) { - var kind = initialToken === SyntaxKind.GetKeyword ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; - return parseAccessorDeclaration(kind, initialPos, /*modifiers*/ undefined); - } - return parseShortOrLonghandPropertyAssignment(); - } - function parseObjectLiteralExpression(): ObjectLiteralExpression { var node = createNode(SyntaxKind.ObjectLiteralExpression); parseExpected(SyntaxKind.OpenBraceToken); From ed81cad39a7dcec8c847776df49473420ab00470 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 2 Dec 2014 22:52:21 -0800 Subject: [PATCH 29/39] Remove the 'FunctionBlock' ast kind. We don't want different AST forms for identical syntactic constructs ('Block' and 'FunctionBock'). This prevents reuse in incremental scenarios and forces the incremental parser to know when to change between the two. --- src/compiler/checker.ts | 19 +++---- src/compiler/emitter.ts | 12 ++--- src/compiler/parser.ts | 12 +++-- src/compiler/types.ts | 1 - src/services/breakpoints.ts | 17 +++++-- src/services/formatting.ts | 2 +- src/services/formatting/rules.ts | 2 - src/services/navigationBar.ts | 6 +-- src/services/outliningElementsCollector.ts | 59 +++++++++++----------- src/services/services.ts | 15 ++++-- src/services/signatureHelp.ts | 2 +- src/services/smartIndenter.ts | 5 +- 12 files changed, 79 insertions(+), 73 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cdb0babd587..3d2c64c7ced 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6024,7 +6024,7 @@ module ts { function getReturnTypeFromBody(func: FunctionLikeDeclaration, contextualMapper?: TypeMapper): Type { var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func); - if (func.body.kind !== SyntaxKind.FunctionBlock) { + if (func.body.kind !== SyntaxKind.Block) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); @@ -6111,7 +6111,7 @@ module ts { } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. - if (!func.body || func.body.kind !== SyntaxKind.FunctionBlock) { + if (!func.body || func.body.kind !== SyntaxKind.Block) { return; } @@ -6177,7 +6177,7 @@ module ts { if (node.type) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (node.body.kind === SyntaxKind.FunctionBlock) { + if (node.body.kind === SyntaxKind.Block) { checkSourceElement(node.body); } else { @@ -7360,6 +7360,9 @@ module ts { function checkBlock(node: Block) { forEach(node.statements, checkSourceElement); + if (isFunctionBlock(node) || node.kind === SyntaxKind.ModuleBlock) { + checkFunctionExpressionBodies(node); + } } function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) { @@ -8491,10 +8494,8 @@ module ts { case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); case SyntaxKind.Block: - return checkBlock(node); - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: - return checkBody(node); + return checkBlock(node); case SyntaxKind.VariableStatement: return checkVariableStatement(node); case SyntaxKind.ExpressionStatement: @@ -8589,7 +8590,6 @@ module ts { case SyntaxKind.BinaryExpression: case SyntaxKind.ConditionalExpression: case SyntaxKind.Block: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: case SyntaxKind.VariableStatement: case SyntaxKind.ExpressionStatement: @@ -8620,11 +8620,6 @@ module ts { } } - function checkBody(node: Block) { - checkBlock(node); - checkFunctionExpressionBodies(node); - } - // Fully type check a source file and collect the relevant diagnostics. function checkSourceFile(node: SourceFile) { var links = getNodeLinks(node); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 38cd18aea07..08589c36923 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2841,17 +2841,17 @@ module ts { scopeEmitStart(node); increaseIndent(); - emitDetachedComments(node.body.kind === SyntaxKind.FunctionBlock ? (node.body).statements : node.body); + emitDetachedComments(node.body.kind === SyntaxKind.Block ? (node.body).statements : node.body); var startIndex = 0; - if (node.body.kind === SyntaxKind.FunctionBlock) { + if (node.body.kind === SyntaxKind.Block) { startIndex = emitDirectivePrologues((node.body).statements, /*startWithNewLine*/ true); } var outPos = writer.getTextPos(); emitCaptureThisForNodeIfNecessary(node); emitDefaultValueAssignments(node); emitRestParameter(node); - if (node.body.kind !== SyntaxKind.FunctionBlock && outPos === writer.getTextPos()) { + if (node.body.kind !== SyntaxKind.Block && outPos === writer.getTextPos()) { decreaseIndent(); write(" "); emitStart(node.body); @@ -2864,7 +2864,7 @@ module ts { emitEnd(node.body); } else { - if (node.body.kind === SyntaxKind.FunctionBlock) { + if (node.body.kind === SyntaxKind.Block) { emitLinesStartingAt((node.body).statements, startIndex); } else { @@ -2876,7 +2876,7 @@ module ts { emitTrailingComments(node.body); } writeLine(); - if (node.body.kind === SyntaxKind.FunctionBlock) { + if (node.body.kind === SyntaxKind.Block) { emitLeadingCommentsOfPosition((node.body).statements.end); decreaseIndent(); emitToken(SyntaxKind.CloseBraceToken, (node.body).statements.end); @@ -3566,7 +3566,7 @@ module ts { case SyntaxKind.Block: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: + case SyntaxKind.Block: case SyntaxKind.ModuleBlock: return emitBlock(node); case SyntaxKind.VariableStatement: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 615f472aaa5..5414794f429 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -311,7 +311,6 @@ module ts { case SyntaxKind.Block: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: return children((node).statements); case SyntaxKind.SourceFile: @@ -435,7 +434,6 @@ module ts { case SyntaxKind.ReturnStatement: return visitor(node); case SyntaxKind.Block: - case SyntaxKind.FunctionBlock: case SyntaxKind.IfStatement: case SyntaxKind.DoStatement: case SyntaxKind.WhileStatement: @@ -472,6 +470,10 @@ module ts { return false; } + export function isFunctionBlock(node: Node) { + return node && node.kind === SyntaxKind.Block && isAnyFunction(node.parent); + } + export function getContainingFunction(node: Node): FunctionLikeDeclaration { while (true) { node = node.parent; @@ -3287,7 +3289,7 @@ module ts { var savedYieldContext = inYieldContext(); setYieldContext(allowYield); - var block = parseBlock(SyntaxKind.FunctionBlock, ignoreMissingOpenBrace, /*checkForStrictMode*/ true); + var block = parseBlock(SyntaxKind.Block, ignoreMissingOpenBrace, /*checkForStrictMode*/ true); setYieldContext(savedYieldContext); @@ -4360,7 +4362,7 @@ module ts { if (!checkModifiers(node)) { var savedInFunctionBlock = inFunctionBlock; - if (node.kind === SyntaxKind.FunctionBlock) { + if (isFunctionBlock(node)) { inFunctionBlock = true; } @@ -4996,7 +4998,7 @@ module ts { } function checkForBodyInAmbientContext(body: Block | Expression, isConstructor: boolean): boolean { - if (inAmbientContext && body && body.kind === SyntaxKind.FunctionBlock) { + if (inAmbientContext && body && body.kind === SyntaxKind.Block) { var diagnostic = isConstructor ? Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index aa8a98db902..eadbb483319 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -212,7 +212,6 @@ module ts { DebuggerStatement, VariableDeclaration, FunctionDeclaration, - FunctionBlock, ClassDeclaration, InterfaceDeclaration, TypeAliasDeclaration, diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index d70884e5d87..4b7b276086f 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -101,10 +101,14 @@ module ts.BreakpointResolver { case SyntaxKind.ArrowFunction: return spanInFunctionDeclaration(node); - case SyntaxKind.FunctionBlock: - return spanInFunctionBlock(node); - case SyntaxKind.Block: + if (isFunctionBlock(node)) { + return spanInFunctionBlock(node); + } + else { + return spanInBlock(node); + } + case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: case SyntaxKind.ModuleBlock: @@ -414,13 +418,18 @@ module ts.BreakpointResolver { return undefined; } - case SyntaxKind.FunctionBlock: case SyntaxKind.EnumDeclaration: case SyntaxKind.ClassDeclaration: // Span on close brace token return textSpan(node); case SyntaxKind.Block: + if (isFunctionBlock(node.parent)) { + // Span on close brace token + return textSpan(node); + } + // fall through. + case SyntaxKind.TryBlock: case SyntaxKind.CatchClause: case SyntaxKind.FinallyBlock: diff --git a/src/services/formatting.ts b/src/services/formatting.ts index 3322ea1e65b..9660d9af6df 100644 --- a/src/services/formatting.ts +++ b/src/services/formatting.ts @@ -897,7 +897,7 @@ module ts.formatting { function isSomeBlock(kind: SyntaxKind): boolean { switch (kind) { case SyntaxKind.Block: - case SyntaxKind.FunctionBlock: + case SyntaxKind.Block: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: case SyntaxKind.ModuleBlock: diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 2723b50af7b..5dc44650346 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -526,7 +526,6 @@ module ts.formatting { case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: return true; } @@ -582,7 +581,6 @@ module ts.formatting { case SyntaxKind.TryBlock: case SyntaxKind.CatchClause: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: case SyntaxKind.SwitchStatement: return true; diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index deb779bea2c..aebd736d190 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -120,7 +120,7 @@ module ts.NavigationBar { if (functionDeclaration.kind === SyntaxKind.FunctionDeclaration) { // A function declaration is 'top level' if it contains any function declarations // within it. - if (functionDeclaration.body && functionDeclaration.body.kind === SyntaxKind.FunctionBlock) { + if (functionDeclaration.body && functionDeclaration.body.kind === SyntaxKind.Block) { // Proper function declarations can only have identifier names if (forEach((functionDeclaration.body).statements, s => s.kind === SyntaxKind.FunctionDeclaration && !isEmpty((s).name.text))) { @@ -130,7 +130,7 @@ module ts.NavigationBar { // Or if it is not parented by another function. i.e all functions // at module scope are 'top level'. - if (functionDeclaration.parent.kind !== SyntaxKind.FunctionBlock) { + if (!isFunctionBlock(functionDeclaration.parent)) { return true; } } @@ -333,7 +333,7 @@ module ts.NavigationBar { } function createFunctionItem(node: FunctionDeclaration) { - if (node.name && node.body && node.body.kind === SyntaxKind.FunctionBlock) { + if (node.name && node.body && node.body.kind === SyntaxKind.Block) { var childItems = getItemsWorker(sortNodes((node.body).statements), createChildItem); return getNavigationBarItem(node.name.text, diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 68f30bee781..83eef2f4378 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -67,38 +67,39 @@ module ts { } switch (n.kind) { case SyntaxKind.Block: - var parent = n.parent; - var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); - var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); + if (!isFunctionBlock(n)) { + var parent = n.parent; + var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); + var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); - // Check if the block is standalone, or 'attached' to some parent statement. - // If the latter, we want to collaps the block, but consider its hint span - // to be the entire span of the parent. - if (parent.kind === SyntaxKind.DoStatement || - parent.kind === SyntaxKind.ForInStatement || - parent.kind === SyntaxKind.ForStatement || - parent.kind === SyntaxKind.IfStatement || - parent.kind === SyntaxKind.WhileStatement || - parent.kind === SyntaxKind.WithStatement || - parent.kind === SyntaxKind.CatchClause) { - - addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + // Check if the block is standalone, or 'attached' to some parent statement. + // If the latter, we want to collaps the block, but consider its hint span + // to be the entire span of the parent. + if (parent.kind === SyntaxKind.DoStatement || + parent.kind === SyntaxKind.ForInStatement || + parent.kind === SyntaxKind.ForStatement || + parent.kind === SyntaxKind.IfStatement || + parent.kind === SyntaxKind.WhileStatement || + parent.kind === SyntaxKind.WithStatement || + parent.kind === SyntaxKind.CatchClause) { + + addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + } + else { + // Block was a standalone block. In this case we want to only collapse + // the span of the block, independent of any parent span. + var span = TextSpan.fromBounds(n.getStart(), n.end); + elements.push({ + textSpan: span, + hintSpan: span, + bannerText: collapseText, + autoCollapse: autoCollapse(n) + }); + } + break; } - else { - // Block was a standalone block. In this case we want to only collapse - // the span of the block, independent of any parent span. - var span = TextSpan.fromBounds(n.getStart(), n.end); - elements.push({ - textSpan: span, - hintSpan: span, - bannerText: collapseText, - autoCollapse: autoCollapse(n) - }); - } - break; + // Fallthrough. - - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: diff --git a/src/services/services.ts b/src/services/services.ts index a04c85071e2..15cc6639669 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -806,10 +806,15 @@ module ts { case SyntaxKind.Constructor: case SyntaxKind.VariableStatement: case SyntaxKind.ModuleBlock: - case SyntaxKind.FunctionBlock: forEachChild(node, visit); break; + case SyntaxKind.Block: + if (isFunctionBlock(node)) { + forEachChild(node, visit); + } + break; + case SyntaxKind.Parameter: // Only consider properties defined as constructor parameters if (!(node.flags & NodeFlags.AccessibilityModifier)) { @@ -1441,7 +1446,7 @@ module ts { } // If the parent is not sourceFile or module block it is local variable - for (var parent = declaration.parent; parent.kind !== SyntaxKind.FunctionBlock; parent = parent.parent) { + for (var parent = declaration.parent; !isFunctionBlock(parent); parent = parent.parent) { // Reached source file or module block if (parent.kind === SyntaxKind.SourceFile || parent.kind === SyntaxKind.ModuleBlock) { return false; @@ -3515,7 +3520,7 @@ module ts { var func = getContainingFunction(returnStatement); // If we didn't find a containing function with a block body, bail out. - if (!(func && hasKind(func.body, SyntaxKind.FunctionBlock))) { + if (!(func && hasKind(func.body, SyntaxKind.Block))) { return undefined; } @@ -3547,7 +3552,7 @@ module ts { // If the "owner" is a function, then we equate 'return' and 'throw' statements in their // ability to "jump out" of the function, and include occurrences for both. - if (owner.kind === SyntaxKind.FunctionBlock) { + if (isFunctionBlock(owner)) { forEachReturnStatement(owner, returnStatement => { pushKeywordIf(keywords, returnStatement.getFirstToken(), SyntaxKind.ReturnKeyword); }); @@ -3603,7 +3608,7 @@ module ts { while (child.parent) { var parent = child.parent; - if (parent.kind === SyntaxKind.FunctionBlock || parent.kind === SyntaxKind.SourceFile) { + if (isFunctionBlock(parent) || parent.kind === SyntaxKind.SourceFile) { return parent; } diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 93363b4676b..bdb76b77e8a 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -396,7 +396,7 @@ module ts.SignatureHelp { function getContainingArgumentInfo(node: Node): ArgumentListInfo { for (var n = node; n.kind !== SyntaxKind.SourceFile; n = n.parent) { - if (n.kind === SyntaxKind.FunctionBlock) { + if (isFunctionBlock(n)) { return undefined; } diff --git a/src/services/smartIndenter.ts b/src/services/smartIndenter.ts index 82226449b96..e93cb5616a9 100644 --- a/src/services/smartIndenter.ts +++ b/src/services/smartIndenter.ts @@ -326,7 +326,6 @@ module ts.formatting { case SyntaxKind.EnumDeclaration: case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.Block: - case SyntaxKind.FunctionBlock: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: case SyntaxKind.ModuleBlock: @@ -357,7 +356,6 @@ module ts.formatting { case SyntaxKind.ForInStatement: case SyntaxKind.ForStatement: case SyntaxKind.IfStatement: - return child !== SyntaxKind.Block; case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.Method: @@ -365,7 +363,7 @@ module ts.formatting { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - return child !== SyntaxKind.FunctionBlock; + return child !== SyntaxKind.Block; default: return false; } @@ -404,7 +402,6 @@ module ts.formatting { case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.Block: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: case SyntaxKind.SwitchStatement: return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); From 090000543831c10a11d9692c8c0ff7492e0a025c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Dec 2014 00:04:54 -0800 Subject: [PATCH 30/39] Don't rewrite function property assignments in the AST. --- src/compiler/binder.ts | 7 +- src/compiler/checker.ts | 107 ++++++++++++------ src/compiler/emitter.ts | 14 +++ src/compiler/parser.ts | 94 ++++++--------- src/compiler/types.ts | 18 ++- src/harness/typeWriter.ts | 21 ++++ src/services/services.ts | 13 ++- ...unctionPropertyAssignments5_es6.errors.txt | 7 +- .../parserComputedPropertyName3.types | 1 - ...alidationFunctionPropertyAssignment.js.map | 2 +- ...onFunctionPropertyAssignment.sourcemap.txt | 9 +- tests/cases/fourslash/functionProperty.ts | 4 +- 12 files changed, 179 insertions(+), 118 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 5051e771a29..1aa32c68b6a 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -411,7 +411,12 @@ module ts { bindDeclaration(node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true); break; case SyntaxKind.Method: - bindDeclaration(node, SymbolFlags.Method, SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); + // If this is an ObjectLiteralExpression method, then it sits in the same space + // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes + // so that it will conflict with any other object literal members with the same + // name. + bindDeclaration(node, SymbolFlags.Method, + isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.IndexSignature: bindDeclaration(node, SymbolFlags.IndexSignature, 0, /*isBlockScopeContainer*/ false); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3d2c64c7ced..422aff11286 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1392,7 +1392,7 @@ module ts { for (var i = 0; i < resolved.properties.length; i++) { var p = resolved.properties[i]; var t = getTypeOfSymbol(p); - if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) { + if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !isObjectLiteralMethod(p.valueDeclaration) && !getPropertiesOfObjectType(t).length) { var signatures = getSignaturesOfType(t, SignatureKind.Call); for (var j = 0; j < signatures.length; j++) { buildSymbolDisplay(p, writer); @@ -3240,14 +3240,13 @@ module ts { // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. - function isContextSensitiveExpression(node: Expression): boolean { + function isContextSensitiveExpression(node: Node): boolean { switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: return !(node).typeParameters && !forEach((node).parameters, p => p.type); case SyntaxKind.ObjectLiteralExpression: - return forEach((node).properties, p => - p.kind === SyntaxKind.LonghandPropertyAssignment && isContextSensitiveExpression((p).initializer)); + return forEach((node).properties, isContextSensitiveExpression); case SyntaxKind.ArrayLiteralExpression: return forEach((node).elements, e => isContextSensitiveExpression(e)); case SyntaxKind.ConditionalExpression: @@ -3256,7 +3255,15 @@ module ts { case SyntaxKind.BinaryExpression: return (node).operator === SyntaxKind.BarBarToken && (isContextSensitiveExpression((node).left) || isContextSensitiveExpression((node).right)); + case SyntaxKind.LonghandPropertyAssignment: + return isContextSensitiveExpression((node).initializer); + case SyntaxKind.Method: + if (isObjectLiteralMethod(node)) { + return !(node).typeParameters && !forEach((node).parameters, p => p.type); + } + return false; } + return false; } @@ -4890,12 +4897,24 @@ module ts { // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of // the matching property in T, if one exists. Otherwise, it is the type of the numeric index signature in T, if one // exists. Otherwise, it is the type of the string index signature in T, if one exists. - function getContextualTypeForPropertyExpression(node: Expression): Type { - var declaration = node.parent; - var objectLiteral = declaration.parent; + function getContextualTypeForObjectLiteralMethod(node: MethodDeclaration): Type { + Debug.assert(isObjectLiteralMethod(node)); + if (isInsideWithStatementBody(node)) { + // We cannot answer semantic questions within a with block, do not proceed any further + return undefined; + } + if (node.contextualType) { + return node.contextualType; + } + + return getContextualTypeForPropertyAssignment(node); + } + + function getContextualTypeForPropertyAssignment(propertyAssignment: PropertyAssignment) { + var objectLiteral = propertyAssignment.parent; var type = getContextualType(objectLiteral); // TODO(jfreeman): Handle this case for computed names and symbols - var name = (declaration.name).text; + var name = (propertyAssignment.name).text; if (type && name) { return getTypeOfPropertyOfContextualType(type, name) || isNumericName(name) && getIndexTypeOfContextualType(type, IndexKind.Number) || @@ -4950,7 +4969,7 @@ module ts { case SyntaxKind.BinaryExpression: return getContextualTypeForBinaryOperand(node); case SyntaxKind.LonghandPropertyAssignment: - return getContextualTypeForPropertyExpression(node); + return getContextualTypeForPropertyAssignment(parent); case SyntaxKind.ArrayLiteralExpression: return getContextualTypeForElementExpression(node); case SyntaxKind.ConditionalExpression: @@ -4985,8 +5004,11 @@ module ts { // If the contextual type is a union type, get the signature from each type possible and if they are // all identical ignoring their return type, the result is same signature but with return type as // union type of return types from these signatures - function getContextualSignature(node: FunctionExpression): Signature { - var type = getContextualType(node); + function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature { + Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + var type = isObjectLiteralMethod(node) + ? getContextualTypeForObjectLiteralMethod(node) + : getContextualType(node); if (!type) { return undefined; } @@ -5082,11 +5104,14 @@ module ts { for (var id in members) { if (hasProperty(members, id)) { var member = members[id]; - if (member.flags & SymbolFlags.Property) { - var memberDecl = member.declarations[0]; + if (member.flags & SymbolFlags.Property || isObjectLiteralMethod(member.declarations[0])) { + var memberDecl = member.declarations[0]; var type: Type; if (memberDecl.kind === SyntaxKind.LonghandPropertyAssignment) { - type = checkExpression(memberDecl.initializer, contextualMapper); + type = checkExpression((memberDecl).initializer, contextualMapper); + } + else if (memberDecl.kind === SyntaxKind.Method) { + type = checkExpression(memberDecl, contextualMapper); } else { Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment); @@ -5097,7 +5122,10 @@ module ts { var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); prop.declarations = member.declarations; prop.parent = member.parent; - if (member.valueDeclaration) prop.valueDeclaration = member.valueDeclaration; + if (member.valueDeclaration) { + prop.valueDeclaration = member.valueDeclaration; + } + prop.type = type; prop.target = member; member = prop; @@ -6133,7 +6161,9 @@ module ts { error(func.type, Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement); } - function checkFunctionExpression(node: FunctionExpression, contextualMapper?: TypeMapper): Type { + function checkFunctionExpressionOrObjectLiteralMethod(node: FunctionExpression | MethodDeclaration, contextualMapper?: TypeMapper): Type { + Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + // The identityMapper object is used to indicate that function expressions are wildcards if (contextualMapper === identityMapper) { return anyFunctionType; @@ -6165,27 +6195,31 @@ module ts { } } - if (fullTypeCheck) { - checkCollisionWithCapturedSuperVariable(node, node.name); - checkCollisionWithCapturedThisVariable(node, node.name); + if (fullTypeCheck && node.kind !== SyntaxKind.Method) { + checkCollisionWithCapturedSuperVariable(node, (node).name); + checkCollisionWithCapturedThisVariable(node,(node).name); } return type; } - function checkFunctionExpressionBody(node: FunctionExpression) { + function checkFunctionExpressionOrObjectLiteralMethodBody(node: FunctionExpression | MethodDeclaration) { + Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); if (node.type) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (node.body.kind === SyntaxKind.Block) { - checkSourceElement(node.body); - } - else { - var exprType = checkExpression(node.body); - if (node.type) { - checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, /*headMessage*/ undefined); + + if (node.body) { + if (node.body.kind === SyntaxKind.Block) { + checkSourceElement(node.body); + } + else { + var exprType = checkExpression(node.body); + if (node.type) { + checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, /*headMessage*/ undefined); + } + checkFunctionExpressionBodies(node.body); } - checkFunctionExpressionBodies(node.body); } } @@ -6559,8 +6593,8 @@ module ts { // object, it serves as an indicator that all contained function and arrow expressions should be considered to // have the wildcard function type; this form of type check is used during overload resolution to exclude // contextually typed function and arrow expressions in the initial phase. - function checkExpression(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type { - var type = checkExpressionNode(node, contextualMapper); + function checkExpression(node: Expression | QualifiedName | MethodDeclaration, contextualMapper?: TypeMapper): Type { + var type = checkExpressionOrQualifiedNameOrObjectLiteralMethodNode(node, contextualMapper); if (contextualMapper && contextualMapper !== identityMapper && node.kind !== SyntaxKind.QualifiedName) { var signature = getSingleCallSignature(type); if (signature && signature.typeParameters) { @@ -6591,7 +6625,7 @@ module ts { return type; } - function checkExpressionNode(node: Expression | QualifiedName, contextualMapper: TypeMapper): Type { + function checkExpressionOrQualifiedNameOrObjectLiteralMethodNode(node: Expression | QualifiedName | MethodDeclaration, contextualMapper: TypeMapper): Type { switch (node.kind) { case SyntaxKind.Identifier: return checkIdentifier(node); @@ -6632,9 +6666,11 @@ module ts { return checkTypeAssertion(node); case SyntaxKind.ParenthesizedExpression: return checkExpression((node).expression); + case SyntaxKind.Method: + return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - return checkFunctionExpression(node, contextualMapper); + return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); case SyntaxKind.TypeOfExpression: return checkTypeOfExpression(node); case SyntaxKind.DeleteExpression: @@ -8558,9 +8594,14 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: forEach((node).parameters, checkFunctionExpressionBodies); - checkFunctionExpressionBody(node); + checkFunctionExpressionOrObjectLiteralMethodBody(node); break; case SyntaxKind.Method: + forEach((node).parameters, checkFunctionExpressionBodies); + if (isObjectLiteralMethod(node)) { + checkFunctionExpressionOrObjectLiteralMethodBody(node); + } + break; case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 08589c36923..ba48eef2f85 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2227,6 +2227,15 @@ module ts { emit(node.expression); write("]"); } + + function emitObjectLiteralMethod(node: MethodDeclaration) { + emitLeadingComments(node); + emit(node.name); + write(": "); + write("function "); + emitSignatureAndBody(node); + emitTrailingComments(node); + } function emitPropertyAssignment(node: PropertyDeclaration) { emitLeadingComments(node); @@ -3527,6 +3536,11 @@ module ts { return emitObjectLiteral(node); case SyntaxKind.LonghandPropertyAssignment: return emitPropertyAssignment(node); + case SyntaxKind.Method: + if (isObjectLiteralMethod(node)) { + return emitObjectLiteralMethod(node); + } + break; case SyntaxKind.ComputedPropertyName: return emitComputedPropertyName(node); case SyntaxKind.PropertyAccessExpression: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5414794f429..1d7a8e2be44 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -474,6 +474,10 @@ module ts { return node && node.kind === SyntaxKind.Block && isAnyFunction(node.parent); } + export function isObjectLiteralMethod(node: Node) { + return node && node.kind === SyntaxKind.Method && node.parent.kind === SyntaxKind.ObjectLiteralExpression; + } + export function getContainingFunction(node: Node): FunctionLikeDeclaration { while (true) { node = node.parent; @@ -1920,16 +1924,10 @@ module ts { return parseInitializer(/*inParameter*/ true); } - function parseSignature(yieldAndGeneratorParameterContext: boolean): ParsedSignature { - var signature = {}; - fillSignature(SyntaxKind.ColonToken, yieldAndGeneratorParameterContext, signature); - return signature; - } - function fillSignature( returnToken: SyntaxKind, yieldAndGeneratorParameterContext: boolean, - signature: ParsedSignature): void { + signature: SignatureDeclaration): void { var returnTokenRequired = returnToken === SyntaxKind.EqualsGreaterThanToken; signature.typeParameters = parseTypeParameters(); signature.parameters = parseParameterList(yieldAndGeneratorParameterContext); @@ -3169,12 +3167,12 @@ module ts { } function parsePropertyAssignment(): PropertyAssignment { - var nodePos = scanner.getStartPos(); + var fullStart = scanner.getStartPos(); var initialToken = token; if (parseContextualModifier(SyntaxKind.GetKeyword) || parseContextualModifier(SyntaxKind.SetKeyword)) { var kind = initialToken === SyntaxKind.GetKeyword ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; - return parseAccessorDeclaration(kind, nodePos, /*modifiers*/undefined); + return parseAccessorDeclaration(kind, fullStart, /*modifiers*/undefined); } var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -3182,18 +3180,7 @@ module ts { var nameToken = token; var propertyName = parsePropertyName(); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - var longhandDeclaration = createNode(SyntaxKind.LonghandPropertyAssignment, nodePos); - longhandDeclaration.name = propertyName; - var sig = parseSignature(/*yieldAndGeneratorParameterContext:*/ !!asteriskToken); - - var body = parseFunctionBlock(!!asteriskToken, /* ignoreMissingOpenBrace */ false); - // do not propagate property name as name for function expression - // for scenarios like - // var x = 1; - // var y = { x() { } } - // otherwise this will bring y.x into the scope of x which is incorrect - longhandDeclaration.initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, longhandDeclaration.pos, asteriskToken, undefined, sig, body); - return finishNode(longhandDeclaration); + return parseMethodDeclaration(fullStart, /*modifiers:*/ undefined, asteriskToken, propertyName, /*questionToken:*/ undefined, /*requireBlock:*/ true); } // Disallowing of optional property assignments happens in the grammar checker. @@ -3201,13 +3188,13 @@ module ts { // Parse to check if it is short-hand property assignment or normal property assignment if ((token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBraceToken) && tokenIsIdentifier) { - var shorthandDeclaration = createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos); + var shorthandDeclaration = createNode(SyntaxKind.ShorthandPropertyAssignment, fullStart); shorthandDeclaration.name = propertyName; shorthandDeclaration.questionToken = questionToken; return finishNode(shorthandDeclaration); } else { - var longhandDeclaration = createNode(SyntaxKind.LonghandPropertyAssignment, nodePos); + var longhandDeclaration = createNode(SyntaxKind.LonghandPropertyAssignment, fullStart); longhandDeclaration.name = propertyName; longhandDeclaration.questionToken = questionToken; parseExpected(SyntaxKind.ColonToken); @@ -3246,17 +3233,6 @@ module ts { return isIdentifier() ? parseIdentifier() : undefined; } - function makeFunctionExpression(kind: SyntaxKind, pos: number, asteriskToken: Node, name: Identifier, sig: ParsedSignature, body: Block | Expression): FunctionExpression { - var node = createNode(kind, pos); - node.asteriskToken = asteriskToken; - node.name = name; - node.typeParameters = sig.typeParameters; - node.parameters = sig.parameters; - node.type = sig.type; - node.body = body; - return finishNode(node); - } - function parseNewExpression(): NewExpression { var node = createNode(SyntaxKind.NewExpression); parseExpected(SyntaxKind.NewKeyword); @@ -3666,7 +3642,7 @@ module ts { function parseFunctionBlockOrSemicolon(isGenerator: boolean): Block { if (token === SyntaxKind.OpenBraceToken) { - return parseFunctionBlock(isGenerator, /* ignoreMissingOpenBrace */ false); + return parseFunctionBlock(isGenerator, /*ignoreMissingOpenBrace:*/ false); } parseSemicolon(Diagnostics.or_expected); @@ -3737,7 +3713,18 @@ module ts { return finishNode(node); } - function parsePropertyMemberDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { + function parseMethodDeclaration(fullStart: number, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, requireBlock: boolean): MethodDeclaration { + var method = createNode(SyntaxKind.Method, fullStart); + setModifiers(method, modifiers); + method.asteriskToken = asteriskToken; + method.name = name; + method.questionToken = questionToken; + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, method); + method.body = requireBlock ? parseFunctionBlock(!!asteriskToken, /*ignoreMissingOpenBrace:*/ false) : parseFunctionBlockOrSemicolon(!!asteriskToken); + return finishNode(method); + } + + function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); var name = parsePropertyName(); @@ -3745,14 +3732,7 @@ module ts { // report an error in the grammar checker. var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - var method = createNode(SyntaxKind.Method, fullStart); - setModifiers(method, modifiers); - method.asteriskToken = asteriskToken; - method.name = name; - method.questionToken = questionToken; - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, method); - method.body = parseFunctionBlockOrSemicolon(!!asteriskToken); - return finishNode(method); + return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, /*requireBlock:*/ false); } else { var property = createNode(SyntaxKind.Property, fullStart); @@ -3877,7 +3857,7 @@ module ts { // the [ token can start an index signature or a computed property name if (isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBracketToken) { - return parsePropertyMemberDeclaration(fullStart, modifiers); + return parsePropertyOrMethodDeclaration(fullStart, modifiers); } // 'isClassMemberStart' should have hinted not to attempt parsing. @@ -4406,7 +4386,7 @@ module ts { case SyntaxKind.ConstructorType: case SyntaxKind.ConstructSignature: case SyntaxKind.FunctionType: - return checkAnyParsedSignature(node); + return checkAnySignatureDeclaration(node); case SyntaxKind.BreakStatement: case SyntaxKind.ContinueStatement: return checkBreakOrContinueStatement(node); @@ -4521,7 +4501,7 @@ module ts { } } - function checkAnyParsedSignature(node: ParsedSignature): boolean { + function checkAnySignatureDeclaration(node: SignatureDeclaration): boolean { return checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); } @@ -4735,7 +4715,7 @@ module ts { } function checkConstructor(node: ConstructorDeclaration) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkConstructorTypeParameters(node) || checkConstructorTypeAnnotation(node) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ true); @@ -4843,7 +4823,7 @@ module ts { } function checkFunctionDeclaration(node: FunctionLikeDeclaration) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkFunctionName(node.name) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) || checkForGenerator(node); @@ -4856,7 +4836,7 @@ module ts { } function checkFunctionExpression(node: FunctionExpression) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkFunctionName(node.name) || checkForGenerator(node); } @@ -4870,7 +4850,7 @@ module ts { } function checkGetAccessor(node: MethodDeclaration) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkAccessor(node); } @@ -4968,11 +4948,12 @@ module ts { } function checkMethod(node: MethodDeclaration) { - if (checkAnyParsedSignature(node) || + if (checkAnySignatureDeclaration(node) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) || checkForGenerator(node)) { return true; } + if (node.parent.kind === SyntaxKind.ClassDeclaration) { if (checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; @@ -5058,10 +5039,9 @@ module ts { // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields var currentKind: number; - if (prop.kind === SyntaxKind.LonghandPropertyAssignment) { - currentKind = Property; - } - else if (prop.kind === SyntaxKind.ShorthandPropertyAssignment) { + if (prop.kind === SyntaxKind.LonghandPropertyAssignment || + prop.kind === SyntaxKind.ShorthandPropertyAssignment || + prop.kind === SyntaxKind.Method) { currentKind = Property; } else if (prop.kind === SyntaxKind.GetAccessor) { @@ -5379,7 +5359,7 @@ module ts { } function checkSetAccessor(node: MethodDeclaration) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkAccessor(node); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index eadbb483319..d887082ab38 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -334,13 +334,6 @@ module ts { } export type EntityName = Identifier | QualifiedName; - - export interface ParsedSignature { - typeParameters?: NodeArray; - parameters: NodeArray; - type?: TypeNode; - } - export type DeclarationName = Identifier | LiteralExpression | ComputedPropertyName; export interface Declaration extends Node { @@ -360,7 +353,10 @@ module ts { expression?: Expression; } - export interface SignatureDeclaration extends Declaration, ParsedSignature { + export interface SignatureDeclaration extends Declaration { + typeParameters?: NodeArray; + parameters: NodeArray; + type?: TypeNode; } export interface VariableDeclaration extends Declaration { @@ -424,7 +420,9 @@ module ts { body?: Block; } - export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement { + export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, PropertyAssignment { + contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution + body?: Block; } @@ -914,7 +912,7 @@ module ts { getFullyQualifiedName(symbol: Symbol): string; getAugmentedPropertiesOfType(type: Type): Symbol[]; getRootSymbols(symbol: Symbol): Symbol[]; - getContextualType(node: Node): Type; + getContextualType(node: Expression): Type; getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[]): Signature; getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts index 83aaaaf920a..a3bff394d2e 100644 --- a/src/harness/typeWriter.ts +++ b/src/harness/typeWriter.ts @@ -49,10 +49,31 @@ class TypeWriterWalker { this.log(node, this.getTypeOfNode(node)); break; + case ts.SyntaxKind.Method: + if (ts.isObjectLiteralMethod(node)) { + // this is a just a temporary workaround so we emit typewriter baselines in the + // same order as before. + var name = (node).name; + if (name.kind === ts.SyntaxKind.Identifier) { + this.log(name, this.getTypeOfNode(name)); + } + + if (node.symbol) { + this.log(node, this.getTypeOfNode(node)); + } + } + break; + // Should not change expression status (maybe expressions) // TODO: Again, ideally should log number and string literals too, // but to be consistent with the old typeWriter, just log identifiers case ts.SyntaxKind.Identifier: + // this is a just a temporary workaround so we emit typewriter baselines in the + // same order as before. + if (ts.isObjectLiteralMethod(node.parent) && (node.parent).name == node) { + break; + } + var identifier = node; if (!this.isLabel(identifier)) { var type = this.getTypeOfNode(identifier); diff --git a/src/services/services.ts b/src/services/services.ts index 15cc6639669..36d502bb47f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4301,8 +4301,12 @@ module ts { var staticFlag = NodeFlags.Static; switch (searchSpaceNode.kind) { - case SyntaxKind.Property: case SyntaxKind.Method: + if (isObjectLiteralMethod(searchSpaceNode)) { + break; + } + // fall through + case SyntaxKind.Property: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -4355,6 +4359,11 @@ module ts { result.push(getReferenceEntryFromNode(node)); } break; + case SyntaxKind.Method: + if (isObjectLiteralMethod(searchSpaceNode) && searchSpaceNode.symbol === container.symbol) { + result.push(getReferenceEntryFromNode(node)); + } + break; case SyntaxKind.ClassDeclaration: // Make sure the container belongs to the same class // and has the appropriate static modifier from the original container. @@ -4483,7 +4492,7 @@ module ts { function getPropertySymbolsFromContextualType(node: Node): Symbol[] { if (isNameOfPropertyAssignment(node)) { - var objectLiteral = node.parent.parent; + var objectLiteral = node.parent.parent; var contextualType = typeInfoResolver.getContextualType(objectLiteral); var name = (node).text; if (contextualType) { diff --git a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt index 24a12267dc5..b3415c27f29 100644 --- a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt +++ b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt @@ -1,10 +1,7 @@ tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS9001: 'generators' are not currently supported. -tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,12): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. -==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (1 errors) ==== var v = { *[foo()]() { } } ~ -!!! error TS9001: 'generators' are not currently supported. - ~~~~~~~ -!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file +!!! error TS9001: 'generators' are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName3.types b/tests/baselines/reference/parserComputedPropertyName3.types index f673d9fbeb8..8a5cfafbd40 100644 --- a/tests/baselines/reference/parserComputedPropertyName3.types +++ b/tests/baselines/reference/parserComputedPropertyName3.types @@ -3,5 +3,4 @@ var v = { [e]() { } }; >v : {} >{ [e]() { } } : {} >e : unknown ->[e]() { } : () => void diff --git a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.js.map b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.js.map index 74b7201ea8f..cc78ea833bb 100644 --- a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.js.map +++ b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationFunctionPropertyAssignment.js.map] -{"version":3,"file":"sourceMapValidationFunctionPropertyAssignment.js","sourceRoot":"","sources":["sourceMapValidationFunctionPropertyAssignment.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,EAAE,CAAC,EAAD;AAAM,CAAC,EAAE,CAAC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationFunctionPropertyAssignment.js","sourceRoot":"","sources":["sourceMapValidationFunctionPropertyAssignment.ts"],"names":["n"],"mappings":"AAAA,IAAI,CAAC,GAAG,EAAE,CAAC;AAAKA,CAACA,EAAE,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.sourcemap.txt b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.sourcemap.txt index c34558a11a3..a1f780ae2fe 100644 --- a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.sourcemap.txt @@ -15,21 +15,18 @@ sourceFile:sourceMapValidationFunctionPropertyAssignment.ts 4 > ^^^ 5 > ^^ 6 > ^ -7 > ^^ 1 > 2 >var 3 > x 4 > = 5 > { 6 > n -7 > 1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) 2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0) 3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0) 4 >Emitted(1, 9) Source(1, 9) + SourceIndex(0) 5 >Emitted(1, 11) Source(1, 11) + SourceIndex(0) 6 >Emitted(1, 12) Source(1, 12) + SourceIndex(0) -7 >Emitted(1, 14) Source(1, 11) + SourceIndex(0) --- >>>} }; 1 > @@ -37,12 +34,12 @@ sourceFile:sourceMapValidationFunctionPropertyAssignment.ts 3 > ^^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >n() { +1 >() { 2 >} 3 > } 4 > ; -1 >Emitted(2, 1) Source(1, 17) + SourceIndex(0) -2 >Emitted(2, 2) Source(1, 18) + SourceIndex(0) +1 >Emitted(2, 1) Source(1, 17) + SourceIndex(0) name (n) +2 >Emitted(2, 2) Source(1, 18) + SourceIndex(0) name (n) 3 >Emitted(2, 4) Source(1, 20) + SourceIndex(0) 4 >Emitted(2, 5) Source(1, 21) + SourceIndex(0) --- diff --git a/tests/cases/fourslash/functionProperty.ts b/tests/cases/fourslash/functionProperty.ts index e9ffdcf2cdf..f19ac86c01a 100644 --- a/tests/cases/fourslash/functionProperty.ts +++ b/tests/cases/fourslash/functionProperty.ts @@ -31,7 +31,7 @@ goTo.marker('signatureC'); verify.currentSignatureHelpIs('x(a: number): void'); goTo.marker('completionA'); -verify.completionListContains("x", "(property) x: (a: number) => void"); +verify.completionListContains("x", "(method) x(a: number): void"); goTo.marker('completionB'); verify.completionListContains("x", "(property) x: (a: number) => void"); @@ -40,7 +40,7 @@ goTo.marker('completionC'); verify.completionListContains("x", "(property) x: (a: number) => void"); goTo.marker('quickInfoA'); -verify.quickInfoIs("(property) x: (a: number) => void", undefined); +verify.quickInfoIs("(method) x(a: number): void", undefined); goTo.marker('quickInfoB'); verify.quickInfoIs("(property) x: (a: number) => void", undefined); From 44f30c8ba929b09662b645f66bb3b9ab0ba73962 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Dec 2014 01:55:22 -0800 Subject: [PATCH 31/39] Remove baseline-hacks from the typewriter. --- src/harness/typeWriter.ts | 21 ------------------- .../reference/assignEveryTypeToAny.types | 2 -- ...callSignaturesWithOptionalParameters.types | 1 - .../reference/commentsOnObjectLiteral3.types | 1 - .../reference/invalidUndefinedValues.types | 1 - .../nameCollisionsInPropertyAssignments.types | 1 - .../objectLiteralShorthandProperties.types | 1 - .../objectLiteralShorthandPropertiesES6.types | 1 - ...bjectTypesIdentityWithCallSignatures.types | 1 - ...jectTypesIdentityWithCallSignatures2.types | 1 - ...thCallSignaturesDifferingParamCounts.types | 1 - ...ntityWithCallSignaturesWithOverloads.types | 1 - ...ypesIdentityWithConstructSignatures2.types | 1 - ...structSignaturesDifferingParamCounts.types | 1 - ...pesIdentityWithGenericCallSignatures.types | 1 - ...esIdentityWithGenericCallSignatures2.types | 1 - ...CallSignaturesDifferingByConstraints.types | 1 - ...cCallSignaturesDifferingByReturnType.types | 1 - ...CallSignaturesDifferingByReturnType2.types | 1 - ...gnaturesDifferingTypeParameterCounts.types | 1 - ...ignaturesDifferingTypeParameterNames.types | 1 - ...hGenericCallSignaturesOptionalParams.types | 1 - ...GenericCallSignaturesOptionalParams2.types | 1 - ...GenericCallSignaturesOptionalParams3.types | 1 - ...ructSignaturesDifferingByConstraints.types | 1 - ...tructSignaturesDifferingByReturnType.types | 1 - ...ructSignaturesDifferingByReturnType2.types | 1 - ...gnaturesDifferingTypeParameterCounts.types | 1 - ...ignaturesDifferingTypeParameterNames.types | 1 - ...ricConstructSignaturesOptionalParams.types | 1 - ...icConstructSignaturesOptionalParams2.types | 1 - ...icConstructSignaturesOptionalParams3.types | 1 - .../parametersWithNoAnnotationAreAny.types | 1 - .../parserFunctionPropertyAssignment1.types | 1 - .../parserFunctionPropertyAssignment2.types | 1 - .../parserFunctionPropertyAssignment3.types | 1 - .../parserFunctionPropertyAssignment4.types | 1 - ...ValidationFunctionPropertyAssignment.types | 1 - .../reference/thisInObjectLiterals.types | 1 - .../throwInEnclosingStatements.types | 1 - .../reference/typeGuardsObjectMethods.types | 1 - 41 files changed, 62 deletions(-) diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts index a3bff394d2e..83aaaaf920a 100644 --- a/src/harness/typeWriter.ts +++ b/src/harness/typeWriter.ts @@ -49,31 +49,10 @@ class TypeWriterWalker { this.log(node, this.getTypeOfNode(node)); break; - case ts.SyntaxKind.Method: - if (ts.isObjectLiteralMethod(node)) { - // this is a just a temporary workaround so we emit typewriter baselines in the - // same order as before. - var name = (node).name; - if (name.kind === ts.SyntaxKind.Identifier) { - this.log(name, this.getTypeOfNode(name)); - } - - if (node.symbol) { - this.log(node, this.getTypeOfNode(node)); - } - } - break; - // Should not change expression status (maybe expressions) // TODO: Again, ideally should log number and string literals too, // but to be consistent with the old typeWriter, just log identifiers case ts.SyntaxKind.Identifier: - // this is a just a temporary workaround so we emit typewriter baselines in the - // same order as before. - if (ts.isObjectLiteralMethod(node.parent) && (node.parent).name == node) { - break; - } - var identifier = node; if (!this.isLabel(identifier)) { var type = this.getTypeOfNode(identifier); diff --git a/tests/baselines/reference/assignEveryTypeToAny.types b/tests/baselines/reference/assignEveryTypeToAny.types index b25aba00837..8917ae22055 100644 --- a/tests/baselines/reference/assignEveryTypeToAny.types +++ b/tests/baselines/reference/assignEveryTypeToAny.types @@ -136,14 +136,12 @@ x = { f() { return 1; } } >x : any >{ f() { return 1; } } : { f: () => number; } >f : () => number ->f() { return 1; } : () => number x = { f(x: T) { return x; } } >x = { f(x: T) { return x; } } : { f: (x: T) => T; } >x : any >{ f(x: T) { return x; } } : { f: (x: T) => T; } >f : (x: T) => T ->f(x: T) { return x; } : (x: T) => T >T : T >x : T >T : T diff --git a/tests/baselines/reference/callSignaturesWithOptionalParameters.types b/tests/baselines/reference/callSignaturesWithOptionalParameters.types index 8b1e929d9e3..49a94c3a6ed 100644 --- a/tests/baselines/reference/callSignaturesWithOptionalParameters.types +++ b/tests/baselines/reference/callSignaturesWithOptionalParameters.types @@ -138,7 +138,6 @@ var b = { foo(x?: number) { }, >foo : (x?: number) => void ->foo(x?: number) { } : (x?: number) => void >x : number a: function foo(x: number, y?: number) { }, diff --git a/tests/baselines/reference/commentsOnObjectLiteral3.types b/tests/baselines/reference/commentsOnObjectLiteral3.types index e7770c7e273..08dfd14cedb 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral3.types +++ b/tests/baselines/reference/commentsOnObjectLiteral3.types @@ -17,7 +17,6 @@ var v = { //PropertyName + CallSignature func1() { }, >func1 : () => void ->func1() { } : () => void //getter get a() { diff --git a/tests/baselines/reference/invalidUndefinedValues.types b/tests/baselines/reference/invalidUndefinedValues.types index 9cc71b87c82..3e3e08183c2 100644 --- a/tests/baselines/reference/invalidUndefinedValues.types +++ b/tests/baselines/reference/invalidUndefinedValues.types @@ -72,7 +72,6 @@ x = { f() { } } >x : any >{ f() { } } : { f: () => void; } >f : () => void ->f() { } : () => void function f(a: T) { >f : (a: T) => void diff --git a/tests/baselines/reference/nameCollisionsInPropertyAssignments.types b/tests/baselines/reference/nameCollisionsInPropertyAssignments.types index 1628b673621..aad0fcc1df4 100644 --- a/tests/baselines/reference/nameCollisionsInPropertyAssignments.types +++ b/tests/baselines/reference/nameCollisionsInPropertyAssignments.types @@ -6,7 +6,6 @@ var y = { x() { x++; } }; >y : { x: () => void; } >{ x() { x++; } } : { x: () => void; } >x : () => void ->x() { x++; } : () => void >x++ : number >x : number diff --git a/tests/baselines/reference/objectLiteralShorthandProperties.types b/tests/baselines/reference/objectLiteralShorthandProperties.types index f28f25e815c..c5b869d5a74 100644 --- a/tests/baselines/reference/objectLiteralShorthandProperties.types +++ b/tests/baselines/reference/objectLiteralShorthandProperties.types @@ -36,7 +36,6 @@ var x3 = { d() { }, >d : () => void ->d() { } : () => void x3, >x3 : any diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types index 0383a3f5d2e..5a85c17694f 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types @@ -36,7 +36,6 @@ var x3 = { d() { }, >d : () => void ->d() { } : () => void x3, >x3 : any diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types b/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types index f73785fab0d..184683910af 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types @@ -56,7 +56,6 @@ var b = { foo(x: string) { return ''; } }; >b : { foo: (x: string) => string; } >{ foo(x: string) { return ''; } } : { foo: (x: string) => string; } >foo : (x: string) => string ->foo(x: string) { return ''; } : (x: string) => string >x : string function foo1(x: A); diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types index 16b658d0e43..0143ae426f4 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types @@ -57,7 +57,6 @@ var b = { foo(x: RegExp) { return ''; } }; >b : { foo: (x: RegExp) => string; } >{ foo(x: RegExp) { return ''; } } : { foo: (x: RegExp) => string; } >foo : (x: RegExp) => string ->foo(x: RegExp) { return ''; } : (x: RegExp) => string >x : RegExp >RegExp : RegExp diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types index 0ebbc639e5f..90ad61ad044 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types @@ -60,7 +60,6 @@ var b = { foo(x: string) { return ''; } }; >b : { foo: (x: string) => string; } >{ foo(x: string) { return ''; } } : { foo: (x: string) => string; } >foo : (x: string) => string ->foo(x: string) { return ''; } : (x: string) => string >x : string function foo1(x: A); diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types index 4d8b8ccb42a..ef31cf1fe4d 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types @@ -105,7 +105,6 @@ var b = { foo(x: any) { return ''; } >foo : (x: any) => any ->foo(x: any) { return ''; } : (x: any) => any >x : any >'' : any diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types index c530f1ced9b..b44bc323a3d 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types @@ -43,7 +43,6 @@ var b = { new(x: RegExp) { return ''; } }; // not a construct signature, functio >b : { new: (x: RegExp) => string; } >{ new(x: RegExp) { return ''; } } : { new: (x: RegExp) => string; } >new : (x: RegExp) => string ->new(x: RegExp) { return ''; } : (x: RegExp) => string >x : RegExp >RegExp : RegExp diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types index e5598f874e0..8d26b98c361 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types @@ -46,7 +46,6 @@ var b = { new(x: string) { return ''; } }; // not a construct signature, functio >b : { new: (x: string) => string; } >{ new(x: string) { return ''; } } : { new: (x: string) => string; } >new : (x: string) => string ->new(x: string) { return ''; } : (x: string) => string >x : string function foo1b(x: B); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types index 240e12b1c22..3416662ffde 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types @@ -68,7 +68,6 @@ var b = { foo(x: T) { return x; } }; >b : { foo: (x: T) => T; } >{ foo(x: T) { return x; } } : { foo: (x: T) => T; } >foo : (x: T) => T ->foo(x: T) { return x; } : (x: T) => T >T : T >x : T >T : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types index 932dbf7e9b3..a7a70a5321d 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types @@ -86,7 +86,6 @@ var b = { foo(x: T, y: U) { return x; } }; >b : { foo: (x: T, y: U) => T; } >{ foo(x: T, y: U) { return x; } } : { foo: (x: T, y: U) => T; } >foo : (x: T, y: U) => T ->foo(x: T, y: U) { return x; } : (x: T, y: U) => T >T : T >U : U >x : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types index 2a5ab2dfe70..04186162b85 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types @@ -70,7 +70,6 @@ var b = { foo(x: T) { return ''; } }; >b : { foo: (x: T) => string; } >{ foo(x: T) { return ''; } } : { foo: (x: T) => string; } >foo : (x: T) => string ->foo(x: T) { return ''; } : (x: T) => string >T : T >RegExp : RegExp >x : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types index 9de1a816ab7..ca7860a68d4 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types @@ -67,7 +67,6 @@ var b = { foo(x: T) { return null; } }; >b : { foo: (x: T) => any; } >{ foo(x: T) { return null; } } : { foo: (x: T) => any; } >foo : (x: T) => any ->foo(x: T) { return null; } : (x: T) => any >T : T >x : T >T : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types index f6f33890c07..6678a6df110 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types @@ -73,7 +73,6 @@ var b = { foo(x: T) { return null; } }; >b : { foo: (x: T) => any; } >{ foo(x: T) { return null; } } : { foo: (x: T) => any; } >foo : (x: T) => any ->foo(x: T) { return null; } : (x: T) => any >T : T >Date : Date >x : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types index dbd6d3e7d03..d2644f41204 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types @@ -81,7 +81,6 @@ var b = { foo(x: A) { return x; } }; >b : { foo: (x: A) => A; } >{ foo(x: A) { return x; } } : { foo: (x: A) => A; } >foo : (x: A) => A ->foo(x: A) { return x; } : (x: A) => A >A : A >B : B >C : C diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types index 85e83528cd0..e5afc672fe1 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types @@ -68,7 +68,6 @@ var b = { foo(x: A) { return x; } }; >b : { foo: (x: A) => A; } >{ foo(x: A) { return x; } } : { foo: (x: A) => A; } >foo : (x: A) => A ->foo(x: A) { return x; } : (x: A) => A >A : A >x : A >A : A diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types index bef916fc410..e4b8417008a 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types @@ -82,7 +82,6 @@ var b = { foo(x: T, y?: T) { return x; } }; >b : { foo: (x: T, y?: T) => T; } >{ foo(x: T, y?: T) { return x; } } : { foo: (x: T, y?: T) => T; } >foo : (x: T, y?: T) => T ->foo(x: T, y?: T) { return x; } : (x: T, y?: T) => T >T : T >x : T >T : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types index c8a4ad6be29..9951084c84e 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types @@ -88,7 +88,6 @@ var b = { foo(x: T, y?: U) { return x; } }; >b : { foo: (x: T, y?: U) => T; } >{ foo(x: T, y?: U) { return x; } } : { foo: (x: T, y?: U) => T; } >foo : (x: T, y?: U) => T ->foo(x: T, y?: U) { return x; } : (x: T, y?: U) => T >T : T >U : U >x : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types index 06c23dcd0b1..bc5c91f94fa 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types @@ -88,7 +88,6 @@ var b = { foo(x: T, y: U) { return x; } }; >b : { foo: (x: T, y: U) => T; } >{ foo(x: T, y: U) { return x; } } : { foo: (x: T, y: U) => T; } >foo : (x: T, y: U) => T ->foo(x: T, y: U) { return x; } : (x: T, y: U) => T >T : T >U : U >x : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types index 8a41814e1a9..cd327865d12 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types @@ -54,7 +54,6 @@ var b = { new(x: T) { return ''; } }; // not a construct signa >b : { new: (x: T) => string; } >{ new(x: T) { return ''; } } : { new: (x: T) => string; } >new : (x: T) => string ->new(x: T) { return ''; } : (x: T) => string >T : T >RegExp : RegExp >x : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types index 1eac69f7f23..712958ca55b 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types @@ -52,7 +52,6 @@ var b = { new(x: T): T { return null; } }; // not a construct signature, func >b : { new: (x: T) => T; } >{ new(x: T): T { return null; } } : { new: (x: T) => T; } >new : (x: T) => T ->new(x: T): T { return null; } : (x: T) => T >T : T >x : T >T : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types index 308f592ef12..80b25828d50 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types @@ -57,7 +57,6 @@ var b = { new(x: T) { return null; } }; // not a construct signa >b : { new: (x: T) => any; } >{ new(x: T) { return null; } } : { new: (x: T) => any; } >new : (x: T) => any ->new(x: T) { return null; } : (x: T) => any >T : T >Date : Date >x : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types index 0276458ea91..15239aacf56 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types @@ -71,7 +71,6 @@ var b = { new(x: A) { return x; } }; >b : { new: (x: A) => A; } >{ new(x: A) { return x; } } : { new: (x: A) => A; } >new : (x: A) => A ->new(x: A) { return x; } : (x: A) => A >A : A >B : B >C : C diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types index 10a8da26907..0ef822a5328 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types @@ -53,7 +53,6 @@ var b = { new(x: A) { return new C(x); } }; >b : { new: (x: A) => C; } >{ new(x: A) { return new C(x); } } : { new: (x: A) => C; } >new : (x: A) => C ->new(x: A) { return new C(x); } : (x: A) => C >A : A >x : A >A : A diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types index 28ef6a81505..a13dbe1bcf4 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types @@ -65,7 +65,6 @@ var b = { new(x: T, y?: T) { return new C(x, y); } }; // not a construct s >b : { new: (x: T, y?: T) => C; } >{ new(x: T, y?: T) { return new C(x, y); } } : { new: (x: T, y?: T) => C; } >new : (x: T, y?: T) => C ->new(x: T, y?: T) { return new C(x, y); } : (x: T, y?: T) => C >T : T >x : T >T : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types index e75f1ce7cbb..dc1429cc9ca 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types @@ -73,7 +73,6 @@ var b = { new(x: T, y?: U) { return new C(x, y); } }; // not a const >b : { new: (x: T, y?: U) => C; } >{ new(x: T, y?: U) { return new C(x, y); } } : { new: (x: T, y?: U) => C; } >new : (x: T, y?: U) => C ->new(x: T, y?: U) { return new C(x, y); } : (x: T, y?: U) => C >T : T >U : U >x : T diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types index 5f5d592df34..9c8da5a6921 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types @@ -73,7 +73,6 @@ var b = { new(x: T, y: U) { return new C(x, y); } }; // not a constr >b : { new: (x: T, y: U) => C; } >{ new(x: T, y: U) { return new C(x, y); } } : { new: (x: T, y: U) => C; } >new : (x: T, y: U) => C ->new(x: T, y: U) { return new C(x, y); } : (x: T, y: U) => C >T : T >U : U >x : T diff --git a/tests/baselines/reference/parametersWithNoAnnotationAreAny.types b/tests/baselines/reference/parametersWithNoAnnotationAreAny.types index 9629d06c114..ee88697a82a 100644 --- a/tests/baselines/reference/parametersWithNoAnnotationAreAny.types +++ b/tests/baselines/reference/parametersWithNoAnnotationAreAny.types @@ -63,7 +63,6 @@ var b = { foo(x) { >foo : (x: any) => any ->foo(x) { return x; } : (x: any) => any >x : any return x; diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment1.types b/tests/baselines/reference/parserFunctionPropertyAssignment1.types index d84e798d023..9b1bdcd8d9f 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment1.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment1.types @@ -3,5 +3,4 @@ var v = { foo() { } }; >v : { foo: () => void; } >{ foo() { } } : { foo: () => void; } >foo : () => void ->foo() { } : () => void diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment2.types b/tests/baselines/reference/parserFunctionPropertyAssignment2.types index 21d182993bb..ab5dd3fdbaa 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment2.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment2.types @@ -2,5 +2,4 @@ var v = { 0() { } }; >v : { 0: () => void; } >{ 0() { } } : { 0: () => void; } ->0() { } : () => void diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment3.types b/tests/baselines/reference/parserFunctionPropertyAssignment3.types index 2c76fdf07a4..e245676e5f2 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment3.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment3.types @@ -2,5 +2,4 @@ var v = { "foo"() { } }; >v : { "foo": () => void; } >{ "foo"() { } } : { "foo": () => void; } ->"foo"() { } : () => void diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment4.types b/tests/baselines/reference/parserFunctionPropertyAssignment4.types index 4aec89e265f..38fb2aadf70 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment4.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment4.types @@ -2,6 +2,5 @@ var v = { 0() { } }; >v : { 0: () => void; } >{ 0() { } } : { 0: () => void; } ->0() { } : () => void >T : T diff --git a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types index a00f5fd0eff..7f5768923c5 100644 --- a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types +++ b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types @@ -3,5 +3,4 @@ var x = { n() { } }; >x : { n: () => void; } >{ n() { } } : { n: () => void; } >n : () => void ->n() { } : () => void diff --git a/tests/baselines/reference/thisInObjectLiterals.types b/tests/baselines/reference/thisInObjectLiterals.types index 8a279923e19..f0e54ef52ee 100644 --- a/tests/baselines/reference/thisInObjectLiterals.types +++ b/tests/baselines/reference/thisInObjectLiterals.types @@ -34,7 +34,6 @@ var obj = { f() { >f : () => any ->f() { return this.spaaace; } : () => any return this.spaaace; >this.spaaace : any diff --git a/tests/baselines/reference/throwInEnclosingStatements.types b/tests/baselines/reference/throwInEnclosingStatements.types index d642dc55b0b..52a49aadf37 100644 --- a/tests/baselines/reference/throwInEnclosingStatements.types +++ b/tests/baselines/reference/throwInEnclosingStatements.types @@ -91,7 +91,6 @@ var aa = { biz() { >biz : () => void ->biz() { throw this; } : () => void throw this; >this : any diff --git a/tests/baselines/reference/typeGuardsObjectMethods.types b/tests/baselines/reference/typeGuardsObjectMethods.types index a063145ce24..ad8c9237760 100644 --- a/tests/baselines/reference/typeGuardsObjectMethods.types +++ b/tests/baselines/reference/typeGuardsObjectMethods.types @@ -20,7 +20,6 @@ var obj1 = { // Inside method method(param: string | number) { >method : (param: string | number) => string | number ->method(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string return strOrNum; } : (param: string | number) => string | number >param : string | number // global vars in function declaration From d5ef6226da585f69a58bdd5c4d7d264182274bd1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Dec 2014 02:09:15 -0800 Subject: [PATCH 32/39] Emit FunctionPropertyAssignments in their native form when emitting in ES6 mode. --- src/compiler/checker.ts | 8 ++++-- src/compiler/emitter.ts | 26 ++++++++++++++----- .../reference/constDeclarations-scopes.js | 2 +- .../constDeclarations-validContexts.js | 2 +- .../reference/letDeclarations-scopes.js | 2 +- .../letDeclarations-validContexts.js | 2 +- .../objectLiteralShorthandPropertiesES6.js | 2 +- .../reference/parserComputedPropertyName3.js | 2 +- 8 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 422aff11286..83830e16eb2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3244,7 +3244,7 @@ module ts { switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - return !(node).typeParameters && !forEach((node).parameters, p => p.type); + return isContextSensitiveFunctionLikeDeclaration(node); case SyntaxKind.ObjectLiteralExpression: return forEach((node).properties, isContextSensitiveExpression); case SyntaxKind.ArrayLiteralExpression: @@ -3259,7 +3259,7 @@ module ts { return isContextSensitiveExpression((node).initializer); case SyntaxKind.Method: if (isObjectLiteralMethod(node)) { - return !(node).typeParameters && !forEach((node).parameters, p => p.type); + return isContextSensitiveFunctionLikeDeclaration(node); } return false; } @@ -3267,6 +3267,10 @@ module ts { return false; } + function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration) { + return !(node).typeParameters && !forEach((node).parameters, p => p.type); + } + function getTypeWithoutConstructors(type: Type): Type { if (type.flags & TypeFlags.ObjectType) { var resolved = resolveObjectOrUnionTypeMembers(type); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ba48eef2f85..9fccef4d6bf 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2228,7 +2228,11 @@ module ts { write("]"); } - function emitObjectLiteralMethod(node: MethodDeclaration) { + function emitDownlevelMethod(node: MethodDeclaration) { + if (!isObjectLiteralMethod(node)) { + return; + } + emitLeadingComments(node); emit(node.name); write(": "); @@ -2236,6 +2240,17 @@ module ts { emitSignatureAndBody(node); emitTrailingComments(node); } + + function emitMethod(node: MethodDeclaration) { + if (!isObjectLiteralMethod(node)) { + return; + } + + emitLeadingComments(node); + emit(node.name); + emitSignatureAndBody(node); + emitTrailingComments(node); + } function emitPropertyAssignment(node: PropertyDeclaration) { emitLeadingComments(node); @@ -3536,11 +3551,6 @@ module ts { return emitObjectLiteral(node); case SyntaxKind.LonghandPropertyAssignment: return emitPropertyAssignment(node); - case SyntaxKind.Method: - if (isObjectLiteralMethod(node)) { - return emitObjectLiteralMethod(node); - } - break; case SyntaxKind.ComputedPropertyName: return emitComputedPropertyName(node); case SyntaxKind.PropertyAccessExpression: @@ -3643,6 +3653,8 @@ module ts { switch (node.kind) { case SyntaxKind.ShorthandPropertyAssignment: return emitDownlevelShorthandPropertyAssignment(node); + case SyntaxKind.Method: + return emitDownlevelMethod(node); } } else { @@ -3651,6 +3663,8 @@ module ts { switch (node.kind) { case SyntaxKind.ShorthandPropertyAssignment: return emitShorthandPropertyAssignment(node); + case SyntaxKind.Method: + return emitMethod(node); } } } diff --git a/tests/baselines/reference/constDeclarations-scopes.js b/tests/baselines/reference/constDeclarations-scopes.js index 800dd856422..aa1d59aee81 100644 --- a/tests/baselines/reference/constDeclarations-scopes.js +++ b/tests/baselines/reference/constDeclarations-scopes.js @@ -265,7 +265,7 @@ var C = (function () { })(); // object literals var o = { - f: function () { + f() { const c = 0; n = c; }, diff --git a/tests/baselines/reference/constDeclarations-validContexts.js b/tests/baselines/reference/constDeclarations-validContexts.js index 355f39af2f2..8be43633d70 100644 --- a/tests/baselines/reference/constDeclarations-validContexts.js +++ b/tests/baselines/reference/constDeclarations-validContexts.js @@ -220,7 +220,7 @@ var C = (function () { })(); // object literals var o = { - f: function () { + f() { const c28 = 0; }, f2: function () { diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js index fb16a03f569..d0f70693d7c 100644 --- a/tests/baselines/reference/letDeclarations-scopes.js +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -282,7 +282,7 @@ var C = (function () { })(); // object literals var o = { - f: function () { + f() { let l = 0; n = l; }, diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js index 13eaafb0712..fe9ed903bf5 100644 --- a/tests/baselines/reference/letDeclarations-validContexts.js +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -240,7 +240,7 @@ var C = (function () { })(); // object literals var o = { - f: function () { + f() { let l28 = 0; }, f2: function () { diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.js b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.js index b398a231351..c65087a8da7 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.js +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.js @@ -32,7 +32,7 @@ var x3 = { a: 0, b, c, - d: function () { + d() { }, x3, parent: x3 diff --git a/tests/baselines/reference/parserComputedPropertyName3.js b/tests/baselines/reference/parserComputedPropertyName3.js index edb8533ad81..2e73fe87d3a 100644 --- a/tests/baselines/reference/parserComputedPropertyName3.js +++ b/tests/baselines/reference/parserComputedPropertyName3.js @@ -2,5 +2,5 @@ var v = { [e]() { } }; //// [parserComputedPropertyName3.js] -var v = { [e]: function () { +var v = { [e]() { } }; From 3440869010cf80c2127b0a2b3b5a7827c3bc03c7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Dec 2014 03:05:37 -0800 Subject: [PATCH 33/39] Print out methods in the types of object literals as if they were methods, not function typed properties. --- src/compiler/checker.ts | 54 ++++++++++++------- src/services/breakpoints.ts | 9 ++-- .../reference/assignEveryTypeToAny.types | 8 +-- ...callSignaturesWithOptionalParameters.types | 16 +++--- .../reference/commentsOnObjectLiteral3.types | 4 +- .../reference/invalidUndefinedValues.types | 4 +- .../invalidVoidAssignments.errors.txt | 4 +- .../reference/invalidVoidValues.errors.txt | 4 +- .../nameCollisionsInPropertyAssignments.types | 4 +- ...rConstrainsPropertyDeclarations.errors.txt | 4 +- .../objectLiteralShorthandProperties.types | 2 +- .../objectLiteralShorthandPropertiesES6.types | 2 +- ...bjectTypesIdentityWithCallSignatures.types | 38 ++++++------- ...jectTypesIdentityWithCallSignatures2.types | 38 ++++++------- ...thCallSignaturesDifferingParamCounts.types | 38 ++++++------- ...ntityWithCallSignaturesWithOverloads.types | 38 ++++++------- ...ypesIdentityWithConstructSignatures2.types | 38 ++++++------- ...structSignaturesDifferingParamCounts.types | 38 ++++++------- ...pesIdentityWithGenericCallSignatures.types | 38 ++++++------- ...esIdentityWithGenericCallSignatures2.types | 38 ++++++------- ...CallSignaturesDifferingByConstraints.types | 38 ++++++------- ...cCallSignaturesDifferingByReturnType.types | 38 ++++++------- ...CallSignaturesDifferingByReturnType2.types | 38 ++++++------- ...gnaturesDifferingTypeParameterCounts.types | 38 ++++++------- ...ignaturesDifferingTypeParameterNames.types | 38 ++++++------- ...hGenericCallSignaturesOptionalParams.types | 38 ++++++------- ...GenericCallSignaturesOptionalParams2.types | 38 ++++++------- ...GenericCallSignaturesOptionalParams3.types | 38 ++++++------- ...ructSignaturesDifferingByConstraints.types | 38 ++++++------- ...tructSignaturesDifferingByReturnType.types | 48 ++++++++--------- ...ructSignaturesDifferingByReturnType2.types | 38 ++++++------- ...gnaturesDifferingTypeParameterCounts.types | 38 ++++++------- ...ignaturesDifferingTypeParameterNames.types | 38 ++++++------- ...ricConstructSignaturesOptionalParams.types | 38 ++++++------- ...icConstructSignaturesOptionalParams2.types | 38 ++++++------- ...icConstructSignaturesOptionalParams3.types | 38 ++++++------- .../parametersWithNoAnnotationAreAny.types | 4 +- .../parserFunctionPropertyAssignment1.types | 4 +- .../parserFunctionPropertyAssignment2.types | 4 +- .../parserFunctionPropertyAssignment3.types | 4 +- .../parserFunctionPropertyAssignment4.types | 4 +- ...ValidationFunctionPropertyAssignment.types | 4 +- ...rConstrainsPropertyDeclarations.errors.txt | 4 +- .../reference/thisInObjectLiterals.types | 6 +-- .../throwInEnclosingStatements.types | 4 +- .../reference/typeGuardsObjectMethods.types | 12 ++--- 46 files changed, 549 insertions(+), 538 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 83830e16eb2..2b205aaca60 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1392,7 +1392,7 @@ module ts { for (var i = 0; i < resolved.properties.length; i++) { var p = resolved.properties[i]; var t = getTypeOfSymbol(p); - if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !isObjectLiteralMethod(p.valueDeclaration) && !getPropertiesOfObjectType(t).length) { + if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) { var signatures = getSignaturesOfType(t, SignatureKind.Call); for (var j = 0; j < signatures.length; j++) { buildSymbolDisplay(p, writer); @@ -2839,7 +2839,7 @@ module ts { // The expression is processed as an identifier expression (section 4.3) // or property access expression(section 4.10), // the widened type(section 3.9) of which becomes the result. - links.resolvedType = getWidenedType(checkExpression(node.exprName)); + links.resolvedType = getWidenedType(checkExpressionOrQualifiedName(node.exprName)); } return links.resolvedType; } @@ -3238,30 +3238,32 @@ module ts { return type; } + function isContextSensitiveExpression(node: Expression): boolean { + return isContextSensitiveCore(node); + } + // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. - function isContextSensitiveExpression(node: Node): boolean { + function isContextSensitiveCore(node: Expression | MethodDeclaration | PropertyAssignment): boolean { + Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: return isContextSensitiveFunctionLikeDeclaration(node); case SyntaxKind.ObjectLiteralExpression: - return forEach((node).properties, isContextSensitiveExpression); + return forEach((node).properties, isContextSensitiveCore); case SyntaxKind.ArrayLiteralExpression: - return forEach((node).elements, e => isContextSensitiveExpression(e)); + return forEach((node).elements, isContextSensitiveCore); case SyntaxKind.ConditionalExpression: - return isContextSensitiveExpression((node).whenTrue) || - isContextSensitiveExpression((node).whenFalse); + return isContextSensitiveCore((node).whenTrue) || + isContextSensitiveCore((node).whenFalse); case SyntaxKind.BinaryExpression: return (node).operator === SyntaxKind.BarBarToken && - (isContextSensitiveExpression((node).left) || isContextSensitiveExpression((node).right)); + (isContextSensitiveCore((node).left) || isContextSensitiveCore((node).right)); case SyntaxKind.LonghandPropertyAssignment: - return isContextSensitiveExpression((node).initializer); + return isContextSensitiveCore((node).initializer); case SyntaxKind.Method: - if (isObjectLiteralMethod(node)) { - return isContextSensitiveFunctionLikeDeclaration(node); - } - return false; + return isContextSensitiveFunctionLikeDeclaration(node); } return false; @@ -5115,7 +5117,7 @@ module ts { type = checkExpression((memberDecl).initializer, contextualMapper); } else if (memberDecl.kind === SyntaxKind.Method) { - type = checkExpression(memberDecl, contextualMapper); + type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment); @@ -5233,7 +5235,7 @@ module ts { } function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { - var type = checkExpression(left); + var type = checkExpressionOrQualifiedName(left); if (type === unknownType) return type; if (type !== anyType) { var apparentType = getApparentType(getWidenedType(type)); @@ -5274,7 +5276,7 @@ module ts { ? (node).expression : (node).left; - var type = checkExpression(left); + var type = checkExpressionOrQualifiedName(left); if (type !== unknownType && type !== anyType) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { @@ -6184,7 +6186,7 @@ module ts { links.flags |= NodeCheckFlags.ContextChecked; if (contextualSignature) { var signature = getSignaturesOfType(type, SignatureKind.Call)[0]; - if (isContextSensitiveExpression(node)) { + if (isContextSensitiveCore(node)) { assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper); } if (!node.type) { @@ -6590,6 +6592,18 @@ module ts { return result; } + function checkExpressionOrQualifiedName(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type { + return checkExpressionCore(node, contextualMapper); + } + + function checkExpression(node: Expression, contextualMapper?: TypeMapper): Type { + return checkExpressionCore(node, contextualMapper); + } + + function checkObjectLiteralMethod(node: MethodDeclaration, contextualMapper?: TypeMapper): Type { + return checkExpressionCore(node, contextualMapper); + } + // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When // contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the // expression is being inferentially typed (section 4.12.2 in spec) and provides the type mapper to use in @@ -6597,7 +6611,7 @@ module ts { // object, it serves as an indicator that all contained function and arrow expressions should be considered to // have the wildcard function type; this form of type check is used during overload resolution to exclude // contextually typed function and arrow expressions in the initial phase. - function checkExpression(node: Expression | QualifiedName | MethodDeclaration, contextualMapper?: TypeMapper): Type { + function checkExpressionCore(node: Expression | QualifiedName | MethodDeclaration, contextualMapper?: TypeMapper): Type { var type = checkExpressionOrQualifiedNameOrObjectLiteralMethodNode(node, contextualMapper); if (contextualMapper && contextualMapper !== identityMapper && node.kind !== SyntaxKind.QualifiedName) { var signature = getSingleCallSignature(type); @@ -7947,7 +7961,7 @@ module ts { } // Check that base type can be evaluated as expression - checkExpression(baseTypeNode.typeName); + checkExpressionOrQualifiedName(baseTypeNode.typeName); } var implementedTypeNodes = getClassImplementedTypeNodes(node); @@ -8436,7 +8450,7 @@ module ts { // ensure it can be evaluated as an expression var moduleName = getFirstIdentifier(node.moduleReference); if (resolveEntityName(node, moduleName, SymbolFlags.Value | SymbolFlags.Namespace).flags & SymbolFlags.Namespace) { - checkExpression(node.moduleReference); + checkExpressionOrQualifiedName(node.moduleReference); } else { error(moduleName, Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, declarationNameToString(moduleName)); diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 4b7b276086f..6bfeb1dc2a6 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -102,12 +102,9 @@ module ts.BreakpointResolver { return spanInFunctionDeclaration(node); case SyntaxKind.Block: - if (isFunctionBlock(node)) { - return spanInFunctionBlock(node); - } - else { - return spanInBlock(node); - } + return isFunctionBlock(node) + ? spanInFunctionBlock(node) + : spanInBlock(node); case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: diff --git a/tests/baselines/reference/assignEveryTypeToAny.types b/tests/baselines/reference/assignEveryTypeToAny.types index 8917ae22055..129440fa463 100644 --- a/tests/baselines/reference/assignEveryTypeToAny.types +++ b/tests/baselines/reference/assignEveryTypeToAny.types @@ -132,15 +132,15 @@ x = i; >i : () => string x = { f() { return 1; } } ->x = { f() { return 1; } } : { f: () => number; } +>x = { f() { return 1; } } : { f(): number; } >x : any ->{ f() { return 1; } } : { f: () => number; } +>{ f() { return 1; } } : { f(): number; } >f : () => number x = { f(x: T) { return x; } } ->x = { f(x: T) { return x; } } : { f: (x: T) => T; } +>x = { f(x: T) { return x; } } : { f(x: T): T; } >x : any ->{ f(x: T) { return x; } } : { f: (x: T) => T; } +>{ f(x: T) { return x; } } : { f(x: T): T; } >f : (x: T) => T >T : T >x : T diff --git a/tests/baselines/reference/callSignaturesWithOptionalParameters.types b/tests/baselines/reference/callSignaturesWithOptionalParameters.types index 49a94c3a6ed..818c52f79d0 100644 --- a/tests/baselines/reference/callSignaturesWithOptionalParameters.types +++ b/tests/baselines/reference/callSignaturesWithOptionalParameters.types @@ -133,8 +133,8 @@ a.foo(1); >foo : (x?: number) => any var b = { ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } ->{ foo(x?: number) { }, a: function foo(x: number, y?: number) { }, b: (x?: number) => { }} : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>{ foo(x?: number) { }, a: function foo(x: number, y?: number) { }, b: (x?: number) => { }} : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } foo(x?: number) { }, >foo : (x?: number) => void @@ -156,36 +156,36 @@ var b = { b.foo(); >b.foo() : void >b.foo : (x?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >foo : (x?: number) => void b.foo(1); >b.foo(1) : void >b.foo : (x?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >foo : (x?: number) => void b.a(1); >b.a(1) : void >b.a : (x: number, y?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >a : (x: number, y?: number) => void b.a(1, 2); >b.a(1, 2) : void >b.a : (x: number, y?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >a : (x: number, y?: number) => void b.b(); >b.b() : void >b.b : (x?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >b : (x?: number) => void b.b(1); >b.b(1) : void >b.b : (x?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >b : (x?: number) => void diff --git a/tests/baselines/reference/commentsOnObjectLiteral3.types b/tests/baselines/reference/commentsOnObjectLiteral3.types index 08dfd14cedb..e81bd646b5a 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral3.types +++ b/tests/baselines/reference/commentsOnObjectLiteral3.types @@ -1,8 +1,8 @@ === tests/cases/compiler/commentsOnObjectLiteral3.ts === var v = { ->v : { prop: number; func: () => void; func1: () => void; a: any; } ->{ //property prop: 1 /* multiple trailing comments */ /*trailing comments*/, //property func: function () { }, //PropertyName + CallSignature func1() { }, //getter get a() { return this.prop; } /*trailing 1*/, //setter set a(value) { this.prop = value; } // trailing 2} : { prop: number; func: () => void; func1: () => void; a: any; } +>v : { prop: number; func: () => void; func1(): void; a: any; } +>{ //property prop: 1 /* multiple trailing comments */ /*trailing comments*/, //property func: function () { }, //PropertyName + CallSignature func1() { }, //getter get a() { return this.prop; } /*trailing 1*/, //setter set a(value) { this.prop = value; } // trailing 2} : { prop: number; func: () => void; func1(): void; a: any; } //property prop: 1 /* multiple trailing comments */ /*trailing comments*/, diff --git a/tests/baselines/reference/invalidUndefinedValues.types b/tests/baselines/reference/invalidUndefinedValues.types index 3e3e08183c2..3f17deede37 100644 --- a/tests/baselines/reference/invalidUndefinedValues.types +++ b/tests/baselines/reference/invalidUndefinedValues.types @@ -68,9 +68,9 @@ x = M; >M : typeof M x = { f() { } } ->x = { f() { } } : { f: () => void; } +>x = { f() { } } : { f(): void; } >x : any ->{ f() { } } : { f: () => void; } +>{ f() { } } : { f(): void; } >f : () => void function f(a: T) { diff --git a/tests/baselines/reference/invalidVoidAssignments.errors.txt b/tests/baselines/reference/invalidVoidAssignments.errors.txt index 64decc2f5e2..9c6be972d3b 100644 --- a/tests/baselines/reference/invalidVoidAssignments.errors.txt +++ b/tests/baselines/reference/invalidVoidAssignments.errors.txt @@ -12,7 +12,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(21,5): e tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(26,1): error TS2322: Type 'typeof E' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(27,1): error TS2322: Type 'E' is not assignable to type 'void'. -tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): error TS2322: Type '{ f: () => void; }' is not assignable to type 'void'. +tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. ==== tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts (13 errors) ==== @@ -72,4 +72,4 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): e x = { f() { } } ~ -!!! error TS2322: Type '{ f: () => void; }' is not assignable to type 'void'. \ No newline at end of file +!!! error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. \ No newline at end of file diff --git a/tests/baselines/reference/invalidVoidValues.errors.txt b/tests/baselines/reference/invalidVoidValues.errors.txt index b8a4400e4e0..eb5ddd02259 100644 --- a/tests/baselines/reference/invalidVoidValues.errors.txt +++ b/tests/baselines/reference/invalidVoidValues.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(7,1): error T tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(8,1): error TS2322: Type 'E' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(12,1): error TS2322: Type 'C' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(16,1): error TS2322: Type 'I' is not assignable to type 'void'. -tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(18,1): error TS2322: Type '{ f: () => void; }' is not assignable to type 'void'. +tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(18,1): error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(21,1): error TS2322: Type 'typeof M' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(24,5): error TS2322: Type 'T' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(26,1): error TS2322: Type '(a: T) => void' is not assignable to type 'void'. @@ -45,7 +45,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(26,1): error x = { f() {} } ~ -!!! error TS2322: Type '{ f: () => void; }' is not assignable to type 'void'. +!!! error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. module M { export var x = 1; } x = M; diff --git a/tests/baselines/reference/nameCollisionsInPropertyAssignments.types b/tests/baselines/reference/nameCollisionsInPropertyAssignments.types index aad0fcc1df4..41bcdd99a71 100644 --- a/tests/baselines/reference/nameCollisionsInPropertyAssignments.types +++ b/tests/baselines/reference/nameCollisionsInPropertyAssignments.types @@ -3,8 +3,8 @@ var x = 1 >x : number var y = { x() { x++; } }; ->y : { x: () => void; } ->{ x() { x++; } } : { x: () => void; } +>y : { x(): void; } +>{ x() { x++; } } : { x(): void; } >x : () => void >x++ : number >x : number diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index 19f2c700ccf..bd9a0bcbc93 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(21,5): error TS2412: Property '3.0' of type 'MyNumber' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. Index signatures are incompatible. Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -108,7 +108,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: string; } = { ~ -!!! error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }'. +!!! error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. diff --git a/tests/baselines/reference/objectLiteralShorthandProperties.types b/tests/baselines/reference/objectLiteralShorthandProperties.types index c5b869d5a74..c34b2ab79b7 100644 --- a/tests/baselines/reference/objectLiteralShorthandProperties.types +++ b/tests/baselines/reference/objectLiteralShorthandProperties.types @@ -23,7 +23,7 @@ var x2 = { var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d: () => void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } a: 0, >a : number diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types index 5a85c17694f..5d5acc279a5 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types @@ -23,7 +23,7 @@ var x2 = { var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d: () => void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } a: 0, >a : number diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types b/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types index 184683910af..efe7e32f5d7 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types @@ -53,8 +53,8 @@ var a: { foo(x: string): string } >x : string var b = { foo(x: string) { return ''; } }; ->b : { foo: (x: string) => string; } ->{ foo(x: string) { return ''; } } : { foo: (x: string) => string; } +>b : { foo(x: string): string; } +>{ foo(x: string) { return ''; } } : { foo(x: string): string; } >foo : (x: string) => string >x : string @@ -129,17 +129,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } >x : any function foo5(x: A); @@ -241,17 +241,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } >x : B >B : B function foo11(x: typeof b); // error ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } >x : any function foo12(x: I); @@ -297,17 +297,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } >x : I >I : I function foo14(x: typeof b); // error ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types index 0143ae426f4..9004a267691 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types @@ -54,8 +54,8 @@ var a: { foo(x: Date): string } >Date : Date var b = { foo(x: RegExp) { return ''; } }; ->b : { foo: (x: RegExp) => string; } ->{ foo(x: RegExp) { return ''; } } : { foo: (x: RegExp) => string; } +>b : { foo(x: RegExp): string; } +>{ foo(x: RegExp) { return ''; } } : { foo(x: RegExp): string; } >foo : (x: RegExp) => string >x : RegExp >RegExp : RegExp @@ -131,17 +131,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: RegExp) => string; }): any; (x: { foo: (x: RegExp) => string; }): any; } ->x : { foo: (x: RegExp) => string; } ->b : { foo: (x: RegExp) => string; } +>foo4 : { (x: { foo(x: RegExp): string; }): any; (x: { foo(x: RegExp): string; }): any; } +>x : { foo(x: RegExp): string; } +>b : { foo(x: RegExp): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: RegExp) => string; }): any; (x: { foo: (x: RegExp) => string; }): any; } ->x : { foo: (x: RegExp) => string; } ->b : { foo: (x: RegExp) => string; } +>foo4 : { (x: { foo(x: RegExp): string; }): any; (x: { foo(x: RegExp): string; }): any; } +>x : { foo(x: RegExp): string; } +>b : { foo(x: RegExp): string; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: RegExp) => string; }): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo4 : { (x: { foo(x: RegExp): string; }): any; (x: { foo(x: RegExp): string; }): any; } >x : any function foo5(x: A); @@ -243,17 +243,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: RegExp): string; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: RegExp) => string; }): any; } ->x : { foo: (x: RegExp) => string; } ->b : { foo: (x: RegExp) => string; } +>foo11 : { (x: B): any; (x: { foo(x: RegExp): string; }): any; } +>x : { foo(x: RegExp): string; } +>b : { foo(x: RegExp): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: RegExp): string; }): any; } >x : any function foo12(x: I); @@ -299,17 +299,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: RegExp): string; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: RegExp) => string; }): any; } ->x : { foo: (x: RegExp) => string; } ->b : { foo: (x: RegExp) => string; } +>foo14 : { (x: I): any; (x: { foo(x: RegExp): string; }): any; } +>x : { foo(x: RegExp): string; } +>b : { foo(x: RegExp): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: RegExp): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types index 90ad61ad044..2f97c721637 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types @@ -57,8 +57,8 @@ var a: { foo(x: string, y: string): string } >y : string var b = { foo(x: string) { return ''; } }; ->b : { foo: (x: string) => string; } ->{ foo(x: string) { return ''; } } : { foo: (x: string) => string; } +>b : { foo(x: string): string; } +>{ foo(x: string) { return ''; } } : { foo(x: string): string; } >foo : (x: string) => string >x : string @@ -133,17 +133,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } >x : any function foo5(x: A); @@ -245,17 +245,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } >x : any function foo12(x: I); @@ -301,17 +301,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } >x : I >I : I function foo14(x: typeof b); // error ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types index ef31cf1fe4d..c3ab4ffb837 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types @@ -100,8 +100,8 @@ var a: { } var b = { ->b : { foo: (x: any) => any; } ->{ foo(x: any) { return ''; }} : { foo: (x: any) => any; } +>b : { foo(x: any): any; } +>{ foo(x: any) { return ''; }} : { foo(x: any): any; } foo(x: any) { return ''; } >foo : (x: any) => any @@ -181,17 +181,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: any) => any; }): any; (x: { foo: (x: any) => any; }): any; } ->x : { foo: (x: any) => any; } ->b : { foo: (x: any) => any; } +>foo4 : { (x: { foo(x: any): any; }): any; (x: { foo(x: any): any; }): any; } +>x : { foo(x: any): any; } +>b : { foo(x: any): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: any) => any; }): any; (x: { foo: (x: any) => any; }): any; } ->x : { foo: (x: any) => any; } ->b : { foo: (x: any) => any; } +>foo4 : { (x: { foo(x: any): any; }): any; (x: { foo(x: any): any; }): any; } +>x : { foo(x: any): any; } +>b : { foo(x: any): any; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: any) => any; }): any; (x: { foo: (x: any) => any; }): any; } +>foo4 : { (x: { foo(x: any): any; }): any; (x: { foo(x: any): any; }): any; } >x : any function foo5(x: A); @@ -293,17 +293,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: any) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: any): any; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: any) => any; }): any; } ->x : { foo: (x: any) => any; } ->b : { foo: (x: any) => any; } +>foo11 : { (x: B): any; (x: { foo(x: any): any; }): any; } +>x : { foo(x: any): any; } +>b : { foo(x: any): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: any) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: any): any; }): any; } >x : any function foo12(x: I); @@ -349,17 +349,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: any) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: any): any; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: any) => any; }): any; } ->x : { foo: (x: any) => any; } ->b : { foo: (x: any) => any; } +>foo14 : { (x: I): any; (x: { foo(x: any): any; }): any; } +>x : { foo(x: any): any; } +>b : { foo(x: any): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: any) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: any): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types index b44bc323a3d..769682c826a 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types @@ -40,8 +40,8 @@ var a: { new(x: Date): string } >Date : Date var b = { new(x: RegExp) { return ''; } }; // not a construct signature, function called new ->b : { new: (x: RegExp) => string; } ->{ new(x: RegExp) { return ''; } } : { new: (x: RegExp) => string; } +>b : { new(x: RegExp): string; } +>{ new(x: RegExp) { return ''; } } : { new(x: RegExp): string; } >new : (x: RegExp) => string >x : RegExp >RegExp : RegExp @@ -103,17 +103,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: RegExp) => string; }): any; (x: { new: (x: RegExp) => string; }): any; } ->x : { new: (x: RegExp) => string; } ->b : { new: (x: RegExp) => string; } +>foo4 : { (x: { new(x: RegExp): string; }): any; (x: { new(x: RegExp): string; }): any; } +>x : { new(x: RegExp): string; } +>b : { new(x: RegExp): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: RegExp) => string; }): any; (x: { new: (x: RegExp) => string; }): any; } ->x : { new: (x: RegExp) => string; } ->b : { new: (x: RegExp) => string; } +>foo4 : { (x: { new(x: RegExp): string; }): any; (x: { new(x: RegExp): string; }): any; } +>x : { new(x: RegExp): string; } +>b : { new(x: RegExp): string; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: RegExp) => string; }): any; (x: { new: (x: RegExp) => string; }): any; } +>foo4 : { (x: { new(x: RegExp): string; }): any; (x: { new(x: RegExp): string; }): any; } >x : any function foo8(x: B); @@ -159,17 +159,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: RegExp) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: RegExp) => string; }): any; } ->x : { new: (x: RegExp) => string; } ->b : { new: (x: RegExp) => string; } +>foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } +>x : { new(x: RegExp): string; } +>b : { new(x: RegExp): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: RegExp) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } >x : any function foo12(x: I); @@ -215,17 +215,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: RegExp) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: RegExp) => string; }): any; } ->x : { new: (x: RegExp) => string; } ->b : { new: (x: RegExp) => string; } +>foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } +>x : { new(x: RegExp): string; } +>b : { new(x: RegExp): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: RegExp) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types index 8d26b98c361..a2779e3bd35 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types @@ -43,8 +43,8 @@ var a: { new(x: string, y: string): string } >y : string var b = { new(x: string) { return ''; } }; // not a construct signature, function called new ->b : { new: (x: string) => string; } ->{ new(x: string) { return ''; } } : { new: (x: string) => string; } +>b : { new(x: string): string; } +>{ new(x: string) { return ''; } } : { new(x: string): string; } >new : (x: string) => string >x : string @@ -105,17 +105,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: string) => string; }): any; (x: { new: (x: string) => string; }): any; } ->x : { new: (x: string) => string; } ->b : { new: (x: string) => string; } +>foo4 : { (x: { new(x: string): string; }): any; (x: { new(x: string): string; }): any; } +>x : { new(x: string): string; } +>b : { new(x: string): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: string) => string; }): any; (x: { new: (x: string) => string; }): any; } ->x : { new: (x: string) => string; } ->b : { new: (x: string) => string; } +>foo4 : { (x: { new(x: string): string; }): any; (x: { new(x: string): string; }): any; } +>x : { new(x: string): string; } +>b : { new(x: string): string; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: string) => string; }): any; (x: { new: (x: string) => string; }): any; } +>foo4 : { (x: { new(x: string): string; }): any; (x: { new(x: string): string; }): any; } >x : any function foo8(x: B); @@ -161,17 +161,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: string) => string; }): any; } ->x : { new: (x: string) => string; } ->b : { new: (x: string) => string; } +>foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } +>x : { new(x: string): string; } +>b : { new(x: string): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } >x : any function foo12(x: I); @@ -217,17 +217,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: string) => string; }): any; } ->x : { new: (x: string) => string; } ->b : { new: (x: string) => string; } +>foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } +>x : { new(x: string): string; } +>b : { new(x: string): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types index 3416662ffde..d3cf9bc0063 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types @@ -65,8 +65,8 @@ var a: { foo(x: T): T } >T : T var b = { foo(x: T) { return x; } }; ->b : { foo: (x: T) => T; } ->{ foo(x: T) { return x; } } : { foo: (x: T) => T; } +>b : { foo(x: T): T; } +>{ foo(x: T) { return x; } } : { foo(x: T): T; } >foo : (x: T) => T >T : T >x : T @@ -144,17 +144,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T) => T; }): any; (x: { foo: (x: T) => T; }): any; } ->x : { foo: (x: T) => T; } ->b : { foo: (x: T) => T; } +>foo4 : { (x: { foo(x: T): T; }): any; (x: { foo(x: T): T; }): any; } +>x : { foo(x: T): T; } +>b : { foo(x: T): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T) => T; }): any; (x: { foo: (x: T) => T; }): any; } ->x : { foo: (x: T) => T; } ->b : { foo: (x: T) => T; } +>foo4 : { (x: { foo(x: T): T; }): any; (x: { foo(x: T): T; }): any; } +>x : { foo(x: T): T; } +>b : { foo(x: T): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T) => T; }): any; (x: { foo: (x: T) => T; }): any; } +>foo4 : { (x: { foo(x: T): T; }): any; (x: { foo(x: T): T; }): any; } >x : any function foo5(x: A); @@ -256,17 +256,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T) => T; }): any; } ->x : { foo: (x: T) => T; } ->b : { foo: (x: T) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T): T; }): any; } +>x : { foo(x: T): T; } +>b : { foo(x: T): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): T; }): any; } >x : any function foo12(x: I); @@ -312,17 +312,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T) => T; }): any; } ->x : { foo: (x: T) => T; } ->b : { foo: (x: T) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T): T; }): any; } +>x : { foo(x: T): T; } +>b : { foo(x: T): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types index a7a70a5321d..0c00e587b78 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types @@ -83,8 +83,8 @@ var a: { foo(x: T, y: U): T } >T : T var b = { foo(x: T, y: U) { return x; } }; ->b : { foo: (x: T, y: U) => T; } ->{ foo(x: T, y: U) { return x; } } : { foo: (x: T, y: U) => T; } +>b : { foo(x: T, y: U): T; } +>{ foo(x: T, y: U) { return x; } } : { foo(x: T, y: U): T; } >foo : (x: T, y: U) => T >T : T >U : U @@ -165,17 +165,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo5(x: A); @@ -277,17 +277,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo12(x: I); @@ -333,17 +333,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types index 04186162b85..432a618c4e2 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types @@ -67,8 +67,8 @@ var a: { foo>(x: T): string } >T : T var b = { foo(x: T) { return ''; } }; ->b : { foo: (x: T) => string; } ->{ foo(x: T) { return ''; } } : { foo: (x: T) => string; } +>b : { foo(x: T): string; } +>{ foo(x: T) { return ''; } } : { foo(x: T): string; } >foo : (x: T) => string >T : T >RegExp : RegExp @@ -152,17 +152,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T) => string; }): any; (x: { foo: (x: T) => string; }): any; } ->x : { foo: (x: T) => string; } ->b : { foo: (x: T) => string; } +>foo4 : { (x: { foo(x: T): string; }): any; (x: { foo(x: T): string; }): any; } +>x : { foo(x: T): string; } +>b : { foo(x: T): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T) => string; }): any; (x: { foo: (x: T) => string; }): any; } ->x : { foo: (x: T) => string; } ->b : { foo: (x: T) => string; } +>foo4 : { (x: { foo(x: T): string; }): any; (x: { foo(x: T): string; }): any; } +>x : { foo(x: T): string; } +>b : { foo(x: T): string; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T) => string; }): any; (x: { foo: (x: T) => string; }): any; } +>foo4 : { (x: { foo(x: T): string; }): any; (x: { foo(x: T): string; }): any; } >x : any function foo5(x: A); @@ -272,18 +272,18 @@ function foo10(x: any) { } >x : any function foo11(x: B>); ->foo11 : { (x: B): any; (x: { foo: (x: T) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): string; }): any; } >x : B >B : B >Array : T[] function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T) => string; }): any; } ->x : { foo: (x: T) => string; } ->b : { foo: (x: T) => string; } +>foo11 : { (x: B): any; (x: { foo(x: T): string; }): any; } +>x : { foo(x: T): string; } +>b : { foo(x: T): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): string; }): any; } >x : any function foo12(x: I); @@ -333,18 +333,18 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): string; }): any; } >x : I >I : I >Number : Number function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T) => string; }): any; } ->x : { foo: (x: T) => string; } ->b : { foo: (x: T) => string; } +>foo14 : { (x: I): any; (x: { foo(x: T): string; }): any; } +>x : { foo(x: T): string; } +>b : { foo(x: T): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types index ca7860a68d4..8b5a042c1e2 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types @@ -64,8 +64,8 @@ var a: { foo(x: T): T } >T : T var b = { foo(x: T) { return null; } }; ->b : { foo: (x: T) => any; } ->{ foo(x: T) { return null; } } : { foo: (x: T) => any; } +>b : { foo(x: T): any; } +>{ foo(x: T) { return null; } } : { foo(x: T): any; } >foo : (x: T) => any >T : T >x : T @@ -142,17 +142,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } >x : any function foo5(x: A); @@ -254,17 +254,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } >x : any function foo12(x: I); @@ -310,17 +310,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types index 6678a6df110..2863cafa885 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types @@ -70,8 +70,8 @@ var a: { foo(x: T): T } >T : T var b = { foo(x: T) { return null; } }; ->b : { foo: (x: T) => any; } ->{ foo(x: T) { return null; } } : { foo: (x: T) => any; } +>b : { foo(x: T): any; } +>{ foo(x: T) { return null; } } : { foo(x: T): any; } >foo : (x: T) => any >T : T >Date : Date @@ -155,17 +155,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } >x : any function foo5(x: A); @@ -275,18 +275,18 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } >x : B >B : B >Date : Date function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } >x : any function foo12(x: I); @@ -336,18 +336,18 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } >x : I >I : I >Date : Date function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types index d2644f41204..125b82c9915 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types @@ -78,8 +78,8 @@ var a: { foo(x: Z): Z } >Z : Z var b = { foo(x: A) { return x; } }; ->b : { foo: (x: A) => A; } ->{ foo(x: A) { return x; } } : { foo: (x: A) => A; } +>b : { foo(x: A): A; } +>{ foo(x: A) { return x; } } : { foo(x: A): A; } >foo : (x: A) => A >A : A >B : B @@ -162,17 +162,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } >x : any function foo5(x: A); @@ -277,17 +277,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } >x : any function foo12(x: I, number, Date, string>); @@ -340,19 +340,19 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } >x : I >I : I >Date : Date >RegExp : RegExp function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types index e5afc672fe1..fd0b14a4f79 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types @@ -65,8 +65,8 @@ var a: { foo(x: Z): Z } >Z : Z var b = { foo(x: A) { return x; } }; ->b : { foo: (x: A) => A; } ->{ foo(x: A) { return x; } } : { foo: (x: A) => A; } +>b : { foo(x: A): A; } +>{ foo(x: A) { return x; } } : { foo(x: A): A; } >foo : (x: A) => A >A : A >x : A @@ -144,17 +144,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } >x : any function foo5(x: A); @@ -256,17 +256,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } >x : any function foo12(x: I); @@ -312,17 +312,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types index e4b8417008a..33fce5295a7 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types @@ -79,8 +79,8 @@ var a: { foo(x: T, y?: T): T } >T : T var b = { foo(x: T, y?: T) { return x; } }; ->b : { foo: (x: T, y?: T) => T; } ->{ foo(x: T, y?: T) { return x; } } : { foo: (x: T, y?: T) => T; } +>b : { foo(x: T, y?: T): T; } +>{ foo(x: T, y?: T) { return x; } } : { foo(x: T, y?: T): T; } >foo : (x: T, y?: T) => T >T : T >x : T @@ -160,17 +160,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T, y?: T) => T; }): any; (x: { foo: (x: T, y?: T) => T; }): any; } ->x : { foo: (x: T, y?: T) => T; } ->b : { foo: (x: T, y?: T) => T; } +>foo4 : { (x: { foo(x: T, y?: T): T; }): any; (x: { foo(x: T, y?: T): T; }): any; } +>x : { foo(x: T, y?: T): T; } +>b : { foo(x: T, y?: T): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T, y?: T) => T; }): any; (x: { foo: (x: T, y?: T) => T; }): any; } ->x : { foo: (x: T, y?: T) => T; } ->b : { foo: (x: T, y?: T) => T; } +>foo4 : { (x: { foo(x: T, y?: T): T; }): any; (x: { foo(x: T, y?: T): T; }): any; } +>x : { foo(x: T, y?: T): T; } +>b : { foo(x: T, y?: T): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T, y?: T) => T; }): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo4 : { (x: { foo(x: T, y?: T): T; }): any; (x: { foo(x: T, y?: T): T; }): any; } >x : any function foo5(x: A); @@ -272,17 +272,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: T): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: T) => T; }): any; } ->x : { foo: (x: T, y?: T) => T; } ->b : { foo: (x: T, y?: T) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: T): T; }): any; } +>x : { foo(x: T, y?: T): T; } +>b : { foo(x: T, y?: T): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: T): T; }): any; } >x : any function foo12(x: I); @@ -328,17 +328,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: T): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: T) => T; }): any; } ->x : { foo: (x: T, y?: T) => T; } ->b : { foo: (x: T, y?: T) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: T): T; }): any; } +>x : { foo(x: T, y?: T): T; } +>b : { foo(x: T, y?: T): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: T): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types index 9951084c84e..2d9eab7c540 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types @@ -85,8 +85,8 @@ var a: { foo(x: T, y?: U): T } >T : T var b = { foo(x: T, y?: U) { return x; } }; ->b : { foo: (x: T, y?: U) => T; } ->{ foo(x: T, y?: U) { return x; } } : { foo: (x: T, y?: U) => T; } +>b : { foo(x: T, y?: U): T; } +>{ foo(x: T, y?: U) { return x; } } : { foo(x: T, y?: U): T; } >foo : (x: T, y?: U) => T >T : T >U : U @@ -167,17 +167,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T, y?: U) => T; }): any; (x: { foo: (x: T, y?: U) => T; }): any; } ->x : { foo: (x: T, y?: U) => T; } ->b : { foo: (x: T, y?: U) => T; } +>foo4 : { (x: { foo(x: T, y?: U): T; }): any; (x: { foo(x: T, y?: U): T; }): any; } +>x : { foo(x: T, y?: U): T; } +>b : { foo(x: T, y?: U): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T, y?: U) => T; }): any; (x: { foo: (x: T, y?: U) => T; }): any; } ->x : { foo: (x: T, y?: U) => T; } ->b : { foo: (x: T, y?: U) => T; } +>foo4 : { (x: { foo(x: T, y?: U): T; }): any; (x: { foo(x: T, y?: U): T; }): any; } +>x : { foo(x: T, y?: U): T; } +>b : { foo(x: T, y?: U): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T, y?: U) => T; }): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo4 : { (x: { foo(x: T, y?: U): T; }): any; (x: { foo(x: T, y?: U): T; }): any; } >x : any function foo5(x: A); @@ -279,17 +279,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: U): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: U) => T; }): any; } ->x : { foo: (x: T, y?: U) => T; } ->b : { foo: (x: T, y?: U) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: U): T; }): any; } +>x : { foo(x: T, y?: U): T; } +>b : { foo(x: T, y?: U): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: U): T; }): any; } >x : any function foo12(x: I); @@ -335,17 +335,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: U): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: U) => T; }): any; } ->x : { foo: (x: T, y?: U) => T; } ->b : { foo: (x: T, y?: U) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: U): T; }): any; } +>x : { foo(x: T, y?: U): T; } +>b : { foo(x: T, y?: U): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: U): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types index bc5c91f94fa..54ec438104e 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types @@ -85,8 +85,8 @@ var a: { foo(x: T, y?: U): T } >T : T var b = { foo(x: T, y: U) { return x; } }; ->b : { foo: (x: T, y: U) => T; } ->{ foo(x: T, y: U) { return x; } } : { foo: (x: T, y: U) => T; } +>b : { foo(x: T, y: U): T; } +>{ foo(x: T, y: U) { return x; } } : { foo(x: T, y: U): T; } >foo : (x: T, y: U) => T >T : T >U : U @@ -167,17 +167,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo5(x: A); @@ -279,17 +279,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo12(x: I); @@ -335,17 +335,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types index cd327865d12..7acc93db124 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types @@ -51,8 +51,8 @@ var a: { new>(x: T): string } >T : T var b = { new(x: T) { return ''; } }; // not a construct signature, function called new ->b : { new: (x: T) => string; } ->{ new(x: T) { return ''; } } : { new: (x: T) => string; } +>b : { new(x: T): string; } +>{ new(x: T) { return ''; } } : { new(x: T): string; } >new : (x: T) => string >T : T >RegExp : RegExp @@ -122,17 +122,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T) => string; }): any; (x: { new: (x: T) => string; }): any; } ->x : { new: (x: T) => string; } ->b : { new: (x: T) => string; } +>foo4 : { (x: { new(x: T): string; }): any; (x: { new(x: T): string; }): any; } +>x : { new(x: T): string; } +>b : { new(x: T): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T) => string; }): any; (x: { new: (x: T) => string; }): any; } ->x : { new: (x: T) => string; } ->b : { new: (x: T) => string; } +>foo4 : { (x: { new(x: T): string; }): any; (x: { new(x: T): string; }): any; } +>x : { new(x: T): string; } +>b : { new(x: T): string; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T) => string; }): any; (x: { new: (x: T) => string; }): any; } +>foo4 : { (x: { new(x: T): string; }): any; (x: { new(x: T): string; }): any; } >x : any function foo8(x: B>); @@ -183,18 +183,18 @@ function foo10(x: any) { } >x : any function foo11(x: B>); ->foo11 : { (x: B): any; (x: { new: (x: T) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): string; }): any; } >x : B >B : B >Array : T[] function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T) => string; }): any; } ->x : { new: (x: T) => string; } ->b : { new: (x: T) => string; } +>foo11 : { (x: B): any; (x: { new(x: T): string; }): any; } +>x : { new(x: T): string; } +>b : { new(x: T): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): string; }): any; } >x : any function foo12(x: I); @@ -244,17 +244,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } >x : I >I : I >Number : Number function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T) => string; }): any; } ->x : { new: (x: T) => string; } ->b : { new: (x: T) => string; } +>foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } +>x : { new(x: T): string; } +>b : { new(x: T): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types index 712958ca55b..4b2e628ad5d 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types @@ -49,8 +49,8 @@ var a: { new(x: T): T } >T : T var b = { new(x: T): T { return null; } }; // not a construct signature, function called new ->b : { new: (x: T) => T; } ->{ new(x: T): T { return null; } } : { new: (x: T) => T; } +>b : { new(x: T): T; } +>{ new(x: T): T { return null; } } : { new(x: T): T; } >new : (x: T) => T >T : T >x : T @@ -114,31 +114,31 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T) => T; }): any; (x: { new: (x: T) => T; }): any; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo4 : { (x: { new(x: T): T; }): any; (x: { new(x: T): T; }): any; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T) => T; }): any; (x: { new: (x: T) => T; }): any; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo4 : { (x: { new(x: T): T; }): any; (x: { new(x: T): T; }): any; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T) => T; }): any; (x: { new: (x: T) => T; }): any; } +>foo4 : { (x: { new(x: T): T; }): any; (x: { new(x: T): T; }): any; } >x : any function foo5(x: typeof a): number; ->foo5 : { (x: new (x: T) => T): number; (x: { new: (x: T) => T; }): string; } +>foo5 : { (x: new (x: T) => T): number; (x: { new(x: T): T; }): string; } >x : new (x: T) => T >a : new (x: T) => T function foo5(x: typeof b): string; // ok ->foo5 : { (x: new (x: T) => T): number; (x: { new: (x: T) => T; }): string; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo5 : { (x: new (x: T) => T): number; (x: { new(x: T): T; }): string; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo5(x: any): any { } ->foo5 : { (x: new (x: T) => T): number; (x: { new: (x: T) => T; }): string; } +>foo5 : { (x: new (x: T) => T): number; (x: { new(x: T): T; }): string; } >x : any function foo8(x: B); @@ -184,17 +184,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T) => T; }): any; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } >x : any function foo12(x: I); @@ -240,17 +240,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T) => T; }): any; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types index 80b25828d50..a25fb5b876a 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types @@ -54,8 +54,8 @@ var a: { new(x: T): T } >T : T var b = { new(x: T) { return null; } }; // not a construct signature, function called new ->b : { new: (x: T) => any; } ->{ new(x: T) { return null; } } : { new: (x: T) => any; } +>b : { new(x: T): any; } +>{ new(x: T) { return null; } } : { new(x: T): any; } >new : (x: T) => any >T : T >Date : Date @@ -125,17 +125,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T) => any; }): any; (x: { new: (x: T) => any; }): any; } ->x : { new: (x: T) => any; } ->b : { new: (x: T) => any; } +>foo4 : { (x: { new(x: T): any; }): any; (x: { new(x: T): any; }): any; } +>x : { new(x: T): any; } +>b : { new(x: T): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T) => any; }): any; (x: { new: (x: T) => any; }): any; } ->x : { new: (x: T) => any; } ->b : { new: (x: T) => any; } +>foo4 : { (x: { new(x: T): any; }): any; (x: { new(x: T): any; }): any; } +>x : { new(x: T): any; } +>b : { new(x: T): any; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T) => any; }): any; (x: { new: (x: T) => any; }): any; } +>foo4 : { (x: { new(x: T): any; }): any; (x: { new(x: T): any; }): any; } >x : any function foo8(x: B); @@ -186,18 +186,18 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } >x : B >B : B >Date : Date function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T) => any; }): any; } ->x : { new: (x: T) => any; } ->b : { new: (x: T) => any; } +>foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } +>x : { new(x: T): any; } +>b : { new(x: T): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } >x : any function foo12(x: I); @@ -247,18 +247,18 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } >x : I >I : I >Date : Date function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T) => any; }): any; } ->x : { new: (x: T) => any; } ->b : { new: (x: T) => any; } +>foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } +>x : { new(x: T): any; } +>b : { new(x: T): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types index 15239aacf56..683c3ace9f9 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types @@ -68,8 +68,8 @@ var a: { new (x: Z): C; } >B : B var b = { new(x: A) { return x; } }; ->b : { new: (x: A) => A; } ->{ new(x: A) { return x; } } : { new: (x: A) => A; } +>b : { new(x: A): A; } +>{ new(x: A) { return x; } } : { new(x: A): A; } >new : (x: A) => A >A : A >B : B @@ -138,17 +138,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: A) => A; }): any; (x: { new: (x: A) => A; }): any; } ->x : { new: (x: A) => A; } ->b : { new: (x: A) => A; } +>foo4 : { (x: { new(x: A): A; }): any; (x: { new(x: A): A; }): any; } +>x : { new(x: A): A; } +>b : { new(x: A): A; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: A) => A; }): any; (x: { new: (x: A) => A; }): any; } ->x : { new: (x: A) => A; } ->b : { new: (x: A) => A; } +>foo4 : { (x: { new(x: A): A; }): any; (x: { new(x: A): A; }): any; } +>x : { new(x: A): A; } +>b : { new(x: A): A; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: A) => A; }): any; (x: { new: (x: A) => A; }): any; } +>foo4 : { (x: { new(x: A): A; }): any; (x: { new(x: A): A; }): any; } >x : any function foo8(x: B); @@ -196,17 +196,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: A) => A; }): any; } ->x : { new: (x: A) => A; } ->b : { new: (x: A) => A; } +>foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } +>x : { new(x: A): A; } +>b : { new(x: A): A; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } >x : any function foo12(x: I, number, Date, string>); @@ -259,18 +259,18 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } >x : I >I : I >Date : Date >RegExp : RegExp function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: A) => A; }): any; } ->x : { new: (x: A) => A; } ->b : { new: (x: A) => A; } +>foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } +>x : { new(x: A): A; } +>b : { new(x: A): A; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types index 0ef822a5328..af65ca5b911 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types @@ -50,8 +50,8 @@ var a: { new(x: Z): B } >Z : Z var b = { new(x: A) { return new C(x); } }; ->b : { new: (x: A) => C; } ->{ new(x: A) { return new C(x); } } : { new: (x: A) => C; } +>b : { new(x: A): C; } +>{ new(x: A) { return new C(x); } } : { new(x: A): C; } >new : (x: A) => C >A : A >x : A @@ -118,17 +118,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: A) => C; }): any; (x: { new: (x: A) => C; }): any; } ->x : { new: (x: A) => C; } ->b : { new: (x: A) => C; } +>foo4 : { (x: { new(x: A): C; }): any; (x: { new(x: A): C; }): any; } +>x : { new(x: A): C; } +>b : { new(x: A): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: A) => C; }): any; (x: { new: (x: A) => C; }): any; } ->x : { new: (x: A) => C; } ->b : { new: (x: A) => C; } +>foo4 : { (x: { new(x: A): C; }): any; (x: { new(x: A): C; }): any; } +>x : { new(x: A): C; } +>b : { new(x: A): C; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: A) => C; }): any; (x: { new: (x: A) => C; }): any; } +>foo4 : { (x: { new(x: A): C; }): any; (x: { new(x: A): C; }): any; } >x : any function foo8(x: B); @@ -174,17 +174,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: A) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: A) => C; }): any; } ->x : { new: (x: A) => C; } ->b : { new: (x: A) => C; } +>foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } +>x : { new(x: A): C; } +>b : { new(x: A): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: A) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } >x : any function foo12(x: I); @@ -230,16 +230,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: A) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: A) => C; }): any; } ->x : { new: (x: A) => C; } ->b : { new: (x: A) => C; } +>foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } +>x : { new(x: A): C; } +>b : { new(x: A): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: A) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types index a13dbe1bcf4..a6dea7c2518 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types @@ -62,8 +62,8 @@ var a: { new(x: T, y?: T): B } >T : T var b = { new(x: T, y?: T) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new: (x: T, y?: T) => C; } ->{ new(x: T, y?: T) { return new C(x, y); } } : { new: (x: T, y?: T) => C; } +>b : { new(x: T, y?: T): C; } +>{ new(x: T, y?: T) { return new C(x, y); } } : { new(x: T, y?: T): C; } >new : (x: T, y?: T) => C >T : T >x : T @@ -133,17 +133,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T, y?: T) => C; }): any; (x: { new: (x: T, y?: T) => C; }): any; } ->x : { new: (x: T, y?: T) => C; } ->b : { new: (x: T, y?: T) => C; } +>foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: { new(x: T, y?: T): C; }): any; } +>x : { new(x: T, y?: T): C; } +>b : { new(x: T, y?: T): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T, y?: T) => C; }): any; (x: { new: (x: T, y?: T) => C; }): any; } ->x : { new: (x: T, y?: T) => C; } ->b : { new: (x: T, y?: T) => C; } +>foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: { new(x: T, y?: T): C; }): any; } +>x : { new(x: T, y?: T): C; } +>b : { new(x: T, y?: T): C; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T, y?: T) => C; }): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: { new(x: T, y?: T): C; }): any; } >x : any function foo8(x: B): string; @@ -189,17 +189,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T, y?: T) => C; }): any; } ->x : { new: (x: T, y?: T) => C; } ->b : { new: (x: T, y?: T) => C; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } +>x : { new(x: T, y?: T): C; } +>b : { new(x: T, y?: T): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } >x : any function foo12(x: I); @@ -245,16 +245,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T, y?: T) => C; }): any; } ->x : { new: (x: T, y?: T) => C; } ->b : { new: (x: T, y?: T) => C; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } +>x : { new(x: T, y?: T): C; } +>b : { new(x: T, y?: T): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types index dc1429cc9ca..3c0f09e61da 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types @@ -70,8 +70,8 @@ var a: { new(x: T, y?: U): B } >U : U var b = { new(x: T, y?: U) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new: (x: T, y?: U) => C; } ->{ new(x: T, y?: U) { return new C(x, y); } } : { new: (x: T, y?: U) => C; } +>b : { new(x: T, y?: U): C; } +>{ new(x: T, y?: U) { return new C(x, y); } } : { new(x: T, y?: U): C; } >new : (x: T, y?: U) => C >T : T >U : U @@ -143,17 +143,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T, y?: U) => C; }): any; (x: { new: (x: T, y?: U) => C; }): any; } ->x : { new: (x: T, y?: U) => C; } ->b : { new: (x: T, y?: U) => C; } +>foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: { new(x: T, y?: U): C; }): any; } +>x : { new(x: T, y?: U): C; } +>b : { new(x: T, y?: U): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T, y?: U) => C; }): any; (x: { new: (x: T, y?: U) => C; }): any; } ->x : { new: (x: T, y?: U) => C; } ->b : { new: (x: T, y?: U) => C; } +>foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: { new(x: T, y?: U): C; }): any; } +>x : { new(x: T, y?: U): C; } +>b : { new(x: T, y?: U): C; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T, y?: U) => C; }): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: { new(x: T, y?: U): C; }): any; } >x : any function foo8(x: B); @@ -199,17 +199,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T, y?: U) => C; }): any; } ->x : { new: (x: T, y?: U) => C; } ->b : { new: (x: T, y?: U) => C; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } +>x : { new(x: T, y?: U): C; } +>b : { new(x: T, y?: U): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } >x : any function foo12(x: I); @@ -255,16 +255,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T, y?: U) => C; }): any; } ->x : { new: (x: T, y?: U) => C; } ->b : { new: (x: T, y?: U) => C; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } +>x : { new(x: T, y?: U): C; } +>b : { new(x: T, y?: U): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types index 9c8da5a6921..f21ccc15abb 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types @@ -70,8 +70,8 @@ var a: { new (x: T, y?: U): B }; >U : U var b = { new(x: T, y: U) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new: (x: T, y: U) => C; } ->{ new(x: T, y: U) { return new C(x, y); } } : { new: (x: T, y: U) => C; } +>b : { new(x: T, y: U): C; } +>{ new(x: T, y: U) { return new C(x, y); } } : { new(x: T, y: U): C; } >new : (x: T, y: U) => C >T : T >U : U @@ -143,17 +143,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T, y: U) => C; }): any; (x: { new: (x: T, y: U) => C; }): any; } ->x : { new: (x: T, y: U) => C; } ->b : { new: (x: T, y: U) => C; } +>foo4 : { (x: { new(x: T, y: U): C; }): any; (x: { new(x: T, y: U): C; }): any; } +>x : { new(x: T, y: U): C; } +>b : { new(x: T, y: U): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T, y: U) => C; }): any; (x: { new: (x: T, y: U) => C; }): any; } ->x : { new: (x: T, y: U) => C; } ->b : { new: (x: T, y: U) => C; } +>foo4 : { (x: { new(x: T, y: U): C; }): any; (x: { new(x: T, y: U): C; }): any; } +>x : { new(x: T, y: U): C; } +>b : { new(x: T, y: U): C; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T, y: U) => C; }): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo4 : { (x: { new(x: T, y: U): C; }): any; (x: { new(x: T, y: U): C; }): any; } >x : any function foo8(x: B); @@ -199,17 +199,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T, y: U) => C; }): any; } ->x : { new: (x: T, y: U) => C; } ->b : { new: (x: T, y: U) => C; } +>foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } +>x : { new(x: T, y: U): C; } +>b : { new(x: T, y: U): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } >x : any function foo12(x: I); @@ -255,16 +255,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T, y: U) => C; }): any; } ->x : { new: (x: T, y: U) => C; } ->b : { new: (x: T, y: U) => C; } +>foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } +>x : { new(x: T, y: U): C; } +>b : { new(x: T, y: U): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } >x : any diff --git a/tests/baselines/reference/parametersWithNoAnnotationAreAny.types b/tests/baselines/reference/parametersWithNoAnnotationAreAny.types index ee88697a82a..0424a169331 100644 --- a/tests/baselines/reference/parametersWithNoAnnotationAreAny.types +++ b/tests/baselines/reference/parametersWithNoAnnotationAreAny.types @@ -58,8 +58,8 @@ var a: { } var b = { ->b : { foo: (x: any) => any; a: (x: any) => any; b: (x: any) => any; } ->{ foo(x) { return x; }, a: function foo(x) { return x; }, b: (x) => x} : { foo: (x: any) => any; a: (x: any) => any; b: (x: any) => any; } +>b : { foo(x: any): any; a: (x: any) => any; b: (x: any) => any; } +>{ foo(x) { return x; }, a: function foo(x) { return x; }, b: (x) => x} : { foo(x: any): any; a: (x: any) => any; b: (x: any) => any; } foo(x) { >foo : (x: any) => any diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment1.types b/tests/baselines/reference/parserFunctionPropertyAssignment1.types index 9b1bdcd8d9f..1b552cdfefd 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment1.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment1.types @@ -1,6 +1,6 @@ === tests/cases/conformance/parser/ecmascript5/PropertyAssignments/parserFunctionPropertyAssignment1.ts === var v = { foo() { } }; ->v : { foo: () => void; } ->{ foo() { } } : { foo: () => void; } +>v : { foo(): void; } +>{ foo() { } } : { foo(): void; } >foo : () => void diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment2.types b/tests/baselines/reference/parserFunctionPropertyAssignment2.types index ab5dd3fdbaa..747b66978af 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment2.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment2.types @@ -1,5 +1,5 @@ === tests/cases/conformance/parser/ecmascript5/PropertyAssignments/parserFunctionPropertyAssignment2.ts === var v = { 0() { } }; ->v : { 0: () => void; } ->{ 0() { } } : { 0: () => void; } +>v : { 0(): void; } +>{ 0() { } } : { 0(): void; } diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment3.types b/tests/baselines/reference/parserFunctionPropertyAssignment3.types index e245676e5f2..9fb2bb45fef 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment3.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment3.types @@ -1,5 +1,5 @@ === tests/cases/conformance/parser/ecmascript5/PropertyAssignments/parserFunctionPropertyAssignment3.ts === var v = { "foo"() { } }; ->v : { "foo": () => void; } ->{ "foo"() { } } : { "foo": () => void; } +>v : { "foo"(): void; } +>{ "foo"() { } } : { "foo"(): void; } diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment4.types b/tests/baselines/reference/parserFunctionPropertyAssignment4.types index 38fb2aadf70..6ab031518d4 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment4.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment4.types @@ -1,6 +1,6 @@ === tests/cases/conformance/parser/ecmascript5/PropertyAssignments/parserFunctionPropertyAssignment4.ts === var v = { 0() { } }; ->v : { 0: () => void; } ->{ 0() { } } : { 0: () => void; } +>v : { 0(): void; } +>{ 0() { } } : { 0(): void; } >T : T diff --git a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types index 7f5768923c5..4644782c551 100644 --- a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types +++ b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types @@ -1,6 +1,6 @@ === tests/cases/compiler/sourceMapValidationFunctionPropertyAssignment.ts === var x = { n() { } }; ->x : { n: () => void; } ->{ n() { } } : { n: () => void; } +>x : { n(): void; } +>{ n() { } } : { n(): void; } >n : () => void diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index e4e8de59185..bdb122f6108 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -24,7 +24,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. Index signatures are incompatible. Type 'string | number | MyString | (() => void)' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -160,7 +160,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: string; } = { ~ -!!! error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }'. +!!! error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'string | number | MyString | (() => void)' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. diff --git a/tests/baselines/reference/thisInObjectLiterals.types b/tests/baselines/reference/thisInObjectLiterals.types index f0e54ef52ee..d3853389a9e 100644 --- a/tests/baselines/reference/thisInObjectLiterals.types +++ b/tests/baselines/reference/thisInObjectLiterals.types @@ -29,8 +29,8 @@ class MyClass { //type of 'this' in an object literal property of a function type is Any var obj = { ->obj : { f: () => any; } ->{ f() { return this.spaaace; }} : { f: () => any; } +>obj : { f(): any; } +>{ f() { return this.spaaace; }} : { f(): any; } f() { >f : () => any @@ -42,6 +42,6 @@ var obj = { } }; var obj: { f: () => any; }; ->obj : { f: () => any; } +>obj : { f(): any; } >f : () => any diff --git a/tests/baselines/reference/throwInEnclosingStatements.types b/tests/baselines/reference/throwInEnclosingStatements.types index 52a49aadf37..dc5b8fb76a5 100644 --- a/tests/baselines/reference/throwInEnclosingStatements.types +++ b/tests/baselines/reference/throwInEnclosingStatements.types @@ -83,8 +83,8 @@ class C { } var aa = { ->aa : { id: number; biz: () => void; } ->{ id:12, biz() { throw this; }} : { id: number; biz: () => void; } +>aa : { id: number; biz(): void; } +>{ id:12, biz() { throw this; }} : { id: number; biz(): void; } id:12, >id : number diff --git a/tests/baselines/reference/typeGuardsObjectMethods.types b/tests/baselines/reference/typeGuardsObjectMethods.types index ad8c9237760..ecb4b8083ea 100644 --- a/tests/baselines/reference/typeGuardsObjectMethods.types +++ b/tests/baselines/reference/typeGuardsObjectMethods.types @@ -14,8 +14,8 @@ var var1: string | number; >var1 : string | number var obj1 = { ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } ->{ // Inside method method(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string return strOrNum; }, get prop() { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string return strOrNum; }, set prop(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string }} : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } +>{ // Inside method method(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string return strOrNum; }, get prop() { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string return strOrNum; }, set prop(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string }} : { method(param: string | number): string | number; prop: string | number; } // Inside method method(param: string | number) { @@ -152,12 +152,12 @@ strOrNum = typeof obj1.method(strOrNum) === "string" && obj1.method(strOrNum); >typeof obj1.method(strOrNum) : string >obj1.method(strOrNum) : string | number >obj1.method : (param: string | number) => string | number ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } >method : (param: string | number) => string | number >strOrNum : string | number >obj1.method(strOrNum) : string | number >obj1.method : (param: string | number) => string | number ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } >method : (param: string | number) => string | number >strOrNum : string | number @@ -169,9 +169,9 @@ strOrNum = typeof obj1.prop === "string" && obj1.prop; >typeof obj1.prop === "string" : boolean >typeof obj1.prop : string >obj1.prop : string | number ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } >prop : string | number >obj1.prop : string | number ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } >prop : string | number From d7c32a421b0b1095349bd1f4834f0eef80baa475 Mon Sep 17 00:00:00 2001 From: Arnavion Date: Wed, 3 Dec 2014 12:08:29 -0800 Subject: [PATCH 34/39] Remove BOM from es6.d.ts Fixes #1354 --- src/lib/es6.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index 0940f26cac5..5706924e8e3 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -1,4 +1,4 @@ -declare type PropertyKey = string | number | Symbol; +declare type PropertyKey = string | number | Symbol; interface Symbol { /** Returns a string representation of an object. */ From c4f4e787cfc84c28e5e1448f84c2f085ba510cee Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 3 Dec 2014 12:41:32 -0800 Subject: [PATCH 35/39] Add test cases for external module reference of the alias --- .../quickInfoDisplayPartsExternalModuleAlias.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts b/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts index a9e0be3fa02..2c43326469c 100644 --- a/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts @@ -7,9 +7,9 @@ ////} // @Filename: quickInfoDisplayPartsExternalModuleAlias_file1.ts -////import /*1*/a1 = require("quickInfoDisplayPartsExternalModuleAlias_file0"); +////import /*1*/a1 = require(/*mod1*/"quickInfoDisplayPartsExternalModuleAlias_file0"); ////new /*2*/a1.m1.c(); -////export import /*3*/a2 = require("quickInfoDisplayPartsExternalModuleAlias_file0"); +////export import /*3*/a2 = require(/*mod2*/"quickInfoDisplayPartsExternalModuleAlias_file0"); ////new /*4*/a2.m1.c(); var marker = 0; @@ -31,4 +31,14 @@ function verifyImport(name: string, isExported: boolean) { verifyImport("a1", /*isExported*/false); verifyImport("a1", /*isExported*/false); verifyImport("a2", /*isExported*/true); -verifyImport("a2", /*isExported*/true); \ No newline at end of file +verifyImport("a2", /*isExported*/true); + +function verifyExternalModuleStringLiteral(marker: string) { + goTo.marker(marker); + verify.verifyQuickInfoDisplayParts("module", "", { start: test.markerByName(marker).position, length: "\"quickInfoDisplayPartsExternalModuleAlias_file0\"".length }, + [{ text: "module", kind: "keyword" }, { text: " ", kind: "space" }, { text: "a1", kind: "aliasName" }], + []); +} + +verifyExternalModuleStringLiteral("mod1"); +verifyExternalModuleStringLiteral("mod2"); \ No newline at end of file From 22d7aed980c54e31ea7c3d5c604c7df51b5457d0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Dec 2014 15:08:12 -0800 Subject: [PATCH 36/39] CR feedback. --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 28 ++++++++++++++-------------- src/compiler/emitter.ts | 5 ++--- src/compiler/parser.ts | 28 ++++++++++++++-------------- src/compiler/types.ts | 29 ++++++++++++++++++++--------- src/services/breakpoints.ts | 12 ++++++------ src/services/services.ts | 8 ++++---- 7 files changed, 61 insertions(+), 51 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 1aa32c68b6a..7acb99d624d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -397,7 +397,7 @@ module ts { } break; case SyntaxKind.Property: - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); break; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2b205aaca60..3aefe76746d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1697,7 +1697,7 @@ module ts { if (declaration.initializer) { var type = checkAndMarkExpression(declaration.initializer); // Widening of property assignments is handled by checkObjectLiteral, exclude them here - if (declaration.kind !== SyntaxKind.LonghandPropertyAssignment) { + if (declaration.kind !== SyntaxKind.PropertyAssignment) { var unwidenedType = type; type = getWidenedType(type); if (type !== unwidenedType) { @@ -3244,7 +3244,7 @@ module ts { // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. - function isContextSensitiveCore(node: Expression | MethodDeclaration | PropertyAssignment): boolean { + function isContextSensitiveCore(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean { Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); switch (node.kind) { case SyntaxKind.FunctionExpression: @@ -3260,8 +3260,8 @@ module ts { case SyntaxKind.BinaryExpression: return (node).operator === SyntaxKind.BarBarToken && (isContextSensitiveCore((node).left) || isContextSensitiveCore((node).right)); - case SyntaxKind.LonghandPropertyAssignment: - return isContextSensitiveCore((node).initializer); + case SyntaxKind.PropertyAssignment: + return isContextSensitiveCore((node).initializer); case SyntaxKind.Method: return isContextSensitiveFunctionLikeDeclaration(node); } @@ -4913,14 +4913,14 @@ module ts { return node.contextualType; } - return getContextualTypeForPropertyAssignment(node); + return getContextualTypeForObjectLiteralElement(node); } - function getContextualTypeForPropertyAssignment(propertyAssignment: PropertyAssignment) { - var objectLiteral = propertyAssignment.parent; + function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElement) { + var objectLiteral = element.parent; var type = getContextualType(objectLiteral); // TODO(jfreeman): Handle this case for computed names and symbols - var name = (propertyAssignment.name).text; + var name = (element.name).text; if (type && name) { return getTypeOfPropertyOfContextualType(type, name) || isNumericName(name) && getIndexTypeOfContextualType(type, IndexKind.Number) || @@ -4974,8 +4974,8 @@ module ts { return getTypeFromTypeNode((parent).type); case SyntaxKind.BinaryExpression: return getContextualTypeForBinaryOperand(node); - case SyntaxKind.LonghandPropertyAssignment: - return getContextualTypeForPropertyAssignment(parent); + case SyntaxKind.PropertyAssignment: + return getContextualTypeForObjectLiteralElement(parent); case SyntaxKind.ArrayLiteralExpression: return getContextualTypeForElementExpression(node); case SyntaxKind.ConditionalExpression: @@ -5111,10 +5111,10 @@ module ts { if (hasProperty(members, id)) { var member = members[id]; if (member.flags & SymbolFlags.Property || isObjectLiteralMethod(member.declarations[0])) { - var memberDecl = member.declarations[0]; + var memberDecl = member.declarations[0]; var type: Type; - if (memberDecl.kind === SyntaxKind.LonghandPropertyAssignment) { - type = checkExpression((memberDecl).initializer, contextualMapper); + if (memberDecl.kind === SyntaxKind.PropertyAssignment) { + type = checkExpression((memberDecl).initializer, contextualMapper); } else if (memberDecl.kind === SyntaxKind.Method) { type = checkObjectLiteralMethod(memberDecl, contextualMapper); @@ -8633,7 +8633,7 @@ module ts { case SyntaxKind.Property: case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: case SyntaxKind.CallExpression: diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9fccef4d6bf..03951f08b4c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2122,7 +2122,7 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: @@ -3549,7 +3549,7 @@ module ts { return emitArrayLiteral(node); case SyntaxKind.ObjectLiteralExpression: return emitObjectLiteral(node); - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: return emitPropertyAssignment(node); case SyntaxKind.ComputedPropertyName: return emitComputedPropertyName(node); @@ -3590,7 +3590,6 @@ module ts { case SyntaxKind.Block: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: - case SyntaxKind.Block: case SyntaxKind.ModuleBlock: return emitBlock(node); case SyntaxKind.VariableStatement: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1d7a8e2be44..bc2bb211959 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -223,7 +223,7 @@ module ts { child((node).type) || child((node).initializer); case SyntaxKind.Property: - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: return children(node.modifiers) || child((node).name) || @@ -589,7 +589,7 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.Property: case SyntaxKind.EnumMember: - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: return (parent).initializer === node; case SyntaxKind.ExpressionStatement: case SyntaxKind.IfStatement: @@ -647,7 +647,7 @@ module ts { case SyntaxKind.Method: return (node).questionToken !== undefined; case SyntaxKind.ShorthandPropertyAssignment: - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: case SyntaxKind.Property: return (node).questionToken !== undefined; } @@ -686,7 +686,7 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: @@ -3166,7 +3166,7 @@ module ts { return finishNode(node); } - function parsePropertyAssignment(): PropertyAssignment { + function parseObjectLiteralElement(): ObjectLiteralElement { var fullStart = scanner.getStartPos(); var initialToken = token; @@ -3194,12 +3194,12 @@ module ts { return finishNode(shorthandDeclaration); } else { - var longhandDeclaration = createNode(SyntaxKind.LonghandPropertyAssignment, fullStart); - longhandDeclaration.name = propertyName; - longhandDeclaration.questionToken = questionToken; + var propertyAssignment = createNode(SyntaxKind.PropertyAssignment, fullStart); + propertyAssignment.name = propertyName; + propertyAssignment.questionToken = questionToken; parseExpected(SyntaxKind.ColonToken); - longhandDeclaration.initializer = allowInAnd(parseAssignmentExpressionOrHigher); - return finishNode(longhandDeclaration); + propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher); + return finishNode(propertyAssignment); } } @@ -3210,7 +3210,7 @@ module ts { node.flags |= NodeFlags.MultiLine; } - node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parsePropertyAssignment); + node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement); parseExpected(SyntaxKind.CloseBraceToken); return finishNode(node); } @@ -4413,7 +4413,7 @@ module ts { case SyntaxKind.IndexSignature: return checkIndexSignature(node); case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(node); case SyntaxKind.LabeledStatement: return checkLabeledStatement(node); - case SyntaxKind.LonghandPropertyAssignment: return checkLonghandPropertyAssignment(node); + case SyntaxKind.PropertyAssignment: return checkPropertyAssignment(node); case SyntaxKind.Method: return checkMethod(node); case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(node); case SyntaxKind.ObjectLiteralExpression: return checkObjectLiteralExpression(node); @@ -5039,7 +5039,7 @@ module ts { // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields var currentKind: number; - if (prop.kind === SyntaxKind.LonghandPropertyAssignment || + if (prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment || prop.kind === SyntaxKind.Method) { currentKind = Property; @@ -5342,7 +5342,7 @@ module ts { } } - function checkLonghandPropertyAssignment(node: LonghandPropertyAssignment) { + function checkPropertyAssignment(node: PropertyAssignment) { return checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d887082ab38..4fa7d9421c4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -231,7 +231,7 @@ module ts { CatchClause, // Property assignments - LonghandPropertyAssignment, + PropertyAssignment, ShorthandPropertyAssignment, // Enum @@ -383,17 +383,17 @@ module ts { export type VariableOrParameterDeclaration = VariableDeclaration | ParameterDeclaration; export type VariableOrParameterOrPropertyDeclaration = VariableOrParameterDeclaration | PropertyDeclaration; - export interface PropertyAssignment extends Declaration { - _propertyAssignmentBrand: any; + export interface ObjectLiteralElement extends Declaration { + _objectLiteralBrandBrand: any; } - export interface ShorthandPropertyAssignment extends PropertyAssignment { + export interface ShorthandPropertyAssignment extends ObjectLiteralElement { name: Identifier; questionToken?: Node; } - export interface LonghandPropertyAssignment extends PropertyAssignment { - _longhandPropertyAssignmentBrand: any; + export interface PropertyAssignment extends ObjectLiteralElement { + _propertyAssignmentBrand: any; name: DeclarationName; questionToken?: Node; initializer: Expression; @@ -420,7 +420,16 @@ module ts { body?: Block; } - export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, PropertyAssignment { + // Note that a MethodDeclaration is considered both a ClassElement and an ObjectLiteralElement. + // Both the grammars for ClassDeclaration and ObjectLiteralExpression allow for MethodDeclarations + // as child elements, and so a MethodDeclaration satisfies both interfaces. This avoids the + // alternative where we would need separate kinds/types for ClassMethodDeclaration and + // ObjectLiteralMethodDeclaration, which would look identical. + // + // Because of this, it may be necessary to determine what sort of MethodDeclaration you have + // at later stages of the compiler pipeline. In that case, you can either check the parent kind + // of the method, or use helpers like isObjectLiteralMethodDeclaration + export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution body?: Block; @@ -430,7 +439,9 @@ module ts { body?: Block; } - export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, PropertyAssignment { + // See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a + // ClassElement and an ObjectLiteralElement. + export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { _accessorDeclarationBrand: any; body: Block; } @@ -587,7 +598,7 @@ module ts { // An ObjectLiteralExpression is the declaration node for an anonymous symbol. export interface ObjectLiteralExpression extends PrimaryExpression, Declaration { - properties: NodeArray; + properties: NodeArray; } export interface PropertyAccessExpression extends MemberExpression { diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 6bfeb1dc2a6..260fa5892aa 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -102,10 +102,10 @@ module ts.BreakpointResolver { return spanInFunctionDeclaration(node); case SyntaxKind.Block: - return isFunctionBlock(node) - ? spanInFunctionBlock(node) - : spanInBlock(node); - + if (isFunctionBlock(node)) { + return spanInFunctionBlock(node); + } + // Fall through case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: case SyntaxKind.ModuleBlock: @@ -240,7 +240,7 @@ module ts.BreakpointResolver { default: // If this is name of property assignment, set breakpoint in the initializer - if (node.parent.kind === SyntaxKind.LonghandPropertyAssignment && (node.parent).name === node) { + if (node.parent.kind === SyntaxKind.PropertyAssignment && (node.parent).name === node) { return spanInNode((node.parent).initializer); } @@ -483,7 +483,7 @@ module ts.BreakpointResolver { function spanInColonToken(node: Node): TextSpan { // Is this : specifying return annotation of the function declaration - if (isAnyFunction(node.parent) || node.parent.kind === SyntaxKind.LonghandPropertyAssignment) { + if (isAnyFunction(node.parent) || node.parent.kind === SyntaxKind.PropertyAssignment) { return spanInPreviousNode(node); } diff --git a/src/services/services.ts b/src/services/services.ts index 36d502bb47f..d233cf70ff9 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1973,14 +1973,14 @@ module ts { /** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */ function isNameOfPropertyAssignment(node: Node): boolean { return (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) && - (node.parent.kind === SyntaxKind.LonghandPropertyAssignment || node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) && (node.parent).name === node; + (node.parent.kind === SyntaxKind.PropertyAssignment || node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) && (node.parent).name === node; } function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean { if (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) { switch (node.parent.kind) { case SyntaxKind.Property: - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: case SyntaxKind.GetAccessor: @@ -2647,7 +2647,7 @@ module ts { var existingMemberNames: Map = {}; forEach(existingMembers, m => { - if (m.kind !== SyntaxKind.LonghandPropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) { + if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) { // Ignore omitted expressions for missing members in the object literal return; } @@ -4717,7 +4717,7 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: case SyntaxKind.Property: - case SyntaxKind.LonghandPropertyAssignment: + case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: case SyntaxKind.Method: From 158cf62206fb6d3c8b8fea7b7b8c408fdf421e4f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Dec 2014 15:36:39 -0800 Subject: [PATCH 37/39] More CR feedback. --- src/compiler/checker.ts | 3 --- src/compiler/parser.ts | 4 ++-- src/compiler/types.ts | 2 -- src/services/syntax/parser.ts | 2 +- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3aefe76746d..50eb3669655 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4909,9 +4909,6 @@ module ts { // We cannot answer semantic questions within a with block, do not proceed any further return undefined; } - if (node.contextualType) { - return node.contextualType; - } return getContextualTypeForObjectLiteralElement(node); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index bc2bb211959..58c715d721f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -471,11 +471,11 @@ module ts { } export function isFunctionBlock(node: Node) { - return node && node.kind === SyntaxKind.Block && isAnyFunction(node.parent); + return node !== undefined && node.kind === SyntaxKind.Block && isAnyFunction(node.parent); } export function isObjectLiteralMethod(node: Node) { - return node && node.kind === SyntaxKind.Method && node.parent.kind === SyntaxKind.ObjectLiteralExpression; + return node !== undefined && node.kind === SyntaxKind.Method && node.parent.kind === SyntaxKind.ObjectLiteralExpression; } export function getContainingFunction(node: Node): FunctionLikeDeclaration { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4fa7d9421c4..ab396d13a85 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -430,8 +430,6 @@ module ts { // at later stages of the compiler pipeline. In that case, you can either check the parent kind // of the method, or use helpers like isObjectLiteralMethodDeclaration export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { - contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution - body?: Block; } diff --git a/src/services/syntax/parser.ts b/src/services/syntax/parser.ts index be71c720de2..8aeafd29720 100644 --- a/src/services/syntax/parser.ts +++ b/src/services/syntax/parser.ts @@ -3444,7 +3444,7 @@ module TypeScript.Parser { parseArrowFunctionBody(/*asyncContext:*/ !!asyncKeyword)); } - function isFunctionBlock(): boolean { + function isStartOfFunctionBlock(): boolean { var currentTokenKind = currentToken().kind; return currentTokenKind === SyntaxKind.OpenBraceToken || currentTokenKind === SyntaxKind.EqualsGreaterThanToken; } From 1c4b8d9c850519131f79fcd5ae1d341f9157ec52 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Dec 2014 15:55:29 -0800 Subject: [PATCH 38/39] Improve names for functions in the checker. --- src/compiler/checker.ts | 79 ++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 50eb3669655..6473818379e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3238,30 +3238,26 @@ module ts { return type; } - function isContextSensitiveExpression(node: Expression): boolean { - return isContextSensitiveCore(node); - } - // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. - function isContextSensitiveCore(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean { + function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean { Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: return isContextSensitiveFunctionLikeDeclaration(node); case SyntaxKind.ObjectLiteralExpression: - return forEach((node).properties, isContextSensitiveCore); + return forEach((node).properties, isContextSensitive); case SyntaxKind.ArrayLiteralExpression: - return forEach((node).elements, isContextSensitiveCore); + return forEach((node).elements, isContextSensitive); case SyntaxKind.ConditionalExpression: - return isContextSensitiveCore((node).whenTrue) || - isContextSensitiveCore((node).whenFalse); + return isContextSensitive((node).whenTrue) || + isContextSensitive((node).whenFalse); case SyntaxKind.BinaryExpression: return (node).operator === SyntaxKind.BarBarToken && - (isContextSensitiveCore((node).left) || isContextSensitiveCore((node).right)); + (isContextSensitive((node).left) || isContextSensitive((node).right)); case SyntaxKind.PropertyAssignment: - return isContextSensitiveCore((node).initializer); + return isContextSensitive((node).initializer); case SyntaxKind.Method: return isContextSensitiveFunctionLikeDeclaration(node); } @@ -3270,7 +3266,7 @@ module ts { } function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration) { - return !(node).typeParameters && !forEach((node).parameters, p => p.type); + return !node.typeParameters && !forEach(node.parameters, p => p.type); } function getTypeWithoutConstructors(type: Type): Type { @@ -4763,7 +4759,7 @@ module ts { function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type { if (isFunctionExpressionOrArrowFunction(parameter.parent)) { var func = parameter.parent; - if (isContextSensitiveExpression(func)) { + if (isContextSensitive(func)) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { @@ -5632,7 +5628,7 @@ module ts { // because it represents a TemplateStringsArray. var excludeArgument: boolean[]; for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { - if (isContextSensitiveExpression(args[i])) { + if (isContextSensitive(args[i])) { if (!excludeArgument) { excludeArgument = new Array(args.length); } @@ -6183,7 +6179,7 @@ module ts { links.flags |= NodeCheckFlags.ContextChecked; if (contextualSignature) { var signature = getSignaturesOfType(type, SignatureKind.Call)[0]; - if (isContextSensitiveCore(node)) { + if (isContextSensitive(node)) { assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper); } if (!node.type) { @@ -6589,16 +6585,30 @@ module ts { return result; } - function checkExpressionOrQualifiedName(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type { - return checkExpressionCore(node, contextualMapper); + function checkObjectLiteralMethod(node: MethodDeclaration, contextualMapper?: TypeMapper): Type { + var type = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); + return mapSingleCallSignatureToType(node, type, contextualMapper); + } + + function mapSingleCallSignatureToType(node: Expression | QualifiedName | MethodDeclaration, type: Type, contextualMapper?: TypeMapper) { + if (contextualMapper && contextualMapper !== identityMapper && node.kind !== SyntaxKind.QualifiedName) { + var signature = getSingleCallSignature(type); + if (signature && signature.typeParameters) { + var contextualType = getContextualType(node); + if (contextualType) { + var contextualSignature = getSingleCallSignature(contextualType); + if (contextualSignature && !contextualSignature.typeParameters) { + return getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); + } + } + } + } + + return type; } function checkExpression(node: Expression, contextualMapper?: TypeMapper): Type { - return checkExpressionCore(node, contextualMapper); - } - - function checkObjectLiteralMethod(node: MethodDeclaration, contextualMapper?: TypeMapper): Type { - return checkExpressionCore(node, contextualMapper); + return checkExpressionOrQualifiedName(node, contextualMapper); } // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When @@ -6608,20 +6618,11 @@ module ts { // object, it serves as an indicator that all contained function and arrow expressions should be considered to // have the wildcard function type; this form of type check is used during overload resolution to exclude // contextually typed function and arrow expressions in the initial phase. - function checkExpressionCore(node: Expression | QualifiedName | MethodDeclaration, contextualMapper?: TypeMapper): Type { - var type = checkExpressionOrQualifiedNameOrObjectLiteralMethodNode(node, contextualMapper); - if (contextualMapper && contextualMapper !== identityMapper && node.kind !== SyntaxKind.QualifiedName) { - var signature = getSingleCallSignature(type); - if (signature && signature.typeParameters) { - var contextualType = getContextualType(node); - if (contextualType) { - var contextualSignature = getSingleCallSignature(contextualType); - if (contextualSignature && !contextualSignature.typeParameters) { - type = getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); - } - } - } - } + function checkExpressionOrQualifiedName(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type { + var type = node.kind == SyntaxKind.QualifiedName + ? checkQualifiedName(node) + : checkExpressionWorker(node, contextualMapper); + type = mapSingleCallSignatureToType(node, type, contextualMapper); if (isConstEnumObjectType(type)) { // enum object type for const enums are only permitted in: @@ -6640,7 +6641,7 @@ module ts { return type; } - function checkExpressionOrQualifiedNameOrObjectLiteralMethodNode(node: Expression | QualifiedName | MethodDeclaration, contextualMapper: TypeMapper): Type { + function checkExpressionWorker(node: Expression, contextualMapper: TypeMapper): Type { switch (node.kind) { case SyntaxKind.Identifier: return checkIdentifier(node); @@ -6662,8 +6663,6 @@ module ts { return stringType; case SyntaxKind.RegularExpressionLiteral: return globalRegExpType; - case SyntaxKind.QualifiedName: - return checkQualifiedName(node); case SyntaxKind.ArrayLiteralExpression: return checkArrayLiteral(node, contextualMapper); case SyntaxKind.ObjectLiteralExpression: @@ -6681,8 +6680,6 @@ module ts { return checkTypeAssertion(node); case SyntaxKind.ParenthesizedExpression: return checkExpression((node).expression); - case SyntaxKind.Method: - return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); From 9a1ec50456996c06af0cbb7cd72d0ca180f27417 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Dec 2014 17:38:55 -0800 Subject: [PATCH 39/39] Improve naming of checker methods. --- src/compiler/checker.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6473818379e..fc67faa8f88 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6586,12 +6586,12 @@ module ts { } function checkObjectLiteralMethod(node: MethodDeclaration, contextualMapper?: TypeMapper): Type { - var type = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); - return mapSingleCallSignatureToType(node, type, contextualMapper); + var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); + return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } - function mapSingleCallSignatureToType(node: Expression | QualifiedName | MethodDeclaration, type: Type, contextualMapper?: TypeMapper) { - if (contextualMapper && contextualMapper !== identityMapper && node.kind !== SyntaxKind.QualifiedName) { + function instantiateTypeWithSingleGenericCallSignature(node: Expression | MethodDeclaration, type: Type, contextualMapper?: TypeMapper) { + if (contextualMapper && contextualMapper !== identityMapper) { var signature = getSingleCallSignature(type); if (signature && signature.typeParameters) { var contextualType = getContextualType(node); @@ -6619,10 +6619,14 @@ module ts { // have the wildcard function type; this form of type check is used during overload resolution to exclude // contextually typed function and arrow expressions in the initial phase. function checkExpressionOrQualifiedName(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type { - var type = node.kind == SyntaxKind.QualifiedName - ? checkQualifiedName(node) - : checkExpressionWorker(node, contextualMapper); - type = mapSingleCallSignatureToType(node, type, contextualMapper); + var type: Type; + if (node.kind == SyntaxKind.QualifiedName) { + type = checkQualifiedName(node); + } + else { + var uninstantiatedType = checkExpressionWorker(node, contextualMapper); + type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); + } if (isConstEnumObjectType(type)) { // enum object type for const enums are only permitted in: