MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / loadAndExtractMap

Function loadAndExtractMap

packages/core/inspector_modules.ts:77–136  ·  view source on GitHub ↗
(mapPath: string, fallbackJsPath?: string)

Source from the content-addressed store, hash-verified

75}
76
77function loadAndExtractMap(mapPath: string, fallbackJsPath?: string) {
78 // check cache first
79 if (!loadedSourceMaps) {
80 loadedSourceMaps = new Map();
81 }
82 let mapText = loadedSourceMaps.get(mapPath);
83 if (mapText) {
84 return mapText; // already loaded
85 } else {
86 if (File.exists(mapPath)) {
87 try {
88 const contents = File.fromPath(mapPath).readTextSync();
89
90 // Note: we may want to do this, keeping for reference if needed in future.
91 // Check size before processing (skip very large source maps)
92 // const maxSizeBytes = 10 * 1024 * 1024; // 10MB limit
93 // if (contents.length > maxSizeBytes) {
94 // console.warn(`Source map ${mapPath} is too large (${contents.length} bytes), skipping...`);
95 // return null;
96 // }
97
98 if (usingSourceMapFiles) {
99 mapText = contents;
100 } else {
101 // parse out the inline base64
102 const match = contents.match(/\/\/[#@] sourceMappingURL=data:application\/json[^,]+,(.+)$/);
103 if (!match) {
104 console.warn(`Invalid source map format in ${mapPath}`);
105 return null;
106 }
107 const base64 = match[1];
108 const binary = atob(base64);
109 // this is the raw text of the source map
110 // seems to work without doing decodeURIComponent tricks
111 mapText = binary;
112 }
113 } catch (error) {
114 console.debug && console.debug(`Failed to load source map ${mapPath}:`, error);
115 return null;
116 }
117 } else {
118 // Try fallback: read inline or linked map from the JS file itself
119 if (fallbackJsPath) {
120 const alt = findInlineOrLinkedMapFromJs(fallbackJsPath);
121 if (alt && alt.text) {
122 mapText = alt.text;
123 // Cache under both the requested key and the alt key so future lookups are fast
124 loadedSourceMaps.set(alt.key, alt.text);
125 } else {
126 return null;
127 }
128 } else {
129 // no source maps
130 return null;
131 }
132 }
133 }
134 loadedSourceMaps.set(mapPath, mapText); // cache it

Callers 1

remapFrameFunction · 0.85

Calls 9

atobFunction · 0.85
warnMethod · 0.80
getMethod · 0.65
readTextSyncMethod · 0.65
existsMethod · 0.45
fromPathMethod · 0.45
matchMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected