UNPKG

859 BMarkdownView Raw
1# @babel/plugin-check-constants
2
3> Validate ES2015 constants (prevents reassignment of const variables).
4
5## Example
6
7**In**
8
9```js
10const a = 1;
11a = 2;
12```
13
14**Out**
15
16```bash
17repl: "a" is read-only
18 1 | const a = 1;
19> 2 | a = 2;
20 | ^
21```
22
23
24## Installation
25
26```sh
27npm install --save-dev @babel/plugin-check-constants
28```
29
30## Usage
31
32### Via `.babelrc` (Recommended)
33
34**.babelrc**
35
36```json
37{
38 "plugins": ["@babel/check-constants"]
39}
40```
41
42### Via CLI
43
44```sh
45babel --plugins @babel/check-constants script.js
46```
47
48### Via Node API
49
50```javascript
51require("@babel/core").transform("code", {
52 plugins: ["@babel/check-constants"]
53});
54```
55
56## Note
57
58This check will only validate consts. If you need it to compile down to `var` then you must also install and enable [`@babel/plugin-transform-block-scoping`](http://babeljs.io/docs/plugins/transform-block-scoping/).