Merge pull request #3170 from babel/fix-numeric-member-expr
Fix invalid codegen for number member expr
This commit is contained in:
commit
4bb7dbabb0
@ -221,14 +221,8 @@ export function MemberExpression(node: Object) {
|
||||
this.print(node.property, node);
|
||||
this.push("]");
|
||||
} else {
|
||||
if (t.isLiteral(node.object) && !t.isTemplateLiteral(node.object)) {
|
||||
let val;
|
||||
if (this.format.minified) {
|
||||
val = this._stringLiteral(node.object);
|
||||
} else {
|
||||
val = this.getPossibleRaw(node.object) || this._stringLiteral(node.object);
|
||||
}
|
||||
|
||||
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(".")) {
|
||||
this.push(".");
|
||||
}
|
||||
|
||||
@ -16,6 +16,12 @@ suite("generation", function () {
|
||||
assert.ok(t.VISITOR_KEYS[type], type + " should not exist");
|
||||
});
|
||||
});
|
||||
|
||||
test("valid code", function() {
|
||||
// Should not generate `0.foo`
|
||||
var mem = t.memberExpression(t.numericLiteral(60702), t.identifier("foo"));
|
||||
new Function(generate.default(mem).code);
|
||||
});
|
||||
});
|
||||
|
||||
var suites = require("babel-helper-fixtures").default(__dirname + "/fixtures");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user