diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index fbe37e73e9e..4ae7963b06c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -563,11 +563,6 @@ namespace ts { return isString(value) ? '"' + escapeNonAsciiString(value) + '"' : "" + value; } - // Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' - export function escapeLeadingUnderscores(identifier: string): __String { - return (identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier) as __String; - } - // Make an identifier from an external module name by extracting the string after the last "/" and replacing // all non-alphanumeric characters with underscores export function makeIdentifierFromModuleName(moduleName: string): string { @@ -4792,6 +4787,11 @@ namespace ts { return undefined; } + /** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */ + export function escapeLeadingUnderscores(identifier: string): __String { + return (identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier) as __String; + } + /** * Remove extra underscore from escaped identifier text content. * diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 99a9c3b6100..3aee996cd20 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3184,6 +3184,8 @@ declare namespace ts { * @returns The original parse tree node if found; otherwise, undefined. */ function getParseTreeNode(node: Node | undefined, nodeTest?: (node: Node) => node is T): T | undefined; + /** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */ + function escapeLeadingUnderscores(identifier: string): __String; /** * Remove extra underscore from escaped identifier text content. * diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 41510d5192b..fa101c24a1f 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3184,6 +3184,8 @@ declare namespace ts { * @returns The original parse tree node if found; otherwise, undefined. */ function getParseTreeNode(node: Node | undefined, nodeTest?: (node: Node) => node is T): T | undefined; + /** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */ + function escapeLeadingUnderscores(identifier: string): __String; /** * Remove extra underscore from escaped identifier text content. *