Repository navigation
refactor(@angular/build): lazily evaluate sideEffects in javascript transformer - #34059
Conversation
9e0d2db to
5598ecb
Compare
…ransformer Previously, compiler-plugin.ts eagerly resolved sideEffects for every JavaScript file loaded during bundling by calling await hasSideEffects(request), which executes esbuild's asynchronous build.resolve to inspect package.json. Within the JavaScript transformer, sideEffects is only needed in two specific locations: when checking if a file belongs to node_modules/@angular/ to apply top-level pure function annotations, and when determining whether to wrap decorators in side-effect-free files that lack primary candidate tokens. The sideEffects check is now evaluated lazily. Method signatures on transformData and transformFile have been simplified to accept a TransformOptions interface with an optional async sideEffects resolver callback. Inside hasAdvancedOptimizationCandidates, the resolver is only evaluated if the file matches the node_modules/@angular/ path pattern or contains decorator tokens without primary optimization tokens. If the candidate check does not query sideEffects, the resolver is never invoked, eliminating unnecessary build.resolve calls for bypassed files, linker-only modules, and files matching primary optimization tokens.
5598ecb to
0c7035a
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the JavaScriptTransformer to accept a lazy sideEffects resolver callback instead of a pre-evaluated boolean. It introduces a new TransformOptions interface to group transformation parameters, moves caching logic from transformFile to transformData to ensure both paths benefit from caching, and updates the compiler plugin and tests accordingly. There are no review comments, so no feedback is provided.
|
This PR was merged into the repository. The changes were merged into the following branches:
|
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Previously,
compiler-plugin.tseagerly resolved sideEffects for every JavaScript file loaded during bundling by callingawait hasSideEffects(request), which executes esbuild's asynchronousbuild.resolveto inspectpackage.json.Within the JavaScript transformer,
sideEffectsis only needed in two specific locations: when checking if a file belongs tonode_modules/@angular/to apply top-level pure function annotations, and when determining whether to wrap decorators in side-effect-free files that lack primary candidate tokens.The
sideEffectscheck is now evaluated lazily. Method signatures on transformData and transformFile have been simplified to accept a TransformOptions interface with an optional asyncsideEffectsresolver callback. InsidehasAdvancedOptimizationCandidates, the resolver is only evaluated if the file matches thenode_modules/@angular/path pattern or contains decorator tokens without primary optimization tokens. If the candidate check does not querysideEffects, the resolver is never invoked, eliminating unnecessarybuild.resolvecalls for bypassed files, linker-only modules, and files matching primary optimization tokens.