Skip to content

Commit d9cd2d0

Browse files
authored
Fixed a crash in getPropertyNameForPropertyNameNode on NoSubstitutionTemplateLiteral (#55930)
1 parent 13a2150 commit d9cd2d0

8 files changed

+58
-3
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17727,7 +17727,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1772717727
return false;
1772817728
}
1772917729

17730-
function getPropertyNameFromIndex(indexType: Type, accessNode: StringLiteral | Identifier | PrivateIdentifier | ObjectBindingPattern | ArrayBindingPattern | ComputedPropertyName | NumericLiteral | IndexedAccessTypeNode | ElementAccessExpression | SyntheticExpression | undefined) {
17730+
function getPropertyNameFromIndex(indexType: Type, accessNode: PropertyName | ObjectBindingPattern | ArrayBindingPattern | IndexedAccessTypeNode | ElementAccessExpression | SyntheticExpression | undefined) {
1773117731
return isTypeUsableAsPropertyName(indexType) ?
1773217732
getPropertyNameFromType(indexType) :
1773317733
accessNode && isPropertyName(accessNode) ?

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ export interface QualifiedName extends Node, FlowContainer {
16921692

16931693
export type EntityName = Identifier | QualifiedName;
16941694

1695-
export type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier;
1695+
export type PropertyName = Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier;
16961696

16971697
export type MemberName = Identifier | PrivateIdentifier;
16981698

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5062,6 +5062,7 @@ export function getPropertyNameForPropertyNameNode(name: PropertyName | JsxAttri
50625062
case SyntaxKind.PrivateIdentifier:
50635063
return name.escapedText;
50645064
case SyntaxKind.StringLiteral:
5065+
case SyntaxKind.NoSubstitutionTemplateLiteral:
50655066
case SyntaxKind.NumericLiteral:
50665067
return escapeLeadingUnderscores(name.text);
50675068
case SyntaxKind.ComputedPropertyName:

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4976,7 +4976,7 @@ declare namespace ts {
49764976
readonly right: Identifier;
49774977
}
49784978
type EntityName = Identifier | QualifiedName;
4979-
type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier;
4979+
type PropertyName = Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier;
49804980
type MemberName = Identifier | PrivateIdentifier;
49814981
type DeclarationName = PropertyName | JsxAttributeName | StringLiteralLike | ElementAccessExpression | BindingPattern | EntityNameExpression;
49824982
interface Declaration extends Node {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/indexTypeNoSubstitutionTemplateLiteral.ts] ////
2+
3+
//// [indexTypeNoSubstitutionTemplateLiteral.ts]
4+
function Foo() {}
5+
Foo[`b`] = function () {};
6+
7+
type Test = keyof typeof Foo;
8+
9+
10+
11+
//// [indexTypeNoSubstitutionTemplateLiteral.js]
12+
"use strict";
13+
function Foo() { }
14+
Foo["b"] = function () { };
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [tests/cases/compiler/indexTypeNoSubstitutionTemplateLiteral.ts] ////
2+
3+
=== indexTypeNoSubstitutionTemplateLiteral.ts ===
4+
function Foo() {}
5+
>Foo : Symbol(Foo, Decl(indexTypeNoSubstitutionTemplateLiteral.ts, 0, 0), Decl(indexTypeNoSubstitutionTemplateLiteral.ts, 0, 17))
6+
7+
Foo[`b`] = function () {};
8+
>Foo : Symbol(Foo, Decl(indexTypeNoSubstitutionTemplateLiteral.ts, 0, 0), Decl(indexTypeNoSubstitutionTemplateLiteral.ts, 0, 17))
9+
>`b` : Symbol(Foo[`b`], Decl(indexTypeNoSubstitutionTemplateLiteral.ts, 0, 17))
10+
11+
type Test = keyof typeof Foo;
12+
>Test : Symbol(Test, Decl(indexTypeNoSubstitutionTemplateLiteral.ts, 1, 26))
13+
>Foo : Symbol(Foo, Decl(indexTypeNoSubstitutionTemplateLiteral.ts, 0, 0), Decl(indexTypeNoSubstitutionTemplateLiteral.ts, 0, 17))
14+
15+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/indexTypeNoSubstitutionTemplateLiteral.ts] ////
2+
3+
=== indexTypeNoSubstitutionTemplateLiteral.ts ===
4+
function Foo() {}
5+
>Foo : typeof Foo
6+
7+
Foo[`b`] = function () {};
8+
>Foo[`b`] = function () {} : () => void
9+
>Foo[`b`] : () => void
10+
>Foo : typeof Foo
11+
>`b` : "b"
12+
>function () {} : () => void
13+
14+
type Test = keyof typeof Foo;
15+
>Test : "b"
16+
>Foo : typeof Foo
17+
18+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @strict: true
2+
3+
function Foo() {}
4+
Foo[`b`] = function () {};
5+
6+
type Test = keyof typeof Foo;
7+

0 commit comments

Comments
 (0)