Fix invalid codegen for non decimal numeric literals in MemberExpression
Fixes T7156
This commit is contained in:
parent
6aff776124
commit
35ed18f628
@ -8,6 +8,7 @@ import * as n from "../node";
|
|||||||
|
|
||||||
const SCIENTIFIC_NOTATION = /e/i;
|
const SCIENTIFIC_NOTATION = /e/i;
|
||||||
const ZERO_DECIMAL_INTEGER = /\.0+$/;
|
const ZERO_DECIMAL_INTEGER = /\.0+$/;
|
||||||
|
const NON_DECIMAL_LITERAL = /^0[box]/;
|
||||||
|
|
||||||
export function UnaryExpression(node: Object) {
|
export function UnaryExpression(node: Object) {
|
||||||
let needsSpace = /[a-z]$/.test(node.operator);
|
let needsSpace = /[a-z]$/.test(node.operator);
|
||||||
@ -225,7 +226,11 @@ export function MemberExpression(node: Object) {
|
|||||||
} else {
|
} else {
|
||||||
if (t.isNumericLiteral(node.object)) {
|
if (t.isNumericLiteral(node.object)) {
|
||||||
let val = this.getPossibleRaw(node.object) || node.object.value;
|
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(".");
|
this.push(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
packages/babel-generator/test/fixtures/edgecase/member-expression-numeric-literals/actual.js
vendored
Normal file
5
packages/babel-generator/test/fixtures/edgecase/member-expression-numeric-literals/actual.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
1..toString;
|
||||||
|
2..toString();
|
||||||
|
0x1F7.toString();
|
||||||
|
0b111110111.toString();
|
||||||
|
0o767.toString();
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
1..toString;
|
||||||
|
2..toString();
|
||||||
|
0x1F7.toString();
|
||||||
|
0b111110111.toString();
|
||||||
|
0o767.toString();
|
||||||
Loading…
x
Reference in New Issue
Block a user