bippy 0.7.3-dev.ebf9a42 → 0.7.3-dev.fbafc40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { JSX_FACTORY_FRAME_COUNT, REACT_STACK_BOTTOM_FRAME_PATTERNS } from "./constants.js";
2
- import { getPrepareStackTrace, setPrepareStackTrace } from "./error-stack.js";
3
- import { parseStack, type StackFrame } from "./parse-stack.js";
1
+ import { JSX_FACTORY_FRAME_COUNT, REACT_STACK_BOTTOM_FRAME_PATTERNS } from "./constants";
2
+ import { getPrepareStackTrace, setPrepareStackTrace } from "./error-stack";
3
+ import { parseStack, type StackFrame } from "./parse-stack";
4
4
 
5
5
  interface V8CallSite {
6
6
  getFunctionName?: () => string | null;
@@ -1,11 +1,11 @@
1
- import type { HooksNode, HooksTree, HookSource } from "./inspect-hooks.js";
1
+ import type { HooksNode, HooksTree, HookSource } from "./inspect-hooks";
2
2
  import {
3
3
  getSourceContentFromSourceMap,
4
4
  getSourceFromSourceMap,
5
5
  getSourceMap,
6
6
  type SourceFetch,
7
7
  type SourceMapRequestOptions,
8
- } from "./symbolication.js";
8
+ } from "./symbolication";
9
9
 
10
10
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
11
11
  export interface HookNames extends Map<string, string> {}
@@ -1,6 +1,6 @@
1
- import type { RendererDispatcherRef } from "../react-internals/index.js";
2
- import { _renderers, getRDTHook, isRendererMap } from "../rdt-hook.js";
3
- import type { ReactDevToolsTarget } from "../rdt-hook.js";
1
+ import type { RendererDispatcherRef } from "../react-internals/index";
2
+ import { _renderers, getRDTHook, isRendererMap } from "../rdt-hook";
3
+ import type { ReactDevToolsTarget } from "../rdt-hook";
4
4
 
