Skip to content

refactor(compiler-cli): extract foreignImports under emitDeclarationOnly in ngtsc - #72339

Draft
atscott wants to merge 1 commit into
angular:mainfrom
atscott:foreign-imports-emit-declaration-only
Draft

atscott wants to merge 1 commit into
angular:mainfrom
atscott:foreign-imports-emit-declaration-only

Conversation

@atscott

@atscott atscott commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

ComponentDecoratorHandler.analyze previously skipped extractForeignImportsFromAst when emitDeclarationOnly was enabled, leaving foreignImports as null. Because analyze still runs analyzeForeignComponentFeatures on the parsed template and compileLocal still ingests the template AST under emitDeclarationOnly, leaving foreignImports unset caused two problems:

Valid components using foreignImports together with @content blocks failed declaration-only emission with a false-positive NG8026 diagnostic claiming @content blocks are only valid as direct children of foreign components (and would fail template ingestion on ContentBlock if not stopped there). Malformed foreignImports entries were also silently skipped under emitDeclarationOnly in ngtsc while NGP still reported NG1010.

Since extractForeignImportsFromAst inspects only the local decorator AST with no cross-file resolution or type-checker dependency, running it unconditionally is safe for isolated declarations, fixes @content under emitDeclarationOnly, and brings ngtsc and NGP into parity.

Verification:

  • bazelisk test //packages/compiler-cli/test/ngtsc:ngtsc //packages/compiler-cli/test/ngtsc:ngtsc_ngp --test_sharding_strategy=disabled --test_arg=--filter="declaration-only emission" (both new tests fail on ngtsc before the fix and pass on both backends after)
  • bazelisk test //packages/compiler-cli/src/ngtsc/annotations/component/test:all //packages/compiler-cli/test/compliance/declaration-only:all (all targets pass)

…nly in ngtsc

`ComponentDecoratorHandler.analyze` previously skipped
`extractForeignImportsFromAst` when `emitDeclarationOnly` was enabled, leaving
`foreignImports` as `null`. Because `analyze` still runs
`analyzeForeignComponentFeatures` on the parsed template and `compileLocal`
still ingests the template AST under `emitDeclarationOnly`, leaving
`foreignImports` unset caused two problems:

Valid components using `foreignImports` together with `@content` blocks failed
declaration-only emission with a false-positive `NG8026` diagnostic claiming
`@content` blocks are only valid as direct children of foreign components
(and would fail template ingestion on `ContentBlock` if not stopped there).
Malformed `foreignImports` entries were also silently skipped under
`emitDeclarationOnly` in `ngtsc` while NGP still reported `NG1010`.

Since `extractForeignImportsFromAst` inspects only the local decorator AST
with no cross-file resolution or type-checker dependency, running it
unconditionally is safe for isolated declarations, fixes `@content` under
`emitDeclarationOnly`, and brings `ngtsc` and NGP into parity.
@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