Esprima2
modern javascript parser
Install / Use
/learn @s0md3v/Esprima2README
esprima2 is a javascript parser written in python. It works for ECMAScript 2024 and has ~1500 unit tests.
Credits
- Ariya Hidayat created the original esprima library.
- Kronuz created a python port as esprima-python, line-by-line - faithfully.
esprimalibrary hasn't been updated since ECMAScript 2019 andesprima-pythonsince ECMAScript 2017.- With
esprima2, I added the missing syntax support and now we can parse modern javascript.
Features
- Full support for ECMAScript 2024
- Sensible syntax tree format as standardized by ESTree project
- Experimental support for JSX, a syntax extension for React
- Optional tracking of syntax node location (index-based and line-column)
- Heavily tested (~1500 unit tests)
Installation
pip install esprima2
Usage
Esprima can be used to perform lexical analysis (tokenization) or syntactic analysis (parsing) a JavaScript program.
A simple example:
>>> import esprima
>>> program = 'const answer = 42'
>>> esprima.tokenize(program)
[{
type: "Keyword",
value: "const"
}, {
type: "Identifier",
value: "answer"
}, {
type: "Punctuator",
value: "="
}, {
type: "Numeric",
value: "42"
}]
>>> esprima.parseScript(program)
{
body: [
{
kind: "const",
declarations: [
{
init: {
raw: "42",
type: "Literal",
value: 42
},
type: "VariableDeclarator",
id: {
type: "Identifier",
name: "answer"
}
}
],
type: "VariableDeclaration"
}
],
type: "Program",
sourceType: "script"
}
More (and original) documentation is available here: https://esprima.org
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
