Skip to content

Commit b057bf9

Browse files
committed
expose escapeLeadingUnderscores
Fixes: microsoft#25343
1 parent 2b14bcb commit b057bf9

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/compiler/utilities.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,6 @@ namespace ts {
563563
return isString(value) ? '"' + escapeNonAsciiString(value) + '"' : "" + value;
564564
}
565565

566-
// Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__'
567-
export function escapeLeadingUnderscores(identifier: string): __String {
568-
return (identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier) as __String;
569-
}
570-
571566
// Make an identifier from an external module name by extracting the string after the last "/" and replacing
572567
// all non-alphanumeric characters with underscores
573568
export function makeIdentifierFromModuleName(moduleName: string): string {
@@ -4792,6 +4787,11 @@ namespace ts {
47924787
return undefined;
47934788
}
47944789

4790+
/** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */
4791+
export function escapeLeadingUnderscores(identifier: string): __String {
4792+
return (identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier) as __String;
4793+
}
4794+
47954795
/**
47964796
* Remove extra underscore from escaped identifier text content.
47974797
*

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,6 +3184,8 @@ declare namespace ts {
31843184
* @returns The original parse tree node if found; otherwise, undefined.
31853185
*/
31863186
function getParseTreeNode<T extends Node>(node: Node | undefined, nodeTest?: (node: Node) => node is T): T | undefined;
3187+
/** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */
3188+
function escapeLeadingUnderscores(identifier: string): __String;
31873189
/**
31883190
* Remove extra underscore from escaped identifier text content.
31893191
*

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,6 +3184,8 @@ declare namespace ts {
31843184
* @returns The original parse tree node if found; otherwise, undefined.
31853185
*/
31863186
function getParseTreeNode<T extends Node>(node: Node | undefined, nodeTest?: (node: Node) => node is T): T | undefined;
3187+
/** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */
3188+
function escapeLeadingUnderscores(identifier: string): __String;
31873189
/**
31883190
* Remove extra underscore from escaped identifier text content.
31893191
*

0 commit comments

Comments
 (0)