An open API service indexing awesome lists of open source software.

https://github.com/putoutjs/babel-wrap


https://github.com/putoutjs/babel-wrap

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

          

## ๐Ÿ—ฟ Using Babel Plugins with Putout

You can add `Babel` to the `plugins` section of `.putout.json` with `babel/` prefix.

*You can disable a rule, or use a match in a similar way.*

*โ˜๏ธRemember to omit `babel-plugin-` or `@babel/plugin`: putout will set it up for you :)*

*Example*
Let's add `babel-plugin-transform-inline-consecutive-adds` to `.putout.json`:

```json
{
"plugins": [
"babel/transform-inline-consecutive-adds"
]
}
```

Then create a file and process it with the help of **Babel Plugin**.

```sh
coderaiser@cloudcmd:~$ cat > a.js
const t = [];
t.push(1);
t.push(2);

coderaiser@cloudcmd:~$ PUTOUT_PRINTER=babel putout a.js -f codeframe
/home/coderaiser/a.js:4:0
2 | t.push(1);
3 | t.push(2);
> 4 |
| ^ transform inline consecutive adds

โœ– 1 errors in 1 files
fixable with the `--fix` option
coderaiser@cloudcmd:~$ putout --fix a.js
coderaiser@cloudcmd:~$ cat a.js
const t = [1, 2];
```

Using ๐ŸŠ**Putout** as a runner for `babel` `plugins` you can not only change file content, but also see what exactly will be changed. You can use your already written `babel` `plugins` or reuse work in progress plugins made for `babel`,

โ˜๏ธ *Remember ๐ŸŠ**Putout** `plugins` gave more accurate information about changing places, and works faster (no need to find information about changes in transformed file).*

### Babel plugins list

Here you can find **Babel Plugins** which feats the most main purpose of ๐ŸŠ**Putout** and advised to use:

transform-inline-consecutive-adds

```diff
-const foo = {};
-foo.a = 42;
-foo.b = ["hi"];
-foo.c = bar();
-foo.d = "str";
+const foo = {
+ a: 42,
+ b: ["hi"],
+ c: bar(),
+ d: "str"
+};

-const bar = [];
-bar.push(1);
-bar.push(2);
+const bar = [1, 2];
```

codemod-object-assign-to-object-spread

```diff
function merge(a) {
- return Object.assign({}, a, {
- hello: 'world'
- });
+ return {
+ ...a,
+ hello: 'world'
+ };
};
```

codemod-optional-catch-binding

```diff
try {
throw 0;
-} catch (err) {
+} catch {
console.log("it failed, but this code executes");
}
```

angularjs-annotate

```diff
-angular.module("MyMod").controller("MyCtrl", ($scope, $timeout) => {});
+angular.module("MyMod").controller("MyCtrl", ["$scope", "$timeout", ($scope, $timeout) => {}]);
```

Please send pull requests with **Babel Plugins** which can be used as codemods, or simplify, fix, makes code more readable.