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-recastVerified import paths — ran on the pinned version, not inferred.
Basic Babel config enabling babel-plugin-recast to preserve formatting.
If you have another parser override, pass it via options: { parserOverride: otherPlugin.parserOverride }.Test source maps after transformation if they are critical.
Pin recast to 0.x in your package.json.
Monitor Babel release notes for changes to these hooks.
Run npm install --save-dev babel-plugin-recast
Run npm install recast@0.x
Chain parserOverrides by passing the other plugin's override via options.