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

Function findInlineOrLinkedMapFromJs

packages/core/inspector_modules.ts:43–75  ·  view source on GitHub ↗
(jsPath: string)

Source from the content-addressed store, hash-verified

41}
42
43function findInlineOrLinkedMapFromJs(jsPath: string): { key: string; text: string } | null {
44 const jsText = safeReadText(jsPath);
45 if (!jsText) return null;
46
47 // Look for the last sourceMappingURL directive
48 // Supports both //# and /*# */ styles; capture up to line end or */
49 const re = /[#@]\s*sourceMappingURL=([^\s*]+)(?:\s*\*\/)?/g;
50 let match: RegExpExecArray | null = null;
51 let last: RegExpExecArray | null = null;
52 while ((match = re.exec(jsText))) last = match;
53 if (!last) return null;
54
55 const url = last[1];
56 if (url.startsWith('data:application/json')) {
57 const base64 = url.split(',')[1];
58 if (!base64) return null;
59 try {
60 const text = atob(base64);
61 return { key: `inline:${jsPath}`, text };
62 } catch (_) {
63 return null;
64 }
65 }
66
67 // Linked .map file (relative)
68 const jsDir = jsPath.substring(0, jsPath.lastIndexOf('/'));
69 const mapPath = `${jsDir}/${url}`;
70 const text = safeReadText(mapPath);
71 if (text) {
72 return { key: mapPath, text };
73 }
74 return null;
75}
76
77function loadAndExtractMap(mapPath: string, fallbackJsPath?: string) {
78 // check cache first

Callers 1

loadAndExtractMapFunction · 0.85

Calls 3

safeReadTextFunction · 0.85
atobFunction · 0.85
lastIndexOfMethod · 0.80

Tested by

no test coverage detected