Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/conartist6/babel-plugin-recast

Wraps your babel parser in recast
https://github.com/conartist6/babel-plugin-recast

Last synced: 12 days ago
JSON representation

Wraps your babel parser in recast

Awesome Lists containing this project

README

        

# babel-plugin-recast

When you are using [babel](https://babeljs.io/) to transform code, allows you to leverage [recast](https://github.com/benjamn/recast/) to preserve as much formatting as possible during the transformation. Great for writing codemods.

## Usage

```js
// babel.config.js

module.exports = (api) => {
api.cache(true); // Or whatever you need

return {
plugins: [
// Order in the plugins array is not important
'babel-plugin-recast',
],
};
};
```

## How it works

This package encapsulates the current mechanism by which recast should be integrated with babel, using the supported but undocumented `parserOverride` and `generatorOverride` plugin hooks.

Note that only one plugin can override parsing. If you already had a plugin to override parsing you can pass its override to this plugin to be chained. You don't need to worry about this with the official `babel-plugin-syntax-*` packages, which are not implemented as parser overrides but merely adjust the options passed to the default parser.

```js
return {
plugins: [
[
'babel-plugin-recast',
{
// Disclaimer: I didn't test this and it may not work
parserOverride: require('other-plugin')
.parserOverride,
},
],
],
};
```

Recast's source mapping supplants babel's when you use this plugin. Is it better? I don't know.