Skip to content

Commit 723616f

Browse files
committed
Inline parseTokenForError, return undefined not false
1 parent c141447 commit 723616f

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

src/compiler/parser.ts

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,29 +1335,29 @@ namespace ts {
13351335
return inContext(NodeFlags.AwaitContext);
13361336
}
13371337

1338-
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | false {
1338+
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
13391339
return parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), message, arg0);
13401340
}
13411341

1342-
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | false {
1342+
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
13431343
// Don't report another error if it would just be at the same position as the last error.
13441344
const lastError = lastOrUndefined(parseDiagnostics);
1345-
let result: DiagnosticWithDetachedLocation | false;
1345+
let result: DiagnosticWithDetachedLocation | undefined;
13461346
if (!lastError || start !== lastError.start) {
1347-
result = createDetachedDiagnostic(fileName, start, length, message, arg0)
1347+
result = createDetachedDiagnostic(fileName, start, length, message, arg0);
13481348
parseDiagnostics.push(result);
13491349
}
13501350
else {
1351-
result = false;
1351+
result = undefined;
13521352
}
13531353

13541354
// Mark that we've encountered an error. We'll set an appropriate bit on the next
13551355
// node we finish so that it can't be reused incrementally.
13561356
parseErrorBeforeNextFinishedNode = true;
1357-
return result
1357+
return result;
13581358
}
13591359

1360-
function parseErrorAt(start: number, end: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | false {
1360+
function parseErrorAt(start: number, end: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
13611361
return parseErrorAtPosition(start, end - start, message, arg0);
13621362
}
13631363

@@ -1539,24 +1539,6 @@ namespace ts {
15391539
return false;
15401540
}
15411541

1542-
/** Like parseExpected, but returns true=succeed, diagnostic=fail, false=fail+failed to log error */
1543-
function parseTokenForError(kind: SyntaxKind, diagnosticMessage?: DiagnosticMessage, shouldAdvance = true): DiagnosticWithDetachedLocation | boolean {
1544-
if (token() === kind) {
1545-
if (shouldAdvance) {
1546-
nextToken();
1547-
}
1548-
return true;
1549-
}
1550-
1551-
// Report specific message if provided with one. Otherwise, report generic fallback message.
1552-
if (diagnosticMessage) {
1553-
return parseErrorAtCurrentToken(diagnosticMessage);
1554-
}
1555-
else {
1556-
return parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(kind));
1557-
}
1558-
}
1559-
15601542
function parseExpectedJSDoc(kind: JSDocSyntaxKind) {
15611543
if (token() === kind) {
15621544
nextTokenJSDoc();
@@ -1567,16 +1549,18 @@ namespace ts {
15671549
}
15681550

15691551
function parseExpectedMatchingBrackets(openKind: SyntaxKind, closeKind: SyntaxKind, openPosition: number) {
1570-
const lastError = parseTokenForError(closeKind);
1571-
if (typeof lastError === 'boolean')
1572-
return lastError
1573-
else {
1552+
if (token() === closeKind) {
1553+
nextToken();
1554+
return true;
1555+
}
1556+
const lastError = parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(closeKind));
1557+
if (lastError) {
15741558
addRelatedInfo(
15751559
lastError,
15761560
createDetachedDiagnostic(fileName, openPosition, 1, Diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, tokenToString(openKind), tokenToString(closeKind))
15771561
);
1578-
return false;
15791562
}
1563+
return false;
15801564
}
15811565

15821566
function parseOptional(t: SyntaxKind): boolean {

0 commit comments

Comments
 (0)