Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Harden against trees without parent pointers for emitting literals; f…
…ix lookahead in text for numeric literal indicators.
  • Loading branch information
DanielRosenwasser committed Mar 2, 2015
commit 5ec68eb0e454cc70f7e339e4a3d23911c61d5833
26 changes: 15 additions & 11 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 {
Expand Down