forked from babel/babel
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
37 lines (33 loc) 路 1015 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { declare } from "@babel/helper-plugin-utils";
import type { NodePath } from "@babel/traverse";
import type * as t from "@babel/types";
/**
* Given a bigIntLiteral or NumericLiteral, remove numeric
* separator `_` from its raw representation
*
* @param {NodePath<BigIntLiteral | NumericLiteral>} { node }: A Babel AST node path
*/
function remover({ node }: NodePath<t.BigIntLiteral | t.NumericLiteral>) {
const { extra } = node;
// @ts-expect-error todo(flow->ts)
if (extra?.raw?.includes("_")) {
// @ts-expect-error todo(flow->ts)
extra.raw = extra.raw.replace(/_/g, "");
}
}
export default declare(api => {
api.assertVersion(7);
return {
name: "transform-numeric-separator",
inherits: USE_ESM
? undefined
: IS_STANDALONE
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-numeric-separator").default,
visitor: {
NumericLiteral: remover,
BigIntLiteral: remover,
},
};
});