Skip to content

Commit 89c3a76

Browse files
committed
PR comments.
1 parent 5c1fffc commit 89c3a76

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

packages/telemetry/browser-telemetry/src/stack/StackParser.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import { StackFrame } from '../api/stack/StackFrame';
44
import { StackTrace } from '../api/stack/StackTrace';
55
import { ParsedStackOptions } from '../options';
66

7+
/**
8+
* In the browser we will not always be able to determine the source file that code originates
9+
* from. When you access a route it may just return HTML with embedded source, or just source,
10+
* in which case there may not be a file name.
11+
*
12+
* There will also be cases where there is no source file, such as when running with various
13+
* dev servers.
14+
*
15+
* In these situations we use this constant in place of the file name.
16+
*/
717
const INDEX_SPECIFIER = '(index)';
818

919
/**
@@ -18,12 +28,19 @@ export function processUrlToFileName(input: string, origin: string): string {
1828
let cleaned = input;
1929
if (input.startsWith(origin)) {
2030
cleaned = input.slice(origin.length);
31+
// If the input is a single `/` then it would get removed and we would
32+
// be left with an empty string. That empty string would get replaced with
33+
// the INDEX_SPECIFIER. In cases where a `/` remains, either singular
34+
// or at the end of a path, then we will append the index specifier.
35+
// For instance the route `/test/` would ultimately be `test/(index)`.
2136
if (cleaned.startsWith('/')) {
2237
cleaned = cleaned.slice(1);
2338
}
39+
2440
if (cleaned === '') {
25-
cleaned = INDEX_SPECIFIER;
41+
return INDEX_SPECIFIER;
2642
}
43+
2744
if (cleaned.endsWith('/')) {
2845
cleaned += INDEX_SPECIFIER;
2946
}
@@ -62,7 +79,27 @@ export function trimSourceLine(options: TrimOptions, line: string, column: numbe
6279
}
6380

6481
/**
82+
* Given a context get trimmed source lines within the specified range.
83+
*
84+
* The context is a list of source code lines, this function returns a subset of
85+
* lines which have been trimmed.
86+
*
87+
* If an error is on a specific line of source code we want to be able to get
88+
* lines before and after that line. This is done relative to the originating
89+
* line of source.
90+
*
91+
* If you wanted to get 3 lines before the origin line, then this function would
92+
* need to be called with `start: originLine - 3, end: originLine`.
93+
*
94+
* If the `start` would underflow the context, then the start is set to 0.
95+
* If the `end` would overflow the context, then the end is set to the context
96+
* length.
97+
*
6598
* Exported for testing.
99+
*
100+
* @param start The inclusive start index.
101+
* @param end The exclusive end index.
102+
* @param trimmer Method which will trim individual lines.
66103
*/
67104
export function getLines(
68105
start: number,
@@ -79,6 +116,13 @@ export function getLines(
79116
}
80117

81118
/**
119+
* Given a stack frame produce source context about that stack frame.
120+
*
121+
* The source context includes the source line of the stack frame, some number
122+
* of lines before the line of the stack frame, and some number of lines
123+
* after the stack frame. The amount of context can be controlled by the
124+
* provided options.
125+
*
82126
* Exported for testing.
83127
*/
84128
export function getSrcLines(

0 commit comments

Comments
 (0)