From f1ce0f5528dbea005146332f7d8fb3f112a2c98c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 4 Aug 2021 07:05:11 -0700 Subject: [PATCH] Visit children of jsdoc type aliases in the binder (#45312) * Visit children of jsdoc type aliases in the binder This sets up parent pointers. Fixes #45254 and almost certainly #45248, though I haven't figured out to repro the second case. * move incorrect parenthesis * manually set comment parent instead * Bind children of typedef where possible * add explanatory comment to binding --- src/compiler/binder.ts | 6 +- src/compiler/parser.ts | 4 +- .../reference/quickInfoLink2.baseline | 105 ++++++++++++++++++ tests/cases/fourslash/quickInfoLink2.ts | 12 ++ 4 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/quickInfoLink2.baseline create mode 100644 tests/cases/fourslash/quickInfoLink2.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 2887481d78e..3b67298ee92 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1666,11 +1666,15 @@ namespace ts { } function bindJSDocTypeAlias(node: JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag) { - setParent(node.tagName, node); + bind(node.tagName); if (node.kind !== SyntaxKind.JSDocEnumTag && node.fullName) { + // don't bind the type name yet; that's delayed until delayedBindJSDocTypedefTag setParent(node.fullName, node); setParentRecursive(node.fullName, /*incremental*/ false); } + if (typeof node.comment !== "string") { + bindEach(node.comment); + } } function bindJSDocClassTag(node: JSDocClassTag) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 135d73a04b6..0aa0a8fb095 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -530,8 +530,8 @@ namespace ts { visitNode(cbNode, (node as JSDocTypedefTag).fullName) || (typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray | undefined)) : visitNode(cbNode, (node as JSDocTypedefTag).fullName) || - visitNode(cbNode, (node as JSDocTypedefTag).typeExpression)) || - (typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray | undefined)); + visitNode(cbNode, (node as JSDocTypedefTag).typeExpression) || + (typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray | undefined))); case SyntaxKind.JSDocCallbackTag: return visitNode(cbNode, (node as JSDocTag).tagName) || visitNode(cbNode, (node as JSDocCallbackTag).fullName) || diff --git a/tests/baselines/reference/quickInfoLink2.baseline b/tests/baselines/reference/quickInfoLink2.baseline new file mode 100644 index 00000000000..3219b7cc600 --- /dev/null +++ b/tests/baselines/reference/quickInfoLink2.baseline @@ -0,0 +1,105 @@ +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoLink2.js", + "position": 39, + "name": "" + }, + "quickInfo": { + "kind": "type", + "kindModifiers": "", + "textSpan": { + "start": 16, + "length": 23 + }, + "displayParts": [ + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "AdditionalWallabyConfig", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "{", + "kind": "punctuation" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "autoDetect", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "boolean", + "kind": "keyword" + }, + { + "text": ";", + "kind": "punctuation" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "}", + "kind": "punctuation" + } + ], + "documentation": [ + { + "text": "Additional valid Wallaby config properties\nthat aren't defined in ", + "kind": "text" + }, + { + "text": "{@link ", + "kind": "link" + }, + { + "text": "IWallabyConfig ", + "kind": "linkText" + }, + { + "text": "}", + "kind": "link" + }, + { + "text": ".", + "kind": "text" + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoLink2.ts b/tests/cases/fourslash/quickInfoLink2.ts new file mode 100644 index 00000000000..4713446b903 --- /dev/null +++ b/tests/cases/fourslash/quickInfoLink2.ts @@ -0,0 +1,12 @@ +/// + +// @checkJs: true +// @Filename: quickInfoLink2.js +//// /** +//// * @typedef AdditionalWallabyConfig/**/ Additional valid Wallaby config properties +//// * that aren't defined in {@link IWallabyConfig}. +//// * @property {boolean} autoDetect +//// */ + +verify.noErrors() +verify.baselineQuickInfo();