(raw: string)
| 76 | } |
| 77 | |
| 78 | export function parseSingleFFOrSafariStack(raw: string): ParsedStack | null { |
| 79 | let line = raw.trim() |
| 80 | |
| 81 | if (SAFARI_NATIVE_CODE_REGEXP.test(line)) { |
| 82 | return null |
| 83 | } |
| 84 | |
| 85 | if (line.includes(' > eval')) { |
| 86 | line = line.replace( |
| 87 | / line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, |
| 88 | ':$1', |
| 89 | ) |
| 90 | } |
| 91 | |
| 92 | // Early return for lines that don't look like Firefox/Safari stack traces |
| 93 | // Firefox/Safari stack traces must contain '@' and should have location info after it |
| 94 | if (!line.includes('@')) { |
| 95 | return null |
| 96 | } |
| 97 | |
| 98 | // Find the correct @ that separates function name from location |
| 99 | // For cases like '@https://@fs/path' or 'functionName@https://@fs/path' |
| 100 | // we need to find the first @ that precedes a valid location (containing :) |
| 101 | let atIndex = -1 |
| 102 | let locationPart = '' |
| 103 | let functionName: string | undefined |
| 104 | |
| 105 | // Try each @ from left to right to find the one that gives us a valid location |
| 106 | for (let i = 0; i < line.length; i++) { |
| 107 | if (line[i] === '@') { |
| 108 | const candidateLocation = line.slice(i + 1) |
| 109 | // Minimum length 3 for valid location: 1 for filename + 1 for colon + 1 for line number (e.g., "a:1") |
| 110 | if (candidateLocation.includes(':') && candidateLocation.length >= 3) { |
| 111 | atIndex = i |
| 112 | locationPart = candidateLocation |
| 113 | functionName = i > 0 ? line.slice(0, i) : undefined |
| 114 | break |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // Validate we found a valid location with minimum length (filename:line format) |
| 120 | if (atIndex === -1 || !locationPart.includes(':') || locationPart.length < 3) { |
| 121 | return null |
| 122 | } |
| 123 | const [url, lineNumber, columnNumber] = extractLocation(locationPart) |
| 124 | |
| 125 | if (!url || !lineNumber || !columnNumber) { |
| 126 | return null |
| 127 | } |
| 128 | |
| 129 | return { |
| 130 | file: url, |
| 131 | method: functionName || '', |
| 132 | line: Number.parseInt(lineNumber), |
| 133 | column: Number.parseInt(columnNumber), |
| 134 | } |
| 135 | } |
no test coverage detected