reference-compiler-cli by angular/angular
npx skills add https://github.com/angular/angular --skill reference-compiler-clingtsc) 架构packages/compiler-cli 包包含了 Angular 编译器 (Ivy),通常被称为 ngtsc。它是 TypeScript 编译器 (tsc) 的一个包装器,为其扩展了 Angular 特有的功能。
ngtsc 的核心目标是将 Angular 装饰器(如 @Component、@Directive、@Pipe)编译成类上的静态属性(Ivy 指令,例如 static ɵcmp = ...)。它还执行模板类型检查和提前 (AOT) 编译。
该编译器被设计为一个的编译流水线。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
NgtscProgram 包装了标准的 ts.Program。它拦截调用,以作为标准工具的直接替代品。o.Expression),然后在发出阶段将其转换为 TypeScript AST 节点。ngtsc/core)NgtscProgram : 实现 api.Program 的公共 API。它管理 ts.Program 和 NgCompiler。NgCompiler : 编译器的大脑。它编排编译阶段(分析、解析、类型检查、发出)。它持有 TraitCompiler。ngtsc/transform)TraitCompiler : 管理"特征"的生命周期。它遍历源文件,识别装饰过的类,并委托给相应的 DecoratorHandler。Trait : 类的状态容器,保存其处理器、分析结果和解析结果。ngtsc/annotations)DecoratorHandler : 用于处理特定装饰器的接口。ComponentDecoratorHandler : 最复杂的处理器。它:
R3TargetBinder)。ɵcmp 指令。DirectiveDecoratorHandler 、PipeDecoratorHandler 、NgModuleDecoratorHandler : 处理它们各自的装饰器。ngtsc/typecheck)TemplateTypeChecker : 生成"类型检查块" (TCBs)。TCB 是一段 TypeScript 代码,它以 tsc 能够理解和检查错误的方式表示模板的逻辑。TypeCheckBlock : 实际生成的代码,用于验证绑定、事件和结构型指令。ngtsc/metadata, ngtsc/scope)MetadataReader : 从源文件(使用 LocalMetadataRegistry)和 .d.ts 文件(使用 DtsMetadataReader)读取 Angular 元数据。ScopeRegistry : 确定组件的"编译作用域"(哪些指令/管道对其可用),处理 NgModule 的传递性导出和独立组件的导入。ngtsc/transform)ivyTransformFactory : 一个 TypeScript 转换器工厂。IvyCompilationVisitor : 访问类,通过 TraitCompiler 触发编译,并收集输出 AST。IvyTransformationVisitor : 将输出 AST 转换为 TypeScript AST,注入 static ɵ... 字段,并移除原始装饰器。NgtscProgram 创建 NgCompiler,后者设置所有注册表和 TraitCompiler。analyzeSync) :
TraitCompiler 扫描文件。DecoratorHandler 提取元数据并解析模板。resolve) :
TraitCompiler 解析特征。ScopeRegistry 找到)。TemplateTypeChecker 为所有组件创建 TCBs。prepareEmit) :
ivyTransformFactory。emit。packages/compiler-cli/src/ngtsc/program.ts: 入口点 (NgtscProgram)。packages/compiler-cli/src/ngtsc/core/src/compiler.ts: 核心逻辑 (NgCompiler)。packages/compiler-cli/src/ngtsc/transform/src/trait.ts: 特征状态机。packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts: 组件编译逻辑。packages/compiler-cli/src/ngtsc/typecheck/src/template_type_checker.ts: 类型检查逻辑。packages/compiler-cli/src/ngtsc/transform/src/transform.ts: AST 转换逻辑。每周安装量
67
代码仓库
GitHub 星标数
100.1K
首次出现
2026年2月11日
安全审计
已安装于
gemini-cli65
github-copilot65
opencode65
amp64
codex64
kimi-cli64
ngtsc) ArchitectureThe packages/compiler-cli package contains the Angular Compiler (Ivy), often referred to as ngtsc. It is a wrapper around the TypeScript compiler (tsc) that extends it with Angular-specific capabilities.
The core goal of ngtsc is to compile Angular decorators (like @Component, @Directive, @Pipe) into static properties on the class (Ivy instructions, e.g., static ɵcmp = ...). It also performs template type checking and ahead-of-time (AOT) compilation.
The compiler is designed as a lazy, incremental, and partial compilation pipeline.
NgtscProgram wraps the standard ts.Program. It intercepts calls to act as a drop-in replacement for standard tooling.o.Expression) for the generated code, which is then translated into TypeScript AST nodes during the emit phase.ngtsc/core)NgtscProgram : The public API implementing api.Program. It manages the ts.Program and the NgCompiler.NgCompiler : The brain of the compiler. It orchestrates the compilation phases (Analysis, Resolution, Type Checking, Emit). It holds the TraitCompiler.ngtsc/transform)TraitCompiler : Manages the lifecycle of "Traits". It iterates over source files, identifies decorated classes, and delegates to the appropriate DecoratorHandler.Trait : A state container for a class, holding its handler, analysis results, and resolution results.ngtsc/annotations)DecoratorHandler : An interface for handling specific decorators.ComponentDecoratorHandler : The most complex handler. It:
R3TargetBinder).ɵcmp instruction.DirectiveDecoratorHandler , PipeDecoratorHandler , NgModuleDecoratorHandler : Handle their respective decorators.ngtsc/typecheck)TemplateTypeChecker : Generates "Type Check Blocks" (TCBs). A TCB is a block of TypeScript code that represents the template's logic in a way tsc can understand and check for errors.TypeCheckBlock : The actual generated code that validates bindings, events, and structural directives.ngtsc/metadata, ngtsc/scope)MetadataReader : Reads Angular metadata from source files (using LocalMetadataRegistry) and .d.ts files (using DtsMetadataReader).ScopeRegistry : Determines the "compilation scope" of a component (which directives/pipes are available to it), handling NgModule transitive exports and Standalone Component imports.ngtsc/transform)ivyTransformFactory : A TypeScript transformer factory.IvyCompilationVisitor : Visits classes, triggers compilation via TraitCompiler, and collects the Output AST.IvyTransformationVisitor : Translates the Output AST into TypeScript AST, injects the static ɵ... fields, and removes the original decorators.NgtscProgram creates NgCompiler, which sets up all registries and the TraitCompiler.analyzeSync):
TraitCompiler scans files.DecoratorHandlers extract metadata and parse templates.resolve):
TraitCompiler resolves traits.packages/compiler-cli/src/ngtsc/program.ts: Entry point (NgtscProgram).packages/compiler-cli/src/ngtsc/core/src/compiler.ts: Core logic (NgCompiler).packages/compiler-cli/src/ngtsc/transform/src/trait.ts: Trait state machine.packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts: Component compilation logic.packages/compiler-cli/src/ngtsc/typecheck/src/template_type_checker.ts: Type checking logic.packages/compiler-cli/src/ngtsc/transform/src/transform.ts: AST transformation logic.Weekly Installs
67
Repository
GitHub Stars
100.1K
First Seen
Feb 11, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli65
github-copilot65
opencode65
amp64
codex64
kimi-cli64
Angular开发者指南:从项目创建到组件与信号式状态管理的最佳实践
564 周安装
Proxychains 网络代理工具:自动解决GitHub/PyPI/npm访问失败和连接超时问题
108 周安装
Windows 基础设施管理员:Active Directory、组策略、PowerShell 自动化与混合身份管理专家
108 周安装
Arize Prompt Optimization - 提示词优化技能详解,提升LLM应用性能与追踪数据分析
188 周安装
Xcode构建性能优化指南:axiom-build-performance 工具使用与Swift编译加速
149 周安装
Nansen Profiler 钱包画像分析器 - 区块链地址余额、交易、盈亏与关联分析工具
133 周安装
Hummingbot 交易机器人 AI 技能:自动化加密货币交易与 DeFi 策略管理
175 周安装
ScopeRegistryTemplateTypeChecker creates TCBs for all components.prepareEmit):
ivyTransformFactory is created.emit is called.