mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Merge pull request #2413 from Microsoft/constAntlyAPainForUs
Fix getOccurrences for 'const' modifier with exported & ambient declarations
This commit is contained in:
commit
d06f71ef9c
@ -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)) {
|
||||
|
||||
@ -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") {
|
||||
|
||||
16
tests/cases/fourslash/getOccurrencesConst02.ts
Normal file
16
tests/cases/fourslash/getOccurrencesConst02.ts
Normal 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);
|
||||
});
|
||||
16
tests/cases/fourslash/getOccurrencesConst03.ts
Normal file
16
tests/cases/fourslash/getOccurrencesConst03.ts
Normal 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);
|
||||
});
|
||||
12
tests/cases/fourslash/getOccurrencesConst04.ts
Normal file
12
tests/cases/fourslash/getOccurrencesConst04.ts
Normal 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);
|
||||
Loading…
x
Reference in New Issue
Block a user