@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.
- package/CHANGELOG.md +0 -22
- package/dist/devtools/index.html +68 -0
- package/dist/src/binder.d.ts +2 -0
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +55 -12
- package/dist/src/binder.js.map +1 -1
- package/dist/src/components/AccessExpression.d.ts +78 -0
- package/dist/src/components/AccessExpression.d.ts.map +1 -0
- package/dist/src/components/AccessExpression.js +218 -0
- package/dist/src/components/AccessExpression.js.map +1 -0
- package/dist/src/components/AccessExpression.test.d.ts +2 -0
- package/dist/src/components/AccessExpression.test.d.ts.map +1 -0
- package/dist/src/components/AccessExpression.test.js +137 -0
- package/dist/src/components/AccessExpression.test.js.map +1 -0
- package/dist/src/components/AppendFile.d.ts.map +1 -1
- package/dist/src/components/AppendFile.js +14 -3
- package/dist/src/components/AppendFile.js.map +1 -1
- package/dist/src/components/Block.js +1 -1
- package/dist/src/components/Block.js.map +1 -1
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +2 -1
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/Prose.js +2 -2
- package/dist/src/components/Prose.js.map +1 -1
- package/dist/src/components/Scope.d.ts.map +1 -1
- package/dist/src/components/Scope.js +6 -1
- package/dist/src/components/Scope.js.map +1 -1
- package/dist/src/components/SourceDirectory.d.ts.map +1 -1
- package/dist/src/components/SourceDirectory.js +1 -2
- package/dist/src/components/SourceDirectory.js.map +1 -1
- package/dist/src/components/TemplateFile.d.ts.map +1 -1
- package/dist/src/components/TemplateFile.js +18 -3
- package/dist/src/components/TemplateFile.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/content-slot.d.ts.map +1 -1
- package/dist/src/content-slot.js +7 -6
- package/dist/src/content-slot.js.map +1 -1
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +10 -3
- package/dist/src/context.js.map +1 -1
- package/dist/src/debug/cli.d.ts +6 -0
- package/dist/src/debug/cli.d.ts.map +1 -0
- package/dist/src/{debug.js → debug/cli.js} +78 -84
- package/dist/src/debug/cli.js.map +1 -0
- package/dist/src/debug/diagnostics.test.d.ts +2 -0
- package/dist/src/debug/diagnostics.test.d.ts.map +1 -0
- package/dist/src/debug/diagnostics.test.js +45 -0
- package/dist/src/debug/diagnostics.test.js.map +1 -0
- package/dist/src/debug/effects.d.ts +73 -0
- package/dist/src/debug/effects.d.ts.map +1 -0
- package/dist/src/debug/effects.js +228 -0
- package/dist/src/debug/effects.js.map +1 -0
- package/dist/src/debug/effects.test.d.ts +2 -0
- package/dist/src/debug/effects.test.d.ts.map +1 -0
- package/dist/src/debug/effects.test.js +84 -0
- package/dist/src/debug/effects.test.js.map +1 -0
- package/dist/src/debug/files.d.ts +14 -0
- package/dist/src/debug/files.d.ts.map +1 -0
- package/dist/src/debug/files.js +40 -0
- package/dist/src/debug/files.js.map +1 -0
- package/dist/src/debug/files.test.d.ts +2 -0
- package/dist/src/debug/files.test.d.ts.map +1 -0
- package/dist/src/debug/files.test.js +89 -0
- package/dist/src/debug/files.test.js.map +1 -0
- package/dist/src/debug/index.d.ts +61 -0
- package/dist/src/debug/index.d.ts.map +1 -0
- package/dist/src/debug/index.js +69 -0
- package/dist/src/debug/index.js.map +1 -0
- package/dist/src/debug/render.d.ts +57 -0
- package/dist/src/debug/render.d.ts.map +1 -0
- package/dist/src/debug/render.js +519 -0
- package/dist/src/debug/render.js.map +1 -0
- package/dist/src/debug/render.test.d.ts +2 -0
- package/dist/src/debug/render.test.d.ts.map +1 -0
- package/dist/src/debug/render.test.js +328 -0
- package/dist/src/debug/render.test.js.map +1 -0
- package/dist/src/debug/serialize.d.ts +9 -0
- package/dist/src/debug/serialize.d.ts.map +1 -0
- package/dist/src/debug/serialize.js +70 -0
- package/dist/src/debug/serialize.js.map +1 -0
- package/dist/src/debug/symbols.d.ts +15 -0
- package/dist/src/debug/symbols.d.ts.map +1 -0
- package/dist/src/debug/symbols.js +173 -0
- package/dist/src/debug/symbols.js.map +1 -0
- package/dist/src/debug/symbols.test.d.ts +2 -0
- package/dist/src/debug/symbols.test.d.ts.map +1 -0
- package/dist/src/debug/symbols.test.js +104 -0
- package/dist/src/debug/symbols.test.js.map +1 -0
- package/dist/src/debug/trace.d.ts +342 -0
- package/dist/src/debug/trace.d.ts.map +1 -0
- package/dist/src/debug/trace.js +443 -0
- package/dist/src/debug/trace.js.map +1 -0
- package/dist/src/devtools/devtools-protocol.d.ts +232 -0
- package/dist/src/devtools/devtools-protocol.d.ts.map +1 -0
- package/dist/src/devtools/devtools-protocol.js +2 -0
- package/dist/src/devtools/devtools-protocol.js.map +1 -0
- package/dist/src/devtools/devtools-server.browser.d.ts +28 -0
- package/dist/src/devtools/devtools-server.browser.d.ts.map +1 -0
- package/dist/src/devtools/devtools-server.browser.js +36 -0
- package/dist/src/devtools/devtools-server.browser.js.map +1 -0
- package/dist/src/devtools/devtools-server.d.ts +72 -0
- package/dist/src/devtools/devtools-server.d.ts.map +1 -0
- package/dist/src/devtools/devtools-server.js +256 -0
- package/dist/src/devtools/devtools-server.js.map +1 -0
- package/dist/src/devtools/devtools-transport.d.ts +23 -0
- package/dist/src/devtools/devtools-transport.d.ts.map +1 -0
- package/dist/src/devtools/devtools-transport.js +114 -0
- package/dist/src/devtools/devtools-transport.js.map +1 -0
- package/dist/src/devtools-entry.browser.d.ts +4 -0
- package/dist/src/devtools-entry.browser.d.ts.map +1 -0
- package/dist/src/devtools-entry.browser.js +2 -0
- package/dist/src/devtools-entry.browser.js.map +1 -0
- package/dist/src/devtools-entry.d.ts +4 -0
- package/dist/src/devtools-entry.d.ts.map +1 -0
- package/dist/src/devtools-entry.js +2 -0
- package/dist/src/devtools-entry.js.map +1 -0
- package/dist/src/diagnostics.d.ts +34 -0
- package/dist/src/diagnostics.d.ts.map +1 -0
- package/dist/src/diagnostics.js +89 -0
- package/dist/src/diagnostics.js.map +1 -0
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/print-hook.d.ts +14 -0
- package/dist/src/print-hook.d.ts.map +1 -0
- package/dist/src/print-hook.js +10 -0
- package/dist/src/print-hook.js.map +1 -0
- package/dist/src/reactive-union-set.d.ts.map +1 -1
- package/dist/src/reactive-union-set.js +28 -3
- package/dist/src/reactive-union-set.js.map +1 -1
- package/dist/src/reactivity.d.ts +50 -8
- package/dist/src/reactivity.d.ts.map +1 -1
- package/dist/src/reactivity.js +225 -39
- package/dist/src/reactivity.js.map +1 -1
- package/dist/src/render-stack.d.ts +30 -0
- package/dist/src/render-stack.d.ts.map +1 -0
- package/dist/src/render-stack.js +251 -0
- package/dist/src/render-stack.js.map +1 -0
- package/dist/src/render.d.ts +9 -19
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +371 -159
- package/dist/src/render.js.map +1 -1
- package/dist/src/resource.d.ts.map +1 -1
- package/dist/src/resource.js +5 -0
- package/dist/src/resource.js.map +1 -1
- package/dist/src/runtime/component.d.ts +7 -1
- package/dist/src/runtime/component.d.ts.map +1 -1
- package/dist/src/runtime/component.js +4 -1
- package/dist/src/runtime/component.js.map +1 -1
- package/dist/src/scheduler.d.ts +8 -0
- package/dist/src/scheduler.d.ts.map +1 -1
- package/dist/src/scheduler.js +69 -3
- package/dist/src/scheduler.js.map +1 -1
- package/dist/src/symbols/basic-symbol.d.ts.map +1 -1
- package/dist/src/symbols/basic-symbol.js +6 -1
- package/dist/src/symbols/basic-symbol.js.map +1 -1
- package/dist/src/symbols/decl.d.ts.map +1 -1
- package/dist/src/symbols/decl.js +5 -1
- package/dist/src/symbols/decl.js.map +1 -1
- package/dist/src/symbols/output-scope.d.ts +2 -1
- package/dist/src/symbols/output-scope.d.ts.map +1 -1
- package/dist/src/symbols/output-scope.js +13 -8
- package/dist/src/symbols/output-scope.js.map +1 -1
- package/dist/src/symbols/output-symbol.d.ts +1 -0
- package/dist/src/symbols/output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/output-symbol.js +25 -8
- package/dist/src/symbols/output-symbol.js.map +1 -1
- package/dist/src/symbols/symbol-flow.d.ts.map +1 -1
- package/dist/src/symbols/symbol-flow.js +24 -8
- package/dist/src/symbols/symbol-flow.js.map +1 -1
- package/dist/src/symbols/symbol-slot.d.ts.map +1 -1
- package/dist/src/symbols/symbol-slot.js +15 -0
- package/dist/src/symbols/symbol-slot.js.map +1 -1
- package/dist/src/symbols/symbol-slot.test.d.ts +2 -0
- package/dist/src/symbols/symbol-slot.test.d.ts.map +1 -0
- package/dist/src/symbols/symbol-slot.test.js +35 -0
- package/dist/src/symbols/symbol-slot.test.js.map +1 -0
- package/dist/src/symbols/symbol-table.d.ts.map +1 -1
- package/dist/src/symbols/symbol-table.js +6 -5
- package/dist/src/symbols/symbol-table.js.map +1 -1
- package/dist/src/trace.d.ts +2 -0
- package/dist/src/trace.d.ts.map +1 -0
- package/dist/src/trace.js +2 -0
- package/dist/src/trace.js.map +1 -0
- package/dist/src/tracer.d.ts +2 -228
- package/dist/src/tracer.d.ts.map +1 -1
- package/dist/src/tracer.js +5 -298
- package/dist/src/tracer.js.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +7 -5
- package/dist/src/utils.js.map +1 -1
- package/dist/test/components/append-file.test.d.ts.map +1 -1
- package/dist/test/components/append-file.test.js +18 -10
- package/dist/test/components/append-file.test.js.map +1 -1
- package/dist/test/components/template-file.test.d.ts.map +1 -1
- package/dist/test/components/template-file.test.js +6 -4
- package/dist/test/components/template-file.test.js.map +1 -1
- package/dist/test/lazy-isempty.test.d.ts +2 -0
- package/dist/test/lazy-isempty.test.d.ts.map +1 -0
- package/dist/test/lazy-isempty.test.js +89 -0
- package/dist/test/lazy-isempty.test.js.map +1 -0
- package/dist/test/reactive-union-set-disposers.test.d.ts +2 -0
- package/dist/test/reactive-union-set-disposers.test.d.ts.map +1 -0
- package/dist/test/reactive-union-set-disposers.test.js +98 -0
- package/dist/test/reactive-union-set-disposers.test.js.map +1 -0
- package/dist/test/reactivity/shallow-reactive.test.d.ts +2 -0
- package/dist/test/reactivity/shallow-reactive.test.d.ts.map +1 -0
- package/dist/test/reactivity/shallow-reactive.test.js +52 -0
- package/dist/test/reactivity/shallow-reactive.test.js.map +1 -0
- package/dist/test/rendering/basic.test.js +3 -0
- package/dist/test/rendering/basic.test.js.map +1 -1
- package/dist/test/rendering/print-render-stack.test.d.ts +2 -0
- package/dist/test/rendering/print-render-stack.test.d.ts.map +1 -0
- package/dist/test/rendering/print-render-stack.test.js +207 -0
- package/dist/test/rendering/print-render-stack.test.js.map +1 -0
- package/dist/test/scheduler-extended.test.d.ts +2 -0
- package/dist/test/scheduler-extended.test.d.ts.map +1 -0
- package/dist/test/scheduler-extended.test.js +96 -0
- package/dist/test/scheduler-extended.test.js.map +1 -0
- package/dist/test/scheduler.test.d.ts +2 -0
- package/dist/test/scheduler.test.d.ts.map +1 -0
- package/dist/test/scheduler.test.js +46 -0
- package/dist/test/scheduler.test.js.map +1 -0
- package/dist/testing/create-test-wrapper.d.ts +1 -1
- package/dist/testing/create-test-wrapper.d.ts.map +1 -1
- package/dist/testing/create-test-wrapper.js +1 -1
- package/dist/testing/create-test-wrapper.js.map +1 -1
- package/dist/testing/devtools-utils.d.ts +26 -0
- package/dist/testing/devtools-utils.d.ts.map +1 -0
- package/dist/testing/devtools-utils.js +140 -0
- package/dist/testing/devtools-utils.js.map +1 -0
- package/dist/testing/extend-expect.d.ts.map +1 -1
- package/dist/testing/extend-expect.js +63 -1
- package/dist/testing/extend-expect.js.map +1 -1
- package/dist/testing/render.d.ts +2 -2
- package/dist/testing/render.d.ts.map +1 -1
- package/dist/testing/render.js +2 -2
- package/dist/testing/render.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -7
- package/scripts/copy-devtools-ui.mjs +26 -0
- package/src/binder.ts +71 -16
- package/src/components/AccessExpression.test.tsx +132 -0
- package/src/components/AccessExpression.tsx +344 -0
- package/src/components/AppendFile.tsx +14 -9
- package/src/components/Block.tsx +1 -1
- package/src/components/Declaration.tsx +2 -1
- package/src/components/Prose.tsx +1 -1
- package/src/components/Scope.tsx +6 -1
- package/src/components/SourceDirectory.tsx +1 -2
- package/src/components/TemplateFile.tsx +18 -9
- package/src/components/index.tsx +1 -0
- package/src/content-slot.tsx +7 -7
- package/src/context.ts +17 -6
- package/src/{debug.ts → debug/cli.ts} +112 -127
- package/src/debug/diagnostics.test.tsx +55 -0
- package/src/debug/effects.test.tsx +89 -0
- package/src/debug/effects.ts +317 -0
- package/src/debug/files.test.tsx +96 -0
- package/src/debug/files.ts +40 -0
- package/src/debug/index.ts +128 -0
- package/src/debug/render.test.tsx +379 -0
- package/src/debug/render.ts +639 -0
- package/src/debug/serialize.ts +85 -0
- package/src/debug/symbols.test.tsx +106 -0
- package/src/debug/symbols.ts +239 -0
- package/src/debug/trace.ts +312 -0
- package/src/devtools/devtools-protocol.ts +312 -0
- package/src/devtools/devtools-server.browser.ts +71 -0
- package/src/devtools/devtools-server.ts +290 -0
- package/src/devtools/devtools-transport.ts +154 -0
- package/src/devtools-entry.browser.ts +52 -0
- package/src/devtools-entry.ts +54 -0
- package/src/diagnostics.ts +141 -0
- package/src/index.ts +2 -7
- package/src/print-hook.ts +22 -0
- package/src/reactive-union-set.ts +85 -44
- package/src/reactivity.ts +301 -59
- package/src/render-stack.ts +294 -0
- package/src/render.ts +470 -216
- package/src/resource.ts +28 -19
- package/src/runtime/component.ts +11 -0
- package/src/scheduler.ts +80 -4
- package/src/symbols/basic-symbol.ts +6 -1
- package/src/symbols/decl.ts +5 -1
- package/src/symbols/output-scope.ts +21 -13
- package/src/symbols/output-symbol.ts +34 -14
- package/src/symbols/symbol-flow.ts +76 -39
- package/src/symbols/symbol-slot.test.tsx +41 -0
- package/src/symbols/symbol-slot.tsx +47 -20
- package/src/symbols/symbol-table.ts +6 -10
- package/src/trace.ts +1 -0
- package/src/tracer.ts +13 -242
- package/src/utils.tsx +24 -17
- package/temp/api.json +4187 -1603
- package/test/components/append-file.test.tsx +36 -29
- package/test/components/template-file.test.tsx +11 -11
- package/test/lazy-isempty.test.tsx +106 -0
- package/test/reactive-union-set-disposers.test.tsx +112 -0
- package/test/reactivity/shallow-reactive.test.tsx +56 -0
- package/test/rendering/basic.test.tsx +4 -0
- package/test/rendering/print-render-stack.test.tsx +244 -0
- package/test/scheduler-extended.test.tsx +122 -0
- package/test/scheduler.test.tsx +50 -0
- package/testing/create-test-wrapper.tsx +1 -1
- package/testing/devtools-utils.ts +203 -0
- package/testing/extend-expect.ts +89 -0
- package/testing/render.ts +2 -2
- package/testing/vitest.d.ts +9 -0
- package/dist/src/debug.d.ts +0 -15
- package/dist/src/debug.d.ts.map +0 -1
- package/dist/src/debug.js.map +0 -1
package/dist/src/render.js
CHANGED
|
@@ -1,15 +1,93 @@
|
|
|
1
|
-
import { isRef
|
|
1
|
+
import { isRef } from "@vue/reactivity";
|
|
2
2
|
import { doc } from "prettier";
|
|
3
3
|
import prettier from "prettier/doc.js";
|
|
4
4
|
import { useContext } from "./context.js";
|
|
5
5
|
import { SourceFileContext } from "./context/source-file.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { debug, getRenderNodeId, isDevtoolsEnabled } from "./debug/index.js";
|
|
7
|
+
import { broadcastDevtoolsMessage } from "./devtools/devtools-server.js";
|
|
8
|
+
import { attachDiagnosticsCollector, DiagnosticsCollector, emitDiagnostic, reportDiagnostics } from "./diagnostics.js";
|
|
9
|
+
import { isPrintHook, printHookTag } from "./print-hook.js";
|
|
10
|
+
import { effect, getContext, getElementCache, isCustomContext, onCleanup, ref, root, untrack } from "./reactivity.js";
|
|
8
11
|
import { isRefkeyable, toRefkey } from "./refkey.js";
|
|
12
|
+
import { getRenderStackSnapshot, popStack, printRenderStack, pushStack } from "./render-stack.js";
|
|
9
13
|
import { isComponentCreator, isRenderableObject, RENDERABLE } from "./runtime/component.js";
|
|
10
14
|
import { isIntrinsicElement } from "./runtime/intrinsic.js";
|
|
11
|
-
import { flushJobs, flushJobsAsync } from "./scheduler.js";
|
|
12
|
-
|
|
15
|
+
import { flushJobs, flushJobsAsync, waitForSignal } from "./scheduler.js";
|
|
16
|
+
const notifiedErrors = new WeakSet();
|
|
17
|
+
let lastRenderError = null;
|
|
18
|
+
function normalizeRenderError(error) {
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
return {
|
|
21
|
+
name: error.name || error.constructor?.name || "Error",
|
|
22
|
+
message: error.message || "",
|
|
23
|
+
stack: error.stack
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (error && typeof error === "object") {
|
|
27
|
+
const anyError = error;
|
|
28
|
+
return {
|
|
29
|
+
name: anyError.name || "Error",
|
|
30
|
+
message: anyError.message || String(error),
|
|
31
|
+
stack: anyError.stack
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
name: "Error",
|
|
36
|
+
message: String(error)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function notifyRenderError(error) {
|
|
40
|
+
if (error && typeof error === "object") {
|
|
41
|
+
if (notifiedErrors.has(error)) return;
|
|
42
|
+
notifiedErrors.add(error);
|
|
43
|
+
}
|
|
44
|
+
if (lastRenderError) return;
|
|
45
|
+
const {
|
|
46
|
+
name,
|
|
47
|
+
message,
|
|
48
|
+
stack
|
|
49
|
+
} = normalizeRenderError(error);
|
|
50
|
+
const componentStack = getRenderStackSnapshot().map(entry => {
|
|
51
|
+
const renderNode = entry.context?.meta?.renderNode;
|
|
52
|
+
const renderNodeId = renderNode ? getRenderNodeId(renderNode) : undefined;
|
|
53
|
+
return {
|
|
54
|
+
name: entry.displayName,
|
|
55
|
+
props: entry.props,
|
|
56
|
+
renderNodeId,
|
|
57
|
+
source: entry.source
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Output to console
|
|
62
|
+
printRenderStack(error);
|
|
63
|
+
|
|
64
|
+
// Send to devtools if enabled
|
|
65
|
+
debug.render.error({
|
|
66
|
+
name,
|
|
67
|
+
message,
|
|
68
|
+
stack
|
|
69
|
+
}, componentStack);
|
|
70
|
+
|
|
71
|
+
// Store for diagnostics
|
|
72
|
+
lastRenderError = {
|
|
73
|
+
error: {
|
|
74
|
+
name,
|
|
75
|
+
message,
|
|
76
|
+
stack
|
|
77
|
+
},
|
|
78
|
+
componentStack
|
|
79
|
+
};
|
|
80
|
+
const lastEntry = componentStack.at(-1);
|
|
81
|
+
emitDiagnostic({
|
|
82
|
+
severity: "error",
|
|
83
|
+
message: `${name}: ${message}`,
|
|
84
|
+
source: lastEntry?.source
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function reportLastRenderError() {
|
|
88
|
+
// Error already reported in notifyRenderError via debug.renderError
|
|
89
|
+
lastRenderError = null;
|
|
90
|
+
}
|
|
13
91
|
const {
|
|
14
92
|
builders: {
|
|
15
93
|
align,
|
|
@@ -112,10 +190,27 @@ const {
|
|
|
112
190
|
*/
|
|
113
191
|
|
|
114
192
|
const nodesToContext = new WeakMap();
|
|
193
|
+
const diagnosticsByTree = new WeakMap();
|
|
115
194
|
export function getContextForRenderNode(node) {
|
|
116
195
|
return nodesToContext.get(node);
|
|
117
196
|
}
|
|
118
|
-
export
|
|
197
|
+
export function getDiagnosticsForTree(tree) {
|
|
198
|
+
return diagnosticsByTree.get(tree)?.getDiagnostics() ?? [];
|
|
199
|
+
}
|
|
200
|
+
function reportDiagnosticsForTree(tree) {
|
|
201
|
+
const diagnostics = diagnosticsByTree.get(tree);
|
|
202
|
+
if (!diagnostics) return;
|
|
203
|
+
const entries = diagnostics.getDiagnostics();
|
|
204
|
+
if (entries.length === 0) return;
|
|
205
|
+
reportDiagnostics(diagnostics);
|
|
206
|
+
void broadcastDevtoolsMessage({
|
|
207
|
+
type: "diagnostics:report",
|
|
208
|
+
diagnostics: entries
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Re-export from print-hook.ts to maintain backwards compatibility
|
|
213
|
+
export { isPrintHook, printHookTag } from "./print-hook.js";
|
|
119
214
|
export function createRenderTreeHook(subtree, hooks) {
|
|
120
215
|
return {
|
|
121
216
|
[printHookTag]: true,
|
|
@@ -123,9 +218,7 @@ export function createRenderTreeHook(subtree, hooks) {
|
|
|
123
218
|
...hooks
|
|
124
219
|
};
|
|
125
220
|
}
|
|
126
|
-
|
|
127
|
-
return typeof type === "object" && type !== null && printHookTag in type;
|
|
128
|
-
}
|
|
221
|
+
|
|
129
222
|
/**
|
|
130
223
|
* Render a component tree to source directories and files. Will ensure that
|
|
131
224
|
* all non-async scheduled jobs are completed before returning. If async jobs
|
|
@@ -135,7 +228,14 @@ export function isPrintHook(type) {
|
|
|
135
228
|
export function render(children, options) {
|
|
136
229
|
const tree = renderTree(children);
|
|
137
230
|
flushJobs();
|
|
138
|
-
|
|
231
|
+
const output = sourceFilesForTree(tree, options);
|
|
232
|
+
reportDiagnosticsForTree(tree);
|
|
233
|
+
reportLastRenderError();
|
|
234
|
+
debug.render.complete();
|
|
235
|
+
if (isDevtoolsEnabled()) {
|
|
236
|
+
void waitForSignal();
|
|
237
|
+
}
|
|
238
|
+
return output;
|
|
139
239
|
}
|
|
140
240
|
|
|
141
241
|
/**
|
|
@@ -143,20 +243,15 @@ export function render(children, options) {
|
|
|
143
243
|
* scheduled jobs are completed before returning.
|
|
144
244
|
*/
|
|
145
245
|
export async function renderAsync(children, options) {
|
|
246
|
+
await debug.prepare();
|
|
146
247
|
const tree = renderTree(children);
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Convert a rendered text tree to source directories and files. Will ensure that
|
|
152
|
-
* all scheduled jobs are completed, including async ones.
|
|
153
|
-
*/
|
|
154
|
-
export async function sourceFilesForTreeAsync(tree, options) {
|
|
155
|
-
// if we await here, we ensure all reactive updates are flushed.
|
|
156
|
-
// sourceFilesForTree will flush again, but won't find anything, because tree
|
|
157
|
-
// printing won't schedule anything.
|
|
248
|
+
// Ensure all reactive updates are flushed before printing.
|
|
158
249
|
await flushJobsAsync();
|
|
159
|
-
|
|
250
|
+
const output = sourceFilesForTree(tree, options);
|
|
251
|
+
reportDiagnosticsForTree(tree);
|
|
252
|
+
reportLastRenderError();
|
|
253
|
+
debug.render.complete();
|
|
254
|
+
return output;
|
|
160
255
|
}
|
|
161
256
|
|
|
162
257
|
/**
|
|
@@ -167,7 +262,15 @@ export function sourceFilesForTree(tree, options) {
|
|
|
167
262
|
let rootDirectory = undefined;
|
|
168
263
|
collectSourceFiles(undefined, tree);
|
|
169
264
|
if (!rootDirectory) {
|
|
170
|
-
|
|
265
|
+
emitDiagnostic({
|
|
266
|
+
severity: "error",
|
|
267
|
+
message: "No root directory found. Make sure you are using the output component."
|
|
268
|
+
});
|
|
269
|
+
return {
|
|
270
|
+
kind: "directory",
|
|
271
|
+
path: "",
|
|
272
|
+
contents: []
|
|
273
|
+
};
|
|
171
274
|
}
|
|
172
275
|
return rootDirectory;
|
|
173
276
|
function collectSourceFiles(currentDirectory, root) {
|
|
@@ -230,27 +333,37 @@ export function sourceFilesForTree(tree, options) {
|
|
|
230
333
|
}
|
|
231
334
|
export function renderTree(children) {
|
|
232
335
|
const rootElem = [];
|
|
336
|
+
const diagnostics = new DiagnosticsCollector();
|
|
337
|
+
lastRenderError = null;
|
|
338
|
+
debug.effect.reset();
|
|
339
|
+
debug.symbols.reset();
|
|
340
|
+
debug.files.reset();
|
|
341
|
+
debug.render.initialize(rootElem);
|
|
233
342
|
try {
|
|
234
343
|
root(() => {
|
|
344
|
+
attachDiagnosticsCollector(diagnostics);
|
|
235
345
|
renderWorker(rootElem, children);
|
|
236
346
|
});
|
|
237
347
|
} catch (e) {
|
|
238
|
-
|
|
348
|
+
notifyRenderError(e);
|
|
349
|
+
reportLastRenderError();
|
|
239
350
|
throw e;
|
|
240
351
|
}
|
|
352
|
+
diagnosticsByTree.set(rootElem, diagnostics);
|
|
241
353
|
return rootElem;
|
|
242
354
|
}
|
|
243
355
|
function renderWorker(node, children) {
|
|
356
|
+
if (lastRenderError) return;
|
|
244
357
|
if (!getContext()) {
|
|
245
358
|
throw new Error("Cannot render without a context. Make sure you are using the Output component.");
|
|
246
359
|
}
|
|
247
|
-
trace(TracePhase.render.worker, () => dumpChildren(children));
|
|
248
360
|
if (Array.isArray(node)) {
|
|
249
361
|
nodesToContext.set(node, getContext());
|
|
250
362
|
}
|
|
251
363
|
if (Array.isArray(children)) {
|
|
252
364
|
for (const child of children.flat(Infinity)) {
|
|
253
365
|
appendChild(node, child);
|
|
366
|
+
if (lastRenderError) break;
|
|
254
367
|
}
|
|
255
368
|
} else {
|
|
256
369
|
appendChild(node, children);
|
|
@@ -264,10 +377,11 @@ export function notifyContentState() {
|
|
|
264
377
|
untrack(() => {
|
|
265
378
|
const startContext = getContext();
|
|
266
379
|
if (startContext.childrenWithContent === 0) {
|
|
267
|
-
if (startContext.
|
|
380
|
+
if (startContext._lastEmpty) {
|
|
268
381
|
// it was already empty, no work to do.
|
|
269
382
|
return;
|
|
270
383
|
}
|
|
384
|
+
startContext._lastEmpty = true;
|
|
271
385
|
if (startContext.isEmpty) {
|
|
272
386
|
startContext.isEmpty.value = true;
|
|
273
387
|
}
|
|
@@ -279,17 +393,23 @@ export function notifyContentState() {
|
|
|
279
393
|
break;
|
|
280
394
|
}
|
|
281
395
|
current.childrenWithContent--;
|
|
396
|
+
if (current.childrenWithContent > 0) {
|
|
397
|
+
// This isn't the last content so we have no work to do
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
current._lastEmpty = true;
|
|
282
401
|
if (current.isEmpty) {
|
|
283
402
|
current.isEmpty.value = true;
|
|
284
403
|
}
|
|
285
404
|
current = current.owner;
|
|
286
405
|
}
|
|
287
406
|
} else {
|
|
288
|
-
if (startContext.
|
|
407
|
+
if (!startContext._lastEmpty) {
|
|
289
408
|
// it was already non-empty, no work to do.
|
|
290
409
|
return;
|
|
291
410
|
}
|
|
292
|
-
|
|
411
|
+
startContext._lastEmpty = false;
|
|
412
|
+
if (startContext.isEmpty) {
|
|
293
413
|
startContext.isEmpty.value = false;
|
|
294
414
|
}
|
|
295
415
|
|
|
@@ -301,7 +421,8 @@ export function notifyContentState() {
|
|
|
301
421
|
// This isn't the first content so we have no work to do
|
|
302
422
|
break;
|
|
303
423
|
}
|
|
304
|
-
|
|
424
|
+
current._lastEmpty = false;
|
|
425
|
+
if (current.isEmpty) {
|
|
305
426
|
current.isEmpty.value = false;
|
|
306
427
|
}
|
|
307
428
|
current = current.owner;
|
|
@@ -310,74 +431,98 @@ export function notifyContentState() {
|
|
|
310
431
|
});
|
|
311
432
|
}
|
|
312
433
|
function appendChild(node, rawChild) {
|
|
313
|
-
|
|
434
|
+
if (lastRenderError) return;
|
|
314
435
|
const child = normalizeChild(rawChild);
|
|
315
436
|
if (typeof child === "string") {
|
|
316
437
|
if (child !== "") {
|
|
317
438
|
contentAdded();
|
|
439
|
+
debug.render.appendTextNode(node, node.length, child);
|
|
318
440
|
}
|
|
319
441
|
node.push(child);
|
|
320
442
|
} else {
|
|
321
443
|
const cache = getElementCache();
|
|
322
444
|
if (cache.has(child)) {
|
|
323
|
-
|
|
324
|
-
|
|
445
|
+
const cachedNode = cache.get(child);
|
|
446
|
+
// recordSubtreeAdded detects cached nodes automatically and re-adds their children
|
|
447
|
+
if (isCustomContext(child)) {
|
|
448
|
+
debug.render.appendCustomContext(node, cachedNode);
|
|
449
|
+
} else {
|
|
450
|
+
debug.render.appendFragmentChild(node, cachedNode);
|
|
451
|
+
}
|
|
452
|
+
node.push(cachedNode);
|
|
325
453
|
return;
|
|
326
454
|
}
|
|
327
455
|
if (isCustomContext(child)) {
|
|
328
|
-
|
|
456
|
+
const newNode = [];
|
|
457
|
+
debug.render.appendCustomContext(node, newNode);
|
|
329
458
|
child.useCustomContext(children => {
|
|
330
|
-
const newNode = [];
|
|
331
459
|
renderWorker(newNode, children);
|
|
332
460
|
node.push(newNode);
|
|
333
461
|
cache.set(child, newNode);
|
|
334
462
|
notifyContentState();
|
|
463
|
+
notifyFileUpdateForNode(node);
|
|
335
464
|
});
|
|
336
465
|
} else if (isIntrinsicElement(child)) {
|
|
337
|
-
trace(TracePhase.render.appendChild, () => "IntrinsicElement: " + debugPrintChild(child));
|
|
338
466
|
// don't need a new context here because intrinsics are never reactive
|
|
467
|
+
const intrinsic = child;
|
|
339
468
|
const newNode = [];
|
|
340
469
|
function formatHookWithChildren(command) {
|
|
341
|
-
|
|
470
|
+
const hook = createRenderTreeHook(newNode, {
|
|
342
471
|
print(tree, print) {
|
|
343
472
|
return command(print(tree));
|
|
344
473
|
}
|
|
345
|
-
})
|
|
474
|
+
});
|
|
475
|
+
debug.render.appendPrintHook(node, node.length, hook, intrinsic.name, newNode);
|
|
476
|
+
node.push(hook);
|
|
346
477
|
renderWorker(newNode, child.props.children);
|
|
478
|
+
notifyFileUpdateForNode(node);
|
|
347
479
|
}
|
|
348
480
|
function formatHook(command) {
|
|
349
|
-
|
|
481
|
+
const hook = createRenderTreeHook(newNode, {
|
|
350
482
|
print() {
|
|
351
483
|
return command;
|
|
352
484
|
}
|
|
353
|
-
})
|
|
485
|
+
});
|
|
486
|
+
debug.render.appendPrintHook(node, node.length, hook, intrinsic.name);
|
|
487
|
+
node.push(hook);
|
|
488
|
+
return hook;
|
|
354
489
|
}
|
|
355
490
|
switch (child.name) {
|
|
356
491
|
case "indent":
|
|
357
492
|
return formatHookWithChildren(indent);
|
|
358
493
|
case "indentIfBreak":
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
494
|
+
{
|
|
495
|
+
const hook = createRenderTreeHook(newNode, {
|
|
496
|
+
print(tree, print) {
|
|
497
|
+
return indentIfBreak(print(tree), {
|
|
498
|
+
groupId: child.props.groupId,
|
|
499
|
+
negate: child.props.negate
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
debug.render.appendPrintHook(node, node.length, hook, intrinsic.name, newNode);
|
|
504
|
+
node.push(hook);
|
|
505
|
+
}
|
|
367
506
|
renderWorker(newNode, child.props.children);
|
|
507
|
+
notifyFileUpdateForNode(node);
|
|
368
508
|
return;
|
|
369
509
|
case "fill":
|
|
370
510
|
return formatHookWithChildren(fill);
|
|
371
511
|
case "group":
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
512
|
+
{
|
|
513
|
+
const hook = createRenderTreeHook(newNode, {
|
|
514
|
+
print(tree, print) {
|
|
515
|
+
return group(print(tree), {
|
|
516
|
+
id: child.props.id,
|
|
517
|
+
shouldBreak: child.props.shouldBreak
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
debug.render.appendPrintHook(node, node.length, hook, intrinsic.name, newNode);
|
|
522
|
+
node.push(hook);
|
|
523
|
+
}
|
|
380
524
|
renderWorker(newNode, child.props.children);
|
|
525
|
+
notifyFileUpdateForNode(node);
|
|
381
526
|
return;
|
|
382
527
|
case "line":
|
|
383
528
|
case "br":
|
|
@@ -392,12 +537,17 @@ function appendChild(node, rawChild) {
|
|
|
392
537
|
case "lbr":
|
|
393
538
|
return formatHook(literalline);
|
|
394
539
|
case "align":
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
540
|
+
{
|
|
541
|
+
const hook = createRenderTreeHook(newNode, {
|
|
542
|
+
print(tree, print) {
|
|
543
|
+
return align(child.props.width ?? child.props.string, print(tree));
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
debug.render.appendPrintHook(node, node.length, hook, intrinsic.name, newNode);
|
|
547
|
+
node.push(hook);
|
|
548
|
+
}
|
|
400
549
|
renderWorker(newNode, child.props.children);
|
|
550
|
+
notifyFileUpdateForNode(node);
|
|
401
551
|
return;
|
|
402
552
|
case "lineSuffix":
|
|
403
553
|
return formatHookWithChildren(lineSuffix);
|
|
@@ -412,59 +562,192 @@ function appendChild(node, rawChild) {
|
|
|
412
562
|
case "markAsRoot":
|
|
413
563
|
return formatHookWithChildren(markAsRoot);
|
|
414
564
|
case "ifBreak":
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
565
|
+
{
|
|
566
|
+
const hook = createRenderTreeHook(newNode, {
|
|
567
|
+
print(tree, print) {
|
|
568
|
+
return ifBreak(print(tree[0]), print(tree[1]));
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
debug.render.appendPrintHook(node, node.length, hook, intrinsic.name, newNode);
|
|
572
|
+
node.push(hook);
|
|
573
|
+
}
|
|
420
574
|
newNode.push([], []);
|
|
575
|
+
debug.render.appendFragmentChild(newNode, newNode[0]);
|
|
576
|
+
debug.render.appendFragmentChild(newNode, newNode[1]);
|
|
421
577
|
renderWorker(newNode[0], child.props.children);
|
|
422
578
|
renderWorker(newNode[1], child.props.flatContents);
|
|
579
|
+
notifyFileUpdateForNode(node);
|
|
423
580
|
return;
|
|
424
581
|
default:
|
|
425
582
|
throw new Error("Unknown intrinsic element");
|
|
426
583
|
}
|
|
427
584
|
} else if (isComponentCreator(child)) {
|
|
585
|
+
const index = node.length;
|
|
586
|
+
const rerenderToken = isDevtoolsEnabled() ? ref(0) : undefined;
|
|
587
|
+
const breakNext = isDevtoolsEnabled() ? ref(false) : undefined;
|
|
428
588
|
// todo: remove this effect (only needed for context, not needed for anything else)
|
|
429
589
|
effect(() => {
|
|
430
|
-
|
|
590
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
591
|
+
rerenderToken?.value;
|
|
431
592
|
const context = getContext();
|
|
432
593
|
context.childrenWithContent = 0;
|
|
433
|
-
context.isEmpty ??= ref(true);
|
|
434
594
|
if (context) context.componentOwner = child;
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
595
|
+
const existing = node[index];
|
|
596
|
+
const componentRoot = Array.isArray(existing) ? existing : [];
|
|
597
|
+
context.meta ??= {};
|
|
598
|
+
context.meta.renderNode = componentRoot;
|
|
599
|
+
const propsSource = child.props ?? undefined;
|
|
600
|
+
const debugSession = debug.render.beginComponent({
|
|
601
|
+
parent: node,
|
|
602
|
+
index,
|
|
603
|
+
node: componentRoot,
|
|
604
|
+
component: child,
|
|
605
|
+
propsSource,
|
|
606
|
+
source: child.source,
|
|
607
|
+
isExisting: Array.isArray(existing),
|
|
608
|
+
actions: {
|
|
609
|
+
rerender: () => {
|
|
610
|
+
lastRenderError = null;
|
|
611
|
+
if (rerenderToken) rerenderToken.value++;
|
|
612
|
+
},
|
|
613
|
+
rerenderAndBreak: () => {
|
|
614
|
+
lastRenderError = null;
|
|
615
|
+
if (breakNext) breakNext.value = true;
|
|
616
|
+
if (rerenderToken) rerenderToken.value++;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
if (Array.isArray(existing)) {
|
|
621
|
+
componentRoot.length = 0;
|
|
622
|
+
}
|
|
623
|
+
pushStack(child.component, child.props, child.source);
|
|
624
|
+
let renderFailed = false;
|
|
625
|
+
let childResult;
|
|
626
|
+
try {
|
|
627
|
+
childResult = untrack(() => {
|
|
628
|
+
const shouldBreak = breakNext?.value;
|
|
629
|
+
if (shouldBreak) {
|
|
630
|
+
breakNext.value = false;
|
|
631
|
+
// eslint-disable-next-line no-debugger
|
|
632
|
+
debugger;
|
|
633
|
+
}
|
|
634
|
+
return child();
|
|
635
|
+
});
|
|
636
|
+
} catch (error) {
|
|
637
|
+
notifyRenderError(error);
|
|
638
|
+
renderFailed = true;
|
|
639
|
+
throw error;
|
|
640
|
+
}
|
|
641
|
+
try {
|
|
642
|
+
if (context?.meta?.directory) {
|
|
643
|
+
debugSession.recordDirectory(context.meta.directory.path);
|
|
644
|
+
}
|
|
645
|
+
if (context?.meta?.sourceFile) {
|
|
646
|
+
context.meta.renderNode = componentRoot;
|
|
647
|
+
debugSession.recordFile(context.meta.sourceFile.path, context.meta.sourceFile.filetype);
|
|
648
|
+
context.meta.sourceFileReady = false;
|
|
649
|
+
}
|
|
650
|
+
if (!renderFailed) {
|
|
651
|
+
renderWorker(componentRoot, childResult);
|
|
652
|
+
}
|
|
653
|
+
} finally {
|
|
654
|
+
popStack();
|
|
655
|
+
}
|
|
656
|
+
if (renderFailed) {
|
|
657
|
+
node[index] = componentRoot;
|
|
658
|
+
cache.set(child, componentRoot);
|
|
659
|
+
notifyFileUpdateForNode(node);
|
|
660
|
+
notifyContentState();
|
|
661
|
+
onCleanup(() => debugSession.dispose());
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (context?.meta?.sourceFile) {
|
|
665
|
+
context.meta.sourceFileReady = true;
|
|
666
|
+
notifyFileUpdateForNode(componentRoot);
|
|
667
|
+
}
|
|
668
|
+
node[index] = componentRoot;
|
|
440
669
|
cache.set(child, componentRoot);
|
|
441
670
|
notifyContentState();
|
|
442
|
-
|
|
671
|
+
onCleanup(() => debugSession.dispose());
|
|
672
|
+
}, undefined, {
|
|
673
|
+
debug: {
|
|
674
|
+
name: `render:${child.component.name || "Anonymous"}`,
|
|
675
|
+
type: "render"
|
|
676
|
+
}
|
|
443
677
|
});
|
|
444
678
|
} else if (typeof child === "function") {
|
|
445
|
-
trace(TracePhase.render.appendChild, () => "Memo: " + child.toString());
|
|
446
679
|
const index = node.length;
|
|
447
680
|
effect(() => {
|
|
448
|
-
|
|
449
|
-
let
|
|
450
|
-
|
|
451
|
-
res =
|
|
681
|
+
let res;
|
|
682
|
+
let renderFailed = false;
|
|
683
|
+
try {
|
|
684
|
+
res = child();
|
|
685
|
+
while (typeof res === "function" && !isComponentCreator(res)) {
|
|
686
|
+
res = res();
|
|
687
|
+
}
|
|
688
|
+
} catch (error) {
|
|
689
|
+
notifyRenderError(error);
|
|
690
|
+
renderFailed = true;
|
|
691
|
+
throw error;
|
|
452
692
|
}
|
|
453
693
|
const context = getContext();
|
|
454
694
|
context.childrenWithContent = 0;
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
695
|
+
const existing = node[index];
|
|
696
|
+
const memoNode = Array.isArray(existing) ? existing : [];
|
|
697
|
+
debug.render.prepareMemoNode(node, memoNode, Array.isArray(existing));
|
|
698
|
+
if (Array.isArray(existing)) {
|
|
699
|
+
memoNode.length = 0;
|
|
700
|
+
}
|
|
701
|
+
if (!renderFailed) {
|
|
702
|
+
renderWorker(memoNode, res);
|
|
703
|
+
}
|
|
704
|
+
node[index] = memoNode;
|
|
705
|
+
cache.set(child, memoNode);
|
|
706
|
+
notifyFileUpdateForNode(node);
|
|
460
707
|
notifyContentState();
|
|
461
|
-
return
|
|
708
|
+
return memoNode;
|
|
709
|
+
}, undefined, {
|
|
710
|
+
debug: {
|
|
711
|
+
name: `render:memo:${child.name || "anonymous"}`,
|
|
712
|
+
type: "render"
|
|
713
|
+
}
|
|
462
714
|
});
|
|
463
715
|
} else {
|
|
464
716
|
throw new Error("Unexpected child type");
|
|
465
717
|
}
|
|
466
718
|
}
|
|
467
719
|
}
|
|
720
|
+
function findSourceFileContext(node) {
|
|
721
|
+
let context = getContextForRenderNode(node) ?? null;
|
|
722
|
+
while (context) {
|
|
723
|
+
if (context.meta?.sourceFile) return context;
|
|
724
|
+
context = context.owner;
|
|
725
|
+
}
|
|
726
|
+
return undefined;
|
|
727
|
+
}
|
|
728
|
+
function notifyFileUpdateForNode(node) {
|
|
729
|
+
// Only do the expensive printTree when devtools are actually enabled
|
|
730
|
+
if (!isDevtoolsEnabled()) return;
|
|
731
|
+
const context = findSourceFileContext(node);
|
|
732
|
+
if (!context?.meta?.sourceFile) return;
|
|
733
|
+
if (context.meta.sourceFileReady === false) return;
|
|
734
|
+
const sourceFile = context.meta.sourceFile;
|
|
735
|
+
const renderNode = context.meta.renderNode ?? node;
|
|
736
|
+
// Pass noFlush here since it flushes jobs and can re-enter rendering
|
|
737
|
+
// during effect setup, triggering premature cleanup.
|
|
738
|
+
const contents = printTree(renderNode, {
|
|
739
|
+
printWidth: context.meta?.printOptions?.printWidth,
|
|
740
|
+
tabWidth: context.meta?.printOptions?.tabWidth,
|
|
741
|
+
useTabs: context.meta?.printOptions?.useTabs,
|
|
742
|
+
insertFinalNewLine: context.meta?.printOptions?.insertFinalNewLine ?? true,
|
|
743
|
+
noFlush: true
|
|
744
|
+
});
|
|
745
|
+
debug.files.updated({
|
|
746
|
+
path: sourceFile.path,
|
|
747
|
+
filetype: sourceFile.filetype,
|
|
748
|
+
contents
|
|
749
|
+
});
|
|
750
|
+
}
|
|
468
751
|
function normalizeChild(child) {
|
|
469
752
|
if (Array.isArray(child)) {
|
|
470
753
|
return child.map(normalizeChild);
|
|
@@ -496,29 +779,6 @@ function normalizeChild(child) {
|
|
|
496
779
|
return String(child);
|
|
497
780
|
}
|
|
498
781
|
}
|
|
499
|
-
function dumpChildren(children) {
|
|
500
|
-
if (Array.isArray(children)) {
|
|
501
|
-
return `[ ${children.map(debugPrintChild).join(", ")} ]`;
|
|
502
|
-
}
|
|
503
|
-
return debugPrintChild(children);
|
|
504
|
-
}
|
|
505
|
-
function debugPrintChild(child) {
|
|
506
|
-
if (isComponentCreator(child)) {
|
|
507
|
-
return "<" + child.component.name + ">";
|
|
508
|
-
} else if (typeof child === "function") {
|
|
509
|
-
return "$memo";
|
|
510
|
-
} else if (isRef(child)) {
|
|
511
|
-
return "$ref";
|
|
512
|
-
} else if (isIntrinsicElement(child)) {
|
|
513
|
-
return `<${child.name}>`;
|
|
514
|
-
} else if (isRenderableObject(child)) {
|
|
515
|
-
return `CustomChildElement(${JSON.stringify(child)})`;
|
|
516
|
-
} else if (isRefkeyable(child)) {
|
|
517
|
-
return `refkey`;
|
|
518
|
-
} else {
|
|
519
|
-
return JSON.stringify(child);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
782
|
const defaultPrintTreeOptions = {
|
|
523
783
|
printWidth: 80,
|
|
524
784
|
tabWidth: 2
|
|
@@ -533,9 +793,10 @@ export function printTree(tree, options) {
|
|
|
533
793
|
...defaultPrintTreeOptions,
|
|
534
794
|
...Object.fromEntries(Object.entries(options ?? {}).filter(([_, v]) => v !== undefined))
|
|
535
795
|
};
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
796
|
+
if (!options.noFlush) {
|
|
797
|
+
// make sure queue is empty
|
|
798
|
+
flushJobs();
|
|
799
|
+
}
|
|
539
800
|
const d = printTreeWorker(tree);
|
|
540
801
|
const result = doc.printer.printDocToString(d, options).formatted;
|
|
541
802
|
return options.insertFinalNewLine && !result.endsWith("\n") ? `${result}\n` : result;
|
|
@@ -554,53 +815,4 @@ function printTreeWorker(tree) {
|
|
|
554
815
|
}
|
|
555
816
|
return doc;
|
|
556
817
|
}
|
|
557
|
-
// debugging utilities
|
|
558
|
-
const renderStack = [];
|
|
559
|
-
export function pushStack(component, props) {
|
|
560
|
-
if (!shouldDebug()) return;
|
|
561
|
-
renderStack.push({
|
|
562
|
-
component,
|
|
563
|
-
props
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
export function popStack() {
|
|
567
|
-
if (!shouldDebug()) return;
|
|
568
|
-
renderStack.pop();
|
|
569
|
-
}
|
|
570
|
-
export function printRenderStack() {
|
|
571
|
-
if (!shouldDebug()) return;
|
|
572
|
-
|
|
573
|
-
// eslint-disable-next-line no-console
|
|
574
|
-
console.error("Error rendering:");
|
|
575
|
-
for (let i = renderStack.length - 1; i >= 0; i--) {
|
|
576
|
-
const {
|
|
577
|
-
component,
|
|
578
|
-
props
|
|
579
|
-
} = renderStack[i];
|
|
580
|
-
// eslint-disable-next-line no-console
|
|
581
|
-
console.error(` at ${component.name}(${inspectProps(props)})`);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function inspectProps(props) {
|
|
585
|
-
return JSON.stringify(Object.fromEntries(Object.entries(props).map(([key, value]) => {
|
|
586
|
-
let safeValue;
|
|
587
|
-
switch (typeof value) {
|
|
588
|
-
case "string":
|
|
589
|
-
case "number":
|
|
590
|
-
case "boolean":
|
|
591
|
-
safeValue = value;
|
|
592
|
-
break;
|
|
593
|
-
case "undefined":
|
|
594
|
-
safeValue = "undefined";
|
|
595
|
-
break;
|
|
596
|
-
case "object":
|
|
597
|
-
safeValue = value ? "{...}" : null;
|
|
598
|
-
break;
|
|
599
|
-
case "function":
|
|
600
|
-
safeValue = "function";
|
|
601
|
-
break;
|
|
602
|
-
}
|
|
603
|
-
return [key, safeValue];
|
|
604
|
-
})));
|
|
605
|
-
}
|
|
606
818
|
//# sourceMappingURL=render.js.map
|