diff --git a/internal/parser/jsdoc.go b/internal/parser/jsdoc.go index 6f3720e5a1..580df95a1f 100644 --- a/internal/parser/jsdoc.go +++ b/internal/parser/jsdoc.go @@ -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, @@ -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 } diff --git a/testdata/baselines/reference/conformance/jsdocParseAwait.errors.txt b/testdata/baselines/reference/conformance/jsdocParseAwait.errors.txt new file mode 100644 index 0000000000..eac1d028f9 --- /dev/null +++ b/testdata/baselines/reference/conformance/jsdocParseAwait.errors.txt @@ -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) {} + \ No newline at end of file diff --git a/testdata/baselines/reference/conformance/jsdocParseAwait.symbols b/testdata/baselines/reference/conformance/jsdocParseAwait.symbols new file mode 100644 index 0000000000..de52121bfd --- /dev/null +++ b/testdata/baselines/reference/conformance/jsdocParseAwait.symbols @@ -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)) + diff --git a/testdata/baselines/reference/conformance/jsdocParseAwait.types b/testdata/baselines/reference/conformance/jsdocParseAwait.types new file mode 100644 index 0000000000..0c3998fe86 --- /dev/null +++ b/testdata/baselines/reference/conformance/jsdocParseAwait.types @@ -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 + diff --git a/testdata/tests/cases/conformance/jsdoc/jsdocParseAwait.ts b/testdata/tests/cases/conformance/jsdoc/jsdocParseAwait.ts new file mode 100644 index 0000000000..a49a04e3b3 --- /dev/null +++ b/testdata/tests/cases/conformance/jsdoc/jsdocParseAwait.ts @@ -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) {}