Fix invalid codegen for number member expr
This commit is contained in:
@@ -221,14 +221,8 @@ export function MemberExpression(node: Object) {
|
|||||||
this.print(node.property, node);
|
this.print(node.property, node);
|
||||||
this.push("]");
|
this.push("]");
|
||||||
} else {
|
} else {
|
||||||
if (t.isLiteral(node.object) && !t.isTemplateLiteral(node.object)) {
|
if (t.isNumericLiteral(node.object)) {
|
||||||
let val;
|
let val = this.getPossibleRaw(node.object) || node.object.value;
|
||||||
if (this.format.minified) {
|
|
||||||
val = this._stringLiteral(node.object);
|
|
||||||
} else {
|
|
||||||
val = this.getPossibleRaw(node.object) || this._stringLiteral(node.object);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !ZERO_DECIMAL_INTEGER.test(val) && !this.endsWith(".")) {
|
if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !ZERO_DECIMAL_INTEGER.test(val) && !this.endsWith(".")) {
|
||||||
this.push(".");
|
this.push(".");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ suite("generation", function () {
|
|||||||
assert.ok(t.VISITOR_KEYS[type], type + " should not exist");
|
assert.ok(t.VISITOR_KEYS[type], type + " should not exist");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("valid code", function() {
|
||||||
|
// Should not generate `0.foo`
|
||||||
|
new Function(generate.default(t.memberExpression(t.numericLiteral(60702), t.identifier("foo"))).code);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var suites = require("babel-helper-fixtures").default(__dirname + "/fixtures");
|
var suites = require("babel-helper-fixtures").default(__dirname + "/fixtures");
|
||||||
|
|||||||
Reference in New Issue
Block a user