Skip to content

Commit 10fccc5

Browse files
committed
Improve error recovery after a dot
1 parent d8151fb commit 10fccc5

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ module ts {
18071807
// the code would be implicitly: "name.keyword; identifierNameOrKeyword".
18081808
// In the first case though, ASI will not take effect because there is not a
18091809
// line terminator after the keyword.
1810-
if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord()) {
1810+
if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) {
18111811
let matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
18121812

18131813
if (matchesPattern) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(4,15): error TS1003: Identifier expected.
2+
tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(9,2): error TS1005: '}' expected.
3+
4+
5+
==== tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts (2 errors) ====
6+
namespace A {
7+
function foo() {
8+
if (true) {
9+
B.
10+
11+
!!! error TS1003: Identifier expected.
12+
13+
14+
namespace B {
15+
export function baz() { }
16+
}
17+
18+
!!! error TS1005: '}' expected.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [errorRecoveryWithDotFollowedByNamespaceKeyword.ts]
2+
namespace A {
3+
function foo() {
4+
if (true) {
5+
B.
6+
7+
8+
namespace B {
9+
export function baz() { }
10+
}
11+
12+
//// [errorRecoveryWithDotFollowedByNamespaceKeyword.js]
13+
var A;
14+
(function (A) {
15+
function foo() {
16+
if (true) {
17+
B.
18+
;
19+
var B;
20+
(function (B) {
21+
function baz() { }
22+
B.baz = baz;
23+
})(B || (B = {}));
24+
}
25+
}
26+
})(A || (A = {}));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace A {
2+
function foo() {
3+
if (true) {
4+
B.
5+
6+
7+
namespace B {
8+
export function baz() { }
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////namespace A {
4+
//// function foo() {
5+
//// if (true) {
6+
//// B./**/
7+
//// namespace B {
8+
//// export function baz() { }
9+
////}
10+
11+
goTo.marker();
12+
verify.completionListContains("baz", "function B.baz(): void");

0 commit comments

Comments
 (0)