Skip to main content

@babel/plugin-proposal-record-and-tuple

安装

¥Installation

npm install --save-dev @babel/plugin-proposal-record-and-tuple

用法

¥Usage

¥With a configuration file (Recommended)

babel.config.json
{
"plugins": ["@babel/plugin-proposal-record-and-tuple"]
}

通过 CLI

¥Via CLI

Shell
$ babel --plugins @babel/plugin-proposal-record-and-tuple script.js

通过 Node API

¥Via Node API

JavaScript
require("@babel/core").transformSync("code", {
plugins: [["@babel/plugin-proposal-record-and-tuple"]],
});

选项

¥Options

importPolyfill

boolean,默认为 false

¥boolean, defaults to false.

默认情况下,此插件仅使用 RecordTuple 全局变量转换提案语法:

¥By default this plugin only transforms the proposal syntax, using the Record and Tuple globals:

JavaScript
let a = #[1, 2, 3];

// ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇

let a = Tuple(1, 2, 3);

你需要加载一个 polyfill,或者你可以传递 "importPolyfill": true 选项将导入注入到 @bloomberg/record-tuple-polyfill,由提案作者维护:

¥You either need to load a polyfill, or you can pass the "importPolyfill": true option to inject imports to @bloomberg/record-tuple-polyfill, maintained by the proposal authors:

babel.config.json
{
"plugins": [
[
"@babel/plugin-proposal-record-and-tuple",
{
"importPolyfill": true
}
]
]
}
JavaScript
let a = #[1, 2, 3];

// ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇

import { Tuple as _Tuple } from "@bloomberg/record-tuple-polyfill";

let a = _Tuple(1, 2, 3);

不要忘记将 @bloomberg/record-tuple-polyfill 添加到你的依赖中!

¥Don't forget to add @bloomberg/record-tuple-polyfill to your dependencies!

polyfillModuleName

string,默认为 "@bloomberg/record-tuple-polyfill"

¥string, defaults to "@bloomberg/record-tuple-polyfill".

如果你希望将导入注入不同于 @bloomberg/record-tuple-polyfill 的 polyfill,你可以使用此选项指定其名称。

¥If you wish to inject imports to a polyfill different from @bloomberg/record-tuple-polyfill, you can use this option to specify its name.

参考

¥References