Harden against trees without parent pointers for emitting literals; fix lookahead in text for numeric literal indicators.

This commit is contained in:
Daniel Rosenwasser 2015-03-02 15:51:23 -08:00
parent 6be13a90b5
commit 5ec68eb0e4

View File

@ -2178,15 +2178,17 @@ module ts {
}
}
function isBinaryOrOctalIntegerLiteral(text: string): boolean {
if (text.length <= 0) {
return false;
}
if (text.charCodeAt(1) === CharacterCodes.B || text.charCodeAt(1) === CharacterCodes.b ||
text.charCodeAt(1) === CharacterCodes.O || text.charCodeAt(1) === CharacterCodes.o) {
return true;
function isBinaryOrOctalIntegerLiteral(node: LiteralExpression, text: string): boolean {
if (node.kind === SyntaxKind.NumericLiteral && text.length > 1) {
switch (text.charCodeAt(1)) {
case CharacterCodes.b:
case CharacterCodes.B:
case CharacterCodes.o:
case CharacterCodes.O:
return true;
}
}
return false;
}
@ -2195,13 +2197,15 @@ module ts {
? getDoubleQuotedStringTextOfLiteral(node)
: node.parent
? getSourceTextOfNodeFromSourceFile(currentSourceFile, node)
: node.text; // TODO(drosen): Is this correct?
: node.kind === SyntaxKind.NumericLiteral
? node.text
: getDoubleQuotedStringTextOfLiteral(node);
if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) {
writer.writeLiteral(text);
}
// For version below ES6, emit binary integer literal and octal integer literal in canonical form
else if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.NumericLiteral && isBinaryOrOctalIntegerLiteral(text)) {
// For versions below ES6, emit binary & octal literals in their canonical decimal form.
else if (languageVersion < ScriptTarget.ES6 && isBinaryOrOctalIntegerLiteral(node, text)) {
write(node.text);
}
else {