From ce3a91c186bafd8ad898693a2a720e42dd343203 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 13:55:09 -0700 Subject: [PATCH 1/3] Added tests for const modifiers. --- ...urrencesConst.ts => getOccurrencesConst01.ts} | 0 tests/cases/fourslash/getOccurrencesConst02.ts | 16 ++++++++++++++++ tests/cases/fourslash/getOccurrencesConst03.ts | 16 ++++++++++++++++ tests/cases/fourslash/getOccurrencesConst04.ts | 12 ++++++++++++ 4 files changed, 44 insertions(+) rename tests/cases/fourslash/{getOccurrencesConst.ts => getOccurrencesConst01.ts} (100%) create mode 100644 tests/cases/fourslash/getOccurrencesConst02.ts create mode 100644 tests/cases/fourslash/getOccurrencesConst03.ts create mode 100644 tests/cases/fourslash/getOccurrencesConst04.ts diff --git a/tests/cases/fourslash/getOccurrencesConst.ts b/tests/cases/fourslash/getOccurrencesConst01.ts similarity index 100% rename from tests/cases/fourslash/getOccurrencesConst.ts rename to tests/cases/fourslash/getOccurrencesConst01.ts diff --git a/tests/cases/fourslash/getOccurrencesConst02.ts b/tests/cases/fourslash/getOccurrencesConst02.ts new file mode 100644 index 00000000000..0dc96fcca6c --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesConst02.ts @@ -0,0 +1,16 @@ +/// + +////module m { +//// declare [|const|] x; +//// declare [|const|] enum E { +//// } +////} +//// +////declare [|const|] x; +////declare [|const|] enum E { +////} + +test.ranges().forEach(range => { + goTo.position(range.start); + verify.occurrencesAtPositionCount(0); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/getOccurrencesConst03.ts b/tests/cases/fourslash/getOccurrencesConst03.ts new file mode 100644 index 00000000000..404ff655044 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesConst03.ts @@ -0,0 +1,16 @@ +/// + +////module m { +//// export [|const|] x; +//// export [|const|] enum E { +//// } +////} +//// +////export [|const|] x; +////export [|const|] enum E { +////} + +test.ranges().forEach(range => { + goTo.position(range.start); + verify.occurrencesAtPositionCount(0); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/getOccurrencesConst04.ts b/tests/cases/fourslash/getOccurrencesConst04.ts new file mode 100644 index 00000000000..6e4d4d6112c --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesConst04.ts @@ -0,0 +1,12 @@ +/// + +////export const class C { +//// private static [|const|] foo; +//// constructor(public [|const|] foo) { +//// } +////} + +test.ranges().forEach(range => { + goTo.position(range.start); + verify.occurrencesAtPositionCount(0); +}); \ No newline at end of file From 9a507fa5bf97fb0b3f36a224937e7fa170456a06 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:06:58 -0700 Subject: [PATCH 2/3] Fixed test. --- tests/cases/fourslash/getOccurrencesConst04.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/cases/fourslash/getOccurrencesConst04.ts b/tests/cases/fourslash/getOccurrencesConst04.ts index 6e4d4d6112c..c7f293450d3 100644 --- a/tests/cases/fourslash/getOccurrencesConst04.ts +++ b/tests/cases/fourslash/getOccurrencesConst04.ts @@ -1,12 +1,12 @@ /// ////export const class C { -//// private static [|const|] foo; -//// constructor(public [|const|] foo) { +//// private static c/*1*/onst foo; +//// constructor(public con/*2*/st foo) { //// } ////} -test.ranges().forEach(range => { - goTo.position(range.start); - verify.occurrencesAtPositionCount(0); -}); \ No newline at end of file +goTo.marker("1"); +verify.occurrencesAtPositionCount(1); +goTo.marker("2"); +verify.occurrencesAtPositionCount(0); \ No newline at end of file From 5cbf667d787a18c09e762c2dbc77eb7e042ae6cd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:07:42 -0700 Subject: [PATCH 3/3] Fixed the contextual check for modifiers to check the original modifier instead of the flags of the node. --- src/services/services.ts | 19 ++++--------------- src/services/utilities.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 1bf5f6336d4..dbddcc939a1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4011,18 +4011,18 @@ module ts { let container = declaration.parent; // Make sure we only highlight the keyword when it makes sense to do so. - if (declaration.flags & NodeFlags.AccessibilityModifier) { + if (isAccessibilityModifier(modifier)) { if (!(container.kind === SyntaxKind.ClassDeclaration || (declaration.kind === SyntaxKind.Parameter && hasKind(container, SyntaxKind.Constructor)))) { return undefined; } } - else if (declaration.flags & NodeFlags.Static) { + else if (modifier === SyntaxKind.StaticKeyword) { if (container.kind !== SyntaxKind.ClassDeclaration) { return undefined; } } - else if (declaration.flags & (NodeFlags.Export | NodeFlags.Ambient)) { + else if (modifier === SyntaxKind.ExportKeyword || modifier === SyntaxKind.DeclareKeyword) { if (!(container.kind === SyntaxKind.ModuleBlock || container.kind === SyntaxKind.SourceFile)) { return undefined; } @@ -4063,7 +4063,7 @@ module ts { default: Debug.fail("Invalid container kind.") } - + forEach(nodes, node => { if (node.modifiers && node.flags & modifierFlag) { forEach(node.modifiers, child => pushKeywordIf(keywords, child, modifier)); @@ -5843,17 +5843,6 @@ module ts { // a string literal, and a template end consisting of '} } `'. let templateStack: SyntaxKind[] = []; - function isAccessibilityModifier(kind: SyntaxKind) { - switch (kind) { - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - return true; - } - - return false; - } - /** Returns true if 'keyword2' can legally follow 'keyword1' in any language construct. */ function canFollow(keyword1: SyntaxKind, keyword2: SyntaxKind) { if (isAccessibilityModifier(keyword1)) { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 7671ee3f88d..6f7957cb4ea 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -320,6 +320,17 @@ module ts { && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); } + export function isAccessibilityModifier(kind: SyntaxKind) { + switch (kind) { + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + return true; + } + + return false; + } + export function compareDataObjects(dst: any, src: any): boolean { for (let e in dst) { if (typeof dst[e] === "object") {