-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathspec.emu
1434 lines (1288 loc) · 76.8 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en-GB-oxendict">
<meta charset="utf-8">
<link rel="icon" href="img/favicon.ico">
<style>
#metadata-block {
margin: 4em 0;
padding: 10px;
border: 1px solid #ee8421;
}
#metadata-block h1 {
font-size: 1.5em;
margin-top: 0;
}
#metadata-block > ul {
list-style-type: none;
margin: 0; padding: 0;
}
#ecma-logo {
width: 500px;
}
/* TODO: Get proper Ecmarkup support for examples */
emu-note[example] {
--note-type: example;
--note-label: "Example";
--note-text-color: #574b0f;
--note-border-color: #e0cb52;
--note-background-color: #fcfaee;
}
emu-note[issue] {
--note-type: issue;
--note-label: "Issue";
--note-border-color: #e05252;
--note-background-color: #fbe9e9;
}
emu-note[issue], emu-note[example] {
counter-increment: var(--note-type);
border-left-color: var(--note-border-color);
background-color: var(--note-background-color);
padding: 0.5em;
&::before {
content: var(--note-label) "\00A0" counter(var(--note-type));
color: var(--note-text-color, black);
text-transform: uppercase;
}
& .note {
display: none;
}
}
emu-clause[example][normative-optional] .attributes-tag emu-xref {
display: none;
}
emu-clause[example][normative-optional] .attributes-tag::before {
content: "Example";
}
dfn code {
font-style: normal;
}
emu-annex#sec-external-definitions dd dfn {
font-style: normal;
}
</style>
<pre class="metadata">
title: Source map format specification
shortname: ECMA-426
status: draft
location: https://tc39.es/ecma426/
</pre>
<p><img src="img/ecma-logo.svg" id="ecma-logo" alt="Ecma International logo"></p>
<div id="metadata-block">
<h1>About this Specification</h1>
<p>The document at <a href="https://tc39.es/ecma426/">https://tc39.es/ecma426/</a> is the most accurate and up-to-date source map specification. It contains the content of the most recently published snapshot plus any modifications that will be included in the next snapshot.</p>
<h1>Contributing to this Specification</h1>
<p>This specification is developed on GitHub. There are a number of ways to contribute to the development of this specification:</p>
<ul>
<li>GitHub Repository: <a href="https://github.com/tc39/ecma426">https://github.com/tc39/ecma426</a></li>
<li>Issues: <a href="https://github.com/tc39/ecma426/issues">All Issues</a>, <a href="https://github.com/tc39/ecma426/issues/new">File a New Issue</a></li>
<li>Pull Requests: <a href="https://github.com/tc39/ecma426/pulls">All Pull Requests</a>, <a href="https://github.com/tc39/ecma426/pulls/new">Create a New Pull Request</a></li>
<li>Test Suite: <a href="https://github.com/tc39/source-map-tests/">tc39/source-map-tests</a></li>
<li>
Editors:
<ul>
<li><a href="https://github.com/takikawa">Asumu Takikawa</a> (Igalia)</li>
</ul>
</li>
</ul>
<p>Refer to the <emu-xref href="#sec-colophon">colophon</emu-xref> for more information on how this document is created.</p>
</div>
<emu-intro id="sec-intro">
<h1>Introduction</h1>
<p>This Ecma Standard defines the Source map format, used for mapping transpiled source code back to the original sources.</p>
<p>The source map format has the following goals:</p>
<ul>
<li>Support source-level debugging allowing bidirectional mapping</li>
<li>Support server-side stack trace deobfuscation</li>
</ul>
<p>The <emu-not-ref>original source</emu-not-ref> map format (v1) was created by Joseph Schorr for use by Closure Inspector to enable source-level debugging of optimized JavaScript code (although the format itself is language agnostic). However, as the size of the projects using source maps expanded, the verbosity of the format started to become a problem. The v2 format (Source Map Revision 2 Proposal) was created by trading some simplicity and flexibility to reduce the overall size of the source map. Even with the changes made with the v2 version of the format, the source map file size was limiting its usefulness. The v3 format is based on suggestions made by Pavel Podivilov (Google).</p>
<p>The source map format does not have version numbers anymore, and it is instead hard-coded to always be "3".</p>
<p>In 2023-2024, the source map format was developed into a more precise Ecma standard, with significant contributions from many people. Further iteration on the source map format is expected to come from TC39-TG4.</p>
<p>
Asumu Takikawa, Nicolò Ribaudo, Jon Kuperman<br/>
ECMA-426, 1<sup>st</sup> edition, Project Editors
</p>
</emu-intro>
<emu-clause id="sec-scope">
<h1>Scope</h1>
<p>This Standard defines the source map format, used by different types of developer tools to improve the debugging experience of code compiled to JavaScript, WebAssembly, and CSS.</p>
</emu-clause>
<emu-clause id="sec-conformance">
<h1>Conformance</h1>
<p>A conforming source map document is a JSON document that conforms to the structure detailed in this specification.</p>
<p>A conforming source map generator should generate documents which are conforming source map documents, and can be decoded by the algorithms in this specification without reporting any errors (even those which are specified as optional).</p>
<p>A conforming source map consumer should implement the algorithms specified in this specification for retrieving (where applicable) and decoding source map documents. A conforming consumer is permitted to ignore errors or report them without terminating where the specification indicates that an algorithm may optionally report an error.</p>
</emu-clause>
<emu-clause id="sec-references">
<h1>References</h1>
<p>The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.</p>
<!-- All documents listed here must also be listed in the "Biography" annex. -->
<emu-clause id="sec-references-normative">
<h1>Normative References</h1>
<p>
ECMA-262, <i>ECMAScript® Language Specification</i>.<br>
<a href="https://tc39.es/ecma262/">https://tc39.es/ecma262/</a>
</p>
<p>
ECMA-404, <i>The JSON Data Interchange Format</i>.<br>
<a href="https://www.ecma-international.org/publications-and-standards/standards/ecma-404/">https://www.ecma-international.org/publications-and-standards/standards/ecma-404/</a>
</p>
</emu-clause>
<emu-clause id="sec-references-informative">
<h1>Informative References</h1>
<!-- NOTE: These references should actually be normative, but Ecma is allergic to normatively referencing web specs. As a rule of thumb, Ecma/IEEE/Unicode specs can go in the "normative" section, while the rest should go here. -->
<p>
IETF RFC 4648, <i>The Base16, Base32, and Base64 Data Encodings</i>.<br>
<a href="https://datatracker.ietf.org/doc/html/rfc4648">https://datatracker.ietf.org/doc/html/rfc4648</a>
</p>
<p>
<i>WebAssembly Core Specification</i>.<br>
<a href="https://www.w3.org/TR/wasm-core-2/">https://www.w3.org/TR/wasm-core-2/</a>
</p>
<p>
WHATWG <i>Encoding</i>.<br>
<a href="https://encoding.spec.whatwg.org/">https://encoding.spec.whatwg.org/</a>
</p>
<p>
WHATWG <emu-not-ref><i>Fetch</i></emu-not-ref>.<br>
<a href="https://fetch.spec.whatwg.org/">https://fetch.spec.whatwg.org/</a>
</p>
<p>
WHATWG <i>Infra</i>.<br>
<a href="https://infra.spec.whatwg.org/">https://infra.spec.whatwg.org/</a>
</p>
<p>
WHATWG <emu-not-ref><i>URL</i></emu-not-ref>.<br>
<a href="https://url.spec.whatwg.org/">https://url.spec.whatwg.org/</a>
</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-notational-conventions">
<h1>Notational Conventions</h1>
<p>This specification follows the same notational conventions as defined by <a href="https://tc39.es/ecma262/#sec-notational-conventions">ECMA-262 (Notational conventions)</a>, with the extensions defined in this section.</p>
<emu-clause id="sec-algorithm-conventions">
<h1>Algorithm Conventions</h1>
<emu-clause id="sec-implicit-completions">
<h1>Implicit Completions</h1>
<p>All abstract operations declared in this specification are implicitly assumed to either return a normal completion containing the algorithm's declared return type, or a throw completion. For example, an abstract operation declared as</p>
<blockquote>
<emu-clause id="example-get-the-answer" type="abstract operation" example>
<h1>
GetTheAnswer (
_input_: an integer,
): an integer
</h1>
<dl class="header"></dl>
</emu-clause>
</blockquote>
<p>is equivalent to:</p>
<blockquote>
<emu-clause id="example-get-the-answer-2" type="abstract operation" example>
<h1>
GetTheAnswer2 (
_input_: an integer,
): either a normal completion containing an integer or a throw completion
</h1>
<dl class="header"></dl>
</emu-clause>
</blockquote>
<p>All calls to abstract operations that return completion records are implicitly assumed to be wrapped by a ReturnIfAbrupt macro, unless they are explicitly wrapped by an explicit Completion call. For example:</p>
<emu-alg>
1. Let _result_ be GetTheAnswer(_value_).
1. Let _second_ be Completion(GetTheAnswer(_value_)).
</emu-alg>
<p>is equivalent to:</p>
<emu-alg>
1. Let _result_ be ReturnIfAbrupt(GetTheAnswer(_value_)).
1. Let _second_ be Completion(GetTheAnswer(_value_)).
</emu-alg>
</emu-clause>
<emu-clause id="sec-optional-errors">
<h1>Optional Errors</h1>
<p>Whenever an algorithm is to <dfn>optionally report an error</dfn>, an implementation may choose one of the following behaviors:</p>
<ul>
<li>Continue executing the rest of the algorithm.</li>
<li>Report an error to the user (for example, in the browser console), and continue executing the rest of the algorithm.</li>
<li>Return a ThrowCompletion.</li>
</ul>
<p>An implementation can choose different behaviors for different optional errors.</p>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-terms-and-definitions">
<h1>Terms and Definitions</h1>
<p>For the purposes of this document, the following terms and definitions apply.</p>
<dl>
<dt><dfn id="sec-terms-and-definitions-generated-code">generated code</dfn></dt>
<dd>
<p>code which is generated by the compiler or transpiler.</p>
</dd>
<dt><dfn id="sec-terms-and-definitions-original-source">original source</dfn></dt>
<dd>
<p>source code which has not been passed through a compiler or transpiler.</p>
</dd>
<dt><dfn id="sec-terms-and-definitions-base64-vlq">base64 VLQ</dfn></dt>
<dd>
<p>a <emu-xref href="#sec-references-informative">base64</emu-xref>-encoded variable-length quantity, where the most significant bit (the 6th bit) is used as the continuation bit, and the "digits" are encoded into the string least significant first, and where the least significant bit of the first digit is used as the sign bit.</p>
<emu-note>The values that can be represented by the base64 VLQ encoding are limited to 32-bit quantities until some use case for larger values is presented. This means that values exceeding 32-bits are invalid and implementations may reject them. The sign bit is counted towards the limit, but the continuation bits are not.</emu-note>
<emu-note example>
The string `"iB"` represents a base64 VLQ with two digits. The first digit `"i"` encodes the bit pattern `0x100010`, which has a continuation bit of `1` (the VLQ continues), a sign bit of `0` (non-negative), and the value bits `0x0001`. The second digit `B` encodes the bit pattern `0x000001`, which has a continuation bit of `0`, no sign bit, and value bits `0x00001`. The decoding of this VLQ string is the number 17.
</emu-note>
<emu-note example>
The string `"V"` represents a base64 VLQ with one digit. The digit `"V"` encodes the bit pattern `0x010101`, which has a continuation bit of `0` (no continuation), a sign bit of `1` (negative), and the value bits `0x1010`. The decoding of this VLQ string is the number -10.
</emu-note>
</dd>
<dt><dfn id="sec-terms-and-definitions-source-mapping-url">source map URL</dfn></dt>
<dd>
<p>URL referencing the location of a source map from the generated code.</p>
</dd>
<dt><dfn id="sec-terms-and-definitions-colun">column</dfn></dt>
<dd>
<p>zero-based indexed offset within a line of the generated code, computed as UTF-16 code units for JavaScript and CSS source maps, and as byte indexes in the binary content (represented as a single line) for WebAssembly source maps.</p>
<emu-note>That means that "A" (`LATIN CAPITAL LETTER A`) measures as 1 code unit, and "🔥" (`FIRE`) measures as 2 code units. Source maps for other content types may diverge from this.</emu-note>
</dd>
</dl>
</emu-clause>
<emu-clause id="sec-json-values-utilities">
<h1>JSON values utilities</h1>
<p>While this specification's algorithms are defined on top of ECMA-262 internals, it is meant to be easily implementable by non-JavaScript platforms. This section contains utilities for working with JSON values, abstracting away ECMA-262 details from the rest of the document.</p>
<p>A <dfn id="type-json-value" variants="JSON values">JSON value</dfn> is either a JSON object, a JSON array, a <emu-xref href="#sec-ecmascript-language-types-string-type">String</emu-xref>, a <emu-xref href="#sec-ecmascript-language-types-number-type">Number</emu-xref>, a <emu-xref href="#sec-ecmascript-language-types-boolean-type">Boolean</emu-xref>, or <emu-xref href="#sec-ecmascript-language-types-null-type">*null*</emu-xref>.</p>
<p>A <dfn id="type-json-object">JSON object</dfn> is an Object such that each of its properties:</p>
<ul>
<li>is a data property,</li>
<li>has a String key,</li>
<li>has JSON value value.</li>
</ul>
<p>A <dfn id="type-json-array">JSON array</dfn> is a JSON object such that:</p>
<ul>
<li>it has a property whose key is *"length"* and whose value is a Number,</li>
<li>all its other properties' keys are integer indices.</li>
</ul>
<emu-clause id="sec-ParseJSON" type="abstract operation">
<h1>
ParseJSON (
_string_: a String,
): a JSON value
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _result_ be Call(<emu-xref href="#sec-json.parse">%JSON.parse%</emu-xref>, *null*, « _string_ »).
1. Assert: _result_ is a JSON value.
1. Return _result_.
</emu-alg>
<emu-note type="editor">
This abstract operation is in the process of being exposed by ECMA-262 itself, at <a href="https://github.com/tc39/ecma262/pull/3540">tc39/ecma262#3540</a>.
</emu-note>
</emu-clause>
<emu-clause id="sec-JSONObjectGet" type="abstract operation">
<h1>
JSONObjectGet (
_object_: a JSON object,
_key_: a String,
): a JSON value or ~missing~
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns the value associated with the specified _key_ in _object_.</dd>
</dl>
<emu-alg>
1. If _object_ does not have an own property with key _key_, return ~missing~.
1. Let _prop_ be _object_'s own property whose key is _key_.
1. Return _prop_'s [[Value]] attribute.
</emu-alg>
</emu-clause>
<emu-clause id="sec-JSONArrayIterate" type="abstract operation">
<h1>
JSONArrayIterate (
_array_: a JSON array,
): a List of JSON values
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns a List containing all elements of _array_, so that it can be iterated by algorithms using "For each".</dd>
</dl>
<emu-alg>
1. Let _length_ be JSONObjectGet(_array_, *"length"*).
1. Assert: _length_ is a non-negative integral Number.
1. Let _list_ be a new empty List.
1. Let _i_ be 0.
1. While _i_ < ℝ(_length_), do
1. Let _value_ be JSONObjectGet(_array_, ToString(𝔽(_i_))).
1. Assert: _value_ is not ~missing~.
1. Append _value_ to _list_.
1. Set _i_ to _i_ + 1.
1. Return _list_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-StringSplit" type="abstract operation">
<h1>
StringSplit (
_string_: a String,
_separators_: a List of String
): a List of Strings
</h1>
<dl class="header">
<dt>description</dt>
<dd>It splits the string in substrings separated by any of the elements of _separators_. If multiple separators match, those appearing first in _separators_ have higher priority.</dd>
</dl>
<emu-alg>
1. Let _parts_ be a new empty List.
1. Let _strLen_ be the length of _string_.
1. Let _lastStart_ be 0.
1. Let _i_ be 0.
1. While _i_ < _strLen_, do
1. Let _matched_ be *false*.
1. For each _sep_ of _separators_, do
1. Let _sepLen_ be the length of _sep_.
1. Let _candidate_ be the substring of _string_ from _i_ to min(_i_ + _sepLen_, _strLen_).
1. If _candidate_ = _sep_ and _matched_ is *false*, then
1. Let _chunk_ be the substring of _string_ from _lastStart_ to _i_.
1. Append _chunk_ to _parts_.
1. Set _lastStart_ to _i_ + _sepLen_.
1. Set _i_ to _i_ + _sepLen_.
1. Set _matched_ to *true*.
1. If _matched_ is *false*, set _i_ to _i_ + 1.
1. Let _chunk_ be the substring of _string_ from _lastStart_ to _strLen_.
1. Append _chunk_ to _parts_.
1. Return _parts_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-source-map-format">
<h1>Source map format</h1>
<p>A source map is a JSON document containing a top-level JSON object with the following structure:</p>
<pre><code class="json">
{
"version" : 3,
"file": "out.js",
"sourceRoot": "",
"sources": ["foo.js", "bar.js"],
"sourcesContent": [null, null],
"names": ["src", "maps", "are", "fun"],
"mappings": "A,AAAB;;ABCDE"
"ignoreList": [0]
}
</code></pre>
<ul>
<li>The <dfn id="json-version"><code>version</code> field</dfn> shall always be the number 3 as an integer. The source map may be rejected if the field has any other value.</li>
<li>The <dfn id="json-file"><code>file</code> field</dfn> is an optional name of the generated code that this source map is associated with. It's not specified if this can be an URL, relative path name, or just a base name. Source map generators may choose the appropriate interpretation for their contexts of use.</li>
<li>The <dfn id="json-sourceRoot"><code>sourceRoot</code> field</dfn> is an optional source root string, used for relocating source files on a server or removing repeated values in the sources entry. This value is prepended to the individual entries in the sources field.</li>
<li>The <dfn id="json-sources"><code>sources</code> field</dfn> is a list of original sources used by the mappings field. Each entry is either a string that is a (potentially relative) URL or *null* if the source name is not known.</li>
<li>The <dfn id="json-sourcesContent"><code>sourcesContent</code> field</dfn> is an optional list of source content (i.e. the original source) strings, used when the source cannot be hosted. The contents are listed in the same order as in the sources field. Entries may be *null* if some <emu-xref href="#sec-terms-and-definitions-original-source">original sources</emu-xref> should be retrieved by name.</li>
<li>The <dfn id="json-names"><code>names</code> field</dfn> is an optional list of symbol names which may be used by the mappings field.</li>
<li>The <dfn id="json-mappings"><code>mappings</code> field</dfn> is a string with the encoded mapping data (see section <emu-xref href="#sec-mappings"></emu-xref>).</li>
<li>The <dfn id="json-ignoreList"><code>ignoreList</code> field</dfn> is an optional list of indices of files that should be considered third party code, such as framework code or bundler-<emu-not-ref>generated code</emu-not-ref>. This allows developer tools to avoid code that developers likely don't want to see or step through, without requiring developers to configure this beforehand. It refers to the sources field and lists the indices of all the known third-party sources in the source map. Some browsers may also use the deprecated `x_google_ignoreList` field if `ignoreList` is not present.</li>
</ul>
<emu-clause id="sec-decoding-source-maps">
<h1>Decoding source maps</h1>
<p>A <dfn id="decoded-source-map-record" variants="Decoded Source Map Records">Decoded Source Map Record</dfn> has the following fields:</p>
<emu-table id="table-decoded-source-map-fields" caption="Fields of Decoded Source Map Records">
<table>
<thead>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
</tr>
</thead>
<tr>
<td>[[File]]</td>
<td>a String or *null*</td>
</tr>
<tr>
<td>[[Sources]]</td>
<td>a List of Decoded Source Records</td>
</tr>
<tr>
<td>[[Mappings]]</td>
<td>a List of Decoded Mapping Records</td>
</tr>
</table>
</emu-table>
<p>A <dfn id="decoded-source-record" variants="Decoded Source Records">Decoded Source Record</dfn> has the following fields:</p>
<emu-table id="table-decoded-source-fields" caption="Fields of Decoded Source Records">
<table>
<thead>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
</tr>
</thead>
<tr>
<td>[[URL]]</td>
<td>a URL or *null*</td>
</tr>
<tr>
<td>[[Content]]</td>
<td>a String or *null*</td>
</tr>
<tr>
<td>[[Ignored]]</td>
<td>a Boolean</td>
</tr>
</table>
</emu-table>
<emu-clause id="sec-ParseSourceMap" type="abstract operation">
<h1>
ParseSourceMap (
_string_: a String,
_baseURL_: an URL,
): a Decoded Source Map Record
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _json_ be ParseJSON(_string_).
1. If _json_ is not a JSON object, throw an error.
1. If JSONObjectGet(_json_, *"sections"*) is not ~missing~, then
1. Return DecodeIndexSourceMap(_json_, _baseURL_).
1. Return DecodeSourceMap(_json_, _baseURL_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-DecodeSourceMap" type="abstract operation">
<h1>
DecodeSourceMap (
_json_: a JSON object,
_baseURL_: an URL,
): a Decoded Source Map Record
</h1>
<dl class="header"></dl>
<emu-alg>
1. If JSONObjectGet(_json_, *"version"*) is not *3*<sub>𝔽</sub>, optionally report an error.
1. Let _mappingsField_ be JSONObjectGet(_json_, *"mappings"*).
1. If _mappingsField_ is not a String, throw an error.
1. If JSONObjectGet(_json_, *"sources"*) is not a JSON array, throw an error.
1. Let _fileField_ be GetOptionalString(_json_, *"file"*).
1. Let _sourceRootField_ be GetOptionalString(_json_, *"sourceRoot"*).
1. Let _sourcesField_ be GetOptionalListOfOptionalStrings(_json_, *"sources"*).
1. Let _sourcesContentField_ be GetOptionalListOfOptionalStrings(_json_, *"sourcesContent"*).
1. Let _ignoreListField_ be GetOptionalListOfArrayIndexes(_json_, *"ignoreList"*).
1. Let _sources_ be DecodeSourceMapSources(_baseURL_, _sourceRootField_, _sourcesField_, _sourcesContentField_, _ignoreListField_).
1. Let _namesField_ be GetOptionalListOfStrings(_json_, *"names"*).
1. Let _mappings_ be DecodeMappings(_mappingsField_, _namesField_, _sources_).
1. Let _sourceMap_ be the Decoded Source Map Record { [[File]]: _fileField_, [[Sources]]: _sources_, [[Mappings]]: _mappings_ }.
</emu-alg>
<emu-clause id="sec-GetOptionalString" type="abstract operation">
<h1>
GetOptionalString(
_object_: a JSON object,
_key_: a String,
): a String or *null*
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _value_ be JSONObjectGet(_object_, _key_).
1. If _value_ is a String, return _value_.
1. If _value_ is not ~missing~, optionally report an error.
1. Return *null*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-GetOptionalListOfStrings" type="abstract operation">
<h1>
GetOptionalListOfStrings(
_object_: a JSON object,
_key_: a String,
): a List of Strings
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _list_ be a new empty List.
1. Let _values_ be JSONObjectGet(_object_, _key_).
1. If _values_ is ~missing~, return _list_.
1. If _values_ is not a JSON array, then
1. Optionally report an error.
1. Return _list_.
1. For each element _item_ of JSONArrayIterate(_values_),
1. If _item_ is a String, append _item_ to _list_.
1. Else,
1. Optionally report an error.
1. Append *""* to _list_.
1. Return _list_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-GetOptionalListOfOptionalStrings" type="abstract operation">
<h1>
GetOptionalListOfOptionalStrings(
_object_: a JSON object,
_key_: a String,
): a List of either Strings or *null*
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _list_ be a new empty List.
1. Let _values_ be JSONObjectGet(_object_, _key_).
1. If _values_ is ~missing~, return _list_.
1. If _values_ is not a JSON array, then
1. Optionally report an error.
1. Return _list_.
1. For each element _item_ of JSONArrayIterate(_values_),
1. If _item_ is a String, append _item_ to _list_.
1. Else,
1. If _item_ ≠ *null*, optionally report an error.
1. Append *null* to _list_.
1. Return _list_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-GetOptionalListOfArrayIndexes" type="abstract operation">
<h1>
GetOptionalListOfArrayIndexes(
_object_: an Object,
_key_: a String,
): a List of non-negative integers
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _list_ be a new empty List.
1. Let _values_ be JSONObjectGet(_object_, _key_).
1. If _values_ is ~missing~, return _list_.
1. If _values_ is not a JSON array, then
1. Optionally report an error.
1. Return _list_.
1. For each element _item_ of JSONArrayIterate(_values_),
1. If _item_ is an integral Number, _item_ ≠ *0*<sub>𝔽</sub>, and _item_ ≥ *0*<sub>𝔽</sub>, then
1. Append ℝ(_item_) to _list_.
1. Else,
1. If _item_ ≠ *null*, optionally report an error.
<!-- TODO: Should this step be removed, so that the list only contains numbers? -->
1. Append *null* to _list_.
1. Return _list_.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-mappings">
<h1>Mappings structure</h1>
<p>The mappings field data is broken down as follows:</p>
<ul>
<li>each group representing a line in the generated file is separated by a semicolon (`;`)</li>
<li>each segment is separated by a comma (`,`)</li>
<li>each segment is made up of 1, 4, or 5 variable length fields.</li>
</ul>
<p>The fields in each segment are:</p>
<ol>
<li>The zero-based starting column of the line in the generated code that the segment represents. If this is the first field of the first segment, or the first segment following a new generated line (`;`), then this field holds the whole base64 VLQ. Otherwise, this field contains a base64 VLQ that is relative to the previous occurrence of this field. <em>Note that this is different from the subsequent fields below because the previous value is reset after every generated line.</em></li>
<li>If present, the zero-based index into the sources list. This field contains a base64 VLQ relative to the previous occurrence of this field, unless it is the first occurrence of this field, in which case the whole value is represented.</li>
<li>If present, the zero-based starting line in the original source. This field contains a base64 VLQ relative to the previous occurrence of this field, unless it is the first occurrence of this field, in which case the whole value is represented. Shall be present if there is a source field.</li>
<li>If present, the zero-based starting column of the line in the original source. This field contains a base64 VLQ relative to the previous occurrence of this field, unless it is the first occurrence of this field, in which case the whole value is represented. Shall be present if there is a source field.</li>
<li>If present, the zero-based index into the names list associated with this segment. This field contains a base64 VLQ relative to the previous occurrence of this field, unless it is the first occurrence of this field, in which case the whole value is represented.</li>
</ol>
<emu-note>The purpose of this encoding is to reduce the source map size. VLQ encoding reduced source maps by 50% relative to the Source Map Revision 2 Proposal in tests performed using Google Calendar.</emu-note>
<emu-note>Segments with one field are intended to represent generated code that is unmapped because there is no corresponding original source code, such as code that is generated by a compiler. Segments with four fields represent mapped code where a corresponding name does not exist. Segments with five fields represent mapped code that also has a mapped name.</emu-note>
<emu-note>Using <emu-not-ref>file</emu-not-ref> offsets was considered but rejected in favor of using line/<emu-not-ref>column</emu-not-ref> data to avoid becoming misaligned with the original due to platform-specific line endings.</emu-note>
<p>A <dfn id="decoded-mapping-record" variants="Decoded Mapping Records">Decoded Mapping Record</dfn> has the following fields:</p>
<emu-table id="table-decoded-mapping-fields" caption="Fields of Decoded Mapping Records">
<table>
<thead>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
</tr>
</thead>
<tr>
<td>[[GeneratedLine]]</td>
<td>a non-negative integer</td>
</tr>
<tr>
<td>[[GeneratedColumn]]</td>
<td>a non-negative integer</td>
</tr>
<tr>
<td>[[OriginalSource]]</td>
<td>a Decoded Source Record or *null*</td>
</tr>
<tr>
<td>[[OriginalLine]]</td>
<td>a non-negative integer or *null*</td>
</tr>
<tr>
<td>[[OriginalColumn]]</td>
<td>a non-negative integer or *null*</td>
</tr>
<tr>
<td>[[Name]]</td>
<td>a String or *null*</td>
</tr>
</table>
</emu-table>
<emu-clause id="sec-DecodeMappings" type="abstract operation">
<h1>
DecodeMappings (
_mappings_: a String,
_names_: a List of Strings,
_sources_: a List of Decoded Source Records,
): a List of Decoded Mapping Record
</h1>
<dl class="header"></dl>
<emu-alg>
1. Perform ValidateBase64VLQGroupings(_mappings_).
1. Let _decodedMappings_ be a new empty List.
1. Let _groups_ be StringSplit(_mappings_, « *";"* »).
1. Let _generatedLine_ be 0.
1. Let _originalLine_ be 0.
1. Let _originalColumn_ be 0.
1. Let _sourceIndex_ be 0.
1. Let _nameIndex_ be 0.
1. Repeat, while _generatedLine_ is less than the number of elements of _groups_,
1. If _groups_[_generatedLine_] ≠ *""*, then
1. Let _segments_ be StringSplit(_groups_[_generatedLine_], « *","* »).
1. Let _generatedColumn_ be 0.
1. For each _segment_ of _segments_, do
1. Let _position_ be the Record { [[Value]]: 0 }.
1. Let _relativeGeneratedColumn_ be DecodeBase64VLQ(_segment_, _position_).
1. If _relativeGeneratedColumn_ = *null*, optionally report an error.
1. Else,
1. Set _generatedColumn_ to _generatedColumn_ + _relativeGeneratedColumn_.
1. If _generatedColumn_ < 0, optionally report an error.
1. Else,
1. Let _decodedMapping_ be the Decoded Mapping Record { [[GeneratedLine]]: _generatedLine_, [[GeneratedColumn]]: _generatedColumn_, [[OriginalSource]]: *null*, [[OriginalLine]]: *null*, [[OriginalColumn]]: *null*, [[Name]]: *null* }.
1. Append _decodedMapping_ to _decodedMappings_.
1. Let _relativeSourceIndex_ be DecodeBase64VLQ(_segment_, _position_).
1. Let _relativeOriginalLine_ be DecodeBase64VLQ(_segment_, _position_).
1. Let _relativeOriginalColumn_ be DecodeBase64VLQ(_segment_, _position_).
1. If _relativeOriginalColumn_ = *null* and _relativeSourceIndex_ ≠ *null*, optionally report an error.
1. Else if _relativeOriginalColumn_ ≠ *null*,
1. Set _sourceIndex_ to _sourceIndex_ + _relativeSourceIndex_.
1. Set _originalLine_ to _originalLine_ + _relativeOriginalLine_.
1. Set _originalColumn_ to _originalColumn_ + _relativeOriginalColumn_.
1. If _sourceIndex_ < 0, _originalLine_ < 0, _originalColumn_ < 0, or _sourceIndex_ ≥ the number of elements of _source_, then
1. Optionally report an error.
1. Else,
1. Set _decodedMapping_.[[OriginalSource]] to _sources_[_sourceIndex_].
1. Set _decodedMapping_.[[OriginalLine]] to _originalLine_.
1. Set _decodedMapping_.[[OriginalColumn]] to _originalColumn_.
1. Let _relativeNameIndex_ be DecodeBase64VLQ(_segment_, _position_).
1. If _relativeNameIndex_ ≠ *null*, then
1. Set _nameIndex_ to _nameIndex_ + _relativeNameIndex_.
1. If _nameIndex_ < 0 or _nameIndex_ ≥ the number of elements of _names_, then
1. Optionally report an error.
1. Else,
1. Set _decodedMapping_.[[Name]] to _names_[_nameIndex_].
1. If _position_.[[Value]] ≠ length of _segment_, optionally report an error.
1. Set _generatedLine_ to _generatedLine_ + 1.
1. Return _decodedMappings_.
</emu-alg>
<emu-clause id="sec-ValidateBase64VLQGroupings" type="abstract operation">
<h1>
ValidateBase64VLQGroupings (
_groupings_: a String,
): ~unused~
</h1>
<dl class="header"></dl>
<emu-alg>
1. If _groupings_ contains any code unit other than:
<ul>
<li>U+002B (`+`), U+002C (`,`), U+002F (`/`), or U+003B (`;`);</li>
<li>U+0030 (`0`) to U+0039 (`9`);</li>
<li>U+0041 (`A`) to U+005A (`Z`);</li>
<li>U+0061 (`a`) to U+007A (`z`)</li>
</ul>
throw an error.
1. Return ~unused~.
</emu-alg>
<emu-note>These are the valid <emu-xref href="#sec-references-informative">base64</emu-xref> characters (excluding the padding character `=`), together with `,` and `;`.</emu-note>
</emu-clause>
<emu-clause id="sec-DecodeBase64VLQ" type="abstract operation">
<h1>
DecodeBase64VLQ (
_segment_: a String,
_position_: a Record with a non-negative integer [[Value]] field,
): an integer or *null*
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _segmentLen_ be the length of _segment_.
1. If _position_.[[Value]] = _segmentLen_, return *null*.
1. Let _first_ be ConsumeBase64ValueAt(_segment_, _position_).
1. Assert: _first_ < 64.
1. If _first_ modulo 2 is 0, let _sign_ be 1.
1. Else, let _sign_ be -1.
1. Let _value_ be min(floor(_first_ / 2), 2<sup>4</sup> - 1).
1. Let _nextShift_ be 16.
1. Let _currentByte_ be _first_.
1. Repeat, while floor(_currentByte_ / 2<sup>5</sup>) modulo 2 = 1,
1. If _position_.[[Value]] = _segmentLen_, throw an error.
1. Set _currentByte_ to ConsumeBase64ValueAt(_segment_, _position_).
1. Let _chunk_ be min(_currentByte_, 2<sup>5</sup> - 1).
1. Set _value_ to _value_ + _chunk_ × _nextShift_.
1. If _value_ ≥ 2<sup>31</sup>, throw an error.
1. Set _nextShift_ to _nextShift_ × 2<sup>5</sup>.
1. If _value_ is 0 and _sign_ is -1, return -2<sup>31</sup>.
1. Return _sign_ × _value_.
</emu-alg>
<emu-clause id="ConsumeBase64ValueAt" type="abstract operation">
<h1>
ConsumeBase64ValueAt (
_string_: a String,
_position_: a Record with a non-negative integer [[Value]] field,
): a non-negative integer
</h1>
<dl class="header"></dl>
<emu-alg>
1. Assert: _position_.[[Value]] is a non-negative integer smaller than the length of _string_.
1. Let _char_ be the substring of _string_ from _position_ to _position_ + 1.
1. Assert: _char_ is a valid <emu-xref href="#sec-references-informative">base64</emu-xref> character as defined by IETF RFC 4648.
1. Set _position_.[[Value]] to _position_.[[Value]] + 1.
1. Return the integer corresponding to _char_, according to the <emu-xref href="#sec-references-informative">base64</emu-xref> encoding as defined by IETF RFC 4648.
</emu-alg>
</emu-clause>
<emu-note>In addition to returning the decoded value, these algorithms update the _position_ passed in by the caller.</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-mappings-for-generated-javascript-code">
<h1>Mappings for generated JavaScript code</h1>
<p>Generated code positions that may have <emu-xref href="#decoded-mapping-record">mapping</emu-xref> entries are defined in terms of <em>input elements</em>, as per the <a href="https://tc39.es/ecma262/#sec-ecmascript-language-lexical-grammar">ECMAScript Lexical Grammar</a>. Mapping entries shall point to either:</p>
<ul>
<li>the first code point of the source text matched by |IdentifierName|, |PrivateIdentifier|, |Punctuator|, |DivPunctuator|, |RightBracePunctuator|, |NumericLiteral| and |RegularExpressionLiteral|.</li>
<li>any code point of the source text matched by |Comment|, |HashbangComment|, |StringLiteral|, |Template|, |TemplateSubstitutionTail|, |WhiteSpace| and |LineTerminator|.</li>
</ul>
</emu-clause>
<emu-clause id="sec-names-for-generated-javascript-code">
<h1>Names for generated JavaScript code</h1>
<p>Source map generators should create a <emu-xref href="#decoded-mapping-record">mapping</emu-xref> entry with a [[Name]] field for a JavaScript token, if:</p>
<ul>
<li>The original source language construct maps semantically to the generated JavaScript code.</li>
<li>The original source language construct has a name.</li>
</ul>
<p>Then the [[Name]] of the <emu-xref href="#decoded-mapping-record">mapping</emu-xref> entry should be the name of the original source language construct. A <emu-xref href="#decoded-mapping-record">mapping</emu-xref> with a non-null [[Name]] is called a <dfn variant="named mappings">named mapping</dfn>.</p>
<emu-note example>
A minifier renaming functions and variables or removing function names from immediately invoked function expressions.
</emu-note>
<p>The following enumeration lists productions of the <a href="https://tc39.es/ecma262/#sec-syntactic-grammar">ECMAScript Syntactic Grammar</a> and the respective token or non-terminal (on the right-hand side of the production) for which source map generators should emit a named mapping. The <emu-xref href="#decoded-mapping-record">mapping</emu-xref> entry created for such tokens shall follow section <emu-xref href="#sec-mappings-for-generated-javascript-code"></emu-xref>.</p>
<p>The enumeration should be understood as the "minimum". In general, source map generators are free to emit any additional named mappings.</p>
<emu-note>
The enumeration also lists tokens where generators "may" emit named mappings in addition to the tokens where they "should". These reflect the reality where existing tooling emits or expects named mappings. The duplicated named mapping is comparably cheap: Indices into names are encoded relative to each other so subsequent mappings to the same name are encoded as 0 (`A`).
</emu-note>
<ul>
<li>
<p>The |BindingIdentifier|(s) for |LexicalDeclaration|, |VariableStatement| and |ParameterList|.</p></li>
<li>
<p>The |BindingIdentifier| for |FunctionDeclaration|, |FunctionExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncGeneratorDeclaration|, and |AsyncGeneratorExpression| if it exists, or the opening parenthesis `(` preceding the |FormalParameters| otherwise.</p>
<p>Source map generators may chose to emit a named mapping on the opening parenthesis regardless of
the presence of the |BindingIdentifier|.</p>
</li>
<li>
<p>For an |ArrowFunction| or |AsyncArrowFunction|:</p>
<ul>
<li>
<p>The `=>` token where |ArrowFunction| is produced with a single |BindingIdentifier| for |ArrowParameters| or |AsyncArrowFunction| is produced with an |AsyncArrowBindingIdentifier|.</p>
<emu-note>This describes the case of (async) arrow functions with a single parameter, where that single parameter is not wrapped in parenthesis.</emu-note>
</li>
<li>
<p>The opening parenthesis `(` where |ArrowFunction| or |AsyncArrowFunction| is produced with |ArrowFormalParameters|.</p>
<p>Source map generators may chose to additionally emit a named mapping on the `=>` token for consistency with the previous case.</p>
</li>
</ul>
</li>
<li>
<p>The |ClassElementName| for |MethodDefinition|. This includes generators, async methods, async generators and accessors. For |MethodDefinition| where |ClassElementName| is *"constructor"*, the [[Name]] should be the original class name if applicable.</p>
<p>Source map generators may chose to additionally emit a named mapping on the opening parenthesis `(`.</p>
</li>
<li>
<p>Source map generators may emit named mapping for |IdentifierReference|| in |Expression|.</p>
</li>
</ul>
</emu-clause>
</emu-clause>
<emu-clause id="sec-sources">
<h1>Resolving sources</h1>
<p>If the sources are not absolute URLs after prepending the sourceRoot, the sources are resolved relative to the source map (like resolving the script `src` attribute in an HTML document).</p>
<emu-clause id="sec-DecodeSourceMapSources" type="abstract operation">
<h1>
DecodeSourceMapSources (
_baseURL_: an URL,
_sourceRoot_: a String or *null*,
_sources_: a List of either Strings or *null*,
_sourcesContent_: a List of either Strings or *null*,
_ignoreList_: a List of non-negative integers,
): a Decoded Source Record
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _decodedSources_ be a new empty List.
1. Let _sourcesContentCount_ be the the number of elements in _sourcesContent_.
1. Let _sourceUrlPrefix_ be *""*.
1. If _sourceRoot_ ≠ *null*, then
1. If _sourceRoot_ contains the code point U+002F (SOLIDUS), then
1. Let _idx_ be the index of the last occurrence of U+002F (SOLIDUS) in _sourceRoot_.
1. Set _sourceUrlPrefix_ to the substring of _sourceRoot_ from 0 to _idx_ + 1.
1. Else, set _sourceUrlPrefix_ to the string-concatenation of _sourceRoot_ and *"/"*.
1. For each _source_ in _sources_ with index _index_, do
1. Let _decodedSource_ be the Decoded Source Record { [[URL]]: *null*, [[Content]]: *null*, [[Ignored]]: *false* }.
1. If _source_ ≠ *null*, then
1. Set _source_ to the string-concatenation of _sourceUrlPrefix_ and _source_.
1. Let _sourceURL_ be the result of URL parsing _source_ with _baseURL_.
1. If _sourceURL_ is ~failure~, optionally report an error.
1. Else, set _decodedSource_.[[URL]] to _sourceURL_.
1. If _ignoredSources_ contains _index_, set _decodedSource_.[[Ignored]] to *true*.
1. If _sourcesContentCount_ ≥ _index_, set _decodedSource_.[[Content]] to _sourcesContent_[_index_].
1. Append _decodedSource_ to _decodedSources_.
1. Return _decodedSources_.
</emu-alg>
<emu-note>Implementations that support showing source contents but do not support showing multiple sources with the same URL and different content will arbitrarily choose one of the various contents corresponding to the given URL.</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-extensions">
<h1>Extensions</h1>
<p>Source map consumers shall ignore any additional unrecognized properties, rather than causing the source map to be rejected, so that additional features can be added to this format without breaking existing users.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-index-source-map">
<h1>Index source map</h1>
<p>To support concatenating generated code and other common post-processing, an alternate representation of a source map is supported:</p>
<pre><code class="json">
{
"version" : 3,
"file": "app.js",
"sections": [
{
"offset": {"line": 0, "column": 0},
"map": {
"version" : 3,
"file": "section.js",
"sources": ["foo.js", "bar.js"],
"names": ["src", "maps", "are", "fun"],
"mappings": "AAAA,E;;ABCDE"
}
},
{
"offset": {"line": 100, "column": 10},
"map": {
"version" : 3,
"file": "another_section.js",
"sources": ["more.js"],
"names": ["more", "is", "better"],
"mappings": "AAAA,E;AACA,C;ABCDE"
}
}
]
}
</code></pre>
<p>The index map follows the form of the standard map. Like the regular source map, the file format is JSON with a top-level object. It shares the version and file field from the regular source map, but gains a new sections field.</p>
<p>The <dfn id="json-sections"><code>sections</code> field</dfn> is an array of objects with the following fields:</p>
<ul>
<li><dfn id="json-sections-offset"><code>offset</code> field</dfn> is an object with two fields, `line` and `column`, that represent the offset into generated code that the referenced source map represents.</li>
<li><dfn id="json-sections-map"><code>map</code> field</dfn> is an embedded complete source map object. An embedded map does not inherit any values from the containing index map.</li>
</ul>
<p>The sections shall be sorted by starting position and the represented sections shall not overlap.</p>
<emu-clause id="sec-DecodeIndexSourceMap" type="abstract operation">
<h1>
DecodeIndexSourceMap (
_json_: an Object,
_baseURL_: an URL,
): a Decoded Source Map Record
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _sectionsField_ be JSONObjectGet(_json_, *"sections"*).
1. Assert: _sectionsField_ is not ~missing~.
1. If _sectionsField_ is not a JSON array, throw an error.
1. If JSONObjectGet(_json_, *"version"*) is not *3<sub>𝔽</sub>*, optionally report an error.
1. Let _fileField_ be GetOptionalString(_json_, *"file"*).
1. Let _sourceMap_ be the Decoded Source Map Record { [[File]]: _fileField_, [[Sources]]: « », [[Mappings]]: « » }.
1. Let _previousOffset_ be *null*.
1. Let _previousLastMapping_ be *null*.
1. For each _section_ of JSONArrayIterate(_sectionsField_), do
1. If _section_ is not a JSON object, optionally report an error.
1. Else,
1. Let _offset_ be JSONObjectGet(_section_, *"offset"*).
1. If _offset_ is not a JSON object, throw an error.
1. Let _offsetLine_ be JSONObjectGet(_offset_, *"line"*).
1. Let _offsetColumn_ be JSONObjectGet(_offset_, *"column"*).
1. If _offsetLine_ is not an integral Number, then
1. Optionally report an error.
1. Set _offsetLine_ to *0*<sub>𝔽</sub>.
1. If _offsetColumn_ is not an integral Number, then
1. Optionally report an error.
1. Set _offsetColumn_ to *0*<sub>𝔽</sub>.
1. If _previousOffset_ ≠ *null*, then
1. If _offsetLine_ < JSONObjectGet(_previousOffset_, *"line"*), optionally report an error.
1. Else if _offsetLine_ = JSONObjectGet(_previousOffset_, *"line"*) and _offsetColumn_ < Get(_previousOffset_, *"column"*), optionally report an error.
1. If _previousLastMapping_ is not *null*, then
1. If _offsetLine_ < _previousLastMapping_.[[GeneratedLine]], optionally report an error.