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

Function fetchCodeframe

packages/vite/hmr/entry-runtime.ts:21–42  ·  view source on GitHub ↗
(u: string, line?: number)

Source from the content-addressed store, hash-verified

19}
20
21async function fetchCodeframe(u: string, line?: number) {
22 try {
23 const res = await fetch(u);
24 const text = await res.text();
25 const hash = res.headers && (res.headers as any).get ? (res.headers as any).get('X-NS-Source-Hash') || '' : '';
26 const lines = String(text || '').split('\n');
27 const L = line && line > 0 ? line : 1;
28 const start = Math.max(1, L - 4),
29 end = Math.min(lines.length, L + 3);
30 let context = '';
31 for (let i = start; i <= end; i++) {
32 const mark = i === L ? '>' : ' ';
33 const num = String(i).padStart(4, ' ');
34 context += `${mark}${num}: ${lines[i - 1]}\n`;
35 }
36 console.warn('[ns-entry][diag]', u === (globalThis as any).__NS_ENTRY_LAST_TARGET__ ? 'sanitized' : 'raw', hash ? `(hash ${hash})` : '', '\n' + context);
37 } catch (fe: any) {
38 try {
39 console.warn('[ns-entry][diag] fetch failed', u, fe && (fe.message || fe));
40 } catch {}
41 }
42}
43
44export default async function startEntry(opts: EntryOpts) {
45 const ORIGIN = String(opts.origin || '');

Callers 1

startEntryFunction · 0.85

Calls 5

fetchFunction · 0.85
warnMethod · 0.80
getMethod · 0.65
StringClass · 0.50
textMethod · 0.45

Tested by

no test coverage detected