Skip to content

Commit e4912a3

Browse files
committed
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
1 parent 6f1d343 commit e4912a3

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

spec.emu

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,10 @@
684684
1. Let _ignoreListField_ be GetOptionalListOfArrayIndexes(_json_, *"ignoreList"*).
685685
1. Let _sources_ be DecodeSourceMapSources(_baseURL_, _sourceRootField_, _sourcesField_, _sourcesContentField_, _ignoreListField_).
686686
1. Let _namesField_ be GetOptionalListOfStrings(_json_, *"names"*).
687+
1. Let _mappings_ be DecodeMappings(_mappingsField_, _namesField_, _sources_).
687688
1. <ins>Let _rangeMappingsField_ be GetOptionalString(_json_, *"rangeMappings"*).</ins>
688689
1. <ins>Let _rangeMappings_ be DecodeRangeMappings(_rangeMappingsField_).</ins>
689-
1. Let _mappings_ be DecodeMappings(_mappingsField_, _namesField_, _sources_, <ins>_rangeMappings_</ins>).
690+
1. <ins>Perform UpdateMappingsForRangeMappings(_mappings_, _rangeMappings_).</ins>
690691
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~.
691692
1. Return the Decoded Source Map Record { [[File]]: _fileField_, [[Sources]]: _sources_, [[Mappings]]: _mappings_ }.
692693
</emu-alg>
@@ -921,10 +922,6 @@
921922
<td>[[NameIndex]]</td>
922923
<td>a non-negative integer</td>
923924
</tr>
924-
<tr>
925-
<td><ins>[[MappingIndex]]</ins></td>
926-
<td><ins>a non-negative integer</ins></td>
927-
</tr>
928925
</table>
929926
</emu-table>
930927

