Don't parse duplicate JSDoc for ExpressionStatement starting with ParenthesizedExpression (#36289)

* don't parse JSDoc on ExpressionStatement if it starts with ParenthesizedExpression

* update test
This commit is contained in:
Klaus Meinhardt
2020-03-12 22:42:49 +01:00
committed by GitHub
parent ddcf139668
commit 7bd6209fbc
4 changed files with 74 additions and 2 deletions

View File

@@ -1400,7 +1400,7 @@ namespace ts {
function createNodeWithJSDoc(kind: SyntaxKind, pos?: number): Node {
const node = createNode(kind, pos);
if (scanner.getTokenFlags() & TokenFlags.PrecedingJSDocComment) {
if (scanner.getTokenFlags() & TokenFlags.PrecedingJSDocComment && (kind !== SyntaxKind.ExpressionStatement || token() !== SyntaxKind.OpenParenToken)) {
addJSDocComment(<HasJSDoc>node);
}
return node;
@@ -5469,7 +5469,7 @@ namespace ts {
// Avoiding having to do the lookahead for a labeled statement by just trying to parse
// out an expression, seeing if it is identifier and then seeing if it is followed by
// a colon.
const node = <ExpressionStatement | LabeledStatement>createNodeWithJSDoc(SyntaxKind.Unknown);
const node = <ExpressionStatement | LabeledStatement>createNodeWithJSDoc(token() === SyntaxKind.Identifier ? SyntaxKind.Unknown : SyntaxKind.ExpressionStatement);
const expression = allowInAnd(parseExpression);
if (expression.kind === SyntaxKind.Identifier && parseOptional(SyntaxKind.ColonToken)) {
node.kind = SyntaxKind.LabeledStatement;