Add some missing | undefined in parser.ts (#17407)

This commit is contained in:
Andy 2017-07-27 11:25:48 -07:00 committed by GitHub
parent 3330f2a33b
commit 70e5c6b1e5

View File

@ -3161,7 +3161,7 @@ namespace ts {
return addJSDocComment(finishNode(node));
}
function tryParseParenthesizedArrowFunctionExpression(): Expression {
function tryParseParenthesizedArrowFunctionExpression(): Expression | undefined {
const triState = isParenthesizedArrowFunctionExpression();
if (triState === Tristate.False) {
// It's definitely not a parenthesized arrow function expression.
@ -3324,7 +3324,7 @@ namespace ts {
return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false);
}
function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction {
function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction | undefined {
// We do a check here so that we won't be doing unnecessarily call to "lookAhead"
if (token() === SyntaxKind.AsyncKeyword) {
const isUnParenthesizedAsyncArrowFunction = lookAhead(isUnParenthesizedAsyncArrowFunctionWorker);
@ -4398,7 +4398,7 @@ namespace ts {
return finishNode(node);
}
function tryParseAccessorDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: NodeArray<Modifier>): AccessorDeclaration {
function tryParseAccessorDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: NodeArray<Modifier>): AccessorDeclaration | undefined {
if (parseContextualModifier(SyntaxKind.GetKeyword)) {
return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers);
}
@ -4511,7 +4511,7 @@ namespace ts {
return addJSDocComment(finishNode(node));
}
function parseOptionalIdentifier() {
function parseOptionalIdentifier(): Identifier | undefined {
return isIdentifier() ? parseIdentifier() : undefined;
}
@ -5576,7 +5576,7 @@ namespace ts {
return addJSDocComment(finishNode(node));
}
function parseNameOfClassDeclarationOrExpression(): Identifier {
function parseNameOfClassDeclarationOrExpression(): Identifier | undefined {
// implements is a future reserved word so
// 'class implements' might mean either
// - class expression with omitted name, 'implements' starts heritage clause
@ -6116,7 +6116,7 @@ namespace ts {
}
export namespace JSDocParser {
export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number) {
export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number): { jsDocTypeExpression: JSDocTypeExpression, diagnostics: Diagnostic[] } | undefined {
initializeState(content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS);
sourceFile = createSourceFile("file.js", ScriptTarget.Latest, ScriptKind.JS);
scanner.setText(content, start, length);
@ -6141,7 +6141,7 @@ namespace ts {
return finishNode(result);
}
export function parseIsolatedJSDocComment(content: string, start: number, length: number) {
export function parseIsolatedJSDocComment(content: string, start: number, length: number): { jsDoc: JSDoc, diagnostics: Diagnostic[] } | undefined {
initializeState(content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS);
sourceFile = <SourceFile>{ languageVariant: LanguageVariant.Standard, text: content };
const jsDoc = parseJSDocCommentWorker(start, length);
@ -6476,7 +6476,7 @@ namespace ts {
tags.end = tag.end;
}
function tryParseTypeExpression(): JSDocTypeExpression {
function tryParseTypeExpression(): JSDocTypeExpression | undefined {
return tryParse(() => {
skipWhitespace();
if (token() !== SyntaxKind.OpenBraceToken) {
@ -6767,7 +6767,7 @@ namespace ts {
return false;
}
function parseTemplateTag(atToken: AtToken, tagName: Identifier): JSDocTemplateTag {
function parseTemplateTag(atToken: AtToken, tagName: Identifier): JSDocTemplateTag | undefined {
if (forEach(tags, t => t.kind === SyntaxKind.JSDocTemplateTag)) {
parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.escapedText);
}
@ -6829,12 +6829,10 @@ namespace ts {
return entity;
}
function parseJSDocIdentifierName(createIfMissing = false): Identifier {
return createJSDocIdentifier(tokenIsIdentifierOrKeyword(token()), createIfMissing);
}
function createJSDocIdentifier(isIdentifier: boolean, createIfMissing: boolean): Identifier {
if (!isIdentifier) {
function parseJSDocIdentifierName(): Identifier | undefined;
function parseJSDocIdentifierName(createIfMissing: true): Identifier;
function parseJSDocIdentifierName(createIfMissing = false): Identifier | undefined {
if (!tokenIsIdentifierOrKeyword(token())) {
if (createIfMissing) {
return createMissingNode<Identifier>(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Identifier_expected);
}
@ -7215,7 +7213,7 @@ namespace ts {
}
}
function getLastChildWorker(node: Node): Node {
function getLastChildWorker(node: Node): Node | undefined {
let last: Node = undefined;
forEachChild(node, child => {
if (nodeIsPresent(child)) {