10000 Fixed crash in `findAllReferences` caused by a `StringLiteral`-like w… · Andarist/TypeScript@38551b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 38551b1

Browse files
committed
Fixed crash in findAllReferences caused by a StringLiteral-like without text
1 parent dd1e258 commit 38551b1

File tree

3 files changed

+126
-5
lines changed

3 files changed

+126
-5
lines changed

src/services/services.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,24 @@ import * as classifier2020 from "./classifier2020.js";
361361
/** The version of the language service API */
362362
export const servicesVersion = "0.8";
363363

364-
function createNode<TKind extends SyntaxKind>(kind: TKind, pos: number, end: number, parent: Node): NodeObject< 10000 span class=pl-c1><TKind> | TokenObject<TKind> | IdentifierObject | PrivateIdentifierObject {
365-
const node = isNodeKind(kind) ? new NodeObject(kind, pos, end) :
366-
kind === SyntaxKind.Identifier ? new IdentifierObject(SyntaxKind.Identifier, pos, end) :
367-
kind === SyntaxKind.PrivateIdentifier ? new PrivateIdentifierObject(SyntaxKind.PrivateIdentifier, pos, end) :
368-
new TokenObject(kind, pos, end);
364+
function createNode<TKind extends SyntaxKind>(kind: TKind, pos: number, end: number, parent: Node): NodeObject<TKind> | TokenObject<TKind> | IdentifierObject | PrivateIdentifierObject | StringLiteralObject {
365+
let node;
366+
if (isNodeKind(kind)) {
367+
node = new NodeObject(kind, pos, end);
368+
}
369+
else if (kind === SyntaxKind.Identifier) {
370+
node = new IdentifierObject(SyntaxKind.Identifier, pos, end);
371+
}
372+
else if (kind === SyntaxKind.PrivateIdentifier) {
373+
node = new PrivateIdentifierObject(SyntaxKind.PrivateIdentifier, pos, end);
374+
}
375+
else if (kind === SyntaxKind.StringLiteral) {
376+
node = new StringLiteralObject(SyntaxKind.StringLiteral, pos, end);
377+
node.text = scanner.getTokenValue();
378+
}
379+
else {
380+
node = new TokenObject(kind, pos, end);
381+
}
369382
node.parent = parent;
370383
node.flags = parent.flags & NodeFlags.ContextFlags;
371384
return node;
@@ -801,6 +814,22 @@ class TokenObject<TKind extends SyntaxKind> extends TokenOrIdentifierObject<TKin
801814
}
802815
}
803816

817+
class StringLiteralObject extends TokenObject<SyntaxKind.StringLiteral> implements StringLiteral {
818+
public text!: string;
819+
declare _literalExpressionBrand: any;
820+
declare _primaryExpressionBrand: any;
821+
declare _memberExpressionBrand: any;
822+
declare _leftHandSideExpressionBrand: any;
823+
declare _updateExpressionBrand: any;
824+
declare _unaryExpressionBrand: any;
825+
declare _expressionBrand: any;
826+
declare _declarationBrand: any;
827+
828+
constructor(kind: SyntaxKind.StringLiteral, pos: number, end: number) {
829+
super(kind, pos, end);
830+
}
831+
}
832+
804833
class IdentifierObject extends TokenOrIdentifierObject<SyntaxKind.Identifier> implements Identifier {
805834
public escapedText!: __String;
806835
declare _primaryExpressionBrand: any;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// === findAllReferences ===
2+
// === lib.d.ts ===
3+
// --- (line: --) skipped ---
4+
//
5+
// interface Object {
6+
// /** The initial value of Object.prototype.constructor is the standard built-in Object constructor. */
7+
// <|[|{| isWriteAccess: true |}constructor|]: Function;|>
8+
//
9+
// /** Returns a string representation of an object. */
10+
// toString(): string;
11+
// --- (line: --) skipped ---
12+
13+
// === /tests/cases/fourslash/findAllRefsConstructor.ts ===
14+
// class A {
15+
// 'constructor'() { }
16+
// }
17+
// const a = new A()
18+
// console.log(a.[|constructor|]/*FIND ALL REFS*/)
19+
20+
// === Definitions ===
21+
// === lib.d.ts ===
22+
// --- (line: --) skipped ---
23+
//
24+
// interface Object {
25+
// /** The initial value of Object.prototype.constructor is the standard built-in Object constructor. */
26+
// <|[|constructor|]: Function;|>
27+
//
28+
// /** Returns a string representation of an object. */
29+
// toString(): string;
30+
// --- (line: --) skipped ---
31+
32+
// === Details ===
33+
[
34+
{
35+
"containerKind": "",
36+
"containerName": "",
37+
"kind": "property",
38+
"name": "(property) Object.constructor: Function",
39+
"displayParts": [
40+
{
41+
"text": "(",
42+
"kind": "punctuation"
43+
},
44+
{
45+
"text": "property",
46+
"kind": "text"
47+
},
48+
{
49+
"text": ")",
50+
"kind": "punctuation"
51+
},
52+
{
53+
"text": " ",
54+
"kind": "space"
55+
},
56+
{
57+
"text": "Object",
58+
"kind": "localName"
59+
},
60+
{
61+
"text": ".",
62+
"kind": "punctuation"
63+
},
64+
{
65+
"text": "constructor",
66+
"kind": "propertyName"
67+
},
68+
{
69+
"text": ":",
70+
"kind": "punctuation"
71+
},
72+
{
73+
"text": " ",
74+
"kind": "space"
75+
},
76+
{
77+
"text": "Function",
78+
"kind": "localName"
79+
}
80+
]
81+
}
82+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
// @target: esnext
3+
4+
////class A {
5+
//// 'constructor'() { }
6+
////}
7+
////const a = new A()
8+
////console.log(a.constructor/**/)
9+
10+
verify.baselineFindAllReferences('');

0 commit comments

Comments
 (0)
0