perf(@angular/build): unify Oxc linking and optimization AST traversal passes - #33880
perf(@angular/build): unify Oxc linking and optimization AST traversal passes#33880alan-agius4 wants to merge 1 commit into
Conversation
1213c1a to
6f022a0
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the Angular partial declaration linking process by integrating it directly into the unified OXC transformation pass, eliminating the need for a separate AST traversal. A new OxcLinker class is introduced to handle individual CallExpression nodes during the main traversal. Feedback focuses on optimizing this integration: first, by checking if a node is already edited before attempting to link it in oxc-transform.ts to prevent redundant operations and potential magic-string conflicts; second, by passing oxcLink instead of shouldLink to transformWithOxc in javascript-transformer-worker.ts to avoid duplicate linking when the Babel linker has already been executed.
| Program(node) { | ||
| adjustTypeScriptEnumsInStatements(node.body); | ||
| adjustStaticMembersInStatements(node.body); | ||
| 'Program:exit'(node) { |
There was a problem hiding this comment.
Changed Program and BlockStatement to 'Program:exit' and 'BlockStatement:exit' so that child AST nodes (like CallExpression) are visited before statement-level IIFE wrapping occurs.
…l passes Combine partial declaration linking and advanced optimizations into a single AST traversal pass over one Oxc parseSync AST in oxc-transform. This eliminates duplicate AST parses and MagicString sourcemap remapping chains when transforming Angular packages.
1c2a4fc to
ddc3ecf
Compare
Unifies Angular partial declaration linking and production AST optimizations into a single Oxc AST traversal pass.
Previously in
transformJavaScriptImpl, when both linking (shouldLink) and production optimizations (advancedOptimizations) were active, OxcparseSyncwas invoked twice per file, deserializing ASTs across the Rust/NAPI boundary twice and generating intermediateMagicStringsourcemaps that required merging via@ampproject/remapping.Changes
oxc-transform.ts):oxc-transformvisitor traversal.parseSyncis invoked only once per file.CallExpression(node), the visitor checks for partial declarations (such asɵɵngDeclareComponent) using the newOxcLinkerclass and links them in-place in the sharedMagicStringinstance while continuing on to elide metadata and annotate top-level pure functions in the same traversal.oxc-linker.ts):oxc-linker.tsto export theOxcLinkerclass, encapsulatingFileLinker,OxcAstHost, andInlineDeclarationScopewith a cleanlinkCallExpression(node)method.javascript-transformer-worker.ts):linkWithOxcandtransformWithOxccalls with a single unified call totransformWithOxc.