Skip to content

Commit 5d64e31

Browse files
Fix document highlights crashes on missing tokens/nodes (#2672)
1 parent bdee9eb commit 5d64e31

41 files changed

Lines changed: 3289 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/fourslash/_scripts/convertFourslash.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,9 @@ function parseBaselineDocumentHighlightsArgs(args: readonly ts.Expression[]): [V
13521352
else if (strArg = parseBaselineMarkerOrRangeArg(arg)) {
13531353
newArgs.push(strArg);
13541354
}
1355+
else if (arg.getText() === "test.markers()") {
1356+
newArgs.push("ToAny(f.Markers())...");
1357+
}
13551358
else {
13561359
console.error(`Unrecognized argument in verify.baselineDocumentHighlights: ${arg.getText()}`);
13571360
return undefined;

internal/fourslash/_scripts/crashingTests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ TestFindReferencesBindingPatternInJsdocNoCrash1
33
TestFindReferencesBindingPatternInJsdocNoCrash2
44
TestFormatDocumentWithTrivia
55
TestFormattingJsxTexts4
6-
TestGetOccurrencesIfElseBroken
76
TestImportNameCodeFix_importType8
87
TestQuickInfoBindingPatternInJsdocNoCrash1

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ TestGetJavaScriptQuickInfo6
304304
TestGetJavaScriptQuickInfo7
305305
TestGetJavaScriptQuickInfo8
306306
TestGetJavaScriptSyntacticDiagnostics24
307-
TestGetOccurrencesIfElseBroken
308307
TestHoverOverComment
309308
TestImportFixesGlobalTypingsCache
310309
TestImportMetaCompletionDetails
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestGetOccurrencesConst02(t *testing.T) {
12+
fourslash.SkipIfFailing(t)
13+
t.Parallel()
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `module m {
16+
declare /*1*/const x;
17+
declare [|const|] enum E {
18+
}
19+
}
20+
21+
declare /*2*/const x;
22+
declare [|const|] enum E {
23+
}`
24+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
25+
defer done()
26+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, ToAny(f.Ranges())...)
27+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, ToAny(f.Markers())...)
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestGetOccurrencesConst03(t *testing.T) {
12+
fourslash.SkipIfFailing(t)
13+
t.Parallel()
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `module m {
16+
export /*1*/const x;
17+
export [|const|] enum E {
18+
}
19+
}
20+
21+
export /*2*/const x;
22+
export [|const|] enum E {
23+
}`
24+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
25+
defer done()
26+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, ToAny(f.Ranges())...)
27+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, ToAny(f.Markers())...)
28+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestGetOccurrencesIfElse4(t *testing.T) {
12+
fourslash.SkipIfFailing(t)
13+
t.Parallel()
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `if (true) {
16+
if (false) {
17+
}
18+
else {
19+
}
20+
if (true) {
21+
}
22+
else {
23+
/*1*/if (false)
24+
/*2*/i/*3*/f (true)
25+
var x = undefined;
26+
}
27+
}
28+
else if (null) {
29+
}
30+
else /* whar garbl */ if (undefined) {
31+
}
32+
else
33+
if (false) {
34+
}
35+
else { }`
36+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
37+
defer done()
38+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, ToAny(f.Markers())...)
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestGetOccurrencesIfElse5(t *testing.T) {
12+
fourslash.SkipIfFailing(t)
13+
t.Parallel()
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `if/*1*/ (true) {
16+
if/*2*/ (false) {
17+
}
18+
else/*3*/ {
19+
}
20+
if/*4*/ (true) {
21+
}
22+
else/*5*/ {
23+
if/*6*/ (false)
24+
if/*7*/ (true)
25+
var x = undefined;
26+
}
27+
}
28+
else/*8*/ if (null) {
29+
}
30+
else/*9*/ /* whar garbl */ if/*10*/ (undefined) {
31+
}
32+
else/*11*/
33+
if/*12*/ (false) {
34+
}
35+
else/*13*/ { }`
36+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
37+
defer done()
38+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, ToAny(f.Markers())...)
39+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestGetOccurrencesLoopBreakContinue6(t *testing.T) {
12+
fourslash.SkipIfFailing(t)
13+
t.Parallel()
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `var arr = [1, 2, 3, 4];
16+
label1: for (var n in arr) {
17+
break;
18+
continue;
19+
break label1;
20+
continue label1;
21+
22+
label2: for (var i = 0; i < arr[n]; i++) {
23+
break label1;
24+
continue label1;
25+
26+
break;
27+
continue;
28+
break label2;
29+
continue label2;
30+
31+
function foo() {
32+
label3: while (true) {
33+
break;
34+
continue;
35+
break label3;
36+
continue label3;
37+
38+
// these cross function boundaries
39+
br/*1*/eak label1;
40+
cont/*2*/inue label1;
41+
bre/*3*/ak label2;
42+
c/*4*/ontinue label2;
43+
44+
label4: do {
45+
break;
46+
continue;
47+
break label4;
48+
continue label4;
49+
50+
break label3;
51+
continue label3;
52+
53+
switch (10) {
54+
case 1:
55+
case 2:
56+
break;
57+
break label4;
58+
default:
59+
continue;
60+
}
61+
62+
// these cross function boundaries
63+
br/*5*/eak label1;
64+
co/*6*/ntinue label1;
65+
br/*7*/eak label2;
66+
con/*8*/tinue label2;
67+
() => { b/*9*/reak; }
68+
} while (true)
69+
}
70+
}
71+
}
72+
}
73+
74+
label5: while (true) break label5;
75+
76+
label7: while (true) co/*10*/ntinue label5;`
77+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
78+
defer done()
79+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, ToAny(f.Markers())...)
80+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestGetOccurrencesLoopBreakContinueNegatives(t *testing.T) {
12+
fourslash.SkipIfFailing(t)
13+
t.Parallel()
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `var arr = [1, 2, 3, 4];
16+
label1: for (var n in arr) {
17+
break;
18+
continue;
19+
break label1;
20+
continue label1;
21+
22+
label2: for (var i = 0; i < arr[n]; i++) {
23+
break label1;
24+
continue label1;
25+
26+
break;
27+
continue;
28+
break label2;
29+
continue label2;
30+
31+
function foo() {
32+
label3: while (true) {
33+
break;
34+
continue;
35+
break label3;
36+
continue label3;
37+
38+
// these cross function boundaries
39+
br/*1*/eak label1;
40+
cont/*2*/inue label1;
41+
bre/*3*/ak label2;
42+
c/*4*/ontinue label2;
43+
44+
label4: do {
45+
break;
46+
continue;
47+
break label4;
48+
continue label4;
49+
50+
break label3;
51+
continue label3;
52+
53+
switch (10) {
54+
case 1:
55+
case 2:
56+
break;
57+
break label4;
58+
default:
59+
continue;
60+
}
61+
62+
// these cross function boundaries
63+
br/*5*/eak label1;
64+
co/*6*/ntinue label1;
65+
br/*7*/eak label2;
66+
con/*8*/tinue label2;
67+
() => { b/*9*/reak; }
68+
} while (true)
69+
}
70+
}
71+
}
72+
}
73+
74+
label5: while (true) break label5;
75+
76+
label7: while (true) co/*10*/ntinue label5;`
77+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
78+
defer done()
79+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, ToAny(f.Markers())...)
80+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestGetOccurrencesReturn4(t *testing.T) {
12+
fourslash.SkipIfFailing(t)
13+
t.Parallel()
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `function f(a: number) {
16+
if (a > 0) {
17+
return (function () {
18+
return/*1*/;
19+
return/*2*/;
20+
return/*3*/;
21+
22+
if (false) {
23+
return/*4*/ true;
24+
}
25+
})() || true;
26+
}
27+
28+
var unusued = [1, 2, 3, 4].map(x => { return/*5*/ 4 })
29+
30+
return/*6*/;
31+
return/*7*/ true;
32+
}`
33+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
34+
defer done()
35+
f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, ToAny(f.Markers())...)
36+
}

0 commit comments

Comments
 (0)