@@ -1778,7 +1778,8 @@ namespace Parser {
1778
1778
1779
1779
const statements = parseList(ParsingContext.SourceElements, parseStatement);
1780
1780
Debug.assert(token() === SyntaxKind.EndOfFileToken);
1781
- const endOfFileToken = addJSDocComment(parseTokenNode<EndOfFileToken>());
1781
+ const endHasJSDoc = hasPrecedingJSDocComment();
1782
+ const endOfFileToken = withJSDoc(parseTokenNode<EndOfFileToken>(), endHasJSDoc);
1782
1783
1783
1784
const sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags, setExternalModuleIndicator);
1784
1785
@@ -1806,12 +1807,12 @@ namespace Parser {
1806
1807
}
1807
1808
}
1808
1809
1810
+ let hasDeprecatedTag = false;
1809
1811
function withJSDoc<T extends HasJSDoc>(node: T, hasJSDoc: boolean): T {
1810
- return hasJSDoc ? addJSDocComment(node) : node;
1811
- }
1812
+ if (!hasJSDoc) {
1813
+ return node;
1814
+ }
1812
1815
1813
- let hasDeprecatedTag = false;
1814
- function addJSDocComment<T extends HasJSDoc>(node: T): T {
1815
1816
Debug.assert(!node.jsDoc); // Should only be called once per node
1816
1817
const jsDoc = mapDefined(getJSDocCommentRanges(node, sourceText), comment => JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos));
1817
1818
if (jsDoc.length) node.jsDoc = jsDoc;
@@ -5025,13 +5026,14 @@ namespace Parser {
5025
5026
// binary expression here, so we pass in the 'lowest' precedence here so that it matches
5026
5027
// and consumes anything.
5027
5028
const pos = getNodePos();
5029
+ const hasJSDoc = hasPrecedingJSDocComment();
5028
5030
const expr = parseBinaryExpressionOrHigher(OperatorPrecedence.Lowest);
5029
5031
5030
5032
// To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized
5031
5033
// parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
5032
5034
// identifier and the current token is an arrow.
5033
5035
if (expr.kind === SyntaxKind.Identifier && token() === SyntaxKind.EqualsGreaterThanToken) {
5034
- return parseSimpleArrowFunctionExpression(pos, expr as Identifier, allowReturnTypeInArrowFunction, /*asyncModifier*/ undefined);
5036
+ return parseSimpleArrowFunctionExpression(pos, expr as Identifier, allowReturnTypeInArrowFunction, hasJSDoc, /*asyncModifier*/ undefined);
5035
5037
}
5036
5038
5037
5039
// Now see if we might be in cases '2' or '3'.
@@ -5107,7 +5109,7 @@ namespace Parser {
5107
5109
}
5108
5110
}
5109
5111
5110
- function parseSimpleArrowFunctionExpression(pos: number, identifier: Identifier, allowReturnTypeInArrowFunction: boolean, asyncModifier?: NodeArray<Modifier> | undefined): ArrowFunction {
5112
+ function parseSimpleArrowFunctionExpression(pos: number, identifier: Identifier, allowReturnTypeInArrowFunction: boolean, hasJSDoc: boolean, asyncModifier?: NodeArray<Modifier> | undefined): ArrowFunction {
5111
5113
Debug.assert(token() === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
5112
5114
const parameter = factory.createParameterDeclaration(
5113
5115
/*modifiers*/ undefined,
@@ -5123,7 +5125,7 @@ namespace Parser {
5123
5125
const equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken);
5124
5126
const body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, allowReturnTypeInArrowFunction);
5125
5127
const node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body);
5126
- return addJSDocComment (finishNode(node, pos));
5128
+ return withJSDoc (finishNode(node, pos), hasJSDoc );
5127
5129
}
5128
5130
5129
5131
function tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction: boolean): Expression | undefined {
@@ -5310,9 +5312,10 @@ namespace Parser {
5310
5312
if (token() === SyntaxKind.AsyncKeyword) {
5311
5313
if (lookAhead(isUnParenthesizedAsyncArrowFunctionWorker) === Tristate.True) {
5312
5314
const pos = getNodePos();
5315
+ const hasJSDoc = hasPrecedingJSDocComment();
5313
5316
const asyncModifier = parseModifiersForArrowFunction();
5314
5317
const expr = parseBinaryExpressionOrHigher(OperatorPrecedence.Lowest);
5315
- return parseSimpleArrowFunctionExpression(pos, expr as Identifier, allowReturnTypeInArrowFunction, asyncModifier);
5318
+ return parseSimpleArrowFunctionExpression(pos, expr as Identifier, allowReturnTypeInArrowFunction, hasJSDoc, asyncModifier);
5316
5319
}
5317
5320
}
5318
5321
return undefined;
0 commit comments