From 0b044f729fe1329c9ae1564aa4e79c172f77696e Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Tue, 13 Feb 2024 14:13:43 -0600 Subject: [PATCH] When attaching JSDoc diagnostics, make sure to only include diagnostics that actually belong with the JSDoc (#57271) --- src/compiler/parser.ts | 2 +- .../reference/errorIsolation.symbols | 16 ++++++++++++++ .../baselines/reference/errorIsolation.types | 21 +++++++++++++++++++ .../cases/conformance/jsdoc/errorIsolation.ts | 8 +++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/errorIsolation.symbols create mode 100644 tests/baselines/reference/errorIsolation.types create mode 100644 tests/cases/conformance/jsdoc/errorIsolation.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2f411c43549..eaa8bbef472 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -8760,7 +8760,7 @@ namespace Parser { if (!jsDocDiagnostics) { jsDocDiagnostics = []; } - jsDocDiagnostics.push(...parseDiagnostics); + addRange(jsDocDiagnostics, parseDiagnostics, saveParseDiagnosticsLength); } currentToken = saveToken; parseDiagnostics.length = saveParseDiagnosticsLength; diff --git a/tests/baselines/reference/errorIsolation.symbols b/tests/baselines/reference/errorIsolation.symbols new file mode 100644 index 00000000000..fe35abd73a0 --- /dev/null +++ b/tests/baselines/reference/errorIsolation.symbols @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/jsdoc/errorIsolation.ts] //// + +=== errorIsolation.js === +const async = { doSomething: _ => {} }; +>async : Symbol(async, Decl(errorIsolation.js, 0, 5)) +>doSomething : Symbol(doSomething, Decl(errorIsolation.js, 0, 15)) +>_ : Symbol(_, Decl(errorIsolation.js, 0, 28)) + +async.doSomething( +>async.doSomething : Symbol(doSomething, Decl(errorIsolation.js, 0, 15)) +>async : Symbol(async, Decl(errorIsolation.js, 0, 5)) +>doSomething : Symbol(doSomething, Decl(errorIsolation.js, 0, 15)) + + /***/ + () => {} +); diff --git a/tests/baselines/reference/errorIsolation.types b/tests/baselines/reference/errorIsolation.types new file mode 100644 index 00000000000..682f1e183c8 --- /dev/null +++ b/tests/baselines/reference/errorIsolation.types @@ -0,0 +1,21 @@ +//// [tests/cases/conformance/jsdoc/errorIsolation.ts] //// + +=== errorIsolation.js === +const async = { doSomething: _ => {} }; +>async : { doSomething: (_: any) => void; } +>{ doSomething: _ => {} } : { doSomething: (_: any) => void; } +>doSomething : (_: any) => void +>_ => {} : (_: any) => void +>_ : any + +async.doSomething( +>async.doSomething( /***/ () => {}) : void +>async.doSomething : (_: any) => void +>async : { doSomething: (_: any) => void; } +>doSomething : (_: any) => void + + /***/ + () => {} +>() => {} : () => void + +); diff --git a/tests/cases/conformance/jsdoc/errorIsolation.ts b/tests/cases/conformance/jsdoc/errorIsolation.ts new file mode 100644 index 00000000000..d06d76dcac8 --- /dev/null +++ b/tests/cases/conformance/jsdoc/errorIsolation.ts @@ -0,0 +1,8 @@ +// @noEmit: true +// @checkJs: true +// @filename: errorIsolation.js +const async = { doSomething: _ => {} }; +async.doSomething( + /***/ + () => {} +); \ No newline at end of file