diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:38:50 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:40:43 +0200 |
commit | 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch) | |
tree | 6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/babel-plugin-check-es2015-constants | |
parent | 963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff) |
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/babel-plugin-check-es2015-constants')
4 files changed, 125 insertions, 0 deletions
diff --git a/node_modules/babel-plugin-check-es2015-constants/.npmignore b/node_modules/babel-plugin-check-es2015-constants/.npmignore new file mode 100644 index 000000000..31852902b --- /dev/null +++ b/node_modules/babel-plugin-check-es2015-constants/.npmignore @@ -0,0 +1,4 @@ +node_modules +*.log +src +test diff --git a/node_modules/babel-plugin-check-es2015-constants/README.md b/node_modules/babel-plugin-check-es2015-constants/README.md new file mode 100644 index 000000000..608891b3d --- /dev/null +++ b/node_modules/babel-plugin-check-es2015-constants/README.md @@ -0,0 +1,59 @@ +# babel-plugin-check-es2015-constants + +Validate ES2015 constants (prevents reassignment of const variables). + +## Example + +**In** + +```js +const a = 1; +a = 2; +``` + +**Out** + +```bash +repl: "a" is read-only + 1 | const a = 1; +> 2 | a = 2; + | ^ +``` + +[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) + +## Installation + +```sh +npm install --save-dev babel-plugin-check-es2015-constants +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["check-es2015-constants"] +} +``` + +### Via CLI + +```sh +babel --plugins check-es2015-constants script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["check-es2015-constants"] +}); +``` + +## Note + +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/). diff --git a/node_modules/babel-plugin-check-es2015-constants/lib/index.js b/node_modules/babel-plugin-check-es2015-constants/lib/index.js new file mode 100644 index 000000000..f4a43eac4 --- /dev/null +++ b/node_modules/babel-plugin-check-es2015-constants/lib/index.js @@ -0,0 +1,45 @@ +"use strict"; + +exports.__esModule = true; + +var _getIterator2 = require("babel-runtime/core-js/get-iterator"); + +var _getIterator3 = _interopRequireDefault(_getIterator2); + +exports.default = function (_ref) { + var messages = _ref.messages; + + return { + visitor: { + Scope: function Scope(_ref2) { + var scope = _ref2.scope; + + for (var name in scope.bindings) { + var binding = scope.bindings[name]; + if (binding.kind !== "const" && binding.kind !== "module") continue; + + for (var _iterator = binding.constantViolations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) { + var _ref3; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref3 = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref3 = _i.value; + } + + var violation = _ref3; + + throw violation.buildCodeFrameError(messages.get("readOnly", name)); + } + } + } + } + }; +}; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +module.exports = exports["default"];
\ No newline at end of file diff --git a/node_modules/babel-plugin-check-es2015-constants/package.json b/node_modules/babel-plugin-check-es2015-constants/package.json new file mode 100644 index 000000000..b335fbf3f --- /dev/null +++ b/node_modules/babel-plugin-check-es2015-constants/package.json @@ -0,0 +1,17 @@ +{ + "name": "babel-plugin-check-es2015-constants", + "version": "6.22.0", + "description": "Compile ES2015 constants to ES5", + "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-check-es2015-constants", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "babel-runtime": "^6.22.0" + }, + "devDependencies": { + "babel-helper-plugin-test-runner": "^6.22.0" + } +} |