Unverified Commit 4cd85a43 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Skip reading filesystem in favor of `sourcesContent` [ch1898] (#13677)

This skips reading from the file system because the `sourcesContent` can be used to access the source code.

I've completely removed the filesystem fallback, because it's probably not our code that'd be syntax highlighted anyway.
parent a92e9762
......@@ -132,12 +132,20 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
}
let pos: NullableMappedPosition
let posSourceContent: string | null = null
try {
const consumer = await new SourceMapConsumer(source.map())
pos = consumer.originalPositionFor({
line: frameLine,
column: frameColumn,
})
if (pos.source) {
posSourceContent =
consumer.sourceContentFor(
pos.source,
/* returnNullOnMissing */ true
) ?? null
}
consumer.destroy()
} catch (err) {
console.log('Failed to parse source map:', err)
......@@ -158,12 +166,9 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
? pos.source.substring(11)
: pos.source
)
const fileContent: string | null = await fs
.readFile(filePath, 'utf-8')
.catch(() => null)
const originalFrame: StackFrame = {
file: fileContent
file: posSourceContent
? path.relative(options.rootDirectory, filePath)
: pos.source,
lineNumber: pos.line,
......@@ -173,9 +178,9 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
}
const originalCodeFrame: string | null =
fileContent && pos.line
posSourceContent && pos.line
? (codeFrameColumns(
fileContent,
posSourceContent,
{ start: { line: pos.line, column: pos.column } },
{ forceColor: true }
) as string)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment