@gerhobbelt/esprima

中文文档
4.0.1-27发布于 2019/07/19BSD-2-ClauseCommonJS零依赖近 30 天下载 2.4万

ECMAScript parsing infrastructure for multipurpose analysis

原始使用文档

NPM version npm download Build Status Coverage Status

NOTE

This fork/clone of esprima tracks the original closely, but adds support for parsing JISON action code blocks, which MAY contain JISON-specific identifiers in the JavaScript code, e.g. $1, @1, #1 and #ID#.

Esprima (esprima.org, BSD license) is a high performance, standard-compliant ECMAScript parser written in ECMAScript (also popularly known as JavaScript). Esprima is created and maintained by Ariya Hidayat, with the help of many contributors.

Features

API

Esprima can be used to perform lexical analysis (tokenization) or syntactic analysis (parsing) of a JavaScript program.

A simple example on Node.js REPL:

> var esprima = require('esprima');
> var program = 'const answer = 42';

> esprima.tokenize(program);
[ { type: 'Keyword', value: 'const' },
  { type: 'Identifier', value: 'answer' },
  { type: 'Punctuator', value: '=' },
  { type: 'Numeric', value: '42' } ]
  
> esprima.parse(program);
{ type: 'Program',
  body:
   [ { type: 'VariableDeclaration',
       declarations: [Object],
       kind: 'const' } ],
  sourceType: 'script' }

For more information, please read the complete documentation.

版本与发布记录

@gerhobbelt/esprima 共发布 21 个版本,首次发布于 2017/10/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.1-27latest2019/07/197 年前
4.0.1-262019/07/197 年前
4.0.1-252019/07/197 年前
4.0.1-242018/05/238 年前
4.0.1-232018/05/238 年前
4.0.1-222018/05/108 年前

关于 @gerhobbelt/esprima 的常见问题

@gerhobbelt/esprima 是什么?

ECMAScript parsing infrastructure for multipurpose analysis

如何安装 @gerhobbelt/esprima?

在项目目录运行 npm install @gerhobbelt/esprima,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 esparse、esvalidate,可以用 npx esparse 直接运行。

@gerhobbelt/esprima 支持 TypeScript 吗?

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

@gerhobbelt/esprima 支持 ESM 还是 CommonJS?

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

@gerhobbelt/esprima 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=4。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@gerhobbelt/esprima 可以商用吗?

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

@gerhobbelt/esprima 的下载量有多少?

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

@gerhobbelt/esprima 还在维护吗?

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