From 7f540b75520e01316f208e1cde8bd3c9ccc65fae Mon Sep 17 00:00:00 2001 From: Martin Man Date: Tue, 8 Oct 2024 16:40:37 +0200 Subject: [PATCH] fix: transform JS bigint literal `XXXn` to `BigInt("XXX")` --- config/babel-plugin-transform-bigint.js | 20 ++++++++++++++++++++ config/webpack.config.js | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 config/babel-plugin-transform-bigint.js diff --git a/config/babel-plugin-transform-bigint.js b/config/babel-plugin-transform-bigint.js new file mode 100644 index 00000000..f0aae4dd --- /dev/null +++ b/config/babel-plugin-transform-bigint.js @@ -0,0 +1,20 @@ +// babel-plugin-transform-bigint.js +module.exports = function(babel) { + const { types: t } = babel; + + return { + name: "babel-plugin-transform-bigint", + visitor: { + BigIntLiteral(path) { + const value = path.node.value; + // Replace BigInt literal with a call to BigInt constructor + path.replaceWith( + t.callExpression( + t.identifier('BigInt'), + [t.stringLiteral(value)] + ) + ); + } + } + }; +}; diff --git a/config/webpack.config.js b/config/webpack.config.js index 893f3d87..ade2de7b 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -429,6 +429,9 @@ module.exports = function (webpackEnv) { // show incorrect code and set breakpoints on the wrong lines. sourceMaps: shouldUseSourceMap, inputSourceMap: shouldUseSourceMap, + plugins: [ + [require.resolve("./babel-plugin-transform-bigint.js")] + ], }, }, // "postcss" loader applies autoprefixer to our CSS.