Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2630,4 +2630,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 {}
}
6 changes: 6 additions & 0 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
22 changes: 22 additions & 0 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,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;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/cases/fourslash/navigationItemsSpecialPropertyAssignment.ts
Original file line number Diff line number Diff line change
@@ -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");
}