@angular-devkit/core 14.0.0-next.0 → 14.0.0-next.11

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 (47) hide show
  1. package/node/BUILD.bazel +0 -1
  2. package/node/experimental/index.js +5 -1
  3. package/node/experimental/jobs/index.js +5 -1
  4. package/node/host.js +10 -42
  5. package/node/index.js +5 -1
  6. package/node/testing/index.js +5 -1
  7. package/package.json +4 -5
  8. package/src/analytics/index.d.ts +1 -1
  9. package/src/analytics/index.js +7 -3
  10. package/src/{exception/exception.d.ts → exception.d.ts} +15 -0
  11. package/src/{exception/exception.js → exception.js} +15 -0
  12. package/src/experimental/jobs/create-job-handler.d.ts +1 -1
  13. package/src/experimental/jobs/create-job-handler.js +4 -4
  14. package/src/experimental/jobs/exception.d.ts +1 -1
  15. package/src/experimental/jobs/exception.js +3 -3
  16. package/src/experimental/jobs/index.js +5 -1
  17. package/src/experimental/jobs/strategy.d.ts +2 -2
  18. package/src/experimental/jobs/strategy.js +11 -4
  19. package/src/experimental.js +5 -1
  20. package/src/index.d.ts +1 -1
  21. package/src/index.js +6 -2
  22. package/src/json/index.js +5 -1
  23. package/src/json/schema/index.js +5 -1
  24. package/src/json/schema/registry.d.ts +1 -1
  25. package/src/json/schema/registry.js +6 -2
  26. package/src/logger/index.js +5 -1
  27. package/src/utils/index.js +5 -1
  28. package/src/utils/strings.d.ts +1 -1
  29. package/src/utils/strings.js +2 -2
  30. package/src/virtual-fs/host/index.js +5 -1
  31. package/src/virtual-fs/index.js +5 -1
  32. package/src/virtual-fs/path.js +4 -4
  33. package/src/workspace/definitions.d.ts +1 -1
  34. package/src/workspace/definitions.js +8 -7
  35. package/src/workspace/index.js +5 -1
  36. package/src/workspace/json/metadata.d.ts +12 -13
  37. package/src/workspace/json/metadata.js +28 -19
  38. package/src/workspace/json/reader.js +71 -86
  39. package/src/workspace/json/utilities.d.ts +3 -7
  40. package/src/workspace/json/utilities.js +62 -180
  41. package/src/workspace/json/writer.js +26 -192
  42. package/src/exception/index.d.ts +0 -8
  43. package/src/exception/index.js +0 -20
  44. package/src/json/parser.d.ts +0 -104
  45. package/src/json/parser.js +0 -788
  46. package/src/json/parser_ast.d.ts +0 -67
  47. package/src/json/parser_ast.js +0 -9
