Skip to content

Commit ab8adc5

Browse files
authored
fix(37135): handle PrivateIdentifiers in isPropertyName (#37184)
1 parent b9c0999 commit ab8adc5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/compiler/utilitiesPublic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,7 @@ namespace ts {
18151815
export function isPropertyName(node: Node): node is PropertyName {
18161816
const kind = node.kind;
18171817
return kind === SyntaxKind.Identifier
1818+
|| kind === SyntaxKind.PrivateIdentifier
18181819
|| kind === SyntaxKind.StringLiteral
18191820
|| kind === SyntaxKind.NumericLiteral
18201821
|| kind === SyntaxKind.ComputedPropertyName;

src/testRunner/unittests/publicApi.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ describe("Public APIs:: token to string", () => {
4646
assertDefinedTokenToString(ts.SyntaxKind.FirstKeyword, ts.SyntaxKind.LastKeyword);
4747
});
4848
});
49+
4950
describe("Public APIs:: createPrivateIdentifier", () => {
5051
it("throws when name doesn't start with #", () => {
51-
assert.throw(() => ts.createPrivateIdentifier("not"), "Debug Failure. First character of private identifier must be #: not");
52+
assert.throw(() => ts.createPrivateIdentifier("not"), "Debug Failure. First character of private identifier must be #: not");
53+
});
54+
});
55+
56+
describe("Public APIs:: isPropertyName", () => {
57+
it("checks if a PrivateIdentifier is a valid property name", () => {
58+
const prop = ts.createPrivateIdentifier("#foo");
59+
assert.isTrue(ts.isPropertyName(prop), "PrivateIdentifier must be a valid property name.");
5260
});
5361
});

0 commit comments

Comments
 (0)