Skip to content

Commit

Permalink
Fixup resource free
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Aug 5, 2020
1 parent e4128cd commit 34c13f1
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/react-dev-overlay/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,30 @@ async function findOriginalSourcePositionAndContent(
position: { line: number; column: number | null }
) {
const consumer = await new SourceMapConsumer(webpackSource.map())
const sourcePosition: NullableMappedPosition = consumer.originalPositionFor({
line: position.line,
column: position.column ?? 0,
})

if (!sourcePosition.source) {
return null
}
try {
const sourcePosition: NullableMappedPosition = consumer.originalPositionFor(
{
line: position.line,
column: position.column ?? 0,
}
)

const sourceContent: string | null =
consumer.sourceContentFor(
sourcePosition.source,
/* returnNullOnMissing */ true
) ?? null
if (!sourcePosition.source) {
return null
}

consumer.destroy()
const sourceContent: string | null =
consumer.sourceContentFor(
sourcePosition.source,
/* returnNullOnMissing */ true
) ?? null

return {
sourcePosition,
sourceContent,
return {
sourcePosition,
sourceContent,
}
} finally {
consumer.destroy()
}
}

Expand Down

0 comments on commit 34c13f1

Please sign in to comment.