Skip to content

fix(compiler): report the template position of HTML-to-R3 transform errors - #748

Open
eintim wants to merge 1 commit into
voidzero-dev:mainfrom
eintim:fix/template-transform-error-location
Open

eintim wants to merge 1 commit into
voidzero-dev:mainfrom
eintim:fix/template-transform-error-location

Conversation

@eintim

@eintim eintim commented Nov 30, 2026

Copy link
Copy Markdown

Fixes #742.

A template error found after HTML parsing, such as @for loop must have a "track" expression, was reported with only its message. For a component with a templateUrl, vite build then pointed at the component's .ts file, with nothing to say where the error was in the HTML:

<section>
  <h2>Items</h2>
  @for (item of [1, 2]) {
    <p>{{ item }}</p>
  }
</section>

It now reports the position ngc gives (broken.component.html:3:3):

@for loop must have a "track" expression
./broken.component.html:3:3

Root cause

Template errors come from two stages. HTML parse errors carry a position since #568: file:line:column in the help text, which the Vite plugin appends to the message. Errors from the HTML-to-R3 transform carry a correct span too, but it was dropped when they were converted to diagnostics. Only the linker path kept it.

Changes

  • compile_component_full, compile_component_template, compile_template_to_js_with_options and compile_template_for_hmr convert R3 transform errors with html_parse_error_diagnostic, as they already do for HTML parse errors. Each uses the same template origin as its HTML-error branch, so an inline template that appears verbatim in the source also gets a label, and the HMR path reports a line and column within the template.
  • html_parse_error_diagnostic returns only the message for an error without a position. Expression parser errors have an empty default span; their message gives the column within the expression. This check was inline in compile_template_for_linker, which now relies on the shared one.
  • No change to the Vite plugin: describeDiagnostic already appends the help text.

…rrors

Errors raised while transforming the parsed template into the R3 AST, such
as `@for loop must have a "track" expression`, were converted to
diagnostics with only their message, dropping the span they carry. For a
`templateUrl` component, `vite build` then pointed at the component's `.ts`
file with no hint of where the error was in the HTML.

Convert them with `html_parse_error_diagnostic`, like HTML parse errors:
`file:line:column` in the help text (and a label for an inline template
that appears verbatim in the source). The function now leaves an error
without a position (an expression parser error) as its message alone, a
check only the linker path had.

Fixes voidzero-dev#742
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vite build omits the HTML filename, line, and column for external template errors

1 participant