@geosolutions/acorn-jsx

中文文档
4.0.2发布于 2019/12/02MITCommonJS近 30 天下载 7628

Alternative, faster React.js JSX parser

原始使用文档
文档目录3 节
  1. Transpiler
  2. Usage
  3. License

Fork info

This repo has been forked because we needed to add this fix We are going to publish on npm the release branch

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

You can use module directly in order to get Acorn instance with plugin installed:

var acorn = require('acorn-jsx');

Or you can use inject.js for injecting plugin into your own version of Acorn like following:

var acorn = require('acorn-jsx/inject')(require('./custom-acorn'));

Then, use plugins option whenever you need to support JSX while parsing:

var ast = acorn.parse(code, {
  plugins: { jsx: true }
});

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:

var ast = acorn.parse(code, {
  plugins: {
    jsx: { allowNamespacedObjects: true }
  }
});

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

var ast = acorn.parse(code, {
  plugins: {
    jsx: { allowNamespaces: false }
  }
});

Note that by default allowNamespaces is enabled for spec compliancy.

License

This plugin is issued under the MIT license.

版本与发布记录

@geosolutions/acorn-jsx 共发布 2 个版本,首次发布于 2019/11/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.2latest2019/12/026 年前
4.0.12019/11/276 年前

关于 @geosolutions/acorn-jsx 的常见问题

@geosolutions/acorn-jsx 是什么?

Alternative, faster React.js JSX parser

如何安装 @geosolutions/acorn-jsx?

在项目目录运行 npm install @geosolutions/acorn-jsx,或使用 pnpm add / yarn add / bun add。

@geosolutions/acorn-jsx 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/geosolutions__acorn-jsx 是否存在。

@geosolutions/acorn-jsx 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@geosolutions/acorn-jsx 可以商用吗?

@geosolutions/acorn-jsx 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@geosolutions/acorn-jsx 的下载量有多少?

根据 npm 官方下载统计,@geosolutions/acorn-jsx 在 2026/10/16 – 2026/11/14 这 30 天内被下载 7,628 次,日均约 254 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@geosolutions/acorn-jsx 还在维护吗?

最新版本 4.0.2 发布于 2019/12/02(6 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/11/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。