1diff --git a/build/serializer/sourceMap.js b/build/serializer/sourceMap.js
2index 2a58f57..a90ce77 100644
3--- a/build/serializer/sourceMap.js
4+++ b/build/serializer/sourceMap.js
5@@ -177,6 +177,58 @@ function repairInvalidNegativeIndices(map) {
6 mappings: encode(decoded)
7 } : map;
8 }
9+// Hermes can emit mappings for Metro trailer/debug lines that have no
10+// corresponding Metro source-map line. @jridgewell/remapping assumes every
11+// referenced generated line exists, so strip those invalid bridge segments.
12+function getGeneratedLineCount(map) {
13+ const { TraceMap, decodedMappings } = loadTraceMapping();
14+ return decodedMappings(new TraceMap(map)).length;
15+}
16+function dropInvalidOriginalSegments(map, maxOriginalLine) {
17+ const { TraceMap, decodedMappings } = loadTraceMapping();
18+ const decoded = decodedMappings(new TraceMap(map));
19+ let didChange = false;
20+ const filtered = decoded.map((line) => {
21+ const filteredLine = line.filter((segment) => {
22+ if (segment.length < 4) {
23+ return true;
24+ }
25+ const sourceIndex = segment[1];
26+ const sourceLine = segment[2];
27+ const sourceColumn = segment[3];
28+ return (sourceIndex >= 0 &&
29+ sourceIndex < map.sources.length &&
30+ sourceLine >= 0 &&
31+ sourceLine < maxOriginalLine &&
32+ sourceColumn >= 0);
33+ });
34+ if (filteredLine.length !== line.length) {
35+ didChange = true;
36+ }
37+ return filteredLine;
38+ });
39+ if (!didChange) {
40+ return map;
41+ }
42+ return {
43+ ...map,
44+ mappings: loadSourcemapCodec().encode(filtered),
45+ };
46+}
47+function sanitizeSourceMapsForComposition(maps) {
48+ let sanitized = maps;
49+ for (let index = 1; index < maps.length; index++) {
50+ const maxOriginalLine = getGeneratedLineCount(sanitized[index - 1]);
51+ const next = dropInvalidOriginalSegments(sanitized[index], maxOriginalLine);
52+ if (next !== sanitized[index]) {
53+ if (sanitized === maps) {
54+ sanitized = maps.slice();
55+ }
56+ sanitized[index] = next;
57+ }
58+ }
59+ return sanitized;
60+}
61 function composeSourceMaps(maps) {
62 if (maps.length < 1) {
63 throw new Error('composeSourceMaps: Expected at least one map');
64@@ -192,7 +244,7 @@ function composeSourceMaps(maps) {
65 };
66 });
67 // Metro convention is original-first; remapping is most-recent first.
68- let input = normalized.slice().reverse();
69+ let input = sanitizeSourceMapsForComposition(normalized).slice().reverse();
70 const remap = loadRemapping();
71 let composed;
72 try {