From 8c0fdbcff0af8aaf8ea0f9813928bc1578b81e97 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 4 Dec 2014 09:49:52 -0800 Subject: [PATCH] Add invariant assert in the parser. --- src/compiler/parser.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9ec83501e48..1763df9cda8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1166,12 +1166,20 @@ module ts { var saveToken = token; var saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; + // Note: it is not actually necessary to save/restore the context falgs here. That's + // because the saving/restorating of these flags happens naturally through the recursive + // descent nature of our parser. However, we still store this here just so we can + // assert that that invariant holds. + var saveContextFlags = contextFlags; + // If we're only looking ahead, then tell the scanner to only lookahead as well. // If we're actually speculatively parsing, then tell the scanner to do the same. var result = isLookAhead ? scanner.lookAhead(callback) : scanner.tryScan(callback); + Debug.assert(saveContextFlags === contextFlags); + // If our callback returned something 'falsy' or we're just looking ahead, // then unconditionally restore us to where we were. if (!result || isLookAhead) { @@ -1958,6 +1966,9 @@ module ts { return result; } + // We didn't even have an open paren. If the caller requires a complete parameter list, + // we definitely can't provide that. However, if they're ok with an incomplete one, + // then just return an empty set of parameters. return requireCompleteParameterList ? undefined : createMissingList(); }