Skip to content

fix: avoid treating await in jsdoc as top-level await #877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/parser/jsdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (p *Parser) parseJSDocComment(parent *ast.Node, start int, end int, fullSta
saveScannerState := p.scanner.Mark()
saveDiagnosticsLength := len(p.diagnostics)
saveHasParseError := p.hasParseError
saveHasAwaitIdentifier := p.statementHasAwaitIdentifier

// initial indent is start+4 to account for leading `/** `
// + 1 because \n is one character before the first character in the line and,
Expand Down Expand Up @@ -158,6 +159,7 @@ func (p *Parser) parseJSDocComment(parent *ast.Node, start int, end int, fullSta
p.scanner.Rewind(saveScannerState)
p.token = saveToken
p.hasParseError = saveHasParseError
p.statementHasAwaitIdentifier = saveHasAwaitIdentifier

return comment
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/a.js(7,7): error TS2322: Type 'number' is not assignable to type 'T'.


==== /a.js (1 errors) ====
/**
* @typedef {object} T
* @property {boolean} await
*/

/** @type {T} */
const a = 1;
~
!!! error TS2322: Type 'number' is not assignable to type 'T'.

/** @type {T} */
const b = {
await: false,
};

/**
* @param {boolean} await
*/
function c(await) {}

28 changes: 28 additions & 0 deletions testdata/baselines/reference/conformance/jsdocParseAwait.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [tests/cases/conformance/jsdoc/jsdocParseAwait.ts] ////

=== /a.js ===
/**
* @typedef {object} T
* @property {boolean} await
*/

/** @type {T} */
const a = 1;
>a : Symbol(a, Decl(a.js, 6, 5))

/** @type {T} */
const b = {
>b : Symbol(b, Decl(a.js, 9, 5))

await: false,
>await : Symbol(await, Decl(a.js, 9, 11))

};

/**
* @param {boolean} await
*/
function c(await) {}
>c : Symbol(c, Decl(a.js, 11, 2))
>await : Symbol(await, Decl(a.js, 16, 11))

31 changes: 31 additions & 0 deletions testdata/baselines/reference/conformance/jsdocParseAwait.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//// [tests/cases/conformance/jsdoc/jsdocParseAwait.ts] ////

=== /a.js ===
/**
* @typedef {object} T
* @property {boolean} await
*/

/** @type {T} */
const a = 1;
>a : T
>1 : 1

/** @type {T} */
const b = {
>b : T
>{ await: false,} : { await: boolean; }

await: false,
>await : boolean
>false : false

};

/**
* @param {boolean} await
*/
function c(await) {}
>c : (await: boolean) => void
>await : boolean

23 changes: 23 additions & 0 deletions testdata/tests/cases/conformance/jsdoc/jsdocParseAwait.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true

// @Filename: /a.js

/**
* @typedef {object} T
* @property {boolean} await
*/

/** @type {T} */
const a = 1;

/** @type {T} */
const b = {
await: false,
};

/**
* @param {boolean} await
*/
function c(await) {}