Fix speculative parsing by terminating the list when encounting illegal token

This commit is contained in:
Yui T 2014-12-08 15:02:45 -08:00
parent 57e1cf984a
commit e9beba783e

View File

@ -2440,6 +2440,14 @@ module ts {
// a generator, or in strict mode (or both)) and it started a yield expression.
return true;
default:
// Error tolerance. If we see the start of some binary operator, we consider
// that the start of an expression. That way we'll parse out a missing identifier,
// give a good message about an identifier being missing, and then consume the
// rest of the binary expression.
if (isBinaryOperator()) {
return true;
}
return isIdentifier();
}
}
@ -2826,7 +2834,7 @@ module ts {
// reScanGreaterToken so that we merge token sequences like > and = into >=
reScanGreaterToken();
var newPrecedence = getOperatorPrecedence();
var newPrecedence = getBinaryOperatorPrecedence();
// Check the precedence to see if we should "take" this operator
if (newPrecedence <= precedence) {
@ -2845,7 +2853,15 @@ module ts {
return leftOperand;
}
function getOperatorPrecedence(): number {
function isBinaryOperator() {
if (inDisallowInContext() && token === SyntaxKind.InKeyword) {
return false;
}
return getBinaryOperatorPrecedence() > 0;
}
function getBinaryOperatorPrecedence(): number {
switch (token) {
case SyntaxKind.BarBarToken:
return 1;