8ae94a0c406a20a3c49a546abd5e44cf68256c6a8257c7c7ddb3f41349222a881da4fbe133d0294326486a26c4bff60d69320ce6b16737bdbfa4e906c05e30 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # babel-plugin-check-es2015-constants
  2. Validate ES2015 constants (prevents reassignment of const variables).
  3. ## Example
  4. **In**
  5. ```js
  6. const a = 1;
  7. a = 2;
  8. ```
  9. **Out**
  10. ```bash
  11. repl: "a" is read-only
  12. 1 | const a = 1;
  13. > 2 | a = 2;
  14. | ^
  15. ```
  16. [Try in REPL](http://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015&experimental=false&loose=false&spec=false&code=const%20a%20%3D%201%3B%0Aa%20%3D%202%3B&playground=true)
  17. ## Installation
  18. ```sh
  19. npm install --save-dev babel-plugin-check-es2015-constants
  20. ```
  21. ## Usage
  22. ### Via `.babelrc` (Recommended)
  23. **.babelrc**
  24. ```json
  25. {
  26. "plugins": ["check-es2015-constants"]
  27. }
  28. ```
  29. ### Via CLI
  30. ```sh
  31. babel --plugins check-es2015-constants script.js
  32. ```
  33. ### Via Node API
  34. ```javascript
  35. require("babel-core").transform("code", {
  36. plugins: ["check-es2015-constants"]
  37. });
  38. ```
  39. ## Note
  40. This check will only validate consts. If you need it to compile down to `var` then you must also install and enable [`transform-es2015-block-scoping`](http://babeljs.io/docs/plugins/transform-es2015-block-scoping/).