Skip to content

Range mappings: spec text for proposal#233

Open
takikawa wants to merge 3 commits intomainfrom
proposal-range-mappings
Open

Range mappings: spec text for proposal#233
takikawa wants to merge 3 commits intomainfrom
proposal-range-mappings

Conversation

@takikawa
Copy link
Collaborator

@takikawa takikawa commented Oct 20, 2025

This is the actual PR for the draft range mappings proposal for detailed review. Comments and feedback welcome.

On the other PR #232, Nic raised some points about what we should do in case there are multiple mappings in one location and only one (or a subset) are range mappings.

https://tc39.es/ecma426/pr/233/

Adds a flag to Decoded Mapping Records which indicate if
a mapping is a range mapping. Populate this field based on
the decoded range mapping offsets.
Comment on lines 1572 to +1728
1. If the result of performing ComparePositions(_last_.[[GeneratedPosition]], _mapping_.[[GeneratedPosition]]) is ~equal~, then
1. Append _mapping_.[[OriginalPosition]] to _originalPositions_.
1. <ins>If _mapping_.[[IsRangeMapping]] is true, then</ins>
Copy link
Member

Choose a reason for hiding this comment

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

(copy-pasting my message from the other PR, to make it more visible)


If we are looking at the mappings at e here:

abcdefg

and we have none but we have two mappings right before at c, out of which one is the range mappings, maybe we should exclude the non-range one? Since the range one actually ends up being an exact match.

Not exactly sure though.

spec.emu Outdated
<td>a non-negative integer</td>
</tr>
<tr>
<td><ins>[[MappingIndex]]</ins></td>
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can we call this something with "range mapping"?

1. If _relativeIndex_ is 0, then
1. Optionally report an error.
1. Set _state_.[[MappingIndex]] to _state_.[[MappingIndex]] + _relativeIndex_.
1. Let _rangeMappingOffset_ be a new Decoded Range Mapping Offset Record { [[GeneratedLine]]: _state_.[[GeneratedLine]], [[MappingIndex]]: _state_.[[MappingIndex]] - 1 }.
Copy link
Member

Choose a reason for hiding this comment

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

Why are we dealing with 1-based indexes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

WIth 1-based indices the error check is pretty simpler, and it's just to reject 0. In the future we could re-use the 0 value for something if there's a need.

If it were 0-based, we would need to error or no-op if a 0 shows up but it's not the first value in the line.

Copy link
Member

Choose a reason for hiding this comment

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

Going though this in code, I still hate it. When I'm reading the relative offsets, I don't want to think about 1-indexing. I would rather this be 0-index, and push the complication into error checking.

This is not a strong objection though, because I can just start my relatives at -1 and treat it like it's 0-index anyways. It just hurts my brain to reason about.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we can revisit this & discuss in the next TG4 meeting. It's not crucial to the proposal that it be 1-based, so if it's confusing to deal with then we could consider changing it back and just adding the error checks.

* Address some quick fixes from review

* Move null check into decode operation

* Return an empty List on null range mappings
* Refactor range mapping decoding based on feedback

  * Range mapping decoding happens separate of and after mapping decoding now
  * Mappings are updated in-place to add range mapping info

* Continue if mapping is NOT-FOUND in range mapping update
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _currentLine_ be *null*.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: -1, so we have a consistent number type?

Comment on lines +1284 to +1287
1. Else,
1. Set _currentIndex_ to _currentIndex_ + 1.
1. If _currentLine_ = _offset_.[[GeneratedLine]] and _currentIndex_ = _offset_.[[MappingIndex]], then
1. Return _mapping_.
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
1. Else,
1. Set _currentIndex_ to _currentIndex_ + 1.
1. If _currentLine_ = _offset_.[[GeneratedLine]] and _currentIndex_ = _offset_.[[MappingIndex]], then
1. Return _mapping_.
1. If _currentLine_ = _offset_.[[GeneratedLine]] and _currentIndex_ = _offset_.[[MappingIndex]], then
1. Return _mapping_.
1. Set _currentIndex_ to _currentIndex_ + 1.

1. If _relativeIndex_ is 0, then
1. Optionally report an error.
1. Set _state_.[[MappingIndex]] to _state_.[[MappingIndex]] + _relativeIndex_.
1. Let _rangeMappingOffset_ be a new Decoded Range Mapping Offset Record { [[GeneratedLine]]: _state_.[[GeneratedLine]], [[MappingIndex]]: _state_.[[MappingIndex]] - 1 }.
Copy link
Member

Choose a reason for hiding this comment

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

Going though this in code, I still hate it. When I'm reading the relative offsets, I don't want to think about 1-indexing. I would rather this be 0-index, and push the complication into error checking.

This is not a strong objection though, because I can just start my relatives at -1 and treat it like it's 0-index anyways. It just hurts my brain to reason about.

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.

3 participants