Skip to content

Commit

Permalink
fix: transform JS bigint literal XXXn to BigInt("XXX")
Browse files Browse the repository at this point in the history
  • Loading branch information
mman committed Oct 8, 2024
1 parent b6f1de2 commit 7f540b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions config/babel-plugin-transform-bigint.js
Original file line number Diff line number Diff line change
@@ -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)]
)
);
}
}
};
};
3 changes: 3 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7f540b7

Please sign in to comment.