Skip to content

Commit bc0c080

Browse files
committed
feat: 建立文档站
1 parent f3b0de9 commit bc0c080

File tree

3 files changed

+135
-1
lines changed

3 files changed

+135
-1
lines changed

.github/workflows/docs.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: 部署文档
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- 'docs/**'
9+
- '.github/workflows/docs.yml'
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
concurrency:
18+
group: "pages"
19+
cancel-in-progress: false
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
defaults:
25+
run:
26+
working-directory: ./docs
27+
28+
steps:
29+
- name: 检出代码
30+
uses: actions/checkout@v4
31+
32+
- name: 设置 Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: 18
36+
cache: npm
37+
cache-dependency-path: docs/package-lock.json
38+
39+
- name: 安装依赖
40+
run: npm ci
41+
42+
- name: 构建文档
43+
run: npm run build
44+
45+
- name: 上传构建产物
46+
uses: actions/upload-pages-artifact@v3
47+
with:
48+
path: ./docs/build
49+
50+
deploy:
51+
environment:
52+
name: github-pages
53+
url: ${{ steps.deployment.outputs.page_url }}
54+
runs-on: ubuntu-latest
55+
needs: build
56+
steps:
57+
- name: 部署到 GitHub Pages
58+
id: deployment
59+
uses: actions/deploy-pages@v4

CLAUDE.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
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).
8+
9+
## Development Commands
10+
11+
### Building
12+
```bash
13+
npm run build # Build the project using Rollup
14+
```
15+
16+
### Testing
17+
```bash
18+
npm test # Run all tests with Jest
19+
npm run test:coverage # Run tests with coverage report
20+
npm run test:debug # Run tests in debug mode with inspector
21+
```
22+
23+
### Code Quality
24+
```bash
25+
npm run typecheck # Type check with TypeScript (use this to verify changes)
26+
```
27+
28+
Note: There are no lint commands defined in package.json. Always run `npm run typecheck` after making changes to ensure TypeScript compliance.
29+
30+
## Architecture Overview
31+
32+
### Core Components
33+
34+
- **VM (`src/vm.ts`)**: Main entry point providing `run()`, `runInContext()`, and `createContext()` functions
35+
- **Visitor Pattern (`src/visitor.ts`)**: Central dispatcher that routes AST nodes to appropriate handlers
36+
- **Context (`src/context.ts`)**: Sandboxed execution environment with global objects (ECMAScript standard globals)
37+
- **Scope (`src/scope.ts`)**: Variable scope management system
38+
- **Path (`src/path.ts`)**: AST node wrapper providing traversal context
39+
- **Stack (`src/stack.ts`)**: Call stack management for debugging and error handling
40+
41+
### Language Support Structure
42+
43+
- **`src/standard/es5/`**: Implementation of ECMAScript 5 features (expressions, statements, declarations)
44+
- **`src/standard/es2015/`**: Implementation of ES2015+ features (arrow functions, let/const, destructuring)
45+
- **`src/standard/index.ts`**: Combines all language feature implementations into a single visitor map
46+
47+
### Key Execution Flow
48+
49+
1. Code is parsed into AST using Babel parser
50+
2. AST is wrapped in Path objects
51+
3. Visitor pattern dispatches each node type to its implementation
52+
4. Scope chain manages variable bindings
53+
5. Context provides sandboxed global environment
54+
55+
### Test Structure
56+
57+
- **`__tests__/helper.ts`**: Core testing utilities with `run()` and `runExp()` functions
58+
- Tests use Babel to transform modern JavaScript to ES5 when needed
59+
- Supports optional code hoisting and minification for testing edge cases
60+
61+
## Implementation Guidelines
62+
63+
- The engine operates in strict mode
64+
- All AST node types must have corresponding implementations in `src/standard/`
65+
- New language features should be added to appropriate ES version directories
66+
- Context isolation is critical - avoid exposing host environment globals
67+
- Follow the existing visitor pattern for consistency
68+
69+
## 语言规范
70+
71+
- 所有对话和文档都使用中文,代码中注释也使用中文
72+
- 文档使用 markdown 格式

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
"test:debug": "npx --node-arg=--inspect-brk jest -i",
1313
"babel": "babel --config-file babel.config.js ./babel/src --out-dir ./babel/result",
1414
"typecheck": "tsc --project tsconfig.json --noEmit #",
15-
"report-coverage": "cat ./coverage/lcov.info | coveralls"
15+
"report-coverage": "cat ./coverage/lcov.info | coveralls",
16+
"docs:dev": "cd docs && npm start",
17+
"docs:build": "cd docs && npm run build",
18+
"docs:install": "cd docs && npm install"
1619
},
1720
"keywords": [],
1821
"author": "ximing",

0 commit comments

Comments
 (0)