bippy 0.6.1-dev.61475ed → 0.6.1-dev.a3b3942

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.
Files changed (66) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +32 -48
  3. package/dist/core.cjs +1 -1
  4. package/dist/core.d.cts +45 -60
  5. package/dist/core.d.ts +45 -60
  6. package/dist/core.js +1 -1
  7. package/dist/core2.cjs +9 -0
  8. package/dist/core2.d.cts +11 -3
  9. package/dist/core2.d.ts +11 -3
  10. package/dist/core2.js +9 -0
  11. package/dist/errors.d.cts +420 -0
  12. package/dist/errors.d.ts +420 -0
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +11 -3
  15. package/dist/index.d.ts +11 -3
  16. package/dist/index.iife.js +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/install-hook-only.cjs +1 -1
  19. package/dist/install-hook-only.d.cts +9 -1
  20. package/dist/install-hook-only.d.ts +9 -1
  21. package/dist/install-hook-only.iife.js +1 -1
  22. package/dist/install-hook-only.js +1 -1
  23. package/dist/rdt-hook.cjs +1 -1
  24. package/dist/rdt-hook.js +1 -1
  25. package/dist/source.cjs +14 -5
  26. package/dist/source.d.cts +27 -11
  27. package/dist/source.d.ts +27 -11
  28. package/dist/source.js +14 -5
  29. package/package.json +22 -16
  30. package/src/core.ts +349 -328
  31. package/src/errors.ts +34 -0
  32. package/src/install-hook-only.ts +2 -2
  33. package/src/rdt-hook.ts +160 -161
  34. package/src/react-internals/generated/react-work-tags.ts +318 -0
  35. package/src/react-internals/index.ts +67 -0
  36. package/src/react-internals/semver.ts +80 -0
  37. package/src/react-internals/types.ts +197 -0
  38. package/src/source/constants.ts +1 -1
  39. package/src/source/error-stack.ts +11 -0
  40. package/src/source/get-display-name-from-source.ts +32 -25
  41. package/src/source/get-source.ts +5 -5
  42. package/src/source/index.ts +9 -1
  43. package/src/source/inspect-hooks.ts +215 -182
  44. package/src/source/owner-stack.ts +127 -166
  45. package/src/source/parse-debug-stack.ts +4 -4
  46. package/src/source/parse-hook-names.ts +1 -1
  47. package/src/source/parse-stack.ts +1 -3
  48. package/src/source/symbolication.ts +490 -90
  49. package/dist/get-source.cjs +0 -19
  50. package/dist/get-source.js +0 -19
  51. package/dist/react-refresh.cjs +0 -9
  52. package/dist/react-refresh.d.cts +0 -66
  53. package/dist/react-refresh.d.ts +0 -66
  54. package/dist/react-refresh.js +0 -9
  55. package/dist/unsubscribe.d.cts +0 -298
  56. package/dist/unsubscribe.d.ts +0 -298
  57. package/src/react-refresh/constants.ts +0 -9
  58. package/src/react-refresh/detect-hmr-transport.ts +0 -33
  59. package/src/react-refresh/index.ts +0 -173
  60. package/src/react-refresh/metro-hmr-transport.ts +0 -188
  61. package/src/react-refresh/next-webpack-hmr-transport.ts +0 -72
  62. package/src/react-refresh/normalize-hmr-file-path.ts +0 -24
  63. package/src/react-refresh/types.ts +0 -7
  64. package/src/react-refresh/vite-hmr-transport.ts +0 -116
  65. package/src/types.ts +0 -438
  66. package/src/unsubscribe.ts +0 -17
@@ -1,9 +1,28 @@
1
- import { Fiber } from "../types.js";
1
+ import { Fiber } from "../react-internals/index.js";
2
2
  import { getDisplayName } from "../core.js";
3
- import { getParentStack } from "./owner-stack.js";
3
+ import { getRawParentStack } from "./owner-stack.js";
4
4
  import { getSourceFromSourceMap, getSourceMap } from "./symbolication.js";
5
5
  import { StackFrame } from "./parse-stack.js";
6
6
 
