@angular/core 22.0.0-next.7 → 22.0.0-next.9

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 (70) hide show
  1. package/fesm2022/_attribute-chunk.mjs +1 -1
  2. package/fesm2022/_debug_node-chunk.mjs +967 -872
  3. package/fesm2022/_debug_node-chunk.mjs.map +1 -1
  4. package/fesm2022/_effect-chunk.mjs +1 -1
  5. package/fesm2022/_not_found-chunk.mjs +1 -1
  6. package/fesm2022/_pending_tasks-chunk.mjs +10 -8
  7. package/fesm2022/_pending_tasks-chunk.mjs.map +1 -1
  8. package/fesm2022/_resource-chunk.mjs +25 -11
  9. package/fesm2022/_resource-chunk.mjs.map +1 -1
  10. package/fesm2022/_untracked-chunk.mjs +1 -1
  11. package/fesm2022/_weak_ref-chunk.mjs +1 -1
  12. package/fesm2022/core.mjs +350 -6
  13. package/fesm2022/core.mjs.map +1 -1
  14. package/fesm2022/primitives-di.mjs +1 -1
  15. package/fesm2022/primitives-event-dispatch.mjs +1 -1
  16. package/fesm2022/primitives-signals.mjs +1 -1
  17. package/fesm2022/rxjs-interop.mjs +4 -1
  18. package/fesm2022/rxjs-interop.mjs.map +1 -1
  19. package/fesm2022/testing.mjs +2 -12
  20. package/fesm2022/testing.mjs.map +1 -1
  21. package/package.json +2 -2
  22. package/schematics/bundles/apply_import_manager-CxA_YYgB.cjs +1 -1
  23. package/schematics/bundles/can-match-snapshot-required.cjs +1 -1
  24. package/schematics/bundles/change-detection-eager.cjs +1 -1
  25. package/schematics/bundles/cleanup-unused-imports.cjs +1 -1
  26. package/schematics/bundles/common-to-standalone-migration.cjs +1 -1
  27. package/schematics/bundles/compiler_host-CY14HvaP.cjs +1 -1
  28. package/schematics/bundles/control-flow-migration.cjs +1 -1
  29. package/schematics/bundles/http-xhr-backend.cjs +1 -1
  30. package/schematics/bundles/imports-CKV-ITqD.cjs +1 -1
  31. package/schematics/bundles/incremental-hydration.cjs +91 -0
  32. package/schematics/bundles/index-DADA7AvC.cjs +1 -1
  33. package/schematics/bundles/inject-migration.cjs +1 -1
  34. package/schematics/bundles/json-file-Drblb4E1.cjs +1916 -0
  35. package/schematics/bundles/leading_space-BTPRV0wu.cjs +1 -1
  36. package/schematics/bundles/migrate_ts_type_references-B9LlDDUg.cjs +1 -1
  37. package/schematics/bundles/ng_component_template-DPAF1aEA.cjs +1 -1
  38. package/schematics/bundles/ng_decorators-IVztR9rk.cjs +1 -1
  39. package/schematics/bundles/ngclass-to-class-migration.cjs +14 -6
  40. package/schematics/bundles/ngstyle-to-style-migration.cjs +1 -1
  41. package/schematics/bundles/nodes-ZSQ7WZRB.cjs +1 -1
  42. package/schematics/bundles/output-migration.cjs +1 -1
  43. package/schematics/bundles/parse_html-C8eKA9px.cjs +1 -1
  44. package/schematics/bundles/project_paths-D2V-Uh2L.cjs +1 -1
  45. package/schematics/bundles/project_tsconfig_paths-DkkMibv-.cjs +1 -1
  46. package/schematics/bundles/property_name-BCpALNpZ.cjs +1 -1
  47. package/schematics/bundles/route-lazy-loading.cjs +1 -1
  48. package/schematics/bundles/router-testing-module-migration.cjs +1 -1
  49. package/schematics/bundles/self-closing-tags-migration.cjs +1 -1
  50. package/schematics/bundles/signal-input-migration.cjs +1 -1
  51. package/schematics/bundles/signal-queries-migration.cjs +1 -1
  52. package/schematics/bundles/signals.cjs +1 -1
  53. package/schematics/bundles/standalone-migration.cjs +1 -1
  54. package/schematics/bundles/strict-safe-navigation-narrow.cjs +32 -0
  55. package/schematics/bundles/strict-templates-default.cjs +63 -0
  56. package/schematics/migrations.json +13 -3
  57. package/types/_api-chunk.d.ts +9 -3
  58. package/types/_chrome_dev_tools_performance-chunk.d.ts +2 -2
  59. package/types/_debug_node-chunk.d.ts +132 -212
  60. package/types/_effect-chunk.d.ts +1 -1
  61. package/types/_event_dispatcher-chunk.d.ts +1 -1
  62. package/types/_formatter-chunk.d.ts +1 -1
  63. package/types/_weak_ref-chunk.d.ts +1 -1
  64. package/types/core.d.ts +876 -749
  65. package/types/primitives-di.d.ts +1 -1
  66. package/types/primitives-event-dispatch.d.ts +1 -1
  67. package/types/primitives-signals.d.ts +1 -1
  68. package/types/rxjs-interop.d.ts +1 -1
  69. package/types/testing.d.ts +2 -2
  70. package/schematics/bundles/strict-templates.cjs +0 -55
