Home

Awesome

<p align="center"> <img alt="babylon" src="https://raw.githubusercontent.com/babel/logo/master/babylon.png" width="700"> </p> <p align="center"> Babylon is a JavaScript parser used in <a href="https://github.com/babel/babel">Babel</a>. </p> <p align="center"> <a href="https://travis-ci.org/babel/babylon"><img alt="Travis Status" src="https://img.shields.io/travis/babel/babylon/master.svg?style=flat&label=travis"></a> <a href="https://codecov.io/gh/babel/babylon"><img alt="Codecov Status" src="https://img.shields.io/codecov/c/github/babel/babylon/master.svg?style=flat"></a> </p>

Credits

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.

API

babylon.parse(code, [options])

Options

Output

Babylon generates AST according to Babel AST format. It is based on ESTree spec with the following deviations:

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

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

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

  plugins: [
    // enable jsx and flow syntax
    "jsx",
    "flow"
  ]
});

Plugins