@alloy-js/core 0.23.0-dev.0 → 0.23.0-dev.10

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 (316) hide show
  1. package/CHANGELOG.md +0 -22
  2. package/dist/devtools/index.html +68 -0
  3. package/dist/src/binder.d.ts +2 -0
  4. package/dist/src/binder.d.ts.map +1 -1
  5. package/dist/src/binder.js +55 -12
  6. package/dist/src/binder.js.map +1 -1
  7. package/dist/src/components/AccessExpression.d.ts +78 -0
  8. package/dist/src/components/AccessExpression.d.ts.map +1 -0
  9. package/dist/src/components/AccessExpression.js +218 -0
  10. package/dist/src/components/AccessExpression.js.map +1 -0
  11. package/dist/src/components/AccessExpression.test.d.ts +2 -0
  12. package/dist/src/components/AccessExpression.test.d.ts.map +1 -0
  13. package/dist/src/components/AccessExpression.test.js +137 -0
  14. package/dist/src/components/AccessExpression.test.js.map +1 -0
  15. package/dist/src/components/AppendFile.d.ts.map +1 -1
  16. package/dist/src/components/AppendFile.js +14 -3
  17. package/dist/src/components/AppendFile.js.map +1 -1
  18. package/dist/src/components/Block.js +1 -1
  19. package/dist/src/components/Block.js.map +1 -1
  20. package/dist/src/components/Declaration.d.ts.map +1 -1
  21. package/dist/src/components/Declaration.js +2 -1
  22. package/dist/src/components/Declaration.js.map +1 -1
  23. package/dist/src/components/Prose.js +2 -2
  24. package/dist/src/components/Prose.js.map +1 -1
  25. package/dist/src/components/Scope.d.ts.map +1 -1
  26. package/dist/src/components/Scope.js +6 -1
  27. package/dist/src/components/Scope.js.map +1 -1
  28. package/dist/src/components/SourceDirectory.d.ts.map +1 -1
  29. package/dist/src/components/SourceDirectory.js +1 -2
  30. package/dist/src/components/SourceDirectory.js.map +1 -1
  31. package/dist/src/components/TemplateFile.d.ts.map +1 -1
  32. package/dist/src/components/TemplateFile.js +18 -3
  33. package/dist/src/components/TemplateFile.js.map +1 -1
  34. package/dist/src/components/index.d.ts +1 -0
  35. package/dist/src/components/index.d.ts.map +1 -1
  36. package/dist/src/components/index.js +1 -0
  37. package/dist/src/components/index.js.map +1 -1
  38. package/dist/src/content-slot.d.ts.map +1 -1
  39. package/dist/src/content-slot.js +7 -6
  40. package/dist/src/content-slot.js.map +1 -1
  41. package/dist/src/context.d.ts.map +1 -1
  42. package/dist/src/context.js +10 -3
  43. package/dist/src/context.js.map +1 -1
  44. package/dist/src/debug/cli.d.ts +6 -0
  45. package/dist/src/debug/cli.d.ts.map +1 -0
  46. package/dist/src/{debug.js → debug/cli.js} +78 -84
  47. package/dist/src/debug/cli.js.map +1 -0
  48. package/dist/src/debug/diagnostics.test.d.ts +2 -0
  49. package/dist/src/debug/diagnostics.test.d.ts.map +1 -0
  50. package/dist/src/debug/diagnostics.test.js +45 -0
  51. package/dist/src/debug/diagnostics.test.js.map +1 -0
  52. package/dist/src/debug/effects.d.ts +73 -0
  53. package/dist/src/debug/effects.d.ts.map +1 -0
  54. package/dist/src/debug/effects.js +228 -0
  55. package/dist/src/debug/effects.js.map +1 -0
  56. package/dist/src/debug/effects.test.d.ts +2 -0
  57. package/dist/src/debug/effects.test.d.ts.map +1 -0
  58. package/dist/src/debug/effects.test.js +84 -0
  59. package/dist/src/debug/effects.test.js.map +1 -0
  60. package/dist/src/debug/files.d.ts +14 -0
  61. package/dist/src/debug/files.d.ts.map +1 -0
  62. package/dist/src/debug/files.js +40 -0
  63. package/dist/src/debug/files.js.map +1 -0
  64. package/dist/src/debug/files.test.d.ts +2 -0
  65. package/dist/src/debug/files.test.d.ts.map +1 -0
  66. package/dist/src/debug/files.test.js +89 -0
  67. package/dist/src/debug/files.test.js.map +1 -0
  68. package/dist/src/debug/index.d.ts +61 -0
  69. package/dist/src/debug/index.d.ts.map +1 -0
  70. package/dist/src/debug/index.js +69 -0
  71. package/dist/src/debug/index.js.map +1 -0
  72. package/dist/src/debug/render.d.ts +57 -0
  73. package/dist/src/debug/render.d.ts.map +1 -0
  74. package/dist/src/debug/render.js +519 -0
  75. package/dist/src/debug/render.js.map +1 -0
  76. package/dist/src/debug/render.test.d.ts +2 -0
  77. package/dist/src/debug/render.test.d.ts.map +1 -0
  78. package/dist/src/debug/render.test.js +328 -0
  79. package/dist/src/debug/render.test.js.map +1 -0
  80. package/dist/src/debug/serialize.d.ts +9 -0
  81. package/dist/src/debug/serialize.d.ts.map +1 -0
  82. package/dist/src/debug/serialize.js +70 -0
  83. package/dist/src/debug/serialize.js.map +1 -0
  84. package/dist/src/debug/symbols.d.ts +15 -0
  85. package/dist/src/debug/symbols.d.ts.map +1 -0
  86. package/dist/src/debug/symbols.js +173 -0
  87. package/dist/src/debug/symbols.js.map +1 -0
  88. package/dist/src/debug/symbols.test.d.ts +2 -0
  89. package/dist/src/debug/symbols.test.d.ts.map +1 -0
  90. package/dist/src/debug/symbols.test.js +104 -0
  91. package/dist/src/debug/symbols.test.js.map +1 -0
  92. package/dist/src/debug/trace.d.ts +342 -0
  93. package/dist/src/debug/trace.d.ts.map +1 -0
  94. package/dist/src/debug/trace.js +443 -0
  95. package/dist/src/debug/trace.js.map +1 -0
  96. package/dist/src/devtools/devtools-protocol.d.ts +232 -0
  97. package/dist/src/devtools/devtools-protocol.d.ts.map +1 -0
  98. package/dist/src/devtools/devtools-protocol.js +2 -0
  99. package/dist/src/devtools/devtools-protocol.js.map +1 -0
  100. package/dist/src/devtools/devtools-server.browser.d.ts +28 -0
  101. package/dist/src/devtools/devtools-server.browser.d.ts.map +1 -0
  102. package/dist/src/devtools/devtools-server.browser.js +36 -0
  103. package/dist/src/devtools/devtools-server.browser.js.map +1 -0
  104. package/dist/src/devtools/devtools-server.d.ts +72 -0
  105. package/dist/src/devtools/devtools-server.d.ts.map +1 -0
  106. package/dist/src/devtools/devtools-server.js +256 -0
  107. package/dist/src/devtools/devtools-server.js.map +1 -0
  108. package/dist/src/devtools/devtools-transport.d.ts +23 -0
  109. package/dist/src/devtools/devtools-transport.d.ts.map +1 -0
  110. package/dist/src/devtools/devtools-transport.js +114 -0
  111. package/dist/src/devtools/devtools-transport.js.map +1 -0
  112. package/dist/src/devtools-entry.browser.d.ts +4 -0
  113. package/dist/src/devtools-entry.browser.d.ts.map +1 -0
  114. package/dist/src/devtools-entry.browser.js +2 -0
  115. package/dist/src/devtools-entry.browser.js.map +1 -0
  116. package/dist/src/devtools-entry.d.ts +4 -0
  117. package/dist/src/devtools-entry.d.ts.map +1 -0
  118. package/dist/src/devtools-entry.js +2 -0
  119. package/dist/src/devtools-entry.js.map +1 -0
  120. package/dist/src/diagnostics.d.ts +34 -0
  121. package/dist/src/diagnostics.d.ts.map +1 -0
  122. package/dist/src/diagnostics.js +89 -0
  123. package/dist/src/diagnostics.js.map +1 -0
  124. package/dist/src/index.d.ts +3 -2
  125. package/dist/src/index.d.ts.map +1 -1
  126. package/dist/src/index.js +3 -2
  127. package/dist/src/index.js.map +1 -1
  128. package/dist/src/print-hook.d.ts +14 -0
  129. package/dist/src/print-hook.d.ts.map +1 -0
  130. package/dist/src/print-hook.js +10 -0
  131. package/dist/src/print-hook.js.map +1 -0
  132. package/dist/src/reactive-union-set.d.ts.map +1 -1
  133. package/dist/src/reactive-union-set.js +28 -3
  134. package/dist/src/reactive-union-set.js.map +1 -1
  135. package/dist/src/reactivity.d.ts +50 -8
  136. package/dist/src/reactivity.d.ts.map +1 -1
  137. package/dist/src/reactivity.js +225 -39
  138. package/dist/src/reactivity.js.map +1 -1
  139. package/dist/src/render-stack.d.ts +30 -0
  140. package/dist/src/render-stack.d.ts.map +1 -0
  141. package/dist/src/render-stack.js +251 -0
  142. package/dist/src/render-stack.js.map +1 -0
  143. package/dist/src/render.d.ts +9 -19
  144. package/dist/src/render.d.ts.map +1 -1
  145. package/dist/src/render.js +371 -159
  146. package/dist/src/render.js.map +1 -1
  147. package/dist/src/resource.d.ts.map +1 -1
  148. package/dist/src/resource.js +5 -0
  149. package/dist/src/resource.js.map +1 -1
  150. package/dist/src/runtime/component.d.ts +7 -1
  151. package/dist/src/runtime/component.d.ts.map +1 -1
  152. package/dist/src/runtime/component.js +4 -1
  153. package/dist/src/runtime/component.js.map +1 -1
  154. package/dist/src/scheduler.d.ts +8 -0
  155. package/dist/src/scheduler.d.ts.map +1 -1
  156. package/dist/src/scheduler.js +69 -3
  157. package/dist/src/scheduler.js.map +1 -1
  158. package/dist/src/symbols/basic-symbol.d.ts.map +1 -1
  159. package/dist/src/symbols/basic-symbol.js +6 -1
  160. package/dist/src/symbols/basic-symbol.js.map +1 -1
  161. package/dist/src/symbols/decl.d.ts.map +1 -1
  162. package/dist/src/symbols/decl.js +5 -1
  163. package/dist/src/symbols/decl.js.map +1 -1
  164. package/dist/src/symbols/output-scope.d.ts +2 -1
  165. package/dist/src/symbols/output-scope.d.ts.map +1 -1
  166. package/dist/src/symbols/output-scope.js +13 -8
  167. package/dist/src/symbols/output-scope.js.map +1 -1
  168. package/dist/src/symbols/output-symbol.d.ts +1 -0
  169. package/dist/src/symbols/output-symbol.d.ts.map +1 -1
  170. package/dist/src/symbols/output-symbol.js +25 -8
  171. package/dist/src/symbols/output-symbol.js.map +1 -1
  172. package/dist/src/symbols/symbol-flow.d.ts.map +1 -1
  173. package/dist/src/symbols/symbol-flow.js +24 -8
  174. package/dist/src/symbols/symbol-flow.js.map +1 -1
  175. package/dist/src/symbols/symbol-slot.d.ts.map +1 -1
  176. package/dist/src/symbols/symbol-slot.js +15 -0
  177. package/dist/src/symbols/symbol-slot.js.map +1 -1
  178. package/dist/src/symbols/symbol-slot.test.d.ts +2 -0
  179. package/dist/src/symbols/symbol-slot.test.d.ts.map +1 -0
  180. package/dist/src/symbols/symbol-slot.test.js +35 -0
  181. package/dist/src/symbols/symbol-slot.test.js.map +1 -0
  182. package/dist/src/symbols/symbol-table.d.ts.map +1 -1
  183. package/dist/src/symbols/symbol-table.js +6 -5
  184. package/dist/src/symbols/symbol-table.js.map +1 -1
  185. package/dist/src/trace.d.ts +2 -0
  186. package/dist/src/trace.d.ts.map +1 -0
  187. package/dist/src/trace.js +2 -0
  188. package/dist/src/trace.js.map +1 -0
  189. package/dist/src/tracer.d.ts +2 -228
  190. package/dist/src/tracer.d.ts.map +1 -1
  191. package/dist/src/tracer.js +5 -298
  192. package/dist/src/tracer.js.map +1 -1
  193. package/dist/src/utils.d.ts.map +1 -1
  194. package/dist/src/utils.js +7 -5
  195. package/dist/src/utils.js.map +1 -1
  196. package/dist/test/components/append-file.test.d.ts.map +1 -1
  197. package/dist/test/components/append-file.test.js +18 -10
  198. package/dist/test/components/append-file.test.js.map +1 -1
  199. package/dist/test/components/template-file.test.d.ts.map +1 -1
  200. package/dist/test/components/template-file.test.js +6 -4
  201. package/dist/test/components/template-file.test.js.map +1 -1
  202. package/dist/test/lazy-isempty.test.d.ts +2 -0
  203. package/dist/test/lazy-isempty.test.d.ts.map +1 -0
  204. package/dist/test/lazy-isempty.test.js +89 -0
  205. package/dist/test/lazy-isempty.test.js.map +1 -0
  206. package/dist/test/reactive-union-set-disposers.test.d.ts +2 -0
  207. package/dist/test/reactive-union-set-disposers.test.d.ts.map +1 -0
  208. package/dist/test/reactive-union-set-disposers.test.js +98 -0
  209. package/dist/test/reactive-union-set-disposers.test.js.map +1 -0
  210. package/dist/test/reactivity/shallow-reactive.test.d.ts +2 -0
  211. package/dist/test/reactivity/shallow-reactive.test.d.ts.map +1 -0
  212. package/dist/test/reactivity/shallow-reactive.test.js +52 -0
  213. package/dist/test/reactivity/shallow-reactive.test.js.map +1 -0
  214. package/dist/test/rendering/basic.test.js +3 -0
  215. package/dist/test/rendering/basic.test.js.map +1 -1
  216. package/dist/test/rendering/print-render-stack.test.d.ts +2 -0
  217. package/dist/test/rendering/print-render-stack.test.d.ts.map +1 -0
  218. package/dist/test/rendering/print-render-stack.test.js +207 -0
  219. package/dist/test/rendering/print-render-stack.test.js.map +1 -0
  220. package/dist/test/scheduler-extended.test.d.ts +2 -0
  221. package/dist/test/scheduler-extended.test.d.ts.map +1 -0
  222. package/dist/test/scheduler-extended.test.js +96 -0
  223. package/dist/test/scheduler-extended.test.js.map +1 -0
  224. package/dist/test/scheduler.test.d.ts +2 -0
  225. package/dist/test/scheduler.test.d.ts.map +1 -0
  226. package/dist/test/scheduler.test.js +46 -0
  227. package/dist/test/scheduler.test.js.map +1 -0
  228. package/dist/testing/create-test-wrapper.d.ts +1 -1
  229. package/dist/testing/create-test-wrapper.d.ts.map +1 -1
  230. package/dist/testing/create-test-wrapper.js +1 -1
  231. package/dist/testing/create-test-wrapper.js.map +1 -1
  232. package/dist/testing/devtools-utils.d.ts +26 -0
  233. package/dist/testing/devtools-utils.d.ts.map +1 -0
  234. package/dist/testing/devtools-utils.js +140 -0
  235. package/dist/testing/devtools-utils.js.map +1 -0
  236. package/dist/testing/extend-expect.d.ts.map +1 -1
  237. package/dist/testing/extend-expect.js +63 -1
  238. package/dist/testing/extend-expect.js.map +1 -1
  239. package/dist/testing/render.d.ts +2 -2
  240. package/dist/testing/render.d.ts.map +1 -1
  241. package/dist/testing/render.js +2 -2
  242. package/dist/testing/render.js.map +1 -1
  243. package/dist/tsconfig.tsbuildinfo +1 -1
  244. package/package.json +21 -7
  245. package/scripts/copy-devtools-ui.mjs +26 -0
  246. package/src/binder.ts +71 -16
  247. package/src/components/AccessExpression.test.tsx +132 -0
  248. package/src/components/AccessExpression.tsx +344 -0
  249. package/src/components/AppendFile.tsx +14 -9
  250. package/src/components/Block.tsx +1 -1
  251. package/src/components/Declaration.tsx +2 -1
  252. package/src/components/Prose.tsx +1 -1
  253. package/src/components/Scope.tsx +6 -1
  254. package/src/components/SourceDirectory.tsx +1 -2
  255. package/src/components/TemplateFile.tsx +18 -9
  256. package/src/components/index.tsx +1 -0
  257. package/src/content-slot.tsx +7 -7
  258. package/src/context.ts +17 -6
  259. package/src/{debug.ts → debug/cli.ts} +112 -127
  260. package/src/debug/diagnostics.test.tsx +55 -0
  261. package/src/debug/effects.test.tsx +89 -0
  262. package/src/debug/effects.ts +317 -0
  263. package/src/debug/files.test.tsx +96 -0
  264. package/src/debug/files.ts +40 -0
  265. package/src/debug/index.ts +128 -0
  266. package/src/debug/render.test.tsx +379 -0
  267. package/src/debug/render.ts +639 -0
  268. package/src/debug/serialize.ts +85 -0
  269. package/src/debug/symbols.test.tsx +106 -0
  270. package/src/debug/symbols.ts +239 -0
  271. package/src/debug/trace.ts +312 -0
  272. package/src/devtools/devtools-protocol.ts +312 -0
  273. package/src/devtools/devtools-server.browser.ts +71 -0
  274. package/src/devtools/devtools-server.ts +290 -0
  275. package/src/devtools/devtools-transport.ts +154 -0
  276. package/src/devtools-entry.browser.ts +52 -0
  277. package/src/devtools-entry.ts +54 -0
  278. package/src/diagnostics.ts +141 -0
  279. package/src/index.ts +2 -7
  280. package/src/print-hook.ts +22 -0
  281. package/src/reactive-union-set.ts +85 -44
  282. package/src/reactivity.ts +301 -59
  283. package/src/render-stack.ts +294 -0
  284. package/src/render.ts +470 -216
  285. package/src/resource.ts +28 -19
  286. package/src/runtime/component.ts +11 -0
  287. package/src/scheduler.ts +80 -4
  288. package/src/symbols/basic-symbol.ts +6 -1
  289. package/src/symbols/decl.ts +5 -1
  290. package/src/symbols/output-scope.ts +21 -13
  291. package/src/symbols/output-symbol.ts +34 -14
  292. package/src/symbols/symbol-flow.ts +76 -39
  293. package/src/symbols/symbol-slot.test.tsx +41 -0
  294. package/src/symbols/symbol-slot.tsx +47 -20
  295. package/src/symbols/symbol-table.ts +6 -10
  296. package/src/trace.ts +1 -0
  297. package/src/tracer.ts +13 -242
  298. package/src/utils.tsx +24 -17
  299. package/temp/api.json +4187 -1603
  300. package/test/components/append-file.test.tsx +36 -29
  301. package/test/components/template-file.test.tsx +11 -11
  302. package/test/lazy-isempty.test.tsx +106 -0
  303. package/test/reactive-union-set-disposers.test.tsx +112 -0
  304. package/test/reactivity/shallow-reactive.test.tsx +56 -0
  305. package/test/rendering/basic.test.tsx +4 -0
  306. package/test/rendering/print-render-stack.test.tsx +244 -0
  307. package/test/scheduler-extended.test.tsx +122 -0
  308. package/test/scheduler.test.tsx +50 -0
  309. package/testing/create-test-wrapper.tsx +1 -1
  310. package/testing/devtools-utils.ts +203 -0
  311. package/testing/extend-expect.ts +89 -0
  312. package/testing/render.ts +2 -2
  313. package/testing/vitest.d.ts +9 -0
  314. package/dist/src/debug.d.ts +0 -15
  315. package/dist/src/debug.d.ts.map +0 -1
  316. package/dist/src/debug.js.map +0 -1
@@ -1,38 +1,63 @@
1
- import { isRef, pauseTracking, ref, resetTracking, shallowRef, stop, effect as vueEffect } from "@vue/reactivity";
1
+ import { isRef, pauseTracking, resetTracking, stop, computed as vueComputed, effect as vueEffect, ref as vueRef, shallowReactive as vueShallowReactive, shallowRef as vueShallowRef, toRef as vueToRef, toRefs as vueToRefs } from "@vue/reactivity";
2
+ import { captureSourceLocation, debug, isDevtoolsEnabled } from "./debug/index.js";
2
3
  import { scheduler } from "./scheduler.js";
3
- import { trace, TracePhase } from "./tracer.js";
4
-
5
- // check for multiple versions of alloy here.
6
4
  if (globalThis.__ALLOY__) {
7
5
  throw new Error("Multiple versions of Alloy are loaded for this project. This will likely cause undesirable behavior.");
8
6
  }
9
7
  globalThis.__ALLOY__ = true;
10
8
  export function getElementCache() {
11
- return getContext().elementCache;
9
+ const ctx = getContext();
10
+ return ctx.elementCache ??= new Map();
12
11
  }
12
+ let contextIdCounter = 0;
13
13
  let globalContext = null;
14
14
  export function getContext() {
15
15
  return globalContext;
16
16
  }
