From 0fb9b1adbd4b2f831b32e10400cbf43e85c741d6 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 1 Jun 2018 16:49:54 -0700 Subject: [PATCH] Fix bug when name resolution fails in a @typedef: Don't set `lastLocation` (#24585) * Fix bug when name resolution fails in a @typedef: Don't set `lastLocation` * Add noEmit to test --- src/compiler/checker.ts | 5 ++--- .../jsdocResolveNameFailureInTypedef.errors.txt | 15 +++++++++++++++ .../jsdocResolveNameFailureInTypedef.symbols | 12 ++++++++++++ .../jsdocResolveNameFailureInTypedef.types | 12 ++++++++++++ .../compiler/jsdocResolveNameFailureInTypedef.ts | 13 +++++++++++++ 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/jsdocResolveNameFailureInTypedef.errors.txt create mode 100644 tests/baselines/reference/jsdocResolveNameFailureInTypedef.symbols create mode 100644 tests/baselines/reference/jsdocResolveNameFailureInTypedef.types create mode 100644 tests/cases/compiler/jsdocResolveNameFailureInTypedef.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ae9ed60f0c1..f374d8eae16 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1460,9 +1460,8 @@ namespace ts { case SyntaxKind.JSDocTypedefTag: case SyntaxKind.JSDocCallbackTag: // js type aliases do not resolve names from their host, so skip past it - lastLocation = location; - location = getJSDocHost(location).parent; - continue; + location = getJSDocHost(location); + break; } if (isSelfReferenceLocation(location)) { lastSelfReferenceLocation = location; diff --git a/tests/baselines/reference/jsdocResolveNameFailureInTypedef.errors.txt b/tests/baselines/reference/jsdocResolveNameFailureInTypedef.errors.txt new file mode 100644 index 00000000000..220be597bdb --- /dev/null +++ b/tests/baselines/reference/jsdocResolveNameFailureInTypedef.errors.txt @@ -0,0 +1,15 @@ +/a.js(7,14): error TS2304: Cannot find name 'CantResolveThis'. + + +==== /a.js (1 errors) ==== + /** + * @param {Ty} x + */ + function f(x) {} + + /** + * @typedef {CantResolveThis} Ty + ~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'CantResolveThis'. + */ + \ No newline at end of file diff --git a/tests/baselines/reference/jsdocResolveNameFailureInTypedef.symbols b/tests/baselines/reference/jsdocResolveNameFailureInTypedef.symbols new file mode 100644 index 00000000000..36d8565cf01 --- /dev/null +++ b/tests/baselines/reference/jsdocResolveNameFailureInTypedef.symbols @@ -0,0 +1,12 @@ +=== /a.js === +/** + * @param {Ty} x + */ +function f(x) {} +>f : Symbol(f, Decl(a.js, 0, 0)) +>x : Symbol(x, Decl(a.js, 3, 11)) + +/** + * @typedef {CantResolveThis} Ty + */ + diff --git a/tests/baselines/reference/jsdocResolveNameFailureInTypedef.types b/tests/baselines/reference/jsdocResolveNameFailureInTypedef.types new file mode 100644 index 00000000000..4d88a942fe9 --- /dev/null +++ b/tests/baselines/reference/jsdocResolveNameFailureInTypedef.types @@ -0,0 +1,12 @@ +=== /a.js === +/** + * @param {Ty} x + */ +function f(x) {} +>f : (x: any) => void +>x : any + +/** + * @typedef {CantResolveThis} Ty + */ + diff --git a/tests/cases/compiler/jsdocResolveNameFailureInTypedef.ts b/tests/cases/compiler/jsdocResolveNameFailureInTypedef.ts new file mode 100644 index 00000000000..016893cfd7b --- /dev/null +++ b/tests/cases/compiler/jsdocResolveNameFailureInTypedef.ts @@ -0,0 +1,13 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true + +// @Filename: /a.js +/** + * @param {Ty} x + */ +function f(x) {} + +/** + * @typedef {CantResolveThis} Ty + */