Esprima (harmony fork)

raw JSON →
1.1.1-dev-harmony verified Fri May 01 auth: no javascript deprecated

Esprima (version 1.1.1-dev-harmony) is a high-performance, standard-compliant ECMAScript parser written in JavaScript. It supports full ES5.1 and experimental ES6/Harmony features (modules, classes, destructuring). Runs in browsers (IE6+) and Node.js (>=0.4.0). Known for being up to 3x faster than UglifyJS v1. This is an unofficial fork with the '-harmony' suffix, indicating pre-release support for ES6. Note: this package may be considered obsolete compared to mainline esprima releases.

error ReferenceError: window is not defined
cause The package assumes a browser environment with 'window' global.
fix
Run in a browser or use a shim like 'global.window = global;' in Node.js.
error TypeError: esprima is not a function
cause Incorrect import syntax (e.g., using default import instead of named import).
fix
Use named import: import { parse } from 'esprima-six-jpike'.
error SyntaxError: Unexpected token ILLEGAL
cause The code contains ES6+ syntax that the harmony fork does not support fully.
fix
Use the 'ecmaVersion' option in a modern parser like 'acorn', or rewrite to ES5.1.
deprecated This package is an unofficial fork (esprima-six-jpike) and may not be maintained. Use official 'esprima' package instead.
fix Switch to 'esprima' latest stable version (e.g., 4.0.1).
gotcha The '-harmony' suffix indicates pre-release ES6 support; features may be incomplete or unstable.
fix For production ES6 parsing, use a dedicated ES6 parser like 'acorn' with the 'ecmaVersion' option.
breaking Node engine requirement '>=0.4.0' is extremely old; newer Node versions may have compatibility issues or missing globals.
fix Use a recent Node LTS version (e.g., 14.x or later) and test thoroughly, or migrate to a maintained parser.
npm install esprima-six-jpike
yarn add esprima-six-jpike
pnpm add esprima-six-jpike

Shows parsing and tokenizing JavaScript code, including experimental ES6/Harmony syntax using the fork.

import { parse, tokenize } from 'esprima-six-jpike';

const code = 'const answer = 42;';

// Parse to AST (supports ES5.1, experimental harmony)
const ast = parse(code, { tolerant: true, loc: true });
console.log(JSON.stringify(ast, null, 2));

// Tokenize
const tokens = tokenize(code, { range: true });
console.log(tokens);

// Example with harmony syntax
const harmonyCode = 'class Person { constructor(name) { this.name = name; } }';
const harmonyAst = parse(harmonyCode, { jsx: false, type: 'module' });
console.log(harmonyAst);