In a source map, what do the `sources`, `sourcesContent`, `names`, `mappings` and `ignoreList` fields hold, and how is `mappings` encoded?
answer
- parallel arrays indexed by number
- semicolons for lines, commas for segments
- one, four or five fields per segment
- Base64 VLQ, sign in the lowest bit
- deltas; only the generated column resets
basics
~10 ssources lists original files, sourcesContent their optional full text, names original identifiers, ignoreList the indices of third-party sources. mappings is a string of Base64 VLQ deltas: semicolons separate generated lines, commas separate segments.
solid answer
~50 s`sources` lists the original files (URLs, resolved against the map after any `sourceRoot` is prepended); `sourcesContent` optionally carries each one's full text in the same order, so tools need not fetch it; `names` lists original identifiers that segments can point at, which is how a minified `g` shows as `greet`; `ignoreList` holds indices into `sources` that developer tools should treat as third-party and skip. `mappings` is one string: `;` separates generated lines and `,` separates segments, and each segment holds 1, 4 or 5 Base64 VLQ numbers: generated column, source index, original line, original column and name index, all zero-based. Every number is a delta from the previous value of the same field, and only the generated column resets at each new line, so one corrupted segment shifts the original positions of every segment after it.
code
json · 9 lines{
"version": 3,
"file": "greet.min.js",
"sources": ["src/greet.js"],
"sourcesContent": ["export function greet(name) {\n return \"Hi \" + name;\n}\n"],
"names": ["greet", "name"],
"mappings": "AAAO,SAASA,EAAMC,GACpB,YAAeA",
"ignoreList": []
}go deeper
Know the fields by job: sources are the original files, names the original identifiers, mappings the positions linking them, and sourcesContent optional embedded text.
Explain the mappings layout precisely: semicolons for generated lines, commas for segments, one, four or five zero-based fields, Base64 VLQ, and deltas with only the generated column resetting per line.
Use the delta encoding to reason about damage: a single bad segment, or a tool that rewrites mappings carelessly, misplaces everything after it, which is why tools edit maps through libraries, not by hand.
Weigh what each optional field costs and gives: sourcesContent makes maps self-contained but discloses code, ignoreList shapes the debugging experience for every team, and index maps suit stitched output.
## The JSON object ECMA-426 defines a source map as one JSON object. Its fields are mostly **parallel lists addressed by index**, with `mappings` tying them together. | Field | Required | What it holds | |---|---|---| | `version` | yes | Always the number `3` | | `file` | no | A name for the generated file the map belongs to | | `sourceRoot` | no | A prefix prepended to every entry in `sources` | | `sources` | yes | Original files, each a (possibly relative) URL, or `null` when unknown | | `sourcesContent` | no | The original text of each source, in the same order; entries may be `null` | | `names` | no | Original identifiers that segments may refer to | | `mappings` | yes | The encoded position data | | `ignoreList` | no | Indices into `sources` that are third-party code | A few details matter in practice: - `sources` entries that are still relative after `sourceRoot` is prepended are resolved **relative to the map's own URL**. - `sourcesContent` is described as text "used when the source cannot be hosted". With it, a tool never has to fetch the original files; without it, the tool requests them by URL. - `ignoreList` lets developer tools skip framework or bundler-generated code when stepping, without the developer configuring anything. Some browsers still read the older, deprecated `x_google_ignoreList` when `ignoreList` is absent. ## How `mappings` is laid out `mappings` is a single string: - a **semicolon** (`;`) ends one **generated** line and starts the next, so the fifth group describes the fifth line of the output; - a **comma** (`,`) separates **segments** within a line; - each segment holds **1, 4 or 5** numbers. The fields of a segment, all zero-based, are: 1. the column in the generated line where the segment starts; 2. the index into `sources`; 3. the line in that original source; 4. the column in that original line; 5. the index into `names`, present only when an original identifier applies. A one-field segment marks generated code with no original, such as a helper the compiler injected. Columns are counted in UTF-16 code units for JavaScript and CSS. ## Base64 VLQ in brief Each number is a **Base64 variable-length quantity**. Every Base64 character carries six bits: the highest is a **continuation bit** (another character follows), and in the first character the lowest is the **sign bit**. Digits are stored least significant first. So `A` is 0, `C` is 1, `D` is -1, the single character `V` decodes to -10, and the two characters `iB` decode to 17. ## Deltas, and what one bad segment does The numbers are **relative**, which is what keeps maps small: - the generated column is a delta from the previous segment **on the same generated line**, and it starts again from zero after every `;`; - the source index, original line, original column and name index are deltas from the **previous occurrence of that field anywhere in the string**, and never reset. A decoder therefore has to walk the whole string from the start. It also means one wrong or missing segment does not stay local: every later segment's original position is computed from it, so everything after the damage points at the wrong place, until the end of the line for generated columns and to the end of the map for original positions. In the example map, segment `SAASA` decodes to `[9, 0, 0, 9, 0]`, which, added to the first segment `[0, 0, 0, 7]`, means generated column 9 maps to source 0, line 0, column 16, name 0 (`greet`). Segment `GACpB` decodes to `[3, 0, 1, -20]`: three columns further, one line down, twenty columns back. ## A map made of maps A second shape exists for output stitched together from pieces: an **index map** replaces `mappings` with a `sections` array, each entry an `offset` (line and column in the generated file) plus a complete embedded map. Sections must be sorted and must not overlap, and an embedded map inherits nothing from the outer one. ## Common misreadings - Treating `mappings` lines as **original** lines: the semicolons count generated lines. - Assuming every number is absolute, which makes hand-decoding produce nonsense after the first segment. - Thinking `names` is required for a mapping to work: it only supplies identifiers; four-field segments map positions without one.
- Why are the values in mappings stored as deltas rather than absolute positions?Size. Consecutive segments usually sit close together, so the difference is a small number, and Base64 VLQ spends one character on any value from -15 to 15. Absolute columns in a long minified line would need several characters each. The price is that decoding must run from the start of the string, and damage propagates.
- What does a segment with only one field mean?It marks a stretch of generated code that has no original position, such as a helper or wrapper the build injected. Tools treat that code as unmapped instead of attributing it to the previous segment's source position. Four-field segments map a position with no name; five-field segments add an index into `names`.
- What happens when a sources entry is null or sourcesContent has a null entry?A `null` source means the original file is unknown, so positions can be mapped to it but nothing can be shown. A `null` in `sourcesContent` just means that source's text is not embedded, and tools fetch it by its URL in `sources` instead.
The mappings string reads like turn-by-turn directions: every step says how far to go from where you last were, never an address. One wrong step misplaces every later stop, and only the generated-column count starts fresh at each new generated line, like house numbers restarting on every street.
- Each semicolon in mappings separates lines of the original source file.
- Every number in a segment is an absolute position, so segments decode independently.
- A mapping cannot work unless the names field is present.
- sourcesContent is required, or tools cannot show the original code.
- ignoreList removes those sources from the map so their code is not mapped.