Merge pull request #2413 from Microsoft/constAntlyAPainForUs

Fix getOccurrences for 'const' modifier with exported & ambient declarations
This commit is contained in:
Daniel Rosenwasser 2015-03-18 16:08:34 -07:00
commit d06f71ef9c
6 changed files with 59 additions and 15 deletions

View File

@ -4024,18 +4024,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;
}
@ -4076,7 +4076,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));
@ -5856,17 +5856,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)) {

View File

@ -471,6 +471,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") {

View File

@ -0,0 +1,16 @@
/// <reference path='fourslash.ts' />
////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);
});

View File

@ -0,0 +1,16 @@
/// <reference path='fourslash.ts' />
////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);
});

View File

@ -0,0 +1,12 @@
/// <reference path='fourslash.ts' />
////export const class C {
//// private static c/*1*/onst foo;
//// constructor(public con/*2*/st foo) {
//// }
////}
goTo.marker("1");
verify.occurrencesAtPositionCount(1);
goTo.marker("2");
verify.occurrencesAtPositionCount(0);