Skip to content

refactor(compiler-cli): poison components with malformed foreignImports in ng-analyze - #72338

Draft
atscott wants to merge 1 commit into
angular:mainfrom
atscott:ngp-poison-malformed-foreign-imports
Draft

atscott wants to merge 1 commit into
angular:mainfrom
atscott:ngp-poison-malformed-foreign-imports

Conversation

@atscott

@atscott atscott commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

When a standalone component has malformed foreignImports entries, ngtsc marks the component as poisoned (isPoisoned = true) alongside the NG1010 diagnostics so template type-checking and scope resolution are skipped unless usePoisonedData is enabled. That prevents noisy follow-on template errors like NG8001 for tags that were supposed to be registered by the broken foreignImports entry.

In ng-analyze, non-standalone components with foreignImports were already poisoned, and foreign_import_issues were extracted and reported as NG1010, but optimize_component never marked standalone components as poisoned when foreign_import_issues was non-empty. As a result, the preprocessor still generated a type-check block for those components and surfaced spurious template errors.

This change sets component.is_poisoned = true in optimize_component after optimize_component_scope when a standalone component has any foreign_import_issues. Setting it after scope optimization lets imports and deferredImports validation still report their diagnostics (matching ngtsc), while clearing resolved scope fields when use_poisoned_data is false and keeping well-formed foreign_imports entries intact for template feature analysis and use_poisoned_data consumers.

Verification:

  • bazelisk test //packages/compiler-cli/preprocessor/ng-analyze:test (all 939 tests pass; new tests fail before the fix)
  • bazelisk test //packages/compiler-cli/test/ngtsc:ngtsc //packages/compiler-cli/test/ngtsc:ngtsc_ngp --test_sharding_strategy=disabled --test_arg=--filter="foreign component template semantics" (new test fails on ngtsc_ngp with 4 diagnostics instead of 1 before the fix, passes on both backends after)
  • bazelisk test //packages/compiler-cli/preprocessor/test:test //packages/compiler-cli/preprocessor/test:typecheck_goldens_test (all shards pass with updated foreign_imports_diagnostics/golden.opt.md)

…ts in ng-analyze

When a standalone component has malformed `foreignImports` entries, `ngtsc`
marks the component as poisoned (`isPoisoned = true`) alongside the `NG1010`
diagnostics so template type-checking and scope resolution are skipped unless
`usePoisonedData` is enabled. That prevents noisy follow-on template errors
like `NG8001` for tags that were supposed to be registered by the broken
`foreignImports` entry.

In `ng-analyze`, non-standalone components with `foreignImports` were already
poisoned, and `foreign_import_issues` were extracted and reported as `NG1010`,
but `optimize_component` never marked standalone components as poisoned when
`foreign_import_issues` was non-empty. As a result, the preprocessor still
generated a type-check block for those components and surfaced spurious
template errors.

This change sets `component.is_poisoned = true` in `optimize_component` after
`optimize_component_scope` when a standalone component has any
`foreign_import_issues`. Setting it after scope optimization lets `imports`
and `deferredImports` validation still report their diagnostics (matching
`ngtsc`), while clearing resolved scope fields when `use_poisoned_data` is
false and keeping well-formed `foreign_imports` entries intact for template
feature analysis and `use_poisoned_data` consumers.
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Dec 3, 2026
@ngbot ngbot Bot added this to the Backlog milestone Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant