From c42ef575be0e02687696354f22fe159609682a70 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 29 Jan 2020 10:11:30 -0800 Subject: [PATCH] createPrivateIdentifier: names must start with # (#36506) --- src/compiler/factoryPublic.ts | 3 +++ src/testRunner/unittests/publicApi.ts | 5 +++++ 2 files changed, 8 insertions(+) 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"); + }); +});