Skip to content

Commit 7bd336d

Browse files
author
Yui T
committed
Fix prefix double underscore with extra underscore
1 parent 05803f5 commit 7bd336d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/compiler/utilities.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,19 @@ namespace ts {
230230
return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node, includeTrivia);
231231
}
232232

233+
function prefixWithUnderscoreUnderscore(identifier: string): boolean {
234+
if (identifier.length <= 2) {
235+
return false;
236+
}
237+
else {
238+
return identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? true : false;
239+
}
240+
}
241+
233242
// Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__'
243+
// TODO(yuisu): comment
234244
export function escapeIdentifier(identifier: string): string {
235-
return identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier;
245+
return prefixWithUnderscoreUnderscore(identifier)? "_" + identifier : identifier;
236246
}
237247

238248
// Remove extra underscore from escaped identifier

0 commit comments

Comments
 (0)