Fix prefix double underscore with extra underscore

This commit is contained in:
Yui T
2015-12-20 16:39:42 -08:00
committed by Kanchalai Tanglertsampan
parent 05803f5285
commit 7bd336d0c6

View File

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