Skip to content

Commit 9e740de

Browse files
authored
Merge pull request microsoft#25965 from ajafff/expose-escapeleadingunderscores
expose escapeLeadingUnderscores
2 parents 9196b7d + b057bf9 commit 9e740de

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 {
@@ -4804,6 +4799,11 @@ namespace ts {
48044799
return undefined;
48054800
}
48064801

4802+
/** Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' */
4803+
export function escapeLeadingUnderscores(identifier: string): __String {
4804+
return (identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier) as __String;
4805+
}
4806+
48074807
/**
48084808
* Remove extra underscore from escaped identifier text content.
48094809
*

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

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

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

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

0 commit comments

Comments
 (0)