7
+ const COMPONENT_DECLARATION_PATTERNS = [
8
+ /(?:^|export\s+)(?:const|let|var)\s+(\w+)\s*=/,
9
+ /(?:^|export\s+)function\s+(\w+)/,
10
+ /(?:^|export\s+)class\s+(\w+)/,
11
+ ];
12
+
13
+ const findComponentDeclarationOnLine = (line: string): string | null => {
14
+ for (const pattern of COMPONENT_DECLARATION_PATTERNS) {
15
+ const match = line.match(pattern);
16
+ if (match?.[1]) return match[1];
17
+ }
18
+ return null;
19
+ };
20
+
21
+ const MAX_DECLARATION_LINE_DISTANCE = 5;
22
+
23
+ // the frame points inside the component, so the nearest declaration wins;
24
+ // searching by pattern over the whole window instead would let an adjacent
25
+ // component's declaration shadow the right one
7
26
  const extractComponentNameFromSource = (
8
27
  sourceContent: string,
9
28
  lineNumber: number,
@@ -15,27 +34,16 @@ const extractComponentNameFromSource = (
15
34
  return null;
16
35
  }
17
36
 
18
- const startLine = Math.max(0, targetLineIndex - 5);
19
- const endLine = Math.min(lines.length, targetLineIndex + 5);
20
- const contextLines = lines.slice(startLine, endLine).join("\n");
21
-
22
- const arrowFunctionPattern = /(?:^|export\s+)(?:const|let|var)\s+(\w+)\s*=/m;
23
- const functionPattern = /(?:^|export\s+)function\s+(\w+)/m;
24
- const classPattern = /(?:^|export\s+)class\s+(\w+)/m;
25
-
26
- const arrowMatch = contextLines.match(arrowFunctionPattern);
27
- if (arrowMatch?.[1]) {
28
- return arrowMatch[1];
29
- }
30
-
31
- const functionMatch = contextLines.match(functionPattern);
32
- if (functionMatch?.[1]) {
33
- return functionMatch[1];
34
- }
35
-
36
- const classMatch = contextLines.match(classPattern);
37
- if (classMatch?.[1]) {
38
- return classMatch[1];
37
+ for (let lineDistance = 0; lineDistance <= MAX_DECLARATION_LINE_DISTANCE; lineDistance++) {
38
+ const lineIndexes =
39
+ lineDistance === 0
40
+ ? [targetLineIndex]
41
+ : [targetLineIndex - lineDistance, targetLineIndex + lineDistance];
42
+ for (const lineIndex of lineIndexes) {
43
+ if (lineIndex < 0 || lineIndex >= lines.length) continue;
44
+ const declarationName = findComponentDeclarationOnLine(lines[lineIndex]);
45
+ if (declarationName) return declarationName;
46
+ }
39
47
  }
40
48
 
41
49
  return null;
@@ -46,8 +54,7 @@ export const getDisplayNameFromSource = async (
46
54
  cache = true,
47
55
  fetchFn?: (url: string) => Promise<Response>,
48
56
  ): Promise<string | null> => {
49
- const parentStackFrames = await getParentStack(fiber, cache, fetchFn);
50
- const stackFrame = parentStackFrames.filter((innerFrame) => innerFrame.fileName)[0];
57
+ const stackFrame = getRawParentStack(fiber).find((innerFrame) => innerFrame.fileName);
51
58
 
52
59
  if (!stackFrame?.fileName) {
53
60
  return getDisplayName(fiber.type);
@@ -1,6 +1,6 @@
1
- import { Fiber } from "../types.js";
1
+ import type { Fiber } from "../react-internals/index.js";
2
2
 
3
- import { FiberSource } from "./types.js";
3
+ import type { FiberSource } from "./types.js";
4
4
  import {
5
5
  SCHEME_REGEX,
6
6
  INTERNAL_SCHEME_PREFIXES,
@@ -95,8 +95,7 @@ export const getSource = async (
95
95
  fetchFn?: (url: string) => Promise<Response>,
96
96
  ): Promise<FiberSource | null> => {
97
97
  if (hasDebugSource(fiber)) {
98
- const debugSource = fiber._debugSource;
99
- return debugSource || null;
98
+ return fiber._debugSource;
100
99
  }
101
100
 
102
101
  const debugStackFrame =
@@ -171,6 +170,7 @@ export const normalizeFileName = (fileName: string): string => {
171
170
  }
172
171
 
173
172
  let normalizedFileName = fileName;
173
+ const isWindowsDrivePath = /^[a-zA-Z]:[\\/]/.test(normalizedFileName);
174
174
 
175
175
  const isHttpUrl =
176
176
  normalizedFileName.startsWith("http://") || normalizedFileName.startsWith("https://");
@@ -214,7 +214,7 @@ export const normalizeFileName = (fileName: string): string => {
214
214
  }
215
215
  }
216
216
 
217
- if (SCHEME_REGEX.test(normalizedFileName)) {
217
+ if (!isWindowsDrivePath && SCHEME_REGEX.test(normalizedFileName)) {
218
218
  const schemeMatch = normalizedFileName.match(SCHEME_REGEX);
219
219
  if (schemeMatch) {
220
220
  normalizedFileName = normalizedFileName.slice(schemeMatch[0].length);
@@ -6,12 +6,20 @@ export {
6
6
  symbolicateStack,
7
7
  type DecodedSourceMapSection,
8
8
  type IndexSourceMap,
9
- type RawSourceMap,
9
+ type SourceFetch,
10
10
  type SourceMap,
11
+ type SourceMapRequestOptions,
11
12
  type StandardSourceMap,
12
13
  } from "./symbolication.js";
13
14
  export type { FiberSource } from "./types.js";
14
15
  export { parseStack, type ParseOptions, type StackFrame } from "./parse-stack.js";
15
16
  export { getDisplayNameFromSource } from "./get-display-name-from-source.js";
17
+ export {
18
+ BippyError,
19
+ BippyHookInspectionError,
20
+ BippyHookRenderError,
21
+ BippySourceMapError,
22
+ BippyUnsupportedHookError,
23
+ } from "../errors.js";
16
24
  export { getFiberHooks, type HookSource, type HooksNode, type HooksTree } from "./inspect-hooks.js";
17
25
  export { parseHookNames, type HookNames } from "./parse-hook-names.js";