Parse user code files using their project's installed Babel version and config, with automatic fallback. Handles JS, TS, TSX, and DTS files with correct parser plugins based on file extension. Supports Babel 7 only. Current stable version 2.1.5 (June 2023). Key differentiator: resolves ambient Babel config per file directory, works around Babel 7 performance bug where parseAsync redoes loadOptionsAsync work. Falls back to @babel/parser defaults if @babel/core or config is missing. Ships ESM and CJS exports with TypeScript definitions. Maintained by codemodsquad.
npm install babel-parse-wild-codeVerified import paths — ran on the pinned version, not inferred.
Demonstrates sync and async parsing with clearCache, custom parser options, and reusable Parser instance for TypeScript files.
Explicitly add these plugins via options.plugins array, or pin to v1.x if you rely on them.
Upgrade your project to Babel 7, or use an alternative parser.
Ensure @babel/core and @babel/parser are installed in the project (not globally) so they can be resolved via require().
Call clearCache() before each batch of parses, or between batches when config may have changed.
If you pass plugins that conflict with resolved plugins, wrap in a function that filters or deduplicates.
Add `tokens: true` to the options object when calling getParserSync/getParserAsync for use with jscodeshift.
If you need the old behavior, set `disallowAmbiguousJSXLike: false` in options.
Install @babel/core as a dependency in your project: npm install @babel/core --save
Use named import: import { parseSync } from 'babel-parse-wild-code'Pass the missing plugin in options: parseSync('file.jsx', { plugins: ['jsx'] })Upgrade @babel/parser to version 7.13.0 or later: npm install @babel/parser@latest