createPrivateIdentifier: names must start with # (#36506)

This commit is contained in:
Nathan Shively-Sanders 2020-01-29 10:11:30 -08:00 committed by GitHub
parent 0cf100dcf8
commit c42ef575be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -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;

View File

@ -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");
});
});