@zenithbuild/runtime 0.6.6 → 0.6.7
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/dist/cleanup.d.ts +31 -0
- package/dist/cleanup.js +0 -11
- package/dist/diagnostics.d.ts +4 -0
- package/dist/diagnostics.js +41 -65
- package/dist/effect.d.ts +1 -0
- package/dist/env.d.ts +2 -0
- package/dist/env.js +1 -11
- package/dist/events.d.ts +8 -0
- package/dist/events.js +2 -6
- package/dist/hydrate.d.ts +57 -0
- package/dist/hydrate.js +110 -351
- package/dist/index.d.ts +6 -0
- package/dist/platform.d.ts +11 -0
- package/dist/platform.js +18 -45
- package/dist/ref.d.ts +4 -0
- package/dist/ref.js +1 -9
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.js +8 -12
- package/dist/signal.d.ts +7 -0
- package/dist/signal.js +3 -15
- package/dist/state.d.ts +10 -0
- package/dist/state.js +4 -20
- package/dist/template.d.ts +2 -0
- package/dist/template.js +0 -10
- package/dist/zeneffect.d.ts +17 -0
- package/dist/zeneffect.js +26 -126
- package/package.json +6 -3
package/dist/hydrate.js
CHANGED
|
@@ -6,33 +6,21 @@
|
|
|
6
6
|
// Runtime discovery is forbidden: this module only resolves selectors from
|
|
7
7
|
// bundler-provided tables and executes explicit index-based bindings.
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
9
|
-
|
|
10
9
|
import { _registerDisposer, _registerListener, cleanup } from './cleanup.js';
|
|
11
10
|
import { isZenithRuntimeError, rethrowZenithRuntimeError, throwZenithRuntimeError } from './diagnostics.js';
|
|
12
11
|
import { signal } from './signal.js';
|
|
13
12
|
import { state } from './state.js';
|
|
14
|
-
import {
|
|
15
|
-
zeneffect,
|
|
16
|
-
zenEffect,
|
|
17
|
-
zenMount,
|
|
18
|
-
createSideEffectScope,
|
|
19
|
-
activateSideEffectScope,
|
|
20
|
-
disposeSideEffectScope
|
|
21
|
-
} from './zeneffect.js';
|
|
22
|
-
|
|
13
|
+
import { zeneffect, zenEffect, zenMount, createSideEffectScope, activateSideEffectScope, disposeSideEffectScope } from './zeneffect.js';
|
|
23
14
|
const ALIAS_CONFLICT = Symbol('alias_conflict');
|
|
24
15
|
const ACTIVE_MARKER_CLASS = 'z-active';
|
|
25
16
|
const UNRESOLVED_LITERAL = Symbol('unresolved_literal');
|
|
26
17
|
const LEGACY_MARKUP_HELPER = 'html';
|
|
27
|
-
|
|
28
18
|
const BOOLEAN_ATTRIBUTES = new Set([
|
|
29
19
|
'disabled', 'checked', 'selected', 'readonly', 'multiple',
|
|
30
20
|
'hidden', 'autofocus', 'required', 'open'
|
|
31
21
|
]);
|
|
32
|
-
|
|
33
22
|
const STRICT_MEMBER_CHAIN_LITERAL_RE = /^(?:true|false|null|undefined|[A-Za-z_$][A-Za-z0-9_$]*(\.[A-Za-z_$][A-Za-z0-9_$]*)*)$/;
|
|
34
23
|
const UNSAFE_MEMBER_KEYS = new Set(['__proto__', 'prototype', 'constructor']);
|
|
35
|
-
|
|
36
24
|
/**
|
|
37
25
|
* Hydrate a pre-rendered DOM tree using explicit payload tables.
|
|
38
26
|
*
|
|
@@ -55,25 +43,8 @@ export function hydrate(payload) {
|
|
|
55
43
|
try {
|
|
56
44
|
const normalized = _validatePayload(payload);
|
|
57
45
|
_deepFreezePayload(payload);
|
|
58
|
-
const {
|
|
59
|
-
root,
|
|
60
|
-
expressions,
|
|
61
|
-
markers,
|
|
62
|
-
events,
|
|
63
|
-
refs,
|
|
64
|
-
stateValues,
|
|
65
|
-
stateKeys,
|
|
66
|
-
signals,
|
|
67
|
-
components,
|
|
68
|
-
route,
|
|
69
|
-
params,
|
|
70
|
-
ssrData,
|
|
71
|
-
props,
|
|
72
|
-
exprFns
|
|
73
|
-
} = normalized;
|
|
74
|
-
|
|
46
|
+
const { root, expressions, markers, events, refs, stateValues, stateKeys, signals, components, route, params, ssrData, props, exprFns } = normalized;
|
|
75
47
|
const componentBindings = Object.create(null);
|
|
76
|
-
|
|
77
48
|
const signalMap = new Map();
|
|
78
49
|
for (let i = 0; i < signals.length; i++) {
|
|
79
50
|
const signalDescriptor = signals[i];
|
|
@@ -86,7 +57,6 @@ export function hydrate(payload) {
|
|
|
86
57
|
}
|
|
87
58
|
signalMap.set(i, candidate);
|
|
88
59
|
}
|
|
89
|
-
|
|
90
60
|
const hydratedRefs = [];
|
|
91
61
|
for (let i = 0; i < refs.length; i++) {
|
|
92
62
|
const refBinding = refs[i];
|
|
@@ -95,7 +65,6 @@ export function hydrate(payload) {
|
|
|
95
65
|
targetRef.current = nodes[0] || null;
|
|
96
66
|
hydratedRefs.push(targetRef);
|
|
97
67
|
}
|
|
98
|
-
|
|
99
68
|
if (hydratedRefs.length > 0) {
|
|
100
69
|
_registerDisposer(() => {
|
|
101
70
|
for (let i = 0; i < hydratedRefs.length; i++) {
|
|
@@ -103,7 +72,6 @@ export function hydrate(payload) {
|
|
|
103
72
|
}
|
|
104
73
|
});
|
|
105
74
|
}
|
|
106
|
-
|
|
107
75
|
for (let i = 0; i < components.length; i++) {
|
|
108
76
|
const component = components[i];
|
|
109
77
|
const resolvedProps = Object.freeze(_resolveComponentProps(component.props || [], signalMap, {
|
|
@@ -145,7 +113,6 @@ export function hydrate(payload) {
|
|
|
145
113
|
}
|
|
146
114
|
}
|
|
147
115
|
}
|
|
148
|
-
|
|
149
116
|
const expressionMarkerIndices = new Set();
|
|
150
117
|
for (let i = 0; i < expressions.length; i++) {
|
|
151
118
|
const expression = expressions[i];
|
|
@@ -154,7 +121,6 @@ export function hydrate(payload) {
|
|
|
154
121
|
}
|
|
155
122
|
expressionMarkerIndices.add(expression.marker_index);
|
|
156
123
|
}
|
|
157
|
-
|
|
158
124
|
const markerByIndex = new Map();
|
|
159
125
|
const markerNodesByIndex = new Map();
|
|
160
126
|
const markerIndices = new Set();
|
|
@@ -165,34 +131,19 @@ export function hydrate(payload) {
|
|
|
165
131
|
}
|
|
166
132
|
markerIndices.add(marker.index);
|
|
167
133
|
markerByIndex.set(marker.index, marker);
|
|
168
|
-
|
|
169
134
|
if (marker.kind === 'event') {
|
|
170
135
|
continue;
|
|
171
136
|
}
|
|
172
|
-
|
|
173
137
|
const nodes = _resolveNodes(root, marker.selector, marker.index, marker.kind);
|
|
174
138
|
markerNodesByIndex.set(marker.index, nodes);
|
|
175
|
-
const value = _evaluateExpression(
|
|
176
|
-
expressions[marker.index],
|
|
177
|
-
stateValues,
|
|
178
|
-
stateKeys,
|
|
179
|
-
signalMap,
|
|
180
|
-
componentBindings,
|
|
181
|
-
params,
|
|
182
|
-
ssrData,
|
|
183
|
-
marker.kind,
|
|
184
|
-
props,
|
|
185
|
-
exprFns
|
|
186
|
-
);
|
|
139
|
+
const value = _evaluateExpression(expressions[marker.index], stateValues, stateKeys, signalMap, componentBindings, params, ssrData, marker.kind, props, exprFns);
|
|
187
140
|
_applyMarkerValue(nodes, marker, value);
|
|
188
141
|
}
|
|
189
|
-
|
|
190
142
|
for (let i = 0; i < expressions.length; i++) {
|
|
191
143
|
if (!markerIndices.has(i)) {
|
|
192
144
|
throw new Error(`[Zenith Runtime] missing marker index ${i}`);
|
|
193
145
|
}
|
|
194
146
|
}
|
|
195
|
-
|
|
196
147
|
function renderMarkerByIndex(index) {
|
|
197
148
|
const marker = markerByIndex.get(index);
|
|
198
149
|
if (!marker || marker.kind === 'event') {
|
|
@@ -200,21 +151,9 @@ export function hydrate(payload) {
|
|
|
200
151
|
}
|
|
201
152
|
const nodes = markerNodesByIndex.get(index) || _resolveNodes(root, marker.selector, marker.index, marker.kind);
|
|
202
153
|
markerNodesByIndex.set(index, nodes);
|
|
203
|
-
const value = _evaluateExpression(
|
|
204
|
-
expressions[index],
|
|
205
|
-
stateValues,
|
|
206
|
-
stateKeys,
|
|
207
|
-
signalMap,
|
|
208
|
-
componentBindings,
|
|
209
|
-
params,
|
|
210
|
-
ssrData,
|
|
211
|
-
marker.kind,
|
|
212
|
-
props,
|
|
213
|
-
exprFns
|
|
214
|
-
);
|
|
154
|
+
const value = _evaluateExpression(expressions[index], stateValues, stateKeys, signalMap, componentBindings, params, ssrData, marker.kind, props, exprFns);
|
|
215
155
|
_applyMarkerValue(nodes, marker, value);
|
|
216
156
|
}
|
|
217
|
-
|
|
218
157
|
const dependentMarkersBySignal = new Map();
|
|
219
158
|
for (let i = 0; i < expressions.length; i++) {
|
|
220
159
|
const expression = expressions[i];
|
|
@@ -230,7 +169,6 @@ export function hydrate(payload) {
|
|
|
230
169
|
dependentMarkersBySignal.get(signalIndex).push(expression.marker_index);
|
|
231
170
|
}
|
|
232
171
|
}
|
|
233
|
-
|
|
234
172
|
for (const [signalId, markerIndexes] of dependentMarkersBySignal.entries()) {
|
|
235
173
|
const targetSignal = signalMap.get(signalId);
|
|
236
174
|
if (!targetSignal) {
|
|
@@ -245,7 +183,6 @@ export function hydrate(payload) {
|
|
|
245
183
|
_registerDisposer(unsubscribe);
|
|
246
184
|
}
|
|
247
185
|
}
|
|
248
|
-
|
|
249
186
|
const dependentMarkersByComponentSignal = new Map();
|
|
250
187
|
for (let i = 0; i < expressions.length; i++) {
|
|
251
188
|
const expression = expressions[i];
|
|
@@ -256,10 +193,9 @@ export function hydrate(payload) {
|
|
|
256
193
|
continue;
|
|
257
194
|
}
|
|
258
195
|
const instanceBindings = componentBindings[expression.component_instance];
|
|
259
|
-
const candidate =
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
: undefined;
|
|
196
|
+
const candidate = instanceBindings && Object.prototype.hasOwnProperty.call(instanceBindings, expression.component_binding)
|
|
197
|
+
? instanceBindings[expression.component_binding]
|
|
198
|
+
: undefined;
|
|
263
199
|
if (!candidate || typeof candidate !== 'object') {
|
|
264
200
|
continue;
|
|
265
201
|
}
|
|
@@ -271,7 +207,6 @@ export function hydrate(payload) {
|
|
|
271
207
|
}
|
|
272
208
|
dependentMarkersByComponentSignal.get(candidate).push(expression.marker_index);
|
|
273
209
|
}
|
|
274
|
-
|
|
275
210
|
for (const [componentSignal, markerIndexes] of dependentMarkersByComponentSignal.entries()) {
|
|
276
211
|
const unsubscribe = componentSignal.subscribe(() => {
|
|
277
212
|
for (let i = 0; i < markerIndexes.length; i++) {
|
|
@@ -282,7 +217,6 @@ export function hydrate(payload) {
|
|
|
282
217
|
_registerDisposer(unsubscribe);
|
|
283
218
|
}
|
|
284
219
|
}
|
|
285
|
-
|
|
286
220
|
const eventIndices = new Set();
|
|
287
221
|
const escDispatchEntries = [];
|
|
288
222
|
for (let i = 0; i < events.length; i++) {
|
|
@@ -291,20 +225,8 @@ export function hydrate(payload) {
|
|
|
291
225
|
throw new Error(`[Zenith Runtime] duplicate event index ${eventBinding.index}`);
|
|
292
226
|
}
|
|
293
227
|
eventIndices.add(eventBinding.index);
|
|
294
|
-
|
|
295
228
|
const nodes = _resolveNodes(root, eventBinding.selector, eventBinding.index, 'event');
|
|
296
|
-
const handler = _evaluateExpression(
|
|
297
|
-
expressions[eventBinding.index],
|
|
298
|
-
stateValues,
|
|
299
|
-
stateKeys,
|
|
300
|
-
signalMap,
|
|
301
|
-
componentBindings,
|
|
302
|
-
params,
|
|
303
|
-
ssrData,
|
|
304
|
-
'event',
|
|
305
|
-
props || {},
|
|
306
|
-
exprFns
|
|
307
|
-
);
|
|
229
|
+
const handler = _evaluateExpression(expressions[eventBinding.index], stateValues, stateKeys, signalMap, componentBindings, params, ssrData, 'event', props || {}, exprFns);
|
|
308
230
|
if (typeof handler !== 'function') {
|
|
309
231
|
throwZenithRuntimeError({
|
|
310
232
|
phase: 'bind',
|
|
@@ -315,13 +237,13 @@ export function hydrate(payload) {
|
|
|
315
237
|
hint: 'Bind events to function references (on:click={handler}).'
|
|
316
238
|
});
|
|
317
239
|
}
|
|
318
|
-
|
|
319
240
|
for (let j = 0; j < nodes.length; j++) {
|
|
320
241
|
const node = nodes[j];
|
|
321
242
|
const wrappedHandler = function zenithEventHandler(event) {
|
|
322
243
|
try {
|
|
323
244
|
return handler.call(this, event);
|
|
324
|
-
}
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
325
247
|
rethrowZenithRuntimeError(error, {
|
|
326
248
|
phase: 'event',
|
|
327
249
|
code: 'EVENT_HANDLER_FAILED',
|
|
@@ -343,7 +265,6 @@ export function hydrate(payload) {
|
|
|
343
265
|
_registerListener(node, eventBinding.event, wrappedHandler);
|
|
344
266
|
}
|
|
345
267
|
}
|
|
346
|
-
|
|
347
268
|
if (escDispatchEntries.length > 0) {
|
|
348
269
|
const doc = root && root.ownerDocument ? root.ownerDocument : (typeof document !== 'undefined' ? document : null);
|
|
349
270
|
if (doc && typeof doc.addEventListener === 'function') {
|
|
@@ -351,10 +272,8 @@ export function hydrate(payload) {
|
|
|
351
272
|
if (!event || event.key !== 'Escape') {
|
|
352
273
|
return;
|
|
353
274
|
}
|
|
354
|
-
|
|
355
275
|
const activeElement = doc.activeElement || null;
|
|
356
276
|
let targetEntry = null;
|
|
357
|
-
|
|
358
277
|
if (activeElement && activeElement !== doc.body && activeElement !== doc.documentElement) {
|
|
359
278
|
for (let i = escDispatchEntries.length - 1; i >= 0; i--) {
|
|
360
279
|
const entry = escDispatchEntries[i];
|
|
@@ -370,7 +289,6 @@ export function hydrate(payload) {
|
|
|
370
289
|
}
|
|
371
290
|
}
|
|
372
291
|
}
|
|
373
|
-
|
|
374
292
|
if (!targetEntry && (activeElement === null || activeElement === doc.body || activeElement === doc.documentElement)) {
|
|
375
293
|
for (let i = escDispatchEntries.length - 1; i >= 0; i--) {
|
|
376
294
|
const entry = escDispatchEntries[i];
|
|
@@ -381,20 +299,18 @@ export function hydrate(payload) {
|
|
|
381
299
|
break;
|
|
382
300
|
}
|
|
383
301
|
}
|
|
384
|
-
|
|
385
302
|
if (!targetEntry) {
|
|
386
303
|
return;
|
|
387
304
|
}
|
|
388
|
-
|
|
389
305
|
return targetEntry.handler.call(targetEntry.node, event);
|
|
390
306
|
};
|
|
391
307
|
doc.addEventListener('keydown', escDispatchListener);
|
|
392
308
|
_registerListener(doc, 'keydown', escDispatchListener);
|
|
393
309
|
}
|
|
394
310
|
}
|
|
395
|
-
|
|
396
311
|
return cleanup;
|
|
397
|
-
}
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
398
314
|
rethrowZenithRuntimeError(error, {
|
|
399
315
|
phase: 'hydrate',
|
|
400
316
|
code: 'BINDING_APPLY_FAILED',
|
|
@@ -402,39 +318,31 @@ export function hydrate(payload) {
|
|
|
402
318
|
});
|
|
403
319
|
}
|
|
404
320
|
}
|
|
405
|
-
|
|
406
321
|
function _validatePayload(payload) {
|
|
407
322
|
if (!payload || typeof payload !== 'object') {
|
|
408
323
|
throw new Error('[Zenith Runtime] hydrate(payload) requires an object payload');
|
|
409
324
|
}
|
|
410
|
-
|
|
411
325
|
if (payload.ir_version !== 1) {
|
|
412
326
|
throw new Error('[Zenith Runtime] unsupported ir_version (expected 1)');
|
|
413
327
|
}
|
|
414
|
-
|
|
415
328
|
const root = payload.root;
|
|
416
329
|
const hasQuery = !!root && typeof root.querySelectorAll === 'function';
|
|
417
330
|
if (!hasQuery) {
|
|
418
331
|
throw new Error('[Zenith Runtime] hydrate(payload) requires payload.root with querySelectorAll');
|
|
419
332
|
}
|
|
420
|
-
|
|
421
333
|
const expressions = payload.expressions;
|
|
422
334
|
if (!Array.isArray(expressions)) {
|
|
423
335
|
throw new Error('[Zenith Runtime] hydrate(payload) requires expressions[]');
|
|
424
336
|
}
|
|
425
|
-
|
|
426
337
|
const markers = payload.markers;
|
|
427
338
|
if (!Array.isArray(markers)) {
|
|
428
339
|
throw new Error('[Zenith Runtime] hydrate(payload) requires markers[]');
|
|
429
340
|
}
|
|
430
|
-
|
|
431
341
|
const events = payload.events;
|
|
432
342
|
if (!Array.isArray(events)) {
|
|
433
343
|
throw new Error('[Zenith Runtime] hydrate(payload) requires events[]');
|
|
434
344
|
}
|
|
435
|
-
|
|
436
345
|
const refs = Array.isArray(payload.refs) ? payload.refs : [];
|
|
437
|
-
|
|
438
346
|
const stateValues = payload.state_values;
|
|
439
347
|
if (!Array.isArray(stateValues)) {
|
|
440
348
|
throw new Error('[Zenith Runtime] hydrate(payload) requires state_values[]');
|
|
@@ -448,12 +356,10 @@ function _validatePayload(payload) {
|
|
|
448
356
|
throw new Error(`[Zenith Runtime] state_keys[${i}] must be a string`);
|
|
449
357
|
}
|
|
450
358
|
}
|
|
451
|
-
|
|
452
359
|
const signals = payload.signals;
|
|
453
360
|
if (!Array.isArray(signals)) {
|
|
454
361
|
throw new Error('[Zenith Runtime] hydrate(payload) requires signals[]');
|
|
455
362
|
}
|
|
456
|
-
|
|
457
363
|
const components = Array.isArray(payload.components) ? payload.components : [];
|
|
458
364
|
const route = typeof payload.route === 'string' && payload.route.length > 0
|
|
459
365
|
? payload.route
|
|
@@ -465,13 +371,9 @@ function _validatePayload(payload) {
|
|
|
465
371
|
? payload.ssr_data
|
|
466
372
|
: {};
|
|
467
373
|
const exprFns = Array.isArray(payload.expr_fns) ? payload.expr_fns : [];
|
|
468
|
-
|
|
469
374
|
if (markers.length !== expressions.length) {
|
|
470
|
-
throw new Error(
|
|
471
|
-
`[Zenith Runtime] marker/expression mismatch: markers=${markers.length}, expressions=${expressions.length}`
|
|
472
|
-
);
|
|
375
|
+
throw new Error(`[Zenith Runtime] marker/expression mismatch: markers=${markers.length}, expressions=${expressions.length}`);
|
|
473
376
|
}
|
|
474
|
-
|
|
475
377
|
for (let i = 0; i < expressions.length; i++) {
|
|
476
378
|
const expression = expressions[i];
|
|
477
379
|
if (!expression || typeof expression !== 'object' || Array.isArray(expression)) {
|
|
@@ -481,9 +383,7 @@ function _validatePayload(payload) {
|
|
|
481
383
|
throw new Error(`[Zenith Runtime] expression at position ${i} has invalid marker_index`);
|
|
482
384
|
}
|
|
483
385
|
if (expression.marker_index !== i) {
|
|
484
|
-
throw new Error(
|
|
485
|
-
`[Zenith Runtime] expression table out of order at position ${i}: marker_index=${expression.marker_index}`
|
|
486
|
-
);
|
|
386
|
+
throw new Error(`[Zenith Runtime] expression table out of order at position ${i}: marker_index=${expression.marker_index}`);
|
|
487
387
|
}
|
|
488
388
|
if (expression.fn_index !== undefined && expression.fn_index !== null) {
|
|
489
389
|
if (!Number.isInteger(expression.fn_index) || expression.fn_index < 0) {
|
|
@@ -496,14 +396,11 @@ function _validatePayload(payload) {
|
|
|
496
396
|
}
|
|
497
397
|
for (let j = 0; j < expression.signal_indices.length; j++) {
|
|
498
398
|
if (!Number.isInteger(expression.signal_indices[j]) || expression.signal_indices[j] < 0) {
|
|
499
|
-
throw new Error(
|
|
500
|
-
`[Zenith Runtime] expression at position ${i} has invalid signal_indices[${j}]`
|
|
501
|
-
);
|
|
399
|
+
throw new Error(`[Zenith Runtime] expression at position ${i} has invalid signal_indices[${j}]`);
|
|
502
400
|
}
|
|
503
401
|
}
|
|
504
402
|
}
|
|
505
403
|
}
|
|
506
|
-
|
|
507
404
|
for (let i = 0; i < markers.length; i++) {
|
|
508
405
|
const marker = markers[i];
|
|
509
406
|
if (!marker || typeof marker !== 'object' || Array.isArray(marker)) {
|
|
@@ -525,7 +422,6 @@ function _validatePayload(payload) {
|
|
|
525
422
|
throw new Error(`[Zenith Runtime] attr marker at position ${i} requires attr name`);
|
|
526
423
|
}
|
|
527
424
|
}
|
|
528
|
-
|
|
529
425
|
for (let i = 0; i < events.length; i++) {
|
|
530
426
|
const eventBinding = events[i];
|
|
531
427
|
if (!eventBinding || typeof eventBinding !== 'object' || Array.isArray(eventBinding)) {
|
|
@@ -541,7 +437,6 @@ function _validatePayload(payload) {
|
|
|
541
437
|
throw new Error(`[Zenith Runtime] event binding at position ${i} requires selector`);
|
|
542
438
|
}
|
|
543
439
|
}
|
|
544
|
-
|
|
545
440
|
for (let i = 0; i < refs.length; i++) {
|
|
546
441
|
const refBinding = refs[i];
|
|
547
442
|
if (!refBinding || typeof refBinding !== 'object' || Array.isArray(refBinding)) {
|
|
@@ -550,26 +445,19 @@ function _validatePayload(payload) {
|
|
|
550
445
|
if (!Number.isInteger(refBinding.index) || refBinding.index < 0) {
|
|
551
446
|
throw new Error(`[Zenith Runtime] ref binding at position ${i} requires non-negative index`);
|
|
552
447
|
}
|
|
553
|
-
if (
|
|
554
|
-
!Number.isInteger(refBinding.state_index) ||
|
|
448
|
+
if (!Number.isInteger(refBinding.state_index) ||
|
|
555
449
|
refBinding.state_index < 0 ||
|
|
556
|
-
refBinding.state_index >= stateValues.length
|
|
557
|
-
|
|
558
|
-
throw new Error(
|
|
559
|
-
`[Zenith Runtime] ref binding at position ${i} has out-of-bounds state_index`
|
|
560
|
-
);
|
|
450
|
+
refBinding.state_index >= stateValues.length) {
|
|
451
|
+
throw new Error(`[Zenith Runtime] ref binding at position ${i} has out-of-bounds state_index`);
|
|
561
452
|
}
|
|
562
453
|
if (typeof refBinding.selector !== 'string' || refBinding.selector.length === 0) {
|
|
563
454
|
throw new Error(`[Zenith Runtime] ref binding at position ${i} requires selector`);
|
|
564
455
|
}
|
|
565
456
|
const candidate = stateValues[refBinding.state_index];
|
|
566
457
|
if (!candidate || typeof candidate !== 'object' || !Object.prototype.hasOwnProperty.call(candidate, 'current')) {
|
|
567
|
-
throw new Error(
|
|
568
|
-
`[Zenith Runtime] ref binding at position ${i} must resolve to a ref-like object`
|
|
569
|
-
);
|
|
458
|
+
throw new Error(`[Zenith Runtime] ref binding at position ${i} must resolve to a ref-like object`);
|
|
570
459
|
}
|
|
571
460
|
}
|
|
572
|
-
|
|
573
461
|
for (let i = 0; i < signals.length; i++) {
|
|
574
462
|
const signalDescriptor = signals[i];
|
|
575
463
|
if (!signalDescriptor || typeof signalDescriptor !== 'object' || Array.isArray(signalDescriptor)) {
|
|
@@ -588,7 +476,6 @@ function _validatePayload(payload) {
|
|
|
588
476
|
throw new Error(`[Zenith Runtime] signal descriptor at position ${i} has out-of-bounds state_index`);
|
|
589
477
|
}
|
|
590
478
|
}
|
|
591
|
-
|
|
592
479
|
for (let i = 0; i < components.length; i++) {
|
|
593
480
|
const component = components[i];
|
|
594
481
|
if (!component || typeof component !== 'object' || Array.isArray(component)) {
|
|
@@ -604,37 +491,37 @@ function _validatePayload(payload) {
|
|
|
604
491
|
throw new Error(`[Zenith Runtime] component at position ${i} requires create() function`);
|
|
605
492
|
}
|
|
606
493
|
}
|
|
607
|
-
|
|
608
494
|
if (payload.params !== undefined) {
|
|
609
495
|
if (!payload.params || typeof payload.params !== 'object' || Array.isArray(payload.params)) {
|
|
610
496
|
throw new Error('[Zenith Runtime] hydrate() requires params object');
|
|
611
497
|
}
|
|
612
498
|
}
|
|
613
|
-
|
|
614
499
|
if (payload.ssr_data !== undefined) {
|
|
615
500
|
if (!payload.ssr_data || typeof payload.ssr_data !== 'object' || Array.isArray(payload.ssr_data)) {
|
|
616
501
|
throw new Error('[Zenith Runtime] hydrate() requires ssr_data object');
|
|
617
502
|
}
|
|
618
503
|
}
|
|
619
|
-
|
|
620
504
|
const props = payload.props && typeof payload.props === 'object' && !Array.isArray(payload.props)
|
|
621
505
|
? payload.props
|
|
622
506
|
: {};
|
|
623
|
-
for (let i = 0; i < expressions.length; i++)
|
|
624
|
-
|
|
625
|
-
for (let i = 0; i <
|
|
626
|
-
|
|
627
|
-
for (let i = 0; i <
|
|
507
|
+
for (let i = 0; i < expressions.length; i++)
|
|
508
|
+
Object.freeze(expressions[i]);
|
|
509
|
+
for (let i = 0; i < markers.length; i++)
|
|
510
|
+
Object.freeze(markers[i]);
|
|
511
|
+
for (let i = 0; i < events.length; i++)
|
|
512
|
+
Object.freeze(events[i]);
|
|
513
|
+
for (let i = 0; i < refs.length; i++)
|
|
514
|
+
Object.freeze(refs[i]);
|
|
515
|
+
for (let i = 0; i < signals.length; i++)
|
|
516
|
+
Object.freeze(signals[i]);
|
|
628
517
|
for (let i = 0; i < components.length; i++) {
|
|
629
518
|
const c = components[i];
|
|
630
519
|
if (Array.isArray(c.props)) {
|
|
631
520
|
for (let j = 0; j < c.props.length; j++) {
|
|
632
521
|
const propDesc = c.props[j];
|
|
633
|
-
if (
|
|
634
|
-
propDesc &&
|
|
522
|
+
if (propDesc &&
|
|
635
523
|
typeof propDesc === 'object' &&
|
|
636
|
-
_isHydrationFreezableContainer(propDesc.value)
|
|
637
|
-
) {
|
|
524
|
+
_isHydrationFreezableContainer(propDesc.value)) {
|
|
638
525
|
Object.freeze(propDesc.value);
|
|
639
526
|
}
|
|
640
527
|
Object.freeze(propDesc);
|
|
@@ -643,14 +530,12 @@ function _validatePayload(payload) {
|
|
|
643
530
|
}
|
|
644
531
|
Object.freeze(c);
|
|
645
532
|
}
|
|
646
|
-
|
|
647
533
|
Object.freeze(expressions);
|
|
648
534
|
Object.freeze(markers);
|
|
649
535
|
Object.freeze(events);
|
|
650
536
|
Object.freeze(refs);
|
|
651
537
|
Object.freeze(signals);
|
|
652
538
|
Object.freeze(components);
|
|
653
|
-
|
|
654
539
|
const validatedPayload = {
|
|
655
540
|
root,
|
|
656
541
|
expressions,
|
|
@@ -667,10 +552,8 @@ function _validatePayload(payload) {
|
|
|
667
552
|
props: Object.freeze(props),
|
|
668
553
|
exprFns: Object.freeze(exprFns)
|
|
669
554
|
};
|
|
670
|
-
|
|
671
555
|
return Object.freeze(validatedPayload);
|
|
672
556
|
}
|
|
673
|
-
|
|
674
557
|
function _resolveComponentProps(propTable, signalMap, context = {}) {
|
|
675
558
|
if (!Array.isArray(propTable)) {
|
|
676
559
|
throw new Error('[Zenith Runtime] component props must be an array');
|
|
@@ -700,20 +583,15 @@ function _resolveComponentProps(propTable, signalMap, context = {}) {
|
|
|
700
583
|
}
|
|
701
584
|
const signalValue = signalMap.get(descriptor.index);
|
|
702
585
|
if (!signalValue || typeof signalValue.get !== 'function') {
|
|
703
|
-
throw new Error(
|
|
704
|
-
`[Zenith Runtime]\nComponent: ${context.component || '<unknown>'}\nRoute: ${context.route || '<unknown>'}\nProp: ${descriptor.name}\nReason: signal index ${descriptor.index} did not resolve`
|
|
705
|
-
);
|
|
586
|
+
throw new Error(`[Zenith Runtime]\nComponent: ${context.component || '<unknown>'}\nRoute: ${context.route || '<unknown>'}\nProp: ${descriptor.name}\nReason: signal index ${descriptor.index} did not resolve`);
|
|
706
587
|
}
|
|
707
588
|
resolved[descriptor.name] = signalValue;
|
|
708
589
|
continue;
|
|
709
590
|
}
|
|
710
|
-
throw new Error(
|
|
711
|
-
`[Zenith Runtime] unsupported component prop type "${descriptor.type}" for "${descriptor.name}"`
|
|
712
|
-
);
|
|
591
|
+
throw new Error(`[Zenith Runtime] unsupported component prop type "${descriptor.type}" for "${descriptor.name}"`);
|
|
713
592
|
}
|
|
714
593
|
return resolved;
|
|
715
594
|
}
|
|
716
|
-
|
|
717
595
|
function _resolveNodes(root, selector, index, kind) {
|
|
718
596
|
const nodes = root.querySelectorAll(selector);
|
|
719
597
|
if (!nodes || nodes.length === 0) {
|
|
@@ -728,7 +606,6 @@ function _resolveNodes(root, selector, index, kind) {
|
|
|
728
606
|
}
|
|
729
607
|
return nodes;
|
|
730
608
|
}
|
|
731
|
-
|
|
732
609
|
function _resolveExpressionSignalIndices(binding) {
|
|
733
610
|
if (!binding || typeof binding !== 'object') {
|
|
734
611
|
return [];
|
|
@@ -741,7 +618,6 @@ function _resolveExpressionSignalIndices(binding) {
|
|
|
741
618
|
}
|
|
742
619
|
return [];
|
|
743
620
|
}
|
|
744
|
-
|
|
745
621
|
function _evaluateExpression(binding, stateValues, stateKeys, signalMap, componentBindings, params, ssrData, mode, props, exprFns) {
|
|
746
622
|
if (binding.fn_index != null && binding.fn_index !== undefined) {
|
|
747
623
|
const fns = Array.isArray(exprFns) ? exprFns : [];
|
|
@@ -770,15 +646,12 @@ function _evaluateExpression(binding, stateValues, stateKeys, signalMap, compone
|
|
|
770
646
|
}
|
|
771
647
|
return mode === 'event' ? signalValue : signalValue.get();
|
|
772
648
|
}
|
|
773
|
-
|
|
774
649
|
if (binding.state_index !== null && binding.state_index !== undefined) {
|
|
775
650
|
const resolved = stateValues[binding.state_index];
|
|
776
|
-
if (
|
|
777
|
-
mode !== 'event' &&
|
|
651
|
+
if (mode !== 'event' &&
|
|
778
652
|
resolved &&
|
|
779
653
|
typeof resolved === 'object' &&
|
|
780
|
-
typeof resolved.get === 'function'
|
|
781
|
-
) {
|
|
654
|
+
typeof resolved.get === 'function') {
|
|
782
655
|
return resolved.get();
|
|
783
656
|
}
|
|
784
657
|
if (mode !== 'event' && typeof resolved === 'function') {
|
|
@@ -786,19 +659,15 @@ function _evaluateExpression(binding, stateValues, stateKeys, signalMap, compone
|
|
|
786
659
|
}
|
|
787
660
|
return resolved;
|
|
788
661
|
}
|
|
789
|
-
|
|
790
662
|
if (typeof binding.component_instance === 'string' && typeof binding.component_binding === 'string') {
|
|
791
663
|
const instanceBindings = componentBindings[binding.component_instance];
|
|
792
|
-
const resolved =
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
if (
|
|
797
|
-
mode !== 'event' &&
|
|
664
|
+
const resolved = instanceBindings && Object.prototype.hasOwnProperty.call(instanceBindings, binding.component_binding)
|
|
665
|
+
? instanceBindings[binding.component_binding]
|
|
666
|
+
: undefined;
|
|
667
|
+
if (mode !== 'event' &&
|
|
798
668
|
resolved &&
|
|
799
669
|
typeof resolved === 'object' &&
|
|
800
|
-
typeof resolved.get === 'function'
|
|
801
|
-
) {
|
|
670
|
+
typeof resolved.get === 'function') {
|
|
802
671
|
return resolved.get();
|
|
803
672
|
}
|
|
804
673
|
if (mode !== 'event' && typeof resolved === 'function') {
|
|
@@ -806,20 +675,10 @@ function _evaluateExpression(binding, stateValues, stateKeys, signalMap, compone
|
|
|
806
675
|
}
|
|
807
676
|
return resolved;
|
|
808
677
|
}
|
|
809
|
-
|
|
810
678
|
if (binding.literal !== null && binding.literal !== undefined) {
|
|
811
679
|
if (typeof binding.literal === 'string') {
|
|
812
680
|
const trimmedLiteral = binding.literal.trim();
|
|
813
|
-
const strictMemberValue = _resolveStrictMemberChainLiteral(
|
|
814
|
-
trimmedLiteral,
|
|
815
|
-
stateValues,
|
|
816
|
-
stateKeys,
|
|
817
|
-
params,
|
|
818
|
-
ssrData,
|
|
819
|
-
mode,
|
|
820
|
-
props,
|
|
821
|
-
binding.marker_index
|
|
822
|
-
);
|
|
681
|
+
const strictMemberValue = _resolveStrictMemberChainLiteral(trimmedLiteral, stateValues, stateKeys, params, ssrData, mode, props, binding.marker_index);
|
|
823
682
|
if (strictMemberValue !== UNRESOLVED_LITERAL) {
|
|
824
683
|
return strictMemberValue;
|
|
825
684
|
}
|
|
@@ -832,7 +691,6 @@ function _evaluateExpression(binding, stateValues, stateKeys, signalMap, compone
|
|
|
832
691
|
if (trimmedLiteral === 'props') {
|
|
833
692
|
return props || {};
|
|
834
693
|
}
|
|
835
|
-
|
|
836
694
|
const primitiveValue = _resolvePrimitiveLiteral(trimmedLiteral);
|
|
837
695
|
if (primitiveValue !== UNRESOLVED_LITERAL) {
|
|
838
696
|
return primitiveValue;
|
|
@@ -853,10 +711,8 @@ function _evaluateExpression(binding, stateValues, stateKeys, signalMap, compone
|
|
|
853
711
|
}
|
|
854
712
|
return binding.literal;
|
|
855
713
|
}
|
|
856
|
-
|
|
857
714
|
return '';
|
|
858
715
|
}
|
|
859
|
-
|
|
860
716
|
function _throwUnresolvedMemberChainError(literal, markerIndex, mode, pathSuffix, hint) {
|
|
861
717
|
throwZenithRuntimeError({
|
|
862
718
|
phase: 'bind',
|
|
@@ -870,44 +726,26 @@ function _throwUnresolvedMemberChainError(literal, markerIndex, mode, pathSuffix
|
|
|
870
726
|
hint
|
|
871
727
|
});
|
|
872
728
|
}
|
|
873
|
-
|
|
874
|
-
function _resolveStrictMemberChainLiteral(
|
|
875
|
-
literal,
|
|
876
|
-
stateValues,
|
|
877
|
-
stateKeys,
|
|
878
|
-
params,
|
|
879
|
-
ssrData,
|
|
880
|
-
mode,
|
|
881
|
-
|
|
882
|
-
props,
|
|
883
|
-
markerIndex
|
|
884
|
-
) {
|
|
729
|
+
function _resolveStrictMemberChainLiteral(literal, stateValues, stateKeys, params, ssrData, mode, props, markerIndex) {
|
|
885
730
|
if (typeof literal !== 'string' || !STRICT_MEMBER_CHAIN_LITERAL_RE.test(literal)) {
|
|
886
731
|
return UNRESOLVED_LITERAL;
|
|
887
732
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
if (literal === 'false')
|
|
891
|
-
|
|
892
|
-
if (literal === '
|
|
893
|
-
|
|
733
|
+
if (literal === 'true')
|
|
734
|
+
return true;
|
|
735
|
+
if (literal === 'false')
|
|
736
|
+
return false;
|
|
737
|
+
if (literal === 'null')
|
|
738
|
+
return null;
|
|
739
|
+
if (literal === 'undefined')
|
|
740
|
+
return undefined;
|
|
894
741
|
const segments = literal.split('.');
|
|
895
742
|
const baseIdentifier = segments[0];
|
|
896
743
|
const scope = _buildLiteralScope(stateValues, stateKeys, params, ssrData, mode, props);
|
|
897
|
-
|
|
898
744
|
if (!Object.prototype.hasOwnProperty.call(scope, baseIdentifier)) {
|
|
899
|
-
_throwUnresolvedMemberChainError(
|
|
900
|
-
|
|
901
|
-
markerIndex,
|
|
902
|
-
mode,
|
|
903
|
-
`expression.${baseIdentifier}`,
|
|
904
|
-
`Base identifier "${baseIdentifier}" is not bound. Check props/data/params and declared state keys.`
|
|
905
|
-
);
|
|
906
|
-
}
|
|
907
|
-
|
|
745
|
+
_throwUnresolvedMemberChainError(literal, markerIndex, mode, `expression.${baseIdentifier}`, `Base identifier "${baseIdentifier}" is not bound. Check props/data/params and declared state keys.`);
|
|
746
|
+
}
|
|
908
747
|
let cursor = scope[baseIdentifier];
|
|
909
748
|
let traversedPath = baseIdentifier;
|
|
910
|
-
|
|
911
749
|
for (let i = 1; i < segments.length; i++) {
|
|
912
750
|
const segment = segments[i];
|
|
913
751
|
if (UNSAFE_MEMBER_KEYS.has(segment)) {
|
|
@@ -919,80 +757,55 @@ function _resolveStrictMemberChainLiteral(
|
|
|
919
757
|
hint: 'Property access to __proto__, prototype, and constructor is forbidden.'
|
|
920
758
|
});
|
|
921
759
|
}
|
|
922
|
-
|
|
923
760
|
if (cursor === null || cursor === undefined) {
|
|
924
|
-
_throwUnresolvedMemberChainError(
|
|
925
|
-
|
|
926
|
-
markerIndex,
|
|
927
|
-
mode,
|
|
928
|
-
`expression.${traversedPath}.${segment}`,
|
|
929
|
-
`Cannot read "${segment}" from ${traversedPath} because it is null or undefined.`
|
|
930
|
-
);
|
|
931
|
-
}
|
|
932
|
-
|
|
761
|
+
_throwUnresolvedMemberChainError(literal, markerIndex, mode, `expression.${traversedPath}.${segment}`, `Cannot read "${segment}" from ${traversedPath} because it is null or undefined.`);
|
|
762
|
+
}
|
|
933
763
|
const cursorType = typeof cursor;
|
|
934
764
|
if (cursorType !== 'object' && cursorType !== 'function') {
|
|
935
|
-
_throwUnresolvedMemberChainError(
|
|
936
|
-
|
|
937
|
-
markerIndex,
|
|
938
|
-
mode,
|
|
939
|
-
`expression.${traversedPath}.${segment}`,
|
|
940
|
-
`Cannot read "${segment}" from ${traversedPath} because it resolved to a ${cursorType}.`
|
|
941
|
-
);
|
|
942
|
-
}
|
|
943
|
-
|
|
765
|
+
_throwUnresolvedMemberChainError(literal, markerIndex, mode, `expression.${traversedPath}.${segment}`, `Cannot read "${segment}" from ${traversedPath} because it resolved to a ${cursorType}.`);
|
|
766
|
+
}
|
|
944
767
|
if (!Object.prototype.hasOwnProperty.call(cursor, segment)) {
|
|
945
|
-
_throwUnresolvedMemberChainError(
|
|
946
|
-
|
|
947
|
-
markerIndex,
|
|
948
|
-
mode,
|
|
949
|
-
`expression.${traversedPath}.${segment}`,
|
|
950
|
-
`Missing member "${segment}" on ${traversedPath}. Check your bindings.`
|
|
951
|
-
);
|
|
952
|
-
}
|
|
953
|
-
|
|
768
|
+
_throwUnresolvedMemberChainError(literal, markerIndex, mode, `expression.${traversedPath}.${segment}`, `Missing member "${segment}" on ${traversedPath}. Check your bindings.`);
|
|
769
|
+
}
|
|
954
770
|
cursor = cursor[segment];
|
|
955
771
|
traversedPath = `${traversedPath}.${segment}`;
|
|
956
772
|
}
|
|
957
|
-
|
|
958
773
|
return cursor;
|
|
959
774
|
}
|
|
960
|
-
|
|
961
775
|
function _resolvePrimitiveLiteral(literal) {
|
|
962
776
|
if (typeof literal !== 'string') {
|
|
963
777
|
return UNRESOLVED_LITERAL;
|
|
964
778
|
}
|
|
965
|
-
if (literal === 'true')
|
|
966
|
-
|
|
967
|
-
if (literal === '
|
|
968
|
-
|
|
969
|
-
|
|
779
|
+
if (literal === 'true')
|
|
780
|
+
return true;
|
|
781
|
+
if (literal === 'false')
|
|
782
|
+
return false;
|
|
783
|
+
if (literal === 'null')
|
|
784
|
+
return null;
|
|
785
|
+
if (literal === 'undefined')
|
|
786
|
+
return undefined;
|
|
970
787
|
if (/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/.test(literal)) {
|
|
971
788
|
return Number(literal);
|
|
972
789
|
}
|
|
973
|
-
|
|
974
790
|
if (literal.length >= 2 && literal.startsWith('"') && literal.endsWith('"')) {
|
|
975
791
|
try {
|
|
976
792
|
return JSON.parse(literal);
|
|
977
|
-
}
|
|
793
|
+
}
|
|
794
|
+
catch {
|
|
978
795
|
return UNRESOLVED_LITERAL;
|
|
979
796
|
}
|
|
980
797
|
}
|
|
981
|
-
|
|
982
798
|
if (literal.length >= 2 && literal.startsWith('\'') && literal.endsWith('\'')) {
|
|
983
799
|
return literal
|
|
984
800
|
.slice(1, -1)
|
|
985
801
|
.replace(/\\\\/g, '\\')
|
|
986
802
|
.replace(/\\'/g, '\'');
|
|
987
803
|
}
|
|
988
|
-
|
|
989
804
|
if (literal.length >= 2 && literal.startsWith('`') && literal.endsWith('`')) {
|
|
990
805
|
return literal.slice(1, -1);
|
|
991
806
|
}
|
|
992
|
-
|
|
993
807
|
return UNRESOLVED_LITERAL;
|
|
994
808
|
}
|
|
995
|
-
|
|
996
809
|
function _buildLiteralScope(stateValues, stateKeys, params, ssrData, mode, props) {
|
|
997
810
|
const scope = Object.create(null);
|
|
998
811
|
scope.params = params;
|
|
@@ -1020,7 +833,6 @@ function _buildLiteralScope(stateValues, stateKeys, params, ssrData, mode, props
|
|
|
1020
833
|
return scope.__zenith_fragment(html);
|
|
1021
834
|
};
|
|
1022
835
|
const aliasConflicts = new Set();
|
|
1023
|
-
|
|
1024
836
|
if (Array.isArray(stateKeys)) {
|
|
1025
837
|
for (let i = 0; i < stateKeys.length; i++) {
|
|
1026
838
|
const key = stateKeys[i];
|
|
@@ -1032,7 +844,6 @@ function _buildLiteralScope(stateValues, stateKeys, params, ssrData, mode, props
|
|
|
1032
844
|
}
|
|
1033
845
|
const value = stateValues[i];
|
|
1034
846
|
scope[key] = value;
|
|
1035
|
-
|
|
1036
847
|
const alias = _deriveStateAlias(key);
|
|
1037
848
|
if (!alias || alias === key || aliasConflicts.has(alias)) {
|
|
1038
849
|
continue;
|
|
@@ -1045,10 +856,8 @@ function _buildLiteralScope(stateValues, stateKeys, params, ssrData, mode, props
|
|
|
1045
856
|
scope[alias] = scope[key];
|
|
1046
857
|
}
|
|
1047
858
|
}
|
|
1048
|
-
|
|
1049
859
|
return scope;
|
|
1050
860
|
}
|
|
1051
|
-
|
|
1052
861
|
function _deriveStateAlias(key) {
|
|
1053
862
|
if (typeof key !== 'string' || key.length === 0) {
|
|
1054
863
|
return null;
|
|
@@ -1073,7 +882,6 @@ function _deriveStateAlias(key) {
|
|
|
1073
882
|
const alias = match[1];
|
|
1074
883
|
return alias === key ? null : alias;
|
|
1075
884
|
}
|
|
1076
|
-
|
|
1077
885
|
function _isLikelyExpressionLiteral(literal) {
|
|
1078
886
|
if (typeof literal !== 'string') {
|
|
1079
887
|
return false;
|
|
@@ -1090,16 +898,18 @@ function _isLikelyExpressionLiteral(literal) {
|
|
|
1090
898
|
}
|
|
1091
899
|
return /=>|[()[\]{}<>=?:.+\-*/%|&!]/.test(trimmed);
|
|
1092
900
|
}
|
|
1093
|
-
|
|
1094
901
|
function _markerTypeForError(kind) {
|
|
1095
|
-
if (kind === 'text')
|
|
1096
|
-
|
|
1097
|
-
if (kind === '
|
|
902
|
+
if (kind === 'text')
|
|
903
|
+
return 'data-zx-e';
|
|
904
|
+
if (kind === 'attr')
|
|
905
|
+
return 'data-zx-attr';
|
|
906
|
+
if (kind === 'event')
|
|
907
|
+
return 'data-zx-on';
|
|
1098
908
|
return kind;
|
|
1099
909
|
}
|
|
1100
|
-
|
|
1101
910
|
function _truncateLiteralForError(str) {
|
|
1102
|
-
if (typeof str !== 'string')
|
|
911
|
+
if (typeof str !== 'string')
|
|
912
|
+
return String(str);
|
|
1103
913
|
const sanitized = str
|
|
1104
914
|
.replace(/[A-Za-z]:\\[^\s"'`]+/g, '<path>')
|
|
1105
915
|
.replace(/\/Users\/[^\s"'`]+/g, '<path>')
|
|
@@ -1109,7 +919,6 @@ function _truncateLiteralForError(str) {
|
|
|
1109
919
|
.replace(/\/var\/folders\/[^\s"'`]+/g, '<path>');
|
|
1110
920
|
return sanitized.length > 100 ? `${sanitized.substring(0, 97)}...` : sanitized;
|
|
1111
921
|
}
|
|
1112
|
-
|
|
1113
922
|
// ──────────────────────────────────────────────────────────────────────────────
|
|
1114
923
|
// _zenhtml — LEGACY internal helper for compiler-generated fragment expressions.
|
|
1115
924
|
//
|
|
@@ -1120,13 +929,11 @@ function _truncateLiteralForError(str) {
|
|
|
1120
929
|
//
|
|
1121
930
|
// Scheduled for removal before 1.0 (replaced by full fragment protocol).
|
|
1122
931
|
// ──────────────────────────────────────────────────────────────────────────────
|
|
1123
|
-
|
|
1124
932
|
const _ZENHTML_UNSAFE_TAG_RE = /<script[\s>]/i;
|
|
1125
933
|
const _ZENHTML_EVENT_ATTR_RE = /\bon[a-z]+\s*=/i;
|
|
1126
934
|
const _ZENHTML_JS_URL_RE = /javascript\s*:/i;
|
|
1127
935
|
const _ZENHTML_PROTO_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
1128
936
|
const _ZENHTML_SCRIPT_CLOSE_RE = /<\/script/gi;
|
|
1129
|
-
|
|
1130
937
|
function _zenhtml(strings, ...values) {
|
|
1131
938
|
if (!Array.isArray(strings)) {
|
|
1132
939
|
throwZenithRuntimeError({
|
|
@@ -1136,7 +943,6 @@ function _zenhtml(strings, ...values) {
|
|
|
1136
943
|
hint: 'This helper only accepts tagged template syntax.'
|
|
1137
944
|
});
|
|
1138
945
|
}
|
|
1139
|
-
|
|
1140
946
|
let result = '';
|
|
1141
947
|
for (let i = 0; i < strings.length; i++) {
|
|
1142
948
|
result += strings[i];
|
|
@@ -1145,7 +951,6 @@ function _zenhtml(strings, ...values) {
|
|
|
1145
951
|
result += _zenhtml_coerce(val, i);
|
|
1146
952
|
}
|
|
1147
953
|
}
|
|
1148
|
-
|
|
1149
954
|
// Final output sanitization: reject dangerous patterns in assembled HTML
|
|
1150
955
|
if (_ZENHTML_UNSAFE_TAG_RE.test(result)) {
|
|
1151
956
|
throwZenithRuntimeError({
|
|
@@ -1171,16 +976,13 @@ function _zenhtml(strings, ...values) {
|
|
|
1171
976
|
hint: 'javascript: URLs are forbidden in embedded markup.'
|
|
1172
977
|
});
|
|
1173
978
|
}
|
|
1174
|
-
|
|
1175
979
|
// Escape any residual </script sequences
|
|
1176
980
|
result = result.replace(_ZENHTML_SCRIPT_CLOSE_RE, '<\\/script');
|
|
1177
|
-
|
|
1178
981
|
return {
|
|
1179
982
|
__zenith_fragment: true,
|
|
1180
983
|
html: result
|
|
1181
984
|
};
|
|
1182
985
|
}
|
|
1183
|
-
|
|
1184
986
|
function _zenhtml_coerce(val, interpolationIndex) {
|
|
1185
987
|
if (val === null || val === undefined || val === false) {
|
|
1186
988
|
return '';
|
|
@@ -1232,16 +1034,13 @@ function _zenhtml_coerce(val, interpolationIndex) {
|
|
|
1232
1034
|
hint: 'Only strings, numbers, booleans, null, undefined, arrays, and __zenith_fragment objects are allowed.'
|
|
1233
1035
|
});
|
|
1234
1036
|
}
|
|
1235
|
-
|
|
1236
1037
|
function _rewriteMarkupLiterals(expression) {
|
|
1237
1038
|
let out = '';
|
|
1238
1039
|
let index = 0;
|
|
1239
1040
|
let quote = null;
|
|
1240
1041
|
let escaped = false;
|
|
1241
|
-
|
|
1242
1042
|
while (index < expression.length) {
|
|
1243
1043
|
const ch = expression[index];
|
|
1244
|
-
|
|
1245
1044
|
if (quote) {
|
|
1246
1045
|
out += ch;
|
|
1247
1046
|
if (escaped) {
|
|
@@ -1260,14 +1059,12 @@ function _rewriteMarkupLiterals(expression) {
|
|
|
1260
1059
|
index += 1;
|
|
1261
1060
|
continue;
|
|
1262
1061
|
}
|
|
1263
|
-
|
|
1264
1062
|
if (ch === '\'' || ch === '"' || ch === '`') {
|
|
1265
1063
|
quote = ch;
|
|
1266
1064
|
out += ch;
|
|
1267
1065
|
index += 1;
|
|
1268
1066
|
continue;
|
|
1269
1067
|
}
|
|
1270
|
-
|
|
1271
1068
|
if (ch === '<') {
|
|
1272
1069
|
const markup = _readMarkupLiteral(expression, index);
|
|
1273
1070
|
if (markup) {
|
|
@@ -1276,19 +1073,15 @@ function _rewriteMarkupLiterals(expression) {
|
|
|
1276
1073
|
continue;
|
|
1277
1074
|
}
|
|
1278
1075
|
}
|
|
1279
|
-
|
|
1280
1076
|
out += ch;
|
|
1281
1077
|
index += 1;
|
|
1282
1078
|
}
|
|
1283
|
-
|
|
1284
1079
|
return out;
|
|
1285
1080
|
}
|
|
1286
|
-
|
|
1287
1081
|
function _readMarkupLiteral(source, start) {
|
|
1288
1082
|
if (source[start] !== '<') {
|
|
1289
1083
|
return null;
|
|
1290
1084
|
}
|
|
1291
|
-
|
|
1292
1085
|
const firstTag = _readTagToken(source, start);
|
|
1293
1086
|
if (!firstTag || firstTag.isClosing) {
|
|
1294
1087
|
return null;
|
|
@@ -1299,10 +1092,8 @@ function _readMarkupLiteral(source, start) {
|
|
|
1299
1092
|
end: firstTag.end
|
|
1300
1093
|
};
|
|
1301
1094
|
}
|
|
1302
|
-
|
|
1303
1095
|
const stack = [firstTag.name];
|
|
1304
1096
|
let cursor = firstTag.end;
|
|
1305
|
-
|
|
1306
1097
|
while (cursor < source.length) {
|
|
1307
1098
|
const nextLt = source.indexOf('<', cursor);
|
|
1308
1099
|
if (nextLt < 0) {
|
|
@@ -1314,11 +1105,9 @@ function _readMarkupLiteral(source, start) {
|
|
|
1314
1105
|
continue;
|
|
1315
1106
|
}
|
|
1316
1107
|
cursor = token.end;
|
|
1317
|
-
|
|
1318
1108
|
if (token.selfClosing) {
|
|
1319
1109
|
continue;
|
|
1320
1110
|
}
|
|
1321
|
-
|
|
1322
1111
|
if (token.isClosing) {
|
|
1323
1112
|
const expected = stack[stack.length - 1];
|
|
1324
1113
|
if (token.name !== expected) {
|
|
@@ -1333,29 +1122,23 @@ function _readMarkupLiteral(source, start) {
|
|
|
1333
1122
|
}
|
|
1334
1123
|
continue;
|
|
1335
1124
|
}
|
|
1336
|
-
|
|
1337
1125
|
stack.push(token.name);
|
|
1338
1126
|
}
|
|
1339
|
-
|
|
1340
1127
|
return null;
|
|
1341
1128
|
}
|
|
1342
|
-
|
|
1343
1129
|
function _readTagToken(source, start) {
|
|
1344
1130
|
if (source[start] !== '<') {
|
|
1345
1131
|
return null;
|
|
1346
1132
|
}
|
|
1347
1133
|
let index = start + 1;
|
|
1348
1134
|
let isClosing = false;
|
|
1349
|
-
|
|
1350
1135
|
if (index < source.length && source[index] === '/') {
|
|
1351
1136
|
isClosing = true;
|
|
1352
1137
|
index += 1;
|
|
1353
1138
|
}
|
|
1354
|
-
|
|
1355
1139
|
if (index >= source.length || !/[A-Za-z_]/.test(source[index])) {
|
|
1356
1140
|
return null;
|
|
1357
1141
|
}
|
|
1358
|
-
|
|
1359
1142
|
const nameStart = index;
|
|
1360
1143
|
while (index < source.length && /[A-Za-z0-9:_-]/.test(source[index])) {
|
|
1361
1144
|
index += 1;
|
|
@@ -1364,7 +1147,6 @@ function _readTagToken(source, start) {
|
|
|
1364
1147
|
return null;
|
|
1365
1148
|
}
|
|
1366
1149
|
const name = source.slice(nameStart, index);
|
|
1367
|
-
|
|
1368
1150
|
let quote = null;
|
|
1369
1151
|
let escaped = false;
|
|
1370
1152
|
let braceDepth = 0;
|
|
@@ -1387,7 +1169,6 @@ function _readTagToken(source, start) {
|
|
|
1387
1169
|
index += 1;
|
|
1388
1170
|
continue;
|
|
1389
1171
|
}
|
|
1390
|
-
|
|
1391
1172
|
if (ch === '\'' || ch === '"' || ch === '`') {
|
|
1392
1173
|
quote = ch;
|
|
1393
1174
|
index += 1;
|
|
@@ -1410,10 +1191,8 @@ function _readTagToken(source, start) {
|
|
|
1410
1191
|
}
|
|
1411
1192
|
index += 1;
|
|
1412
1193
|
}
|
|
1413
|
-
|
|
1414
1194
|
return null;
|
|
1415
1195
|
}
|
|
1416
|
-
|
|
1417
1196
|
function _markupLiteralToTemplate(markup) {
|
|
1418
1197
|
let out = '`';
|
|
1419
1198
|
let index = 0;
|
|
@@ -1424,7 +1203,8 @@ function _markupLiteralToTemplate(markup) {
|
|
|
1424
1203
|
if (segment) {
|
|
1425
1204
|
if (_isAttributeExpressionStart(markup, index)) {
|
|
1426
1205
|
out += '"${' + segment.content + '}"';
|
|
1427
|
-
}
|
|
1206
|
+
}
|
|
1207
|
+
else {
|
|
1428
1208
|
out += '${' + segment.content + '}';
|
|
1429
1209
|
}
|
|
1430
1210
|
index = segment.end;
|
|
@@ -1452,7 +1232,6 @@ function _markupLiteralToTemplate(markup) {
|
|
|
1452
1232
|
out += '`';
|
|
1453
1233
|
return out;
|
|
1454
1234
|
}
|
|
1455
|
-
|
|
1456
1235
|
function _isAttributeExpressionStart(markup, start) {
|
|
1457
1236
|
let cursor = start - 1;
|
|
1458
1237
|
while (cursor >= 0) {
|
|
@@ -1465,7 +1244,6 @@ function _isAttributeExpressionStart(markup, start) {
|
|
|
1465
1244
|
}
|
|
1466
1245
|
return false;
|
|
1467
1246
|
}
|
|
1468
|
-
|
|
1469
1247
|
function _readBalancedBraces(source, start) {
|
|
1470
1248
|
if (source[start] !== '{') {
|
|
1471
1249
|
return null;
|
|
@@ -1475,7 +1253,6 @@ function _readBalancedBraces(source, start) {
|
|
|
1475
1253
|
let quote = null;
|
|
1476
1254
|
let escaped = false;
|
|
1477
1255
|
let content = '';
|
|
1478
|
-
|
|
1479
1256
|
while (index < source.length) {
|
|
1480
1257
|
const ch = source[index];
|
|
1481
1258
|
if (quote) {
|
|
@@ -1496,7 +1273,6 @@ function _readBalancedBraces(source, start) {
|
|
|
1496
1273
|
index += 1;
|
|
1497
1274
|
continue;
|
|
1498
1275
|
}
|
|
1499
|
-
|
|
1500
1276
|
if (ch === '\'' || ch === '"' || ch === '`') {
|
|
1501
1277
|
quote = ch;
|
|
1502
1278
|
content += ch;
|
|
@@ -1524,10 +1300,8 @@ function _readBalancedBraces(source, start) {
|
|
|
1524
1300
|
content += ch;
|
|
1525
1301
|
index += 1;
|
|
1526
1302
|
}
|
|
1527
|
-
|
|
1528
1303
|
return null;
|
|
1529
1304
|
}
|
|
1530
|
-
|
|
1531
1305
|
function _applyMarkerValue(nodes, marker, value) {
|
|
1532
1306
|
const markerPath = `marker[${marker.index}]`;
|
|
1533
1307
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -1538,20 +1312,20 @@ function _applyMarkerValue(nodes, marker, value) {
|
|
|
1538
1312
|
_mountStructuralFragment(node, value, `${markerPath}.text`);
|
|
1539
1313
|
continue;
|
|
1540
1314
|
}
|
|
1541
|
-
|
|
1542
1315
|
const html = _renderFragmentValue(value, `${markerPath}.text`);
|
|
1543
1316
|
if (html !== null) {
|
|
1544
1317
|
node.innerHTML = html;
|
|
1545
|
-
}
|
|
1318
|
+
}
|
|
1319
|
+
else {
|
|
1546
1320
|
node.textContent = _coerceText(value, `${markerPath}.text`);
|
|
1547
1321
|
}
|
|
1548
1322
|
continue;
|
|
1549
1323
|
}
|
|
1550
|
-
|
|
1551
1324
|
if (marker.kind === 'attr') {
|
|
1552
1325
|
_applyAttribute(node, marker.attr, value);
|
|
1553
1326
|
}
|
|
1554
|
-
}
|
|
1327
|
+
}
|
|
1328
|
+
catch (error) {
|
|
1555
1329
|
rethrowZenithRuntimeError(error, {
|
|
1556
1330
|
phase: 'bind',
|
|
1557
1331
|
code: 'BINDING_APPLY_FAILED',
|
|
@@ -1568,30 +1342,31 @@ function _applyMarkerValue(nodes, marker, value) {
|
|
|
1568
1342
|
}
|
|
1569
1343
|
}
|
|
1570
1344
|
}
|
|
1571
|
-
|
|
1572
1345
|
function _isStructuralFragment(value) {
|
|
1573
1346
|
if (Array.isArray(value)) {
|
|
1574
1347
|
for (let i = 0; i < value.length; i++) {
|
|
1575
|
-
if (_isStructuralFragment(value[i]))
|
|
1348
|
+
if (_isStructuralFragment(value[i]))
|
|
1349
|
+
return true;
|
|
1576
1350
|
}
|
|
1577
1351
|
return false;
|
|
1578
1352
|
}
|
|
1579
1353
|
return value && typeof value === 'object' && value.__zenith_fragment === true && typeof value.mount === 'function';
|
|
1580
1354
|
}
|
|
1581
|
-
|
|
1582
1355
|
function _mountStructuralFragment(container, value, rootPath = 'renderable') {
|
|
1583
1356
|
if (container.__z_unmounts) {
|
|
1584
1357
|
for (let i = 0; i < container.__z_unmounts.length; i++) {
|
|
1585
|
-
try {
|
|
1358
|
+
try {
|
|
1359
|
+
container.__z_unmounts[i]();
|
|
1360
|
+
}
|
|
1361
|
+
catch (e) { }
|
|
1586
1362
|
}
|
|
1587
1363
|
}
|
|
1588
|
-
|
|
1589
1364
|
container.innerHTML = '';
|
|
1590
1365
|
const newUnmounts = [];
|
|
1591
|
-
|
|
1592
1366
|
function mountItem(item, path) {
|
|
1593
1367
|
if (Array.isArray(item)) {
|
|
1594
|
-
for (let i = 0; i < item.length; i++)
|
|
1368
|
+
for (let i = 0; i < item.length; i++)
|
|
1369
|
+
mountItem(item[i], `${path}[${i}]`);
|
|
1595
1370
|
return;
|
|
1596
1371
|
}
|
|
1597
1372
|
if (item && item.__zenith_fragment === true && typeof item.mount === 'function') {
|
|
@@ -1599,21 +1374,23 @@ function _mountStructuralFragment(container, value, rootPath = 'renderable') {
|
|
|
1599
1374
|
if (typeof item.unmount === 'function') {
|
|
1600
1375
|
newUnmounts.push(item.unmount.bind(item));
|
|
1601
1376
|
}
|
|
1602
|
-
}
|
|
1377
|
+
}
|
|
1378
|
+
else {
|
|
1603
1379
|
const text = _coerceText(item, path);
|
|
1604
1380
|
if (text || text === '') {
|
|
1605
1381
|
const textNode = document.createTextNode(text);
|
|
1606
1382
|
container.appendChild(textNode);
|
|
1607
1383
|
newUnmounts.push(() => {
|
|
1608
|
-
if (textNode.parentNode)
|
|
1384
|
+
if (textNode.parentNode)
|
|
1385
|
+
textNode.parentNode.removeChild(textNode);
|
|
1609
1386
|
});
|
|
1610
1387
|
}
|
|
1611
1388
|
}
|
|
1612
1389
|
}
|
|
1613
|
-
|
|
1614
1390
|
try {
|
|
1615
1391
|
mountItem(value, rootPath);
|
|
1616
|
-
}
|
|
1392
|
+
}
|
|
1393
|
+
catch (error) {
|
|
1617
1394
|
rethrowZenithRuntimeError(error, {
|
|
1618
1395
|
phase: 'render',
|
|
1619
1396
|
code: 'FRAGMENT_MOUNT_FAILED',
|
|
@@ -1624,9 +1401,9 @@ function _mountStructuralFragment(container, value, rootPath = 'renderable') {
|
|
|
1624
1401
|
}
|
|
1625
1402
|
container.__z_unmounts = newUnmounts;
|
|
1626
1403
|
}
|
|
1627
|
-
|
|
1628
1404
|
function _coerceText(value, path = 'renderable') {
|
|
1629
|
-
if (value === null || value === undefined || value === false || value === true)
|
|
1405
|
+
if (value === null || value === undefined || value === false || value === true)
|
|
1406
|
+
return '';
|
|
1630
1407
|
if (typeof value === 'function') {
|
|
1631
1408
|
throwZenithRuntimeError({
|
|
1632
1409
|
phase: 'render',
|
|
@@ -1647,7 +1424,6 @@ function _coerceText(value, path = 'renderable') {
|
|
|
1647
1424
|
}
|
|
1648
1425
|
return String(value);
|
|
1649
1426
|
}
|
|
1650
|
-
|
|
1651
1427
|
function _renderFragmentValue(value, path = 'renderable') {
|
|
1652
1428
|
if (value === null || value === undefined || value === false || value === true) {
|
|
1653
1429
|
return '';
|
|
@@ -1665,17 +1441,14 @@ function _renderFragmentValue(value, path = 'renderable') {
|
|
|
1665
1441
|
}
|
|
1666
1442
|
return out;
|
|
1667
1443
|
}
|
|
1668
|
-
if (
|
|
1669
|
-
value &&
|
|
1444
|
+
if (value &&
|
|
1670
1445
|
typeof value === 'object' &&
|
|
1671
1446
|
value.__zenith_fragment === true &&
|
|
1672
|
-
typeof value.html === 'string'
|
|
1673
|
-
) {
|
|
1447
|
+
typeof value.html === 'string') {
|
|
1674
1448
|
return value.html;
|
|
1675
1449
|
}
|
|
1676
1450
|
return null;
|
|
1677
1451
|
}
|
|
1678
|
-
|
|
1679
1452
|
function _escapeHtml(input) {
|
|
1680
1453
|
return String(input)
|
|
1681
1454
|
.replace(/&/g, '&')
|
|
@@ -1684,7 +1457,6 @@ function _escapeHtml(input) {
|
|
|
1684
1457
|
.replace(/"/g, '"')
|
|
1685
1458
|
.replace(/'/g, ''');
|
|
1686
1459
|
}
|
|
1687
|
-
|
|
1688
1460
|
function _renderLegacyMarkupInterpolation(value) {
|
|
1689
1461
|
if (value === null || value === undefined || value === false || value === true) {
|
|
1690
1462
|
return '';
|
|
@@ -1696,17 +1468,14 @@ function _renderLegacyMarkupInterpolation(value) {
|
|
|
1696
1468
|
}
|
|
1697
1469
|
return out;
|
|
1698
1470
|
}
|
|
1699
|
-
if (
|
|
1700
|
-
value &&
|
|
1471
|
+
if (value &&
|
|
1701
1472
|
typeof value === 'object' &&
|
|
1702
1473
|
value.__zenith_fragment === true &&
|
|
1703
|
-
typeof value.html === 'string'
|
|
1704
|
-
) {
|
|
1474
|
+
typeof value.html === 'string') {
|
|
1705
1475
|
return value.html;
|
|
1706
1476
|
}
|
|
1707
1477
|
return _escapeHtml(_coerceText(value, 'legacy markup interpolation'));
|
|
1708
1478
|
}
|
|
1709
|
-
|
|
1710
1479
|
function _applyAttribute(node, attrName, value) {
|
|
1711
1480
|
if (typeof attrName === 'string' && attrName.toLowerCase() === 'innerhtml') {
|
|
1712
1481
|
node.innerHTML = value === null || value === undefined || value === false
|
|
@@ -1714,23 +1483,19 @@ function _applyAttribute(node, attrName, value) {
|
|
|
1714
1483
|
: String(value);
|
|
1715
1484
|
return;
|
|
1716
1485
|
}
|
|
1717
|
-
|
|
1718
1486
|
if (attrName === 'class' || attrName === 'className') {
|
|
1719
1487
|
node.className = value === null || value === undefined || value === false ? '' : String(value);
|
|
1720
1488
|
return;
|
|
1721
1489
|
}
|
|
1722
|
-
|
|
1723
1490
|
if (attrName === 'style') {
|
|
1724
1491
|
if (value === null || value === undefined || value === false) {
|
|
1725
1492
|
node.removeAttribute('style');
|
|
1726
1493
|
return;
|
|
1727
1494
|
}
|
|
1728
|
-
|
|
1729
1495
|
if (typeof value === 'string') {
|
|
1730
1496
|
node.setAttribute('style', value);
|
|
1731
1497
|
return;
|
|
1732
1498
|
}
|
|
1733
|
-
|
|
1734
1499
|
if (typeof value === 'object') {
|
|
1735
1500
|
const entries = Object.entries(value);
|
|
1736
1501
|
let styleText = '';
|
|
@@ -1741,31 +1506,27 @@ function _applyAttribute(node, attrName, value) {
|
|
|
1741
1506
|
node.setAttribute('style', styleText);
|
|
1742
1507
|
return;
|
|
1743
1508
|
}
|
|
1744
|
-
|
|
1745
1509
|
node.setAttribute('style', String(value));
|
|
1746
1510
|
return;
|
|
1747
1511
|
}
|
|
1748
|
-
|
|
1749
1512
|
if (BOOLEAN_ATTRIBUTES.has(attrName)) {
|
|
1750
1513
|
if (value) {
|
|
1751
1514
|
node.setAttribute(attrName, '');
|
|
1752
|
-
}
|
|
1515
|
+
}
|
|
1516
|
+
else {
|
|
1753
1517
|
node.removeAttribute(attrName);
|
|
1754
1518
|
}
|
|
1755
1519
|
return;
|
|
1756
1520
|
}
|
|
1757
|
-
|
|
1758
1521
|
if (value === null || value === undefined || value === false) {
|
|
1759
1522
|
node.removeAttribute(attrName);
|
|
1760
1523
|
return;
|
|
1761
1524
|
}
|
|
1762
|
-
|
|
1763
1525
|
node.setAttribute(attrName, String(value));
|
|
1764
1526
|
}
|
|
1765
|
-
|
|
1766
1527
|
function _deepFreezePayload(obj) {
|
|
1767
|
-
if (!_isHydrationFreezableContainer(obj) || Object.isFrozen(obj))
|
|
1768
|
-
|
|
1528
|
+
if (!_isHydrationFreezableContainer(obj) || Object.isFrozen(obj))
|
|
1529
|
+
return;
|
|
1769
1530
|
Object.freeze(obj);
|
|
1770
1531
|
const keys = Object.keys(obj);
|
|
1771
1532
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -1775,7 +1536,6 @@ function _deepFreezePayload(obj) {
|
|
|
1775
1536
|
}
|
|
1776
1537
|
}
|
|
1777
1538
|
}
|
|
1778
|
-
|
|
1779
1539
|
function _isHydrationRefObject(obj) {
|
|
1780
1540
|
if (!obj || typeof obj !== 'object') {
|
|
1781
1541
|
return false;
|
|
@@ -1798,7 +1558,6 @@ function _isHydrationRefObject(obj) {
|
|
|
1798
1558
|
}
|
|
1799
1559
|
return false;
|
|
1800
1560
|
}
|
|
1801
|
-
|
|
1802
1561
|
function _isPlainObject(value) {
|
|
1803
1562
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1804
1563
|
return false;
|
|
@@ -1806,11 +1565,11 @@ function _isPlainObject(value) {
|
|
|
1806
1565
|
const proto = Object.getPrototypeOf(value);
|
|
1807
1566
|
return proto === Object.prototype || proto === null;
|
|
1808
1567
|
}
|
|
1809
|
-
|
|
1810
1568
|
function _isHydrationFreezableContainer(value) {
|
|
1811
|
-
if (Array.isArray(value))
|
|
1812
|
-
|
|
1813
|
-
|
|
1569
|
+
if (Array.isArray(value))
|
|
1570
|
+
return true;
|
|
1571
|
+
if (!_isPlainObject(value))
|
|
1572
|
+
return false;
|
|
1814
1573
|
if (_isHydrationRefObject(value)) {
|
|
1815
1574
|
return false;
|
|
1816
1575
|
}
|