Skip to content

feat: implement JIT compilation output for transformAngularFile#98

Merged
Brooooooklyn merged 3 commits intomainfrom
feat/jit-compilation-output
Mar 9, 2026
Merged

feat: implement JIT compilation output for transformAngularFile#98
Brooooooklyn merged 3 commits intomainfrom
feat/jit-compilation-output

Conversation

@Brooooooklyn
Copy link
Member

@Brooooooklyn Brooooooklyn commented Mar 8, 2026

When jit: true is passed, the compiler now produces Angular JIT-compatible
output instead of AOT-compiled code. This matches the output format of
Angular CLI's JitCompilation class:

  • Decorator downleveling via __decorate from tslib
  • templateUrl/styleUrl replaced with angular:jit:template:file; imports
  • Constructor params emitted as static ctorParameters for runtime DI
  • Class restructured to let X = class X {}; X = __decorate([...], X);
  • Templates are NOT compiled (runtime JIT compiler handles that)
  • Import elision disabled (ctor param types needed at runtime)

Closes #97

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com


Note

Medium Risk
Introduces a large new transformation/codegen path that changes emitted JS semantics (decorator removal, import insertion, export reshaping), so regressions are possible despite strong test coverage.

Overview
Adds a new jit compilation path to transform_angular_file that emits Angular JIT-compatible JavaScript instead of AOT output.

In JIT mode, Angular-decorated classes (@Component, @Directive, @Pipe, @Injectable, @NgModule) are rewritten to let X = class X { ... }, have decorators removed from the class body, and get a __decorate call (with a new import { __decorate } from "tslib") plus restored exports. Component templateUrl/styleUrl/styleUrls are rewritten into angular:jit:*:file;... imports and template/styles references, and runtime metadata is emitted via static ctorParameters and static propDecorators (including Angular-like union-type handling for ctor param types).

Expands integration coverage with new standalone emission assertions and a comprehensive suite of JIT snapshot tests for templates/resources, class restructuring, DI metadata, and member decorator downleveling.

Written by Cursor Bugbot for commit 56a1f69. This will update automatically on new commits. Configure here.

When `jit: true` is passed, the compiler now produces Angular JIT-compatible
output instead of AOT-compiled code. This matches the output format of
Angular CLI's JitCompilation class:

- Decorator downleveling via `__decorate` from tslib
- templateUrl/styleUrl replaced with `angular:jit:template:file;` imports
- Constructor params emitted as `static ctorParameters` for runtime DI
- Class restructured to `let X = class X {}; X = __decorate([...], X);`
- Templates are NOT compiled (runtime JIT compiler handles that)
- Import elision disabled (ctor param types needed at runtime)

Closes #97

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Brooooooklyn and others added 2 commits March 8, 2026 22:54
…ypes

Fixes two bugs identified in code review:

1. (High) Member decorators (@input, @output, @HostBinding, etc.) were
   removed from class bodies without being emitted as `static propDecorators`.
   Angular's JIT runtime reads `propDecorators` to discover inputs/outputs/
   queries at runtime — without it, data binding silently breaks. Now emits:
     static propDecorators = {
       myInput: [{ type: Input }],
       myOutput: [{ type: Output }],
     };

2. (Medium) `extract_type_name_from_annotation` only skipped TSNullKeyword
   in union types. For `undefined | T` or `null | undefined | T`, the function
   encountered TSUndefinedKeyword first, immediately recursed and returned None,
   never reaching the actual type. Fixed to try each union member and return
   the first resolvable name.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…xpression

Angular's reference filters only `null` literal types from union types
and requires exactly one non-null type to remain. Previously we iterated
all union members and returned the first resolvable one, which is more
permissive than Angular's behavior.

With Angular-aligned semantics:
- `T | null` → resolves to T (1 non-null type remains)
- `undefined | T` → unresolvable (2 non-null types remain)
- `null | undefined | T` → unresolvable (2 non-null types remain)

Unresolvable types emit `{ type: undefined }` matching Angular's
`paramType || ts.factory.createIdentifier('undefined')` fallback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Brooooooklyn Brooooooklyn force-pushed the feat/jit-compilation-output branch from 47a1211 to 56a1f69 Compare March 9, 2026 01:38
@Brooooooklyn Brooooooklyn merged commit 2f40ae5 into main Mar 9, 2026
4 checks passed
@Brooooooklyn Brooooooklyn deleted the feat/jit-compilation-output branch March 9, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JitCompilation-like output

1 participant