Repository navigation
perf(@angular/build): avoid TS AST eviction and d.ts re-emit on external resource edits - #34433
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the file reference tracking in the library builder compilation pipeline and improves AOT compilation state persistence by tracking emitted d.ts source files in a WeakSet across compilations instead of using a local Set. Additionally, a new integration test has been added to verify rebuilding behavior and recovery from template errors when external Sass partials or templates are modified. I have no feedback to provide as there are no review comments.
caadb0e to
ee01c14
Compare
…nal resource edits Register external stylesheet dependencies on `stylesheetFile ?? containingFile` in the library builder so modifying an external stylesheet or imported SCSS partial does not add the component `.ts` file to `effectiveModifiedFiles` and evict it from `TypeScriptCompilation`'s AST cache. Instead, `getResourceDependencies` maps the modified stylesheet back to the component `.ts` file via `resourceModifiedFiles` while reusing the cached `ts.SourceFile` AST. Additionally, persist a `WeakSet<ts.SourceFile>` of emitted declaration files on `AngularCompilationState` across incremental watch builds so that unchanged `ts.SourceFile`s re-emitted solely due to external resource edits (`templateUrl` / `styleUrl`) pass `EmitOnly.Js` to `program.emit`, skipping redundant `.d.ts` generation and downstream declaration processing.
ee01c14 to
95c28b8
Compare
|
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. |
This PR implements two watch-mode incremental build optimizations for external Angular component resources (
templateUrlandstyleUrl):Register external stylesheet dependencies on
stylesheetFile ?? containingFile:Previously,
transformStylesheetin the library builder registeredresult.referencedFilesdirectly againstcontainingFile(the component.tsfile). Editing an external stylesheet or an imported SCSS partial therefore added the component.tsfile toeffectiveModifiedFiles, evicting the.tsfile fromTypeScriptCompilation's AST cache and forcing TypeScript to re-read and re-parse the.tsfile on disk. By registering external stylesheet references onstylesheetFile ?? containingFile,expandModifiedFilesexpands an edited_partial.scsstocomp.scss, whichgetResourceDependenciesthen maps tocomp.tsviaresourceModifiedFileswithout evicting the cachedts.SourceFileAST.Skip
.d.tsre-emit (EmitOnly.Js) for unchangedts.SourceFiles on resource-only edits:Persists a
WeakSet<ts.SourceFile>(emittedDtsSourceFiles) onAngularCompilationStateacross incremental watch builds. When a component'sts.SourceFileobject is unchanged in memory (i.e. only its external.htmltemplate or.scss/.cssstylesheet was modified), the fallback emit loop passesEmitOnly.Jstoprogram.emit(), skipping redundant.d.tsgeneration and downstream declaration bundling/processing.