Don't report a grammar error for a real parse error.

This commit is contained in:
Cyrus Najmabadi 2014-11-19 17:15:25 -08:00
parent 1a0f32213f
commit cfb74249c8
3 changed files with 20 additions and 12 deletions

View File

@ -1010,7 +1010,10 @@ module ts {
function createNode(kind: SyntaxKind, pos?: number): Node {
nodeCount++;
var node = new (nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind)))();
if (!(pos >= 0)) pos = scanner.getStartPos();
if (!(pos >= 0)) {
pos = scanner.getStartPos();
}
node.pos = pos;
node.end = pos;
return node;
@ -2225,16 +2228,21 @@ 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() && lookAhead(() => scanner.isReservedWord())) {
grammarErrorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, Diagnostics.Identifier_expected);
var id = <Identifier>createMissingNode();
}
else {
var id = parseIdentifierName();
var id: Identifier;
if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord()) {
var matchesPattern = lookAhead(() => {
nextToken();
return !scanner.hasPrecedingLineBreak() && (scanner.isIdentifier() || scanner.isReservedWord);
});
if (matchesPattern) {
errorAtPos(dotOrBracketStart + 1, 0, Diagnostics.Identifier_expected);
id = <Identifier>createMissingNode();
}
}
propertyAccess.left = expr;
propertyAccess.right = id;
propertyAccess.right = id || parseIdentifierName();
expr = finishNode(propertyAccess);
continue;
}

View File

@ -1,4 +1,4 @@
tests/cases/compiler/enumConflictsWithGlobalIdentifier.ts(4,28): error TS1003: Identifier expected.
tests/cases/compiler/enumConflictsWithGlobalIdentifier.ts(4,29): error TS1003: Identifier expected.
tests/cases/compiler/enumConflictsWithGlobalIdentifier.ts(4,9): error TS2304: Cannot find name 'IgnoreRulesSpecific'.
@ -7,7 +7,7 @@ tests/cases/compiler/enumConflictsWithGlobalIdentifier.ts(4,9): error TS2304: Ca
IgnoreRulesSpecific = 0,
}
var x = IgnoreRulesSpecific.
~
!!! error TS1003: Identifier expected.
~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'IgnoreRulesSpecific'.

View File

@ -1,4 +1,4 @@
tests/cases/compiler/enumMemberResolution.ts(4,28): error TS1003: Identifier expected.
tests/cases/compiler/enumMemberResolution.ts(4,29): error TS1003: Identifier expected.
tests/cases/compiler/enumMemberResolution.ts(4,9): error TS2304: Cannot find name 'IgnoreRulesSpecific'.
@ -7,7 +7,7 @@ tests/cases/compiler/enumMemberResolution.ts(4,9): error TS2304: Cannot find nam
IgnoreRulesSpecific = 0
}
var x = IgnoreRulesSpecific. // error
~
!!! error TS1003: Identifier expected.
~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'IgnoreRulesSpecific'.