Skip to content

Commit c27b379

Browse files
Merge pull request #3860 from DickvdBrink/fix-occurrences-in-classexpression
Fix occurrences in classexpressions
2 parents 742b2ad + 46292a2 commit c27b379

5 files changed

+111
-3
lines changed

src/services/services.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4682,12 +4682,13 @@ namespace ts {
46824682
// Make sure we only highlight the keyword when it makes sense to do so.
46834683
if (isAccessibilityModifier(modifier)) {
46844684
if (!(container.kind === SyntaxKind.ClassDeclaration ||
4685+
container.kind === SyntaxKind.ClassExpression ||
46854686
(declaration.kind === SyntaxKind.Parameter && hasKind(container, SyntaxKind.Constructor)))) {
46864687
return undefined;
46874688
}
46884689
}
46894690
else if (modifier === SyntaxKind.StaticKeyword) {
4690-
if (container.kind !== SyntaxKind.ClassDeclaration) {
4691+
if (!(container.kind === SyntaxKind.ClassDeclaration || container.kind === SyntaxKind.ClassExpression)) {
46914692
return undefined;
46924693
}
46934694
}
@@ -4726,12 +4727,13 @@ namespace ts {
47264727
(<ClassDeclaration>container.parent).members);
47274728
break;
47284729
case SyntaxKind.ClassDeclaration:
4729-
nodes = (<ClassDeclaration>container).members;
4730+
case SyntaxKind.ClassExpression:
4731+
nodes = (<ClassLikeDeclaration>container).members;
47304732

47314733
// If we're an accessibility modifier, we're in an instance member and should search
47324734
// the constructor's parameter list for instance members as well.
47334735
if (modifierFlag & NodeFlags.AccessibilityModifier) {
4734-
let constructor = forEach((<ClassDeclaration>container).members, member => {
4736+
let constructor = forEach((<ClassLikeDeclaration>container).members, member => {
47354737
return member.kind === SyntaxKind.Constructor && <ConstructorDeclaration>member;
47364738
});
47374739

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////let A = class Foo {
4+
//// [|constructor|]();
5+
//// [|constructor|](x: number);
6+
//// [|constructor|](y: string);
7+
//// [|constructor|](a?: any) {
8+
//// }
9+
////}
10+
////
11+
////let B = class D {
12+
//// constructor(x: number) {
13+
//// }
14+
////}
15+
16+
const ranges = test.ranges();
17+
for (let r of ranges) {
18+
goTo.position(r.start);
19+
20+
for (let range of ranges) {
21+
verify.occurrencesAtPositionContains(range, false);
22+
}
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////let A = class Foo {
4+
//// [|private|] foo;
5+
//// [|private|] private;
6+
//// constructor([|private|] y: string, public x: string) {
7+
//// }
8+
//// [|private|] method() { }
9+
//// public method2() { }
10+
//// [|private|] static static() { }
11+
////}
12+
////
13+
////let B = class D {
14+
//// constructor(private x: number) {
15+
//// }
16+
//// private test() {}
17+
//// public test2() {}
18+
////}
19+
20+
const ranges = test.ranges();
21+
for (let r of ranges) {
22+
goTo.position(r.start);
23+
24+
for (let range of ranges) {
25+
verify.occurrencesAtPositionContains(range, false);
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////let A = class Foo {
4+
//// [|public|] foo;
5+
//// [|public|] public;
6+
//// constructor([|public|] y: string, private x: string) {
7+
//// }
8+
//// [|public|] method() { }
9+
//// private method2() {}
10+
//// [|public|] static static() { }
11+
////}
12+
////
13+
////let B = class D {
14+
//// constructor(private x: number) {
15+
//// }
16+
//// private test() {}
17+
//// public test2() {}
18+
////}
19+
20+
const ranges = test.ranges();
21+
for (let r of ranges) {
22+
goTo.position(r.start);
23+
24+
for (let range of ranges) {
25+
verify.occurrencesAtPositionContains(range, false);
26+
}
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////let A = class Foo {
4+
//// public static foo;
5+
//// [|static|] a;
6+
//// constructor(public y: string, private x: string) {
7+
//// }
8+
//// public method() { }
9+
//// private method2() {}
10+
//// public [|static|] static() { }
11+
//// private [|static|] static2() { }
12+
////}
13+
////
14+
////let B = class D {
15+
//// static a;
16+
//// constructor(private x: number) {
17+
//// }
18+
//// private static test() {}
19+
//// public static test2() {}
20+
////}
21+
22+
const ranges = test.ranges();
23+
for (let r of ranges) {
24+
goTo.position(r.start);
25+
26+
for (let range of ranges) {
27+
verify.occurrencesAtPositionContains(range, false);
28+
}
29+
}

0 commit comments

Comments
 (0)