Skip to content

Commit 89c572c

Browse files
authored
Fixed a symbol display crash on expando members write locations (#55478)
1 parent 7b26d2e commit 89c572c

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/services/symbolDisplay.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AccessorDeclaration,
23
addRange,
34
arrayFrom,
45
BinaryExpression,
@@ -16,7 +17,6 @@ import {
1617
first,
1718
firstDefined,
1819
forEach,
19-
GetAccessorDeclaration,
2020
getCombinedLocalAndExportSymbolFlags,
2121
getDeclarationOfKind,
2222
getExternalModuleImportEqualsDeclarationExpression,
@@ -83,7 +83,6 @@ import {
8383
ScriptElementKind,
8484
ScriptElementKindModifier,
8585
SemanticMeaning,
86-
SetAccessorDeclaration,
8786
Signature,
8887
SignatureDeclaration,
8988
SignatureFlags,
@@ -276,7 +275,14 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker: Type
276275
if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Class || symbolFlags & SymbolFlags.Alias) {
277276
// If symbol is accessor, they are allowed only if location is at declaration identifier of the accessor
278277
if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) {
279-
const declaration = find(symbol.declarations as ((GetAccessorDeclaration | SetAccessorDeclaration | PropertyDeclaration)[]), declaration => declaration.name === location);
278+
const declaration = find(
279+
symbol.declarations as (AccessorDeclaration | PropertyDeclaration | PropertyAccessExpression)[],
280+
(declaration): declaration is AccessorDeclaration | PropertyDeclaration =>
281+
declaration.name === location
282+
// an expando member could have been added to an object with a set accessor
283+
// we need to ignore such write location as it shouldn't be displayed as `(setter)` anyway
284+
&& declaration.kind !== SyntaxKind.PropertyAccessExpression,
285+
);
280286
if (declaration) {
281287
switch (declaration.kind) {
282288
case SyntaxKind.GetAccessor:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @strict: true
4+
// @checkJs: true
5+
// @filename: index.js
6+
7+
//// const x = {};
8+
////
9+
//// Object.defineProperty(x, "foo", {
10+
//// /** @param {number} v */
11+
//// set(v) {},
12+
//// });
13+
////
14+
//// x.foo/**/ = 1;
15+
16+
verify.quickInfoAt("", "(property) x.foo: number");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @strict: true
4+
// @checkJs: true
5+
// @filename: index.js
6+
7+
//// const obj = {};
8+
//// let val = 10;
9+
//// Object.defineProperty(obj, "a", {
10+
//// configurable: true,
11+
//// enumerable: true,
12+
//// set(v) {
13+
//// val = v;
14+
//// },
15+
//// });
16+
////
17+
//// obj.a/**/ = 100;
18+
19+
verify.quickInfoAt("", "(property) obj.a: any");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy