Support navTo for special assignment kinds (#18154)
* Support navTo for special assignment kinds * Return ScriptElementKind.unknown
This commit is contained in:
parent
b533b24686
commit
7541c705bf
|
@ -2628,4 +2628,6 @@ namespace ts {
|
|||
export function and<T>(f: (arg: T) => boolean, g: (arg: T) => boolean) {
|
||||
return (arg: T) => f(arg) && g(arg);
|
||||
}
|
||||
|
||||
export function assertTypeIsNever(_: never): void {}
|
||||
}
|
||||
|
|
|
@ -722,6 +722,12 @@ namespace ts {
|
|||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.BinaryExpression:
|
||||
if (getSpecialPropertyAssignmentKind(node as BinaryExpression) !== SpecialPropertyAssignmentKind.None) {
|
||||
addDeclaration(node as BinaryExpression);
|
||||
}
|
||||
// falls through
|
||||
|
||||
default:
|
||||
forEachChild(node, visit);
|
||||
}
|
||||
|
|
|
@ -343,6 +343,28 @@ namespace ts {
|
|||
return ScriptElementKind.alias;
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
return ScriptElementKind.typeElement;
|
||||
case SyntaxKind.BinaryExpression:
|
||||
const kind = getSpecialPropertyAssignmentKind(node as BinaryExpression);
|
||||
const { right } = node as BinaryExpression;
|
||||
switch (kind) {
|
||||
case SpecialPropertyAssignmentKind.None:
|
||||
return ScriptElementKind.unknown;
|
||||
case SpecialPropertyAssignmentKind.ExportsProperty:
|
||||
case SpecialPropertyAssignmentKind.ModuleExports:
|
||||
const rightKind = getNodeKind(right);
|
||||
return rightKind === ScriptElementKind.unknown ? ScriptElementKind.constElement : rightKind;
|
||||
case SpecialPropertyAssignmentKind.PrototypeProperty:
|
||||
return ScriptElementKind.memberFunctionElement; // instance method
|
||||
case SpecialPropertyAssignmentKind.ThisProperty:
|
||||
return ScriptElementKind.memberVariableElement; // property
|
||||
case SpecialPropertyAssignmentKind.Property:
|
||||
// static method / property
|
||||
return isFunctionExpression(right) ? ScriptElementKind.memberFunctionElement : ScriptElementKind.memberVariableElement;
|
||||
default: {
|
||||
assertTypeIsNever(kind);
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
}
|
||||
default:
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @allowJs: true
|
||||
// @Filename: /a.js
|
||||
////exports.{| "name": "x", "kind": "const" |}x = 0;
|
||||
////exports.{| "name": "y", "kind": "function" |}y = function() {};
|
||||
////function Cls() {
|
||||
//// this.{| "name": "prop", "kind": "property" |}prop = 0;
|
||||
////}
|
||||
////Cls.{| "name": "staticMethod", "kind": "method" |}staticMethod = function() {};
|
||||
////Cls.{| "name": "staticProperty", "kind": "property" |}staticProperty = 0;
|
||||
////Cls.prototype.{| "name": "instance", "kind": "method" |}instance = function() {};
|
||||
|
||||
for (const marker of test.markers()) {
|
||||
verify.navigationItemsListContains(
|
||||
marker.data.name,
|
||||
marker.data.kind,
|
||||
marker.data.name,
|
||||
"exact");
|
||||
}
|
Loading…
Reference in a new issue