mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Add better error recovery logic for cases with line ending with "id." followed by a declaration e.g. "class id"
This commit is contained in:
parent
085cabf8e0
commit
5d577df69e
@ -2198,10 +2198,38 @@ module ts {
|
||||
|
||||
function parseCallAndAccess(expr: Expression, inNewExpression: boolean): Expression {
|
||||
while (true) {
|
||||
var dotStart = scanner.getTokenPos();
|
||||
if (parseOptional(SyntaxKind.DotToken)) {
|
||||
var propertyAccess = <PropertyAccess>createNode(SyntaxKind.PropertyAccess, expr.pos);
|
||||
// Technically a keyword is valid here as all keywords are identifier names.
|
||||
// However, often we'll encounter this in error situations when the keyword
|
||||
// is actually starting another valid construct.
|
||||
//
|
||||
// So, we check for the following specific case:
|
||||
//
|
||||
// name.
|
||||
// keyword identifierNameOrKeyword
|
||||
//
|
||||
// Note: the newlines are important here. For example, if that above code
|
||||
// were rewritten into:
|
||||
//
|
||||
// name.keyword
|
||||
// identifierNameOrKeyword
|
||||
//
|
||||
// Then we would consider it valid. That's because ASI would take effect and
|
||||
// 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() && lookAhead(() => scanner.isReservedWord())) {
|
||||
grammarErrorAtPos(dotStart, scanner.getStartPos() - dotStart, Diagnostics.Identifier_expected);
|
||||
var id = <Identifier>createMissingNode();
|
||||
}
|
||||
else {
|
||||
var id = parseIdentifierName();
|
||||
}
|
||||
|
||||
propertyAccess.left = expr;
|
||||
propertyAccess.right = parseIdentifierName();
|
||||
propertyAccess.right = id;
|
||||
expr = finishNode(propertyAccess);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
IgnoreRulesSpecific = 0,
|
||||
}
|
||||
var x = IgnoreRulesSpecific.
|
||||
~
|
||||
!!! Identifier expected.
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! Cannot find name 'IgnoreRulesSpecific'.
|
||||
var y = Position.IgnoreRulesSpecific;
|
||||
~
|
||||
!!! ',' expected.
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
IgnoreRulesSpecific = 0
|
||||
}
|
||||
var x = IgnoreRulesSpecific. // error
|
||||
~
|
||||
!!! Identifier expected.
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! Cannot find name 'IgnoreRulesSpecific'.
|
||||
var y = 1;
|
||||
~
|
||||
!!! ',' expected.
|
||||
var z = Position2.IgnoreRulesSpecific; // no error
|
||||
|
||||
@ -16,9 +16,9 @@
|
||||
|
||||
// Verify the memberlist of module when the following line has a keyword
|
||||
goTo.marker('namedType');
|
||||
verify.completionListContains('C1', 'TypeModule1.C1');
|
||||
verify.completionListContains('C2', 'TypeModule1.C2');
|
||||
verify.completionListContains('C1');
|
||||
verify.completionListContains('C2');
|
||||
|
||||
goTo.marker('dotedExpression');
|
||||
verify.completionListContains('C1', 'TypeModule1.C1');
|
||||
verify.completionListContains('C2', 'TypeModule1.C2');
|
||||
verify.completionListContains('C1');
|
||||
verify.completionListContains('C2');
|
||||
Loading…
x
Reference in New Issue
Block a user