@@ -935,7 +932,6 @@
935932
_mappings_: a List of Decoded Mapping Records,
936933
_names_: a List of Strings,
937934
_sources_: a List of Decoded Source Records,
938-
<ins>_rangeMappings_: a List of of Decoded Range Mapping Offset Records,</ins>
939935
)
940936
</h1>
941937
<dl class="header"></dl>
@@ -944,11 +940,10 @@
944940
Line `;` LineList
945941
</emu-grammar>
946942
<emu-alg>
947-
1. Perform DecodeMappingsField of |Line| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
943+
1. Perform DecodeMappingsField of |Line| with arguments _state_, _mappings_, _names_ and _sources_.
948944
1. Set _state_.[[GeneratedLine]] to _state_.[[GeneratedLine]] + 1.
949945
1. Set _state_.[[GeneratedColumn]] to 0.
950-
1. <ins>Set _state_.[[MappingIndex]] to 0.</ins>
951-
1. Perform DecodeMappingsField of |LineList| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
946+
1. Perform DecodeMappingsField of |LineList| with arguments _state_, _mappings_, _names_ and _sources_.
952947
</emu-alg>
953948
<emu-grammar>
954949
Line : [empty]
@@ -961,50 +956,47 @@
961956
Mapping `,` MappingList
962957
</emu-grammar>
963958
<emu-alg>
964-
1. Perform DecodeMappingsField of |Mapping| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
965-
1. Perform DecodeMappingsField of |MappingList| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
959+
1. Perform DecodeMappingsField of |Mapping| with arguments _state_, _mappings_, _names_ and _sources_.
960+
1. Perform DecodeMappingsField of |MappingList| with arguments _state_, _mappings_, _names_ and _sources_.
966961
</emu-alg>
967962
<emu-grammar>
968963
Mapping :
969964
GeneratedColumn
970965
</emu-grammar>
971966
<emu-alg>
972-
1. Perform DecodeMappingsField of |GeneratedColumn| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
967+
1. Perform DecodeMappingsField of |GeneratedColumn| with arguments _state_, _mappings_, _names_ and _sources_.
973968
1. If _state_.[[GeneratedColumn]] &lt; 0, then
974969
1. Optionally report an error.
975970
1. Return.
976971
1. Let _position_ be a new Position Record { [[Line]]: _state_.[[GeneratedLine]], [[Column]]: _state_.[[GeneratedColumn]] }.
977972
1. Let _decodedMapping_ be a new DecodedMappingRecord { [[GeneratedPosition]]: _position_, [[OriginalPosition]]: *null*, [[Name]]: *null*, <ins>[[IsRangeMapping]]: *false*</ins> }.
978973
1. Append _decodedMapping_ to _mappings_.
979-
1. <ins>Set _state_.[[MappingIndex]] to _state_.[[MappingIndex]] + 1.</ins>
980974
</emu-alg>
981975
<emu-grammar>
982976
Mapping :
983977
GeneratedColumn OriginalSource OriginalLine OriginalColumn Name?
984978
</emu-grammar>
985979
<emu-alg>
986-
1. Perform DecodeMappingsField of |GeneratedColumn| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
980+
1. Perform DecodeMappingsField of |GeneratedColumn| with arguments _state_, _mappings_, _names_ and _sources_.
987981
1. If _state_.[[GeneratedColumn]] &lt; 0, then
988982
1. Optionally report an error.
989983
1. Return.
990984
1. Let _generatedPosition_ be a new Position Record { [[Line]]: _state_.[[GeneratedLine]], [[Column]]: _state_.[[GeneratedColumn]] }.
991-
1. Perform DecodeMappingsField of |OriginalSource| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
992-
1. Perform DecodeMappingsField of |OriginalLine| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
993-
1. Perform DecodeMappingsField of |OriginalColumn| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
985+
1. Perform DecodeMappingsField of |OriginalSource| with arguments _state_, _mappings_, _names_ and _sources_.
986+
1. Perform DecodeMappingsField of |OriginalLine| with arguments _state_, _mappings_, _names_ and _sources_.
987+
1. Perform DecodeMappingsField of |OriginalColumn| with arguments _state_, _mappings_, _names_ and _sources_.
994988
1. If _state_.[[SourceIndex]] &lt; 0 or _state_.[[SourceIndex]] ≥ the number of elements of _sources_ or _state_.[[OriginalLine]] &lt; 0 or _state_.[[OriginalColumn]] &lt; 0, then
995989
1. Optionally report an error.
996990
1. Let _originalPosition_ be *null*.
997991
1. Else,
998992
1. Let _originalPosition_ be a new Original Position Record { [[Source]]: _sources_[_state_.[[SourceIndex]]], [[Line]]: _state_.[[OriginalLine]], [[Column]]: _state_.[[OriginalColumn]] }.
999993
1. Let _name_ be *null*.
1000994
1. If |Name| is present, then
1001-
1. Perform DecodeMappingsField of |Name| with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
995+
1. Perform DecodeMappingsField of |Name| with arguments _state_, _mappings_, _names_ and _sources_.
1002996
1. If _state_.[[NameIndex]] &lt; 0 or _state_.[[NameIndex]] ≥ the number of elements of _names_, optionally report an error.
1003997
1. Else, set _name_ to _names_[_state_.[[NameIndex]]].
1004-
1. <ins>Let _isRangeMapping_ be the result of performing LookupRangeMapping with arguments _rangeMappings_, _state_.[[GeneratedLine]], and _state_.[[MappingIndex]].</ins>
1005-
1. Let _decodedMapping_ be a new DecodedMappingRecord { [[GeneratedPosition]]: _generatedPosition_, [[OriginalPosition]]: _originalPosition_, [[Name]]: _name_, <ins>[[IsRangeMapping]]: _isRangeMapping_</ins> }.
998+
1. Let _decodedMapping_ be a new DecodedMappingRecord { [[GeneratedPosition]]: _generatedPosition_, [[OriginalPosition]]: _originalPosition_, [[Name]]: _name_, <ins>[[IsRangeMapping]]: *false*</ins> }.
1006999
1. Append _decodedMapping_ to _mappings_.
1007-
1. <ins>Set _state_.[[MappingIndex]] to _state_.[[MappingIndex]] + 1.</ins>
10081000
</emu-alg>
10091001
<emu-grammar>
10101002
GeneratedColumn :
@@ -1055,7 +1047,6 @@
10551047
_rawMappings_: a String,
10561048
_names_: a List of Strings,
10571049
_sources_: a List of Decoded Source Records,
1058-
<ins>_rangeMappings_: a List of Decoded Range Mapping Offset Records,</ins>
10591050
): a List of Decoded Mapping Record
10601051
</h1>
10611052
<dl class="header"></dl>
@@ -1066,7 +1057,7 @@
10661057
1. Optionally report an error.
10671058
1. Return _mappings_.
10681059
1. Let _state_ be a new Decode Mapping State Record with all fields set to 0.
1069-
1. Perform DecodeMappingsField of _mappingsNode_ with arguments _state_, _mappings_, _names_<ins>,</ins> <del>and</del> _sources_ <ins>and _rangeMappings_</ins>.
1060+
1. Perform DecodeMappingsField of _mappingsNode_ with arguments _state_, _mappings_, _names_ and _sources_.
10701061
1. Return _mappings_.
10711062
</emu-alg>
10721063
</emu-clause>
@@ -1255,21 +1246,44 @@
12551246
</emu-alg>
12561247
</emu-clause>
12571248

