diff --git a/src/compiler/factoryPublic.ts b/src/compiler/factoryPublic.ts index 19e927f4f66..2c59abbb494 100644 --- a/src/compiler/factoryPublic.ts +++ b/src/compiler/factoryPublic.ts @@ -218,6 +218,9 @@ namespace ts { // Private Identifiers export function createPrivateIdentifier(text: string): PrivateIdentifier { + if (text[0] !== "#") { + Debug.fail("First character of private identifier must be #: " + text); + } const node = createSynthesizedNode(SyntaxKind.PrivateIdentifier) as PrivateIdentifier; node.escapedText = escapeLeadingUnderscores(text); return node; diff --git a/src/testRunner/unittests/publicApi.ts b/src/testRunner/unittests/publicApi.ts index a31104de62a..c8f380129c6 100644 --- a/src/testRunner/unittests/publicApi.ts +++ b/src/testRunner/unittests/publicApi.ts @@ -46,3 +46,8 @@ describe("Public APIs:: token to string", () => { assertDefinedTokenToString(ts.SyntaxKind.FirstKeyword, ts.SyntaxKind.LastKeyword); }); }); +describe("Public APIs:: createPrivateIdentifier", () => { + it("throws when name doesn't start with #", () => { + assert.throw(() => ts.createPrivateIdentifier("not"), "Debug Failure. First character of private identifier must be #: not"); + }); +});