mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Fix prefix double underscore with extra underscore
This commit is contained in:
committed by
Kanchalai Tanglertsampan
parent
05803f5285
commit
7bd336d0c6
@@ -230,9 +230,19 @@ namespace ts {
|
||||
return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node, includeTrivia);
|
||||
}
|
||||
|
||||
function prefixWithUnderscoreUnderscore(identifier: string): boolean {
|
||||
if (identifier.length <= 2) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__'
|
||||
// TODO(yuisu): comment
|
||||
export function escapeIdentifier(identifier: string): string {
|
||||
return identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier;
|
||||
return prefixWithUnderscoreUnderscore(identifier)? "_" + identifier : identifier;
|
||||
}
|
||||
|
||||
// Remove extra underscore from escaped identifier
|
||||
|
||||
Reference in New Issue
Block a user