t3-code-android-nightly/patches/@expo__metro-config@58.0.6.patch
Julius Marminge 8dc07f199c
chore(mobile): upgrade to Expo SDK 58 and React Native 0.88 RC (#12045)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-10-01 10:51:22 -07:00

72 lines
2.7 KiB
Diff

diff --git a/build/serializer/sourceMap.js b/build/serializer/sourceMap.js
index 2a58f57..a90ce77 100644
--- a/build/serializer/sourceMap.js
+++ b/build/serializer/sourceMap.js
@@ -177,6 +177,58 @@ function repairInvalidNegativeIndices(map) {
mappings: encode(decoded)
} : map;
}
+// Hermes can emit mappings for Metro trailer/debug lines that have no
+// corresponding Metro source-map line. @jridgewell/remapping assumes every
+// referenced generated line exists, so strip those invalid bridge segments.
+function getGeneratedLineCount(map) {
+ const { TraceMap, decodedMappings } = loadTraceMapping();
+ return decodedMappings(new TraceMap(map)).length;
+}
+function dropInvalidOriginalSegments(map, maxOriginalLine) {
+ const { TraceMap, decodedMappings } = loadTraceMapping();
+ const decoded = decodedMappings(new TraceMap(map));
+ let didChange = false;
+ const filtered = decoded.map((line) => {
+ const filteredLine = line.filter((segment) => {
+ if (segment.length < 4) {
+ return true;
+ }
+ const sourceIndex = segment[1];
+ const sourceLine = segment[2];
+ const sourceColumn = segment[3];
+ return (sourceIndex >= 0 &&
+ sourceIndex < map.sources.length &&
+ sourceLine >= 0 &&
+ sourceLine < maxOriginalLine &&
+ sourceColumn >= 0);
+ });
+ if (filteredLine.length !== line.length) {
+ didChange = true;
+ }
+ return filteredLine;
+ });
+ if (!didChange) {
+ return map;
+ }
+ return {
+ ...map,
+ mappings: loadSourcemapCodec().encode(filtered),
+ };
+}
+function sanitizeSourceMapsForComposition(maps) {
+ let sanitized = maps;
+ for (let index = 1; index < maps.length; index++) {
+ const maxOriginalLine = getGeneratedLineCount(sanitized[index - 1]);
+ const next = dropInvalidOriginalSegments(sanitized[index], maxOriginalLine);
+ if (next !== sanitized[index]) {
+ if (sanitized === maps) {
+ sanitized = maps.slice();
+ }
+ sanitized[index] = next;
+ }
+ }
+ return sanitized;
+}
function composeSourceMaps(maps) {
if (maps.length < 1) {
throw new Error('composeSourceMaps: Expected at least one map');
@@ -192,7 +244,7 @@ function composeSourceMaps(maps) {
};
});
// Metro convention is original-first; remapping is most-recent first.
- let input = normalized.slice().reverse();
+ let input = sanitizeSourceMapsForComposition(normalized).slice().reverse();
const remap = loadRemapping();
let composed;
try {