Merge pull request #3379 from babel/memexp-numliteral

Fix: invalid codegen for non decimal numeric literals in MemberExpression
This commit is contained in:
Henry Zhu 2016-02-29 11:40:30 -05:00
commit 66ea5342de
3 changed files with 16 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import * as n from "../node";
const SCIENTIFIC_NOTATION = /e/i;
const ZERO_DECIMAL_INTEGER = /\.0+$/;
const NON_DECIMAL_LITERAL = /^0[box]/;
export function UnaryExpression(node) {
let needsSpace = /[a-z]$/.test(node.operator);
@ -224,7 +225,11 @@ export function MemberExpression(node) {
} else {
if (t.isNumericLiteral(node.object)) {
let val = this.getPossibleRaw(node.object) || node.object.value;
if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !ZERO_DECIMAL_INTEGER.test(val) && !this.endsWith(".")) {
if (isInteger(+val) &&
!NON_DECIMAL_LITERAL.test(val) &&
!SCIENTIFIC_NOTATION.test(val) &&
!ZERO_DECIMAL_INTEGER.test(val) &&
!this.endsWith(".")) {
this.push(".");
}
}

View File

@ -0,0 +1,5 @@
1..toString;
2..toString();
0x1F7.toString();
0b111110111.toString();
0o767.toString();

View File

@ -0,0 +1,5 @@
1..toString;
2..toString();
0x1F7.toString();
0b111110111.toString();
0o767.toString();