|
489 | 489 |
|
490 | 490 | <emu-clause id="sec-position-record-type"> |
491 | 491 | <h1>Position Record</h1> |
492 | | - <p>A <dfn>Position Record</dfn> is a tuple of a non-negative line and non-negative column number:</p> |
| 492 | + <p>A <dfn variants="Position Records">Position Record</dfn> is a tuple of a non-negative line and non-negative column number:</p> |
493 | 493 | <emu-table id="table-position-record-fields" caption="Position Record Fields"> |
494 | 494 | <table> |
495 | 495 | <thead> |
|
683 | 683 | 1. Let _sources_ be DecodeSourceMapSources(_baseURL_, _sourceRootField_, _sourcesField_, _sourcesContentField_, _ignoreListField_). |
684 | 684 | 1. Let _namesField_ be GetOptionalListOfStrings(_json_, *"names"*). |
685 | 685 | 1. Let _mappings_ be DecodeMappings(_mappingsField_, _namesField_, _sources_). |
| 686 | + 1. [declared="a,b"] Sort _mappings_ in ascending order, with a Decoded Mapping Record _a_ being less than a Decoded Mapping Record _b_ if ComparePositions(_a_.[[GeneratedPosition]], _b_.[[GeneratedPosition]]) is ~lesser~. |
686 | 687 | 1. Return the Decoded Source Map Record { [[File]]: _fileField_, [[Sources]]: _sources_, [[Mappings]]: _mappings_ }. |
687 | 688 | </emu-alg> |
688 | 689 |
|
|
1264 | 1265 | 1. Append _mapping_ to _offsetMappings_. |
1265 | 1266 | 1. Set _sourceMap_.[[Mappings]] to the list-concatenation of _sourceMap_.[[Mappings]] and _offsetMappings_. |
1266 | 1267 | 1. Set _previousOffsetPosition_ to _offsetPosition_. |
1267 | | - 1. [declared="a,b"] Let _sortedMappings_ be a copy of _offsetMappings_, sorted in ascending order, with a Decoded Mapping Record _a_ being less than a Decoded Mapping Record _b_ if ComparePositions(_a_.[[GeneratedPosition]], _b_.[[GeneratedPosition]]) is ~lesser~. |
1268 | | - 1. If _sortedMappings_ is not empty, set _previousLastMapping_ to the last element of _sortedMappings_. |
| 1268 | + 1. If _offsetMappings_ is not empty, set _previousLastMapping_ to the last element of _offsetMappings_. |
1269 | 1269 | 1. Return _sourceMap_. |
1270 | 1270 | </emu-alg> |
1271 | 1271 |
|
@@ -1539,6 +1539,75 @@ return lastURL;</code></pre> |
1539 | 1539 | </emu-clause> |
1540 | 1540 | </emu-clause> |
1541 | 1541 |
|
| 1542 | +<emu-clause id="sec-operations-on-source-map-records"> |
| 1543 | + <h1>Operations on source map records</h1> |
| 1544 | + |
| 1545 | + <p>After decoding a source map, source map consumers can use the resulting Decoded Source Map Records to look up position information for debugging or other use cases. This section describes the behaviour of typical operations that may be supported by source map consumers.</p> |
| 1546 | + <p>The GetOriginalPosition operation may be used to query the position in an original source that corresponds to a position in the generated code. For example, this can be used in a debugger to navigate from the generated code to the original source based on a user's mouse click.</p> |
| 1547 | + <p>The GetGeneratedPositionsForOriginalLine is used to query the positions in the generated code that map to a position in the original source. There may be multiple generated code positions that map to a given original position. The result list can be further filtered, for example, to match a particular column. This operation could be used, for example, as part of setting breakpoints at all generated lines that match a particular line in the original source that a user clicks in a debugger.</p> |
| 1548 | + |
| 1549 | + <emu-clause id="sec-GetOriginalPosition" type="abstract operation"> |
| 1550 | + <h1> |
| 1551 | + GetOriginalPosition ( |
| 1552 | + _sourceMapRecord_: a Decoded Source Map Record, |
| 1553 | + _generatedPosition_: a Position Record, |
| 1554 | + ): a Decoded Mapping Record or *null* |
| 1555 | + </h1> |
| 1556 | + <dl class="header"></dl> |
| 1557 | + <emu-alg> |
| 1558 | + 1. Let _mappings_ be _sourceMapRecord_.[[Mappings]]. |
| 1559 | + 1. Let _closest_ be *null*. |
| 1560 | + 1. For each element _mapping_ of _mappings_, do |
| 1561 | + 1. If the result of performing ComparePositions(_mapping_.[[GeneratedPosition]], _generatedPosition_) is ~greater~, then |
| 1562 | + 1. Return _closest_. |
| 1563 | + 1. Else, |
| 1564 | + 1. Set _closest_ to _mapping_. |
| 1565 | + 1. Return _closest_. |
| 1566 | + </emu-alg> |
| 1567 | + </emu-clause> |
| 1568 | + |
| 1569 | + <emu-clause id="sec-GetGeneratedPositionsForOriginalLine" type="abstract operation"> |
| 1570 | + <h1> |
| 1571 | + GetGeneratedPositionsForOriginalLine ( |
| 1572 | + _sourceMapRecord_: a Decoded Source Map Record, |
| 1573 | + _originalSource_: a Decoded Source Record, |
| 1574 | + _originalLine_: a non-negative integral Number, |
| 1575 | + ): a list of Position Records |
| 1576 | + </h1> |
| 1577 | + <dl class="header"></dl> |
| 1578 | + <emu-alg> |
| 1579 | + 1. Let _mappings_ be _sourceMapRecord_.[[Mappings]]. |
| 1580 | + 1. Let _generatedPositions_ be a new empty List. |
| 1581 | + 1. Let _reverseMappings_ be ComputeReverseMappings(_mappings_, _originalSource_). |
| 1582 | + 1. For each element _mapping_ of _reverseMappings_, do |
| 1583 | + 1. Let _originalPosition_ be _mapping_.[[OriginalPosition]]. |
| 1584 | + 1. If _originalPosition_ ≠ *null*, then |
| 1585 | + 1. If _originalPosition_.[[Line]] is equal to _originalLine_, then |
| 1586 | + 1. Append _mapping_.[[GeneratedPosition]] to _generatedPositions_. |
| 1587 | + 1. Return _generatedPositions_. |
| 1588 | + </emu-alg> |
| 1589 | + |
| 1590 | + <emu-clause id="sec-ComputeReverseMappings" type="abstract operation"> |
| 1591 | + <h1> |
| 1592 | + ComputeReverseMappings ( |
| 1593 | + _mappings_: a list of Decoded Mapping Records, |
| 1594 | + _originalSource_: a Decoded Source Record, |
| 1595 | + ): a list of Decoded Mapping Records |
| 1596 | + </h1> |
| 1597 | + <dl class="header"></dl> |
| 1598 | + <emu-alg> |
| 1599 | + 1. Let _reverseMappings_ be a new empty List. |
| 1600 | + 1. For each element _mapping_ of _mappings_, do |
| 1601 | + 1. If _mapping_.[[OriginalSource]] ≠ *null*, then |
| 1602 | + 1. If _mapping_.[[OriginalSource]] and _originalSource_ are the same Decoded Source Record, then |
| 1603 | + 1. Append _mapping_ to _reverseMappings_. |
| 1604 | + 1. [declared="a,b"] Sort _reverseMappings_ in ascending order, with a Decoded Mapping Record _a_ being less than a Decoded Mapping Record _b_ if ComparePositions(_a_.[[GeneratedPosition]], _b_.[[GeneratedPosition]]) is ~lesser~. |
| 1605 | + 1. Return _reverseMappings_. |
| 1606 | + </emu-alg> |
| 1607 | + </emu-clause> |
| 1608 | + </emu-clause> |
| 1609 | +</emu-clause> |
| 1610 | + |
1542 | 1611 | <emu-annex id="sec-conventions"> |
1543 | 1612 | <h1>Conventions</h1> |
1544 | 1613 |
|
|
0 commit comments