1258-
<emu-clause id="sec-LookupRangeMapping" type="abstract operation">
1249+
<emu-clause id="sec-UpdateMappingsForRangeMapping" type="abstract operation">
12591250
<h1>
1260-
LookupRangeMapping (
1261-
_rangeMappings_: a List of Decoded Range Mapping Offset Records,
1262-
_generatedLine_: an integral Number,
1263-
_mappingIndex_: an integral Number,
1264-
): a Boolean
1251+
UpdateMappingsForRangeMappings (
1252+
_mappings_: a List of Decoded Mapping Records,
1253+
_rangeMappingsOffsets_: a List of Decoded Range Mapping Offset Records,
1254+
): ~unused~
12651255
</h1>
12661256
<dl class="header"></dl>
12671257
<emu-alg>
1268-
1. Let _rangeMappingOffset_ be a new Decoded Range Mapping Offset Record { [[GeneratedLine]] : _generatedLine_, [[MappingIndex]]: _mappingIndex_ }.
1269-
1. If _rangeMappingOffset_ is an element of _rangeMappings_, then
1270-
1. Return *true*.
1271-
1. Else,
1272-
1. Return *false*.
1258+
1. For each Decoded Range Mapping Offset Record _rangeMappingOffset_ of _rangeMappingsOffsets_, do
1259+
1. Let _mapping_ be the result of FindMappingForRangeMappingOffset(_mappings_, _rangeMappingOffset_).
1260+
1. If _mapping_ is ~not-found~, optionally report an error.
1261+
1. If _mapping_.[[OriginalPosition]] is *null*, optionally report an error.
1262+
1. Assert: _mapping_.[[IsRangeMapping]] is *false*.
1263+
1. Set _mapping_.[[IsRangeMapping]] to *true*.
1264+
</emu-alg>
1265+
</emu-clause>
1266+
1267+
<emu-clause id="sec-FindMappingForRangeMappingOffset" type="abstract operation">
1268+
<h1>
1269+
FindMappingForRangeMappingOffset (
1270+
_mappings_: a List of Decoded Mapping Records,
1271+
_offset_: a Decoded Range Mapping Offset Record,
1272+
): a Decoded Mapping Record or ~not-found~
1273+
</h1>
1274+
<dl class="header"></dl>
1275+
<emu-alg>
1276+
1. Let _currentLine_ be *null*.
1277+
1. Let _currentIndex_ be 0.
1278+
1. For each Decoded Mapping Record _mapping_ of _mappings_, do
1279+
1. If _currentLine_ ≠ _mapping_.[[GeneratedLine]], then
1280+
1. Set _currentLine_ to _mapping_.[[GeneratedLine]].
1281+
1. Set _currentIndex_ to 0.
1282+
1. Else,
1283+
1. Set _currentIndex_ to _currentIndex_ + 1.
1284+
1. If _currentLine_ = _offset_.[[GeneratedLine]] and _currentIndex_ = _offset_.[[MappingIndex]], then
1285+
1. Return _mapping_.
1286+
1. Return ~not-found~.
12731287
</emu-alg>
12741288
</emu-clause>
12751289
</emu-clause>

0 commit comments

Comments
 (0)