From ac390fe7b542f87abb535f5372c7369081aa4cd3 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 21 Jan 2016 16:16:52 -0800 Subject: [PATCH] Address PR --- src/compiler/emitter.ts | 2 +- src/compiler/utilities.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f015af92a9f..d35a723a093 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3889,7 +3889,7 @@ 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 = createSynthesizedNode(propName.kind); - // We need to escape identifier here because when parsing an identifier prefixing with "__" + // We need to unescape 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) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8f1c05adabe..4bf1422e888 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -232,8 +232,7 @@ namespace ts { // 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 { - const prefixedWithUnderscores = identifier.length >= 3 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._; - return prefixedWithUnderscores ? "_" + identifier : identifier; + return identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier; } // Remove extra underscore from escaped identifier