@soundscript/soundscript 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +10 -0
  3. package/async.d.ts +81 -0
  4. package/async.js +214 -0
  5. package/async.js.map +1 -0
  6. package/bin/soundscript.js +54 -0
  7. package/codec.d.ts +31 -0
  8. package/codec.js +31 -0
  9. package/codec.js.map +1 -0
  10. package/compare.d.ts +28 -0
  11. package/compare.js +121 -0
  12. package/compare.js.map +1 -0
  13. package/decode.d.ts +84 -0
  14. package/decode.js +249 -0
  15. package/decode.js.map +1 -0
  16. package/encode.d.ts +98 -0
  17. package/encode.js +128 -0
  18. package/encode.js.map +1 -0
  19. package/experimental/component.d.ts +40 -0
  20. package/experimental/component.js +46 -0
  21. package/experimental/component.js.map +1 -0
  22. package/experimental/css.d.ts +16 -0
  23. package/experimental/css.js +10 -0
  24. package/experimental/css.js.map +1 -0
  25. package/experimental/debug.d.ts +2 -0
  26. package/experimental/debug.js +10 -0
  27. package/experimental/debug.js.map +1 -0
  28. package/experimental/graphql.d.ts +16 -0
  29. package/experimental/graphql.js +10 -0
  30. package/experimental/graphql.js.map +1 -0
  31. package/experimental/sql.d.ts +22 -0
  32. package/experimental/sql.js +24 -0
  33. package/experimental/sql.js.map +1 -0
  34. package/failures.d.ts +23 -0
  35. package/failures.js +42 -0
  36. package/failures.js.map +1 -0
  37. package/hash.d.ts +34 -0
  38. package/hash.js +116 -0
  39. package/hash.js.map +1 -0
  40. package/hkt.d.ts +40 -0
  41. package/hkt.js +4 -0
  42. package/hkt.js.map +1 -0
  43. package/index.d.ts +9 -0
  44. package/index.js +16 -0
  45. package/index.js.map +1 -0
  46. package/json.d.ts +98 -0
  47. package/json.js +638 -0
  48. package/json.js.map +1 -0
  49. package/match.d.ts +11 -0
  50. package/match.js +14 -0
  51. package/match.js.map +1 -0
  52. package/package.json +153 -0
  53. package/result.d.ts +52 -0
  54. package/result.js +104 -0
  55. package/result.js.map +1 -0
  56. package/soundscript/async.sts +315 -0
  57. package/soundscript/codec.sts +75 -0
  58. package/soundscript/compare.sts +159 -0
  59. package/soundscript/decode.sts +382 -0
  60. package/soundscript/encode.sts +254 -0
  61. package/soundscript/experimental/component.sts +69 -0
  62. package/soundscript/experimental/css.sts +28 -0
  63. package/soundscript/experimental/debug.sts +10 -0
  64. package/soundscript/experimental/graphql.sts +28 -0
  65. package/soundscript/experimental/sql.sts +53 -0
  66. package/soundscript/failures.sts +64 -0
  67. package/soundscript/hash.sts +196 -0
  68. package/soundscript/hkt.sts +41 -0
  69. package/soundscript/index.sts +23 -0
  70. package/soundscript/json.sts +824 -0
  71. package/soundscript/match.sts +26 -0
  72. package/soundscript/result.sts +179 -0
  73. package/soundscript/thunk.sts +15 -0
  74. package/soundscript/typeclasses.sts +167 -0
  75. package/thunk.d.ts +2 -0
  76. package/thunk.js +10 -0
  77. package/thunk.js.map +1 -0
  78. package/typeclasses.d.ts +57 -0
  79. package/typeclasses.js +78 -0
  80. package/typeclasses.js.map +1 -0
