Skip to content

Commit c42ef57

Browse files
authored
createPrivateIdentifier: names must start with # (microsoft#36506)
1 parent 0cf100d commit c42ef57

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/compiler/factoryPublic.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ namespace ts {
218218

219219
// Private Identifiers
220220
export function createPrivateIdentifier(text: string): PrivateIdentifier {
221+
if (text[0] !== "#") {
222+
Debug.fail("First character of private identifier must be #: " + text);
223+
}
221224
const node = createSynthesizedNode(SyntaxKind.PrivateIdentifier) as PrivateIdentifier;
222225
node.escapedText = escapeLeadingUnderscores(text);
223226
return node;

src/testRunner/unittests/publicApi.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ describe("Public APIs:: token to string", () => {
4646
assertDefinedTokenToString(ts.SyntaxKind.FirstKeyword, ts.SyntaxKind.LastKeyword);
4747
});
4848
});
49+
describe("Public APIs:: createPrivateIdentifier", () => {
50+
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+
});
53+
});

0 commit comments

Comments
 (0)