Add test for find-all-refs on string literal types in JsDoc for TypeScript files

This commit is contained in:
Oleksandr T
2022-10-04 23:23:54 +00:00
committed by Daniel Rosenwasser
parent dc8a10ee99
commit 0f92a13d2c
6 changed files with 50 additions and 2 deletions
+3
View File
@@ -2090,6 +2090,9 @@ namespace ts.FindAllReferences {
cancellationToken.throwIfCancellationRequested();
return mapDefined(getPossibleSymbolReferenceNodes(sourceFile, node.text), ref => {
if (isStringLiteralLike(ref) && ref.text === node.text) {
if (ref.flags & (NodeFlags.JSDoc & ~NodeFlags.JavaScriptFile)) {
return undefined;
}
if (type) {
const refType = getContextualTypeFromParentOrAncestorTypeNode(ref, checker);
if (type !== checker.getStringType() && type === refType) {
-2
View File
@@ -790,8 +790,6 @@ namespace ts {
}
export function getContextualTypeFromParentOrAncestorTypeNode(node: Expression, checker: TypeChecker): Type | undefined {
if (node.flags & (NodeFlags.JSDoc & ~NodeFlags.JavaScriptFile)) return undefined;
const contextualType = getContextualTypeFromParent(node, checker);
if (contextualType) return contextualType;
@@ -0,0 +1,38 @@
// === /a.ts ===
// /**
// * @type {"foo" | "bar"}
// */
// let x = "[|foo|]"/*FIND ALL REFS*/
[
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/a.ts",
"kind": "var",
"name": "foo",
"textSpan": {
"start": 42,
"length": 3
},
"displayParts": [
{
"text": "\"foo\"",
"kind": "stringLiteral"
}
]
},
"references": [
{
"textSpan": {
"start": 42,
"length": 3
},
"fileName": "/a.ts",
"isWriteAccess": false,
"isInString": true
}
]
}
]
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />
// @filename: /a.ts
/////**
//// * @type {"foo" | "bar"}
//// */
////let x = "foo"/**/
verify.baselineFindAllReferences("");