From 2b2ebf596045b04b77b97f578bd84a9788abcee7 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 13 Oct 2014 15:01:31 -0700 Subject: [PATCH] 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