Skip to content

Fixed a symbol display crash on expando members write locations #55478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
12 changes: 9 additions & 3 deletions src/services/symbolDisplay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AccessorDeclaration,
addRange,
arrayFrom,
BinaryExpression,
Expand All @@ -16,7 +17,6 @@ import {
first,
firstDefined,
forEach,
GetAccessorDeclaration,
getCombinedLocalAndExportSymbolFlags,
getDeclarationOfKind,
getExternalModuleImportEqualsDeclarationExpression,
Expand Down Expand Up @@ -83,7 +83,6 @@ import {
ScriptElementKind,
ScriptElementKindModifier,
SemanticMeaning,
SetAccessorDeclaration,
Signature,
SignatureDeclaration,
SignatureFlags,
Expand Down Expand Up @@ -276,7 +275,14 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker: Type
if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Class || symbolFlags & SymbolFlags.Alias) {
// If symbol is accessor, they are allowed only if location is at declaration identifier of the accessor
if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) {
const declaration = find(symbol.declarations as ((GetAccessorDeclaration | SetAccessorDeclaration | PropertyDeclaration)[]), declaration => declaration.name === location);
const declaration = find(
symbol.declarations as (AccessorDeclaration | PropertyDeclaration | PropertyAccessExpression)[],
(declaration): declaration is AccessorDeclaration | PropertyDeclaration =>
declaration.name === location
// an expando member could have been added to an object with a set accessor
// we need to ignore such write location as it shouldn't be displayed as `(setter)` anyway
&& declaration.kind !== SyntaxKind.PropertyAccessExpression,
);
if (declaration) {
switch (declaration.kind) {
case SyntaxKind.GetAccessor:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />

// @strict: true
// @checkJs: true
// @filename: index.js

//// const x = {};
////
//// Object.defineProperty(x, "foo", {
//// /** @param {number} v */
//// set(v) {},
//// });
////
//// x.foo/**/ = 1;

verify.quickInfoAt("", "(property) x.foo: number");
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />

// @strict: true
// @checkJs: true
// @filename: index.js

//// const obj = {};
//// let val = 10;
//// Object.defineProperty(obj, "a", {
//// configurable: true,
//// enumerable: true,
//// set(v) {
//// val = v;
//// },
//// });
////
//// obj.a/**/ = 100;

verify.quickInfoAt("", "(property) obj.a: any");