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) { ...@@ -132,12 +132,20 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
} }
let pos: NullableMappedPosition let pos: NullableMappedPosition
let posSourceContent: string | null = null
try { try {
const consumer = await new SourceMapConsumer(source.map()) const consumer = await new SourceMapConsumer(source.map())
pos = consumer.originalPositionFor({ pos = consumer.originalPositionFor({
line: frameLine, line: frameLine,
column: frameColumn, column: frameColumn,
}) })
if (pos.source) {
posSourceContent =
consumer.sourceContentFor(
pos.source,
/* returnNullOnMissing */ true
) ?? null
}
consumer.destroy() consumer.destroy()
} catch (err) { } catch (err) {
console.log('Failed to parse source map:', err) console.log('Failed to parse source map:', err)
...@@ -158,12 +166,9 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) { ...@@ -158,12 +166,9 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
? pos.source.substring(11) ? pos.source.substring(11)
: pos.source : pos.source
) )
const fileContent: string | null = await fs
.readFile(filePath, 'utf-8')
.catch(() => null)
const originalFrame: StackFrame = { const originalFrame: StackFrame = {
file: fileContent file: posSourceContent
? path.relative(options.rootDirectory, filePath) ? path.relative(options.rootDirectory, filePath)
: pos.source, : pos.source,
lineNumber: pos.line, lineNumber: pos.line,
...@@ -173,9 +178,9 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) { ...@@ -173,9 +178,9 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
} }
const originalCodeFrame: string | null = const originalCodeFrame: string | null =
fileContent && pos.line posSourceContent && pos.line
? (codeFrameColumns( ? (codeFrameColumns(
fileContent, posSourceContent,
{ start: { line: pos.line, column: pos.column } }, { start: { line: pos.line, column: pos.column } },
{ forceColor: true } { forceColor: true }
) as string) ) 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