Skip to content

fix(import-elision): keep an @Inject token's import the file also uses as a value elsewhere - #606

Merged
Brooooooklyn merged 1 commit into
voidzero-dev:mainfrom
encharm:fix/inject-token-used-elsewhere
Oct 23, 2026
Merged

Brooooooklyn merged 1 commit into
voidzero-dev:mainfrom
encharm:fix/inject-token-used-elsewhere

Conversation

@Rush

@Rush Rush commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

With advancedOptimizations (no class metadata), an import used in a constructor's @Inject(TOKEN) is elided as decorator-only, since compilation removes the decorator. But it was elided even when the file also uses TOKEN as a value elsewhere:

import { SSR_RENDER_STATE } from './ssr';

@Injectable()
class ServerErrorHandler {
  constructor(@Inject(SSR_RENDER_STATE) private state: SsrRenderState) {}
}

export const providers = [{ provide: SSR_RENDER_STATE, useExisting: 'SsrRenderState' }];

The factory gets i1.SSR_RENDER_STATE through a namespace import, but the named import was removed, so providers referenced an undefined SSR_RENDER_STATE and the bundle threw when loaded. The other value uses were collected by a walk that only looked at classes, plain top-level consts and expression statements; an exported const, a function, a block or export default were missed.

Now a name is decorator-only when every value reference to it (from the semantic model) is inside a decorator compilation removes: the reference ids within Angular's constructor parameter decorators and declare properties' decorators. The walk still proposes the candidates; the references confirm them.

test_inject_token_used_elsewhere_in_the_file_is_kept covers an exported const, an exported and a local function, export default, a block and another class's static property; each kept the import only with the change. The existing elision tests pass unchanged.

…as a value elsewhere

An import used in @Inject(TOKEN) was elided as decorator-only unless the walk of
other value uses saw it, and that walk skipped exported consts, functions and other
statements: `export const providers = [{ provide: TOKEN }]` lost its import. A name
is now decorator-only when every value reference to it is inside a decorator
compilation removes.
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T09:19:15.534121Z 2c36897 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 2c36897b23

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@Brooooooklyn Brooooooklyn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! A small follow-up (aliased @Inject) is coming right after this merges.

@Brooooooklyn
Brooooooklyn merged commit d0bc40e into voidzero-dev:main Oct 23, 2026
9 checks passed
@Brooooooklyn

Copy link
Copy Markdown
Member

Follow-up for aliased @Inject (import { Inject as I }) is in #621.

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.

2 participants