package/json.js ADDED
@@ -0,0 +1,638 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _JsonLikeParser_instances, _JsonLikeParser_index, _JsonLikeParser_text, _JsonLikeParser_consumeKeyword, _JsonLikeParser_parseArray, _JsonLikeParser_parseNumber, _JsonLikeParser_parseObject, _JsonLikeParser_parseString, _JsonLikeParser_consumeDigits, _JsonLikeParser_skipWhitespace, _JsonLikeParser_isDigit, _JsonLikeParser_error;
13
+ import { Failure } from '@soundscript/soundscript/failures';
14
+ import { isErr, resultOf } from '@soundscript/soundscript/result';
15
+ const MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
16
+ const MIN_SAFE_INTEGER_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
17
+ export class JsonParseFailure extends Failure {
18
+ constructor(cause) {
19
+ super('Failed to parse JSON.', { cause });
20
+ }
21
+ }
22
+ export class JsonStringifyFailure extends Failure {
23
+ constructor(cause) {
24
+ super('Failed to stringify JSON.', { cause });
25
+ }
26
+ }
27
+ export function parseJson(text, options = {}) {
28
+ return resultOf(() => options.int64 === 'lossless' ? parseLosslessJson(text) : JSON.parse(text), (cause) => new JsonParseFailure(cause));
29
+ }
30
+ export function stringifyJson(value, options = {}) {
31
+ return resultOf(() => {
32
+ if (options.int64 === 'string') {
33
+ return stringifyJsonWithInt64Mode(value, 'string');
34
+ }
35
+ if (options.int64 === 'lossless') {
36
+ return stringifyJsonWithInt64Mode(value, 'lossless');
37
+ }
38
+ const encoded = JSON.stringify(value);
39
+ if (encoded === undefined) {
40
+ throw new TypeError('JSON.stringify returned undefined for a JsonValue input.');
41
+ }
42
+ return encoded;
43
+ }, (cause) => new JsonStringifyFailure(cause));
44
+ }
45
+ export function parseAndDecode(text, decoder) {
46
+ const parsed = parseJson(text);
47
+ return isErr(parsed) ? parsed : decoder.decode(parsed.value);
48
+ }
49
+ export function encodeAndStringify(value, encoder) {
50
+ const encoded = encoder.encode(value);
51
+ return isErr(encoded) ? encoded : stringifyJson(encoded.value);
52
+ }
53
+ export function isJsonValue(value) {
54
+ return isJsonValueInternal(value, new Set());
55
+ }
56
+ export function parseJsonLike(text) {
57
+ return resultOf(() => {
58
+ const parser = new JsonLikeParser(text);
59
+ const value = parser.parseValue();
60
+ parser.finish();
61
+ return value;
62
+ }, (cause) => new JsonParseFailure(cause));
63
+ }
64
+ export function stringifyJsonLike(value, options = {}) {
65
+ return resultOf(() => {
66
+ const encoded = stringifyJsonLikeInternal(value, new Set(), options.bigint ?? 'reject', 'root');
67
+ if (encoded === undefined) {
68
+ throw new TypeError('JSON-like stringification produced no top-level value.');
69
+ }
70
+ return encoded;
71
+ }, (cause) => new JsonStringifyFailure(cause));
72
+ }
73
+ export function decodeJson(text, decoder) {
74
+ const parsed = parseJsonLike(text);
75
+ return isErr(parsed) ? parsed : decoder.decode(parsed.value);
76
+ }
77
+ export function encodeJson(value, encoder, options = {}) {
78
+ const encoded = encoder.encode(value);
79
+ return isErr(encoded) ? encoded : stringifyJsonLike(encoded.value, options);
80
+ }
81
+ export function isJsonLikeValue(value) {
82
+ return isJsonLikeValueInternal(value, new Set());
83
+ }
84
+ function stringifyJsonWithInt64Mode(value, int64Mode) {
85
+ return stringifyJsonWithInt64ModeInternal(value, int64Mode, new Set());
86
+ }
87
+ function stringifyJsonWithInt64ModeInternal(value, int64Mode, visited) {
88
+ switch (typeof value) {
89
+ case 'string':
90
+ return JSON.stringify(value);
91
+ case 'number': {
92
+ const encoded = JSON.stringify(value);
93
+ if (encoded === undefined) {
94
+ throw new TypeError('JSON.stringify returned undefined for a numeric input.');
95
+ }
96
+ return encoded;
97
+ }
98
+ case 'bigint':
99
+ return int64Mode === 'string'
100
+ ? JSON.stringify(value.toString())
101
+ : value.toString();
102
+ case 'boolean':
103
+ return value ? 'true' : 'false';
104
+ case 'object':
105
+ if (value === null) {
106
+ return 'null';
107
+ }
108
+ if (visited.has(value)) {
109
+ throw new TypeError('Could not stringify cyclic JSON value.');
110
+ }
111
+ visited.add(value);
112
+ try {
113
+ if (Array.isArray(value)) {
114
+ return `[${value.map((entry) => stringifyJsonWithInt64ModeInternal(entry, int64Mode, visited)).join(',')}]`;
115
+ }
116
+ const fields = Object.keys(value).map((key) => `${JSON.stringify(key)}:${stringifyJsonWithInt64ModeInternal(value[key], int64Mode, visited)}`);
117
+ return `{${fields.join(',')}}`;
118
+ }
119
+ finally {
120
+ visited.delete(value);
121
+ }
122
+ default:
123
+ throw new TypeError(`Unsupported JSON value kind: ${typeof value}`);
124
+ }
125
+ }
126
+ function parseLosslessJson(text) {
127
+ const parser = new LosslessJsonParser(text);
128
+ const value = parser.parseValue();
129
+ parser.skipWhitespace();
130
+ if (!parser.isAtEnd()) {
131
+ parser.fail('Unexpected trailing characters.');
132
+ }
133
+ return value;
134
+ }
135
+ function isJsonValueInternal(value, visited) {
136
+ switch (typeof value) {
137
+ case 'string':
138
+ case 'number':
139
+ case 'boolean':
140
+ return true;
141
+ case 'object':
142
+ if (value === null) {
143
+ return true;
144
+ }
145
+ if (visited.has(value)) {
146
+ return true;
147
+ }
148
+ visited.add(value);
149
+ try {
150
+ if (Array.isArray(value)) {
151
+ return value.every((entry) => isJsonValueInternal(entry, visited));
152
+ }
153
+ for (const key of Object.keys(value)) {
154
+ if (!isJsonValueInternal(value[key], visited)) {
155
+ return false;
156
+ }
157
+ }
158
+ return true;
159
+ }
160
+ finally {
161
+ visited.delete(value);
162
+ }
163
+ default:
164
+ return false;
165
+ }
166
+ }
167
+ function isJsonLikeValueInternal(value, visited) {
168
+ switch (typeof value) {
169
+ case 'string':
170
+ case 'number':
171
+ case 'boolean':
172
+ case 'bigint':
173
+ case 'undefined':
174
+ return true;
175
+ case 'object':
176
+ if (value === null) {
177
+ return true;
178
+ }
179
+ if (visited.has(value)) {
180
+ return true;
181
+ }
182
+ visited.add(value);
183
+ try {
184
+ if (Array.isArray(value)) {
185
+ return value.every((entry) => isJsonLikeValueInternal(entry, visited));
186
+ }
187
+ for (const key of Object.keys(value)) {
188
+ if (!isJsonLikeValueInternal(value[key], visited)) {
189
+ return false;
190
+ }
191
+ }
192
+ return true;
193
+ }
194
+ finally {
195
+ visited.delete(value);
196
+ }
197
+ default:
198
+ return false;
199
+ }
200
+ }
201
+ function stringifyJsonLikeInternal(value, visited, bigintMode, position) {
202
+ switch (typeof value) {
203
+ case 'string':
204
+ return JSON.stringify(value);
205
+ case 'number':
206
+ return Number.isFinite(value) ? JSON.stringify(value) : 'null';
207
+ case 'boolean':
208
+ return value ? 'true' : 'false';
209
+ case 'bigint':
210
+ switch (bigintMode) {
211
+ case 'string':
212
+ return JSON.stringify(value.toString());
213
+ case 'number':
214
+ return value.toString();
215
+ case 'reject':
216
+ throw new TypeError('Encountered bigint while stringifying JSON-like data.');
217
+ }
218
+ case 'undefined':
219
+ return position === 'array' ? 'null' : undefined;
220
+ case 'object':
221
+ if (value === null) {
222
+ return 'null';
223
+ }
224
+ if (visited.has(value)) {
225
+ throw new TypeError('Converting circular structure to JSON-like text.');
226
+ }
227
+ visited.add(value);
228
+ try {
229
+ if (Array.isArray(value)) {
230
+ return `[${value.map((entry) => stringifyJsonLikeInternal(entry, visited, bigintMode, 'array') ?? 'null').join(',')}]`;
231
+ }
232
+ const encodedProperties = [];
233
+ for (const key of Object.keys(value)) {
234
+ const encodedValue = stringifyJsonLikeInternal(value[key], visited, bigintMode, 'object');
235
+ if (encodedValue === undefined) {
236
+ continue;
237
+ }
238
+ encodedProperties.push(`${JSON.stringify(key)}:${encodedValue}`);
239
+ }
240
+ return `{${encodedProperties.join(',')}}`;
241
+ }
242
+ finally {
243
+ visited.delete(value);
244
+ }
245
+ default:
246
+ throw new TypeError('Encountered an unsupported JSON-like value.');
247
+ }
248
+ }
249
+ class LosslessJsonParser {
250
+ constructor(text) {
251
+ this.index = 0;
252
+ this.text = text;
253
+ }
254
+ fail(message) {
255
+ throw new SyntaxError(`${message} At character ${this.index}.`);
256
+ }
257
+ isAtEnd() {
258
+ return this.index >= this.text.length;
259
+ }
260
+ skipWhitespace() {
261
+ while (!this.isAtEnd() && /\s/u.test(this.text[this.index])) {
262
+ this.index += 1;
263
+ }
264
+ }
265
+ parseValue() {
266
+ this.skipWhitespace();
267
+ if (this.isAtEnd()) {
268
+ this.fail('Unexpected end of JSON input.');
269
+ }
270
+ const current = this.text[this.index];
271
+ switch (current) {
272
+ case '"':
273
+ return this.parseString();
274
+ case '{':
275
+ return this.parseObject();
276
+ case '[':
277
+ return this.parseArray();
278
+ case 't':
279
+ this.consumeKeyword('true');
280
+ return true;
281
+ case 'f':
282
+ this.consumeKeyword('false');
283
+ return false;
284
+ case 'n':
285
+ this.consumeKeyword('null');
286
+ return null;
287
+ default:
288
+ if (current === '-' || isAsciiDigit(current)) {
289
+ return this.parseNumber();
290
+ }
291
+ this.fail(`Unexpected token ${JSON.stringify(current)}.`);
292
+ }
293
+ }
294
+ consumeKeyword(keyword) {
295
+ if (!this.text.startsWith(keyword, this.index)) {
296
+ this.fail(`Expected ${keyword}.`);
297
+ }
298
+ this.index += keyword.length;
299
+ }
300
+ parseString() {
301
+ let result = '';
302
+ this.index += 1;
303
+ while (!this.isAtEnd()) {
304
+ const current = this.text[this.index];
305
+ if (current === '"') {
306
+ this.index += 1;
307
+ return result;
308
+ }
309
+ if (current === '\\') {
310
+ this.index += 1;
311
+ if (this.isAtEnd()) {
312
+ this.fail('Unexpected end of escape sequence.');
313
+ }
314
+ result += this.parseEscapeSequence();
315
+ continue;
316
+ }
317
+ result += current;
318
+ this.index += 1;
319
+ }
320
+ this.fail('Unterminated string literal.');
321
+ }
322
+ parseEscapeSequence() {
323
+ const current = this.text[this.index];
324
+ this.index += 1;
325
+ switch (current) {
326
+ case '"':
327
+ case '\\':
328
+ case '/':
329
+ return current;
330
+ case 'b':
331
+ return '\b';
332
+ case 'f':
333
+ return '\f';
334
+ case 'n':
335
+ return '\n';
336
+ case 'r':
337
+ return '\r';
338
+ case 't':
339
+ return '\t';
340
+ case 'u': {
341
+ const hex = this.text.slice(this.index, this.index + 4);
342
+ if (!/^[0-9A-Fa-f]{4}$/u.test(hex)) {
343
+ this.fail('Invalid unicode escape.');
344
+ }
345
+ this.index += 4;
346
+ return String.fromCharCode(Number.parseInt(hex, 16));
347
+ }
348
+ default:
349
+ this.fail(`Invalid escape sequence \\${current}.`);
350
+ }
351
+ }
352
+ parseArray() {
353
+ const result = [];
354
+ this.index += 1;
355
+ this.skipWhitespace();
356
+ if (this.text[this.index] === ']') {
357
+ this.index += 1;
358
+ return result;
359
+ }
360
+ while (true) {
361
+ result.push(this.parseValue());
362
+ this.skipWhitespace();
363
+ const current = this.text[this.index];
364
+ if (current === ']') {
365
+ this.index += 1;
366
+ return result;
367
+ }
368
+ if (current !== ',') {
369
+ this.fail('Expected , or ] in array literal.');
370
+ }
371
+ this.index += 1;
372
+ }
373
+ }
374
+ parseObject() {
375
+ const result = {};
376
+ this.index += 1;
377
+ this.skipWhitespace();
378
+ if (this.text[this.index] === '}') {
379
+ this.index += 1;
380
+ return result;
381
+ }
382
+ while (true) {
383
+ this.skipWhitespace();
384
+ if (this.text[this.index] !== '"') {
385
+ this.fail('Expected string key in object literal.');
386
+ }
387
+ const key = this.parseString();
388
+ this.skipWhitespace();
389
+ if (this.text[this.index] !== ':') {
390
+ this.fail('Expected : after object key.');
391
+ }
392
+ this.index += 1;
393
+ result[key] = this.parseValue();
394
+ this.skipWhitespace();
395
+ const current = this.text[this.index];
396
+ if (current === '}') {
397
+ this.index += 1;
398
+ return result;
399
+ }
400
+ if (current !== ',') {
401
+ this.fail('Expected , or } in object literal.');
402
+ }
403
+ this.index += 1;
404
+ }
405
+ }
406
+ parseNumber() {
407
+ const start = this.index;
408
+ if (this.text[this.index] === '-') {
409
+ this.index += 1;
410
+ }
411
+ if (this.text[this.index] === '0') {
412
+ this.index += 1;
413
+ }
414
+ else {
415
+ this.consumeDigits();
416
+ }
417
+ let isInteger = true;
418
+ if (this.text[this.index] === '.') {
419
+ isInteger = false;
420
+ this.index += 1;
421
+ this.consumeDigits();
422
+ }
423
+ const exponentMarker = this.text[this.index];
424
+ if (exponentMarker === 'e' || exponentMarker === 'E') {
425
+ isInteger = false;
426
+ this.index += 1;
427
+ const sign = this.text[this.index];
428
+ if (sign === '+' || sign === '-') {
429
+ this.index += 1;
430
+ }
431
+ this.consumeDigits();
432
+ }
433
+ const token = this.text.slice(start, this.index);
434
+ if (!isInteger) {
435
+ return Number(token);
436
+ }
437
+ if (token === '-0') {
438
+ return -0;
439
+ }
440
+ const bigintValue = BigInt(token);
441
+ return bigintValue <= MAX_SAFE_INTEGER_BIGINT && bigintValue >= MIN_SAFE_INTEGER_BIGINT
442
+ ? Number(token)
443
+ : bigintValue;
444
+ }
445
+ consumeDigits() {
446
+ const start = this.index;
447
+ while (!this.isAtEnd() && isAsciiDigit(this.text[this.index])) {
448
+ this.index += 1;
449
+ }
450
+ if (start === this.index) {
451
+ this.fail('Expected digits.');
452
+ }
453
+ }
454
+ }
455
+ class JsonLikeParser {
456
+ constructor(text) {
457
+ _JsonLikeParser_instances.add(this);
458
+ _JsonLikeParser_index.set(this, 0);
459
+ _JsonLikeParser_text.set(this, void 0);
460
+ __classPrivateFieldSet(this, _JsonLikeParser_text, text, "f");
461
+ }
462
+ finish() {
463
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_skipWhitespace).call(this);
464
+ if (__classPrivateFieldGet(this, _JsonLikeParser_index, "f") !== __classPrivateFieldGet(this, _JsonLikeParser_text, "f").length) {
465
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Unexpected trailing JSON input');
466
+ }
467
+ }
468
+ parseValue() {
469
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_skipWhitespace).call(this);
470
+ const current = __classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")];
471
+ switch (current) {
472
+ case '{':
473
+ return __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_parseObject).call(this);
474
+ case '[':
475
+ return __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_parseArray).call(this);
476
+ case '"':
477
+ return __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_parseString).call(this);
478
+ case 't':
479
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_consumeKeyword).call(this, 'true');
480
+ return true;
481
+ case 'f':
482
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_consumeKeyword).call(this, 'false');
483
+ return false;
484
+ case 'n':
485
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_consumeKeyword).call(this, 'null');
486
+ return null;
487
+ default:
488
+ if (current === '-' || __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_isDigit).call(this, current)) {
489
+ return __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_parseNumber).call(this);
490
+ }
491
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Unexpected token in JSON input');
492
+ }
493
+ }
494
+ }
495
+ _JsonLikeParser_index = new WeakMap(), _JsonLikeParser_text = new WeakMap(), _JsonLikeParser_instances = new WeakSet(), _JsonLikeParser_consumeKeyword = function _JsonLikeParser_consumeKeyword(keyword) {
496
+ if (__classPrivateFieldGet(this, _JsonLikeParser_text, "f").slice(__classPrivateFieldGet(this, _JsonLikeParser_index, "f"), __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + keyword.length) !== keyword) {
497
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, `Expected ${keyword}`);
498
+ }
499
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + keyword.length, "f");
500
+ }, _JsonLikeParser_parseArray = function _JsonLikeParser_parseArray() {
501
+ const values = [];
502
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
503
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_skipWhitespace).call(this);
504
+ if (__classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")] === ']') {
505
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
506
+ return values;
507
+ }
508
+ while (true) {
509
+ values.push(this.parseValue());
510
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_skipWhitespace).call(this);
511
+ const current = __classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")];
512
+ if (current === ']') {
513
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
514
+ return values;
515
+ }
516
+ if (current !== ',') {
517
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Expected , or ] in JSON array');
518
+ }
519
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
520
+ }
521
+ }, _JsonLikeParser_parseNumber = function _JsonLikeParser_parseNumber() {
522
+ const start = __classPrivateFieldGet(this, _JsonLikeParser_index, "f");
523
+ if (__classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")] === '-') {
524
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
525
+ }
526
+ if (__classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")] === '0') {
527
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
528
+ }
529
+ else {
530
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_consumeDigits).call(this);
531
+ }
532
+ let isInteger = true;
533
+ if (__classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")] === '.') {
534
+ isInteger = false;
535
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
536
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_consumeDigits).call(this);
537
+ }
538
+ const exponent = __classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")];
539
+ if (exponent === 'e' || exponent === 'E') {
540
+ isInteger = false;
541
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
542
+ const sign = __classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")];
543
+ if (sign === '+' || sign === '-') {
544
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
545
+ }
546
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_consumeDigits).call(this);
547
+ }
548
+ const token = __classPrivateFieldGet(this, _JsonLikeParser_text, "f").slice(start, __classPrivateFieldGet(this, _JsonLikeParser_index, "f"));
549
+ if (!isInteger) {
550
+ return Number(token);
551
+ }
552
+ const bigintValue = BigInt(token);
553
+ const numberValue = Number(token);
554
+ return Number.isSafeInteger(numberValue) && BigInt(numberValue) === bigintValue
555
+ ? numberValue
556
+ : bigintValue;
557
+ }, _JsonLikeParser_parseObject = function _JsonLikeParser_parseObject() {
558
+ const object = {};
559
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
560
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_skipWhitespace).call(this);
561
+ if (__classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")] === '}') {
562
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
563
+ return object;
564
+ }
565
+ while (true) {
566
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_skipWhitespace).call(this);
567
+ if (__classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")] !== '"') {
568
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Expected string key in JSON object');
569
+ }
570
+ const key = __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_parseString).call(this);
571
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_skipWhitespace).call(this);
572
+ if (__classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")] !== ':') {
573
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Expected : in JSON object');
574
+ }
575
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
576
+ object[key] = this.parseValue();
577
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_skipWhitespace).call(this);
578
+ const current = __classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")];
579
+ if (current === '}') {
580
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
581
+ return object;
582
+ }
583
+ if (current !== ',') {
584
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Expected , or } in JSON object');
585
+ }
586
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
587
+ }
588
+ }, _JsonLikeParser_parseString = function _JsonLikeParser_parseString() {
589
+ const start = __classPrivateFieldGet(this, _JsonLikeParser_index, "f");
590
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
591
+ while (__classPrivateFieldGet(this, _JsonLikeParser_index, "f") < __classPrivateFieldGet(this, _JsonLikeParser_text, "f").length) {
592
+ const current = __classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")];
593
+ if (current === '"') {
594
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
595
+ return JSON.parse(__classPrivateFieldGet(this, _JsonLikeParser_text, "f").slice(start, __classPrivateFieldGet(this, _JsonLikeParser_index, "f")));
596
+ }
597
+ if (current === '\\') {
598
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
599
+ const escaped = __classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")];
600
+ if (escaped === undefined) {
601
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Unterminated string escape');
602
+ }
603
+ if (escaped === 'u') {
604
+ for (let index = 0; index < 4; index += 1) {
605
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
606
+ if (!/[0-9A-Fa-f]/u.test(__classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")] ?? '')) {
607
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Invalid unicode escape');
608
+ }
609
+ }
610
+ }
611
+ }
612
+ else if (current <= '\u001F') {
613
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Invalid control character in string literal');
614
+ }
615
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
616
+ }
617
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Unterminated string literal');
618
+ }, _JsonLikeParser_consumeDigits = function _JsonLikeParser_consumeDigits() {
619
+ const start = __classPrivateFieldGet(this, _JsonLikeParser_index, "f");
620
+ while (__classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_isDigit).call(this, __classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")])) {
621
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
622
+ }
623
+ if (start === __classPrivateFieldGet(this, _JsonLikeParser_index, "f")) {
624
+ __classPrivateFieldGet(this, _JsonLikeParser_instances, "m", _JsonLikeParser_error).call(this, 'Expected digit in JSON number');
625
+ }
626
+ }, _JsonLikeParser_skipWhitespace = function _JsonLikeParser_skipWhitespace() {
627
+ while (/\s/u.test(__classPrivateFieldGet(this, _JsonLikeParser_text, "f")[__classPrivateFieldGet(this, _JsonLikeParser_index, "f")] ?? '')) {
628
+ __classPrivateFieldSet(this, _JsonLikeParser_index, __classPrivateFieldGet(this, _JsonLikeParser_index, "f") + 1, "f");
629
+ }
630
+ }, _JsonLikeParser_isDigit = function _JsonLikeParser_isDigit(value) {
631
+ return value !== undefined && value >= '0' && value <= '9';
632
+ }, _JsonLikeParser_error = function _JsonLikeParser_error(message) {
633
+ throw new SyntaxError(`${message} at position ${__classPrivateFieldGet(this, _JsonLikeParser_index, "f")}.`);
634
+ };
635
+ function isAsciiDigit(text) {
636
+ return text >= '0' && text <= '9';
637
+ }
638
+ //# sourceMappingURL=json.js.map