PSA: moved into babel/babel as @babel/parser -->
Installations
npm install babylon
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.1.4
NPM Version
5.3.0
Score
99.3
Supply Chain
100
Quality
81.5
Maintenance
100
Vulnerability
100
License
Releases
v7.0.0-beta.30
Updated on Oct 28, 2017
v7.0.0-beta.29
Updated on Oct 16, 2017
v7.0.0-beta.28
Updated on Oct 14, 2017
v7.0.0-beta.27
Updated on Sep 29, 2017
v7.0.0-beta.26
Updated on Sep 27, 2017
v7.0.0-beta.25
Updated on Sep 25, 2017
Contributors
Unable to fetch Contributors
Languages
JavaScript (99.59%)
Makefile (0.41%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
2,636,589,581
Last Day
837,631
Last Week
5,998,634
Last Month
20,945,145
Last Year
250,477,194
GitHub Statistics
MIT License
1,711 Stars
1,767 Commits
255 Forks
52 Watchers
9 Branches
148 Contributors
Updated on Jan 21, 2025
Bundle Size
120.58 kB
Minified
32.77 kB
Minified + Gzipped
Package Meta Information
Latest Version
6.18.0
Package Id
babylon@6.18.0
Size
67.62 kB
NPM Version
5.3.0
Node Version
8.1.4
Published on
Aug 15, 2017
Total Downloads
Cumulative downloads
Total Downloads
2,636,589,581
Last Day
-26.6%
837,631
Compared to previous day
Last Week
17.9%
5,998,634
Compared to previous week
Last Month
51.7%
20,945,145
Compared to previous month
Last Year
-11%
250,477,194
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
23
Babylon is a JavaScript parser used in Babel.
- The latest ECMAScript version enabled by default (ES2017).
- Comment attachment.
- Support for JSX, Flow, Typescript.
- Support for experimental language proposals (accepting PRs for anything at least stage-0).
Credits
Heavily based on acorn and acorn-jsx, thanks to the awesome work of @RReverser and @marijnh.
API
babylon.parse(code, [options])
babylon.parseExpression(code, [options])
parse()
parses the provided code
as an entire ECMAScript program, while
parseExpression()
tries to parse a single Expression with performance in
mind. When in doubt, use .parse()
.
Options
-
allowImportExportEverywhere: By default,
import
andexport
declarations can only appear at a program's top level. Setting this option totrue
allows them anywhere where a statement is allowed. -
allowReturnOutsideFunction: By default, a return statement at the top level raises an error. Set this to
true
to accept such code. -
allowSuperOutsideMethod: TODO
-
sourceType: Indicate the mode the code should be parsed in. Can be one of
"script"
,"module"
, or"unambiguous"
. Defaults to"script"
."unambiguous"
will make Babylon attempt to guess, based on the presence of ES6import
orexport
statements. Files with ES6import
s andexport
s are considered"module"
and are otherwise"script"
. -
sourceFilename: Correlate output AST nodes with their source filename. Useful when generating code and source maps from the ASTs of multiple input files.
-
startLine: By default, the first line of code parsed is treated as line 1. You can provide a line number to alternatively start with. Useful for integration with other source tools.
-
plugins: Array containing the plugins that you want to enable.
-
strictMode: TODO
-
ranges: Adds a
ranges
property to each node:[node.start, node.end]
-
tokens: Adds all parsed tokens to a
tokens
property on theFile
node
Output
Babylon generates AST according to Babel AST format. It is based on ESTree spec with the following deviations:
There is now an
estree
plugin which reverts these deviations
- Literal token is replaced with StringLiteral, NumericLiteral, BooleanLiteral, NullLiteral, RegExpLiteral
- Property token is replaced with ObjectProperty and ObjectMethod
- MethodDefinition is replaced with ClassMethod
- Program and BlockStatement contain additional
directives
field with Directive and DirectiveLiteral - ClassMethod, ObjectProperty, and ObjectMethod value property's properties in FunctionExpression is coerced/brought into the main method node.
AST for JSX code is based on Facebook JSX AST with the addition of one node type:
JSXText
Semver
Babylon follows semver in most situations. The only thing to note is that some spec-compliancy bug fixes may be released under patch versions.
For example: We push a fix to early error on something like #107 - multiple default exports per file. That would be considered a bug fix even though it would cause a build to fail.
Example
1require("babylon").parse("code", { 2 // parse in strict mode and allow module declarations 3 sourceType: "module", 4 5 plugins: [ 6 // enable jsx and flow syntax 7 "jsx", 8 "flow" 9 ] 10});
Plugins
Name | Code Example |
---|---|
estree (repo) | n/a |
jsx (repo) | <a attr="b">{s}</a> |
flow (repo) | var a: string = ""; |
typescript (repo) | var a: string = ""; |
doExpressions | var a = do { if (true) { 'hi'; } }; |
objectRestSpread (proposal) | var a = { b, ...c }; |
decorators (Stage 1) and decorators2 (Stage 2 proposal) | @a class A {} |
classProperties (proposal) | class A { b = 1; } |
classPrivateProperties (proposal) | class A { #b = 1; } |
classPrivateMethods (proposal) | class A { #c() {} } |
exportExtensions (proposal 1), (proposal 2) | Proposal 1: export v from "mod" Proposal 2: export * as ns from "mod" |
asyncGenerators (proposal) | async function*() {} , for await (let a of b) {} |
functionBind (proposal) | a::b , ::console.log |
functionSent | function.sent |
dynamicImport (proposal) | import('./guy').then(a) |
numericSeparator (proposal) | 1_000_000 |
optionalChaining (proposal) | a?.b |
importMeta (proposal) | import.meta.url |
bigInt (proposal) | 100n |
optionalCatchBinding (proposal) | try {throw 0;} catch{do();} |
throwExpressions (proposal) | () => throw new Error("") |
pipelineOperator (proposal) | a |> b |
nullishCoalescingOperator (proposal) | a ?? b |
FAQ
Will Babylon support a plugin system?
Previous issues: babel/babel#1351, #500.
We currently aren't willing to commit to supporting the API for plugins or the resulting ecosystem (there is already enough work maintaining Babel's own plugin system). It's not clear how to make that API effective, and it would limit out ability to refactor and optimize the codebase.
Our current recommendation for those that want to create their own custom syntax is for users to fork Babylon.
To consume your custom parser, you can add to your .babelrc
via its npm package name or require it if using JavaScript,
1{ 2 "parserOpts": { 3 "parser": "custom-fork-of-babylon-on-npm-here" 4 } 5}

No vulnerabilities found.
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
no binaries found in the repo
Reason
Found 16/25 approved changesets -- score normalized to 6
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 21 are checked with a SAST tool
Reason
68 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-hr2v-3952-633q
- Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-p9w8-2mpq-49h9
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-2m96-9w4j-wgv7
- Warn: Project is vulnerable to: GHSA-h726-x36v-rx45
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.9
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More