Registry / http-networking / babel-parse-wild-code

babel-parse-wild-code

JSON →
library2.1.5jsnpmunverified

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-code
INSTALL
IMPORT
SIG · BABEL-PARSE-WILD-C
B
babel-parse-wild-code
http-networkingjavascriptv2.1.5
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.

parseSync
import { parseSync } from 'babel-parse-wild-code'
const parseSync = require('babel-parse-wild-code').parseSync
ESM export since v2.1.0; CJS require works but named import in ESM is preferred.
parseAsync
import { parseAsync } from 'babel-parse-wild-code'
import parseAsync from 'babel-parse-wild-code'
Named export, not default. Default export does not exist.
Parser
import { Parser } from 'babel-parse-wild-code'
const { Parser } = require('babel-parse-wild-code');
Class constructor; ESM and CJS both supported.
clearCache
import { clearCache } from 'babel-parse-wild-code'
Call before bulk parsing to clear per-directory caches of @babel/core and @babel/parser.
getParserSync
import { getParserSync } from 'babel-parse-wild-code'
import { getParserSync } from 'babel-parse-wild-code/getParserSync'
Only top-level named export; no subpath exports.
getParserAsync
import { getParserAsync } from 'babel-parse-wild-code'
Async variant of getParserSync; same import path.

Demonstrates sync and async parsing with clearCache, custom parser options, and reusable Parser instance for TypeScript files.

import { parseSync, clearCache } from 'babel-parse-wild-code' // Clear cache before bulk operations clearCache() // Parse a TypeScript file synchronously const ast = parseSync('path/to/file.ts') console.log(ast.program.body) // Parse with custom parser options (e.g., tokens for jscodeshift) const astWithTokens = parseSync('path/to/file.tsx', { tokens: true, plugins: ['jsx'] }) // Async parsing import { parseAsync } from 'babel-parse-wild-code' const ast2 = await parseAsync('path/to/file.js') // Get a reusable Parser instance import { getParserSync, Parser } from 'babel-parse-wild-code' const parser: Parser = getParserSync('path/to/file.ts') const parsed = parser.parse('const x: number = 1')
Debug
Known issues
breakingVersion 2.0.0 removed default parser plugins for experimental proposals (decorators, doExpressions, exportDefaultFrom, functionBind, pipelineOperator, throwExpressions).
fix
Explicitly add these plugins via options.plugins array, or pin to v1.x if you rely on them.
affects: >=2.0.0
deprecatedBabel 6 is not supported; only Babel 7 is supported.
fix
Upgrade your project to Babel 7, or use an alternative parser.
affects: >=1.0.0
gotchaIf @babel/core or @babel/parser cannot be resolved from the file's directory, the library falls back to bundled default parser options without any project-specific config.
fix
Ensure @babel/core and @babel/parser are installed in the project (not globally) so they can be resolved via require().
affects: >=1.0.0
gotchaThe cache is per-directory and not automatically invalidated on Babel config changes. Clear the cache manually with clearCache() before bulk parsing to avoid stale options.
fix
Call clearCache() before each batch of parses, or between batches when config may have changed.
affects: >=1.0.0
gotchaOptions passed to parseSync/parseAsync are merged with resolved options for the file, but plugins are concatenated — duplicates are not removed.
fix
If you pass plugins that conflict with resolved plugins, wrap in a function that filters or deduplicates.
affects: >=1.0.0
gotchaWhen using getParserSync/getParserAsync with jscodeshift, you must pass `{ tokens: true }` in options to include tokens in the AST.
fix
Add `tokens: true` to the options object when calling getParserSync/getParserAsync for use with jscodeshift.
affects: >=1.0.0
breakingIn v2.0.0, the default parser options for .d.ts files changed: disallowAmbiguousJSXLike is now set to true for .d.ts files to conform to TypeScript's parser behavior.
fix
If you need the old behavior, set `disallowAmbiguousJSXLike: false` in options.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module '@babel/core'
@babel/core is not installed or not in node_modules path relative to the file being parsed.
fix
Install @babel/core as a dependency in your project: npm install @babel/core --save
TypeError: (0 , babel-parse-wild-code.parseSync) is not a function
Importing the default export instead of named export, or using wrong module system.
fix
Use named import: import { parseSync } from 'babel-parse-wild-code'
SyntaxError: Unexpected token (1:0)
Parsing a file with a syntax that requires a plugin that is not included in the default parser options for that file extension (e.g., JSX in .js file without jsx plugin).
fix
Pass the missing plugin in options: parseSync('file.jsx', { plugins: ['jsx'] })
Error: @babel/parser: Option 'allowUndeclaredExports' is not registered
Using an older version of @babel/parser that does not support certain options that babel-parse-wild-code sets for .d.ts files.
fix
Upgrade @babel/parser to version 7.13.0 or later: npm install @babel/parser@latest
Upgrade
Version history
2.1.5latest on npm
Audit
Dependencies
@babel/coreoptionalpeer dependency for loading Babel config; fallback to @babel/parser if missing
@babel/parseroptionalpeer dependency for actual parsing; fallback to bundled default if missing
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources