mini-typescript 项目教程
1. 项目的目录结构及介绍
mini-typescript 是一个用于教学目的的 TypeScript 编译器模型。以下是其目录结构的详细介绍:
mini-typescript/
├── baselines/
│ └── reference/
├── src/
│ ├── checker/
│ ├── compiler/
│ ├── parser/
│ ├── program/
│ ├── scanner/
│ ├── transformer/
│ └── types.ts
├── tests/
│ └── singleVar.ts
├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── package-lock.json
├── package.json
└── tsconfig.json
- baselines/: 包含参考基准文件。
- src/: 包含编译器的主要源代码文件。
- checker/: 类型检查器代码。
- compiler/: 编译器核心代码。
- parser/: 解析器代码。
- program/: 程序管理代码。
- scanner/: 扫描器代码。
- transformer/: 转换器代码。
- types.ts: 类型定义文件。
- tests/: 包含测试文件。
- .gitattributes: Git 属性配置文件。
- .gitignore: Git 忽略配置文件。
- LICENSE: 项目许可证。
- README.md: 项目说明文档。
- package-lock.json: npm 依赖锁定文件。
- package.json: npm 项目配置文件。
- tsconfig.json: TypeScript 配置文件。
2. 项目的启动文件介绍
项目的启动文件是 src/compiler/index.ts
。这个文件是编译器的入口点,负责初始化和调用编译器的各个模块。
3. 项目的配置文件介绍
package.json
package.json
文件包含了项目的元数据和依赖信息。以下是一些关键字段:
{
"name": "mini-typescript",
"version": "1.0.0",
"description": "A miniature model of the Typescript compiler intended to teach the structure of the real Typescript compiler",
"main": "src/compiler/index.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"mtsc": "node dist/compiler/index.js"
},
"dependencies": {
"typescript": "^4.0.0"
}
}
- name: 项目名称。
- version: 项目版本。
- description: 项目描述。
- main: 项目入口文件。
- scripts: 包含可执行的脚本命令。
- dependencies: 项目依赖。
tsconfig.json
tsconfig.json
文件包含了 TypeScript 编译器的配置选项。以下是一些关键字段:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true
},
"include": [
"src/**/*"
]
}
- compilerOptions: 编译器选项。
- target: 编译目标版本。
- module: 模块系统。
- outDir: 输出目录。
- strict: 启用严格模式。
- esModuleInterop: 启用 ES 模块互操作。
- include: 包含的文件和目录。