Registry / devops / babel-plugin-recast

babel-plugin-recast

JSON →
library0.2.0jsnpmunverified

Babel plugin (v0.2.0, stable) that integrates recast's AST parsing and code generation to preserve original formatting during Babel transformations, ideal for codemods. Unlike standard Babel plugins that discard formatting, it uses undocumented parserOverride/generatorOverride hooks to maintain whitespace and style. Requires peer dependency recast 0.x. Light maintenance, release cadence is minimal.

npm install babel-plugin-recast
INSTALL
IMPORT
SIG · BABEL-PLUGIN-RECAS
B
babel-plugin-recast
devopsjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

babel-plugin-recast
module.exports = { plugins: ['babel-plugin-recast'] };
import plugin from 'babel-plugin-recast'; // Not a JS module
Used as a Babel plugin name string in config, not a direct import.
parserOverride
plugins: [['babel-plugin-recast', { parserOverride: otherPlugin.parserOverride }]]
plugins: ['babel-plugin-recast', { parserOverride: ... }] // Options must be paired with plugin name in array
Options are passed as the second element of an array in Babel config.
generatorOverride
Not directly exposed; recast handles it internally.
Setting generatorOverride in plugin options
generatorOverride is not configurable via this plugin.

Basic Babel config enabling babel-plugin-recast to preserve formatting.

// babel.config.js module.exports = function (api) { api.cache(true); return { plugins: ['babel-plugin-recast'] }; }; // Run: npx babel input.js --out-file output.js --config-file babel.config.js
Debug
Known issues
gotchaOnly one plugin can override parsing. Chaining with other parser overrides is possible but untested.
fix
If you have another parser override, pass it via options: { parserOverride: otherPlugin.parserOverride }.
affects: >=0.0.0
gotchaRecast's source mapping replaces Babel's; may cause unexpected behavior in source maps.
fix
Test source maps after transformation if they are critical.
affects: >=0.0.0
breakingPeer dependency recast must be 0.x; breaking changes may occur if recast major version updates.
fix
Pin recast to 0.x in your package.json.
affects: >=0.0.0
gotchaUndocumented hooks parserOverride and generatorOverride may break in future Babel versions.
fix
Monitor Babel release notes for changes to these hooks.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Plugin babel-plugin-recast not found
Missing or incorrectly installed package.
fix
Run npm install --save-dev babel-plugin-recast
Cannot find module 'recast'
Missing peer dependency recast.
fix
Run npm install recast@0.x
Multiple parser overrides found
Another plugin also overrides parsing without chaining.
fix
Chain parserOverrides by passing the other plugin's override via options.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
recastrequiredPeer dependency required for AST manipulation and formatting preservation
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
babel-plugin-recast — npm install babel-plugin-recast · libregistry