@babel/plugin-syntax-bigint is a Babel syntax plugin that enables parsing of BigInt literals in JavaScript code. This is a syntax-only plugin that doesn't transform code but allows Babel to recognize and parse BigInt literal syntax (e.g., 123n). The plugin was designed to provide BigInt syntax support before it became part of the default parser configuration.
npm install --save-dev @babel/plugin-syntax-bigint// Default import (the plugin factory function)
import plugin from "@babel/plugin-syntax-bigint";For CommonJS:
const plugin = require("@babel/plugin-syntax-bigint");This plugin is used by adding it to your Babel configuration, not imported directly in your code:
{
"plugins": ["@babel/plugin-syntax-bigint"]
}Or with options:
// babel.config.js
module.exports = {
plugins: [
["@babel/plugin-syntax-bigint"]
]
};Once enabled, your code can use BigInt literals:
// This syntax becomes parseable with the plugin
const bigNumber = 123456789012345678901234567890n;
const anotherBig = BigInt("123456789012345678901234567890");The main export is a Babel plugin factory function that creates the syntax plugin.
/**
* Creates a Babel plugin that enables BigInt literal syntax parsing
* @param {Object} api - Babel API object with version assertion capabilities
* @returns {Object} Plugin configuration object
*/
function plugin(api: BabelAPI): BabelPlugin;
interface BabelAPI {
assertVersion(version: number): void;
}
interface BabelPlugin {
name: string;
manipulateOptions(opts: BabelOptions, parserOpts: ParserOptions): void;
}
interface BabelOptions {
[key: string]: any;
}
interface ParserOptions {
plugins: string[];
}Plugin Properties:
"syntax-bigint" - Plugin identifierThe plugin works by modifying Babel's parser options to include BigInt syntax support.
/**
* Modifies parser options to enable BigInt literal parsing
* @param {Object} opts - Babel transformation options
* @param {Object} parserOpts - Parser-specific options with plugins array
*/
manipulateOptions(opts: BabelOptions, parserOpts: ParserOptions): void;Behavior: Pushes "bigInt" string to the parserOpts.plugins array, enabling the parser to recognize BigInt literal syntax.
@babel/helper-plugin-utils@babel/core ^7.0.0-0 as a peer dependencyIn newer Babel versions (7.8.3+), BigInt literal parsing is enabled by default, making this plugin unnecessary for most modern projects. This plugin should only be used when: