Skip to content

feat: add additional template source location metadata - #68564

Closed
rictic wants to merge 1 commit into
angular:mainfrom
rictic:html-source-loc
Closed

rictic wants to merge 1 commit into
angular:mainfrom
rictic:html-source-loc

Conversation

@rictic

@rictic rictic commented May 4, 2026

Copy link
Copy Markdown

Part of an internal project at Google, but likely useful more broadly. Similar to the existing source locations op, but this is template system agnostic and includes more precise ranges suitable for bidirectionally mapping between source code and HTML.

Doc with more internal info: go/html-source-loc.

I'm piggybacking off of job.enableDebugLocations but happy to create a new flag for this purpose instead.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the new behavior?

This adds a new kind of opt-in debug metadata.

Does this PR introduce a breaking change?

  • Yes
  • No

@pullapprove
pullapprove Bot requested a review from crisbeto May 4, 2026 23:43
@angular-robot angular-robot Bot added the detected: feature PR contains a feature commit label May 4, 2026
@rictic
rictic force-pushed the html-source-loc branch from ec96746 to 056012e Compare May 5, 2026 00:16
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label May 5, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 5, 2026
Part of an internal project at Google, but likely useful more broadly. Similar to the existing source locations op, but this is template system agnostic and includes more precise ranges suitable for bidirectionally mapping between source code and HTML.

Doc with more internal info: go/html-source-loc.
@rictic
rictic force-pushed the html-source-loc branch from 056012e to f1fee0f Compare May 5, 2026 00:36
env.driveMain();
const content = env.getContents('test.js');
expect(content).toContain('ɵɵdomElementStart(0, "div")(1, "span")(2, "strong");');
expect(content).toContain('ɵɵdomElementStart(0, "div", 0)(1, "span", 1)(2, "strong", 2);');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did these additional arguments show up?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's because there are additional attributes on the elements now, because of the new data-sourcecode-loc attributes being added when the flag that controls this feature is enabled

import * as ir from '../../ir';
import type {ComponentCompilationJob} from '../compilation';

/**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we reuse the existing attachSourceLocations here? As far as I can tell the main differences here are:

  1. We attach more information here (e.g. both start and end positions).
  2. We can call the attribute something different.
  3. The formatting is different.

We only have one user of this internally so we can work with them to account for any changes we make to the formatting.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool, I wasn't sure that there weren't more users. I'm coordinating with that user for them to suppor data-sourcecode-loc. Follow along at https://b.corp.google.com/510157286

@crisbeto

Copy link
Copy Markdown
Member

We ended up handling this through #70303.

@crisbeto crisbeto closed this Aug 27, 2026
@angular-automatic-lock-bot

Copy link
Copy Markdown

This pull request has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Oct 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: compiler Issues related to `ngc`, Angular's template compiler detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants