Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/conartist6/babel-plugin-recast
- Owner: conartist6
- License: mit
- Created: 2020-05-23T17:19:13.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-23T13:31:18.000Z (over 3 years ago)
- Last Synced: 2024-12-19T02:25:54.633Z (15 days ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.jsmodule.exports = (api) => {
api.cache(true); // Or whatever you needreturn {
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.