UNPKG

1.16 kBMarkdownView Raw
1# babel-plugin-transform-es2015-block-scoping
2
3> Compile ES2015 block scoping (const and let) to ES5
4
5## Installation
6
7```sh
8npm install --save-dev babel-plugin-transform-es2015-block-scoping
9```
10
11## Usage
12
13### Via `.babelrc` (Recommended)
14
15**.babelrc**
16
17Without options:
18
19```json
20{
21 "plugins": ["transform-es2015-block-scoping"]
22}
23```
24
25With options:
26
27```json
28{
29 "plugins": [
30 ["transform-es2015-block-scoping", {
31 "throwIfClosureRequired": true
32 }]
33 ]
34}
35```
36
37### Via CLI
38
39```sh
40babel --plugins transform-es2015-block-scoping script.js
41```
42
43### Via Node API
44
45```javascript
46require("babel-core").transform("code", {
47 plugins: ["transform-es2015-block-scoping"]
48});
49```
50
51## Options `throwIfClosureRequired`
52
53In cases such as the following it's impossible to rewrite let/const without adding an additional function and closure while transforming:
54
55```javascript
56for (let i = 0; i < 5; i++) {
57 setTimeout(() => console.log(i), 1);
58}
59```
60
61In extremely performance-sensitive code, this can be undesirable. If `"throwIfClosureRequired": true` is set, Babel throws when transforming these patterns instead of automatically adding an additional function.