expose escapeLeadingUnderscores

Fixes: #25343
This commit is contained in:
Klaus Meinhardt 2018-07-26 14:20:48 +02:00
parent 2b14bcbb56
commit b057bf9f01
3 changed files with 9 additions and 5 deletions

View File

@ -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.
*

View File

@ -3184,6 +3184,8 @@ declare namespace ts {
* @returns The original parse tree node if found; otherwise, undefined.
*/
function getParseTreeNode<T extends Node>(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.
*

View File

@ -3184,6 +3184,8 @@ declare namespace ts {
* @returns The original parse tree node if found; otherwise, undefined.
*/
function getParseTreeNode<T extends Node>(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.
*