@engine262/engine262

中文文档
0.0.1-46acc94625794d30f81b7a83dd608887530163a6发布于 2026/11/13MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 3402

Implementation of ECMA-262 in JavaScript

原始使用文档
文档目录8 节
  1. Why this exists
  2. Requirements
  3. Using engine262
  4. engine262 playground
  5. engine262 CLI
  6. engine262 API
  7. Developing engine262
  8. Related Projects

engine262

An implementation of ECMA-262 in JavaScript

Goals

  • 100% Spec Compliance
  • Introspection
  • Ease of modification

Non-Goals

  • Speed at the expense of any of the goals

This project is bound by a Code of Conduct.

Join us in #engine262:matrix.org.

Why this exists

While helping develop new features for JavaScript, I've found that one of the most useful methods of finding what works and what doesn't is being able to actually run code using the new feature. Babel is fantastic for this, but sometimes features just can't be nicely represented with it. Similarly, implementing a feature in one of the engines is a large undertaking, involving long compile times and annoying bugs with the optimizing compilers.

engine262 is a tool to allow JavaScript developers to have a playground where new features can be quickly prototyped and explored. As an example, adding do expressions to this engine is as simple as the following diff:

--- a/src/evaluator.mts
+++ b/src/evaluator.mts
@@ -232,6 +232,8 @@ export function* Evaluate(node) {
     case 'GeneratorBody':
     case 'AsyncGeneratorBody':
       return yield* Evaluate_AnyFunctionBody(node);
+    case 'DoExpression':
+      return yield* Evaluate_Block(node.Block);
     default:
       throw new OutOfRange('Evaluate', node);
   }
--- a/src/parser/ExpressionParser.mts
+++ b/src/parser/ExpressionParser.mts
@@ -579,6 +579,12 @@ export class ExpressionParser extends FunctionParser {
         return this.parseRegularExpressionLiteral();
       case Token.LPAREN:
         return this.parseParenthesizedExpression();
+      case Token.DO: {
+        const node = this.startNode<ParseNode.DoExpression>();
+        this.next();
+        node.Block = this.parseBlock();
+        return this.finishNode(node, 'DoExpression');
+      }
       default:
         return this.unexpected();
     }

This simplicity applies to many other proposals, such as optional chaining, pattern matching, the pipeline operator, and more. This engine has also been used to find bugs in ECMA-262 and test262, the test suite for conforming JavaScript implementations.

Requirements

To run engine262 itself, a engine with support for recent ECMAScript features is needed. Additionally, the CLI (bin/engine262.js) and test262 runner (test/test262/test262.mts) require a recent version of Node.js.

Using engine262

You can install it from npm.

npm install @engine262/engine262
yarn install @engine262/engine262
pnpm install @engine262/engine262

If you install it globally, you can use the CLI like so:

$ engine262

engine262 playground

Classic playground and Chrome Devtools style playground

engine262 CLI

--module/-m

Evaluate the file as a module.

--eval <string> / -e <string>

Evaluate the given string and exit.

--features=<featureA,featureB> / --features=all

Run engine262 --list-features to see all ECMAScript features can be switched.

--no-test262

Do not expose $ and $262 global variable for test262 test suite.

--no-inspector

Do not start an inspector.

By default engine262 will start an inspector on ws://localhost:9229/ (like Node.js with --inspector). See the Node.js guide for connecting.

--no-preview

Do not enable the preview feature in the inspector.

engine262 API

See the example.

Developing engine262

npm run build and npm run watch will build and watch the build.

npm run test:test262 will run the test262 test suite. Run npm run test:test262 -- --help to see the test runner options.

npm start start the engine262 CLI.

npm run inspector start the website (debugging engine262 mainly happens here).

Many people and organizations have attempted to write a JavaScript interpreter in JavaScript much like engine262, with different goals. Some of them are included here for reference, though engine262 is not based on any of them.

版本与发布记录

@engine262/engine262 共发布 157 个版本,首次发布于 2021/11/27;过去 12 个月发布了 53 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.1-46acc94625794d30f81b7a83dd608887530163a6latest2026/11/13今天
0.0.1-2278ba8f84ab6fdfeb487eb4dbc93b34a6526c4b2026/11/13今天
0.0.1-48467be077f4dcbf8745469f4898c14b755881542026/11/13今天
0.0.1-67a6b6157fd4c08bb5c5295e613ff582fd9ac4882026/11/058 天前
0.0.1-02ef2d2b668543572cfd0d45ea1ff00ba95a32072026/11/049 天前
0.0.1-d553e7b52501fbc47eae981c8d0fa7a5c26d01712026/10/2321 天前

关于 @engine262/engine262 的常见问题

@engine262/engine262 是什么?

Implementation of ECMA-262 in JavaScript

如何安装 @engine262/engine262?

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

@engine262/engine262 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@engine262/engine262 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@engine262/engine262 可以商用吗?

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

@engine262/engine262 的下载量有多少?

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

@engine262/engine262 还在维护吗?

最新版本 0.0.1-46acc94625794d30f81b7a83dd608887530163a6 发布于 2026/11/13(今天);至今共发布 157 个版本,其中过去 12 个月发布了 53 个;首次发布于 2021/11/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。