* @returns 1-based lines and 1-based columns
( frame: TurbopackStackFrame )
| 178 | * @returns 1-based lines and 1-based columns |
| 179 | */ |
| 180 | async function nativeTraceSource( |
| 181 | frame: TurbopackStackFrame |
| 182 | ): Promise<{ frame: IgnorableStackFrame; source: string | null } | undefined> { |
| 183 | const sourceURL = frame.file |
| 184 | let sourceMapPayload: ModernSourceMapPayload | undefined |
| 185 | try { |
| 186 | sourceMapPayload = findSourceMap(sourceURL)?.payload |
| 187 | } catch (cause) { |
| 188 | throw new Error( |
| 189 | `${sourceURL}: Invalid source map. Only conformant source maps can be used to find the original code.`, |
| 190 | { cause } |
| 191 | ) |
| 192 | } |
| 193 | |
| 194 | if (sourceMapPayload !== undefined) { |
| 195 | let consumer: SourceMapConsumer |
| 196 | try { |
| 197 | consumer = await new SourceMapConsumer(sourceMapPayload) |
| 198 | } catch (cause) { |
| 199 | throw new Error( |
| 200 | `${sourceURL}: Invalid source map. Only conformant source maps can be used to find the original code.`, |
| 201 | { cause } |
| 202 | ) |
| 203 | } |
| 204 | let traced: { |
| 205 | originalPosition: NullableMappedPosition |
| 206 | sourceContent: string | null |
| 207 | } | null |
| 208 | try { |
| 209 | const originalPosition = consumer.originalPositionFor({ |
| 210 | line: frame.line ?? 1, |
| 211 | // 0-based columns out requires 0-based columns in. |
| 212 | column: (frame.column ?? 1) - 1, |
| 213 | }) |
| 214 | |
| 215 | if (originalPosition.source === null) { |
| 216 | traced = null |
| 217 | } else { |
| 218 | const sourceContent: string | null = |
| 219 | consumer.sourceContentFor( |
| 220 | originalPosition.source, |
| 221 | /* returnNullOnMissing */ true |
| 222 | ) ?? null |
| 223 | |
| 224 | traced = { originalPosition, sourceContent } |
| 225 | } |
| 226 | } finally { |
| 227 | consumer.destroy() |
| 228 | } |
| 229 | |
| 230 | if (traced !== null) { |
| 231 | const { originalPosition, sourceContent } = traced |
| 232 | const applicableSourceMap = findApplicableSourceMapPayload( |
| 233 | (frame.line ?? 1) - 1, |
| 234 | (frame.column ?? 1) - 1, |
| 235 | sourceMapPayload |
| 236 | ) |
| 237 |
no test coverage detected