@slidev/cli 0.47.0 → 0.47.1

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.
@@ -1,1563 +0,0 @@
1
- import "./chunk-BXO7ZPPU.mjs";
2
-
3
- // ../../node_modules/.pnpm/jsonc-parser@3.2.0/node_modules/jsonc-parser/lib/esm/impl/scanner.js
4
- function createScanner(text, ignoreTrivia = false) {
5
- const len = text.length;
6
- let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
7
- function scanHexDigits(count, exact) {
8
- let digits = 0;
9
- let value2 = 0;
10
- while (digits < count || !exact) {
11
- let ch = text.charCodeAt(pos);
12
- if (ch >= 48 && ch <= 57) {
13
- value2 = value2 * 16 + ch - 48;
14
- } else if (ch >= 65 && ch <= 70) {
15
- value2 = value2 * 16 + ch - 65 + 10;
16
- } else if (ch >= 97 && ch <= 102) {
17
- value2 = value2 * 16 + ch - 97 + 10;
18
- } else {
19
- break;
20
- }
21
- pos++;
22
- digits++;
23
- }
24
- if (digits < count) {
25
- value2 = -1;
26
- }
27
- return value2;
28
- }
29
- function setPosition(newPosition) {
30
- pos = newPosition;
31
- value = "";
32
- tokenOffset = 0;
33
- token = 16;
34
- scanError = 0;
35
- }
36
- function scanNumber() {
37
- let start = pos;
38
- if (text.charCodeAt(pos) === 48) {
39
- pos++;
40
- } else {
41
- pos++;
42
- while (pos < text.length && isDigit(text.charCodeAt(pos))) {
43
- pos++;
44
- }
45
- }
46
- if (pos < text.length && text.charCodeAt(pos) === 46) {
47
- pos++;
48
- if (pos < text.length && isDigit(text.charCodeAt(pos))) {
49
- pos++;
50
- while (pos < text.length && isDigit(text.charCodeAt(pos))) {
51
- pos++;
52
- }
53
- } else {
54
- scanError = 3;
55
- return text.substring(start, pos);
56
- }
57
- }
58
- let end = pos;
59
- if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
60
- pos++;
61
- if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
62
- pos++;
63
- }
64
- if (pos < text.length && isDigit(text.charCodeAt(pos))) {
65
- pos++;
66
- while (pos < text.length && isDigit(text.charCodeAt(pos))) {
67
- pos++;
68
- }
69
- end = pos;
70
- } else {
71
- scanError = 3;
72
- }
73
- }
74
- return text.substring(start, end);
75
- }
76
- function scanString() {
77
- let result = "", start = pos;
78
- while (true) {
79
- if (pos >= len) {
80
- result += text.substring(start, pos);
81
- scanError = 2;
82
- break;
83
- }
84
- const ch = text.charCodeAt(pos);
85
- if (ch === 34) {
86
- result += text.substring(start, pos);
87
- pos++;
88
- break;
89
- }
90
- if (ch === 92) {
91
- result += text.substring(start, pos);
92
- pos++;
93
- if (pos >= len) {
94
- scanError = 2;
95
- break;
96
- }
97
- const ch2 = text.charCodeAt(pos++);
98
- switch (ch2) {
99
- case 34:
100
- result += '"';
101
- break;
102
- case 92:
103
- result += "\\";
104
- break;
105
- case 47:
106
- result += "/";
107
- break;
108
- case 98:
109
- result += "\b";
110
- break;
111
- case 102:
112
- result += "\f";
113
- break;
114
- case 110:
115
- result += "\n";
116
- break;
117
- case 114:
118
- result += "\r";
119
- break;
120
- case 116:
121
- result += " ";
122
- break;
123
- case 117:
124
- const ch3 = scanHexDigits(4, true);
125
- if (ch3 >= 0) {
126
- result += String.fromCharCode(ch3);
127
- } else {
128
- scanError = 4;
129
- }
130
- break;
131
- default:
132
- scanError = 5;
133
- }
134
- start = pos;
135
- continue;
136
- }
137
- if (ch >= 0 && ch <= 31) {
138
- if (isLineBreak(ch)) {
139
- result += text.substring(start, pos);
140
- scanError = 2;
141
- break;
142
- } else {
143
- scanError = 6;
144
- }
145
- }
146
- pos++;
147
- }
148
- return result;
149
- }
150
- function scanNext() {
151
- value = "";
152
- scanError = 0;
153
- tokenOffset = pos;
154
- lineStartOffset = lineNumber;
155
- prevTokenLineStartOffset = tokenLineStartOffset;
156
- if (pos >= len) {
157
- tokenOffset = len;
158
- return token = 17;
159
- }
160
- let code = text.charCodeAt(pos);
161
- if (isWhiteSpace(code)) {
162
- do {
163
- pos++;
164
- value += String.fromCharCode(code);
165
- code = text.charCodeAt(pos);
166
- } while (isWhiteSpace(code));
167
- return token = 15;
168
- }
169
- if (isLineBreak(code)) {
170
- pos++;
171
- value += String.fromCharCode(code);
172
- if (code === 13 && text.charCodeAt(pos) === 10) {
173
- pos++;
174
- value += "\n";
175
- }
176
- lineNumber++;
177
- tokenLineStartOffset = pos;
178
- return token = 14;
179
- }
180
- switch (code) {
181
- case 123:
182
- pos++;
183
- return token = 1;
184
- case 125:
185
- pos++;
186
- return token = 2;
187
- case 91:
188
- pos++;
189
- return token = 3;
190
- case 93:
191
- pos++;
192
- return token = 4;
193
- case 58:
194
- pos++;
195
- return token = 6;
196
- case 44:
197
- pos++;
198
- return token = 5;
199
- case 34:
200
- pos++;
201
- value = scanString();
202
- return token = 10;
203
- case 47:
204
- const start = pos - 1;
205
- if (text.charCodeAt(pos + 1) === 47) {
206
- pos += 2;
207
- while (pos < len) {
208
- if (isLineBreak(text.charCodeAt(pos))) {
209
- break;
210
- }
211
- pos++;
212
- }
213
- value = text.substring(start, pos);
214
- return token = 12;
215
- }
216
- if (text.charCodeAt(pos + 1) === 42) {
217
- pos += 2;
218
- const safeLength = len - 1;
219
- let commentClosed = false;
220
- while (pos < safeLength) {
221
- const ch = text.charCodeAt(pos);
222
- if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
223
- pos += 2;
224
- commentClosed = true;
225
- break;
226
- }
227
- pos++;
228
- if (isLineBreak(ch)) {
229
- if (ch === 13 && text.charCodeAt(pos) === 10) {
230
- pos++;
231
- }
232
- lineNumber++;
233
- tokenLineStartOffset = pos;
234
- }
235
- }
236
- if (!commentClosed) {
237
- pos++;
238
- scanError = 1;
239
- }
240
- value = text.substring(start, pos);
241
- return token = 13;
242
- }
243
- value += String.fromCharCode(code);
244
- pos++;
245
- return token = 16;
246
- case 45:
247
- value += String.fromCharCode(code);
248
- pos++;
249
- if (pos === len || !isDigit(text.charCodeAt(pos))) {
250
- return token = 16;
251
- }
252
- case 48:
253
- case 49:
254
- case 50:
255
- case 51:
256
- case 52:
257
- case 53:
258
- case 54:
259
- case 55:
260
- case 56:
261
- case 57:
262
- value += scanNumber();
263
- return token = 11;
264
- default:
265
- while (pos < len && isUnknownContentCharacter(code)) {
266
- pos++;
267
- code = text.charCodeAt(pos);
268
- }
269
- if (tokenOffset !== pos) {
270
- value = text.substring(tokenOffset, pos);
271
- switch (value) {
272
- case "true":
273
- return token = 8;
274
- case "false":
275
- return token = 9;
276
- case "null":
277
- return token = 7;
278
- }
279
- return token = 16;
280
- }
281
- value += String.fromCharCode(code);
282
- pos++;
283
- return token = 16;
284
- }
285
- }
286
- function isUnknownContentCharacter(code) {
287
- if (isWhiteSpace(code) || isLineBreak(code)) {
288
- return false;
289
- }
290
- switch (code) {
291
- case 125:
292
- case 93:
293
- case 123:
294
- case 91:
295
- case 34:
296
- case 58:
297
- case 44:
298
- case 47:
299
- return false;
300
- }
301
- return true;
302
- }
303
- function scanNextNonTrivia() {
304
- let result;
305
- do {
306
- result = scanNext();
307
- } while (result >= 12 && result <= 15);
308
- return result;
309
- }
310
- return {
311
- setPosition,
312
- getPosition: () => pos,
313
- scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
314
- getToken: () => token,
315
- getTokenValue: () => value,
316
- getTokenOffset: () => tokenOffset,
317
- getTokenLength: () => pos - tokenOffset,
318
- getTokenStartLine: () => lineStartOffset,
319
- getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
320
- getTokenError: () => scanError
321
- };
322
- }
323
- function isWhiteSpace(ch) {
324
- return ch === 32 || ch === 9;
325
- }
326
- function isLineBreak(ch) {
327
- return ch === 10 || ch === 13;
328
- }
329
- function isDigit(ch) {
330
- return ch >= 48 && ch <= 57;
331
- }
332
- var CharacterCodes;
333
- (function(CharacterCodes2) {
334
- CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
335
- CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
336
- CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
337
- CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
338
- CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
339
- CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
340
- CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
341
- CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
342
- CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
343
- CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
344
- CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
345
- CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
346
- CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
347
- CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
348
- CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
349
- CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
350
- CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
351
- CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
352
- CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
353
- CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
354
- CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
355
- CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
356
- CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
357
- CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
358
- CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
359
- CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
360
- CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
361
- CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
362
- CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
363
- CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
364
- CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
365
- CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
366
- CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
367
- CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
368
- CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
369
- CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
370
- CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
371
- CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
372
- CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
373
- CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
374
- CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
375
- CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
376
- CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
377
- CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
378
- CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
379
- CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
380
- CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
381
- CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
382
- CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
383
- CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
384
- CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
385
- CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
386
- CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
387
- CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
388
- CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
389
- CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
390
- CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
391
- CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
392
- CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
393
- CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
394
- CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
395
- CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
396
- CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
397
- CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
398
- CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
399
- CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
400
- CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
401
- CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
402
- CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
403
- CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
404
- CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
405
- CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
406
- CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
407
- CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
408
- CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
409
- CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
410
- CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
411
- CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
412
- CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
413
- CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
414
- })(CharacterCodes || (CharacterCodes = {}));
415
-
416
- // ../../node_modules/.pnpm/jsonc-parser@3.2.0/node_modules/jsonc-parser/lib/esm/impl/format.js
417
- function format(documentText, range, options) {
418
- let initialIndentLevel;
419
- let formatText;
420
- let formatTextStart;
421
- let rangeStart;
422
- let rangeEnd;
423
- if (range) {
424
- rangeStart = range.offset;
425
- rangeEnd = rangeStart + range.length;
426
- formatTextStart = rangeStart;
427
- while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
428
- formatTextStart--;
429
- }
430
- let endOffset = rangeEnd;
431
- while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
432
- endOffset++;
433
- }
434
- formatText = documentText.substring(formatTextStart, endOffset);
435
- initialIndentLevel = computeIndentLevel(formatText, options);
436
- } else {
437
- formatText = documentText;
438
- initialIndentLevel = 0;
439
- formatTextStart = 0;
440
- rangeStart = 0;
441
- rangeEnd = documentText.length;
442
- }
443
- const eol = getEOL(options, documentText);
444
- let numberLineBreaks = 0;
445
- let indentLevel = 0;
446
- let indentValue;
447
- if (options.insertSpaces) {
448
- indentValue = repeat(" ", options.tabSize || 4);
449
- } else {
450
- indentValue = " ";
451
- }
452
- let scanner = createScanner(formatText, false);
453
- let hasError = false;
454
- function newLinesAndIndent() {
455
- if (numberLineBreaks > 1) {
456
- return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
457
- } else {
458
- return eol + repeat(indentValue, initialIndentLevel + indentLevel);
459
- }
460
- }
461
- function scanNext() {
462
- let token = scanner.scan();
463
- numberLineBreaks = 0;
464
- while (token === 15 || token === 14) {
465
- if (token === 14 && options.keepLines) {
466
- numberLineBreaks += 1;
467
- } else if (token === 14) {
468
- numberLineBreaks = 1;
469
- }
470
- token = scanner.scan();
471
- }
472
- hasError = token === 16 || scanner.getTokenError() !== 0;
473
- return token;
474
- }
475
- const editOperations = [];
476
- function addEdit(text, startOffset, endOffset) {
477
- if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
478
- editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
479
- }
480
- }
481
- let firstToken = scanNext();
482
- if (options.keepLines && numberLineBreaks > 0) {
483
- addEdit(repeat(eol, numberLineBreaks), 0, 0);
484
- }
485
- if (firstToken !== 17) {
486
- let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
487
- let initialIndent = repeat(indentValue, initialIndentLevel);
488
- addEdit(initialIndent, formatTextStart, firstTokenStart);
489
- }
490
- while (firstToken !== 17) {
491
- let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
492
- let secondToken = scanNext();
493
- let replaceContent = "";
494
- let needsLineBreak = false;
495
- while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
496
- let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
497
- addEdit(" ", firstTokenEnd, commentTokenStart);
498
- firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
499
- needsLineBreak = secondToken === 12;
500
- replaceContent = needsLineBreak ? newLinesAndIndent() : "";
501
- secondToken = scanNext();
502
- }
503
- if (secondToken === 2) {
504
- if (firstToken !== 1) {
505
- indentLevel--;
506
- }
507
- ;
508
- if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
509
- replaceContent = newLinesAndIndent();
510
- } else if (options.keepLines) {
511
- replaceContent = " ";
512
- }
513
- } else if (secondToken === 4) {
514
- if (firstToken !== 3) {
515
- indentLevel--;
516
- }
517
- ;
518
- if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
519
- replaceContent = newLinesAndIndent();
520
- } else if (options.keepLines) {
521
- replaceContent = " ";
522
- }
523
- } else {
524
- switch (firstToken) {
525
- case 3:
526
- case 1:
527
- indentLevel++;
528
- if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
529
- replaceContent = newLinesAndIndent();
530
- } else {
531
- replaceContent = " ";
532
- }
533
- break;
534
- case 5:
535
- if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
536
- replaceContent = newLinesAndIndent();
537
- } else {
538
- replaceContent = " ";
539
- }
540
- break;
541
- case 12:
542
- replaceContent = newLinesAndIndent();
543
- break;
544
- case 13:
545
- if (numberLineBreaks > 0) {
546
- replaceContent = newLinesAndIndent();
547
- } else if (!needsLineBreak) {
548
- replaceContent = " ";
549
- }
550
- break;
551
- case 6:
552
- if (options.keepLines && numberLineBreaks > 0) {
553
- replaceContent = newLinesAndIndent();
554
- } else if (!needsLineBreak) {
555
- replaceContent = " ";
556
- }
557
- break;
558
- case 10:
559
- if (options.keepLines && numberLineBreaks > 0) {
560
- replaceContent = newLinesAndIndent();
561
- } else if (secondToken === 6 && !needsLineBreak) {
562
- replaceContent = "";
563
- }
564
- break;
565
- case 7:
566
- case 8:
567
- case 9:
568
- case 11:
569
- case 2:
570
- case 4:
571
- if (options.keepLines && numberLineBreaks > 0) {
572
- replaceContent = newLinesAndIndent();
573
- } else {
574
- if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
575
- replaceContent = " ";
576
- } else if (secondToken !== 5 && secondToken !== 17) {
577
- hasError = true;
578
- }
579
- }
580
- break;
581
- case 16:
582
- hasError = true;
583
- break;
584
- }
585
- if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
586
- replaceContent = newLinesAndIndent();
587
- }
588
- }
589
- if (secondToken === 17) {
590
- if (options.keepLines && numberLineBreaks > 0) {
591
- replaceContent = newLinesAndIndent();
592
- } else {
593
- replaceContent = options.insertFinalNewline ? eol : "";
594
- }
595
- }
596
- const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
597
- addEdit(replaceContent, firstTokenEnd, secondTokenStart);
598
- firstToken = secondToken;
599
- }
600
- return editOperations;
601
- }
602
- function repeat(s, count) {
603
- let result = "";
604
- for (let i = 0; i < count; i++) {
605
- result += s;
606
- }
607
- return result;
608
- }
609
- function computeIndentLevel(content, options) {
610
- let i = 0;
611
- let nChars = 0;
612
- const tabSize = options.tabSize || 4;
613
- while (i < content.length) {
614
- let ch = content.charAt(i);
615
- if (ch === " ") {
616
- nChars++;
617
- } else if (ch === " ") {
618
- nChars += tabSize;
619
- } else {
620
- break;
621
- }
622
- i++;
623
- }
624
- return Math.floor(nChars / tabSize);
625
- }
626
- function getEOL(options, text) {
627
- for (let i = 0; i < text.length; i++) {
628
- const ch = text.charAt(i);
629
- if (ch === "\r") {
630
- if (i + 1 < text.length && text.charAt(i + 1) === "\n") {
631
- return "\r\n";
632
- }
633
- return "\r";
634
- } else if (ch === "\n") {
635
- return "\n";
636
- }
637
- }
638
- return options && options.eol || "\n";
639
- }
640
- function isEOL(text, offset) {
641
- return "\r\n".indexOf(text.charAt(offset)) !== -1;
642
- }
643
-
644
- // ../../node_modules/.pnpm/jsonc-parser@3.2.0/node_modules/jsonc-parser/lib/esm/impl/parser.js
645
- var ParseOptions;
646
- (function(ParseOptions2) {
647
- ParseOptions2.DEFAULT = {
648
- allowTrailingComma: false
649
- };
650
- })(ParseOptions || (ParseOptions = {}));
651
- function getLocation(text, position) {
652
- const segments = [];
653
- const earlyReturnException = new Object();
654
- let previousNode = void 0;
655
- const previousNodeInst = {
656
- value: {},
657
- offset: 0,
658
- length: 0,
659
- type: "object",
660
- parent: void 0
661
- };
662
- let isAtPropertyKey = false;
663
- function setPreviousNode(value, offset, length, type) {
664
- previousNodeInst.value = value;
665
- previousNodeInst.offset = offset;
666
- previousNodeInst.length = length;
667
- previousNodeInst.type = type;
668
- previousNodeInst.colonOffset = void 0;
669
- previousNode = previousNodeInst;
670
- }
671
- try {
672
- visit(text, {
673
- onObjectBegin: (offset, length) => {
674
- if (position <= offset) {
675
- throw earlyReturnException;
676
- }
677
- previousNode = void 0;
678
- isAtPropertyKey = position > offset;
679
- segments.push("");
680
- },
681
- onObjectProperty: (name, offset, length) => {
682
- if (position < offset) {
683
- throw earlyReturnException;
684
- }
685
- setPreviousNode(name, offset, length, "property");
686
- segments[segments.length - 1] = name;
687
- if (position <= offset + length) {
688
- throw earlyReturnException;
689
- }
690
- },
691
- onObjectEnd: (offset, length) => {
692
- if (position <= offset) {
693
- throw earlyReturnException;
694
- }
695
- previousNode = void 0;
696
- segments.pop();
697
- },
698
- onArrayBegin: (offset, length) => {
699
- if (position <= offset) {
700
- throw earlyReturnException;
701
- }
702
- previousNode = void 0;
703
- segments.push(0);
704
- },
705
- onArrayEnd: (offset, length) => {
706
- if (position <= offset) {
707
- throw earlyReturnException;
708
- }
709
- previousNode = void 0;
710
- segments.pop();
711
- },
712
- onLiteralValue: (value, offset, length) => {
713
- if (position < offset) {
714
- throw earlyReturnException;
715
- }
716
- setPreviousNode(value, offset, length, getNodeType(value));
717
- if (position <= offset + length) {
718
- throw earlyReturnException;
719
- }
720
- },
721
- onSeparator: (sep, offset, length) => {
722
- if (position <= offset) {
723
- throw earlyReturnException;
724
- }
725
- if (sep === ":" && previousNode && previousNode.type === "property") {
726
- previousNode.colonOffset = offset;
727
- isAtPropertyKey = false;
728
- previousNode = void 0;
729
- } else if (sep === ",") {
730
- const last = segments[segments.length - 1];
731
- if (typeof last === "number") {
732
- segments[segments.length - 1] = last + 1;
733
- } else {
734
- isAtPropertyKey = true;
735
- segments[segments.length - 1] = "";
736
- }
737
- previousNode = void 0;
738
- }
739
- }
740
- });
741
- } catch (e) {
742
- if (e !== earlyReturnException) {
743
- throw e;
744
- }
745
- }
746
- return {
747
- path: segments,
748
- previousNode,
749
- isAtPropertyKey,
750
- matches: (pattern) => {
751
- let k = 0;
752
- for (let i = 0; k < pattern.length && i < segments.length; i++) {
753
- if (pattern[k] === segments[i] || pattern[k] === "*") {
754
- k++;
755
- } else if (pattern[k] !== "**") {
756
- return false;
757
- }
758
- }
759
- return k === pattern.length;
760
- }
761
- };
762
- }
763
- function parse(text, errors = [], options = ParseOptions.DEFAULT) {
764
- let currentProperty = null;
765
- let currentParent = [];
766
- const previousParents = [];
767
- function onValue(value) {
768
- if (Array.isArray(currentParent)) {
769
- currentParent.push(value);
770
- } else if (currentProperty !== null) {
771
- currentParent[currentProperty] = value;
772
- }
773
- }
774
- const visitor = {
775
- onObjectBegin: () => {
776
- const object = {};
777
- onValue(object);
778
- previousParents.push(currentParent);
779
- currentParent = object;
780
- currentProperty = null;
781
- },
782
- onObjectProperty: (name) => {
783
- currentProperty = name;
784
- },
785
- onObjectEnd: () => {
786
- currentParent = previousParents.pop();
787
- },
788
- onArrayBegin: () => {
789
- const array = [];
790
- onValue(array);
791
- previousParents.push(currentParent);
792
- currentParent = array;
793
- currentProperty = null;
794
- },
795
- onArrayEnd: () => {
796
- currentParent = previousParents.pop();
797
- },
798
- onLiteralValue: onValue,
799
- onError: (error, offset, length) => {
800
- errors.push({ error, offset, length });
801
- }
802
- };
803
- visit(text, visitor, options);
804
- return currentParent[0];
805
- }
806
- function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
807
- let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: void 0 };
808
- function ensurePropertyComplete(endOffset) {
809
- if (currentParent.type === "property") {
810
- currentParent.length = endOffset - currentParent.offset;
811
- currentParent = currentParent.parent;
812
- }
813
- }
814
- function onValue(valueNode) {
815
- currentParent.children.push(valueNode);
816
- return valueNode;
817
- }
818
- const visitor = {
819
- onObjectBegin: (offset) => {
820
- currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
821
- },
822
- onObjectProperty: (name, offset, length) => {
823
- currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
824
- currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
825
- },
826
- onObjectEnd: (offset, length) => {
827
- ensurePropertyComplete(offset + length);
828
- currentParent.length = offset + length - currentParent.offset;
829
- currentParent = currentParent.parent;
830
- ensurePropertyComplete(offset + length);
831
- },
832
- onArrayBegin: (offset, length) => {
833
- currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
834
- },
835
- onArrayEnd: (offset, length) => {
836
- currentParent.length = offset + length - currentParent.offset;
837
- currentParent = currentParent.parent;
838
- ensurePropertyComplete(offset + length);
839
- },
840
- onLiteralValue: (value, offset, length) => {
841
- onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
842
- ensurePropertyComplete(offset + length);
843
- },
844
- onSeparator: (sep, offset, length) => {
845
- if (currentParent.type === "property") {
846
- if (sep === ":") {
847
- currentParent.colonOffset = offset;
848
- } else if (sep === ",") {
849
- ensurePropertyComplete(offset);
850
- }
851
- }
852
- },
853
- onError: (error, offset, length) => {
854
- errors.push({ error, offset, length });
855
- }
856
- };
857
- visit(text, visitor, options);
858
- const result = currentParent.children[0];
859
- if (result) {
860
- delete result.parent;
861
- }
862
- return result;
863
- }
864
- function findNodeAtLocation(root, path) {
865
- if (!root) {
866
- return void 0;
867
- }
868
- let node = root;
869
- for (let segment of path) {
870
- if (typeof segment === "string") {
871
- if (node.type !== "object" || !Array.isArray(node.children)) {
872
- return void 0;
873
- }
874
- let found = false;
875
- for (const propertyNode of node.children) {
876
- if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
877
- node = propertyNode.children[1];
878
- found = true;
879
- break;
880
- }
881
- }
882
- if (!found) {
883
- return void 0;
884
- }
885
- } else {
886
- const index = segment;
887
- if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
888
- return void 0;
889
- }
890
- node = node.children[index];
891
- }
892
- }
893
- return node;
894
- }
895
- function getNodePath(node) {
896
- if (!node.parent || !node.parent.children) {
897
- return [];
898
- }
899
- const path = getNodePath(node.parent);
900
- if (node.parent.type === "property") {
901
- const key = node.parent.children[0].value;
902
- path.push(key);
903
- } else if (node.parent.type === "array") {
904
- const index = node.parent.children.indexOf(node);
905
- if (index !== -1) {
906
- path.push(index);
907
- }
908
- }
909
- return path;
910
- }
911
- function getNodeValue(node) {
912
- switch (node.type) {
913
- case "array":
914
- return node.children.map(getNodeValue);
915
- case "object":
916
- const obj = /* @__PURE__ */ Object.create(null);
917
- for (let prop of node.children) {
918
- const valueNode = prop.children[1];
919
- if (valueNode) {
920
- obj[prop.children[0].value] = getNodeValue(valueNode);
921
- }
922
- }
923
- return obj;
924
- case "null":
925
- case "string":
926
- case "number":
927
- case "boolean":
928
- return node.value;
929
- default:
930
- return void 0;
931
- }
932
- }
933
- function contains(node, offset, includeRightBound = false) {
934
- return offset >= node.offset && offset < node.offset + node.length || includeRightBound && offset === node.offset + node.length;
935
- }
936
- function findNodeAtOffset(node, offset, includeRightBound = false) {
937
- if (contains(node, offset, includeRightBound)) {
938
- const children = node.children;
939
- if (Array.isArray(children)) {
940
- for (let i = 0; i < children.length && children[i].offset <= offset; i++) {
941
- const item = findNodeAtOffset(children[i], offset, includeRightBound);
942
- if (item) {
943
- return item;
944
- }
945
- }
946
- }
947
- return node;
948
- }
949
- return void 0;
950
- }
951
- function visit(text, visitor, options = ParseOptions.DEFAULT) {
952
- const _scanner = createScanner(text, false);
953
- const _jsonPath = [];
954
- function toNoArgVisit(visitFunction) {
955
- return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
956
- }
957
- function toNoArgVisitWithPath(visitFunction) {
958
- return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
959
- }
960
- function toOneArgVisit(visitFunction) {
961
- return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
962
- }
963
- function toOneArgVisitWithPath(visitFunction) {
964
- return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
965
- }
966
- const onObjectBegin = toNoArgVisitWithPath(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisitWithPath(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
967
- const disallowComments = options && options.disallowComments;
968
- const allowTrailingComma = options && options.allowTrailingComma;
969
- function scanNext() {
970
- while (true) {
971
- const token = _scanner.scan();
972
- switch (_scanner.getTokenError()) {
973
- case 4:
974
- handleError(
975
- 14
976
- /* ParseErrorCode.InvalidUnicode */
977
- );
978
- break;
979
- case 5:
980
- handleError(
981
- 15
982
- /* ParseErrorCode.InvalidEscapeCharacter */
983
- );
984
- break;
985
- case 3:
986
- handleError(
987
- 13
988
- /* ParseErrorCode.UnexpectedEndOfNumber */
989
- );
990
- break;
991
- case 1:
992
- if (!disallowComments) {
993
- handleError(
994
- 11
995
- /* ParseErrorCode.UnexpectedEndOfComment */
996
- );
997
- }
998
- break;
999
- case 2:
1000
- handleError(
1001
- 12
1002
- /* ParseErrorCode.UnexpectedEndOfString */
1003
- );
1004
- break;
1005
- case 6:
1006
- handleError(
1007
- 16
1008
- /* ParseErrorCode.InvalidCharacter */
1009
- );
1010
- break;
1011
- }
1012
- switch (token) {
1013
- case 12:
1014
- case 13:
1015
- if (disallowComments) {
1016
- handleError(
1017
- 10
1018
- /* ParseErrorCode.InvalidCommentToken */
1019
- );
1020
- } else {
1021
- onComment();
1022
- }
1023
- break;
1024
- case 16:
1025
- handleError(
1026
- 1
1027
- /* ParseErrorCode.InvalidSymbol */
1028
- );
1029
- break;
1030
- case 15:
1031
- case 14:
1032
- break;
1033
- default:
1034
- return token;
1035
- }
1036
- }
1037
- }
1038
- function handleError(error, skipUntilAfter = [], skipUntil = []) {
1039
- onError(error);
1040
- if (skipUntilAfter.length + skipUntil.length > 0) {
1041
- let token = _scanner.getToken();
1042
- while (token !== 17) {
1043
- if (skipUntilAfter.indexOf(token) !== -1) {
1044
- scanNext();
1045
- break;
1046
- } else if (skipUntil.indexOf(token) !== -1) {
1047
- break;
1048
- }
1049
- token = scanNext();
1050
- }
1051
- }
1052
- }
1053
- function parseString(isValue) {
1054
- const value = _scanner.getTokenValue();
1055
- if (isValue) {
1056
- onLiteralValue(value);
1057
- } else {
1058
- onObjectProperty(value);
1059
- _jsonPath.push(value);
1060
- }
1061
- scanNext();
1062
- return true;
1063
- }
1064
- function parseLiteral() {
1065
- switch (_scanner.getToken()) {
1066
- case 11:
1067
- const tokenValue = _scanner.getTokenValue();
1068
- let value = Number(tokenValue);
1069
- if (isNaN(value)) {
1070
- handleError(
1071
- 2
1072
- /* ParseErrorCode.InvalidNumberFormat */
1073
- );
1074
- value = 0;
1075
- }
1076
- onLiteralValue(value);
1077
- break;
1078
- case 7:
1079
- onLiteralValue(null);
1080
- break;
1081
- case 8:
1082
- onLiteralValue(true);
1083
- break;
1084
- case 9:
1085
- onLiteralValue(false);
1086
- break;
1087
- default:
1088
- return false;
1089
- }
1090
- scanNext();
1091
- return true;
1092
- }
1093
- function parseProperty() {
1094
- if (_scanner.getToken() !== 10) {
1095
- handleError(3, [], [
1096
- 2,
1097
- 5
1098
- /* SyntaxKind.CommaToken */
1099
- ]);
1100
- return false;
1101
- }
1102
- parseString(false);
1103
- if (_scanner.getToken() === 6) {
1104
- onSeparator(":");
1105
- scanNext();
1106
- if (!parseValue()) {
1107
- handleError(4, [], [
1108
- 2,
1109
- 5
1110
- /* SyntaxKind.CommaToken */
1111
- ]);
1112
- }
1113
- } else {
1114
- handleError(5, [], [
1115
- 2,
1116
- 5
1117
- /* SyntaxKind.CommaToken */
1118
- ]);
1119
- }
1120
- _jsonPath.pop();
1121
- return true;
1122
- }
1123
- function parseObject() {
1124
- onObjectBegin();
1125
- scanNext();
1126
- let needsComma = false;
1127
- while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
1128
- if (_scanner.getToken() === 5) {
1129
- if (!needsComma) {
1130
- handleError(4, [], []);
1131
- }
1132
- onSeparator(",");
1133
- scanNext();
1134
- if (_scanner.getToken() === 2 && allowTrailingComma) {
1135
- break;
1136
- }
1137
- } else if (needsComma) {
1138
- handleError(6, [], []);
1139
- }
1140
- if (!parseProperty()) {
1141
- handleError(4, [], [
1142
- 2,
1143
- 5
1144
- /* SyntaxKind.CommaToken */
1145
- ]);
1146
- }
1147
- needsComma = true;
1148
- }
1149
- onObjectEnd();
1150
- if (_scanner.getToken() !== 2) {
1151
- handleError(7, [
1152
- 2
1153
- /* SyntaxKind.CloseBraceToken */
1154
- ], []);
1155
- } else {
1156
- scanNext();
1157
- }
1158
- return true;
1159
- }
1160
- function parseArray() {
1161
- onArrayBegin();
1162
- scanNext();
1163
- let isFirstElement = true;
1164
- let needsComma = false;
1165
- while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
1166
- if (_scanner.getToken() === 5) {
1167
- if (!needsComma) {
1168
- handleError(4, [], []);
1169
- }
1170
- onSeparator(",");
1171
- scanNext();
1172
- if (_scanner.getToken() === 4 && allowTrailingComma) {
1173
- break;
1174
- }
1175
- } else if (needsComma) {
1176
- handleError(6, [], []);
1177
- }
1178
- if (isFirstElement) {
1179
- _jsonPath.push(0);
1180
- isFirstElement = false;
1181
- } else {
1182
- _jsonPath[_jsonPath.length - 1]++;
1183
- }
1184
- if (!parseValue()) {
1185
- handleError(4, [], [
1186
- 4,
1187
- 5
1188
- /* SyntaxKind.CommaToken */
1189
- ]);
1190
- }
1191
- needsComma = true;
1192
- }
1193
- onArrayEnd();
1194
- if (!isFirstElement) {
1195
- _jsonPath.pop();
1196
- }
1197
- if (_scanner.getToken() !== 4) {
1198
- handleError(8, [
1199
- 4
1200
- /* SyntaxKind.CloseBracketToken */
1201
- ], []);
1202
- } else {
1203
- scanNext();
1204
- }
1205
- return true;
1206
- }
1207
- function parseValue() {
1208
- switch (_scanner.getToken()) {
1209
- case 3:
1210
- return parseArray();
1211
- case 1:
1212
- return parseObject();
1213
- case 10:
1214
- return parseString(true);
1215
- default:
1216
- return parseLiteral();
1217
- }
1218
- }
1219
- scanNext();
1220
- if (_scanner.getToken() === 17) {
1221
- if (options.allowEmptyContent) {
1222
- return true;
1223
- }
1224
- handleError(4, [], []);
1225
- return false;
1226
- }
1227
- if (!parseValue()) {
1228
- handleError(4, [], []);
1229
- return false;
1230
- }
1231
- if (_scanner.getToken() !== 17) {
1232
- handleError(9, [], []);
1233
- }
1234
- return true;
1235
- }
1236
- function stripComments(text, replaceCh) {
1237
- let _scanner = createScanner(text), parts = [], kind, offset = 0, pos;
1238
- do {
1239
- pos = _scanner.getPosition();
1240
- kind = _scanner.scan();
1241
- switch (kind) {
1242
- case 12:
1243
- case 13:
1244
- case 17:
1245
- if (offset !== pos) {
1246
- parts.push(text.substring(offset, pos));
1247
- }
1248
- if (replaceCh !== void 0) {
1249
- parts.push(_scanner.getTokenValue().replace(/[^\r\n]/g, replaceCh));
1250
- }
1251
- offset = _scanner.getPosition();
1252
- break;
1253
- }
1254
- } while (kind !== 17);
1255
- return parts.join("");
1256
- }
1257
- function getNodeType(value) {
1258
- switch (typeof value) {
1259
- case "boolean":
1260
- return "boolean";
1261
- case "number":
1262
- return "number";
1263
- case "string":
1264
- return "string";
1265
- case "object": {
1266
- if (!value) {
1267
- return "null";
1268
- } else if (Array.isArray(value)) {
1269
- return "array";
1270
- }
1271
- return "object";
1272
- }
1273
- default:
1274
- return "null";
1275
- }
1276
- }
1277
-
1278
- // ../../node_modules/.pnpm/jsonc-parser@3.2.0/node_modules/jsonc-parser/lib/esm/impl/edit.js
1279
- function setProperty(text, originalPath, value, options) {
1280
- const path = originalPath.slice();
1281
- const errors = [];
1282
- const root = parseTree(text, errors);
1283
- let parent = void 0;
1284
- let lastSegment = void 0;
1285
- while (path.length > 0) {
1286
- lastSegment = path.pop();
1287
- parent = findNodeAtLocation(root, path);
1288
- if (parent === void 0 && value !== void 0) {
1289
- if (typeof lastSegment === "string") {
1290
- value = { [lastSegment]: value };
1291
- } else {
1292
- value = [value];
1293
- }
1294
- } else {
1295
- break;
1296
- }
1297
- }
1298
- if (!parent) {
1299
- if (value === void 0) {
1300
- throw new Error("Can not delete in empty document");
1301
- }
1302
- return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
1303
- } else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
1304
- const existing = findNodeAtLocation(parent, [lastSegment]);
1305
- if (existing !== void 0) {
1306
- if (value === void 0) {
1307
- if (!existing.parent) {
1308
- throw new Error("Malformed AST");
1309
- }
1310
- const propertyIndex = parent.children.indexOf(existing.parent);
1311
- let removeBegin;
1312
- let removeEnd = existing.parent.offset + existing.parent.length;
1313
- if (propertyIndex > 0) {
1314
- let previous = parent.children[propertyIndex - 1];
1315
- removeBegin = previous.offset + previous.length;
1316
- } else {
1317
- removeBegin = parent.offset + 1;
1318
- if (parent.children.length > 1) {
1319
- let next = parent.children[1];
1320
- removeEnd = next.offset;
1321
- }
1322
- }
1323
- return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
1324
- } else {
1325
- return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
1326
- }
1327
- } else {
1328
- if (value === void 0) {
1329
- return [];
1330
- }
1331
- const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
1332
- const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
1333
- let edit;
1334
- if (index > 0) {
1335
- let previous = parent.children[index - 1];
1336
- edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1337
- } else if (parent.children.length === 0) {
1338
- edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1339
- } else {
1340
- edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
1341
- }
1342
- return withFormatting(text, edit, options);
1343
- }
1344
- } else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
1345
- const insertIndex = lastSegment;
1346
- if (insertIndex === -1) {
1347
- const newProperty = `${JSON.stringify(value)}`;
1348
- let edit;
1349
- if (parent.children.length === 0) {
1350
- edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1351
- } else {
1352
- const previous = parent.children[parent.children.length - 1];
1353
- edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1354
- }
1355
- return withFormatting(text, edit, options);
1356
- } else if (value === void 0 && parent.children.length >= 0) {
1357
- const removalIndex = lastSegment;
1358
- const toRemove = parent.children[removalIndex];
1359
- let edit;
1360
- if (parent.children.length === 1) {
1361
- edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
1362
- } else if (parent.children.length - 1 === removalIndex) {
1363
- let previous = parent.children[removalIndex - 1];
1364
- let offset = previous.offset + previous.length;
1365
- let parentEndOffset = parent.offset + parent.length;
1366
- edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
1367
- } else {
1368
- edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
1369
- }
1370
- return withFormatting(text, edit, options);
1371
- } else if (value !== void 0) {
1372
- let edit;
1373
- const newProperty = `${JSON.stringify(value)}`;
1374
- if (!options.isArrayInsertion && parent.children.length > lastSegment) {
1375
- const toModify = parent.children[lastSegment];
1376
- edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
1377
- } else if (parent.children.length === 0 || lastSegment === 0) {
1378
- edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
1379
- } else {
1380
- const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
1381
- const previous = parent.children[index - 1];
1382
- edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1383
- }
1384
- return withFormatting(text, edit, options);
1385
- } else {
1386
- throw new Error(`Can not ${value === void 0 ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
1387
- }
1388
- } else {
1389
- throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
1390
- }
1391
- }
1392
- function withFormatting(text, edit, options) {
1393
- if (!options.formattingOptions) {
1394
- return [edit];
1395
- }
1396
- let newText = applyEdit(text, edit);
1397
- let begin = edit.offset;
1398
- let end = edit.offset + edit.content.length;
1399
- if (edit.length === 0 || edit.content.length === 0) {
1400
- while (begin > 0 && !isEOL(newText, begin - 1)) {
1401
- begin--;
1402
- }
1403
- while (end < newText.length && !isEOL(newText, end)) {
1404
- end++;
1405
- }
1406
- }
1407
- const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
1408
- for (let i = edits.length - 1; i >= 0; i--) {
1409
- const edit2 = edits[i];
1410
- newText = applyEdit(newText, edit2);
1411
- begin = Math.min(begin, edit2.offset);
1412
- end = Math.max(end, edit2.offset + edit2.length);
1413
- end += edit2.content.length - edit2.length;
1414
- }
1415
- const editLength = text.length - (newText.length - end) - begin;
1416
- return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
1417
- }
1418
- function applyEdit(text, edit) {
1419
- return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
1420
- }
1421
-
1422
- // ../../node_modules/.pnpm/jsonc-parser@3.2.0/node_modules/jsonc-parser/lib/esm/main.js
1423
- var createScanner2 = createScanner;
1424
- var ScanError;
1425
- (function(ScanError2) {
1426
- ScanError2[ScanError2["None"] = 0] = "None";
1427
- ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
1428
- ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
1429
- ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
1430
- ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
1431
- ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
1432
- ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
1433
- })(ScanError || (ScanError = {}));
1434
- var SyntaxKind;
1435
- (function(SyntaxKind2) {
1436
- SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
1437
- SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
1438
- SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
1439
- SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
1440
- SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
1441
- SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
1442
- SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
1443
- SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
1444
- SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
1445
- SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
1446
- SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
1447
- SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
1448
- SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
1449
- SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
1450
- SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
1451
- SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
1452
- SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
1453
- })(SyntaxKind || (SyntaxKind = {}));
1454
- var getLocation2 = getLocation;
1455
- var parse2 = parse;
1456
- var parseTree2 = parseTree;
1457
- var findNodeAtLocation2 = findNodeAtLocation;
1458
- var findNodeAtOffset2 = findNodeAtOffset;
1459
- var getNodePath2 = getNodePath;
1460
- var getNodeValue2 = getNodeValue;
1461
- var visit2 = visit;
1462
- var stripComments2 = stripComments;
1463
- var ParseErrorCode;
1464
- (function(ParseErrorCode2) {
1465
- ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
1466
- ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
1467
- ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
1468
- ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
1469
- ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
1470
- ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
1471
- ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
1472
- ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
1473
- ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
1474
- ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
1475
- ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
1476
- ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
1477
- ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
1478
- ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
1479
- ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
1480
- ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
1481
- })(ParseErrorCode || (ParseErrorCode = {}));
1482
- function printParseErrorCode(code) {
1483
- switch (code) {
1484
- case 1:
1485
- return "InvalidSymbol";
1486
- case 2:
1487
- return "InvalidNumberFormat";
1488
- case 3:
1489
- return "PropertyNameExpected";
1490
- case 4:
1491
- return "ValueExpected";
1492
- case 5:
1493
- return "ColonExpected";
1494
- case 6:
1495
- return "CommaExpected";
1496
- case 7:
1497
- return "CloseBraceExpected";
1498
- case 8:
1499
- return "CloseBracketExpected";
1500
- case 9:
1501
- return "EndOfFileExpected";
1502
- case 10:
1503
- return "InvalidCommentToken";
1504
- case 11:
1505
- return "UnexpectedEndOfComment";
1506
- case 12:
1507
- return "UnexpectedEndOfString";
1508
- case 13:
1509
- return "UnexpectedEndOfNumber";
1510
- case 14:
1511
- return "InvalidUnicode";
1512
- case 15:
1513
- return "InvalidEscapeCharacter";
1514
- case 16:
1515
- return "InvalidCharacter";
1516
- }
1517
- return "<unknown ParseErrorCode>";
1518
- }
1519
- function format2(documentText, range, options) {
1520
- return format(documentText, range, options);
1521
- }
1522
- function modify(text, path, value, options) {
1523
- return setProperty(text, path, value, options);
1524
- }
1525
- function applyEdits(text, edits) {
1526
- let sortedEdits = edits.slice(0).sort((a, b) => {
1527
- const diff = a.offset - b.offset;
1528
- if (diff === 0) {
1529
- return a.length - b.length;
1530
- }
1531
- return diff;
1532
- });
1533
- let lastModifiedOffset = text.length;
1534
- for (let i = sortedEdits.length - 1; i >= 0; i--) {
1535
- let e = sortedEdits[i];
1536
- if (e.offset + e.length <= lastModifiedOffset) {
1537
- text = applyEdit(text, e);
1538
- } else {
1539
- throw new Error("Overlapping edit");
1540
- }
1541
- lastModifiedOffset = e.offset;
1542
- }
1543
- return text;
1544
- }
1545
- export {
1546
- ParseErrorCode,
1547
- ScanError,
1548
- SyntaxKind,
1549
- applyEdits,
1550
- createScanner2 as createScanner,
1551
- findNodeAtLocation2 as findNodeAtLocation,
1552
- findNodeAtOffset2 as findNodeAtOffset,
1553
- format2 as format,
1554
- getLocation2 as getLocation,
1555
- getNodePath2 as getNodePath,
1556
- getNodeValue2 as getNodeValue,
1557
- modify,
1558
- parse2 as parse,
1559
- parseTree2 as parseTree,
1560
- printParseErrorCode,
1561
- stripComments2 as stripComments,
1562
- visit2 as visit
1563
- };