Improve error recovery after a dot

This commit is contained in:
Jason Freeman 2015-06-09 18:09:14 -07:00
parent d8151fbd91
commit 10fccc578e
5 changed files with 66 additions and 1 deletions

View file

@ -1807,7 +1807,7 @@ module ts {
// the code would be implicitly: "name.keyword; identifierNameOrKeyword".
// In the first case though, ASI will not take effect because there is not a
// line terminator after the keyword.
if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord()) {
if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) {
let matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
if (matchesPattern) {

View file

@ -0,0 +1,18 @@
tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(4,15): error TS1003: Identifier expected.
tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(9,2): error TS1005: '}' expected.
==== tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts (2 errors) ====
namespace A {
function foo() {
if (true) {
B.
!!! error TS1003: Identifier expected.
namespace B {
export function baz() { }
}
!!! error TS1005: '}' expected.

View file

@ -0,0 +1,26 @@
//// [errorRecoveryWithDotFollowedByNamespaceKeyword.ts]
namespace A {
function foo() {
if (true) {
B.
namespace B {
export function baz() { }
}
//// [errorRecoveryWithDotFollowedByNamespaceKeyword.js]
var A;
(function (A) {
function foo() {
if (true) {
B.
;
var B;
(function (B) {
function baz() { }
B.baz = baz;
})(B || (B = {}));
}
}
})(A || (A = {}));

View file

@ -0,0 +1,9 @@
namespace A {
function foo() {
if (true) {
B.
namespace B {
export function baz() { }
}

View file

@ -0,0 +1,12 @@
/// <reference path='fourslash.ts'/>
////namespace A {
//// function foo() {
//// if (true) {
//// B./**/
//// namespace B {
//// export function baz() { }
////}
goTo.marker();
verify.completionListContains("baz", "function B.baz(): void");