mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
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:
parent
ddcf139668
commit
7bd6209fbc
@ -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;
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
=== tests/cases/compiler/test.js ===
|
||||
// @ts-check
|
||||
/** @typedef {number} NotADuplicateIdentifier */
|
||||
|
||||
(2 * 2);
|
||||
|
||||
/** @typedef {number} AlsoNotADuplicate */
|
||||
|
||||
(2 * 2) + 1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a {NotADuplicateIdentifier}
|
||||
* @param b {AlsoNotADuplicate}
|
||||
*/
|
||||
function makeSureTypedefsAreStillRecognized(a, b) {}
|
||||
>makeSureTypedefsAreStillRecognized : Symbol(makeSureTypedefsAreStillRecognized, Decl(test.js, 7, 12))
|
||||
>a : Symbol(a, Decl(test.js, 15, 44))
|
||||
>b : Symbol(b, Decl(test.js, 15, 46))
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
=== tests/cases/compiler/test.js ===
|
||||
// @ts-check
|
||||
/** @typedef {number} NotADuplicateIdentifier */
|
||||
|
||||
(2 * 2);
|
||||
>(2 * 2) : number
|
||||
>2 * 2 : number
|
||||
>2 : 2
|
||||
>2 : 2
|
||||
|
||||
/** @typedef {number} AlsoNotADuplicate */
|
||||
|
||||
(2 * 2) + 1;
|
||||
>(2 * 2) + 1 : number
|
||||
>(2 * 2) : number
|
||||
>2 * 2 : number
|
||||
>2 : 2
|
||||
>2 : 2
|
||||
>1 : 1
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a {NotADuplicateIdentifier}
|
||||
* @param b {AlsoNotADuplicate}
|
||||
*/
|
||||
function makeSureTypedefsAreStillRecognized(a, b) {}
|
||||
>makeSureTypedefsAreStillRecognized : (a: number, b: number) => void
|
||||
>a : number
|
||||
>b : number
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @filename: test.js
|
||||
// @ts-check
|
||||
/** @typedef {number} NotADuplicateIdentifier */
|
||||
|
||||
(2 * 2);
|
||||
|
||||
/** @typedef {number} AlsoNotADuplicate */
|
||||
|
||||
(2 * 2) + 1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a {NotADuplicateIdentifier}
|
||||
* @param b {AlsoNotADuplicate}
|
||||
*/
|
||||
function makeSureTypedefsAreStillRecognized(a, b) {}
|
||||
Loading…
x
Reference in New Issue
Block a user