JavaScript Makefile
Latest commit 1e74783 Feb 23, 2017 @hzoo hzoo committed on GitHub add estree to docs [skip ci] (#372)
Failed to load latest commit information.
.github Correct repo [skip ci] Nov 1, 2016
ast AST spec: fix casing of `RegExpLiteral` (#318) [skip ci] Jan 20, 2017
bin Update eslint-config-babel to the latest version πŸš€ (#299) Jan 15, 2017
scripts Run tests of flow with babylon (#225) Nov 14, 2016
src Revert "Fix export default async function to be FunctionDeclaration" (#… Feb 23, 2017
test Revert "Fix export default async function to be FunctionDeclaration" (#… Feb 23, 2017
.babelrc User external-helpers (#254) Jan 2, 2017
.editorconfig Add .gitattributes and .editorconfig for LF line endings (#179) Oct 15, 2016
.eslintignore Readd missin .eslinignore for IDEs Oct 15, 2016
.eslintrc Remove kcheck (#173) Oct 14, 2016
.flowconfig Disallow import type { type a } from … (#305) Jan 17, 2017
.gitattributes Fix .gitattributes line ending setting (#191) Oct 17, 2016
.gitignore User external-helpers (#254) Jan 2, 2017
.travis.yml Fix syntax error in .travis.yml Jan 10, 2017
AUTHORS add acorn license - cc @RReverser Jul 30, 2015 Fix error in changelog Feb 23, 2017 first commit Mar 10, 2016 Update contributing with more test info [skip ci] (#355) Feb 12, 2017
LICENSE add acorn license - cc @RReverser Jul 30, 2015
Makefile Run tests of flow with babylon (#225) Nov 14, 2016 add estree to docs [skip ci] (#372) Feb 23, 2017
codecov.yml Enable partial code coverage (#109) Sep 6, 2016
package.json 6.16.1 Feb 23, 2017
rollup.config.js Use rollup for bundling to speed up startup time (#190) Oct 26, 2016
yarn.lock Update yarn.lock Jan 18, 2017


Babylon is a JavaScript parser used in Babel.

Travis Status Codecov Status

  • The latest ECMAScript version enabled by default (ES2017).
  • Comment attachment.
  • Support for JSX and Flow.
  • Support for experimental language proposals (accepting PRs for anything at least stage-0).


Heavily based on acorn and acorn-jsx, thanks to the awesome work of @RReverser and @marijnh.

Significant diversions are expected to occur in the future such as streaming, EBNF definitions, sweet.js integration, interspatial parsing and more.


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().


  • allowImportExportEverywhere: By default, import and export declarations can only appear at a program's top level. Setting this option to true 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 either "script" or "module".

  • 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


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

AST for JSX code is based on Facebook JSX AST with the addition of one node type:

  • JSXText


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.


require("babylon").parse("code", {
  // parse in strict mode and allow module declarations
  sourceType: "module",

  plugins: [
    // enable jsx and flow syntax


  • estree
  • jsx
  • flow
  • doExpressions
  • objectRestSpread
  • decorators (Based on an outdated version of the Decorators proposal. Will be removed in a future version of Babylon)
  • classProperties
  • exportExtensions
  • asyncGenerators
  • functionBind
  • functionSent
  • dynamicImport