Skip to content

fix: align linker output with Angular TypeScript compiler#91

Merged
Brooooooklyn merged 1 commit intomainfrom
fix/linker-alignment-with-angular-ts-compiler
Mar 6, 2026
Merged

fix: align linker output with Angular TypeScript compiler#91
Brooooooklyn merged 1 commit intomainfrom
fix/linker-alignment-with-angular-ts-compiler

Conversation

@Brooooooklyn
Copy link
Member

@Brooooooklyn Brooooooklyn commented Mar 6, 2026

  • fix deps: null to use ɵɵgetInheritedFactory instead of no-args constructor
  • fix deps: 'invalid' to emit ɵɵinvalidFactory()
  • add ForPipe flag (16) for Pipe dependency inject calls
  • fix attribute: true to use token as arg to ɵɵinjectAttribute
  • handle token: null deps with ɵɵinvalidFactoryDep(index)
  • fix useClass != type without deps to delegate to useClass.ɵfac
  • omit providedIn when null (matching TS behavior)
  • refactor extract_deps_source to take target param, generate correct
    inject function directly instead of fragile string replacement
  • only emit standalone: false (omit when true, matching TS default)
  • remove extra type property from defineInjector output
  • omit declarations/imports/exports from defineNgModule in AOT mode
  • add id support and registerNgModuleType IIFE side-effect for NgModules
  • fix link_injectable to use conditional factory pattern for useValue,
    useExisting, useFactory (with deps), and useClass (with deps)
  • fix useFactory without deps to wrap as () => factory()
  • fix useClass === type without deps to include __ngFactoryType__ param
  • fix link_class_metadata_async to extract callback params and read
    decorators/ctorParameters/propDecorators from resolveMetadata return value

Close #89

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


Note

Medium Risk
Touches core linking logic for DI factories/injectables and NgModule/injector emission, which can change runtime behavior if mismatched. Risk is mitigated by extensive new regression tests covering the new edge cases.

Overview
Updates ɵɵngDeclareFactory linking to match Angular semantics for deps: treats deps: null as inherited (uses ɵɵgetInheritedFactory), deps: 'invalid' as ɵɵinvalidFactory(), emits ɵɵinvalidFactoryDep(index) for token: null, fixes @Attribute() handling to pass the dep token, and generates the correct inject function/flags directly (including Pipe ForPipe flag 16 and ɵɵdirectiveInject vs ɵɵinject).

Reworks ɵɵngDeclareInjectable linking to omit providedIn when unset/null and to use Angular’s conditional-factory pattern for useValue, useExisting, and useFactory/useClass (including delegating useClass != type to useClass.ɵfac and wrapping useFactory without deps as () => factory()).

Adjusts emitted definitions to omit standalone when it would be true (only emit standalone: false), removes the extra type field from defineInjector, changes defineNgModule output to omit declarations/imports/exports in AOT mode while adding id support via registerNgModuleType IIFE, and fixes ɵɵngDeclareClassMetadataAsync linking to derive callback params and metadata from resolveMetadata’s returned object. Adds comprehensive tests for all of the above behaviors.

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

Copy link
Member Author

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

@Brooooooklyn Brooooooklyn force-pushed the fix/linker-alignment-with-angular-ts-compiler branch from 92b0851 to d60a641 Compare March 6, 2026 08:04
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.

- fix `deps: null` to use `ɵɵgetInheritedFactory` instead of no-args constructor
- fix `deps: 'invalid'` to emit `ɵɵinvalidFactory()`
- add ForPipe flag (16) for Pipe dependency inject calls
- fix `attribute: true` to use token as arg to `ɵɵinjectAttribute`
- handle `token: null` deps with `ɵɵinvalidFactoryDep(index)`
- fix `useClass != type` without deps to delegate to `useClass.ɵfac`
- omit `providedIn` when null (matching TS behavior)
- refactor `extract_deps_source` to take target param, generate correct
  inject function directly instead of fragile string replacement
- only emit `standalone: false` (omit when true, matching TS default)
- remove extra `type` property from `defineInjector` output
- omit `declarations`/`imports`/`exports` from `defineNgModule` in AOT mode
- add `id` support and `registerNgModuleType` IIFE side-effect for NgModules
- fix `link_injectable` to use conditional factory pattern for useValue,
  useExisting, useFactory (with deps), and useClass (with deps)
- fix `useFactory` without deps to wrap as `() => factory()`
- fix `useClass === type` without deps to include `__ngFactoryType__` param
- fix `link_class_metadata_async` to extract callback params and read
  decorators/ctorParameters/propDecorators from resolveMetadata return value

Close #89

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Brooooooklyn Brooooooklyn force-pushed the fix/linker-alignment-with-angular-ts-compiler branch from d60a641 to 2505237 Compare March 6, 2026 08:27
@Brooooooklyn
Copy link
Member Author

cursor review

@cursor
Copy link

cursor bot commented Mar 6, 2026

Skipping Bugbot: Unable to authenticate your request. Please make sure Bugbot is properly installed and configured for this repository.

@Brooooooklyn Brooooooklyn merged commit ed0568b into main Mar 6, 2026
3 checks passed
@Brooooooklyn Brooooooklyn deleted the fix/linker-alignment-with-angular-ts-compiler branch March 6, 2026 08:35
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.

Linker generates wrong factory for ɵɵngDeclareFactory with deps: null

1 participant