seroval 1.7.7 → 1.7.8
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/dev/index.cjs +43 -36
- package/dist/dev/index.d.cts +2 -1
- package/dist/dev/index.d.ts +2 -1
- package/dist/dev/index.js +43 -36
- package/dist/index.cjs +43 -36
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +43 -36
- package/package.json +1 -1
package/dist/dev/index.cjs
CHANGED
|
@@ -8,7 +8,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
8
8
|
let Feature = /* @__PURE__ */ function(Feature) {
|
|
9
9
|
Feature[Feature["AggregateError"] = 1] = "AggregateError";
|
|
10
10
|
/**
|
|
11
|
-
* @deprecated Has no effect. Output
|
|
11
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
12
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
12
13
|
*/
|
|
13
14
|
Feature[Feature["ArrowFunction"] = 2] = "ArrowFunction";
|
|
14
15
|
Feature[Feature["ErrorPrototypeStack"] = 4] = "ErrorPrototypeStack";
|
|
@@ -166,7 +167,8 @@ function escapeCharCode(code) {
|
|
|
166
167
|
default: return;
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
|
-
function serializeString(
|
|
170
|
+
function serializeString(input) {
|
|
171
|
+
const str = "" + input;
|
|
170
172
|
if (!NEEDS_ESCAPE.test(str)) return str;
|
|
171
173
|
if (str.length >= MIN_JSON_STRINGIFY_LENGTH && !JSON_ESCAPE_DIFFERENCES.test(str)) {
|
|
172
174
|
let result = JSON.stringify(str).slice(1, -1);
|
|
@@ -1457,7 +1459,8 @@ async function parsePlainObject$1(ctx, depth, id, current, empty) {
|
|
|
1457
1459
|
return createObjectNode(id, current, empty, await parseProperties$1(ctx, depth, current));
|
|
1458
1460
|
}
|
|
1459
1461
|
async function parseBoxed$1(ctx, depth, id, current) {
|
|
1460
|
-
|
|
1462
|
+
const node = parseValueAsync(ctx, depth, current.valueOf());
|
|
1463
|
+
return createBoxedNode(id, node instanceof Promise ? await node : node);
|
|
1461
1464
|
}
|
|
1462
1465
|
async function parseView$1(ctx, depth, type, id, current) {
|
|
1463
1466
|
const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
|
|
@@ -1566,14 +1569,13 @@ async function parseAsyncIterable$1(ctx, depth, current) {
|
|
|
1566
1569
|
const sequence = [];
|
|
1567
1570
|
for (;;) {
|
|
1568
1571
|
let result;
|
|
1572
|
+
markParserRef(ctx.base, id);
|
|
1569
1573
|
try {
|
|
1570
1574
|
result = await iterator.next();
|
|
1571
1575
|
} catch (error) {
|
|
1572
|
-
markParserRef(ctx.base, id);
|
|
1573
1576
|
sequence.push(createStreamEventNode(33, id, await parseAsync(ctx, depth, error)));
|
|
1574
1577
|
break;
|
|
1575
1578
|
}
|
|
1576
|
-
markParserRef(ctx.base, id);
|
|
1577
1579
|
let parsed;
|
|
1578
1580
|
try {
|
|
1579
1581
|
parsed = await parseAsync(ctx, depth, result.value);
|
|
@@ -2274,10 +2276,6 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
2274
2276
|
function createSequenceAssign(ctx, ref, index, value) {
|
|
2275
2277
|
createAssignment(ctx.base, getRefParam(ctx, ref) + ".v[" + index + "]", value);
|
|
2276
2278
|
}
|
|
2277
|
-
/**
|
|
2278
|
-
* Checks if the value is in the stack. Stack here is a reference
|
|
2279
|
-
* structure to know if a object is to be accessed in a TDZ.
|
|
2280
|
-
*/
|
|
2281
2279
|
function getKeyKind(key) {
|
|
2282
2280
|
const first = key.charCodeAt(0);
|
|
2283
2281
|
if (first >= 48 && first <= 57) {
|
|
@@ -2287,6 +2285,10 @@ function getKeyKind(key) {
|
|
|
2287
2285
|
if (key === "Infinity") return 2;
|
|
2288
2286
|
return isValidIdentifier(key) ? 1 : 0;
|
|
2289
2287
|
}
|
|
2288
|
+
/**
|
|
2289
|
+
* Checks if the value is in the stack. Stack here is a reference
|
|
2290
|
+
* structure to know if a object is to be accessed in a TDZ.
|
|
2291
|
+
*/
|
|
2290
2292
|
function isIndexedValueInStack(ctx, node) {
|
|
2291
2293
|
return node.t === 4 && ctx.stack.includes(node.i);
|
|
2292
2294
|
}
|
|
@@ -2365,8 +2367,7 @@ function serializeProperty(ctx, source, key, val) {
|
|
|
2365
2367
|
if (isIndexedValueInStack(ctx.base, val)) {
|
|
2366
2368
|
const refParam = getRefParam(ctx, val.i);
|
|
2367
2369
|
markSerializerRef(ctx.base, source.i);
|
|
2368
|
-
|
|
2369
|
-
else createArrayAssign(ctx, source.i, kind === 2 ? key : "\"" + key + "\"", refParam);
|
|
2370
|
+
createKeyAssign(ctx, source.i, kind, key, refParam);
|
|
2370
2371
|
return "";
|
|
2371
2372
|
}
|
|
2372
2373
|
if (key !== "__proto__") return (kind === 0 ? "\"" + key + "\"" : key) + ":" + serialize$1(ctx, val);
|
|
@@ -2769,19 +2770,17 @@ function serializeCross(ctx, tree) {
|
|
|
2769
2770
|
if (id == null) return result;
|
|
2770
2771
|
const patches = resolvePatches(ctx.base);
|
|
2771
2772
|
const ref = getRefParam(ctx, id);
|
|
2772
|
-
const scopeId = ctx.state.scopeId;
|
|
2773
|
-
const params = scopeId == null ? "" : "$R";
|
|
2774
2773
|
let body = result;
|
|
2775
2774
|
if (patches) {
|
|
2776
2775
|
if (!ctx.base.assignAll && !result.startsWith(ref + "=")) body = ref + "=" + result;
|
|
2777
2776
|
body = "(" + body + "," + patches + ref + ")";
|
|
2778
2777
|
}
|
|
2779
|
-
|
|
2778
|
+
const scopeId = ctx.state.scopeId;
|
|
2779
|
+
if (scopeId == null) {
|
|
2780
2780
|
if (tree.t === 10 && !patches) return "(" + body + ")";
|
|
2781
2781
|
return body;
|
|
2782
2782
|
}
|
|
2783
|
-
|
|
2784
|
-
return "(" + createFunction([params], body) + ")" + args;
|
|
2783
|
+
return "(" + createFunction(["$R"], body) + ")($R[\"" + serializeString(scopeId) + "\"])";
|
|
2785
2784
|
}
|
|
2786
2785
|
function wrapSerializationError(error) {
|
|
2787
2786
|
return error instanceof SerovalSerializationError ? error : new SerovalSerializationError(error);
|
|
@@ -3143,7 +3142,7 @@ function consumeLiveStream(ctx, depth, id, current) {
|
|
|
3143
3142
|
});
|
|
3144
3143
|
}
|
|
3145
3144
|
function wrapPromiseResult(ctx, type, id, node) {
|
|
3146
|
-
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]
|
|
3145
|
+
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]);
|
|
3147
3146
|
}
|
|
3148
3147
|
function handlePromise(type, id, depth, data) {
|
|
3149
3148
|
if (this.state.alive) parseEvent(this, depth, data, wrapPromiseResult.bind(null, this, type, id), void 0);
|
|
@@ -3205,6 +3204,7 @@ function createStreamParserState(options) {
|
|
|
3205
3204
|
writing: false,
|
|
3206
3205
|
inFlight: void 0,
|
|
3207
3206
|
reason: void 0,
|
|
3207
|
+
starting: false,
|
|
3208
3208
|
onParse: options.onParse,
|
|
3209
3209
|
onError: options.onError,
|
|
3210
3210
|
onDone: options.onDone,
|
|
@@ -3333,25 +3333,30 @@ function startStreamParse(ctx, current) {
|
|
|
3333
3333
|
const state = ctx.state;
|
|
3334
3334
|
let parsed;
|
|
3335
3335
|
let failure;
|
|
3336
|
-
state.
|
|
3336
|
+
state.starting = true;
|
|
3337
3337
|
try {
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3338
|
+
state.parsing++;
|
|
3339
|
+
try {
|
|
3340
|
+
parsed = parseSOS(ctx, 0, current);
|
|
3341
|
+
} catch (error) {
|
|
3342
|
+
failure = { value: error };
|
|
3343
|
+
} finally {
|
|
3344
|
+
state.parsing--;
|
|
3345
|
+
if (!state.alive) releaseParserValues(ctx);
|
|
3346
|
+
}
|
|
3347
|
+
if (failure) {
|
|
3348
|
+
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3349
|
+
else throw failure.value;
|
|
3350
|
+
} else if (parsed && state.alive) {
|
|
3351
|
+
state.queue.unshift({
|
|
3352
|
+
node: parsed,
|
|
3353
|
+
initial: true,
|
|
3354
|
+
accept: void 0
|
|
3355
|
+
});
|
|
3356
|
+
drainOutput(ctx);
|
|
3357
|
+
}
|
|
3341
3358
|
} finally {
|
|
3342
|
-
state.
|
|
3343
|
-
if (!state.alive) releaseParserValues(ctx);
|
|
3344
|
-
}
|
|
3345
|
-
if (failure) {
|
|
3346
|
-
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3347
|
-
else throw failure.value;
|
|
3348
|
-
} else if (parsed && state.alive) {
|
|
3349
|
-
state.queue.unshift({
|
|
3350
|
-
node: parsed,
|
|
3351
|
-
initial: true,
|
|
3352
|
-
accept: void 0
|
|
3353
|
-
});
|
|
3354
|
-
drainOutput(ctx);
|
|
3359
|
+
state.starting = false;
|
|
3355
3360
|
}
|
|
3356
3361
|
}
|
|
3357
3362
|
function runCleanups(state) {
|
|
@@ -3402,7 +3407,7 @@ function stopStreamParse(ctx, mode, reason) {
|
|
|
3402
3407
|
try {
|
|
3403
3408
|
if (mode === 1) {
|
|
3404
3409
|
if (onError) onError(reason);
|
|
3405
|
-
else throw reason;
|
|
3410
|
+
else if (state.starting) throw reason;
|
|
3406
3411
|
} else if (mode === 0) onDone?.();
|
|
3407
3412
|
} catch (error) {
|
|
3408
3413
|
failure = { value: error };
|
|
@@ -3569,6 +3574,7 @@ var Serializer = class {
|
|
|
3569
3574
|
if (this.alive && !this.flushed && options) {
|
|
3570
3575
|
this.pending++;
|
|
3571
3576
|
this.keys.add(key);
|
|
3577
|
+
let starting = true;
|
|
3572
3578
|
const cleanup = crossSerializeStream(value, {
|
|
3573
3579
|
plugins: this.plugins,
|
|
3574
3580
|
scopeId: options.scopeId,
|
|
@@ -3580,7 +3586,7 @@ var Serializer = class {
|
|
|
3580
3586
|
let failure;
|
|
3581
3587
|
try {
|
|
3582
3588
|
if (options.onError) options.onError(error);
|
|
3583
|
-
else throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3589
|
+
else if (starting) throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3584
3590
|
} catch (handlerError) {
|
|
3585
3591
|
failure = { value: handlerError };
|
|
3586
3592
|
}
|
|
@@ -3599,6 +3605,7 @@ var Serializer = class {
|
|
|
3599
3605
|
this.finishWrite();
|
|
3600
3606
|
}
|
|
3601
3607
|
});
|
|
3608
|
+
starting = false;
|
|
3602
3609
|
if (this.alive) this.cleanups.push(cleanup);
|
|
3603
3610
|
else cleanup();
|
|
3604
3611
|
}
|
package/dist/dev/index.d.cts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
export declare enum Feature {
|
|
8
8
|
AggregateError = 1,
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated Has no effect. Output
|
|
10
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
11
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
11
12
|
*/
|
|
12
13
|
ArrowFunction = 2,
|
|
13
14
|
ErrorPrototypeStack = 4,
|
package/dist/dev/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
export declare enum Feature {
|
|
8
8
|
AggregateError = 1,
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated Has no effect. Output
|
|
10
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
11
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
11
12
|
*/
|
|
12
13
|
ArrowFunction = 2,
|
|
13
14
|
ErrorPrototypeStack = 4,
|
package/dist/dev/index.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
let Feature = /* @__PURE__ */ function(Feature) {
|
|
8
8
|
Feature[Feature["AggregateError"] = 1] = "AggregateError";
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated Has no effect. Output
|
|
10
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
11
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
11
12
|
*/
|
|
12
13
|
Feature[Feature["ArrowFunction"] = 2] = "ArrowFunction";
|
|
13
14
|
Feature[Feature["ErrorPrototypeStack"] = 4] = "ErrorPrototypeStack";
|
|
@@ -165,7 +166,8 @@ function escapeCharCode(code) {
|
|
|
165
166
|
default: return;
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
|
-
function serializeString(
|
|
169
|
+
function serializeString(input) {
|
|
170
|
+
const str = "" + input;
|
|
169
171
|
if (!NEEDS_ESCAPE.test(str)) return str;
|
|
170
172
|
if (str.length >= MIN_JSON_STRINGIFY_LENGTH && !JSON_ESCAPE_DIFFERENCES.test(str)) {
|
|
171
173
|
let result = JSON.stringify(str).slice(1, -1);
|
|
@@ -1456,7 +1458,8 @@ async function parsePlainObject$1(ctx, depth, id, current, empty) {
|
|
|
1456
1458
|
return createObjectNode(id, current, empty, await parseProperties$1(ctx, depth, current));
|
|
1457
1459
|
}
|
|
1458
1460
|
async function parseBoxed$1(ctx, depth, id, current) {
|
|
1459
|
-
|
|
1461
|
+
const node = parseValueAsync(ctx, depth, current.valueOf());
|
|
1462
|
+
return createBoxedNode(id, node instanceof Promise ? await node : node);
|
|
1460
1463
|
}
|
|
1461
1464
|
async function parseView$1(ctx, depth, type, id, current) {
|
|
1462
1465
|
const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
|
|
@@ -1565,14 +1568,13 @@ async function parseAsyncIterable$1(ctx, depth, current) {
|
|
|
1565
1568
|
const sequence = [];
|
|
1566
1569
|
for (;;) {
|
|
1567
1570
|
let result;
|
|
1571
|
+
markParserRef(ctx.base, id);
|
|
1568
1572
|
try {
|
|
1569
1573
|
result = await iterator.next();
|
|
1570
1574
|
} catch (error) {
|
|
1571
|
-
markParserRef(ctx.base, id);
|
|
1572
1575
|
sequence.push(createStreamEventNode(33, id, await parseAsync(ctx, depth, error)));
|
|
1573
1576
|
break;
|
|
1574
1577
|
}
|
|
1575
|
-
markParserRef(ctx.base, id);
|
|
1576
1578
|
let parsed;
|
|
1577
1579
|
try {
|
|
1578
1580
|
parsed = await parseAsync(ctx, depth, result.value);
|
|
@@ -2273,10 +2275,6 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
2273
2275
|
function createSequenceAssign(ctx, ref, index, value) {
|
|
2274
2276
|
createAssignment(ctx.base, getRefParam(ctx, ref) + ".v[" + index + "]", value);
|
|
2275
2277
|
}
|
|
2276
|
-
/**
|
|
2277
|
-
* Checks if the value is in the stack. Stack here is a reference
|
|
2278
|
-
* structure to know if a object is to be accessed in a TDZ.
|
|
2279
|
-
*/
|
|
2280
2278
|
function getKeyKind(key) {
|
|
2281
2279
|
const first = key.charCodeAt(0);
|
|
2282
2280
|
if (first >= 48 && first <= 57) {
|
|
@@ -2286,6 +2284,10 @@ function getKeyKind(key) {
|
|
|
2286
2284
|
if (key === "Infinity") return 2;
|
|
2287
2285
|
return isValidIdentifier(key) ? 1 : 0;
|
|
2288
2286
|
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Checks if the value is in the stack. Stack here is a reference
|
|
2289
|
+
* structure to know if a object is to be accessed in a TDZ.
|
|
2290
|
+
*/
|
|
2289
2291
|
function isIndexedValueInStack(ctx, node) {
|
|
2290
2292
|
return node.t === 4 && ctx.stack.includes(node.i);
|
|
2291
2293
|
}
|
|
@@ -2364,8 +2366,7 @@ function serializeProperty(ctx, source, key, val) {
|
|
|
2364
2366
|
if (isIndexedValueInStack(ctx.base, val)) {
|
|
2365
2367
|
const refParam = getRefParam(ctx, val.i);
|
|
2366
2368
|
markSerializerRef(ctx.base, source.i);
|
|
2367
|
-
|
|
2368
|
-
else createArrayAssign(ctx, source.i, kind === 2 ? key : "\"" + key + "\"", refParam);
|
|
2369
|
+
createKeyAssign(ctx, source.i, kind, key, refParam);
|
|
2369
2370
|
return "";
|
|
2370
2371
|
}
|
|
2371
2372
|
if (key !== "__proto__") return (kind === 0 ? "\"" + key + "\"" : key) + ":" + serialize$1(ctx, val);
|
|
@@ -2768,19 +2769,17 @@ function serializeCross(ctx, tree) {
|
|
|
2768
2769
|
if (id == null) return result;
|
|
2769
2770
|
const patches = resolvePatches(ctx.base);
|
|
2770
2771
|
const ref = getRefParam(ctx, id);
|
|
2771
|
-
const scopeId = ctx.state.scopeId;
|
|
2772
|
-
const params = scopeId == null ? "" : "$R";
|
|
2773
2772
|
let body = result;
|
|
2774
2773
|
if (patches) {
|
|
2775
2774
|
if (!ctx.base.assignAll && !result.startsWith(ref + "=")) body = ref + "=" + result;
|
|
2776
2775
|
body = "(" + body + "," + patches + ref + ")";
|
|
2777
2776
|
}
|
|
2778
|
-
|
|
2777
|
+
const scopeId = ctx.state.scopeId;
|
|
2778
|
+
if (scopeId == null) {
|
|
2779
2779
|
if (tree.t === 10 && !patches) return "(" + body + ")";
|
|
2780
2780
|
return body;
|
|
2781
2781
|
}
|
|
2782
|
-
|
|
2783
|
-
return "(" + createFunction([params], body) + ")" + args;
|
|
2782
|
+
return "(" + createFunction(["$R"], body) + ")($R[\"" + serializeString(scopeId) + "\"])";
|
|
2784
2783
|
}
|
|
2785
2784
|
function wrapSerializationError(error) {
|
|
2786
2785
|
return error instanceof SerovalSerializationError ? error : new SerovalSerializationError(error);
|
|
@@ -3142,7 +3141,7 @@ function consumeLiveStream(ctx, depth, id, current) {
|
|
|
3142
3141
|
});
|
|
3143
3142
|
}
|
|
3144
3143
|
function wrapPromiseResult(ctx, type, id, node) {
|
|
3145
|
-
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]
|
|
3144
|
+
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]);
|
|
3146
3145
|
}
|
|
3147
3146
|
function handlePromise(type, id, depth, data) {
|
|
3148
3147
|
if (this.state.alive) parseEvent(this, depth, data, wrapPromiseResult.bind(null, this, type, id), void 0);
|
|
@@ -3204,6 +3203,7 @@ function createStreamParserState(options) {
|
|
|
3204
3203
|
writing: false,
|
|
3205
3204
|
inFlight: void 0,
|
|
3206
3205
|
reason: void 0,
|
|
3206
|
+
starting: false,
|
|
3207
3207
|
onParse: options.onParse,
|
|
3208
3208
|
onError: options.onError,
|
|
3209
3209
|
onDone: options.onDone,
|
|
@@ -3332,25 +3332,30 @@ function startStreamParse(ctx, current) {
|
|
|
3332
3332
|
const state = ctx.state;
|
|
3333
3333
|
let parsed;
|
|
3334
3334
|
let failure;
|
|
3335
|
-
state.
|
|
3335
|
+
state.starting = true;
|
|
3336
3336
|
try {
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3337
|
+
state.parsing++;
|
|
3338
|
+
try {
|
|
3339
|
+
parsed = parseSOS(ctx, 0, current);
|
|
3340
|
+
} catch (error) {
|
|
3341
|
+
failure = { value: error };
|
|
3342
|
+
} finally {
|
|
3343
|
+
state.parsing--;
|
|
3344
|
+
if (!state.alive) releaseParserValues(ctx);
|
|
3345
|
+
}
|
|
3346
|
+
if (failure) {
|
|
3347
|
+
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3348
|
+
else throw failure.value;
|
|
3349
|
+
} else if (parsed && state.alive) {
|
|
3350
|
+
state.queue.unshift({
|
|
3351
|
+
node: parsed,
|
|
3352
|
+
initial: true,
|
|
3353
|
+
accept: void 0
|
|
3354
|
+
});
|
|
3355
|
+
drainOutput(ctx);
|
|
3356
|
+
}
|
|
3340
3357
|
} finally {
|
|
3341
|
-
state.
|
|
3342
|
-
if (!state.alive) releaseParserValues(ctx);
|
|
3343
|
-
}
|
|
3344
|
-
if (failure) {
|
|
3345
|
-
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3346
|
-
else throw failure.value;
|
|
3347
|
-
} else if (parsed && state.alive) {
|
|
3348
|
-
state.queue.unshift({
|
|
3349
|
-
node: parsed,
|
|
3350
|
-
initial: true,
|
|
3351
|
-
accept: void 0
|
|
3352
|
-
});
|
|
3353
|
-
drainOutput(ctx);
|
|
3358
|
+
state.starting = false;
|
|
3354
3359
|
}
|
|
3355
3360
|
}
|
|
3356
3361
|
function runCleanups(state) {
|
|
@@ -3401,7 +3406,7 @@ function stopStreamParse(ctx, mode, reason) {
|
|
|
3401
3406
|
try {
|
|
3402
3407
|
if (mode === 1) {
|
|
3403
3408
|
if (onError) onError(reason);
|
|
3404
|
-
else throw reason;
|
|
3409
|
+
else if (state.starting) throw reason;
|
|
3405
3410
|
} else if (mode === 0) onDone?.();
|
|
3406
3411
|
} catch (error) {
|
|
3407
3412
|
failure = { value: error };
|
|
@@ -3568,6 +3573,7 @@ var Serializer = class {
|
|
|
3568
3573
|
if (this.alive && !this.flushed && options) {
|
|
3569
3574
|
this.pending++;
|
|
3570
3575
|
this.keys.add(key);
|
|
3576
|
+
let starting = true;
|
|
3571
3577
|
const cleanup = crossSerializeStream(value, {
|
|
3572
3578
|
plugins: this.plugins,
|
|
3573
3579
|
scopeId: options.scopeId,
|
|
@@ -3579,7 +3585,7 @@ var Serializer = class {
|
|
|
3579
3585
|
let failure;
|
|
3580
3586
|
try {
|
|
3581
3587
|
if (options.onError) options.onError(error);
|
|
3582
|
-
else throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3588
|
+
else if (starting) throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3583
3589
|
} catch (handlerError) {
|
|
3584
3590
|
failure = { value: handlerError };
|
|
3585
3591
|
}
|
|
@@ -3598,6 +3604,7 @@ var Serializer = class {
|
|
|
3598
3604
|
this.finishWrite();
|
|
3599
3605
|
}
|
|
3600
3606
|
});
|
|
3607
|
+
starting = false;
|
|
3601
3608
|
if (this.alive) this.cleanups.push(cleanup);
|
|
3602
3609
|
else cleanup();
|
|
3603
3610
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
8
8
|
let Feature = /* @__PURE__ */ function(Feature) {
|
|
9
9
|
Feature[Feature["AggregateError"] = 1] = "AggregateError";
|
|
10
10
|
/**
|
|
11
|
-
* @deprecated Has no effect. Output
|
|
11
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
12
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
12
13
|
*/
|
|
13
14
|
Feature[Feature["ArrowFunction"] = 2] = "ArrowFunction";
|
|
14
15
|
Feature[Feature["ErrorPrototypeStack"] = 4] = "ErrorPrototypeStack";
|
|
@@ -166,7 +167,8 @@ function escapeCharCode(code) {
|
|
|
166
167
|
default: return;
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
|
-
function serializeString(
|
|
170
|
+
function serializeString(input) {
|
|
171
|
+
const str = "" + input;
|
|
170
172
|
if (!NEEDS_ESCAPE.test(str)) return str;
|
|
171
173
|
if (str.length >= MIN_JSON_STRINGIFY_LENGTH && !JSON_ESCAPE_DIFFERENCES.test(str)) {
|
|
172
174
|
let result = JSON.stringify(str).slice(1, -1);
|
|
@@ -1441,7 +1443,8 @@ async function parsePlainObject$1(ctx, depth, id, current, empty) {
|
|
|
1441
1443
|
return createObjectNode(id, current, empty, await parseProperties$1(ctx, depth, current));
|
|
1442
1444
|
}
|
|
1443
1445
|
async function parseBoxed$1(ctx, depth, id, current) {
|
|
1444
|
-
|
|
1446
|
+
const node = parseValueAsync(ctx, depth, current.valueOf());
|
|
1447
|
+
return createBoxedNode(id, node instanceof Promise ? await node : node);
|
|
1445
1448
|
}
|
|
1446
1449
|
async function parseView$1(ctx, depth, type, id, current) {
|
|
1447
1450
|
const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
|
|
@@ -1550,14 +1553,13 @@ async function parseAsyncIterable$1(ctx, depth, current) {
|
|
|
1550
1553
|
const sequence = [];
|
|
1551
1554
|
for (;;) {
|
|
1552
1555
|
let result;
|
|
1556
|
+
markParserRef(ctx.base, id);
|
|
1553
1557
|
try {
|
|
1554
1558
|
result = await iterator.next();
|
|
1555
1559
|
} catch (error) {
|
|
1556
|
-
markParserRef(ctx.base, id);
|
|
1557
1560
|
sequence.push(createStreamEventNode(33, id, await parseAsync(ctx, depth, error)));
|
|
1558
1561
|
break;
|
|
1559
1562
|
}
|
|
1560
|
-
markParserRef(ctx.base, id);
|
|
1561
1563
|
let parsed;
|
|
1562
1564
|
try {
|
|
1563
1565
|
parsed = await parseAsync(ctx, depth, result.value);
|
|
@@ -2258,10 +2260,6 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
2258
2260
|
function createSequenceAssign(ctx, ref, index, value) {
|
|
2259
2261
|
createAssignment(ctx.base, getRefParam(ctx, ref) + ".v[" + index + "]", value);
|
|
2260
2262
|
}
|
|
2261
|
-
/**
|
|
2262
|
-
* Checks if the value is in the stack. Stack here is a reference
|
|
2263
|
-
* structure to know if a object is to be accessed in a TDZ.
|
|
2264
|
-
*/
|
|
2265
2263
|
function getKeyKind(key) {
|
|
2266
2264
|
const first = key.charCodeAt(0);
|
|
2267
2265
|
if (first >= 48 && first <= 57) {
|
|
@@ -2271,6 +2269,10 @@ function getKeyKind(key) {
|
|
|
2271
2269
|
if (key === "Infinity") return 2;
|
|
2272
2270
|
return isValidIdentifier(key) ? 1 : 0;
|
|
2273
2271
|
}
|
|
2272
|
+
/**
|
|
2273
|
+
* Checks if the value is in the stack. Stack here is a reference
|
|
2274
|
+
* structure to know if a object is to be accessed in a TDZ.
|
|
2275
|
+
*/
|
|
2274
2276
|
function isIndexedValueInStack(ctx, node) {
|
|
2275
2277
|
return node.t === 4 && ctx.stack.includes(node.i);
|
|
2276
2278
|
}
|
|
@@ -2349,8 +2351,7 @@ function serializeProperty(ctx, source, key, val) {
|
|
|
2349
2351
|
if (isIndexedValueInStack(ctx.base, val)) {
|
|
2350
2352
|
const refParam = getRefParam(ctx, val.i);
|
|
2351
2353
|
markSerializerRef(ctx.base, source.i);
|
|
2352
|
-
|
|
2353
|
-
else createArrayAssign(ctx, source.i, kind === 2 ? key : "\"" + key + "\"", refParam);
|
|
2354
|
+
createKeyAssign(ctx, source.i, kind, key, refParam);
|
|
2354
2355
|
return "";
|
|
2355
2356
|
}
|
|
2356
2357
|
if (key !== "__proto__") return (kind === 0 ? "\"" + key + "\"" : key) + ":" + serialize$1(ctx, val);
|
|
@@ -2753,19 +2754,17 @@ function serializeCross(ctx, tree) {
|
|
|
2753
2754
|
if (id == null) return result;
|
|
2754
2755
|
const patches = resolvePatches(ctx.base);
|
|
2755
2756
|
const ref = getRefParam(ctx, id);
|
|
2756
|
-
const scopeId = ctx.state.scopeId;
|
|
2757
|
-
const params = scopeId == null ? "" : "$R";
|
|
2758
2757
|
let body = result;
|
|
2759
2758
|
if (patches) {
|
|
2760
2759
|
if (!ctx.base.assignAll && !result.startsWith(ref + "=")) body = ref + "=" + result;
|
|
2761
2760
|
body = "(" + body + "," + patches + ref + ")";
|
|
2762
2761
|
}
|
|
2763
|
-
|
|
2762
|
+
const scopeId = ctx.state.scopeId;
|
|
2763
|
+
if (scopeId == null) {
|
|
2764
2764
|
if (tree.t === 10 && !patches) return "(" + body + ")";
|
|
2765
2765
|
return body;
|
|
2766
2766
|
}
|
|
2767
|
-
|
|
2768
|
-
return "(" + createFunction([params], body) + ")" + args;
|
|
2767
|
+
return "(" + createFunction(["$R"], body) + ")($R[\"" + serializeString(scopeId) + "\"])";
|
|
2769
2768
|
}
|
|
2770
2769
|
function wrapSerializationError(error) {
|
|
2771
2770
|
return error instanceof SerovalSerializationError ? error : new SerovalSerializationError(error);
|
|
@@ -3127,7 +3126,7 @@ function consumeLiveStream(ctx, depth, id, current) {
|
|
|
3127
3126
|
});
|
|
3128
3127
|
}
|
|
3129
3128
|
function wrapPromiseResult(ctx, type, id, node) {
|
|
3130
|
-
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]
|
|
3129
|
+
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]);
|
|
3131
3130
|
}
|
|
3132
3131
|
function handlePromise(type, id, depth, data) {
|
|
3133
3132
|
if (this.state.alive) parseEvent(this, depth, data, wrapPromiseResult.bind(null, this, type, id), void 0);
|
|
@@ -3189,6 +3188,7 @@ function createStreamParserState(options) {
|
|
|
3189
3188
|
writing: false,
|
|
3190
3189
|
inFlight: void 0,
|
|
3191
3190
|
reason: void 0,
|
|
3191
|
+
starting: false,
|
|
3192
3192
|
onParse: options.onParse,
|
|
3193
3193
|
onError: options.onError,
|
|
3194
3194
|
onDone: options.onDone,
|
|
@@ -3317,25 +3317,30 @@ function startStreamParse(ctx, current) {
|
|
|
3317
3317
|
const state = ctx.state;
|
|
3318
3318
|
let parsed;
|
|
3319
3319
|
let failure;
|
|
3320
|
-
state.
|
|
3320
|
+
state.starting = true;
|
|
3321
3321
|
try {
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3322
|
+
state.parsing++;
|
|
3323
|
+
try {
|
|
3324
|
+
parsed = parseSOS(ctx, 0, current);
|
|
3325
|
+
} catch (error) {
|
|
3326
|
+
failure = { value: error };
|
|
3327
|
+
} finally {
|
|
3328
|
+
state.parsing--;
|
|
3329
|
+
if (!state.alive) releaseParserValues(ctx);
|
|
3330
|
+
}
|
|
3331
|
+
if (failure) {
|
|
3332
|
+
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3333
|
+
else throw failure.value;
|
|
3334
|
+
} else if (parsed && state.alive) {
|
|
3335
|
+
state.queue.unshift({
|
|
3336
|
+
node: parsed,
|
|
3337
|
+
initial: true,
|
|
3338
|
+
accept: void 0
|
|
3339
|
+
});
|
|
3340
|
+
drainOutput(ctx);
|
|
3341
|
+
}
|
|
3325
3342
|
} finally {
|
|
3326
|
-
state.
|
|
3327
|
-
if (!state.alive) releaseParserValues(ctx);
|
|
3328
|
-
}
|
|
3329
|
-
if (failure) {
|
|
3330
|
-
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3331
|
-
else throw failure.value;
|
|
3332
|
-
} else if (parsed && state.alive) {
|
|
3333
|
-
state.queue.unshift({
|
|
3334
|
-
node: parsed,
|
|
3335
|
-
initial: true,
|
|
3336
|
-
accept: void 0
|
|
3337
|
-
});
|
|
3338
|
-
drainOutput(ctx);
|
|
3343
|
+
state.starting = false;
|
|
3339
3344
|
}
|
|
3340
3345
|
}
|
|
3341
3346
|
function runCleanups(state) {
|
|
@@ -3386,7 +3391,7 @@ function stopStreamParse(ctx, mode, reason) {
|
|
|
3386
3391
|
try {
|
|
3387
3392
|
if (mode === 1) {
|
|
3388
3393
|
if (onError) onError(reason);
|
|
3389
|
-
else throw reason;
|
|
3394
|
+
else if (state.starting) throw reason;
|
|
3390
3395
|
} else if (mode === 0) onDone?.();
|
|
3391
3396
|
} catch (error) {
|
|
3392
3397
|
failure = { value: error };
|
|
@@ -3553,6 +3558,7 @@ var Serializer = class {
|
|
|
3553
3558
|
if (this.alive && !this.flushed && options) {
|
|
3554
3559
|
this.pending++;
|
|
3555
3560
|
this.keys.add(key);
|
|
3561
|
+
let starting = true;
|
|
3556
3562
|
const cleanup = crossSerializeStream(value, {
|
|
3557
3563
|
plugins: this.plugins,
|
|
3558
3564
|
scopeId: options.scopeId,
|
|
@@ -3564,7 +3570,7 @@ var Serializer = class {
|
|
|
3564
3570
|
let failure;
|
|
3565
3571
|
try {
|
|
3566
3572
|
if (options.onError) options.onError(error);
|
|
3567
|
-
else throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3573
|
+
else if (starting) throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3568
3574
|
} catch (handlerError) {
|
|
3569
3575
|
failure = { value: handlerError };
|
|
3570
3576
|
}
|
|
@@ -3583,6 +3589,7 @@ var Serializer = class {
|
|
|
3583
3589
|
this.finishWrite();
|
|
3584
3590
|
}
|
|
3585
3591
|
});
|
|
3592
|
+
starting = false;
|
|
3586
3593
|
if (this.alive) this.cleanups.push(cleanup);
|
|
3587
3594
|
else cleanup();
|
|
3588
3595
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
export declare enum Feature {
|
|
8
8
|
AggregateError = 1,
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated Has no effect. Output
|
|
10
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
11
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
11
12
|
*/
|
|
12
13
|
ArrowFunction = 2,
|
|
13
14
|
ErrorPrototypeStack = 4,
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
export declare enum Feature {
|
|
8
8
|
AggregateError = 1,
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated Has no effect. Output
|
|
10
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
11
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
11
12
|
*/
|
|
12
13
|
ArrowFunction = 2,
|
|
13
14
|
ErrorPrototypeStack = 4,
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
let Feature = /* @__PURE__ */ function(Feature) {
|
|
8
8
|
Feature[Feature["AggregateError"] = 1] = "AggregateError";
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated Has no effect. Output
|
|
10
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
11
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
11
12
|
*/
|
|
12
13
|
Feature[Feature["ArrowFunction"] = 2] = "ArrowFunction";
|
|
13
14
|
Feature[Feature["ErrorPrototypeStack"] = 4] = "ErrorPrototypeStack";
|
|
@@ -165,7 +166,8 @@ function escapeCharCode(code) {
|
|
|
165
166
|
default: return;
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
|
-
function serializeString(
|
|
169
|
+
function serializeString(input) {
|
|
170
|
+
const str = "" + input;
|
|
169
171
|
if (!NEEDS_ESCAPE.test(str)) return str;
|
|
170
172
|
if (str.length >= MIN_JSON_STRINGIFY_LENGTH && !JSON_ESCAPE_DIFFERENCES.test(str)) {
|
|
171
173
|
let result = JSON.stringify(str).slice(1, -1);
|
|
@@ -1440,7 +1442,8 @@ async function parsePlainObject$1(ctx, depth, id, current, empty) {
|
|
|
1440
1442
|
return createObjectNode(id, current, empty, await parseProperties$1(ctx, depth, current));
|
|
1441
1443
|
}
|
|
1442
1444
|
async function parseBoxed$1(ctx, depth, id, current) {
|
|
1443
|
-
|
|
1445
|
+
const node = parseValueAsync(ctx, depth, current.valueOf());
|
|
1446
|
+
return createBoxedNode(id, node instanceof Promise ? await node : node);
|
|
1444
1447
|
}
|
|
1445
1448
|
async function parseView$1(ctx, depth, type, id, current) {
|
|
1446
1449
|
const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
|
|
@@ -1549,14 +1552,13 @@ async function parseAsyncIterable$1(ctx, depth, current) {
|
|
|
1549
1552
|
const sequence = [];
|
|
1550
1553
|
for (;;) {
|
|
1551
1554
|
let result;
|
|
1555
|
+
markParserRef(ctx.base, id);
|
|
1552
1556
|
try {
|
|
1553
1557
|
result = await iterator.next();
|
|
1554
1558
|
} catch (error) {
|
|
1555
|
-
markParserRef(ctx.base, id);
|
|
1556
1559
|
sequence.push(createStreamEventNode(33, id, await parseAsync(ctx, depth, error)));
|
|
1557
1560
|
break;
|
|
1558
1561
|
}
|
|
1559
|
-
markParserRef(ctx.base, id);
|
|
1560
1562
|
let parsed;
|
|
1561
1563
|
try {
|
|
1562
1564
|
parsed = await parseAsync(ctx, depth, result.value);
|
|
@@ -2257,10 +2259,6 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
2257
2259
|
function createSequenceAssign(ctx, ref, index, value) {
|
|
2258
2260
|
createAssignment(ctx.base, getRefParam(ctx, ref) + ".v[" + index + "]", value);
|
|
2259
2261
|
}
|
|
2260
|
-
/**
|
|
2261
|
-
* Checks if the value is in the stack. Stack here is a reference
|
|
2262
|
-
* structure to know if a object is to be accessed in a TDZ.
|
|
2263
|
-
*/
|
|
2264
2262
|
function getKeyKind(key) {
|
|
2265
2263
|
const first = key.charCodeAt(0);
|
|
2266
2264
|
if (first >= 48 && first <= 57) {
|
|
@@ -2270,6 +2268,10 @@ function getKeyKind(key) {
|
|
|
2270
2268
|
if (key === "Infinity") return 2;
|
|
2271
2269
|
return isValidIdentifier(key) ? 1 : 0;
|
|
2272
2270
|
}
|
|
2271
|
+
/**
|
|
2272
|
+
* Checks if the value is in the stack. Stack here is a reference
|
|
2273
|
+
* structure to know if a object is to be accessed in a TDZ.
|
|
2274
|
+
*/
|
|
2273
2275
|
function isIndexedValueInStack(ctx, node) {
|
|
2274
2276
|
return node.t === 4 && ctx.stack.includes(node.i);
|
|
2275
2277
|
}
|
|
@@ -2348,8 +2350,7 @@ function serializeProperty(ctx, source, key, val) {
|
|
|
2348
2350
|
if (isIndexedValueInStack(ctx.base, val)) {
|
|
2349
2351
|
const refParam = getRefParam(ctx, val.i);
|
|
2350
2352
|
markSerializerRef(ctx.base, source.i);
|
|
2351
|
-
|
|
2352
|
-
else createArrayAssign(ctx, source.i, kind === 2 ? key : "\"" + key + "\"", refParam);
|
|
2353
|
+
createKeyAssign(ctx, source.i, kind, key, refParam);
|
|
2353
2354
|
return "";
|
|
2354
2355
|
}
|
|
2355
2356
|
if (key !== "__proto__") return (kind === 0 ? "\"" + key + "\"" : key) + ":" + serialize$1(ctx, val);
|
|
@@ -2752,19 +2753,17 @@ function serializeCross(ctx, tree) {
|
|
|
2752
2753
|
if (id == null) return result;
|
|
2753
2754
|
const patches = resolvePatches(ctx.base);
|
|
2754
2755
|
const ref = getRefParam(ctx, id);
|
|
2755
|
-
const scopeId = ctx.state.scopeId;
|
|
2756
|
-
const params = scopeId == null ? "" : "$R";
|
|
2757
2756
|
let body = result;
|
|
2758
2757
|
if (patches) {
|
|
2759
2758
|
if (!ctx.base.assignAll && !result.startsWith(ref + "=")) body = ref + "=" + result;
|
|
2760
2759
|
body = "(" + body + "," + patches + ref + ")";
|
|
2761
2760
|
}
|
|
2762
|
-
|
|
2761
|
+
const scopeId = ctx.state.scopeId;
|
|
2762
|
+
if (scopeId == null) {
|
|
2763
2763
|
if (tree.t === 10 && !patches) return "(" + body + ")";
|
|
2764
2764
|
return body;
|
|
2765
2765
|
}
|
|
2766
|
-
|
|
2767
|
-
return "(" + createFunction([params], body) + ")" + args;
|
|
2766
|
+
return "(" + createFunction(["$R"], body) + ")($R[\"" + serializeString(scopeId) + "\"])";
|
|
2768
2767
|
}
|
|
2769
2768
|
function wrapSerializationError(error) {
|
|
2770
2769
|
return error instanceof SerovalSerializationError ? error : new SerovalSerializationError(error);
|
|
@@ -3126,7 +3125,7 @@ function consumeLiveStream(ctx, depth, id, current) {
|
|
|
3126
3125
|
});
|
|
3127
3126
|
}
|
|
3128
3127
|
function wrapPromiseResult(ctx, type, id, node) {
|
|
3129
|
-
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]
|
|
3128
|
+
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]);
|
|
3130
3129
|
}
|
|
3131
3130
|
function handlePromise(type, id, depth, data) {
|
|
3132
3131
|
if (this.state.alive) parseEvent(this, depth, data, wrapPromiseResult.bind(null, this, type, id), void 0);
|
|
@@ -3188,6 +3187,7 @@ function createStreamParserState(options) {
|
|
|
3188
3187
|
writing: false,
|
|
3189
3188
|
inFlight: void 0,
|
|
3190
3189
|
reason: void 0,
|
|
3190
|
+
starting: false,
|
|
3191
3191
|
onParse: options.onParse,
|
|
3192
3192
|
onError: options.onError,
|
|
3193
3193
|
onDone: options.onDone,
|
|
@@ -3316,25 +3316,30 @@ function startStreamParse(ctx, current) {
|
|
|
3316
3316
|
const state = ctx.state;
|
|
3317
3317
|
let parsed;
|
|
3318
3318
|
let failure;
|
|
3319
|
-
state.
|
|
3319
|
+
state.starting = true;
|
|
3320
3320
|
try {
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3321
|
+
state.parsing++;
|
|
3322
|
+
try {
|
|
3323
|
+
parsed = parseSOS(ctx, 0, current);
|
|
3324
|
+
} catch (error) {
|
|
3325
|
+
failure = { value: error };
|
|
3326
|
+
} finally {
|
|
3327
|
+
state.parsing--;
|
|
3328
|
+
if (!state.alive) releaseParserValues(ctx);
|
|
3329
|
+
}
|
|
3330
|
+
if (failure) {
|
|
3331
|
+
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3332
|
+
else throw failure.value;
|
|
3333
|
+
} else if (parsed && state.alive) {
|
|
3334
|
+
state.queue.unshift({
|
|
3335
|
+
node: parsed,
|
|
3336
|
+
initial: true,
|
|
3337
|
+
accept: void 0
|
|
3338
|
+
});
|
|
3339
|
+
drainOutput(ctx);
|
|
3340
|
+
}
|
|
3324
3341
|
} finally {
|
|
3325
|
-
state.
|
|
3326
|
-
if (!state.alive) releaseParserValues(ctx);
|
|
3327
|
-
}
|
|
3328
|
-
if (failure) {
|
|
3329
|
-
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3330
|
-
else throw failure.value;
|
|
3331
|
-
} else if (parsed && state.alive) {
|
|
3332
|
-
state.queue.unshift({
|
|
3333
|
-
node: parsed,
|
|
3334
|
-
initial: true,
|
|
3335
|
-
accept: void 0
|
|
3336
|
-
});
|
|
3337
|
-
drainOutput(ctx);
|
|
3342
|
+
state.starting = false;
|
|
3338
3343
|
}
|
|
3339
3344
|
}
|
|
3340
3345
|
function runCleanups(state) {
|
|
@@ -3385,7 +3390,7 @@ function stopStreamParse(ctx, mode, reason) {
|
|
|
3385
3390
|
try {
|
|
3386
3391
|
if (mode === 1) {
|
|
3387
3392
|
if (onError) onError(reason);
|
|
3388
|
-
else throw reason;
|
|
3393
|
+
else if (state.starting) throw reason;
|
|
3389
3394
|
} else if (mode === 0) onDone?.();
|
|
3390
3395
|
} catch (error) {
|
|
3391
3396
|
failure = { value: error };
|
|
@@ -3552,6 +3557,7 @@ var Serializer = class {
|
|
|
3552
3557
|
if (this.alive && !this.flushed && options) {
|
|
3553
3558
|
this.pending++;
|
|
3554
3559
|
this.keys.add(key);
|
|
3560
|
+
let starting = true;
|
|
3555
3561
|
const cleanup = crossSerializeStream(value, {
|
|
3556
3562
|
plugins: this.plugins,
|
|
3557
3563
|
scopeId: options.scopeId,
|
|
@@ -3563,7 +3569,7 @@ var Serializer = class {
|
|
|
3563
3569
|
let failure;
|
|
3564
3570
|
try {
|
|
3565
3571
|
if (options.onError) options.onError(error);
|
|
3566
|
-
else throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3572
|
+
else if (starting) throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3567
3573
|
} catch (handlerError) {
|
|
3568
3574
|
failure = { value: handlerError };
|
|
3569
3575
|
}
|
|
@@ -3582,6 +3588,7 @@ var Serializer = class {
|
|
|
3582
3588
|
this.finishWrite();
|
|
3583
3589
|
}
|
|
3584
3590
|
});
|
|
3591
|
+
starting = false;
|
|
3585
3592
|
if (this.alive) this.cleanups.push(cleanup);
|
|
3586
3593
|
else cleanup();
|
|
3587
3594
|
}
|