mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
a46292af26
For external templates (using `templateUrl`), primary diagnostics are reported against the synthetic `ts.SourceFile` representing the HTML template document. However, secondary related messages (such as those in `foreign_component.ts` and `oob.ts`) were explicitly passing the component's TypeScript file as `sourceFile`. Because the character offsets (`start` and `end`) originate from the HTML template AST, associating them with the TypeScript source file caused IDEs and CLI diagnostics to map HTML offsets onto the `.ts` file, resulting in corrupt or out-of-bounds source locations. This commit resolves the issue by: 1. Making `sourceFile` optional in `makeTemplateDiagnostic` and related checker interfaces (`TemplateTypeChecker`, `TemplateContext`). 2. Defaulting `relatedMessage.sourceFile` to the template's source file (`sf` for external/indirect templates, or the component `.ts` file for direct inline templates) when not explicitly provided. 3. Removing explicit `sourceFile: this.sourceMapping.node.getSourceFile()` mappings from `foreign_component.ts` and DOM element checks in `oob.ts`, allowing them to automatically resolve to the template file. 4. Adding unit test coverage for external templates encountering foreign component conflicts with related messages.