bippy 0.6.1-dev.3a24abf → 0.6.1-dev.b88fcb4

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 (48) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +7 -1
  3. package/dist/core.cjs +1 -1
  4. package/dist/core.d.cts +39 -41
  5. package/dist/core.d.ts +39 -41
  6. package/dist/core.js +1 -1
  7. package/dist/core2.cjs +1 -1
  8. package/dist/core2.d.cts +11 -3
  9. package/dist/core2.d.ts +11 -3
  10. package/dist/core2.js +1 -1
  11. package/dist/{types.d.cts → errors.d.cts} +205 -31
  12. package/dist/{types.d.ts → errors.d.ts} +205 -31
  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 +8 -0
  20. package/dist/install-hook-only.d.ts +8 -0
  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 +13 -13
  26. package/dist/source.d.cts +27 -9
  27. package/dist/source.d.ts +27 -9
  28. package/dist/source.js +13 -13
  29. package/package.json +10 -6
  30. package/src/core.ts +269 -224
  31. package/src/errors.ts +99 -0
  32. package/src/rdt-hook.ts +154 -99
  33. package/src/react-internals/generated/react-work-tags.ts +314 -0
  34. package/src/react-internals/index.ts +67 -0
  35. package/src/react-internals/semver.ts +78 -0
  36. package/src/{types.ts → react-internals/types.ts} +13 -3
  37. package/src/source/error-stack.ts +11 -0
  38. package/src/source/get-display-name-from-source.ts +1 -1
  39. package/src/source/get-source.ts +2 -2
  40. package/src/source/index.ts +9 -1
  41. package/src/source/inspect-hooks.ts +199 -165
  42. package/src/source/owner-stack.ts +26 -39
  43. package/src/source/parse-debug-stack.ts +4 -4
  44. package/src/source/parse-hook-names.ts +1 -1
  45. package/src/source/symbolication.ts +468 -101
  46. package/src/generated/react-work-tags.ts +0 -169
  47. package/src/react-internals.ts +0 -67
  48. package/src/unsubscribe.ts +0 -17
@@ -1,26 +1,17 @@
1
1
  import { getDisplayName, getType, traverseFiber } from "../core.js";
2
2
  import { _renderers, getRDTHook } from "../rdt-hook.js";
3
- import {
4
- ActivityComponentTag,
5
- ClassComponentTag,
6
- ForwardRefTag,
7
- FunctionComponentTag,
8
- HostComponentTag,
9
- HostHoistableTag,
10
- HostSingletonTag,
11
- LazyComponentTag,
12
- SimpleMemoComponentTag,
13
- SuspenseComponentTag,
14
- SuspenseListComponentTag,
15
- ViewTransitionComponentTag,
16
- } from "../react-internals.js";
17
- import type { Fiber, RendererDispatcherRef, ServerComponentInfo } from "../types.js";
3
+ import { getReactWorkTagsForFiber } from "../react-internals/index.js";
4
+ import type {
5
+ Fiber,
6
+ RendererDispatcherRef,
7
+ ServerComponentInfo,
8
+ } from "../react-internals/index.js";
18
9
  import {
19
10
  SERVER_FRAME_MARKER,
20
11
  SERVER_ENV_PATTERN,
21
12
  SERVER_COMPONENT_URL_PREFIXES,
22
13
  } from "./constants.js";
23
-
14
+ import { getPrepareStackTrace, setPrepareStackTrace } from "./error-stack.js";
24
15
  import { parseDebugStack } from "./parse-debug-stack.js";
25
16
  import { parseStack, StackFrame } from "./parse-stack.js";
26
17
  import { symbolicateStack } from "./symbolication.js";
@@ -160,9 +151,8 @@ const describeNativeComponentFrame = (
160
151
  return cachedFrame;
161
152
  }
162
153
 
163
- const previousPrepareStackTrace = Error.prepareStackTrace;
164
- // HACK: V8 API allows undefined but bun-types declares it as non-optional
165
- (Error as { prepareStackTrace?: typeof Error.prepareStackTrace }).prepareStackTrace = undefined;
154
+ const previousPrepareStackTrace = getPrepareStackTrace();
155
+ setPrepareStackTrace(undefined);
166
156
  reEntry = true;
167
157
 
168
158
  const dispatcherSnapshots = clearRendererDispatchers();
@@ -173,7 +163,7 @@ const describeNativeComponentFrame = (
173
163
  try {
174
164
  // HACK: Run the control and sample under the same property name so their stacks share a frame.
175
165
  const RunInRootFrame = {
176
- DetermineComponentFrameRoot() {
166
+ DetermineComponentFrameRoot(this: void) {
177
167
  let control: unknown;
178
168
  try {
179
169
  if (construct) {
@@ -325,7 +315,7 @@ const describeNativeComponentFrame = (
325
315
  } finally {
326
316
  reEntry = false;
327
317
 
328
- Error.prepareStackTrace = previousPrepareStackTrace;
318
+ setPrepareStackTrace(previousPrepareStackTrace);
329
319
 
330
320
  restoreRendererDispatchers(dispatcherSnapshots);
331
321
  console.error = previousConsoleError;
@@ -341,32 +331,33 @@ const describeNativeComponentFrame = (
341
331
  // https://github.com/facebook/react/blob/ac3e705a18696168acfcaed39dce0cfaa6be8836/packages/react-reconciler/src/ReactFiberComponentStack.js#L180
342
332
  export const describeFiber = (fiber: Fiber, childFiber: Fiber | null): string => {
343
333
  let stackFrame = "";
334
+ const workTags = getReactWorkTagsForFiber(fiber);
344
335
  switch (fiber.tag) {
345
- case ActivityComponentTag:
336
+ case workTags.ActivityComponent:
346
337
  stackFrame = describeBuiltInComponentFrame("Activity");
347
338
  break;
348
- case ClassComponentTag:
339
+ case workTags.ClassComponent:
349
340
  stackFrame = describeNativeComponentFrame(fiber.type, true);
350
341
  break;
351
- case ForwardRefTag:
342
+ case workTags.ForwardRef:
352
343
  stackFrame = describeNativeComponentFrame(getType(fiber.type) ?? fiber.type, false);
353
344
  break;
354
- case FunctionComponentTag:
355
- case SimpleMemoComponentTag:
345
+ case workTags.FunctionComponent:
346
+ case workTags.SimpleMemoComponent:
356
347
  stackFrame = describeNativeComponentFrame(fiber.type, false);
357
348
  break;
358
- case HostComponentTag:
359
- case HostHoistableTag:
360
- case HostSingletonTag:
349
+ case workTags.HostComponent:
350
+ case workTags.HostHoistable:
351
+ case workTags.HostSingleton:
361
352
  if (typeof fiber.type === "string") {
362
353
  stackFrame = describeBuiltInComponentFrame(fiber.type);
363
354
  }
364
355
  break;
365
- case LazyComponentTag:
356
+ case workTags.LazyComponent:
366
357
  // TODO: When we support Thenables as component types we should rename this.
367
358
  stackFrame = describeBuiltInComponentFrame("Lazy");
368
359
  break;
369
- case SuspenseComponentTag:
360
+ case workTags.SuspenseComponent:
370
361
  if (fiber.child !== childFiber && childFiber !== null) {
371
362
  // If we came from the second Fiber then we're in the Suspense Fallback.
372
363
  stackFrame = describeBuiltInComponentFrame("Suspense Fallback");
@@ -374,10 +365,10 @@ export const describeFiber = (fiber: Fiber, childFiber: Fiber | null): string =>
374
365
  stackFrame = describeBuiltInComponentFrame("Suspense");
375
366
  }
376
367
  break;
377
- case SuspenseListComponentTag:
368
+ case workTags.SuspenseListComponent:
378
369
  stackFrame = describeBuiltInComponentFrame("SuspenseList");
379
370
  break;
380
- case ViewTransitionComponentTag:
371
+ case workTags.ViewTransitionComponent:
381
372
  // Note: enableViewTransition feature flag is not available in this codebase,
382
373
  // so we'll always include ViewTransition
383
374
  stackFrame = describeBuiltInComponentFrame("ViewTransition");
@@ -406,8 +397,8 @@ export const getFallbackParentStack = (thisFiber: Fiber): string => {
406
397
  // Since we don't have __DEV__ in this codebase, we'll check for _debugInfo
407
398
  const debugInfo = currentFiber._debugInfo;
408
399
  if (debugInfo && Array.isArray(debugInfo)) {
409
- for (let i = debugInfo.length - 1; i >= 0; i--) {
410
- const debugEntry = debugInfo[i];
400
+ for (let debugInfoIndex = debugInfo.length - 1; debugInfoIndex >= 0; debugInfoIndex--) {
401
+ const debugEntry = debugInfo[debugInfoIndex];
411
402
  if (typeof debugEntry.name === "string") {
412
403
  componentStack += describeDebugInfoFrame(debugEntry.name, debugEntry.env);
413
404
  }
@@ -445,14 +436,10 @@ export const getFallbackParentStack = (thisFiber: Fiber): string => {
445
436
  * @see https://github.com/facebook/react/blob/main/packages/react-devtools-shared/src/backend/shared/DevToolsOwnerStack.js#L12
446
437
  */
447
438
  export const formatOwnerStack = (stack: string): string => {
448
- const prevPrepareStackTrace = Error.prepareStackTrace;
449
- // HACK: V8 API allows undefined but bun-types declares it as non-optional
450
- (Error as { prepareStackTrace?: typeof Error.prepareStackTrace }).prepareStackTrace = undefined;
451
439
  let formattedStack = stack;
452
440
  if (!formattedStack) {
453
441
  return "";
454
442
  }
455
- Error.prepareStackTrace = prevPrepareStackTrace;
456
443
 
457
444
  if (formattedStack.startsWith("Error: react-stack-top-frame\n")) {
458
445
  // V8's default formatting prefixes with the error message which we
@@ -1,4 +1,5 @@
1
1
  import { JSX_FACTORY_FRAME_COUNT, REACT_STACK_BOTTOM_FRAME_PATTERNS } from "./constants.js";
2
+ import { getPrepareStackTrace, setPrepareStackTrace } from "./error-stack.js";
2
3
  import { parseStack, StackFrame } from "./parse-stack.js";
3
4
 
4
5
  interface V8CallSite {
@@ -117,14 +118,13 @@ export const parseDebugStack = (debugStack: Error): ParsedDebugStack => {
117
118
  }
118
119
  return stackString;
119
120
  };
120
- const previousPrepareStackTrace = Error.prepareStackTrace;
121
- // node's CallSite typings disagree with browser-safe optional methods
122
- Error.prepareStackTrace = collectFramesAndFormatStack as typeof Error.prepareStackTrace;
121
+ const previousPrepareStackTrace = getPrepareStackTrace();
122
+ setPrepareStackTrace(collectFramesAndFormatStack);
123
123
  let stackString: string;
124
124
  try {
125
125
  stackString = String(debugStack.stack);
126
126
  } finally {
127
- Error.prepareStackTrace = previousPrepareStackTrace;
127
+ setPrepareStackTrace(previousPrepareStackTrace);
128
128
  }
129
129
 
130
130
  const result = structuredResult ?? parseMaterializedStack(stackString);
@@ -35,7 +35,7 @@ const flattenHooksTree = (hooksTree: HooksTree): HooksNode[] => {
35
35
 
36
36
  const findSourceContentByFileName = (
37
37
  sources: string[],
38
- sourcesContent: string[] | undefined,
38
+ sourcesContent: Array<string | null> | undefined,
39
39
  fileName: string,
40
40
  ): string | null => {
41
41
  if (!sourcesContent) return null;