This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
JSVM2 is a JavaScript interpreter implemented in JavaScript, designed to execute JavaScript code in a sandboxed environment. It implements ECMAScript 5 features with partial ES2015+ support and follows the ECMAScript specification (https://www.ecma-international.org/wp-content/uploads/ECMA-262_5th_edition_december_2009.pdf).
npm run build # Build the project using Rollupnpm test # Run all tests with Jest
npm run test:coverage # Run tests with coverage report
npm run test:debug # Run tests in debug mode with inspectornpm run typecheck # Type check with TypeScript (use this to verify changes)Note: There are no lint commands defined in package.json. Always run npm run typecheck after making changes to ensure TypeScript compliance.
- VM (
src/vm.ts): Main entry point providingrun(),runInContext(), andcreateContext()functions - Visitor Pattern (
src/visitor.ts): Central dispatcher that routes AST nodes to appropriate handlers - Context (
src/context.ts): Sandboxed execution environment with global objects (ECMAScript standard globals) - Scope (
src/scope.ts): Variable scope management system - Path (
src/path.ts): AST node wrapper providing traversal context - Stack (
src/stack.ts): Call stack management for debugging and error handling
src/standard/es5/: Implementation of ECMAScript 5 features (expressions, statements, declarations)src/standard/es2015/: Implementation of ES2015+ features (arrow functions, let/const, destructuring)src/standard/index.ts: Combines all language feature implementations into a single visitor map
- Code is parsed into AST using Babel parser
- AST is wrapped in Path objects
- Visitor pattern dispatches each node type to its implementation
- Scope chain manages variable bindings
- Context provides sandboxed global environment
__tests__/helper.ts: Core testing utilities withrun()andrunExp()functions- Tests use Babel to transform modern JavaScript to ES5 when needed
- Supports optional code hoisting and minification for testing edge cases
- The engine operates in strict mode
- All AST node types must have corresponding implementations in
src/standard/ - New language features should be added to appropriate ES version directories
- Context isolation is critical - avoid exposing host environment globals
- Follow the existing visitor pattern for consistency
- 所有对话和文档都使用中文,代码中注释也使用中文
- 文档使用 markdown 格式