Skip to content

Commit 0939f77

Browse files
Added tests for missing 'try' parsing
1 parent efb6db8 commit 0939f77

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

tests/baselines/reference/invalidTryStatements2.errors.txt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
==== tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts (2 errors) ====
1+
==== tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts (6 errors) ====
22
function fn() {
33
try {
44
} catch { // syntax error, missing '(x)'
@@ -10,5 +10,32 @@
1010
~~~~~
1111
!!! A 'catch' clause must be preceded by a 'try' statement.
1212

13-
finally{ } // error missing try
13+
finally{ } // potential error; can be absorbed by the 'catch'
14+
}
15+
16+
function fn2() {
17+
finally { } // error missing try
18+
~~~~~~~
19+
!!! A 'finally' block must be preceded by a 'try' statement.
20+
catch (x) { } // error missing try
21+
~~~~~
22+
!!! A 'catch' clause must be preceded by a 'try' statement.
23+
24+
// no error
25+
try {
26+
}
27+
finally {
28+
}
29+
30+
// error missing try
31+
finally {
32+
~~~~~~~
33+
!!! A 'finally' block must be preceded by a 'try' statement.
34+
}
35+
36+
// error missing try
37+
catch (x) {
38+
~~~~~
39+
!!! A 'catch' clause must be preceded by a 'try' statement.
40+
}
1441
}

tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,24 @@ function fn() {
55

66
catch(x) { } // error missing try
77

8-
finally{ } // error missing try
8+
finally{ } // potential error; can be absorbed by the 'catch'
9+
}
10+
11+
function fn2() {
12+
finally { } // error missing try
13+
catch (x) { } // error missing try
14+
15+
// no error
16+
try {
17+
}
18+
finally {
19+
}
20+
21+
// error missing try
22+
finally {
23+
}
24+
25+
// error missing try
26+
catch (x) {
27+
}
928
}

0 commit comments

Comments
 (0)