move to codemods folder [skip ci]
This commit is contained in:
parent
5c824273bc
commit
8597219ce5
@ -7,6 +7,11 @@ packages/*/lib
|
|||||||
packages/*/dist
|
packages/*/dist
|
||||||
packages/*/test/fixtures
|
packages/*/test/fixtures
|
||||||
packages/*/test/tmp
|
packages/*/test/tmp
|
||||||
|
codemods/*/node_modules
|
||||||
|
codemods/*/lib
|
||||||
|
codemods/*/dist
|
||||||
|
codemods/*/test/fixtures
|
||||||
|
codemods/*/test/tmp
|
||||||
packages/babel-standalone/babel.js
|
packages/babel-standalone/babel.js
|
||||||
packages/babel-standalone/babel.min.js
|
packages/babel-standalone/babel.min.js
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# babel-plugin-transform-remove-unused-catch-binding
|
# babel-plugin-codemod-optional-catch-binding
|
||||||
|
|
||||||
> If the argument bound to the catch block is not referenced in the catch block, that argument and the catch binding is removed.
|
> If the argument bound to the catch block is not referenced in the catch block, that argument and the catch binding is removed.
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ try {
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm install --save-dev babel-plugin-transform-remove-unused-catch-binding
|
npm install --save-dev babel-plugin-codemod-optional-catch-binding
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -37,21 +37,21 @@ npm install --save-dev babel-plugin-transform-remove-unused-catch-binding
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"plugins": ["transform-remove-unused-catch-binding"]
|
"plugins": ["codemod-optional-catch-binding"]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Via CLI
|
### Via CLI
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
babel --plugins transform-remove-unused-catch-binding script.js
|
babel --plugins codemod-optional-catch-binding script.js
|
||||||
```
|
```
|
||||||
|
|
||||||
### Via Node API
|
### Via Node API
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
require("babel-core").transform("code", {
|
require("babel-core").transform("code", {
|
||||||
plugins: ["transform-remove-unused-catch-binding"]
|
plugins: ["codemod-optional-catch-binding"]
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.__esModule = true;
|
||||||
|
|
||||||
|
exports.default = function (babel) {
|
||||||
|
const {
|
||||||
|
types: t
|
||||||
|
} = babel;
|
||||||
|
return {
|
||||||
|
inherits: _babelPluginSyntaxOptionalCatchBinding2.default,
|
||||||
|
visitor: {
|
||||||
|
CatchClause(path) {
|
||||||
|
if (path.node.param === null || !t.isIdentifier(path.node.param)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const binding = path.scope.getOwnBinding(path.node.param.name);
|
||||||
|
|
||||||
|
if (binding.constantViolations.length > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!binding.referenced) {
|
||||||
|
const paramPath = path.get("param");
|
||||||
|
paramPath.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var _babelPluginSyntaxOptionalCatchBinding = require("babel-plugin-syntax-optional-catch-binding");
|
||||||
|
|
||||||
|
var _babelPluginSyntaxOptionalCatchBinding2 = _interopRequireDefault(_babelPluginSyntaxOptionalCatchBinding);
|
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "babel-plugin-transform-remove-unused-catch-binding",
|
"name": "babel-plugin-codemod-optional-catch-binding",
|
||||||
"version": "7.0.0-beta.0",
|
"version": "7.0.0-beta.0",
|
||||||
"description": "Remove unused catch bindings",
|
"description": "Remove unused catch bindings",
|
||||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-remove-unused-catch-binding",
|
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-remove-unused-catch-binding",
|
||||||
Loading…
x
Reference in New Issue
Block a user