@@ -1,788 +0,0 @@
1
- "use strict";
2
- /**
3
- * @license
4
- * Copyright Google LLC All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.parseJson = exports.parseJsonAst = exports.JsonParseMode = exports.PathSpecificJsonException = exports.UnexpectedEndOfInputException = exports.InvalidJsonCharacterException = exports.JsonException = void 0;
11
- /* eslint-disable no-constant-condition */
12
- const exception_1 = require("../exception");
13
- class JsonException extends exception_1.BaseException {
14
- }
15
- exports.JsonException = JsonException;
16
- /**
17
- * A character was invalid in this context.
18
- * @deprecated
19
- * @private
20
- */
21
- class InvalidJsonCharacterException extends JsonException {
22
- constructor(context) {
23
- const pos = context.previous;
24
- const invalidChar = JSON.stringify(_peek(context));
25
- super(`Invalid JSON character: ${invalidChar} at ${pos.line}:${pos.character}.`);
26
- this.invalidChar = invalidChar;
27
- this.line = pos.line;
28
- this.offset = pos.offset;
29
- this.character = pos.character;
30
- }
31
- }
32
- exports.InvalidJsonCharacterException = InvalidJsonCharacterException;
33
- /**
34
- * More input was expected, but we reached the end of the stream.
35
- * @deprecated
36
- * @private
37
- */
38
- class UnexpectedEndOfInputException extends JsonException {
39
- constructor(_context) {
40
- super(`Unexpected end of file.`);
41
- }
42
- }
43
- exports.UnexpectedEndOfInputException = UnexpectedEndOfInputException;
44
- /**
45
- * An error happened within a file.
46
- * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
47
- */
48
- class PathSpecificJsonException extends JsonException {
49
- constructor(path, exception) {
50
- super(`An error happened at file path ${JSON.stringify(path)}: ${exception.message}`);
51
- this.path = path;
52
- this.exception = exception;
53
- }
54
- }
55
- exports.PathSpecificJsonException = PathSpecificJsonException;
56
- /**
57
- * Peek and return the next character from the context.
58
- * @private
59
- */
60
- function _peek(context) {
61
- return context.original[context.position.offset];
62
- }
63
- /**
64
- * Move the context to the next character, including incrementing the line if necessary.
65
- * @private
66
- */
67
- function _next(context) {
68
- context.previous = context.position;
69
- let { offset, line, character } = context.position;
70
- const char = context.original[offset];
71
- offset++;
72
- if (char == '\n') {
73
- line++;
74
- character = 0;
75
- }
76
- else {
77
- character++;
78
- }
79
- context.position = { offset, line, character };
80
- }
81
- function _token(context, valid) {
82
- const char = _peek(context);
83
- if (valid) {
84
- if (!char) {
85
- throw new UnexpectedEndOfInputException(context);
86
- }
87
- if (valid.indexOf(char) == -1) {
88
- throw new InvalidJsonCharacterException(context);
89
- }
90
- }
91
- // Move the position of the context to the next character.
92
- _next(context);
93
- return char;
94
- }
95
- /**
96
- * Read the exponent part of a number. The exponent part is looser for JSON than the number
97
- * part. `str` is the string of the number itself found so far, and start the position
98
- * where the full number started. Returns the node found.
99
- * @private
100
- */
101
- function _readExpNumber(context, start, str, comments) {
102
- let char;
103
- let signed = false;
104
- while (true) {
105
- char = _token(context);
106
- if (char == '+' || char == '-') {
107
- if (signed) {
108
- break;
109
- }
110
- signed = true;
111
- str += char;
112
- }
113
- else if (char == '0' ||
114
- char == '1' ||
115
- char == '2' ||
116
- char == '3' ||
117
- char == '4' ||
118
- char == '5' ||
119
- char == '6' ||
120
- char == '7' ||
121
- char == '8' ||
122
- char == '9') {
123
- signed = true;
124
- str += char;
125
- }
126
- else {
127
- break;
128
- }
129
- }
130
- // We're done reading this number.
131
- context.position = context.previous;
132
- return {
133
- kind: 'number',
134
- start,
135
- end: context.position,
136
- text: context.original.substring(start.offset, context.position.offset),
137
- value: Number.parseFloat(str),
138
- comments: comments,
139
- };
140
- }
141
- /**
142
- * Read the hexa part of a 0xBADCAFE hexadecimal number.
143
- * @private
144
- */
145
- function _readHexaNumber(context, isNegative, start, comments) {
146
- // Read an hexadecimal number, until it's not hexadecimal.
147
- let hexa = '';
148
- const valid = '0123456789abcdefABCDEF';
149
- for (let ch = _peek(context); ch && valid.includes(ch); ch = _peek(context)) {
150
- // Add it to the hexa string.
151
- hexa += ch;
152
- // Move the position of the context to the next character.
153
- _next(context);
154
- }
155
- const value = Number.parseInt(hexa, 16);
156
- // We're done reading this number.
157
- return {
158
- kind: 'number',
159
- start,
160
- end: context.position,
161
- text: context.original.substring(start.offset, context.position.offset),
162
- value: isNegative ? -value : value,
163
- comments,
164
- };
165
- }
166
- /**
167
- * Read a number from the context.
168
- * @private
169
- */
170
- function _readNumber(context, comments = _readBlanks(context)) {
171
- let str = '';
172
- let dotted = false;
173
- const start = context.position;
174
- // read until `e` or end of line.
175
- while (true) {
176
- const char = _token(context);
177
- // Read tokens, one by one.
178
- if (char == '-') {
179
- if (str != '') {
180
- throw new InvalidJsonCharacterException(context);
181
- }
182
- }
183
- else if (char == 'I' &&
184
- (str == '-' || str == '' || str == '+') &&
185
- (context.mode & JsonParseMode.NumberConstantsAllowed) != 0) {
186
- // Infinity?
187
- // _token(context, 'I'); Already read.
188
- _token(context, 'n');
189
- _token(context, 'f');
190
- _token(context, 'i');
191
- _token(context, 'n');
192
- _token(context, 'i');
193
- _token(context, 't');
194
- _token(context, 'y');
195
- str += 'Infinity';
196
- break;
197
- }
198
- else if (char == '0') {
199
- if (str == '0' || str == '-0') {
200
- throw new InvalidJsonCharacterException(context);
201
- }
202
- }
203
- else if (char == '1' ||
204
- char == '2' ||
205
- char == '3' ||
206
- char == '4' ||
207
- char == '5' ||
208
- char == '6' ||
209
- char == '7' ||
210
- char == '8' ||
211
- char == '9') {
212
- if (str == '0' || str == '-0') {
213
- throw new InvalidJsonCharacterException(context);
214
- }
215
- }
216
- else if (char == '+' && str == '') {
217
- // Pass over.
218
- }
219
- else if (char == '.') {
220
- if (dotted) {
221
- throw new InvalidJsonCharacterException(context);
222
- }
223
- dotted = true;
224
- }
225
- else if (char == 'e' || char == 'E') {
226
- return _readExpNumber(context, start, str + char, comments);
227
- }
228
- else if (char == 'x' &&
229
- (str == '0' || str == '-0') &&
230
- (context.mode & JsonParseMode.HexadecimalNumberAllowed) != 0) {
231
- return _readHexaNumber(context, str == '-0', start, comments);
232
- }
233
- else {
234
- // We read one too many characters, so rollback the last character.
235
- context.position = context.previous;
236
- break;
237
- }
238
- str += char;
239
- }
240
- // We're done reading this number.
241
- if (str.endsWith('.') && (context.mode & JsonParseMode.HexadecimalNumberAllowed) == 0) {
242
- throw new InvalidJsonCharacterException(context);
243
- }
244
- return {
245
- kind: 'number',
246
- start,
247
- end: context.position,
248
- text: context.original.substring(start.offset, context.position.offset),
249
- value: Number.parseFloat(str),
250
- comments,
251
- };
252
- }
253
- /**
254
- * Read a string from the context. Takes the comments of the string or read the blanks before the
255
- * string.
256
- * @private
257
- */
258
- function _readString(context, comments = _readBlanks(context)) {
259
- const start = context.position;
260
- // Consume the first string delimiter.
261
- const delim = _token(context);
262
- if ((context.mode & JsonParseMode.SingleQuotesAllowed) == 0) {
263
- if (delim == "'") {
264
- throw new InvalidJsonCharacterException(context);
265
- }
266
- }
267
- let str = '';
268
- while (true) {
269
- let char = _token(context);
270
- if (char == delim) {
271
- return {
272
- kind: 'string',
273
- start,
274
- end: context.position,
275
- text: context.original.substring(start.offset, context.position.offset),
276
- value: str,
277
- comments: comments,
278
- };
279
- }
280
- else if (char == '\\') {
281
- char = _token(context);
282
- switch (char) {
283
- case '\\':
284
- case '/':
285
- case '"':
286
- case delim:
287
- str += char;
288
- break;
289
- case 'b':
290
- str += '\b';
291
- break;
292
- case 'f':
293
- str += '\f';
294
- break;
295
- case 'n':
296
- str += '\n';
297
- break;
298
- case 'r':
299
- str += '\r';
300
- break;
301
- case 't':
302
- str += '\t';
303
- break;
304
- case 'u':
305
- const [c0] = _token(context, '0123456789abcdefABCDEF');
306
- const [c1] = _token(context, '0123456789abcdefABCDEF');
307
- const [c2] = _token(context, '0123456789abcdefABCDEF');
308
- const [c3] = _token(context, '0123456789abcdefABCDEF');
309
- str += String.fromCharCode(parseInt(c0 + c1 + c2 + c3, 16));
310
- break;
311
- case undefined:
312
- throw new UnexpectedEndOfInputException(context);
313
- case '\n':
314
- // Only valid when multiline strings are allowed.
315
- if ((context.mode & JsonParseMode.MultiLineStringAllowed) == 0) {
316
- throw new InvalidJsonCharacterException(context);
317
- }
318
- str += char;
319
- break;
320
- default:
321
- throw new InvalidJsonCharacterException(context);
322
- }
323
- }
324
- else if (char === undefined) {
325
- throw new UnexpectedEndOfInputException(context);
326
- }
327
- else if (char == '\b' || char == '\f' || char == '\n' || char == '\r' || char == '\t') {
328
- throw new InvalidJsonCharacterException(context);
329
- }
330
- else {
331
- str += char;
332
- }
333
- }
334
- }
335
- /**
336
- * Read the constant `true` from the context.
337
- * @private
338
- */
339
- function _readTrue(context, comments = _readBlanks(context)) {
340
- const start = context.position;
341
- _token(context, 't');
342
- _token(context, 'r');
343
- _token(context, 'u');
344
- _token(context, 'e');
345
- const end = context.position;
346
- return {
347
- kind: 'true',
348
- start,
349
- end,
350
- text: context.original.substring(start.offset, end.offset),
351
- value: true,
352
- comments,
353
- };
354
- }
355
- /**
356
- * Read the constant `false` from the context.
357
- * @private
358
- */
359
- function _readFalse(context, comments = _readBlanks(context)) {
360
- const start = context.position;
361
- _token(context, 'f');
362
- _token(context, 'a');
363
- _token(context, 'l');
364
- _token(context, 's');
365
- _token(context, 'e');
366
- const end = context.position;
367
- return {
368
- kind: 'false',
369
- start,
370
- end,
371
- text: context.original.substring(start.offset, end.offset),
372
- value: false,
373
- comments,
374
- };
375
- }
376
- /**
377
- * Read the constant `null` from the context.
378
- * @private
379
- */
380
- function _readNull(context, comments = _readBlanks(context)) {
381
- const start = context.position;
382
- _token(context, 'n');
383
- _token(context, 'u');
384
- _token(context, 'l');
385
- _token(context, 'l');
386
- const end = context.position;
387
- return {
388
- kind: 'null',
389
- start,
390
- end,
391
- text: context.original.substring(start.offset, end.offset),
392
- value: null,
393
- comments: comments,
394
- };
395
- }
396
- /**
397
- * Read the constant `NaN` from the context.
398
- * @private
399
- */
400
- function _readNaN(context, comments = _readBlanks(context)) {
401
- const start = context.position;
402
- _token(context, 'N');
403
- _token(context, 'a');
404
- _token(context, 'N');
405
- const end = context.position;
406
- return {
407
- kind: 'number',
408
- start,
409
- end,
410
- text: context.original.substring(start.offset, end.offset),
411
- value: NaN,
412
- comments: comments,
413
- };
414
- }
415
- /**
416
- * Read an array of JSON values from the context.
417
- * @private
418
- */
419
- function _readArray(context, comments = _readBlanks(context)) {
420
- const start = context.position;
421
- // Consume the first delimiter.
422
- _token(context, '[');
423
- const value = [];
424
- const elements = [];
425
- _readBlanks(context);
426
- if (_peek(context) != ']') {
427
- const node = _readValue(context);
428
- elements.push(node);
429
- value.push(node.value);
430
- }
431
- while (_peek(context) != ']') {
432
- _token(context, ',');
433
- const valueComments = _readBlanks(context);
434
- if ((context.mode & JsonParseMode.TrailingCommasAllowed) !== 0 && _peek(context) === ']') {
435
- break;
436
- }
437
- const node = _readValue(context, valueComments);
438
- elements.push(node);
439
- value.push(node.value);
440
- }
441
- _token(context, ']');
442
- return {
443
- kind: 'array',
444
- start,
445
- end: context.position,
446
- text: context.original.substring(start.offset, context.position.offset),
447
- value,
448
- elements,
449
- comments,
450
- };
451
- }
452
- /**
453
- * Read an identifier from the context. An identifier is a valid JavaScript identifier, and this
454
- * function is only used in Loose mode.
455
- * @private
456
- */
457
- function _readIdentifier(context, comments = _readBlanks(context)) {
458
- const start = context.position;
459
- let char = _peek(context);
460
- if (char && '0123456789'.indexOf(char) != -1) {
461
- const identifierNode = _readNumber(context);
462
- return {
463
- kind: 'identifier',
464
- start,
465
- end: identifierNode.end,
466
- text: identifierNode.text,
467
- value: identifierNode.value.toString(),
468
- };
469
- }
470
- const identValidFirstChar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ';
471
- const identValidChar = '_$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ0123456789';
472
- let first = true;
473
- let value = '';
474
- while (true) {
475
- char = _token(context);
476
- if (char == undefined ||
477
- (first ? identValidFirstChar.indexOf(char) : identValidChar.indexOf(char)) == -1) {
478
- context.position = context.previous;
479
- return {
480
- kind: 'identifier',
481
- start,
482
- end: context.position,
483
- text: context.original.substr(start.offset, context.position.offset),
484
- value,
485
- comments,
486
- };
487
- }
488
- value += char;
489
- first = false;
490
- }
491
- }
492
- /**
493
- * Read a property from the context. A property is a string or (in Loose mode only) a number or
494
- * an identifier, followed by a colon `:`.
495
- * @private
496
- */
497
- function _readProperty(context, comments = _readBlanks(context)) {
498
- const start = context.position;
499
- let key;
500
- if ((context.mode & JsonParseMode.IdentifierKeyNamesAllowed) != 0) {
501
- const top = _peek(context);
502
- if (top == '"' || top == "'") {
503
- key = _readString(context);
504
- }
505
- else {
506
- key = _readIdentifier(context);
507
- }
508
- }
509
- else {
510
- key = _readString(context);
511
- }
512
- _readBlanks(context);
513
- _token(context, ':');
514
- const value = _readValue(context);
515
- const end = context.position;
516
- return {
517
- kind: 'keyvalue',
518
- key,
519
- value,
520
- start,
521
- end,
522
- text: context.original.substring(start.offset, end.offset),
523
- comments,
524
- };
525
- }
526
- /**
527
- * Read an object of properties -> JSON values from the context.
528
- * @private
529
- */
530
- function _readObject(context, comments = _readBlanks(context)) {
531
- const start = context.position;
532
- // Consume the first delimiter.
533
- _token(context, '{');
534
- const value = {};
535
- const properties = [];
536
- _readBlanks(context);
537
- if (_peek(context) != '}') {
538
- const property = _readProperty(context);
539
- value[property.key.value] = property.value.value;
540
- properties.push(property);
541
- while (_peek(context) != '}') {
542
- _token(context, ',');
543
- const propertyComments = _readBlanks(context);
544
- if ((context.mode & JsonParseMode.TrailingCommasAllowed) !== 0 && _peek(context) === '}') {
545
- break;
546
- }
547
- const property = _readProperty(context, propertyComments);
548
- value[property.key.value] = property.value.value;
549
- properties.push(property);
550
- }
551
- }
552
- _token(context, '}');
553
- return {
554
- kind: 'object',
555
- properties,
556
- start,
557
- end: context.position,
558
- value,
559
- text: context.original.substring(start.offset, context.position.offset),
560
- comments,
561
- };
562
- }
563
- /**
564
- * Remove any blank character or comments (in Loose mode) from the context, returning an array
565
- * of comments if any are found.
566
- * @private
567
- */
568
- function _readBlanks(context) {
569
- if ((context.mode & JsonParseMode.CommentsAllowed) != 0) {
570
- const comments = [];
571
- while (true) {
572
- const char = context.original[context.position.offset];
573
- if (char == '/' && context.original[context.position.offset + 1] == '*') {
574
- const start = context.position;
575
- // Multi line comment.
576
- _next(context);
577
- _next(context);
578
- while (context.original[context.position.offset] != '*' ||
579
- context.original[context.position.offset + 1] != '/') {
580
- _next(context);
581
- if (context.position.offset >= context.original.length) {
582
- throw new UnexpectedEndOfInputException(context);
583
- }
584
- }
585
- // Remove "*/".
586
- _next(context);
587
- _next(context);
588
- comments.push({
589
- kind: 'multicomment',
590
- start,
591
- end: context.position,
592
- text: context.original.substring(start.offset, context.position.offset),
593
- content: context.original.substring(start.offset + 2, context.position.offset - 2),
594
- });
595
- }
596
- else if (char == '/' && context.original[context.position.offset + 1] == '/') {
597
- const start = context.position;
598
- // Multi line comment.
599
- _next(context);
600
- _next(context);
601
- while (context.original[context.position.offset] != '\n') {
602
- _next(context);
603
- if (context.position.offset >= context.original.length) {
604
- break;
605
- }
606
- }
607
- // Remove "\n".
608
- if (context.position.offset < context.original.length) {
609
- _next(context);
610
- }
611
- comments.push({
612
- kind: 'comment',
613
- start,
614
- end: context.position,
615
- text: context.original.substring(start.offset, context.position.offset),
616
- content: context.original.substring(start.offset + 2, context.position.offset - 1),
617
- });
618
- }
619
- else if (char == ' ' || char == '\t' || char == '\n' || char == '\r' || char == '\f') {
620
- _next(context);
621
- }
622
- else {
623
- break;
624
- }
625
- }
626
- return comments;
627
- }
628
- else {
629
- let char = context.original[context.position.offset];
630
- while (char == ' ' || char == '\t' || char == '\n' || char == '\r' || char == '\f') {
631
- _next(context);
632
- char = context.original[context.position.offset];
633
- }
634
- return [];
635
- }
636
- }
637
- /**
638
- * Read a JSON value from the context, which can be any form of JSON value.
639
- * @private
640
- */
641
- function _readValue(context, comments = _readBlanks(context)) {
642
- let result;
643
- // Clean up before.
644
- const char = _peek(context);
645
- switch (char) {
646
- case undefined:
647
- throw new UnexpectedEndOfInputException(context);
648
- case '-':
649
- case '0':
650
- case '1':
651
- case '2':
652
- case '3':
653
- case '4':
654
- case '5':
655
- case '6':
656
- case '7':
657
- case '8':
658
- case '9':
659
- result = _readNumber(context, comments);
660
- break;
661
- case '.':
662
- case '+':
663
- if ((context.mode & JsonParseMode.LaxNumberParsingAllowed) == 0) {
664
- throw new InvalidJsonCharacterException(context);
665
- }
666
- result = _readNumber(context, comments);
667
- break;
668
- case "'":
669
- case '"':
670
- result = _readString(context, comments);
671
- break;
672
- case 'I':
673
- if ((context.mode & JsonParseMode.NumberConstantsAllowed) == 0) {
674
- throw new InvalidJsonCharacterException(context);
675
- }
676
- result = _readNumber(context, comments);
677
- break;
678
- case 'N':
679
- if ((context.mode & JsonParseMode.NumberConstantsAllowed) == 0) {
680
- throw new InvalidJsonCharacterException(context);
681
- }
682
- result = _readNaN(context, comments);
683
- break;
684
- case 't':
685
- result = _readTrue(context, comments);
686
- break;
687
- case 'f':
688
- result = _readFalse(context, comments);
689
- break;
690
- case 'n':
691
- result = _readNull(context, comments);
692
- break;
693
- case '[':
694
- result = _readArray(context, comments);
695
- break;
696
- case '{':
697
- result = _readObject(context, comments);
698
- break;
699
- default:
700
- throw new InvalidJsonCharacterException(context);
701
- }
702
- // Clean up after.
703
- _readBlanks(context);
704
- return result;
705
- }
706
- /**
707
- * The Parse mode used for parsing the JSON string.
708
- */
709
- var JsonParseMode;
710
- (function (JsonParseMode) {
711
- JsonParseMode[JsonParseMode["Strict"] = 0] = "Strict";
712
- JsonParseMode[JsonParseMode["CommentsAllowed"] = 1] = "CommentsAllowed";
713
- JsonParseMode[JsonParseMode["SingleQuotesAllowed"] = 2] = "SingleQuotesAllowed";
714
- JsonParseMode[JsonParseMode["IdentifierKeyNamesAllowed"] = 4] = "IdentifierKeyNamesAllowed";
715
- JsonParseMode[JsonParseMode["TrailingCommasAllowed"] = 8] = "TrailingCommasAllowed";
716
- JsonParseMode[JsonParseMode["HexadecimalNumberAllowed"] = 16] = "HexadecimalNumberAllowed";
717
- JsonParseMode[JsonParseMode["MultiLineStringAllowed"] = 32] = "MultiLineStringAllowed";
718
- JsonParseMode[JsonParseMode["LaxNumberParsingAllowed"] = 64] = "LaxNumberParsingAllowed";
719
- JsonParseMode[JsonParseMode["NumberConstantsAllowed"] = 128] = "NumberConstantsAllowed";
720
- JsonParseMode[JsonParseMode["Default"] = 0] = "Default";
721
- JsonParseMode[JsonParseMode["Loose"] = 255] = "Loose";
722
- JsonParseMode[JsonParseMode["Json"] = 0] = "Json";
723
- JsonParseMode[JsonParseMode["Json5"] = 255] = "Json5";
724
- })(JsonParseMode = exports.JsonParseMode || (exports.JsonParseMode = {}));
725
- /**
726
- * Parse the JSON string and return its AST. The AST may be losing data (end comments are
727
- * discarded for example, and space characters are not represented in the AST), but all values
728
- * will have a single node in the AST (a 1-to-1 mapping).
729
- *
730
- * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
731
- * @param input The string to use.
732
- * @param mode The mode to parse the input with. {@see JsonParseMode}.
733
- * @returns {JsonAstNode} The root node of the value of the AST.
734
- */
735
- function parseJsonAst(input, mode = JsonParseMode.Default) {
736
- if (mode == JsonParseMode.Default) {
737
- mode = JsonParseMode.Strict;
738
- }
739
- const context = {
740
- position: { offset: 0, line: 0, character: 0 },
741
- previous: { offset: 0, line: 0, character: 0 },
742
- original: input,
743
- comments: undefined,
744
- mode,
745
- };
746
- const ast = _readValue(context);
747
- if (context.position.offset < input.length) {
748
- const rest = input.substr(context.position.offset);
749
- const i = rest.length > 20 ? rest.substr(0, 20) + '...' : rest;
750
- throw new Error(`Expected end of file, got "${i}" at ` +
751
- `${context.position.line}:${context.position.character}.`);
752
- }
753
- return ast;
754
- }
755
- exports.parseJsonAst = parseJsonAst;
756
- /**
757
- * Parse a JSON string into its value. This discards the AST and only returns the value itself.
758
- *
759
- * If a path option is pass, it also absorbs JSON parsing errors and return a new error with the
760
- * path in it. Useful for showing errors when parsing from a file.
761
- *
762
- * @deprecated Deprecated since version 11. Use 3rd party JSON parsers such as `jsonc-parser` instead.
763
- * @param input The string to parse.
764
- * @param mode The mode to parse the input with. {@see JsonParseMode}.
765
- * @param options Additional optinos for parsing.
766
- * @returns {JsonValue} The value represented by the JSON string.
767
- */
768
- function parseJson(input, mode = JsonParseMode.Default, options) {
769
- try {
770
- // Try parsing for the fastest path available, if error, uses our own parser for better errors.
771
- if (mode == JsonParseMode.Strict) {
772
- try {
773
- return JSON.parse(input);
774
- }
775
- catch (err) {
776
- return parseJsonAst(input, mode).value;
777
- }
778
- }
779
- return parseJsonAst(input, mode).value;
780
- }
781
- catch (e) {
782
- if (options && options.path && e instanceof JsonException) {
783
- throw new PathSpecificJsonException(options.path, e);
784
- }
785
- throw e;
786
- }
787
- }
788
- exports.parseJson = parseJson;