Repository navigation
fix(linker): link declarations wherever they sit, like Babel's linker - #620
Conversation
…pressions Babel's linker links every ɵɵngDeclare* call; this one walked only some expression kinds and missed declarations inside array and object literals, `new` arguments, member and binary expressions, templates and awaits. A library compiled with Deepkit's runtime types records each static initializer as a function in a `static __type = [...]` array, so every class carried an unlinked copy of its declarations, whose `ngImport: i0` kept all of @angular/core in the bundle (+130 KB minified in an app using @deepkit/desktop-ui).
The hand-written walker only went into the statements and expressions it listed, so declarations in an IIFE callee, a spread argument, a statement head, a computed key, a superclass, a tagged template, an optional call or a default value stayed unlinked. An oxc Visit now reaches every call. A linked factory that starts a longer statement, such as `ɵɵngDeclareFactory(…).name;`, gets parentheses (and a `;` before them), like Babel's output, so it is not read as a function declaration. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20f0e0a57a
ℹ️ 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".
… list In the bare body of `if`, `else`, a loop or a label, the `;` became the body itself, so the rest of the statement ran unconditionally. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7420e133ee
ℹ️ 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".
Decorators are now visited, and `@function X_Factory(…) {…}` does not parse.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
Replaces #605, which conflicts with main and sits on an org fork I can't push to. It keeps #605's commit (author: Damian Kaczmarek) and adds a fix on top.
Problem
Babel's linker (
@angular/compiler-cli/linker/babel) links everyɵɵngDeclare*call it meets. This linker used a hand-written walker that only went into the statements and expressions it listed, so declarations elsewhere stayed unlinked, and theirngImport: i0kept all of@angular/corein the bundle. Deepkit's runtime types hit this:static __type = [() => i0.ɵɵngDeclareComponent(...)](+130 KB minified in an app using@deepkit/desktop-ui).Fix
new, member, unary, binary, template andawaitexpressions.Visit, which reaches every call like Babel does (about 270 lines less). When a linked factory starts a longer statement, it now gets parentheses, as in Babel's output.ɵɵngDeclarecalls[() => D],{ m() { return D } }(Deepkit)(() => { class X { static ɵfac = D } … })(),(function(){…}).call(this)f(...[D]),new X(...[D])if (D),for (x = D;;),while,switch,throw,yield,c ? :extends f(D),[D]() {},{ [D]: v }tag`${D}`,a?.b(D),(x = D) => {},import(D)Factory at the start of a statement (
D=ɵɵngDeclareFactory(…)):Checks
cargo test --workspace: 3413 passed. New tests:test_link_declarations_in_any_positionandtest_link_factory_starting_a_statement_keeps_its_meaning.@angular/*fesm2022 files and@deepkit/desktop-ui. All outputs parse. Every declaration is linked: main left 268, this PR leaves 30, and those 30 are the runtime's ownɵɵngDeclare*names incore.mjs/compiler.mjs, which main leaves too. Code and source maps are byte-identical to fix(linker): link declarations nested in arrays, objects and other expressions #605 on the Angular files.core.mjslinks in 0.80 ms (0.78 ms with fix(linker): link declarations nested in arrays, objects and other expressions #605).Not covered (Babel links these, this linker does not yet): a declaration nested inside another declaration's arguments, and the string-key callee
i0["ɵɵngDeclare…"]().Co-authored-by: Damian Kaczmarek rush@rushbase.net
🤖 Generated with Claude Code