Address PR

This commit is contained in:
Yui T
2015-12-21 17:07:18 -08:00
committed by Kanchalai Tanglertsampan
parent 4759cdbf67
commit 540ae01015
2 changed files with 6 additions and 10 deletions

View File

@@ -3889,6 +3889,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
// We create a synthetic copy of the identifier in order to avoid the rewriting that might
// otherwise occur when the identifier is emitted.
index = <Identifier | LiteralExpression>createSynthesizedNode(propName.kind);
// We need to escape identifier here because when parsing an identifier prefixing with "__"
// the parser need to append "_" in order to escape colliding with magic identifiers such as "__proto__"
// Therefore, in order to correctly emit identifiers that are written in original TypeScript file,
// we will unescapeIdentifier to remove additional underscore (if no underscore is added, the function will return original input string)
(<Identifier | LiteralExpression>index).text = unescapeIdentifier((<Identifier | LiteralExpression>propName).text);
}

View File

@@ -230,18 +230,10 @@ 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__'
export function escapeIdentifier(identifier: string): string {
return prefixWithUnderscoreUnderscore(identifier) ? "_" + identifier : identifier;
const prefixWithUnderscore = identifier.length > 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._;
return prefixWithUnderscore ? "_" + identifier : identifier;
}
// Remove extra underscore from escaped identifier