account for integers with decimal 0 - fixes #3002

This commit is contained in:
Sebastian McKenzie
2015-11-11 22:11:47 -08:00
parent 74a1b7fce6
commit 139a61e50d
3 changed files with 6 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import * as t from "babel-types";
import n from "../node";
const SCIENTIFIC_NOTATION = /e/i;
const ZERO_DECIMAL_INTEGER = /\.0+$/;
export function UnaryExpression(node: Object) {
let needsSpace = /[a-z]$/.test(node.operator);
@@ -208,7 +209,7 @@ export function MemberExpression(node: Object) {
} else {
if (t.isLiteral(node.object) && !t.isTemplateLiteral(node.object)) {
let val = this.getPossibleRaw(node.object) || this._stringLiteral(node.object);
if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !this.endsWith(".")) {
if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !ZERO_DECIMAL_INTEGER.test(val) && !this.endsWith(".")) {
this.push(".");
}
}

View File

@@ -9,3 +9,5 @@ foo[test()][bar()];
0..toString();
0.5.toString();
1.0.toString();
1.000.toString();

View File

@@ -9,3 +9,5 @@ foo[test()][bar()];
0..toString();
0.5.toString();
1.0.toString();
1.000.toString();