MCPcopy Create free account
hub / github.com/react/create-react-app / map

Function map

packages/react-error-overlay/src/utils/mapper.js:19–71  ·  view source on GitHub ↗

* Enhances a set of StackFrame s with their original positions and code (when available). * @param {StackFrame[]} frames A set of StackFrame s which contain (generated) code positions. * @param {number} [contextLines=3] The number of lines to provide before and after the li

(
  frames: StackFrame[],
  contextLines: number = 3
)

Source from the content-addressed store, hash-verified

17 * @param {number} [contextLines=3] The number of lines to provide before and after the line specified in the <code>StackFrame</code>.
18 */
19async function map(
20 frames: StackFrame[],
21 contextLines: number = 3
22): Promise<StackFrame[]> {
23 const cache: any = {};
24 const files: string[] = [];
25 frames.forEach(frame => {
26 const { fileName } = frame;
27 if (fileName == null) {
28 return;
29 }
30 if (files.indexOf(fileName) !== -1) {
31 return;
32 }
33 files.push(fileName);
34 });
35 await settle(
36 files.map(async fileName => {
37 const fetchUrl =
38 fileName.indexOf('webpack-internal:') === 0
39 ? `/__get-internal-source?fileName=${encodeURIComponent(fileName)}`
40 : fileName;
41
42 const fileSource = await fetch(fetchUrl).then(r => r.text());
43 const map = await getSourceMap(fileName, fileSource);
44 cache[fileName] = { fileSource, map };
45 })
46 );
47 return frames.map(frame => {
48 const { functionName, fileName, lineNumber, columnNumber } = frame;
49 let { map, fileSource } = cache[fileName] || {};
50 if (map == null || lineNumber == null) {
51 return frame;
52 }
53 const { source, line, column } = map.getOriginalPosition(
54 lineNumber,
55 columnNumber
56 );
57 const originalSource = source == null ? [] : map.getSource(source);
58 return new StackFrame(
59 functionName,
60 fileName,
61 lineNumber,
62 columnNumber,
63 getLinesAround(lineNumber, contextLines, fileSource),
64 functionName,
65 source,
66 line,
67 column,
68 getLinesAround(line, contextLines, originalSource)
69 );
70 });
71}
72
73export { map };
74export default map;

Callers 2

getStackFramesFunction · 0.90
mapper.jsFile · 0.90

Calls 5

getSourceMapFunction · 0.90
getLinesAroundFunction · 0.90
settleFunction · 0.85
getOriginalPositionMethod · 0.80
getSourceMethod · 0.45

Tested by

no test coverage detected