Repository navigation
fix(import-elision): keep imports the output still references - #622
Open
Brooooooklyn wants to merge 1 commit into
Open
Brooooooklyn wants to merge 1 commit into
Brooooooklyn wants to merge 1 commit into
Conversation
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Without class metadata, an import used only in decorators compilation
removes is elided. A name-based walk guessed which decorators those were,
so some imports were dropped while the output still named them, and the
module threw on load:
- `@Inject(forwardRef(() => T))` / `@Inject(NS.x)`: the factory copies
the argument as written
- `@ViewChild(Foo)` / `{ read: Bar }` / `@Input({ transform: fn })` on
a `declare` field: compiled into the definition by local name
- a non-Angular decorator on a `declare` field, Angular param decorators
on a class that isn't compiled, a constructor after the first: they stay
The walk is gone. A reference counts as removed only when the transform
strips it and compiles nothing that names it: on a class with an Angular
class decorator, the first constructor's Angular param decorators (with a
bare `@Inject(X)` argument, which the factory names as `iN.X`) and the
callee of an Angular decorator on a `declare` field. The transform keeps
what an Angular decorator it didn't strip after all references.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Brooooooklyn
force-pushed
the
fix/elision-output-references
branch
from
October 23, 2026 12:18
c282ad5 to
e0b5811
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #606 and #621.
Problem
Without class metadata (
advancedOptimizations/emitClassMetadata: false), import elision drops an import used only in decorators that compilation removes. A walk over local names guessed which decorators those were. Some imports were therefore dropped while the output still named them, and the module threw aReferenceErroron load:@Inject(forwardRef(() => TOKEN)),@Inject(TOKEN.sub)@ViewChild(Foo) declare q/{ read: Bar }ɵɵviewQuery(Foo, …)@Input({ transform: toNum }) declare vinputs: { v: [.., toNum] }@Dec(TOKEN) declare p(not Angular's)__decorate([Dec(TOKEN)], …)@Inject(TOKEN)on a class with no Angular decorator (plain, abstract base)ctor_overload.tscompliance case)@Optional()Fix
The name-based walk is gone (about 350 lines). A reference counts as removed only when the transform strips it and compiles nothing that names it. That happens only on a class with an Angular class decorator:
@Inject(X)when it is a bare identifier, since the factory names itiN.X.declarefields: the callee of an Angular decorator, but not its arguments.An import is elided when every value reference to it is removed. After compiling, the transform also keeps whatever an Angular decorator references when that decorator was left in place after all.
A few rare shapes now keep an import that could have gone, which is safe:
@Inject(TOKEN.sub)on a component,@ViewChild(forwardRef(…)) declare,@Input({ alias: CONST }) declare.Checks
tests/import_elision_output_references_test.rs: 12 tests compile throughtransform_angular_filewithadvanced_optimizations. Each "kept" test also checks that the output names the import, so nothing is kept for no reason. 11 fail on the base. The control (@Optional() @Inject(TOKEN)on an@Injectablestill drops all three; the output hasi1.TOKEN) passes on both.test_declare_property_viewchild_arg_elidedasserted the wrong elision (the query names the predicate). It is now…_kept.cargo test --workspace: 3427 passed.--all-features: 3528 passed. vitest: 376 passed. Strict compare: 1162 fixtures, 0 mismatches..tsfiles (14,625 imports) compiled withadvancedOptimizations, checked against their own output. Elided imports the output still uses went from 3 on the base to 0. Imports kept but unused: 0. Only those 3 imports changed.Not changed: with constructor overloads, the factory still reads the first constructor, not the implementation as ngtsc does. The import is kept now, so the module loads, but the factory's deps still differ from ngtsc's.
🤖 Generated with Claude Code