17
+
18
+ /**
19
+ * Walk up the owner chain to find the nearest ancestor context that
20
+ * corresponds to an effect (has meta.effectId). This bridges non-effect
21
+ * scopes (like createRoot iterations in For) so the owner chain always
22
+ * connects effect-to-effect.
23
+ */
24
+ function resolveOwnerEffectContextId(context) {
25
+ let owner = context.owner;
26
+ while (owner) {
27
+ if (owner.meta?.effectId !== undefined) {
28
+ return owner.id;
29
+ }
30
+ owner = owner.owner;
31
+ }
32
+ return context.owner?.id ?? null;
33
+ }
34
+
35
+ /**
36
+ * Ensure that a context has an isEmpty ref, creating one if needed.
37
+ * Only call this when you need to reactively observe isEmpty (e.g.,
38
+ * ContentSlot, mapJoin). Most contexts don't need an isEmpty ref.
39
+ */
40
+ export function ensureIsEmpty(context) {
41
+ context.isEmpty ??= ref(context.childrenWithContent === 0);
42
+ return context.isEmpty;
43
+ }
17
44
  export function root(fn, options) {
18
45
  const context = {
46
+ id: contextIdCounter++,
19
47
  componentOwner: options?.componentOwner,
20
- disposables: [],
21
48
  owner: globalContext,
22
- context: {},
23
- elementCache: new Map(),
24
49
  takesSymbols: false,
25
50
  takenSymbols: undefined,
26
51
  childrenWithContent: 0,
27
- isEmpty: ref(true),
52
+ _lastEmpty: true,
28
53
  isRoot: true
29
54
  };
30
55
  globalContext = context;
31
56
  let ret;
32
57
  try {
33
58
  ret = untrack(() => fn(() => {
34
- for (const d of context.disposables) {
35
- d();
59
+ for (const d of context.disposables ?? []) {
60
+ untrack(d);
36
61
  }
37
62
  }));
38
63
  } finally {
@@ -46,36 +71,127 @@ export function untrack(fn) {
46
71
  resetTracking();
47
72
  return v;
48
73
  }
49
- export function memo(fn, equal) {
74
+
75
+ /**
76
+ * Walk up the context owner chain to find the nearest effect ID.
77
+ * Used to attribute reactive mutations to the effect that caused them.
78
+ */
79
+ export function findCurrentEffectId() {
80
+ let ctx = globalContext;
81
+ while (ctx) {
82
+ const id = ctx.meta?.effectId;
83
+ if (id !== undefined && id !== -1) return id;
84
+ ctx = ctx.owner;
85
+ }
86
+ return undefined;
87
+ }
88
+ export function memo(fn, equal, name) {
50
89
  const o = shallowRef();
51
90
  effect(prev => {
52
91
  const res = fn();
53
92
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
54
93
  (!equal || prev !== res) && (o.value = res);
55
94
  return res;
56
- }, undefined);
57
- return () => o.value;
95
+ }, undefined, {
96
+ debug: {
97
+ name: name ? `memo:${name}` : "memo"
98
+ }
99
+ });
100
+ const getter = () => o.value;
101
+ if (name) {
102
+ Object.defineProperty(getter, "name", {
103
+ value: name,
104
+ configurable: true
105
+ });
106
+ }
107
+ return getter;
58
108
  }
59
- export function effect(fn, current) {
109
+ export function effect(fn, current, options) {
60
110
  const context = {
61
- context: {},
62
- disposables: [],
111
+ id: contextIdCounter++,
63
112
  owner: globalContext,
64
- elementCache: new Map(),
65
113
  takesSymbols: false,
66
114
  takenSymbols: undefined,
67
115
  childrenWithContent: 0,
116
+ _lastEmpty: true,
68
117
  isRoot: false
69
118
  };
119
+ const debugInfo = options?.debug;
120
+ const effectId = debug.effect.register({
121
+ name: debugInfo?.name ?? fn.name,
122
+ type: debugInfo?.type,
123
+ createdAt: captureSourceLocation(),
124
+ contextId: context.id,
125
+ ownerContextId: resolveOwnerEffectContextId(context)
126
+ });
127
+ if (effectId !== -1) {
128
+ context.meta ??= {};
129
+ context.meta.effectId = effectId;
130
+ }
70
131
  const cleanupFn = final => {
71
132
  const d = context.disposables;
72
- context.disposables = [];
73
- for (let k = 0, len = d.length; k < len; k++) d[k]();
133
+ context.disposables = undefined;
134
+ if (d) {
135
+ for (let k = 0, len = d.length; k < len; k++) untrack(d[k]);
136
+ }
74
137
 
75
138
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
76
139
  final && stop(runner);
77
140
  };
78
141
  onCleanup(() => cleanupFn(true));
142
+ const effectOpts = {
143
+ // allow recursive effects with 32, 1 and 4 are default flags
144
+ flags: 1 | 4 | 32,
145
+ scheduler: scheduler()
146
+ };
147
+ if (effectId !== -1) {
148
+ effectOpts.onTrack = event => {
149
+ const targetKey = typeof event.key === "symbol" ? event.key.toString() : event.key;
150
+ if (isRef(event.target)) {
151
+ const id = refId(event.target);
152
+ debug.effect.ensureRef({
153
+ id,
154
+ kind: "ref"
155
+ });
156
+ debug.effect.track({
157
+ effectId,
158
+ target: event.target,
159
+ refId: id,
160
+ targetKey
161
+ });
162
+ } else {
163
+ debug.effect.track({
164
+ effectId,
165
+ target: event.target,
166
+ targetKey
167
+ });
168
+ }
169
+ };
170
+ effectOpts.onTrigger = event => {
171
+ const targetKey = typeof event.key === "symbol" ? event.key.toString() : event.key;
172
+ if (isRef(event.target)) {
173
+ const id = refId(event.target);
174
+ debug.effect.ensureRef({
175
+ id,
176
+ kind: "ref"
177
+ });
178
+ debug.effect.trigger({
179
+ effectId,
180
+ target: event.target,
181
+ refId: id,
182
+ targetKey,
183
+ kind: "triggered-by"
184
+ });
185
+ } else {
186
+ debug.effect.trigger({
187
+ effectId,
188
+ target: event.target,
189
+ targetKey,
190
+ kind: "triggered-by"
191
+ });
192
+ }
193
+ };
194
+ }
79
195
  const runner = vueEffect(() => {
80
196
  cleanupFn(false);
81
197
  const oldContext = globalContext;
@@ -85,22 +201,10 @@ export function effect(fn, current) {
85
201
  } finally {
86
202
  globalContext = oldContext;
87
203
  }
88
- }, {
89
- // allow recursive effects with 32, 1 and 4 are default flags
90
- // @ts-expect-error flags is a vue internal thing
91
- flags: 1 | 4 | 32,
92
- scheduler: scheduler(),
93
- onTrack(event) {
94
- trace(TracePhase.effect.track, () => {
95
- return `tracking ${isRef(event.target) ? `Ref:${refId(event.target)}` : event.target}, ${String(event.key)}`;
96
- });
97
- },
98
- onTrigger(event) {
99
- trace(TracePhase.effect.trigger, () => {
100
- return `triggering ${isRef(event.target) ? `Ref:${refId(event.target)}` : event.target}, ${String(event.key)}`;
101
- });
102
- }
103
- });
204
+ }, effectOpts);
205
+ if (effectId !== -1) {
206
+ effectIdMap.set(runner.effect, effectId);
207
+ }
104
208
  }
105
209
 
106
210
  /**
@@ -123,7 +227,7 @@ export function effect(fn, current) {
123
227
  */
124
228
  export function onCleanup(fn) {
125
229
  if (globalContext != null) {
126
- globalContext.disposables.push(fn);
230
+ (globalContext.disposables ??= []).push(fn);
127
231
  }
128
232
  }
129
233
 
@@ -144,14 +248,96 @@ export function createCustomContext(useCallback) {
144
248
  export function isCustomContext(child) {
145
249
  return typeof child === "object" && child !== null && Object.hasOwn(child, CUSTOM_CONTEXT_SYM);
146
250
  }
251
+ export function ref(value, options) {
252
+ const result = vueRef(value);
253
+ debug.effect.registerRef({
254
+ id: refId(result, options?.isInfrastructure),
255
+ kind: "ref",
256
+ createdAt: captureSourceLocation(),
257
+ createdByEffectId: globalContext?.meta?.effectId,
258
+ isInfrastructure: options?.isInfrastructure
259
+ });
260
+ return result;
261
+ }
262
+
263
+ // Stores creation location for shallowReactive objects so registerNonRefTarget
264
+ // can look it up later (since targets are lazily registered on first track/trigger).
265
+ const reactiveCreationLocations = new WeakMap();
266
+ export function getReactiveCreationLocation(target) {
267
+ return reactiveCreationLocations.get(target);
268
+ }
269
+ export function shallowReactive(target) {
270
+ const result = vueShallowReactive(target);
271
+ if (isDevtoolsEnabled()) {
272
+ // Store by raw target — Vue's onTrack/onTrigger events pass the raw object, not the proxy.
273
+ reactiveCreationLocations.set(target, captureSourceLocation());
274
+ }
275
+ return result;
276
+ }
277
+ export function shallowRef(value) {
278
+ const result = vueShallowRef(value);
279
+ debug.effect.registerRef({
280
+ id: refId(result),
281
+ kind: "shallowRef",
282
+ createdAt: captureSourceLocation(),
283
+ createdByEffectId: globalContext?.meta?.effectId
284
+ });
285
+ return result;
286
+ }
287
+ export function computed(getter) {
288
+ const result = vueComputed(getter);
289
+ debug.effect.registerRef({
290
+ id: refId(result),
291
+ kind: "computed",
292
+ createdAt: captureSourceLocation(),
293
+ createdByEffectId: globalContext?.meta?.effectId
294
+ });
295
+ return result;
296
+ }
297
+ export function toRef(object, key, defaultValue) {
298
+ const result = defaultValue === undefined ? vueToRef(object, key) : vueToRef(object, key, defaultValue);
299
+ debug.effect.registerRef({
300
+ id: refId(result),
301
+ kind: "toRef",
302
+ createdAt: captureSourceLocation(),
303
+ createdByEffectId: globalContext?.meta?.effectId
304
+ });
305
+ return result;
306
+ }
307
+ export function toRefs(object) {
308
+ const result = vueToRefs(object);
309
+ for (const refValue of Object.values(result)) {
310
+ debug.effect.registerRef({
311
+ id: refId(refValue),
312
+ kind: "toRef",
313
+ createdAt: captureSourceLocation(),
314
+ createdByEffectId: globalContext?.meta?.effectId
315
+ });
316
+ }
317
+ return result;
318
+ }
147
319
  const seenRefs = new WeakMap();
148
320
  let refIdCounter = 1;
149
- export function refId(ref) {
321
+ let infraRefIdCounter = -1;
322
+ const effectIdMap = new WeakMap();
323
+ export function refId(ref, isInfrastructure) {
150
324
  let id = seenRefs.get(ref);
151
325
  if (id === undefined) {
152
- id = refIdCounter++;
326
+ id = isInfrastructure ? infraRefIdCounter-- : refIdCounter++;
153
327
  seenRefs.set(ref, id);
154
328
  }
155
329
  return id;
156
330
  }
331
+
332
+ /** Allocate a unique reactive target ID from the same counter space as ref IDs. */
333
+ export function nextReactiveId() {
334
+ return refIdCounter++;
335
+ }
336
+ export function resetRefIdCounter() {
337
+ refIdCounter = 1;
338
+ infraRefIdCounter = -1;
339
+ }
340
+ export function getEffectDebugId(effect) {
341
+ return effectIdMap.get(effect);
342
+ }
157
343
  //# sourceMappingURL=reactivity.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["isRef","pauseTracking","ref","resetTracking","shallowRef","stop","effect","vueEffect","scheduler","trace","TracePhase","globalThis","__ALLOY__","Error","getElementCache","getContext","elementCache","globalContext","root","fn","options","context","componentOwner","disposables","owner","Map","takesSymbols","takenSymbols","undefined","childrenWithContent","isEmpty","isRoot","ret","untrack","d","v","memo","equal","o","prev","res","value","current","cleanupFn","final","k","len","length","runner","onCleanup","oldContext","flags","onTrack","event","track","target","refId","String","key","onTrigger","trigger","push","CUSTOM_CONTEXT_SYM","Symbol","createCustomContext","useCallback","useCustomContext","useCb","isCustomContext","child","Object","hasOwn","seenRefs","WeakMap","refIdCounter","id","get","set"],"sources":["../../src/reactivity.ts"],"sourcesContent":[null],"mappings":"AAAA,SACEA,KAAK,EACLC,aAAa,EAEbC,GAAG,EAEHC,aAAa,EAEbC,UAAU,EACVC,IAAI,EACJC,MAAM,IAAIC,SAAS,QACd,iBAAiB;AAGxB,SAASC,SAAS,QAAQ,gBAAgB;AAE1C,SAASC,KAAK,EAAEC,UAAU,QAAQ,aAAa;;AAE/C;AACA,IAAKC,UAAU,CAASC,SAAS,EAAE;EACjC,MAAM,IAAIC,KAAK,CACb,sGACF,CA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,CAACE,KAAK,CAAC;IACpB;EACF,CAAC;AACH;AAEA,OAAO,SAASC,eAAeA,CAACC,KAAe,EAA0B;EACvE,OACE,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACdC,MAAM,CAACC,MAAM,CAACF,KAAK,EAAEP,kBAAkB,CAAC;AAE5C;AAEA,MAAMU,QAAQ,GAAG,IAAIC,OAAO,CAAuB,CAAC;AACpD,IAAIC,YAAY,GAAG,CAAC;AAEpB,OAAO,SAASlB,KAAKA,CAACtD,GAAiB,EAAU;EAC/C,IAAIyE,EAAE,GAAGH,QAAQ,CAACI,GAAG,CAAC1E,GAAG,CAAC;EAC1B,IAAIyE,EAAE,KAAK/C,SAAS,EAAE;IACpB+C,EAAE,GAAGD,YAAY,EAAE;IACnBF,QAAQ,CAACK,GAAG,CAAC3E,GAAG,EAAEyE,EAAE,CAAC;EACvB;EACA,OAAOA,EAAE;AACX","ignoreList":[]}
1
+ {"version":3,"names":["isRef","pauseTracking","resetTracking","stop","computed","vueComputed","effect","vueEffect","ref","vueRef","shallowReactive","vueShallowReactive","shallowRef","vueShallowRef","toRef","vueToRef","toRefs","vueToRefs","captureSourceLocation","debug","isDevtoolsEnabled","scheduler","globalThis","__ALLOY__","Error","getElementCache","ctx","getContext","elementCache","Map","contextIdCounter","globalContext","resolveOwnerEffectContextId","context","owner","meta","effectId","undefined","id","ensureIsEmpty","isEmpty","childrenWithContent","root","fn","options","componentOwner","takesSymbols","takenSymbols","_lastEmpty","isRoot","ret","untrack","d","disposables","v","findCurrentEffectId","memo","equal","name","o","prev","res","value","getter","Object","defineProperty","configurable","current","debugInfo","register","type","createdAt","contextId","ownerContextId","cleanupFn","final","k","len","length","runner","onCleanup","effectOpts","flags","onTrack","event","targetKey","key","toString","target","refId","ensureRef","kind","track","onTrigger","trigger","oldContext","effectIdMap","set","push","CUSTOM_CONTEXT_SYM","Symbol","createCustomContext","useCallback","useCustomContext","useCb","isCustomContext","child","hasOwn","result","registerRef","isInfrastructure","createdByEffectId","reactiveCreationLocations","WeakMap","getReactiveCreationLocation","get","object","defaultValue","refValue","values","seenRefs","refIdCounter","infraRefIdCounter","nextReactiveId","resetRefIdCounter","getEffectDebugId"],"sources":["../../src/reactivity.ts"],"sourcesContent":[null],"mappings":"AAAA,SACEA,KAAK,EACLC,aAAa,EAGbC,aAAa,EAEbC,IAAI,EACJC,QAAQ,IAAIC,WAAW,EACvBC,MAAM,IAAIC,SAAS,EACnBC,GAAG,IAAIC,MAAM,EACbC,eAAe,IAAIC,kBAAkB,EACrCC,UAAU,IAAIC,aAAa,EAC3BC,KAAK,IAAIC,QAAQ,EACjBC,MAAM,IAAIC,SAAS,QACd,iBAAiB;AACxB,SACEC,qBAAqB,EACrBC,KAAK,EACLC,iBAAiB,QACZ,kBAAkB;AAGzB,SAASC,SAAS,QAAQ,gBAAgB;AAG1C,IAAKC,UAAU,CAASC,SAAS,EAAE;EACjC,MAAM,IAAIC,KAAK,CACb,sGACF,CAAC;AACH;AACCF,UAAU,CAASC,SAAS,GAAG,IAAI;AAEpC,OAAO,SAASE,eAAeA,CAAA,EAAG;EAChC,MAAMC,GAAG,GAAGC,UAAU,CAAC,CAAE;EACzB,OAAQD,GAAG,CAACE,YAAY,KAAK,IAAIC,GAAG,CAAC,CAAC;AACxC;AAaA,IAAIC,gBAAgB,GAAG,CAAC;AA4DxB,IAAIC,aAA6B,GAAG,IAAI;AACxC,OAAO,SAASJ,UAAUA,CAAA,EAAG;EAC3B,OAAOI,aAAa;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,2BAA2BA,CAACC,OAAgB,EAAiB;EACpE,IAAIC,KAAK,GAAGD,OAAO,CAACC,KAAK;EACzB,OAAOA,KAAK,EAAE;IACZ,IAAIA,KAAK,CAACC,IAAI,EAAEC,QAAQ,KAAKC,SAAS,EAAE;MACtC,OAAOH,KAAK,CAACI,EAAE;IACjB;IACAJ,KAAK,GAAGA,KAAK,CAACA,KAAK;EACrB;E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EC;IAC1C,CAAC,CAAC;EACJ;EACA,OAAOwE,MAAM;AACf;AAEA,MAAMY,QAAQ,GAAG,IAAIP,OAAO,CAAuB,CAAC;AACpD,IAAIQ,YAAY,GAAG,CAAC;AACpB,IAAIC,iBAAiB,GAAG,CAAC,CAAC;AAC1B,MAAM1B,WAAW,GAAG,IAAIiB,OAAO,CAAiB,CAAC;AAEjD,OAAO,SAASxB,KAAKA,CAACjF,GAAiB,EAAEsG,gBAA0B,EAAU;EAC3E,IAAIxE,EAAE,GAAGkF,QAAQ,CAACL,GAAG,CAAC3G,GAAG,CAAC;EAC1B,IAAI8B,EAAE,KAAKD,SAAS,EAAE;IACpBC,EAAE,GAAGwE,gBAAgB,GAAGY,iBAAiB,EAAE,GAAGD,YAAY,EAAE;IAC5DD,QAAQ,CAACvB,GAAG,CAACzF,GAAG,EAAE8B,EAAE,CAAC;EACvB;EACA,OAAOA,EAAE;AACX;;AAEA;AACA,OAAO,SAASqF,cAAcA,CAAA,EAAW;EACvC,OAAOF,YAAY,EAAE;AACvB;AAEA,OAAO,SAASG,iBAAiBA,CAAA,EAAS;EACxCH,YAAY,GAAG,CAAC;EAChBC,iBAAiB,GAAG,CAAC,CAAC;AACxB;AAEA,OAAO,SAASG,gBAAgBA,CAACvH,MAAc,EAAsB;EACnE,OAAO0F,WAAW,CAACmB,GAAG,CAAC7G,MAAM,CAAC;AAChC","ignoreList":[]}
@@ -0,0 +1,30 @@
1
+ import { Context } from "./reactivity.js";
2
+ import { Component, Props, SourceLocation } from "./runtime/component.js";
3
+ export interface RenderStackSnapshotEntry {
4
+ component: Component<any>;
5
+ props: Props;
6
+ context: Context | null;
7
+ source?: SourceLocation;
8
+ displayName: string;
9
+ }
10
+ export declare function pushStack(component: Component<any>, props: Props, source?: SourceLocation): void;
11
+ export declare function popStack(): void;
12
+ export declare function currentComponentName(): string | undefined;
13
+ export declare function clearRenderStack(): void;
14
+ /**
15
+ * Get the current rendering path from the render stack context.
16
+ * Prefers SourceFileContext over SourceDirectoryContext.
17
+ */
18
+ export declare function getCurrentRenderPath(): string | undefined;
19
+ export declare function getRenderStackSnapshot(): RenderStackSnapshotEntry[];
20
+ /**
21
+ * Print the current render stack to the console for debugging.
22
+ *
23
+ * This differs from debug.component.stack in that this uses a purpose-built
24
+ * stack rather than walking the context chain. When this is called, the context
25
+ * chain has been restored. In the future this can probably be unified nicely.
26
+ *
27
+ * @param error - Optional error to print the stack trace from
28
+ */
29
+ export declare function printRenderStack(error?: unknown): void;
30
+ //# sourceMappingURL=render-stack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-stack.d.ts","sourceRoot":"","sources":["../../src/render-stack.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAc,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAU1E,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;IAC1B,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,SAAS,CACvB,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,EACzB,KAAK,EAAE,KAAK,EACZ,MAAM,CAAC,EAAE,cAAc,QAGxB;AAED,wBAAgB,QAAQ,SAEvB;AAED,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAGzD;AAED,wBAAgB,gBAAgB,SAE/B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAoBzD;AAED,wBAAgB,sBAAsB,IAAI,wBAAwB,EAAE,CAQnE;AA4DD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,EAAE,OAAO,QAkJ/C"}
@@ -0,0 +1,251 @@
1
+ import pc from "picocolors";
2
+ import { contextsByKey } from "./context.js";
3
+ import { SourceDirectoryContext } from "./context/source-directory.js";
4
+ import { SourceFileContext } from "./context/source-file.js";
5
+ import { getContext } from "./reactivity.js";
6
+ // Store render stack for error diagnostics
7
+ const renderStack = [];
8
+ export function pushStack(component, props, source) {
9
+ renderStack.push({
10
+ component,
11
+ props,
12
+ context: getContext(),
13
+ source
14
+ });
15
+ }
16
+ export function popStack() {
17
+ renderStack.pop();
18
+ }
19
+ export function currentComponentName() {
20
+ const entry = renderStack[renderStack.length - 1];
21
+ return entry?.component.name || undefined;
22
+ }
23
+ export function clearRenderStack() {
24
+ renderStack.length = 0;
25
+ }
26
+
27
+ /**
28
+ * Get the current rendering path from the render stack context.
29
+ * Prefers SourceFileContext over SourceDirectoryContext.
30
+ */
31
+ export function getCurrentRenderPath() {
32
+ let currentPath;
33
+ for (let i = renderStack.length - 1; i >= 0; i--) {
34
+ const {
35
+ context
36
+ } = renderStack[i];
37
+ // Prefer SourceFileContext over SourceDirectoryContext
38
+ if (context?.context?.[SourceFileContext.id]) {
39
+ const fileContext = context.context[SourceFileContext.id];
40
+ return fileContext.path;
41
+ }
42
+ if (!currentPath && context?.context?.[SourceDirectoryContext.id]) {
43
+ const dirContext = context.context[SourceDirectoryContext.id];
44
+ currentPath = dirContext.path;
45
+ // Don't break - keep looking for a SourceFileContext
46
+ }
47
+ }
48
+ return currentPath;
49
+ }
50
+ export function getRenderStackSnapshot() {
51
+ return renderStack.map(entry => ({
52
+ component: entry.component,
53
+ props: entry.props,
54
+ context: entry.context,
55
+ source: entry.source,
56
+ displayName: getComponentDisplayName(entry.component, entry.props)
57
+ }));
58
+ }
59
+
60
+ // Helper functions
61
+ function getComponentDisplayName(component, props) {
62
+ // Check if this is a Provider and if we can find its context name
63
+ if (component.name === "Provider") {
64
+ // Try to find the context this provider is associated with
65
+ for (const ctx of contextsByKey.values()) {
66
+ if (ctx.Provider === component && ctx.name) {
67
+ return ctx.name;
68
+ }
69
+ }
70
+ }
71
+ return component.name;
72
+ }
73
+ function inspectProps(props) {
74
+ const entries = Object.entries(props).filter(([key]) => key !== "children") // Exclude children prop
75
+ .map(([key, value]) => {
76
+ const formattedValue = formatValue(value);
77
+ return `${pc.dim(key)}: ${formattedValue}`;
78
+ });
79
+ return entries.length > 0 ? entries.join(pc.dim(", ")) : "";
80
+ }
81
+ function formatValue(value) {
82
+ switch (typeof value) {
83
+ case "string":
84
+ return pc.blue(`"${value}"`);
85
+ case "number":
86
+ case "boolean":
87
+ return pc.blue(String(value));
88
+ case "undefined":
89
+ return pc.gray("undefined");
90
+ case "object":
91
+ return value ? pc.gray("{...}") : pc.gray("null");
92
+ case "function":
93
+ return pc.gray("function");
94
+ default:
95
+ return pc.gray(String(value));
96
+ }
97
+ }
98
+ function formatSourceLocation(source) {
99
+ const cwd = process.cwd();
100
+ let filePath = source.fileName;
101
+
102
+ // Convert to relative path if under cwd
103
+ if (filePath.startsWith(cwd)) {
104
+ filePath = filePath.slice(cwd.length + 1); // +1 to remove leading slash
105
+ }
106
+ return `${filePath}:${source.lineNumber}:${source.columnNumber}`;
107
+ }
108
+
109
+ /**
110
+ * Print the current render stack to the console for debugging.
111
+ *
112
+ * This differs from debug.component.stack in that this uses a purpose-built
113
+ * stack rather than walking the context chain. When this is called, the context
114
+ * chain has been restored. In the future this can probably be unified nicely.
115
+ *
116
+ * @param error - Optional error to print the stack trace from
117
+ */
118
+ export function printRenderStack(error) {
119
+ // Find the nearest SourceFileContext or SourceDirectoryContext from the render stack
120
+ let currentPath;
121
+ for (let i = renderStack.length - 1; i >= 0; i--) {
122
+ const {
123
+ context
124
+ } = renderStack[i];
125
+ // Prefer SourceFileContext over SourceDirectoryContext
126
+ if (context?.context?.[SourceFileContext.id]) {
127
+ const fileContext = context.context[SourceFileContext.id];
128
+ currentPath = fileContext.path;
129
+ break;
130
+ }
131
+ if (!currentPath && context?.context?.[SourceDirectoryContext.id]) {
132
+ const dirContext = context.context[SourceDirectoryContext.id];
133
+ currentPath = dirContext.path;
134
+ // Don't break - keep looking for a SourceFileContext
135
+ }
136
+ }
137
+ if (currentPath) {
138
+ // eslint-disable-next-line no-console
139
+ console.error(pc.red(`Error rendering in file ${currentPath}`));
140
+ } else {
141
+ // eslint-disable-next-line no-console
142
+ console.error(pc.red("Error rendering:"));
143
+ }
144
+
145
+ // Print the error message and stack if provided
146
+ if (error) {
147
+ if (error instanceof Error) {
148
+ // eslint-disable-next-line no-console
149
+ console.error(pc.red(` ${error.message}`));
150
+ if (error.stack) {
151
+ // Print stack lines (skip the first line which is the error message)
152
+ const stackLines = error.stack.split("\n").slice(1);
153
+ for (const line of stackLines) {
154
+ // eslint-disable-next-line no-console
155
+ console.error(pc.gray(line));
156
+ }
157
+ }
158
+ } else {
159
+ // eslint-disable-next-line no-console
160
+ console.error(pc.red(` ${String(error)}`));
161
+ }
162
+ // eslint-disable-next-line no-console
163
+ console.error(); // Empty line before component stack
164
+ }
165
+
166
+ // First pass: determine which providers should be nested vs standalone
167
+ // A provider should be nested under its parent if it's from a different file
168
+ // (i.e., it's part of the component's implementation, not user-provided)
169
+ const nestedProviderIndices = new Set();
170
+ for (let i = renderStack.length - 1; i >= 0; i--) {
171
+ const {
172
+ component,
173
+ source
174
+ } = renderStack[i];
175
+
176
+ // Skip anonymous components and providers
177
+ if (!component.name || component.name === "Provider") {
178
+ continue;
179
+ }
180
+
181
+ // Look for providers that come immediately after this component
182
+ for (let j = i + 1; j < renderStack.length; j++) {
183
+ const providerEntry = renderStack[j];
184
+ if (!providerEntry.component.name) continue;
185
+ if (providerEntry.component.name !== "Provider") break;
186
+
187
+ // Nest provider if it's from a different file (component-internal)
188
+ const shouldNest = !source || !providerEntry.source || source.fileName !== providerEntry.source.fileName;
189
+ if (shouldNest) {
190
+ nestedProviderIndices.add(j);
191
+ } else {
192
+ // Stop looking - this provider and all after should be standalone
193
+ break;
194
+ }
195
+ }
196
+ }
197
+
198
+ // Second pass: print stack entries in order, nesting providers where appropriate
199
+ for (let i = renderStack.length - 1; i >= 0; i--) {
200
+ const {
201
+ component,
202
+ props,
203
+ source
204
+ } = renderStack[i];
205
+
206
+ // Skip anonymous components
207
+ if (!component.name) {
208
+ continue;
209
+ }
210
+
211
+ // Skip providers that will be nested under their parent
212
+ if (nestedProviderIndices.has(i)) {
213
+ continue;
214
+ }
215
+ const displayName = getComponentDisplayName(component, props);
216
+ const sourceStr = source ? pc.gray(` (${formatSourceLocation(source)})`) : "";
217
+
218
+ // eslint-disable-next-line no-console
219
+ console.error(` ${pc.cyan("at")} ${pc.bold(displayName)}${sourceStr}`);
220
+
221
+ // Print props on next line if there are any
222
+ const propsStr = inspectProps(props);
223
+ if (propsStr) {
224
+ // eslint-disable-next-line no-console
225
+ console.error(` ${propsStr}`);
226
+ }
227
+
228
+ // For non-Provider components, print any nested providers
229
+ if (component.name !== "Provider") {
230
+ for (let j = i + 1; j < renderStack.length; j++) {
231
+ if (!nestedProviderIndices.has(j)) break;
232
+ const providerEntry = renderStack[j];
233
+ if (!providerEntry.component.name) continue;
234
+ const providerName = getComponentDisplayName(providerEntry.component, providerEntry.props);
235
+ const providerSourceStr = providerEntry.source ? pc.gray(` (${formatSourceLocation(providerEntry.source)})`) : "";
236
+
237
+ // eslint-disable-next-line no-console
238
+ console.error(` ${pc.magenta("provides")} ${pc.bold(providerName)}${providerSourceStr}`);
239
+ const providerPropsStr = inspectProps(providerEntry.props);
240
+ if (providerPropsStr) {
241
+ // eslint-disable-next-line no-console
242
+ console.error(` ${providerPropsStr}`);
243
+ }
244
+ }
245
+ }
246
+ }
247
+
248
+ // Clear the stack after printing to avoid stale data on subsequent render errors
249
+ clearRenderStack();
250
+ }
251
+ //# sourceMappingURL=render-stack.js.map