5
5
  export const getRendererDispatcherRefs = (
6
6
  target: ReactDevToolsTarget = globalThis,
@@ -1,8 +1,9 @@
1
1
  import { decode, type SourceMapMappings, type SourceMapSegment } from "@jridgewell/sourcemap-codec";
2
2
 
3
- import { BippySourceMapError } from "../errors.js";
4
- import { SCHEME_REGEX } from "./constants.js";
5
- import type { StackFrame } from "./parse-stack.js";
3
+ import { BippySourceMapError } from "../errors";
4
+ import { SCHEME_REGEX } from "./constants";
5
+ import { normalizeFileName } from "./normalize-file-name";
6
+ import type { StackFrame } from "./parse-stack";
6
7
 
7
8
  export interface DecodedSourceMapSection {
8
9
  map: {
@@ -272,37 +273,40 @@ export const getSourceFromSourceMapByFunctionName = (
272
273
  );
273
274
  };
274
275
 
275
- const findSourceContentByFileName = (
276
- sources: string[],
277
- sourcesContent: Array<string | null> | undefined,
278
- fileName: string,
279
- ): string | null => {
280
- if (!sourcesContent) return null;
281
- const sourceIndex = getStringIndex(sources, fileName);
282
- return sourceIndex === -1 ? null : (sourcesContent[sourceIndex] ?? null);
276
+ const canonicalSourcePath = (fileName: string): string => {
277
+ const normalizedFileName = normalizeFileName(fileName);
278
+ return normalizedFileName.startsWith("./") ? normalizedFileName.slice(2) : normalizedFileName;
283
279
  };
284
280
 
285
281
  export const getSourceContentFromSourceMap = (
286
282
  sourceMap: SourceMap,
287
283
  originalFileName: string,
288
284
  ): string | null => {
289
- const sourceContent = findSourceContentByFileName(
290
- sourceMap.sources,
291
- sourceMap.sourcesContent,
292
- originalFileName,
293
- );
294
- if (sourceContent !== null) return sourceContent;
295
-
296
- if (!sourceMap.sections) return null;
297
- for (const section of sourceMap.sections) {
298
- const sectionSourceContent = findSourceContentByFileName(
299
- section.map.sources,
300
- section.map.sourcesContent,
301
- originalFileName,
302
- );
303
- if (sectionSourceContent !== null) return sectionSourceContent;
285
+ const maps = [sourceMap, ...(sourceMap.sections?.map((section) => section.map) ?? [])];
286
+ let hasExactSource = false;
287
+ for (const map of maps) {
288
+ const sourceIndex = getStringIndex(map.sources, originalFileName);
289
+ if (sourceIndex === -1) continue;
290
+ hasExactSource = true;
291
+ const sourceContent = map.sourcesContent?.[sourceIndex];
292
+ if (typeof sourceContent === "string") return sourceContent;
304
293
  }
305
- return null;
294
+ if (hasExactSource) return null;
295
+
296
+ const canonicalFileName = canonicalSourcePath(originalFileName);
297
+ if (!canonicalFileName) return null;
298
+ let matchedFileName: string | undefined;
299
+ let matchedContent: string | null = null;
300
+ for (const map of maps) {
301
+ for (let index = 0; index < map.sources.length; index++) {
302
+ const fileName = map.sources[index];
303
+ if (!fileName || canonicalSourcePath(fileName) !== canonicalFileName) continue;
304
+ if (matchedFileName !== undefined && matchedFileName !== fileName) return null;
305
+ matchedFileName = fileName;
306
+ matchedContent ??= map.sourcesContent?.[index] ?? null;
307
+ }
308
+ }
309
+ return matchedContent;
306
310
  };
307
311
 
308
312
  const resolveUrl = (reference: string, baseUrl: string): string | null => {
@@ -445,12 +449,46 @@ const getIgnoredSourceIndices = (rawSourceMap: StandardSourceMap): Set<number> |
445
449
  return ignoreList?.length ? new Set(ignoreList) : undefined;
446
450
  };
447
451
 
452
+ const isAbsoluteSourcePath = (source: string): boolean =>
453
+ source.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(source) || SCHEME_REGEX.test(source);
454
+
455
+ const resolveRelativeSource = (source: string, sourceMapUrl: string): string => {
456
+ if (!source.startsWith("./") && !source.startsWith("../")) return source;
457
+ if (INLINE_SOURCEMAP_REGEX.test(sourceMapUrl)) return source;
458
+ return resolveUrl(source, sourceMapUrl) ?? source;
459
+ };
460
+
461
+ const normalizeJoinedSourcePath = (joinedSource: string): string => {
462
+ const pathSegments = joinedSource.split("/");
463
+ const normalizedPathSegments: string[] = [];
464
+ for (const pathSegment of pathSegments) {
465
+ if (pathSegment === "" || pathSegment === ".") {
466
+ if (pathSegment === "" && normalizedPathSegments.length === 0) {
467
+ normalizedPathSegments.push("");
468
+ }
469
+ continue;
470
+ }
471
+ if (pathSegment === "..") {
472
+ const previousSegment = normalizedPathSegments[normalizedPathSegments.length - 1];
473
+ if (previousSegment && previousSegment !== ".." && previousSegment !== "") {
474
+ normalizedPathSegments.pop();
475
+ } else {
476
+ normalizedPathSegments.push("..");
477
+ }
478
+ continue;
479
+ }
480
+ normalizedPathSegments.push(pathSegment);
481
+ }
482
+ return normalizedPathSegments.join("/");
483
+ };
484
+
448
485
  const resolveSourceRoot = (
449
486
  sourceRoot: string | undefined,
450
487
  source: string,
451
488
  sourceMapUrl: string,
452
489
  ): string => {
453
- if (!sourceRoot || SCHEME_REGEX.test(source) || source.startsWith("/")) return source;
490
+ if (isAbsoluteSourcePath(source)) return source;
491
+ if (!sourceRoot) return resolveRelativeSource(source, sourceMapUrl);
454
492
  const normalizedSourceRoot = sourceRoot.endsWith("/") ? sourceRoot : `${sourceRoot}/`;
455
493
  const normalizedSource = source.replace(/^\.\//, "");
456
494
  try {
@@ -459,16 +497,7 @@ const resolveSourceRoot = (
459
497
  : new URL(normalizedSourceRoot, sourceMapUrl).toString();
460
498
  return new URL(normalizedSource, baseUrl).toString();
461
499
  } catch {
462
- const pathSegments = `${normalizedSourceRoot}${normalizedSource}`.split("/");
463
- const normalizedPathSegments: string[] = [];
464
- for (const pathSegment of pathSegments) {
465
- if (pathSegment === "..") {
466
- normalizedPathSegments.pop();
467
- } else if (pathSegment !== ".") {
468
- normalizedPathSegments.push(pathSegment);
469
- }
470
- }
471
- return normalizedPathSegments.join("/");
500
+ return normalizeJoinedSourcePath(`${normalizedSourceRoot}${normalizedSource}`);
472
501
  }
473
502
  };
474
503