@@ -0,0 +1,1916 @@
1
+ 'use strict';
2
+ /**
3
+ * @license Angular v22.0.0-next.9
4
+ * (c) 2010-2026 Google LLC. https://angular.dev/
5
+ * License: MIT
6
+ */
7
+ 'use strict';
8
+
9
+ var require$$0$1 = require('node:os');
10
+
11
+ function getAugmentedNamespace(n) {
12
+ if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
13
+ var f = n.default;
14
+ if (typeof f == "function") {
15
+ var a = function a () {
16
+ var isInstance = false;
17
+ try {
18
+ isInstance = this instanceof a;
19
+ } catch {}
20
+ if (isInstance) {
21
+ return Reflect.construct(f, arguments, this.constructor);
22
+ }
23
+ return f.apply(this, arguments);
24
+ };
25
+ a.prototype = f.prototype;
26
+ } else a = {};
27
+ Object.defineProperty(a, '__esModule', {value: true});
28
+ Object.keys(n).forEach(function (k) {
29
+ var d = Object.getOwnPropertyDescriptor(n, k);
30
+ Object.defineProperty(a, k, d.get ? d : {
31
+ enumerable: true,
32
+ get: function () {
33
+ return n[k];
34
+ }
35
+ });
36
+ });
37
+ return a;
38
+ }
39
+
40
+ var jsonFile = {};
41
+
42
+ /*---------------------------------------------------------------------------------------------
43
+ * Copyright (c) Microsoft Corporation. All rights reserved.
44
+ * Licensed under the MIT License. See License.txt in the project root for license information.
45
+ *--------------------------------------------------------------------------------------------*/
46
+ /**
47
+ * Creates a JSON scanner on the given text.
48
+ * If ignoreTrivia is set, whitespaces or comments are ignored.
49
+ */
50
+ function createScanner$1(text, ignoreTrivia = false) {
51
+ const len = text.length;
52
+ let pos = 0, value = '', tokenOffset = 0, token = 16 /* SyntaxKind.Unknown */, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0 /* ScanError.None */;
53
+ function scanHexDigits(count, exact) {
54
+ let digits = 0;
55
+ let value = 0;
56
+ while (digits < count || false) {
57
+ let ch = text.charCodeAt(pos);
58
+ if (ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */) {
59
+ value = value * 16 + ch - 48 /* CharacterCodes._0 */;
60
+ }
61
+ else if (ch >= 65 /* CharacterCodes.A */ && ch <= 70 /* CharacterCodes.F */) {
62
+ value = value * 16 + ch - 65 /* CharacterCodes.A */ + 10;
63
+ }
64
+ else if (ch >= 97 /* CharacterCodes.a */ && ch <= 102 /* CharacterCodes.f */) {
65
+ value = value * 16 + ch - 97 /* CharacterCodes.a */ + 10;
66
+ }
67
+ else {
68
+ break;
69
+ }
70
+ pos++;
71
+ digits++;
72
+ }
73
+ if (digits < count) {
74
+ value = -1;
75
+ }
76
+ return value;
77
+ }
78
+ function setPosition(newPosition) {
79
+ pos = newPosition;
80
+ value = '';
81
+ tokenOffset = 0;
82
+ token = 16 /* SyntaxKind.Unknown */;
83
+ scanError = 0 /* ScanError.None */;
84
+ }
85
+ function scanNumber() {
86
+ let start = pos;
87
+ if (text.charCodeAt(pos) === 48 /* CharacterCodes._0 */) {
88
+ pos++;
89
+ }
90
+ else {
91
+ pos++;
92
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
93
+ pos++;
94
+ }
95
+ }
96
+ if (pos < text.length && text.charCodeAt(pos) === 46 /* CharacterCodes.dot */) {
97
+ pos++;
98
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
99
+ pos++;
100
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
101
+ pos++;
102
+ }
103
+ }
104
+ else {
105
+ scanError = 3 /* ScanError.UnexpectedEndOfNumber */;
106
+ return text.substring(start, pos);
107
+ }
108
+ }
109
+ let end = pos;
110
+ if (pos < text.length && (text.charCodeAt(pos) === 69 /* CharacterCodes.E */ || text.charCodeAt(pos) === 101 /* CharacterCodes.e */)) {
111
+ pos++;
112
+ if (pos < text.length && text.charCodeAt(pos) === 43 /* CharacterCodes.plus */ || text.charCodeAt(pos) === 45 /* CharacterCodes.minus */) {
113
+ pos++;
114
+ }
115
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
116
+ pos++;
117
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
118
+ pos++;
119
+ }
120
+ end = pos;
121
+ }
122
+ else {
123
+ scanError = 3 /* ScanError.UnexpectedEndOfNumber */;
124
+ }
125
+ }
126
+ return text.substring(start, end);
127
+ }
128
+ function scanString() {
129
+ let result = '', start = pos;
130
+ while (true) {
131
+ if (pos >= len) {
132
+ result += text.substring(start, pos);
133
+ scanError = 2 /* ScanError.UnexpectedEndOfString */;
134
+ break;
135
+ }
136
+ const ch = text.charCodeAt(pos);
137
+ if (ch === 34 /* CharacterCodes.doubleQuote */) {
138
+ result += text.substring(start, pos);
139
+ pos++;
140
+ break;
141
+ }
142
+ if (ch === 92 /* CharacterCodes.backslash */) {
143
+ result += text.substring(start, pos);
144
+ pos++;
145
+ if (pos >= len) {
146
+ scanError = 2 /* ScanError.UnexpectedEndOfString */;
147
+ break;
148
+ }
149
+ const ch2 = text.charCodeAt(pos++);
150
+ switch (ch2) {
151
+ case 34 /* CharacterCodes.doubleQuote */:
152
+ result += '\"';
153
+ break;
154
+ case 92 /* CharacterCodes.backslash */:
155
+ result += '\\';
156
+ break;
157
+ case 47 /* CharacterCodes.slash */:
158
+ result += '/';
159
+ break;
160
+ case 98 /* CharacterCodes.b */:
161
+ result += '\b';
162
+ break;
163
+ case 102 /* CharacterCodes.f */:
164
+ result += '\f';
165
+ break;
166
+ case 110 /* CharacterCodes.n */:
167
+ result += '\n';
168
+ break;
169
+ case 114 /* CharacterCodes.r */:
170
+ result += '\r';
171
+ break;
172
+ case 116 /* CharacterCodes.t */:
173
+ result += '\t';
174
+ break;
175
+ case 117 /* CharacterCodes.u */:
176
+ const ch3 = scanHexDigits(4);
177
+ if (ch3 >= 0) {
178
+ result += String.fromCharCode(ch3);
179
+ }
180
+ else {
181
+ scanError = 4 /* ScanError.InvalidUnicode */;
182
+ }
183
+ break;
184
+ default:
185
+ scanError = 5 /* ScanError.InvalidEscapeCharacter */;
186
+ }
187
+ start = pos;
188
+ continue;
189
+ }
190
+ if (ch >= 0 && ch <= 0x1f) {
191
+ if (isLineBreak(ch)) {
192
+ result += text.substring(start, pos);
193
+ scanError = 2 /* ScanError.UnexpectedEndOfString */;
194
+ break;
195
+ }
196
+ else {
197
+ scanError = 6 /* ScanError.InvalidCharacter */;
198
+ // mark as error but continue with string
199
+ }
200
+ }
201
+ pos++;
202
+ }
203
+ return result;
204
+ }
205
+ function scanNext() {
206
+ value = '';
207
+ scanError = 0 /* ScanError.None */;
208
+ tokenOffset = pos;
209
+ lineStartOffset = lineNumber;
210
+ prevTokenLineStartOffset = tokenLineStartOffset;
211
+ if (pos >= len) {
212
+ // at the end
213
+ tokenOffset = len;
214
+ return token = 17 /* SyntaxKind.EOF */;
215
+ }
216
+ let code = text.charCodeAt(pos);
217
+ // trivia: whitespace
218
+ if (isWhiteSpace(code)) {
219
+ do {
220
+ pos++;
221
+ value += String.fromCharCode(code);
222
+ code = text.charCodeAt(pos);
223
+ } while (isWhiteSpace(code));
224
+ return token = 15 /* SyntaxKind.Trivia */;
225
+ }
226
+ // trivia: newlines
227
+ if (isLineBreak(code)) {
228
+ pos++;
229
+ value += String.fromCharCode(code);
230
+ if (code === 13 /* CharacterCodes.carriageReturn */ && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) {
231
+ pos++;
232
+ value += '\n';
233
+ }
234
+ lineNumber++;
235
+ tokenLineStartOffset = pos;
236
+ return token = 14 /* SyntaxKind.LineBreakTrivia */;
237
+ }
238
+ switch (code) {
239
+ // tokens: []{}:,
240
+ case 123 /* CharacterCodes.openBrace */:
241
+ pos++;
242
+ return token = 1 /* SyntaxKind.OpenBraceToken */;
243
+ case 125 /* CharacterCodes.closeBrace */:
244
+ pos++;
245
+ return token = 2 /* SyntaxKind.CloseBraceToken */;
246
+ case 91 /* CharacterCodes.openBracket */:
247
+ pos++;
248
+ return token = 3 /* SyntaxKind.OpenBracketToken */;
249
+ case 93 /* CharacterCodes.closeBracket */:
250
+ pos++;
251
+ return token = 4 /* SyntaxKind.CloseBracketToken */;
252
+ case 58 /* CharacterCodes.colon */:
253
+ pos++;
254
+ return token = 6 /* SyntaxKind.ColonToken */;
255
+ case 44 /* CharacterCodes.comma */:
256
+ pos++;
257
+ return token = 5 /* SyntaxKind.CommaToken */;
258
+ // strings
259
+ case 34 /* CharacterCodes.doubleQuote */:
260
+ pos++;
261
+ value = scanString();
262
+ return token = 10 /* SyntaxKind.StringLiteral */;
263
+ // comments
264
+ case 47 /* CharacterCodes.slash */:
265
+ const start = pos - 1;
266
+ // Single-line comment
267
+ if (text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
268
+ pos += 2;
269
+ while (pos < len) {
270
+ if (isLineBreak(text.charCodeAt(pos))) {
271
+ break;
272
+ }
273
+ pos++;
274
+ }
275
+ value = text.substring(start, pos);
276
+ return token = 12 /* SyntaxKind.LineCommentTrivia */;
277
+ }
278
+ // Multi-line comment
279
+ if (text.charCodeAt(pos + 1) === 42 /* CharacterCodes.asterisk */) {
280
+ pos += 2;
281
+ const safeLength = len - 1; // For lookahead.
282
+ let commentClosed = false;
283
+ while (pos < safeLength) {
284
+ const ch = text.charCodeAt(pos);
285
+ if (ch === 42 /* CharacterCodes.asterisk */ && text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
286
+ pos += 2;
287
+ commentClosed = true;
288
+ break;
289
+ }
290
+ pos++;
291
+ if (isLineBreak(ch)) {
292
+ if (ch === 13 /* CharacterCodes.carriageReturn */ && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) {
293
+ pos++;
294
+ }
295
+ lineNumber++;
296
+ tokenLineStartOffset = pos;
297
+ }
298
+ }
299
+ if (!commentClosed) {
300
+ pos++;
301
+ scanError = 1 /* ScanError.UnexpectedEndOfComment */;
302
+ }
303
+ value = text.substring(start, pos);
304
+ return token = 13 /* SyntaxKind.BlockCommentTrivia */;
305
+ }
306
+ // just a single slash
307
+ value += String.fromCharCode(code);
308
+ pos++;
309
+ return token = 16 /* SyntaxKind.Unknown */;
310
+ // numbers
311
+ case 45 /* CharacterCodes.minus */:
312
+ value += String.fromCharCode(code);
313
+ pos++;
314
+ if (pos === len || !isDigit(text.charCodeAt(pos))) {
315
+ return token = 16 /* SyntaxKind.Unknown */;
316
+ }
317
+ // found a minus, followed by a number so
318
+ // we fall through to proceed with scanning
319
+ // numbers
320
+ case 48 /* CharacterCodes._0 */:
321
+ case 49 /* CharacterCodes._1 */:
322
+ case 50 /* CharacterCodes._2 */:
323
+ case 51 /* CharacterCodes._3 */:
324
+ case 52 /* CharacterCodes._4 */:
325
+ case 53 /* CharacterCodes._5 */:
326
+ case 54 /* CharacterCodes._6 */:
327
+ case 55 /* CharacterCodes._7 */:
328
+ case 56 /* CharacterCodes._8 */:
329
+ case 57 /* CharacterCodes._9 */:
330
+ value += scanNumber();
331
+ return token = 11 /* SyntaxKind.NumericLiteral */;
332
+ // literals and unknown symbols
333
+ default:
334
+ // is a literal? Read the full word.
335
+ while (pos < len && isUnknownContentCharacter(code)) {
336
+ pos++;
337
+ code = text.charCodeAt(pos);
338
+ }
339
+ if (tokenOffset !== pos) {
340
+ value = text.substring(tokenOffset, pos);
341
+ // keywords: true, false, null
342
+ switch (value) {
343
+ case 'true': return token = 8 /* SyntaxKind.TrueKeyword */;
344
+ case 'false': return token = 9 /* SyntaxKind.FalseKeyword */;
345
+ case 'null': return token = 7 /* SyntaxKind.NullKeyword */;
346
+ }
347
+ return token = 16 /* SyntaxKind.Unknown */;
348
+ }
349
+ // some
350
+ value += String.fromCharCode(code);
351
+ pos++;
352
+ return token = 16 /* SyntaxKind.Unknown */;
353
+ }
354
+ }
355
+ function isUnknownContentCharacter(code) {
356
+ if (isWhiteSpace(code) || isLineBreak(code)) {
357
+ return false;
358
+ }
359
+ switch (code) {
360
+ case 125 /* CharacterCodes.closeBrace */:
361
+ case 93 /* CharacterCodes.closeBracket */:
362
+ case 123 /* CharacterCodes.openBrace */:
363
+ case 91 /* CharacterCodes.openBracket */:
364
+ case 34 /* CharacterCodes.doubleQuote */:
365
+ case 58 /* CharacterCodes.colon */:
366
+ case 44 /* CharacterCodes.comma */:
367
+ case 47 /* CharacterCodes.slash */:
368
+ return false;
369
+ }
370
+ return true;
371
+ }
372
+ function scanNextNonTrivia() {
373
+ let result;
374
+ do {
375
+ result = scanNext();
376
+ } while (result >= 12 /* SyntaxKind.LineCommentTrivia */ && result <= 15 /* SyntaxKind.Trivia */);
377
+ return result;
378
+ }
379
+ return {
380
+ setPosition: setPosition,
381
+ getPosition: () => pos,
382
+ scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
383
+ getToken: () => token,
384
+ getTokenValue: () => value,
385
+ getTokenOffset: () => tokenOffset,
386
+ getTokenLength: () => pos - tokenOffset,
387
+ getTokenStartLine: () => lineStartOffset,
388
+ getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
389
+ getTokenError: () => scanError,
390
+ };
391
+ }
392
+ function isWhiteSpace(ch) {
393
+ return ch === 32 /* CharacterCodes.space */ || ch === 9 /* CharacterCodes.tab */;
394
+ }
395
+ function isLineBreak(ch) {
396
+ return ch === 10 /* CharacterCodes.lineFeed */ || ch === 13 /* CharacterCodes.carriageReturn */;
397
+ }
398
+ function isDigit(ch) {
399
+ return ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */;
400
+ }
401
+ var CharacterCodes;
402
+ (function (CharacterCodes) {
403
+ CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed";
404
+ CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn";
405
+ CharacterCodes[CharacterCodes["space"] = 32] = "space";
406
+ CharacterCodes[CharacterCodes["_0"] = 48] = "_0";
407
+ CharacterCodes[CharacterCodes["_1"] = 49] = "_1";
408
+ CharacterCodes[CharacterCodes["_2"] = 50] = "_2";
409
+ CharacterCodes[CharacterCodes["_3"] = 51] = "_3";
410
+ CharacterCodes[CharacterCodes["_4"] = 52] = "_4";
411
+ CharacterCodes[CharacterCodes["_5"] = 53] = "_5";
412
+ CharacterCodes[CharacterCodes["_6"] = 54] = "_6";
413
+ CharacterCodes[CharacterCodes["_7"] = 55] = "_7";
414
+ CharacterCodes[CharacterCodes["_8"] = 56] = "_8";
415
+ CharacterCodes[CharacterCodes["_9"] = 57] = "_9";
416
+ CharacterCodes[CharacterCodes["a"] = 97] = "a";
417
+ CharacterCodes[CharacterCodes["b"] = 98] = "b";
418
+ CharacterCodes[CharacterCodes["c"] = 99] = "c";
419
+ CharacterCodes[CharacterCodes["d"] = 100] = "d";
420
+ CharacterCodes[CharacterCodes["e"] = 101] = "e";
421
+ CharacterCodes[CharacterCodes["f"] = 102] = "f";
422
+ CharacterCodes[CharacterCodes["g"] = 103] = "g";
423
+ CharacterCodes[CharacterCodes["h"] = 104] = "h";
424
+ CharacterCodes[CharacterCodes["i"] = 105] = "i";
425
+ CharacterCodes[CharacterCodes["j"] = 106] = "j";
426
+ CharacterCodes[CharacterCodes["k"] = 107] = "k";
427
+ CharacterCodes[CharacterCodes["l"] = 108] = "l";
428
+ CharacterCodes[CharacterCodes["m"] = 109] = "m";
429
+ CharacterCodes[CharacterCodes["n"] = 110] = "n";
430
+ CharacterCodes[CharacterCodes["o"] = 111] = "o";
431
+ CharacterCodes[CharacterCodes["p"] = 112] = "p";
432
+ CharacterCodes[CharacterCodes["q"] = 113] = "q";
433
+ CharacterCodes[CharacterCodes["r"] = 114] = "r";
434
+ CharacterCodes[CharacterCodes["s"] = 115] = "s";
435
+ CharacterCodes[CharacterCodes["t"] = 116] = "t";
436
+ CharacterCodes[CharacterCodes["u"] = 117] = "u";
437
+ CharacterCodes[CharacterCodes["v"] = 118] = "v";
438
+ CharacterCodes[CharacterCodes["w"] = 119] = "w";
439
+ CharacterCodes[CharacterCodes["x"] = 120] = "x";
440
+ CharacterCodes[CharacterCodes["y"] = 121] = "y";
441
+ CharacterCodes[CharacterCodes["z"] = 122] = "z";
442
+ CharacterCodes[CharacterCodes["A"] = 65] = "A";
443
+ CharacterCodes[CharacterCodes["B"] = 66] = "B";
444
+ CharacterCodes[CharacterCodes["C"] = 67] = "C";
445
+ CharacterCodes[CharacterCodes["D"] = 68] = "D";
446
+ CharacterCodes[CharacterCodes["E"] = 69] = "E";
447
+ CharacterCodes[CharacterCodes["F"] = 70] = "F";
448
+ CharacterCodes[CharacterCodes["G"] = 71] = "G";
449
+ CharacterCodes[CharacterCodes["H"] = 72] = "H";
450
+ CharacterCodes[CharacterCodes["I"] = 73] = "I";
451
+ CharacterCodes[CharacterCodes["J"] = 74] = "J";
452
+ CharacterCodes[CharacterCodes["K"] = 75] = "K";
453
+ CharacterCodes[CharacterCodes["L"] = 76] = "L";
454
+ CharacterCodes[CharacterCodes["M"] = 77] = "M";
455
+ CharacterCodes[CharacterCodes["N"] = 78] = "N";
456
+ CharacterCodes[CharacterCodes["O"] = 79] = "O";
457
+ CharacterCodes[CharacterCodes["P"] = 80] = "P";
458
+ CharacterCodes[CharacterCodes["Q"] = 81] = "Q";
459
+ CharacterCodes[CharacterCodes["R"] = 82] = "R";
460
+ CharacterCodes[CharacterCodes["S"] = 83] = "S";
461
+ CharacterCodes[CharacterCodes["T"] = 84] = "T";
462
+ CharacterCodes[CharacterCodes["U"] = 85] = "U";
463
+ CharacterCodes[CharacterCodes["V"] = 86] = "V";
464
+ CharacterCodes[CharacterCodes["W"] = 87] = "W";
465
+ CharacterCodes[CharacterCodes["X"] = 88] = "X";
466
+ CharacterCodes[CharacterCodes["Y"] = 89] = "Y";
467
+ CharacterCodes[CharacterCodes["Z"] = 90] = "Z";
468
+ CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk";
469
+ CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash";
470
+ CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace";
471
+ CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket";
472
+ CharacterCodes[CharacterCodes["colon"] = 58] = "colon";
473
+ CharacterCodes[CharacterCodes["comma"] = 44] = "comma";
474
+ CharacterCodes[CharacterCodes["dot"] = 46] = "dot";
475
+ CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote";
476
+ CharacterCodes[CharacterCodes["minus"] = 45] = "minus";
477
+ CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace";
478
+ CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket";
479
+ CharacterCodes[CharacterCodes["plus"] = 43] = "plus";
480
+ CharacterCodes[CharacterCodes["slash"] = 47] = "slash";
481
+ CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed";
482
+ CharacterCodes[CharacterCodes["tab"] = 9] = "tab";
483
+ })(CharacterCodes || (CharacterCodes = {}));
484
+
485
+ const cachedSpaces = new Array(20).fill(0).map((_, index) => {
486
+ return ' '.repeat(index);
487
+ });
488
+ const maxCachedValues = 200;
489
+ const cachedBreakLinesWithSpaces = {
490
+ ' ': {
491
+ '\n': new Array(maxCachedValues).fill(0).map((_, index) => {
492
+ return '\n' + ' '.repeat(index);
493
+ }),
494
+ '\r': new Array(maxCachedValues).fill(0).map((_, index) => {
495
+ return '\r' + ' '.repeat(index);
496
+ }),
497
+ '\r\n': new Array(maxCachedValues).fill(0).map((_, index) => {
498
+ return '\r\n' + ' '.repeat(index);
499
+ }),
500
+ },
501
+ '\t': {
502
+ '\n': new Array(maxCachedValues).fill(0).map((_, index) => {
503
+ return '\n' + '\t'.repeat(index);
504
+ }),
505
+ '\r': new Array(maxCachedValues).fill(0).map((_, index) => {
506
+ return '\r' + '\t'.repeat(index);
507
+ }),
508
+ '\r\n': new Array(maxCachedValues).fill(0).map((_, index) => {
509
+ return '\r\n' + '\t'.repeat(index);
510
+ }),
511
+ }
512
+ };
513
+ const supportedEols = ['\n', '\r', '\r\n'];
514
+
515
+ /*---------------------------------------------------------------------------------------------
516
+ * Copyright (c) Microsoft Corporation. All rights reserved.
517
+ * Licensed under the MIT License. See License.txt in the project root for license information.
518
+ *--------------------------------------------------------------------------------------------*/
519
+ function format$1(documentText, range, options) {
520
+ let initialIndentLevel;
521
+ let formatText;
522
+ let formatTextStart;
523
+ let rangeStart;
524
+ let rangeEnd;
525
+ if (range) {
526
+ rangeStart = range.offset;
527
+ rangeEnd = rangeStart + range.length;
528
+ formatTextStart = rangeStart;
529
+ while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
530
+ formatTextStart--;
531
+ }
532
+ let endOffset = rangeEnd;
533
+ while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
534
+ endOffset++;
535
+ }
536
+ formatText = documentText.substring(formatTextStart, endOffset);
537
+ initialIndentLevel = computeIndentLevel(formatText, options);
538
+ }
539
+ else {
540
+ formatText = documentText;
541
+ initialIndentLevel = 0;
542
+ formatTextStart = 0;
543
+ rangeStart = 0;
544
+ rangeEnd = documentText.length;
545
+ }
546
+ const eol = getEOL(options, documentText);
547
+ const eolFastPathSupported = supportedEols.includes(eol);
548
+ let numberLineBreaks = 0;
549
+ let indentLevel = 0;
550
+ let indentValue;
551
+ if (options.insertSpaces) {
552
+ indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
553
+ }
554
+ else {
555
+ indentValue = '\t';
556
+ }
557
+ const indentType = indentValue === '\t' ? '\t' : ' ';
558
+ let scanner = createScanner$1(formatText, false);
559
+ let hasError = false;
560
+ function newLinesAndIndent() {
561
+ if (numberLineBreaks > 1) {
562
+ return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
563
+ }
564
+ const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
565
+ if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
566
+ return eol + repeat(indentValue, initialIndentLevel + indentLevel);
567
+ }
568
+ if (amountOfSpaces <= 0) {
569
+ return eol;
570
+ }
571
+ return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
572
+ }
573
+ function scanNext() {
574
+ let token = scanner.scan();
575
+ numberLineBreaks = 0;
576
+ while (token === 15 /* SyntaxKind.Trivia */ || token === 14 /* SyntaxKind.LineBreakTrivia */) {
577
+ if (token === 14 /* SyntaxKind.LineBreakTrivia */ && options.keepLines) {
578
+ numberLineBreaks += 1;
579
+ }
580
+ else if (token === 14 /* SyntaxKind.LineBreakTrivia */) {
581
+ numberLineBreaks = 1;
582
+ }
583
+ token = scanner.scan();
584
+ }
585
+ hasError = token === 16 /* SyntaxKind.Unknown */ || scanner.getTokenError() !== 0 /* ScanError.None */;
586
+ return token;
587
+ }
588
+ const editOperations = [];
589
+ function addEdit(text, startOffset, endOffset) {
590
+ if (!hasError && (!range || (startOffset < rangeEnd && endOffset > rangeStart)) && documentText.substring(startOffset, endOffset) !== text) {
591
+ editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
592
+ }
593
+ }
594
+ let firstToken = scanNext();
595
+ if (options.keepLines && numberLineBreaks > 0) {
596
+ addEdit(repeat(eol, numberLineBreaks), 0, 0);
597
+ }
598
+ if (firstToken !== 17 /* SyntaxKind.EOF */) {
599
+ let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
600
+ let initialIndent = (indentValue.length * initialIndentLevel < 20) && options.insertSpaces
601
+ ? cachedSpaces[indentValue.length * initialIndentLevel]
602
+ : repeat(indentValue, initialIndentLevel);
603
+ addEdit(initialIndent, formatTextStart, firstTokenStart);
604
+ }
605
+ while (firstToken !== 17 /* SyntaxKind.EOF */) {
606
+ let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
607
+ let secondToken = scanNext();
608
+ let replaceContent = '';
609
+ let needsLineBreak = false;
610
+ while (numberLineBreaks === 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
611
+ let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
612
+ addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
613
+ firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
614
+ needsLineBreak = secondToken === 12 /* SyntaxKind.LineCommentTrivia */;
615
+ replaceContent = needsLineBreak ? newLinesAndIndent() : '';
616
+ secondToken = scanNext();
617
+ }
618
+ if (secondToken === 2 /* SyntaxKind.CloseBraceToken */) {
619
+ if (firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
620
+ indentLevel--;
621
+ }
622
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
623
+ replaceContent = newLinesAndIndent();
624
+ }
625
+ else if (options.keepLines) {
626
+ replaceContent = cachedSpaces[1];
627
+ }
628
+ }
629
+ else if (secondToken === 4 /* SyntaxKind.CloseBracketToken */) {
630
+ if (firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
631
+ indentLevel--;
632
+ }
633
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
634
+ replaceContent = newLinesAndIndent();
635
+ }
636
+ else if (options.keepLines) {
637
+ replaceContent = cachedSpaces[1];
638
+ }
639
+ }
640
+ else {
641
+ switch (firstToken) {
642
+ case 3 /* SyntaxKind.OpenBracketToken */:
643
+ case 1 /* SyntaxKind.OpenBraceToken */:
644
+ indentLevel++;
645
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
646
+ replaceContent = newLinesAndIndent();
647
+ }
648
+ else {
649
+ replaceContent = cachedSpaces[1];
650
+ }
651
+ break;
652
+ case 5 /* SyntaxKind.CommaToken */:
653
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
654
+ replaceContent = newLinesAndIndent();
655
+ }
656
+ else {
657
+ replaceContent = cachedSpaces[1];
658
+ }
659
+ break;
660
+ case 12 /* SyntaxKind.LineCommentTrivia */:
661
+ replaceContent = newLinesAndIndent();
662
+ break;
663
+ case 13 /* SyntaxKind.BlockCommentTrivia */:
664
+ if (numberLineBreaks > 0) {
665
+ replaceContent = newLinesAndIndent();
666
+ }
667
+ else if (!needsLineBreak) {
668
+ replaceContent = cachedSpaces[1];
669
+ }
670
+ break;
671
+ case 6 /* SyntaxKind.ColonToken */:
672
+ if (options.keepLines && numberLineBreaks > 0) {
673
+ replaceContent = newLinesAndIndent();
674
+ }
675
+ else if (!needsLineBreak) {
676
+ replaceContent = cachedSpaces[1];
677
+ }
678
+ break;
679
+ case 10 /* SyntaxKind.StringLiteral */:
680
+ if (options.keepLines && numberLineBreaks > 0) {
681
+ replaceContent = newLinesAndIndent();
682
+ }
683
+ else if (secondToken === 6 /* SyntaxKind.ColonToken */ && !needsLineBreak) {
684
+ replaceContent = '';
685
+ }
686
+ break;
687
+ case 7 /* SyntaxKind.NullKeyword */:
688
+ case 8 /* SyntaxKind.TrueKeyword */:
689
+ case 9 /* SyntaxKind.FalseKeyword */:
690
+ case 11 /* SyntaxKind.NumericLiteral */:
691
+ case 2 /* SyntaxKind.CloseBraceToken */:
692
+ case 4 /* SyntaxKind.CloseBracketToken */:
693
+ if (options.keepLines && numberLineBreaks > 0) {
694
+ replaceContent = newLinesAndIndent();
695
+ }
696
+ else {
697
+ if ((secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */) && !needsLineBreak) {
698
+ replaceContent = cachedSpaces[1];
699
+ }
700
+ else if (secondToken !== 5 /* SyntaxKind.CommaToken */ && secondToken !== 17 /* SyntaxKind.EOF */) {
701
+ hasError = true;
702
+ }
703
+ }
704
+ break;
705
+ case 16 /* SyntaxKind.Unknown */:
706
+ hasError = true;
707
+ break;
708
+ }
709
+ if (numberLineBreaks > 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
710
+ replaceContent = newLinesAndIndent();
711
+ }
712
+ }
713
+ if (secondToken === 17 /* SyntaxKind.EOF */) {
714
+ if (options.keepLines && numberLineBreaks > 0) {
715
+ replaceContent = newLinesAndIndent();
716
+ }
717
+ else {
718
+ replaceContent = options.insertFinalNewline ? eol : '';
719
+ }
720
+ }
721
+ const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
722
+ addEdit(replaceContent, firstTokenEnd, secondTokenStart);
723
+ firstToken = secondToken;
724
+ }
725
+ return editOperations;
726
+ }
727
+ function repeat(s, count) {
728
+ let result = '';
729
+ for (let i = 0; i < count; i++) {
730
+ result += s;
731
+ }
732
+ return result;
733
+ }
734
+ function computeIndentLevel(content, options) {
735
+ let i = 0;
736
+ let nChars = 0;
737
+ const tabSize = options.tabSize || 4;
738
+ while (i < content.length) {
739
+ let ch = content.charAt(i);
740
+ if (ch === cachedSpaces[1]) {
741
+ nChars++;
742
+ }
743
+ else if (ch === '\t') {
744
+ nChars += tabSize;
745
+ }
746
+ else {
747
+ break;
748
+ }
749
+ i++;
750
+ }
751
+ return Math.floor(nChars / tabSize);
752
+ }
753
+ function getEOL(options, text) {
754
+ for (let i = 0; i < text.length; i++) {
755
+ const ch = text.charAt(i);
756
+ if (ch === '\r') {
757
+ if (i + 1 < text.length && text.charAt(i + 1) === '\n') {
758
+ return '\r\n';
759
+ }
760
+ return '\r';
761
+ }
762
+ else if (ch === '\n') {
763
+ return '\n';
764
+ }
765
+ }
766
+ return (options && options.eol) || '\n';
767
+ }
768
+ function isEOL(text, offset) {
769
+ return '\r\n'.indexOf(text.charAt(offset)) !== -1;
770
+ }
771
+
772
+ /*---------------------------------------------------------------------------------------------
773
+ * Copyright (c) Microsoft Corporation. All rights reserved.
774
+ * Licensed under the MIT License. See License.txt in the project root for license information.
775
+ *--------------------------------------------------------------------------------------------*/
776
+ var ParseOptions;
777
+ (function (ParseOptions) {
778
+ ParseOptions.DEFAULT = {
779
+ allowTrailingComma: false
780
+ };
781
+ })(ParseOptions || (ParseOptions = {}));
782
+ /**
783
+ * For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
784
+ */
785
+ function getLocation$1(text, position) {
786
+ const segments = []; // strings or numbers
787
+ const earlyReturnException = new Object();
788
+ let previousNode = undefined;
789
+ const previousNodeInst = {
790
+ value: {},
791
+ offset: 0,
792
+ length: 0,
793
+ type: 'object',
794
+ parent: undefined
795
+ };
796
+ let isAtPropertyKey = false;
797
+ function setPreviousNode(value, offset, length, type) {
798
+ previousNodeInst.value = value;
799
+ previousNodeInst.offset = offset;
800
+ previousNodeInst.length = length;
801
+ previousNodeInst.type = type;
802
+ previousNodeInst.colonOffset = undefined;
803
+ previousNode = previousNodeInst;
804
+ }
805
+ try {
806
+ visit$1(text, {
807
+ onObjectBegin: (offset, length) => {
808
+ if (position <= offset) {
809
+ throw earlyReturnException;
810
+ }
811
+ previousNode = undefined;
812
+ isAtPropertyKey = position > offset;
813
+ segments.push(''); // push a placeholder (will be replaced)
814
+ },
815
+ onObjectProperty: (name, offset, length) => {
816
+ if (position < offset) {
817
+ throw earlyReturnException;
818
+ }
819
+ setPreviousNode(name, offset, length, 'property');
820
+ segments[segments.length - 1] = name;
821
+ if (position <= offset + length) {
822
+ throw earlyReturnException;
823
+ }
824
+ },
825
+ onObjectEnd: (offset, length) => {
826
+ if (position <= offset) {
827
+ throw earlyReturnException;
828
+ }
829
+ previousNode = undefined;
830
+ segments.pop();
831
+ },
832
+ onArrayBegin: (offset, length) => {
833
+ if (position <= offset) {
834
+ throw earlyReturnException;
835
+ }
836
+ previousNode = undefined;
837
+ segments.push(0);
838
+ },
839
+ onArrayEnd: (offset, length) => {
840
+ if (position <= offset) {
841
+ throw earlyReturnException;
842
+ }
843
+ previousNode = undefined;
844
+ segments.pop();
845
+ },
846
+ onLiteralValue: (value, offset, length) => {
847
+ if (position < offset) {
848
+ throw earlyReturnException;
849
+ }
850
+ setPreviousNode(value, offset, length, getNodeType(value));
851
+ if (position <= offset + length) {
852
+ throw earlyReturnException;
853
+ }
854
+ },
855
+ onSeparator: (sep, offset, length) => {
856
+ if (position <= offset) {
857
+ throw earlyReturnException;
858
+ }
859
+ if (sep === ':' && previousNode && previousNode.type === 'property') {
860
+ previousNode.colonOffset = offset;
861
+ isAtPropertyKey = false;
862
+ previousNode = undefined;
863
+ }
864
+ else if (sep === ',') {
865
+ const last = segments[segments.length - 1];
866
+ if (typeof last === 'number') {
867
+ segments[segments.length - 1] = last + 1;
868
+ }
869
+ else {
870
+ isAtPropertyKey = true;
871
+ segments[segments.length - 1] = '';
872
+ }
873
+ previousNode = undefined;
874
+ }
875
+ }
876
+ });
877
+ }
878
+ catch (e) {
879
+ if (e !== earlyReturnException) {
880
+ throw e;
881
+ }
882
+ }
883
+ return {
884
+ path: segments,
885
+ previousNode,
886
+ isAtPropertyKey,
887
+ matches: (pattern) => {
888
+ let k = 0;
889
+ for (let i = 0; k < pattern.length && i < segments.length; i++) {
890
+ if (pattern[k] === segments[i] || pattern[k] === '*') {
891
+ k++;
892
+ }
893
+ else if (pattern[k] !== '**') {
894
+ return false;
895
+ }
896
+ }
897
+ return k === pattern.length;
898
+ }
899
+ };
900
+ }
901
+ /**
902
+ * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
903
+ * Therefore always check the errors list to find out if the input was valid.
904
+ */
905
+ function parse$1(text, errors = [], options = ParseOptions.DEFAULT) {
906
+ let currentProperty = null;
907
+ let currentParent = [];
908
+ const previousParents = [];
909
+ function onValue(value) {
910
+ if (Array.isArray(currentParent)) {
911
+ currentParent.push(value);
912
+ }
913
+ else if (currentProperty !== null) {
914
+ currentParent[currentProperty] = value;
915
+ }
916
+ }
917
+ const visitor = {
918
+ onObjectBegin: () => {
919
+ const object = {};
920
+ onValue(object);
921
+ previousParents.push(currentParent);
922
+ currentParent = object;
923
+ currentProperty = null;
924
+ },
925
+ onObjectProperty: (name) => {
926
+ currentProperty = name;
927
+ },
928
+ onObjectEnd: () => {
929
+ currentParent = previousParents.pop();
930
+ },
931
+ onArrayBegin: () => {
932
+ const array = [];
933
+ onValue(array);
934
+ previousParents.push(currentParent);
935
+ currentParent = array;
936
+ currentProperty = null;
937
+ },
938
+ onArrayEnd: () => {
939
+ currentParent = previousParents.pop();
940
+ },
941
+ onLiteralValue: onValue,
942
+ onError: (error, offset, length) => {
943
+ errors.push({ error, offset, length });
944
+ }
945
+ };
946
+ visit$1(text, visitor, options);
947
+ return currentParent[0];
948
+ }
949
+ /**
950
+ * Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
951
+ */
952
+ function parseTree$1(text, errors = [], options = ParseOptions.DEFAULT) {
953
+ let currentParent = { type: 'array', offset: -1, length: -1, children: [], parent: undefined }; // artificial root
954
+ function ensurePropertyComplete(endOffset) {
955
+ if (currentParent.type === 'property') {
956
+ currentParent.length = endOffset - currentParent.offset;
957
+ currentParent = currentParent.parent;
958
+ }
959
+ }
960
+ function onValue(valueNode) {
961
+ currentParent.children.push(valueNode);
962
+ return valueNode;
963
+ }
964
+ const visitor = {
965
+ onObjectBegin: (offset) => {
966
+ currentParent = onValue({ type: 'object', offset, length: -1, parent: currentParent, children: [] });
967
+ },
968
+ onObjectProperty: (name, offset, length) => {
969
+ currentParent = onValue({ type: 'property', offset, length: -1, parent: currentParent, children: [] });
970
+ currentParent.children.push({ type: 'string', value: name, offset, length, parent: currentParent });
971
+ },
972
+ onObjectEnd: (offset, length) => {
973
+ ensurePropertyComplete(offset + length); // in case of a missing value for a property: make sure property is complete
974
+ currentParent.length = offset + length - currentParent.offset;
975
+ currentParent = currentParent.parent;
976
+ ensurePropertyComplete(offset + length);
977
+ },
978
+ onArrayBegin: (offset, length) => {
979
+ currentParent = onValue({ type: 'array', offset, length: -1, parent: currentParent, children: [] });
980
+ },
981
+ onArrayEnd: (offset, length) => {
982
+ currentParent.length = offset + length - currentParent.offset;
983
+ currentParent = currentParent.parent;
984
+ ensurePropertyComplete(offset + length);
985
+ },
986
+ onLiteralValue: (value, offset, length) => {
987
+ onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
988
+ ensurePropertyComplete(offset + length);
989
+ },
990
+ onSeparator: (sep, offset, length) => {
991
+ if (currentParent.type === 'property') {
992
+ if (sep === ':') {
993
+ currentParent.colonOffset = offset;
994
+ }
995
+ else if (sep === ',') {
996
+ ensurePropertyComplete(offset);
997
+ }
998
+ }
999
+ },
1000
+ onError: (error, offset, length) => {
1001
+ errors.push({ error, offset, length });
1002
+ }
1003
+ };
1004
+ visit$1(text, visitor, options);
1005
+ const result = currentParent.children[0];
1006
+ if (result) {
1007
+ delete result.parent;
1008
+ }
1009
+ return result;
1010
+ }
1011
+ /**
1012
+ * Finds the node at the given path in a JSON DOM.
1013
+ */
1014
+ function findNodeAtLocation$1(root, path) {
1015
+ if (!root) {
1016
+ return undefined;
1017
+ }
1018
+ let node = root;
1019
+ for (let segment of path) {
1020
+ if (typeof segment === 'string') {
1021
+ if (node.type !== 'object' || !Array.isArray(node.children)) {
1022
+ return undefined;
1023
+ }
1024
+ let found = false;
1025
+ for (const propertyNode of node.children) {
1026
+ if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
1027
+ node = propertyNode.children[1];
1028
+ found = true;
1029
+ break;
1030
+ }
1031
+ }
1032
+ if (!found) {
1033
+ return undefined;
1034
+ }
1035
+ }
1036
+ else {
1037
+ const index = segment;
1038
+ if (node.type !== 'array' || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
1039
+ return undefined;
1040
+ }
1041
+ node = node.children[index];
1042
+ }
1043
+ }
1044
+ return node;
1045
+ }
1046
+ /**
1047
+ * Gets the JSON path of the given JSON DOM node
1048
+ */
1049
+ function getNodePath$1(node) {
1050
+ if (!node.parent || !node.parent.children) {
1051
+ return [];
1052
+ }
1053
+ const path = getNodePath$1(node.parent);
1054
+ if (node.parent.type === 'property') {
1055
+ const key = node.parent.children[0].value;
1056
+ path.push(key);
1057
+ }
1058
+ else if (node.parent.type === 'array') {
1059
+ const index = node.parent.children.indexOf(node);
1060
+ if (index !== -1) {
1061
+ path.push(index);
1062
+ }
1063
+ }
1064
+ return path;
1065
+ }
1066
+ /**
1067
+ * Evaluates the JavaScript object of the given JSON DOM node
1068
+ */
1069
+ function getNodeValue$1(node) {
1070
+ switch (node.type) {
1071
+ case 'array':
1072
+ return node.children.map(getNodeValue$1);
1073
+ case 'object':
1074
+ const obj = Object.create(null);
1075
+ for (let prop of node.children) {
1076
+ const valueNode = prop.children[1];
1077
+ if (valueNode) {
1078
+ obj[prop.children[0].value] = getNodeValue$1(valueNode);
1079
+ }
1080
+ }
1081
+ return obj;
1082
+ case 'null':
1083
+ case 'string':
1084
+ case 'number':
1085
+ case 'boolean':
1086
+ return node.value;
1087
+ default:
1088
+ return undefined;
1089
+ }
1090
+ }
1091
+ function contains(node, offset, includeRightBound = false) {
1092
+ return (offset >= node.offset && offset < (node.offset + node.length)) || includeRightBound && (offset === (node.offset + node.length));
1093
+ }
1094
+ /**
1095
+ * Finds the most inner node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
1096
+ */
1097
+ function findNodeAtOffset$1(node, offset, includeRightBound = false) {
1098
+ if (contains(node, offset, includeRightBound)) {
1099
+ const children = node.children;
1100
+ if (Array.isArray(children)) {
1101
+ for (let i = 0; i < children.length && children[i].offset <= offset; i++) {
1102
+ const item = findNodeAtOffset$1(children[i], offset, includeRightBound);
1103
+ if (item) {
1104
+ return item;
1105
+ }
1106
+ }
1107
+ }
1108
+ return node;
1109
+ }
1110
+ return undefined;
1111
+ }
1112
+ /**
1113
+ * Parses the given text and invokes the visitor functions for each object, array and literal reached.
1114
+ */
1115
+ function visit$1(text, visitor, options = ParseOptions.DEFAULT) {
1116
+ const _scanner = createScanner$1(text, false);
1117
+ // Important: Only pass copies of this to visitor functions to prevent accidental modification, and
1118
+ // to not affect visitor functions which stored a reference to a previous JSONPath
1119
+ const _jsonPath = [];
1120
+ // Depth of onXXXBegin() callbacks suppressed. onXXXEnd() decrements this if it isn't 0 already.
1121
+ // Callbacks are only called when this value is 0.
1122
+ let suppressedCallbacks = 0;
1123
+ function toNoArgVisit(visitFunction) {
1124
+ return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
1125
+ }
1126
+ function toOneArgVisit(visitFunction) {
1127
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
1128
+ }
1129
+ function toOneArgVisitWithPath(visitFunction) {
1130
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
1131
+ }
1132
+ function toBeginVisit(visitFunction) {
1133
+ return visitFunction ?
1134
+ () => {
1135
+ if (suppressedCallbacks > 0) {
1136
+ suppressedCallbacks++;
1137
+ }
1138
+ else {
1139
+ let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
1140
+ if (cbReturn === false) {
1141
+ suppressedCallbacks = 1;
1142
+ }
1143
+ }
1144
+ }
1145
+ : () => true;
1146
+ }
1147
+ function toEndVisit(visitFunction) {
1148
+ return visitFunction ?
1149
+ () => {
1150
+ if (suppressedCallbacks > 0) {
1151
+ suppressedCallbacks--;
1152
+ }
1153
+ if (suppressedCallbacks === 0) {
1154
+ visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
1155
+ }
1156
+ }
1157
+ : () => true;
1158
+ }
1159
+ const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
1160
+ const disallowComments = options && options.disallowComments;
1161
+ const allowTrailingComma = options && options.allowTrailingComma;
1162
+ function scanNext() {
1163
+ while (true) {
1164
+ const token = _scanner.scan();
1165
+ switch (_scanner.getTokenError()) {
1166
+ case 4 /* ScanError.InvalidUnicode */:
1167
+ handleError(14 /* ParseErrorCode.InvalidUnicode */);
1168
+ break;
1169
+ case 5 /* ScanError.InvalidEscapeCharacter */:
1170
+ handleError(15 /* ParseErrorCode.InvalidEscapeCharacter */);
1171
+ break;
1172
+ case 3 /* ScanError.UnexpectedEndOfNumber */:
1173
+ handleError(13 /* ParseErrorCode.UnexpectedEndOfNumber */);
1174
+ break;
1175
+ case 1 /* ScanError.UnexpectedEndOfComment */:
1176
+ if (!disallowComments) {
1177
+ handleError(11 /* ParseErrorCode.UnexpectedEndOfComment */);
1178
+ }
1179
+ break;
1180
+ case 2 /* ScanError.UnexpectedEndOfString */:
1181
+ handleError(12 /* ParseErrorCode.UnexpectedEndOfString */);
1182
+ break;
1183
+ case 6 /* ScanError.InvalidCharacter */:
1184
+ handleError(16 /* ParseErrorCode.InvalidCharacter */);
1185
+ break;
1186
+ }
1187
+ switch (token) {
1188
+ case 12 /* SyntaxKind.LineCommentTrivia */:
1189
+ case 13 /* SyntaxKind.BlockCommentTrivia */:
1190
+ if (disallowComments) {
1191
+ handleError(10 /* ParseErrorCode.InvalidCommentToken */);
1192
+ }
1193
+ else {
1194
+ onComment();
1195
+ }
1196
+ break;
1197
+ case 16 /* SyntaxKind.Unknown */:
1198
+ handleError(1 /* ParseErrorCode.InvalidSymbol */);
1199
+ break;
1200
+ case 15 /* SyntaxKind.Trivia */:
1201
+ case 14 /* SyntaxKind.LineBreakTrivia */:
1202
+ break;
1203
+ default:
1204
+ return token;
1205
+ }
1206
+ }
1207
+ }
1208
+ function handleError(error, skipUntilAfter = [], skipUntil = []) {
1209
+ onError(error);
1210
+ if (skipUntilAfter.length + skipUntil.length > 0) {
1211
+ let token = _scanner.getToken();
1212
+ while (token !== 17 /* SyntaxKind.EOF */) {
1213
+ if (skipUntilAfter.indexOf(token) !== -1) {
1214
+ scanNext();
1215
+ break;
1216
+ }
1217
+ else if (skipUntil.indexOf(token) !== -1) {
1218
+ break;
1219
+ }
1220
+ token = scanNext();
1221
+ }
1222
+ }
1223
+ }
1224
+ function parseString(isValue) {
1225
+ const value = _scanner.getTokenValue();
1226
+ if (isValue) {
1227
+ onLiteralValue(value);
1228
+ }
1229
+ else {
1230
+ onObjectProperty(value);
1231
+ // add property name afterwards
1232
+ _jsonPath.push(value);
1233
+ }
1234
+ scanNext();
1235
+ return true;
1236
+ }
1237
+ function parseLiteral() {
1238
+ switch (_scanner.getToken()) {
1239
+ case 11 /* SyntaxKind.NumericLiteral */:
1240
+ const tokenValue = _scanner.getTokenValue();
1241
+ let value = Number(tokenValue);
1242
+ if (isNaN(value)) {
1243
+ handleError(2 /* ParseErrorCode.InvalidNumberFormat */);
1244
+ value = 0;
1245
+ }
1246
+ onLiteralValue(value);
1247
+ break;
1248
+ case 7 /* SyntaxKind.NullKeyword */:
1249
+ onLiteralValue(null);
1250
+ break;
1251
+ case 8 /* SyntaxKind.TrueKeyword */:
1252
+ onLiteralValue(true);
1253
+ break;
1254
+ case 9 /* SyntaxKind.FalseKeyword */:
1255
+ onLiteralValue(false);
1256
+ break;
1257
+ default:
1258
+ return false;
1259
+ }
1260
+ scanNext();
1261
+ return true;
1262
+ }
1263
+ function parseProperty() {
1264
+ if (_scanner.getToken() !== 10 /* SyntaxKind.StringLiteral */) {
1265
+ handleError(3 /* ParseErrorCode.PropertyNameExpected */, [], [2 /* SyntaxKind.CloseBraceToken */, 5 /* SyntaxKind.CommaToken */]);
1266
+ return false;
1267
+ }
1268
+ parseString(false);
1269
+ if (_scanner.getToken() === 6 /* SyntaxKind.ColonToken */) {
1270
+ onSeparator(':');
1271
+ scanNext(); // consume colon
1272
+ if (!parseValue()) {
1273
+ handleError(4 /* ParseErrorCode.ValueExpected */, [], [2 /* SyntaxKind.CloseBraceToken */, 5 /* SyntaxKind.CommaToken */]);
1274
+ }
1275
+ }
1276
+ else {
1277
+ handleError(5 /* ParseErrorCode.ColonExpected */, [], [2 /* SyntaxKind.CloseBraceToken */, 5 /* SyntaxKind.CommaToken */]);
1278
+ }
1279
+ _jsonPath.pop(); // remove processed property name
1280
+ return true;
1281
+ }
1282
+ function parseObject() {
1283
+ onObjectBegin();
1284
+ scanNext(); // consume open brace
1285
+ let needsComma = false;
1286
+ while (_scanner.getToken() !== 2 /* SyntaxKind.CloseBraceToken */ && _scanner.getToken() !== 17 /* SyntaxKind.EOF */) {
1287
+ if (_scanner.getToken() === 5 /* SyntaxKind.CommaToken */) {
1288
+ if (!needsComma) {
1289
+ handleError(4 /* ParseErrorCode.ValueExpected */, [], []);
1290
+ }
1291
+ onSeparator(',');
1292
+ scanNext(); // consume comma
1293
+ if (_scanner.getToken() === 2 /* SyntaxKind.CloseBraceToken */ && allowTrailingComma) {
1294
+ break;
1295
+ }
1296
+ }
1297
+ else if (needsComma) {
1298
+ handleError(6 /* ParseErrorCode.CommaExpected */, [], []);
1299
+ }
1300
+ if (!parseProperty()) {
1301
+ handleError(4 /* ParseErrorCode.ValueExpected */, [], [2 /* SyntaxKind.CloseBraceToken */, 5 /* SyntaxKind.CommaToken */]);
1302
+ }
1303
+ needsComma = true;
1304
+ }
1305
+ onObjectEnd();
1306
+ if (_scanner.getToken() !== 2 /* SyntaxKind.CloseBraceToken */) {
1307
+ handleError(7 /* ParseErrorCode.CloseBraceExpected */, [2 /* SyntaxKind.CloseBraceToken */], []);
1308
+ }
1309
+ else {
1310
+ scanNext(); // consume close brace
1311
+ }
1312
+ return true;
1313
+ }
1314
+ function parseArray() {
1315
+ onArrayBegin();
1316
+ scanNext(); // consume open bracket
1317
+ let isFirstElement = true;
1318
+ let needsComma = false;
1319
+ while (_scanner.getToken() !== 4 /* SyntaxKind.CloseBracketToken */ && _scanner.getToken() !== 17 /* SyntaxKind.EOF */) {
1320
+ if (_scanner.getToken() === 5 /* SyntaxKind.CommaToken */) {
1321
+ if (!needsComma) {
1322
+ handleError(4 /* ParseErrorCode.ValueExpected */, [], []);
1323
+ }
1324
+ onSeparator(',');
1325
+ scanNext(); // consume comma
1326
+ if (_scanner.getToken() === 4 /* SyntaxKind.CloseBracketToken */ && allowTrailingComma) {
1327
+ break;
1328
+ }
1329
+ }
1330
+ else if (needsComma) {
1331
+ handleError(6 /* ParseErrorCode.CommaExpected */, [], []);
1332
+ }
1333
+ if (isFirstElement) {
1334
+ _jsonPath.push(0);
1335
+ isFirstElement = false;
1336
+ }
1337
+ else {
1338
+ _jsonPath[_jsonPath.length - 1]++;
1339
+ }
1340
+ if (!parseValue()) {
1341
+ handleError(4 /* ParseErrorCode.ValueExpected */, [], [4 /* SyntaxKind.CloseBracketToken */, 5 /* SyntaxKind.CommaToken */]);
1342
+ }
1343
+ needsComma = true;
1344
+ }
1345
+ onArrayEnd();
1346
+ if (!isFirstElement) {
1347
+ _jsonPath.pop(); // remove array index
1348
+ }
1349
+ if (_scanner.getToken() !== 4 /* SyntaxKind.CloseBracketToken */) {
1350
+ handleError(8 /* ParseErrorCode.CloseBracketExpected */, [4 /* SyntaxKind.CloseBracketToken */], []);
1351
+ }
1352
+ else {
1353
+ scanNext(); // consume close bracket
1354
+ }
1355
+ return true;
1356
+ }
1357
+ function parseValue() {
1358
+ switch (_scanner.getToken()) {
1359
+ case 3 /* SyntaxKind.OpenBracketToken */:
1360
+ return parseArray();
1361
+ case 1 /* SyntaxKind.OpenBraceToken */:
1362
+ return parseObject();
1363
+ case 10 /* SyntaxKind.StringLiteral */:
1364
+ return parseString(true);
1365
+ default:
1366
+ return parseLiteral();
1367
+ }
1368
+ }
1369
+ scanNext();
1370
+ if (_scanner.getToken() === 17 /* SyntaxKind.EOF */) {
1371
+ if (options.allowEmptyContent) {
1372
+ return true;
1373
+ }
1374
+ handleError(4 /* ParseErrorCode.ValueExpected */, [], []);
1375
+ return false;
1376
+ }
1377
+ if (!parseValue()) {
1378
+ handleError(4 /* ParseErrorCode.ValueExpected */, [], []);
1379
+ return false;
1380
+ }
1381
+ if (_scanner.getToken() !== 17 /* SyntaxKind.EOF */) {
1382
+ handleError(9 /* ParseErrorCode.EndOfFileExpected */, [], []);
1383
+ }
1384
+ return true;
1385
+ }
1386
+ /**
1387
+ * Takes JSON with JavaScript-style comments and remove
1388
+ * them. Optionally replaces every none-newline character
1389
+ * of comments with a replaceCharacter
1390
+ */
1391
+ function stripComments$1(text, replaceCh) {
1392
+ let _scanner = createScanner$1(text), parts = [], kind, offset = 0, pos;
1393
+ do {
1394
+ pos = _scanner.getPosition();
1395
+ kind = _scanner.scan();
1396
+ switch (kind) {
1397
+ case 12 /* SyntaxKind.LineCommentTrivia */:
1398
+ case 13 /* SyntaxKind.BlockCommentTrivia */:
1399
+ case 17 /* SyntaxKind.EOF */:
1400
+ if (offset !== pos) {
1401
+ parts.push(text.substring(offset, pos));
1402
+ }
1403
+ if (replaceCh !== undefined) {
1404
+ parts.push(_scanner.getTokenValue().replace(/[^\r\n]/g, replaceCh));
1405
+ }
1406
+ offset = _scanner.getPosition();
1407
+ break;
1408
+ }
1409
+ } while (kind !== 17 /* SyntaxKind.EOF */);
1410
+ return parts.join('');
1411
+ }
1412
+ function getNodeType(value) {
1413
+ switch (typeof value) {
1414
+ case 'boolean': return 'boolean';
1415
+ case 'number': return 'number';
1416
+ case 'string': return 'string';
1417
+ case 'object': {
1418
+ if (!value) {
1419
+ return 'null';
1420
+ }
1421
+ else if (Array.isArray(value)) {
1422
+ return 'array';
1423
+ }
1424
+ return 'object';
1425
+ }
1426
+ default: return 'null';
1427
+ }
1428
+ }
1429
+
1430
+ /*---------------------------------------------------------------------------------------------
1431
+ * Copyright (c) Microsoft Corporation. All rights reserved.
1432
+ * Licensed under the MIT License. See License.txt in the project root for license information.
1433
+ *--------------------------------------------------------------------------------------------*/
1434
+ function setProperty(text, originalPath, value, options) {
1435
+ const path = originalPath.slice();
1436
+ const errors = [];
1437
+ const root = parseTree$1(text, errors);
1438
+ let parent = void 0;
1439
+ let lastSegment = void 0;
1440
+ while (path.length > 0) {
1441
+ lastSegment = path.pop();
1442
+ parent = findNodeAtLocation$1(root, path);
1443
+ if (parent === void 0 && value !== void 0) {
1444
+ if (typeof lastSegment === 'string') {
1445
+ value = { [lastSegment]: value };
1446
+ }
1447
+ else {
1448
+ value = [value];
1449
+ }
1450
+ }
1451
+ else {
1452
+ break;
1453
+ }
1454
+ }
1455
+ if (!parent) {
1456
+ // empty document
1457
+ if (value === void 0) { // delete
1458
+ throw new Error('Can not delete in empty document');
1459
+ }
1460
+ return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
1461
+ }
1462
+ else if (parent.type === 'object' && typeof lastSegment === 'string' && Array.isArray(parent.children)) {
1463
+ const existing = findNodeAtLocation$1(parent, [lastSegment]);
1464
+ if (existing !== void 0) {
1465
+ if (value === void 0) { // delete
1466
+ if (!existing.parent) {
1467
+ throw new Error('Malformed AST');
1468
+ }
1469
+ const propertyIndex = parent.children.indexOf(existing.parent);
1470
+ let removeBegin;
1471
+ let removeEnd = existing.parent.offset + existing.parent.length;
1472
+ if (propertyIndex > 0) {
1473
+ // remove the comma of the previous node
1474
+ let previous = parent.children[propertyIndex - 1];
1475
+ removeBegin = previous.offset + previous.length;
1476
+ }
1477
+ else {
1478
+ removeBegin = parent.offset + 1;
1479
+ if (parent.children.length > 1) {
1480
+ // remove the comma of the next node
1481
+ let next = parent.children[1];
1482
+ removeEnd = next.offset;
1483
+ }
1484
+ }
1485
+ return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: '' }, options);
1486
+ }
1487
+ else {
1488
+ // set value of existing property
1489
+ return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
1490
+ }
1491
+ }
1492
+ else {
1493
+ if (value === void 0) { // delete
1494
+ return []; // property does not exist, nothing to do
1495
+ }
1496
+ const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
1497
+ const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map(p => p.children[0].value)) : parent.children.length;
1498
+ let edit;
1499
+ if (index > 0) {
1500
+ let previous = parent.children[index - 1];
1501
+ edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
1502
+ }
1503
+ else if (parent.children.length === 0) {
1504
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1505
+ }
1506
+ else {
1507
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty + ',' };
1508
+ }
1509
+ return withFormatting(text, edit, options);
1510
+ }
1511
+ }
1512
+ else if (parent.type === 'array' && typeof lastSegment === 'number' && Array.isArray(parent.children)) {
1513
+ const insertIndex = lastSegment;
1514
+ if (insertIndex === -1) {
1515
+ // Insert
1516
+ const newProperty = `${JSON.stringify(value)}`;
1517
+ let edit;
1518
+ if (parent.children.length === 0) {
1519
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1520
+ }
1521
+ else {
1522
+ const previous = parent.children[parent.children.length - 1];
1523
+ edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
1524
+ }
1525
+ return withFormatting(text, edit, options);
1526
+ }
1527
+ else if (value === void 0 && parent.children.length >= 0) {
1528
+ // Removal
1529
+ const removalIndex = lastSegment;
1530
+ const toRemove = parent.children[removalIndex];
1531
+ let edit;
1532
+ if (parent.children.length === 1) {
1533
+ // only item
1534
+ edit = { offset: parent.offset + 1, length: parent.length - 2, content: '' };
1535
+ }
1536
+ else if (parent.children.length - 1 === removalIndex) {
1537
+ // last item
1538
+ let previous = parent.children[removalIndex - 1];
1539
+ let offset = previous.offset + previous.length;
1540
+ let parentEndOffset = parent.offset + parent.length;
1541
+ edit = { offset, length: parentEndOffset - 2 - offset, content: '' };
1542
+ }
1543
+ else {
1544
+ edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' };
1545
+ }
1546
+ return withFormatting(text, edit, options);
1547
+ }
1548
+ else if (value !== void 0) {
1549
+ let edit;
1550
+ const newProperty = `${JSON.stringify(value)}`;
1551
+ if (!options.isArrayInsertion && parent.children.length > lastSegment) {
1552
+ const toModify = parent.children[lastSegment];
1553
+ edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
1554
+ }
1555
+ else if (parent.children.length === 0 || lastSegment === 0) {
1556
+ edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + ',' };
1557
+ }
1558
+ else {
1559
+ const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
1560
+ const previous = parent.children[index - 1];
1561
+ edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
1562
+ }
1563
+ return withFormatting(text, edit, options);
1564
+ }
1565
+ else {
1566
+ throw new Error(`Can not ${value === void 0 ? 'remove' : (options.isArrayInsertion ? 'insert' : 'modify')} Array index ${insertIndex} as length is not sufficient`);
1567
+ }
1568
+ }
1569
+ else {
1570
+ throw new Error(`Can not add ${typeof lastSegment !== 'number' ? 'index' : 'property'} to parent of type ${parent.type}`);
1571
+ }
1572
+ }
1573
+ function withFormatting(text, edit, options) {
1574
+ if (!options.formattingOptions) {
1575
+ return [edit];
1576
+ }
1577
+ // apply the edit
1578
+ let newText = applyEdit(text, edit);
1579
+ // format the new text
1580
+ let begin = edit.offset;
1581
+ let end = edit.offset + edit.content.length;
1582
+ if (edit.length === 0 || edit.content.length === 0) { // insert or remove
1583
+ while (begin > 0 && !isEOL(newText, begin - 1)) {
1584
+ begin--;
1585
+ }
1586
+ while (end < newText.length && !isEOL(newText, end)) {
1587
+ end++;
1588
+ }
1589
+ }
1590
+ const edits = format$1(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
1591
+ // apply the formatting edits and track the begin and end offsets of the changes
1592
+ for (let i = edits.length - 1; i >= 0; i--) {
1593
+ const edit = edits[i];
1594
+ newText = applyEdit(newText, edit);
1595
+ begin = Math.min(begin, edit.offset);
1596
+ end = Math.max(end, edit.offset + edit.length);
1597
+ end += edit.content.length - edit.length;
1598
+ }
1599
+ // create a single edit with all changes
1600
+ const editLength = text.length - (newText.length - end) - begin;
1601
+ return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
1602
+ }
1603
+ function applyEdit(text, edit) {
1604
+ return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
1605
+ }
1606
+
1607
+ /*---------------------------------------------------------------------------------------------
1608
+ * Copyright (c) Microsoft Corporation. All rights reserved.
1609
+ * Licensed under the MIT License. See License.txt in the project root for license information.
1610
+ *--------------------------------------------------------------------------------------------*/
1611
+ /**
1612
+ * Creates a JSON scanner on the given text.
1613
+ * If ignoreTrivia is set, whitespaces or comments are ignored.
1614
+ */
1615
+ const createScanner = createScanner$1;
1616
+ var ScanError;
1617
+ (function (ScanError) {
1618
+ ScanError[ScanError["None"] = 0] = "None";
1619
+ ScanError[ScanError["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
1620
+ ScanError[ScanError["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
1621
+ ScanError[ScanError["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
1622
+ ScanError[ScanError["InvalidUnicode"] = 4] = "InvalidUnicode";
1623
+ ScanError[ScanError["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
1624
+ ScanError[ScanError["InvalidCharacter"] = 6] = "InvalidCharacter";
1625
+ })(ScanError || (ScanError = {}));
1626
+ var SyntaxKind;
1627
+ (function (SyntaxKind) {
1628
+ SyntaxKind[SyntaxKind["OpenBraceToken"] = 1] = "OpenBraceToken";
1629
+ SyntaxKind[SyntaxKind["CloseBraceToken"] = 2] = "CloseBraceToken";
1630
+ SyntaxKind[SyntaxKind["OpenBracketToken"] = 3] = "OpenBracketToken";
1631
+ SyntaxKind[SyntaxKind["CloseBracketToken"] = 4] = "CloseBracketToken";
1632
+ SyntaxKind[SyntaxKind["CommaToken"] = 5] = "CommaToken";
1633
+ SyntaxKind[SyntaxKind["ColonToken"] = 6] = "ColonToken";
1634
+ SyntaxKind[SyntaxKind["NullKeyword"] = 7] = "NullKeyword";
1635
+ SyntaxKind[SyntaxKind["TrueKeyword"] = 8] = "TrueKeyword";
1636
+ SyntaxKind[SyntaxKind["FalseKeyword"] = 9] = "FalseKeyword";
1637
+ SyntaxKind[SyntaxKind["StringLiteral"] = 10] = "StringLiteral";
1638
+ SyntaxKind[SyntaxKind["NumericLiteral"] = 11] = "NumericLiteral";
1639
+ SyntaxKind[SyntaxKind["LineCommentTrivia"] = 12] = "LineCommentTrivia";
1640
+ SyntaxKind[SyntaxKind["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
1641
+ SyntaxKind[SyntaxKind["LineBreakTrivia"] = 14] = "LineBreakTrivia";
1642
+ SyntaxKind[SyntaxKind["Trivia"] = 15] = "Trivia";
1643
+ SyntaxKind[SyntaxKind["Unknown"] = 16] = "Unknown";
1644
+ SyntaxKind[SyntaxKind["EOF"] = 17] = "EOF";
1645
+ })(SyntaxKind || (SyntaxKind = {}));
1646
+ /**
1647
+ * For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
1648
+ */
1649
+ const getLocation = getLocation$1;
1650
+ /**
1651
+ * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
1652
+ * Therefore, always check the errors list to find out if the input was valid.
1653
+ */
1654
+ const parse = parse$1;
1655
+ /**
1656
+ * Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
1657
+ */
1658
+ const parseTree = parseTree$1;
1659
+ /**
1660
+ * Finds the node at the given path in a JSON DOM.
1661
+ */
1662
+ const findNodeAtLocation = findNodeAtLocation$1;
1663
+ /**
1664
+ * Finds the innermost node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
1665
+ */
1666
+ const findNodeAtOffset = findNodeAtOffset$1;
1667
+ /**
1668
+ * Gets the JSON path of the given JSON DOM node
1669
+ */
1670
+ const getNodePath = getNodePath$1;
1671
+ /**
1672
+ * Evaluates the JavaScript object of the given JSON DOM node
1673
+ */
1674
+ const getNodeValue = getNodeValue$1;
1675
+ /**
1676
+ * Parses the given text and invokes the visitor functions for each object, array and literal reached.
1677
+ */
1678
+ const visit = visit$1;
1679
+ /**
1680
+ * Takes JSON with JavaScript-style comments and remove
1681
+ * them. Optionally replaces every none-newline character
1682
+ * of comments with a replaceCharacter
1683
+ */
1684
+ const stripComments = stripComments$1;
1685
+ var ParseErrorCode;
1686
+ (function (ParseErrorCode) {
1687
+ ParseErrorCode[ParseErrorCode["InvalidSymbol"] = 1] = "InvalidSymbol";
1688
+ ParseErrorCode[ParseErrorCode["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
1689
+ ParseErrorCode[ParseErrorCode["PropertyNameExpected"] = 3] = "PropertyNameExpected";
1690
+ ParseErrorCode[ParseErrorCode["ValueExpected"] = 4] = "ValueExpected";
1691
+ ParseErrorCode[ParseErrorCode["ColonExpected"] = 5] = "ColonExpected";
1692
+ ParseErrorCode[ParseErrorCode["CommaExpected"] = 6] = "CommaExpected";
1693
+ ParseErrorCode[ParseErrorCode["CloseBraceExpected"] = 7] = "CloseBraceExpected";
1694
+ ParseErrorCode[ParseErrorCode["CloseBracketExpected"] = 8] = "CloseBracketExpected";
1695
+ ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 9] = "EndOfFileExpected";
1696
+ ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 10] = "InvalidCommentToken";
1697
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
1698
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
1699
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
1700
+ ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 14] = "InvalidUnicode";
1701
+ ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
1702
+ ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
1703
+ })(ParseErrorCode || (ParseErrorCode = {}));
1704
+ function printParseErrorCode(code) {
1705
+ switch (code) {
1706
+ case 1 /* ParseErrorCode.InvalidSymbol */: return 'InvalidSymbol';
1707
+ case 2 /* ParseErrorCode.InvalidNumberFormat */: return 'InvalidNumberFormat';
1708
+ case 3 /* ParseErrorCode.PropertyNameExpected */: return 'PropertyNameExpected';
1709
+ case 4 /* ParseErrorCode.ValueExpected */: return 'ValueExpected';
1710
+ case 5 /* ParseErrorCode.ColonExpected */: return 'ColonExpected';
1711
+ case 6 /* ParseErrorCode.CommaExpected */: return 'CommaExpected';
1712
+ case 7 /* ParseErrorCode.CloseBraceExpected */: return 'CloseBraceExpected';
1713
+ case 8 /* ParseErrorCode.CloseBracketExpected */: return 'CloseBracketExpected';
1714
+ case 9 /* ParseErrorCode.EndOfFileExpected */: return 'EndOfFileExpected';
1715
+ case 10 /* ParseErrorCode.InvalidCommentToken */: return 'InvalidCommentToken';
1716
+ case 11 /* ParseErrorCode.UnexpectedEndOfComment */: return 'UnexpectedEndOfComment';
1717
+ case 12 /* ParseErrorCode.UnexpectedEndOfString */: return 'UnexpectedEndOfString';
1718
+ case 13 /* ParseErrorCode.UnexpectedEndOfNumber */: return 'UnexpectedEndOfNumber';
1719
+ case 14 /* ParseErrorCode.InvalidUnicode */: return 'InvalidUnicode';
1720
+ case 15 /* ParseErrorCode.InvalidEscapeCharacter */: return 'InvalidEscapeCharacter';
1721
+ case 16 /* ParseErrorCode.InvalidCharacter */: return 'InvalidCharacter';
1722
+ }
1723
+ return '<unknown ParseErrorCode>';
1724
+ }
1725
+ /**
1726
+ * Computes the edit operations needed to format a JSON document.
1727
+ *
1728
+ * @param documentText The input text
1729
+ * @param range The range to format or `undefined` to format the full content
1730
+ * @param options The formatting options
1731
+ * @returns The edit operations describing the formatting changes to the original document following the format described in {@linkcode EditResult}.
1732
+ * To apply the edit operations to the input, use {@linkcode applyEdits}.
1733
+ */
1734
+ function format(documentText, range, options) {
1735
+ return format$1(documentText, range, options);
1736
+ }
1737
+ /**
1738
+ * Computes the edit operations needed to modify a value in the JSON document.
1739
+ *
1740
+ * @param documentText The input text
1741
+ * @param path The path of the value to change. The path represents either to the document root, a property or an array item.
1742
+ * If the path points to an non-existing property or item, it will be created.
1743
+ * @param value The new value for the specified property or item. If the value is undefined,
1744
+ * the property or item will be removed.
1745
+ * @param options Options
1746
+ * @returns The edit operations describing the changes to the original document, following the format described in {@linkcode EditResult}.
1747
+ * To apply the edit operations to the input, use {@linkcode applyEdits}.
1748
+ */
1749
+ function modify(text, path, value, options) {
1750
+ return setProperty(text, path, value, options);
1751
+ }
1752
+ /**
1753
+ * Applies edits to an input string.
1754
+ * @param text The input text
1755
+ * @param edits Edit operations following the format described in {@linkcode EditResult}.
1756
+ * @returns The text with the applied edits.
1757
+ * @throws An error if the edit operations are not well-formed as described in {@linkcode EditResult}.
1758
+ */
1759
+ function applyEdits(text, edits) {
1760
+ let sortedEdits = edits.slice(0).sort((a, b) => {
1761
+ const diff = a.offset - b.offset;
1762
+ if (diff === 0) {
1763
+ return a.length - b.length;
1764
+ }
1765
+ return diff;
1766
+ });
1767
+ let lastModifiedOffset = text.length;
1768
+ for (let i = sortedEdits.length - 1; i >= 0; i--) {
1769
+ let e = sortedEdits[i];
1770
+ if (e.offset + e.length <= lastModifiedOffset) {
1771
+ text = applyEdit(text, e);
1772
+ }
1773
+ else {
1774
+ throw new Error('Overlapping edit');
1775
+ }
1776
+ lastModifiedOffset = e.offset;
1777
+ }
1778
+ return text;
1779
+ }
1780
+
1781
+ var main = /*#__PURE__*/Object.freeze({
1782
+ __proto__: null,
1783
+ get ParseErrorCode () { return ParseErrorCode; },
1784
+ get ScanError () { return ScanError; },
1785
+ get SyntaxKind () { return SyntaxKind; },
1786
+ applyEdits: applyEdits,
1787
+ createScanner: createScanner,
1788
+ findNodeAtLocation: findNodeAtLocation,
1789
+ findNodeAtOffset: findNodeAtOffset,
1790
+ format: format,
1791
+ getLocation: getLocation,
1792
+ getNodePath: getNodePath,
1793
+ getNodeValue: getNodeValue,
1794
+ modify: modify,
1795
+ parse: parse,
1796
+ parseTree: parseTree,
1797
+ printParseErrorCode: printParseErrorCode,
1798
+ stripComments: stripComments,
1799
+ visit: visit
1800
+ });
1801
+
1802
+ var require$$0 = /*@__PURE__*/getAugmentedNamespace(main);
1803
+
1804
+ var eol = {};
1805
+
1806
+ var hasRequiredEol;
1807
+
1808
+ function requireEol () {
1809
+ if (hasRequiredEol) return eol;
1810
+ hasRequiredEol = 1;
1811
+
1812
+ Object.defineProperty(eol, "__esModule", { value: true });
1813
+ eol.getEOL = getEOL;
1814
+ const node_os_1 = require$$0$1;
1815
+ const CRLF = '\r\n';
1816
+ const LF = '\n';
1817
+ function getEOL(content) {
1818
+ const newlines = content.match(/(?:\r?\n)/g);
1819
+ if (newlines?.length) {
1820
+ const crlf = newlines.filter((l) => l === CRLF).length;
1821
+ const lf = newlines.length - crlf;
1822
+ return crlf > lf ? CRLF : LF;
1823
+ }
1824
+ return node_os_1.EOL;
1825
+ }
1826
+
1827
+ return eol;
1828
+ }
1829
+
1830
+ var hasRequiredJsonFile;
1831
+
1832
+ function requireJsonFile () {
1833
+ if (hasRequiredJsonFile) return jsonFile;
1834
+ hasRequiredJsonFile = 1;
1835
+
1836
+ Object.defineProperty(jsonFile, "__esModule", { value: true });
1837
+ jsonFile.JSONFile = void 0;
1838
+ const jsonc_parser_1 = require$$0;
1839
+ const eol_1 = requireEol();
1840
+ /** @private */
1841
+ class JSONFile {
1842
+ host;
1843
+ path;
1844
+ content;
1845
+ eol;
1846
+ constructor(host, path) {
1847
+ this.host = host;
1848
+ this.path = path;
1849
+ this.content = this.host.readText(this.path);
1850
+ this.eol = (0, eol_1.getEOL)(this.content);
1851
+ }
1852
+ _jsonAst;
1853
+ get JsonAst() {
1854
+ if (this._jsonAst) {
1855
+ return this._jsonAst;
1856
+ }
1857
+ const errors = [];
1858
+ this._jsonAst = (0, jsonc_parser_1.parseTree)(this.content, errors, { allowTrailingComma: true });
1859
+ if (errors.length) {
1860
+ const { error, offset } = errors[0];
1861
+ throw new Error(`Failed to parse "${this.path}" as JSON AST Object. ${(0, jsonc_parser_1.printParseErrorCode)(error)} at location: ${offset}.`);
1862
+ }
1863
+ return this._jsonAst;
1864
+ }
1865
+ get(jsonPath) {
1866
+ const jsonAstNode = this.JsonAst;
1867
+ if (!jsonAstNode) {
1868
+ return undefined;
1869
+ }
1870
+ if (jsonPath.length === 0) {
1871
+ return (0, jsonc_parser_1.getNodeValue)(jsonAstNode);
1872
+ }
1873
+ const node = (0, jsonc_parser_1.findNodeAtLocation)(jsonAstNode, jsonPath);
1874
+ return node === undefined ? undefined : (0, jsonc_parser_1.getNodeValue)(node);
1875
+ }
1876
+ modify(jsonPath, value, insertInOrder) {
1877
+ let getInsertionIndex;
1878
+ if (insertInOrder === undefined) {
1879
+ const property = jsonPath.slice(-1)[0];
1880
+ getInsertionIndex = (properties) => [...properties, property].sort().findIndex((p) => p === property);
1881
+ }
1882
+ else if (insertInOrder !== false) {
1883
+ getInsertionIndex = insertInOrder;
1884
+ }
1885
+ const edits = (0, jsonc_parser_1.modify)(this.content, jsonPath, value, {
1886
+ getInsertionIndex,
1887
+ formattingOptions: {
1888
+ eol: this.eol,
1889
+ insertSpaces: true,
1890
+ tabSize: 2,
1891
+ },
1892
+ });
1893
+ if (edits.length > 0) {
1894
+ const editedContent = (0, jsonc_parser_1.applyEdits)(this.content, edits);
1895
+ // Update the file content if it changed
1896
+ if (editedContent !== this.content) {
1897
+ this.content = editedContent;
1898
+ this.host.overwrite(this.path, editedContent);
1899
+ this._jsonAst = undefined;
1900
+ }
1901
+ }
1902
+ }
1903
+ remove(jsonPath) {
1904
+ if (this.get(jsonPath) !== undefined) {
1905
+ this.modify(jsonPath, undefined);
1906
+ }
1907
+ }
1908
+ }
1909
+ jsonFile.JSONFile = JSONFile;
1910
+
1911
+ return jsonFile;
1912
+ }
1913
+
1914
+ var jsonFileExports = requireJsonFile();
1915
+
1916
+ exports.jsonFileExports = jsonFileExports;