Skip to content

Commit

Permalink
chore: fix getOriginalPosition() to work in Storybook (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored Jan 11, 2024
1 parent 1594e42 commit 8b9a354
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: fix getOriginalPosition() to work in Storybook",
"packageName": "@griffel/devtools",
"email": "[email protected]",
"dependentChangeType": "patch"
}
22 changes: 14 additions & 8 deletions packages/devtools/src/sourceMap/sourceMapConsumer.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import type { MappedPosition, RawSourceMap } from 'source-map-js';
import { SourceMapConsumer } from 'source-map-js';
import type { MappedPosition, RawSourceMap } from 'source-map-js';

export const resources: Promise<chrome.devtools.inspectedWindow.Resource[]> = new Promise(resolve => {
chrome.devtools.inspectedWindow.getResources(currResources => {
resolve(currResources);
});
});
chrome.devtools.inspectedWindow.onResourceAdded.addListener(async resource => {
if (!resource.url.startsWith('debugger')) {
(await resources).push(resource);
if (chrome.devtools) {
chrome.devtools.inspectedWindow.getResources(currResources => {
resolve(currResources);
});
}
});

if (chrome.devtools) {
chrome.devtools.inspectedWindow.onResourceAdded.addListener(async resource => {
if (!resource.url.startsWith('debugger')) {
(await resources).push(resource);
}
});
}

export async function getOriginalPosition(sourceMapJSON: RawSourceMap, sourceLoc: MappedPosition) {
const { source, line, column } = sourceLoc;

try {
const sourceMapConsumer = new SourceMapConsumer(sourceMapJSON);
const result = sourceMapConsumer.originalPositionFor({ line, column });
Expand Down

0 comments on commit 8b9a354

Please sign in to comment.