GithubHelp home page GithubHelp logo

acorn-jsx's Introduction

Acorn-JSX

Build Status NPM version

This is plugin for Acorn - a tiny, fast JavaScript parser, written completely in JavaScript.

It was created as an experimental alternative, faster React.js JSX parser.

According to benchmarks, Acorn-JSX is 2x faster than official Esprima-based parser when location tracking is turned on in both (call it "source maps enabled mode"). At the same time, it consumes all the ES6+JSX syntax that can be consumed by Esprima-FB (this is proved by official tests).

UPDATE [14-Apr-2015]: Facebook implementation started deprecation process in favor of Acorn + Acorn-JSX + Babel for parsing and transpiling JSX syntax.

Transpiler

Please note that this tool only parses source code to JSX AST, which is useful for various language tools and services. If you want to transpile your code to regular ES5-compliant JavaScript with source map, check out the babel transpiler which uses acorn-jsx under the hood.

Usage

Requiring this module provides you with an Acorn plugin that you can use like this:

var acorn = require("acorn");
var jsx = require("acorn-jsx");
acorn.Parser.extend(jsx()).parse("my(<jsx/>, 'code');");

Note that official spec doesn't support mix of XML namespaces and object-style access in tag names (#27) like in <namespace:Object.Property />, so it was deprecated in [email protected]. If you still want to opt-in to support of such constructions, you can pass the following option:

acorn.Parser.extend(jsx({ allowNamespacedObjects: true }))

Also, since most apps use pure React transformer, a new option was introduced that allows to prohibit namespaces completely:

acorn.Parser.extend(jsx({ allowNamespaces: false }))

Note that by default allowNamespaces is enabled for spec compliancy.

License

This plugin is issued under the MIT license.

acorn-jsx's People

Contributors

abraidwood avatar adrianheine avatar angelozerr avatar aparajita avatar arian avatar artemgovorov avatar benekastah avatar blai avatar btmills avatar conradirwin avatar fitzgen avatar forbeslindesay avatar greenkeeperio-bot avatar jamiebuilds avatar jayphelps avatar jenseng avatar johannesherr avatar lehni avatar marijnh avatar mathiasbynens avatar mishoo avatar mrcarlberg avatar mrennie avatar nzakas avatar oxyc avatar p01 avatar rreverser avatar sebmck avatar shinnn avatar wjx avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.