StringNumericLiteral does not include NumericLiteralSeparator (#10938)
This commit is contained in:
parent
771c730fda
commit
7bc22e42f5
@ -1,30 +1,14 @@
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
import syntaxNumericSeparator from "@babel/plugin-syntax-numeric-separator";
|
||||
import { types as t } from "@babel/core";
|
||||
|
||||
export default declare(api => {
|
||||
api.assertVersion(7);
|
||||
|
||||
function replaceNumberArg({ node }) {
|
||||
if (node.callee.name !== "Number") {
|
||||
return;
|
||||
}
|
||||
|
||||
const arg = node.arguments[0];
|
||||
if (!t.isStringLiteral(arg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
arg.value = arg.value.replace(/_/g, "");
|
||||
}
|
||||
|
||||
return {
|
||||
name: "proposal-numeric-separator",
|
||||
inherits: syntaxNumericSeparator,
|
||||
|
||||
visitor: {
|
||||
CallExpression: replaceNumberArg,
|
||||
NewExpression: replaceNumberArg,
|
||||
NumericLiteral({ node }) {
|
||||
const { extra } = node;
|
||||
if (extra && /_/.test(extra.raw)) {
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
expect(Number("1_000")).toBe(Number("1000"));
|
||||
expect(Number("0xAE_BE_CE")).toBe(Number("0xAEBECE"));
|
||||
expect(Number("0b1010_0001_1000_0101")).toBe(Number("0b1010000110000101"));
|
||||
expect(Number("0o0_6_6_6")).toBe(Number("0o0666"));
|
||||
|
||||
expect(new Number("1_000").valueOf()).toBe(new Number("1000").valueOf());
|
||||
expect(new Number("0xAE_BE_CE").valueOf()).toBe(new Number("0xAEBECE").valueOf());
|
||||
expect(new Number("0b1010_0001_1000_0101").valueOf()).toBe(new Number("0b1010000110000101").valueOf());
|
||||
expect(new Number("0o0_6_6_6").valueOf()).toBe(new Number("0o0666").valueOf());
|
||||
|
||||
expect(Number(1_000)).toBe(Number("1000"));
|
||||
expect(Number(0xAE_BE_CE)).toBe(Number("0xAEBECE"));
|
||||
expect(Number(0b1010_0001_1000_0101)).toBe(Number("0b1010000110000101"));
|
||||
expect(Number(0o0_6_6_6)).toBe(Number("0o0666"));
|
||||
|
||||
expect(new Number(1_000).valueOf()).toBe(new Number("1000").valueOf());
|
||||
expect(new Number(0xAE_BE_CE).valueOf()).toBe(new Number("0xAEBECE").valueOf());
|
||||
expect(new Number(0b1010_0001_1000_0101).valueOf()).toBe(new Number("0b1010000110000101").valueOf());
|
||||
expect(new Number(0o0_6_6_6).valueOf()).toBe(new Number("0o0666").valueOf());
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["proposal-numeric-separator"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user