50a56adcc32df0e9bc9c284057ab8bc8d7838e86.svn-base
67.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
import { c as _classCallCheck, j as _inherits, k as _createSuper, b as _createClass, e as _defineProperty, p as _assertThisInitialized, a as _typeof, q as _toArray, T as Type, _ as _createForOfIteratorHelper, l as _get, m as _getPrototypeOf, o as YAMLReferenceError, r as _possibleConstructorReturn, h as _slicedToArray, g as YAMLSemanticError, n as defaultTags, f as YAMLWarning, C as Char, Y as YAMLSyntaxError, P as PlainValue } from './PlainValue-ff5147c6.js';
function addCommentBefore(str, indent, comment) {
if (!comment) return str;
var cc = comment.replace(/[\s\S]^/gm, "$&".concat(indent, "#"));
return "#".concat(cc, "\n").concat(indent).concat(str);
}
function addComment(str, indent, comment) {
return !comment ? str : comment.indexOf('\n') === -1 ? "".concat(str, " #").concat(comment) : "".concat(str, "\n") + comment.replace(/^/gm, "".concat(indent || '', "#"));
}
var Node = function Node() {
_classCallCheck(this, Node);
};
function toJSON(value, arg, ctx) {
if (Array.isArray(value)) return value.map(function (v, i) {
return toJSON(v, String(i), ctx);
});
if (value && typeof value.toJSON === 'function') {
var anchor = ctx && ctx.anchors && ctx.anchors.get(value);
if (anchor) ctx.onCreate = function (res) {
anchor.res = res;
delete ctx.onCreate;
};
var res = value.toJSON(arg, ctx);
if (anchor && ctx.onCreate) ctx.onCreate(res);
return res;
}
if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value);
return value;
}
var Scalar = /*#__PURE__*/function (_Node) {
_inherits(Scalar, _Node);
var _super = _createSuper(Scalar);
function Scalar(value) {
var _this;
_classCallCheck(this, Scalar);
_this = _super.call(this);
_this.value = value;
return _this;
}
_createClass(Scalar, [{
key: "toJSON",
value: function toJSON$1(arg, ctx) {
return ctx && ctx.keep ? this.value : toJSON(this.value, arg, ctx);
}
}, {
key: "toString",
value: function toString() {
return String(this.value);
}
}]);
return Scalar;
}(Node);
function collectionFromPath(schema, path, value) {
var v = value;
for (var i = path.length - 1; i >= 0; --i) {
var k = path[i];
var o = Number.isInteger(k) && k >= 0 ? [] : {};
o[k] = v;
v = o;
}
return schema.createNode(v, false);
} // null, undefined, or an empty non-string iterable (e.g. [])
var isEmptyPath = function isEmptyPath(path) {
return path == null || _typeof(path) === 'object' && path[Symbol.iterator]().next().done;
};
var Collection = /*#__PURE__*/function (_Node) {
_inherits(Collection, _Node);
var _super = _createSuper(Collection);
function Collection(schema) {
var _this;
_classCallCheck(this, Collection);
_this = _super.call(this);
_defineProperty(_assertThisInitialized(_this), "items", []);
_this.schema = schema;
return _this;
}
_createClass(Collection, [{
key: "addIn",
value: function addIn(path, value) {
if (isEmptyPath(path)) this.add(value);else {
var _path = _toArray(path),
key = _path[0],
rest = _path.slice(1);
var node = this.get(key, true);
if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
}
}
}, {
key: "deleteIn",
value: function deleteIn(_ref) {
var _ref2 = _toArray(_ref),
key = _ref2[0],
rest = _ref2.slice(1);
if (rest.length === 0) return this.delete(key);
var node = this.get(key, true);
if (node instanceof Collection) return node.deleteIn(rest);else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
}
}, {
key: "getIn",
value: function getIn(_ref3, keepScalar) {
var _ref4 = _toArray(_ref3),
key = _ref4[0],
rest = _ref4.slice(1);
var node = this.get(key, true);
if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
}
}, {
key: "hasAllNullValues",
value: function hasAllNullValues() {
return this.items.every(function (node) {
if (!node || node.type !== 'PAIR') return false;
var n = node.value;
return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
});
}
}, {
key: "hasIn",
value: function hasIn(_ref5) {
var _ref6 = _toArray(_ref5),
key = _ref6[0],
rest = _ref6.slice(1);
if (rest.length === 0) return this.has(key);
var node = this.get(key, true);
return node instanceof Collection ? node.hasIn(rest) : false;
}
}, {
key: "setIn",
value: function setIn(_ref7, value) {
var _ref8 = _toArray(_ref7),
key = _ref8[0],
rest = _ref8.slice(1);
if (rest.length === 0) {
this.set(key, value);
} else {
var node = this.get(key, true);
if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
}
} // overridden in implementations
/* istanbul ignore next */
}, {
key: "toJSON",
value: function toJSON() {
return null;
}
}, {
key: "toString",
value: function toString(ctx, _ref9, onComment, onChompKeep) {
var _this2 = this;
var blockItem = _ref9.blockItem,
flowChars = _ref9.flowChars,
isMap = _ref9.isMap,
itemIndent = _ref9.itemIndent;
var _ctx = ctx,
indent = _ctx.indent,
indentStep = _ctx.indentStep,
stringify = _ctx.stringify;
var inFlow = this.type === Type.FLOW_MAP || this.type === Type.FLOW_SEQ || ctx.inFlow;
if (inFlow) itemIndent += indentStep;
var allNullValues = isMap && this.hasAllNullValues();
ctx = Object.assign({}, ctx, {
allNullValues: allNullValues,
indent: itemIndent,
inFlow: inFlow,
type: null
});
var chompKeep = false;
var hasItemWithNewLine = false;
var nodes = this.items.reduce(function (nodes, item, i) {
var comment;
if (item) {
if (!chompKeep && item.spaceBefore) nodes.push({
type: 'comment',
str: ''
});
if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(function (line) {
nodes.push({
type: 'comment',
str: "#".concat(line)
});
});
if (item.comment) comment = item.comment;
if (inFlow && (!chompKeep && item.spaceBefore || item.commentBefore || item.comment || item.key && (item.key.commentBefore || item.key.comment) || item.value && (item.value.commentBefore || item.value.comment))) hasItemWithNewLine = true;
}
chompKeep = false;
var str = stringify(item, ctx, function () {
return comment = null;
}, function () {
return chompKeep = true;
});
if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
if (inFlow && i < _this2.items.length - 1) str += ',';
str = addComment(str, itemIndent, comment);
if (chompKeep && (comment || inFlow)) chompKeep = false;
nodes.push({
type: 'item',
str: str
});
return nodes;
}, []);
var str;
if (nodes.length === 0) {
str = flowChars.start + flowChars.end;
} else if (inFlow) {
var start = flowChars.start,
end = flowChars.end;
var strings = nodes.map(function (n) {
return n.str;
});
if (hasItemWithNewLine || strings.reduce(function (sum, str) {
return sum + str.length + 2;
}, 2) > Collection.maxFlowStringSingleLineLength) {
str = start;
var _iterator = _createForOfIteratorHelper(strings),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var s = _step.value;
str += s ? "\n".concat(indentStep).concat(indent).concat(s) : '\n';
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
str += "\n".concat(indent).concat(end);
} else {
str = "".concat(start, " ").concat(strings.join(' '), " ").concat(end);
}
} else {
var _strings = nodes.map(blockItem);
str = _strings.shift();
var _iterator2 = _createForOfIteratorHelper(_strings),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _s = _step2.value;
str += _s ? "\n".concat(indent).concat(_s) : '\n';
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
if (this.comment) {
str += '\n' + this.comment.replace(/^/gm, "".concat(indent, "#"));
if (onComment) onComment();
} else if (chompKeep && onChompKeep) onChompKeep();
return str;
}
}]);
return Collection;
}(Node);
_defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
function asItemIndex(key) {
var idx = key instanceof Scalar ? key.value : key;
if (idx && typeof idx === 'string') idx = Number(idx);
return Number.isInteger(idx) && idx >= 0 ? idx : null;
}
var YAMLSeq = /*#__PURE__*/function (_Collection) {
_inherits(YAMLSeq, _Collection);
var _super = _createSuper(YAMLSeq);
function YAMLSeq() {
_classCallCheck(this, YAMLSeq);
return _super.apply(this, arguments);
}
_createClass(YAMLSeq, [{
key: "add",
value: function add(value) {
this.items.push(value);
}
}, {
key: "delete",
value: function _delete(key) {
var idx = asItemIndex(key);
if (typeof idx !== 'number') return false;
var del = this.items.splice(idx, 1);
return del.length > 0;
}
}, {
key: "get",
value: function get(key, keepScalar) {
var idx = asItemIndex(key);
if (typeof idx !== 'number') return undefined;
var it = this.items[idx];
return !keepScalar && it instanceof Scalar ? it.value : it;
}
}, {
key: "has",
value: function has(key) {
var idx = asItemIndex(key);
return typeof idx === 'number' && idx < this.items.length;
}
}, {
key: "set",
value: function set(key, value) {
var idx = asItemIndex(key);
if (typeof idx !== 'number') throw new Error("Expected a valid index, not ".concat(key, "."));
this.items[idx] = value;
}
}, {
key: "toJSON",
value: function toJSON$1(_, ctx) {
var seq = [];
if (ctx && ctx.onCreate) ctx.onCreate(seq);
var i = 0;
var _iterator = _createForOfIteratorHelper(this.items),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var item = _step.value;
seq.push(toJSON(item, String(i++), ctx));
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return seq;
}
}, {
key: "toString",
value: function toString(ctx, onComment, onChompKeep) {
if (!ctx) return JSON.stringify(this);
return _get(_getPrototypeOf(YAMLSeq.prototype), "toString", this).call(this, ctx, {
blockItem: function blockItem(n) {
return n.type === 'comment' ? n.str : "- ".concat(n.str);
},
flowChars: {
start: '[',
end: ']'
},
isMap: false,
itemIndent: (ctx.indent || '') + ' '
}, onComment, onChompKeep);
}
}]);
return YAMLSeq;
}(Collection);
var stringifyKey = function stringifyKey(key, jsKey, ctx) {
if (jsKey === null) return '';
if (_typeof(jsKey) !== 'object') return String(jsKey);
if (key instanceof Node && ctx && ctx.doc) return key.toString({
anchors: {},
doc: ctx.doc,
indent: '',
indentStep: ctx.indentStep,
inFlow: true,
inStringifyKey: true,
stringify: ctx.stringify
});
return JSON.stringify(jsKey);
};
var Pair = /*#__PURE__*/function (_Node) {
_inherits(Pair, _Node);
var _super = _createSuper(Pair);
function Pair(key) {
var _this;
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
_classCallCheck(this, Pair);
_this = _super.call(this);
_this.key = key;
_this.value = value;
_this.type = Pair.Type.PAIR;
return _this;
}
_createClass(Pair, [{
key: "addToJSMap",
value: function addToJSMap(ctx, map) {
var key = toJSON(this.key, '', ctx);
if (map instanceof Map) {
var value = toJSON(this.value, key, ctx);
map.set(key, value);
} else if (map instanceof Set) {
map.add(key);
} else {
var stringKey = stringifyKey(this.key, key, ctx);
map[stringKey] = toJSON(this.value, stringKey, ctx);
}
return map;
}
}, {
key: "toJSON",
value: function toJSON(_, ctx) {
var pair = ctx && ctx.mapAsMap ? new Map() : {};
return this.addToJSMap(ctx, pair);
}
}, {
key: "toString",
value: function toString(ctx, onComment, onChompKeep) {
if (!ctx || !ctx.doc) return JSON.stringify(this);
var _ctx$doc$options = ctx.doc.options,
indentSize = _ctx$doc$options.indent,
indentSeq = _ctx$doc$options.indentSeq,
simpleKeys = _ctx$doc$options.simpleKeys;
var key = this.key,
value = this.value;
var keyComment = key instanceof Node && key.comment;
if (simpleKeys) {
if (keyComment) {
throw new Error('With simple keys, key nodes cannot have comments');
}
if (key instanceof Collection) {
var msg = 'With simple keys, collection cannot be used as a key value';
throw new Error(msg);
}
}
var explicitKey = !simpleKeys && (!key || keyComment || key instanceof Collection || key.type === Type.BLOCK_FOLDED || key.type === Type.BLOCK_LITERAL);
var _ctx = ctx,
doc = _ctx.doc,
indent = _ctx.indent,
indentStep = _ctx.indentStep,
stringify = _ctx.stringify;
ctx = Object.assign({}, ctx, {
implicitKey: !explicitKey,
indent: indent + indentStep
});
var chompKeep = false;
var str = stringify(key, ctx, function () {
return keyComment = null;
}, function () {
return chompKeep = true;
});
str = addComment(str, ctx.indent, keyComment);
if (ctx.allNullValues && !simpleKeys) {
if (this.comment) {
str = addComment(str, ctx.indent, this.comment);
if (onComment) onComment();
} else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
return ctx.inFlow ? str : "? ".concat(str);
}
str = explicitKey ? "? ".concat(str, "\n").concat(indent, ":") : "".concat(str, ":");
if (this.comment) {
// expected (but not strictly required) to be a single-line comment
str = addComment(str, ctx.indent, this.comment);
if (onComment) onComment();
}
var vcb = '';
var valueComment = null;
if (value instanceof Node) {
if (value.spaceBefore) vcb = '\n';
if (value.commentBefore) {
var cs = value.commentBefore.replace(/^/gm, "".concat(ctx.indent, "#"));
vcb += "\n".concat(cs);
}
valueComment = value.comment;
} else if (value && _typeof(value) === 'object') {
value = doc.schema.createNode(value, true);
}
ctx.implicitKey = false;
if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1;
chompKeep = false;
if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof YAMLSeq && value.type !== Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
// If indentSeq === false, consider '- ' as part of indentation where possible
ctx.indent = ctx.indent.substr(2);
}
var valueStr = stringify(value, ctx, function () {
return valueComment = null;
}, function () {
return chompKeep = true;
});
var ws = ' ';
if (vcb || this.comment) {
ws = "".concat(vcb, "\n").concat(ctx.indent);
} else if (!explicitKey && value instanceof Collection) {
var flow = valueStr[0] === '[' || valueStr[0] === '{';
if (!flow || valueStr.includes('\n')) ws = "\n".concat(ctx.indent);
}
if (chompKeep && !valueComment && onChompKeep) onChompKeep();
return addComment(str + ws + valueStr, ctx.indent, valueComment);
}
}, {
key: "commentBefore",
get: function get() {
return this.key instanceof Node ? this.key.commentBefore : undefined;
},
set: function set(cb) {
if (this.key == null) this.key = new Scalar(null);
if (this.key instanceof Node) this.key.commentBefore = cb;else {
var msg = 'Pair.commentBefore is an alias for Pair.key.commentBefore. To set it, the key must be a Node.';
throw new Error(msg);
}
}
}]);
return Pair;
}(Node);
_defineProperty(Pair, "Type", {
PAIR: 'PAIR',
MERGE_PAIR: 'MERGE_PAIR'
});
var getAliasCount = function getAliasCount(node, anchors) {
if (node instanceof Alias) {
var anchor = anchors.get(node.source);
return anchor.count * anchor.aliasCount;
} else if (node instanceof Collection) {
var count = 0;
var _iterator = _createForOfIteratorHelper(node.items),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var item = _step.value;
var c = getAliasCount(item, anchors);
if (c > count) count = c;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return count;
} else if (node instanceof Pair) {
var kc = getAliasCount(node.key, anchors);
var vc = getAliasCount(node.value, anchors);
return Math.max(kc, vc);
}
return 1;
};
var Alias = /*#__PURE__*/function (_Node) {
_inherits(Alias, _Node);
var _super = _createSuper(Alias);
_createClass(Alias, null, [{
key: "stringify",
value: function stringify(_ref, _ref2) {
var range = _ref.range,
source = _ref.source;
var anchors = _ref2.anchors,
doc = _ref2.doc,
implicitKey = _ref2.implicitKey,
inStringifyKey = _ref2.inStringifyKey;
var anchor = Object.keys(anchors).find(function (a) {
return anchors[a] === source;
});
if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
if (anchor) return "*".concat(anchor).concat(implicitKey ? ' ' : '');
var msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
throw new Error("".concat(msg, " [").concat(range, "]"));
}
}]);
function Alias(source) {
var _this;
_classCallCheck(this, Alias);
_this = _super.call(this);
_this.source = source;
_this.type = Type.ALIAS;
return _this;
}
_createClass(Alias, [{
key: "toJSON",
value: function toJSON$1(arg, ctx) {
if (!ctx) return toJSON(this.source, arg, ctx);
var anchors = ctx.anchors,
maxAliasCount = ctx.maxAliasCount;
var anchor = anchors.get(this.source);
/* istanbul ignore if */
if (!anchor || anchor.res === undefined) {
var msg = 'This should not happen: Alias anchor was not resolved?';
if (this.cstNode) throw new YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
}
if (maxAliasCount >= 0) {
anchor.count += 1;
if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
if (anchor.count * anchor.aliasCount > maxAliasCount) {
var _msg = 'Excessive alias count indicates a resource exhaustion attack';
if (this.cstNode) throw new YAMLReferenceError(this.cstNode, _msg);else throw new ReferenceError(_msg);
}
}
return anchor.res;
} // Only called when stringifying an alias mapping key while constructing
// Object output.
}, {
key: "toString",
value: function toString(ctx) {
return Alias.stringify(this, ctx);
}
}, {
key: "tag",
set: function set(t) {
throw new Error('Alias nodes cannot have tags');
}
}]);
return Alias;
}(Node);
_defineProperty(Alias, "default", true);
function findPair(items, key) {
var k = key instanceof Scalar ? key.value : key;
var _iterator = _createForOfIteratorHelper(items),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var it = _step.value;
if (it instanceof Pair) {
if (it.key === key || it.key === k) return it;
if (it.key && it.key.value === k) return it;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return undefined;
}
var YAMLMap = /*#__PURE__*/function (_Collection) {
_inherits(YAMLMap, _Collection);
var _super = _createSuper(YAMLMap);
function YAMLMap() {
_classCallCheck(this, YAMLMap);
return _super.apply(this, arguments);
}
_createClass(YAMLMap, [{
key: "add",
value: function add(pair, overwrite) {
if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value);
var prev = findPair(this.items, pair.key);
var sortEntries = this.schema && this.schema.sortMapEntries;
if (prev) {
if (overwrite) prev.value = pair.value;else throw new Error("Key ".concat(pair.key, " already set"));
} else if (sortEntries) {
var i = this.items.findIndex(function (item) {
return sortEntries(pair, item) < 0;
});
if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
} else {
this.items.push(pair);
}
}
}, {
key: "delete",
value: function _delete(key) {
var it = findPair(this.items, key);
if (!it) return false;
var del = this.items.splice(this.items.indexOf(it), 1);
return del.length > 0;
}
}, {
key: "get",
value: function get(key, keepScalar) {
var it = findPair(this.items, key);
var node = it && it.value;
return !keepScalar && node instanceof Scalar ? node.value : node;
}
}, {
key: "has",
value: function has(key) {
return !!findPair(this.items, key);
}
}, {
key: "set",
value: function set(key, value) {
this.add(new Pair(key, value), true);
}
/**
* @param {*} arg ignored
* @param {*} ctx Conversion context, originally set in Document#toJSON()
* @param {Class} Type If set, forces the returned collection type
* @returns {*} Instance of Type, Map, or Object
*/
}, {
key: "toJSON",
value: function toJSON(_, ctx, Type) {
var map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
if (ctx && ctx.onCreate) ctx.onCreate(map);
var _iterator2 = _createForOfIteratorHelper(this.items),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var item = _step2.value;
item.addToJSMap(ctx, map);
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
return map;
}
}, {
key: "toString",
value: function toString(ctx, onComment, onChompKeep) {
if (!ctx) return JSON.stringify(this);
var _iterator3 = _createForOfIteratorHelper(this.items),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var item = _step3.value;
if (!(item instanceof Pair)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead"));
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
return _get(_getPrototypeOf(YAMLMap.prototype), "toString", this).call(this, ctx, {
blockItem: function blockItem(n) {
return n.str;
},
flowChars: {
start: '{',
end: '}'
},
isMap: true,
itemIndent: ctx.indent || ''
}, onComment, onChompKeep);
}
}]);
return YAMLMap;
}(Collection);
var MERGE_KEY = '<<';
var Merge = /*#__PURE__*/function (_Pair) {
_inherits(Merge, _Pair);
var _super = _createSuper(Merge);
function Merge(pair) {
var _this;
_classCallCheck(this, Merge);
if (pair instanceof Pair) {
var seq = pair.value;
if (!(seq instanceof YAMLSeq)) {
seq = new YAMLSeq();
seq.items.push(pair.value);
seq.range = pair.value.range;
}
_this = _super.call(this, pair.key, seq);
_this.range = pair.range;
} else {
_this = _super.call(this, new Scalar(MERGE_KEY), new YAMLSeq());
}
_this.type = Pair.Type.MERGE_PAIR;
return _possibleConstructorReturn(_this);
} // If the value associated with a merge key is a single mapping node, each of
// its key/value pairs is inserted into the current mapping, unless the key
// already exists in it. If the value associated with the merge key is a
// sequence, then this sequence is expected to contain mapping nodes and each
// of these nodes is merged in turn according to its order in the sequence.
// Keys in mapping nodes earlier in the sequence override keys specified in
// later mapping nodes. -- http://yaml.org/type/merge.html
_createClass(Merge, [{
key: "addToJSMap",
value: function addToJSMap(ctx, map) {
var _iterator = _createForOfIteratorHelper(this.value.items),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var source = _step.value.source;
if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
var srcMap = source.toJSON(null, ctx, Map);
var _iterator2 = _createForOfIteratorHelper(srcMap),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _step2$value = _slicedToArray(_step2.value, 2),
key = _step2$value[0],
value = _step2$value[1];
if (map instanceof Map) {
if (!map.has(key)) map.set(key, value);
} else if (map instanceof Set) {
map.add(key);
} else {
if (!Object.prototype.hasOwnProperty.call(map, key)) map[key] = value;
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return map;
}
}, {
key: "toString",
value: function toString(ctx, onComment) {
var seq = this.value;
if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
this.value = seq.items[0];
var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
this.value = seq;
return str;
}
}]);
return Merge;
}(Pair);
var binaryOptions = {
defaultType: Type.BLOCK_LITERAL,
lineWidth: 76
};
var boolOptions = {
trueStr: 'true',
falseStr: 'false'
};
var intOptions = {
asBigInt: false
};
var nullOptions = {
nullStr: 'null'
};
var strOptions = {
defaultType: Type.PLAIN,
doubleQuoted: {
jsonEncoding: false,
minMultiLineLength: 40
},
fold: {
lineWidth: 80,
minContentWidth: 20
}
};
function resolveScalar(str, tags, scalarFallback) {
var _iterator = _createForOfIteratorHelper(tags),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _step$value = _step.value,
format = _step$value.format,
test = _step$value.test,
resolve = _step$value.resolve;
if (test) {
var match = str.match(test);
if (match) {
var res = resolve.apply(null, match);
if (!(res instanceof Scalar)) res = new Scalar(res);
if (format) res.format = format;
return res;
}
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
if (scalarFallback) str = scalarFallback(str);
return new Scalar(str);
}
var FOLD_FLOW = 'flow';
var FOLD_BLOCK = 'block';
var FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line
// returns index of last newline in more-indented block
var consumeMoreIndentedLines = function consumeMoreIndentedLines(text, i) {
var ch = text[i + 1];
while (ch === ' ' || ch === '\t') {
do {
ch = text[i += 1];
} while (ch && ch !== '\n');
ch = text[i + 1];
}
return i;
};
/**
* Tries to keep input at up to `lineWidth` characters, splitting only on spaces
* not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
* terminated with `\n` and started with `indent`.
*
* @param {string} text
* @param {string} indent
* @param {string} [mode='flow'] `'block'` prevents more-indented lines
* from being folded; `'quoted'` allows for `\` escapes, including escaped
* newlines
* @param {Object} options
* @param {number} [options.indentAtStart] Accounts for leading contents on
* the first line, defaulting to `indent.length`
* @param {number} [options.lineWidth=80]
* @param {number} [options.minContentWidth=20] Allow highly indented lines to
* stretch the line width
* @param {function} options.onFold Called once if the text is folded
* @param {function} options.onFold Called once if any line of text exceeds
* lineWidth characters
*/
function foldFlowLines(text, indent, mode, _ref) {
var indentAtStart = _ref.indentAtStart,
_ref$lineWidth = _ref.lineWidth,
lineWidth = _ref$lineWidth === void 0 ? 80 : _ref$lineWidth,
_ref$minContentWidth = _ref.minContentWidth,
minContentWidth = _ref$minContentWidth === void 0 ? 20 : _ref$minContentWidth,
onFold = _ref.onFold,
onOverflow = _ref.onOverflow;
if (!lineWidth || lineWidth < 0) return text;
var endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
if (text.length <= endStep) return text;
var folds = [];
var escapedFolds = {};
var end = lineWidth - (typeof indentAtStart === 'number' ? indentAtStart : indent.length);
var split = undefined;
var prev = undefined;
var overflow = false;
var i = -1;
if (mode === FOLD_BLOCK) {
i = consumeMoreIndentedLines(text, i);
if (i !== -1) end = i + endStep;
}
for (var ch; ch = text[i += 1];) {
if (mode === FOLD_QUOTED && ch === '\\') {
switch (text[i + 1]) {
case 'x':
i += 3;
break;
case 'u':
i += 5;
break;
case 'U':
i += 9;
break;
default:
i += 1;
}
}
if (ch === '\n') {
if (mode === FOLD_BLOCK) i = consumeMoreIndentedLines(text, i);
end = i + endStep;
split = undefined;
} else {
if (ch === ' ' && prev && prev !== ' ' && prev !== '\n' && prev !== '\t') {
// space surrounded by non-space can be replaced with newline + indent
var next = text[i + 1];
if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i;
}
if (i >= end) {
if (split) {
folds.push(split);
end = split + endStep;
split = undefined;
} else if (mode === FOLD_QUOTED) {
// white-space collected at end may stretch past lineWidth
while (prev === ' ' || prev === '\t') {
prev = ch;
ch = text[i += 1];
overflow = true;
} // i - 2 accounts for not-dropped last char + newline-escaping \
folds.push(i - 2);
escapedFolds[i - 2] = true;
end = i - 2 + endStep;
split = undefined;
} else {
overflow = true;
}
}
}
prev = ch;
}
if (overflow && onOverflow) onOverflow();
if (folds.length === 0) return text;
if (onFold) onFold();
var res = text.slice(0, folds[0]);
for (var _i = 0; _i < folds.length; ++_i) {
var fold = folds[_i];
var _end = folds[_i + 1] || text.length;
if (mode === FOLD_QUOTED && escapedFolds[fold]) res += "".concat(text[fold], "\\");
res += "\n".concat(indent).concat(text.slice(fold + 1, _end));
}
return res;
}
var getFoldOptions = function getFoldOptions(_ref) {
var indentAtStart = _ref.indentAtStart;
return indentAtStart ? Object.assign({
indentAtStart: indentAtStart
}, strOptions.fold) : strOptions.fold;
}; // Also checks for lines starting with %, as parsing the output as YAML 1.1 will
// presume that's starting a new document.
var containsDocumentMarker = function containsDocumentMarker(str) {
return /^(%|---|\.\.\.)/m.test(str);
};
function lineLengthOverLimit(str, limit) {
var strLen = str.length;
if (strLen <= limit) return false;
for (var i = 0, start = 0; i < strLen; ++i) {
if (str[i] === '\n') {
if (i - start > limit) return true;
start = i + 1;
if (strLen - start <= limit) return false;
}
}
return true;
}
function doubleQuotedString(value, ctx) {
var implicitKey = ctx.implicitKey;
var _strOptions$doubleQuo = strOptions.doubleQuoted,
jsonEncoding = _strOptions$doubleQuo.jsonEncoding,
minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength;
var json = JSON.stringify(value);
if (jsonEncoding) return json;
var indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
var str = '';
var start = 0;
for (var i = 0, ch = json[i]; ch; ch = json[++i]) {
if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') {
// space before newline needs to be escaped to not be folded
str += json.slice(start, i) + '\\ ';
i += 1;
start = i;
ch = '\\';
}
if (ch === '\\') switch (json[i + 1]) {
case 'u':
{
str += json.slice(start, i);
var code = json.substr(i + 2, 4);
switch (code) {
case '0000':
str += '\\0';
break;
case '0007':
str += '\\a';
break;
case '000b':
str += '\\v';
break;
case '001b':
str += '\\e';
break;
case '0085':
str += '\\N';
break;
case '00a0':
str += '\\_';
break;
case '2028':
str += '\\L';
break;
case '2029':
str += '\\P';
break;
default:
if (code.substr(0, 2) === '00') str += '\\x' + code.substr(2);else str += json.substr(i, 6);
}
i += 5;
start = i + 1;
}
break;
case 'n':
if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
i += 1;
} else {
// folding will eat first newline
str += json.slice(start, i) + '\n\n';
while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') {
str += '\n';
i += 2;
}
str += indent; // space after newline needs to be escaped to not be folded
if (json[i + 2] === ' ') str += '\\';
i += 1;
start = i + 1;
}
break;
default:
i += 1;
}
}
str = start ? str + json.slice(start) : json;
return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
}
function singleQuotedString(value, ctx) {
if (ctx.implicitKey) {
if (/\n/.test(value)) return doubleQuotedString(value, ctx);
} else {
// single quoted string can't have leading or trailing whitespace around newline
if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx);
}
var indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
var res = "'" + value.replace(/'/g, "''").replace(/\n+/g, "$&\n".concat(indent)) + "'";
return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
}
function blockString(_ref2, ctx, onComment, onChompKeep) {
var comment = _ref2.comment,
type = _ref2.type,
value = _ref2.value;
// 1. Block can't end in whitespace unless the last line is non-empty.
// 2. Strings consisting of only whitespace are best rendered explicitly.
if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
return doubleQuotedString(value, ctx);
}
var indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
var indentSize = indent ? '2' : '1'; // root is at -1
var literal = type === Type.BLOCK_FOLDED ? false : type === Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length);
var header = literal ? '|' : '>';
if (!value) return header + '\n';
var wsStart = '';
var wsEnd = '';
value = value.replace(/[\n\t ]*$/, function (ws) {
var n = ws.indexOf('\n');
if (n === -1) {
header += '-'; // strip
} else if (value === ws || n !== ws.length - 1) {
header += '+'; // keep
if (onChompKeep) onChompKeep();
}
wsEnd = ws.replace(/\n$/, '');
return '';
}).replace(/^[\n ]*/, function (ws) {
if (ws.indexOf(' ') !== -1) header += indentSize;
var m = ws.match(/ +$/);
if (m) {
wsStart = ws.slice(0, -m[0].length);
return m[0];
} else {
wsStart = ws;
return '';
}
});
if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, "$&".concat(indent));
if (wsStart) wsStart = wsStart.replace(/\n+/g, "$&".concat(indent));
if (comment) {
header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
if (onComment) onComment();
}
if (!value) return "".concat(header).concat(indentSize, "\n").concat(indent).concat(wsEnd);
if (literal) {
value = value.replace(/\n+/g, "$&".concat(indent));
return "".concat(header, "\n").concat(indent).concat(wsStart).concat(value).concat(wsEnd);
}
value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
// ^ ind.line ^ empty ^ capture next empty lines only at end of indent
.replace(/\n+/g, "$&".concat(indent));
var body = foldFlowLines("".concat(wsStart).concat(value).concat(wsEnd), indent, FOLD_BLOCK, strOptions.fold);
return "".concat(header, "\n").concat(indent).concat(body);
}
function plainString(item, ctx, onComment, onChompKeep) {
var comment = item.comment,
type = item.type,
value = item.value;
var actualString = ctx.actualString,
implicitKey = ctx.implicitKey,
indent = ctx.indent,
inFlow = ctx.inFlow;
if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) {
return doubleQuotedString(value, ctx);
}
if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
// not allowed:
// - empty string, '-' or '?'
// - start with an indicator character (except [?:-]) or /[?-] /
// - '\n ', ': ' or ' \n' anywhere
// - '#' not preceded by a non-space char
// - end with ' ' or ':'
return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
}
if (!implicitKey && !inFlow && type !== Type.PLAIN && value.indexOf('\n') !== -1) {
// Where allowed & type not set explicitly, prefer block style for multiline strings
return blockString(item, ctx, onComment, onChompKeep);
}
if (indent === '' && containsDocumentMarker(value)) {
ctx.forceBlockIndent = true;
return blockString(item, ctx, onComment, onChompKeep);
}
var str = value.replace(/\n+/g, "$&\n".concat(indent)); // Verify that output will be parsed as a string, as e.g. plain numbers and
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
// and others in v1.1.
if (actualString) {
var tags = ctx.doc.schema.tags;
var resolved = resolveScalar(str, tags, tags.scalarFallback).value;
if (typeof resolved !== 'string') return doubleQuotedString(value, ctx);
}
var body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
if (onComment) onComment();
return addCommentBefore(body, indent, comment);
}
return body;
}
function stringifyString(item, ctx, onComment, onChompKeep) {
var defaultType = strOptions.defaultType;
var implicitKey = ctx.implicitKey,
inFlow = ctx.inFlow;
var _item = item,
type = _item.type,
value = _item.value;
if (typeof value !== 'string') {
value = String(value);
item = Object.assign({}, item, {
value: value
});
}
var _stringify = function _stringify(_type) {
switch (_type) {
case Type.BLOCK_FOLDED:
case Type.BLOCK_LITERAL:
return blockString(item, ctx, onComment, onChompKeep);
case Type.QUOTE_DOUBLE:
return doubleQuotedString(value, ctx);
case Type.QUOTE_SINGLE:
return singleQuotedString(value, ctx);
case Type.PLAIN:
return plainString(item, ctx, onComment, onChompKeep);
default:
return null;
}
};
if (type !== Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
// force double quotes on control characters
type = Type.QUOTE_DOUBLE;
} else if ((implicitKey || inFlow) && (type === Type.BLOCK_FOLDED || type === Type.BLOCK_LITERAL)) {
// should not happen; blocks are not valid inside flow containers
type = Type.QUOTE_DOUBLE;
}
var res = _stringify(type);
if (res === null) {
res = _stringify(defaultType);
if (res === null) throw new Error("Unsupported default string type ".concat(defaultType));
}
return res;
}
function stringifyNumber(_ref) {
var format = _ref.format,
minFractionDigits = _ref.minFractionDigits,
tag = _ref.tag,
value = _ref.value;
if (typeof value === 'bigint') return String(value);
if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
var n = JSON.stringify(value);
if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) {
var i = n.indexOf('.');
if (i < 0) {
i = n.length;
n += '.';
}
var d = minFractionDigits - (n.length - i - 1);
while (d-- > 0) {
n += '0';
}
}
return n;
}
function checkFlowCollectionEnd(errors, cst) {
var char, name;
switch (cst.type) {
case Type.FLOW_MAP:
char = '}';
name = 'flow map';
break;
case Type.FLOW_SEQ:
char = ']';
name = 'flow sequence';
break;
default:
errors.push(new YAMLSemanticError(cst, 'Not a flow collection!?'));
return;
}
var lastItem;
for (var i = cst.items.length - 1; i >= 0; --i) {
var item = cst.items[i];
if (!item || item.type !== Type.COMMENT) {
lastItem = item;
break;
}
}
if (lastItem && lastItem.char !== char) {
var msg = "Expected ".concat(name, " to end with ").concat(char);
var err;
if (typeof lastItem.offset === 'number') {
err = new YAMLSemanticError(cst, msg);
err.offset = lastItem.offset + 1;
} else {
err = new YAMLSemanticError(lastItem, msg);
if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
}
errors.push(err);
}
}
function checkFlowCommentSpace(errors, comment) {
var prev = comment.context.src[comment.range.start - 1];
if (prev !== '\n' && prev !== '\t' && prev !== ' ') {
var msg = 'Comments must be separated from other tokens by white space characters';
errors.push(new YAMLSemanticError(comment, msg));
}
}
function getLongKeyError(source, key) {
var sk = String(key);
var k = sk.substr(0, 8) + '...' + sk.substr(-8);
return new YAMLSemanticError(source, "The \"".concat(k, "\" key is too long"));
}
function resolveComments(collection, comments) {
var _iterator = _createForOfIteratorHelper(comments),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _step$value = _step.value,
afterKey = _step$value.afterKey,
before = _step$value.before,
comment = _step$value.comment;
var item = collection.items[before];
if (!item) {
if (comment !== undefined) {
if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
}
} else {
if (afterKey && item.value) item = item.value;
if (comment === undefined) {
if (afterKey || !item.commentBefore) item.spaceBefore = true;
} else {
if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
}
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
// on error, will return { str: string, errors: Error[] }
function resolveString(doc, node) {
var res = node.strValue;
if (!res) return '';
if (typeof res === 'string') return res;
res.errors.forEach(function (error) {
if (!error.source) error.source = node;
doc.errors.push(error);
});
return res.str;
}
function resolveTagHandle(doc, node) {
var _node$tag = node.tag,
handle = _node$tag.handle,
suffix = _node$tag.suffix;
var prefix = doc.tagPrefixes.find(function (p) {
return p.handle === handle;
});
if (!prefix) {
var dtp = doc.getDefaults().tagPrefixes;
if (dtp) prefix = dtp.find(function (p) {
return p.handle === handle;
});
if (!prefix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag handle is non-default and was not declared."));
}
if (!suffix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix."));
if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
if (suffix[0] === '^') {
doc.warnings.push(new YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
return suffix;
}
if (/[:/]/.test(suffix)) {
// word/foo -> tag:word.yaml.org,2002:foo
var vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
return vocab ? "tag:".concat(vocab[1], ".yaml.org,2002:").concat(vocab[2]) : "tag:".concat(suffix);
}
}
return prefix.prefix + decodeURIComponent(suffix);
}
function resolveTagName(doc, node) {
var tag = node.tag,
type = node.type;
var nonSpecific = false;
if (tag) {
var handle = tag.handle,
suffix = tag.suffix,
verbatim = tag.verbatim;
if (verbatim) {
if (verbatim !== '!' && verbatim !== '!!') return verbatim;
var msg = "Verbatim tags aren't resolved, so ".concat(verbatim, " is invalid.");
doc.errors.push(new YAMLSemanticError(node, msg));
} else if (handle === '!' && !suffix) {
nonSpecific = true;
} else {
try {
return resolveTagHandle(doc, node);
} catch (error) {
doc.errors.push(error);
}
}
}
switch (type) {
case Type.BLOCK_FOLDED:
case Type.BLOCK_LITERAL:
case Type.QUOTE_DOUBLE:
case Type.QUOTE_SINGLE:
return defaultTags.STR;
case Type.FLOW_MAP:
case Type.MAP:
return defaultTags.MAP;
case Type.FLOW_SEQ:
case Type.SEQ:
return defaultTags.SEQ;
case Type.PLAIN:
return nonSpecific ? defaultTags.STR : null;
default:
return null;
}
}
function resolveByTagName(doc, node, tagName) {
var tags = doc.schema.tags;
var matchWithTest = [];
var _iterator = _createForOfIteratorHelper(tags),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var tag = _step.value;
if (tag.tag === tagName) {
if (tag.test) matchWithTest.push(tag);else {
var res = tag.resolve(doc, node);
return res instanceof Collection ? res : new Scalar(res);
}
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
var str = resolveString(doc, node);
if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback);
return null;
}
function getFallbackTagName(_ref) {
var type = _ref.type;
switch (type) {
case Type.FLOW_MAP:
case Type.MAP:
return defaultTags.MAP;
case Type.FLOW_SEQ:
case Type.SEQ:
return defaultTags.SEQ;
default:
return defaultTags.STR;
}
}
function resolveTag(doc, node, tagName) {
try {
var res = resolveByTagName(doc, node, tagName);
if (res) {
if (tagName && node.tag) res.tag = tagName;
return res;
}
} catch (error) {
/* istanbul ignore if */
if (!error.source) error.source = node;
doc.errors.push(error);
return null;
}
try {
var fallback = getFallbackTagName(node);
if (!fallback) throw new Error("The tag ".concat(tagName, " is unavailable"));
var msg = "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback);
doc.warnings.push(new YAMLWarning(node, msg));
var _res = resolveByTagName(doc, node, fallback);
_res.tag = tagName;
return _res;
} catch (error) {
var refError = new YAMLReferenceError(node, error.message);
refError.stack = error.stack;
doc.errors.push(refError);
return null;
}
}
var isCollectionItem = function isCollectionItem(node) {
if (!node) return false;
var type = node.type;
return type === Type.MAP_KEY || type === Type.MAP_VALUE || type === Type.SEQ_ITEM;
};
function resolveNodeProps(errors, node) {
var comments = {
before: [],
after: []
};
var hasAnchor = false;
var hasTag = false;
var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
var _iterator = _createForOfIteratorHelper(props),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _step$value = _step.value,
start = _step$value.start,
end = _step$value.end;
switch (node.context.src[start]) {
case Char.COMMENT:
{
if (!node.commentHasRequiredWhitespace(start)) {
var msg = 'Comments must be separated from other tokens by white space characters';
errors.push(new YAMLSemanticError(node, msg));
}
var header = node.header,
valueRange = node.valueRange;
var cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before;
cc.push(node.context.src.slice(start + 1, end));
break;
}
// Actual anchor & tag resolution is handled by schema, here we just complain
case Char.ANCHOR:
if (hasAnchor) {
var _msg = 'A node can have at most one anchor';
errors.push(new YAMLSemanticError(node, _msg));
}
hasAnchor = true;
break;
case Char.TAG:
if (hasTag) {
var _msg2 = 'A node can have at most one tag';
errors.push(new YAMLSemanticError(node, _msg2));
}
hasTag = true;
break;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return {
comments: comments,
hasAnchor: hasAnchor,
hasTag: hasTag
};
}
function resolveNodeValue(doc, node) {
var anchors = doc.anchors,
errors = doc.errors,
schema = doc.schema;
if (node.type === Type.ALIAS) {
var name = node.rawValue;
var src = anchors.getNode(name);
if (!src) {
var msg = "Aliased anchor not found: ".concat(name);
errors.push(new YAMLReferenceError(node, msg));
return null;
} // Lazy resolution for circular references
var res = new Alias(src);
anchors._cstAliases.push(res);
return res;
}
var tagName = resolveTagName(doc, node);
if (tagName) return resolveTag(doc, node, tagName);
if (node.type !== Type.PLAIN) {
var _msg3 = "Failed to resolve ".concat(node.type, " node here");
errors.push(new YAMLSyntaxError(node, _msg3));
return null;
}
try {
var str = resolveString(doc, node);
return resolveScalar(str, schema.tags, schema.tags.scalarFallback);
} catch (error) {
if (!error.source) error.source = node;
errors.push(error);
return null;
}
} // sets node.resolved on success
function resolveNode(doc, node) {
if (!node) return null;
if (node.error) doc.errors.push(node.error);
var _resolveNodeProps = resolveNodeProps(doc.errors, node),
comments = _resolveNodeProps.comments,
hasAnchor = _resolveNodeProps.hasAnchor,
hasTag = _resolveNodeProps.hasTag;
if (hasAnchor) {
var anchors = doc.anchors;
var name = node.anchor;
var prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor
// name have already been resolved, so it may safely be renamed.
if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as
// anchors need to be available during resolution to allow for
// circular references.
anchors.map[name] = node;
}
if (node.type === Type.ALIAS && (hasAnchor || hasTag)) {
var msg = 'An alias node must not specify any properties';
doc.errors.push(new YAMLSemanticError(node, msg));
}
var res = resolveNodeValue(doc, node);
if (res) {
res.range = [node.range.start, node.range.end];
if (doc.options.keepCstNodes) res.cstNode = node;
if (doc.options.keepNodeTypes) res.type = node.type;
var cb = comments.before.join('\n');
if (cb) {
res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb;
}
var ca = comments.after.join('\n');
if (ca) res.comment = res.comment ? "".concat(res.comment, "\n").concat(ca) : ca;
}
return node.resolved = res;
}
function resolveMap(doc, cst) {
if (cst.type !== Type.MAP && cst.type !== Type.FLOW_MAP) {
var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping");
doc.errors.push(new YAMLSyntaxError(cst, msg));
return null;
}
var _ref = cst.type === Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst),
comments = _ref.comments,
items = _ref.items;
var map = new YAMLMap();
map.items = items;
resolveComments(map, comments);
var hasCollectionKey = false;
for (var i = 0; i < items.length; ++i) {
var iKey = items[i].key;
if (iKey instanceof Collection) hasCollectionKey = true;
if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
items[i] = new Merge(items[i]);
var sources = items[i].value.items;
var error = null;
sources.some(function (node) {
if (node instanceof Alias) {
// During parsing, alias sources are CST nodes; to account for
// circular references their resolved values can't be used here.
var type = node.source.type;
if (type === Type.MAP || type === Type.FLOW_MAP) return false;
return error = 'Merge nodes aliases can only point to maps';
}
return error = 'Merge nodes can only have Alias nodes as values';
});
if (error) doc.errors.push(new YAMLSemanticError(cst, error));
} else {
for (var j = i + 1; j < items.length; ++j) {
var jKey = items[j].key;
if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
var _msg = "Map keys must be unique; \"".concat(iKey, "\" is repeated");
doc.errors.push(new YAMLSemanticError(cst, _msg));
break;
}
}
}
}
if (hasCollectionKey && !doc.options.mapAsMap) {
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
doc.warnings.push(new YAMLWarning(cst, warn));
}
cst.resolved = map;
return map;
}
var valueHasPairComment = function valueHasPairComment(_ref2) {
var _ref2$context = _ref2.context,
lineStart = _ref2$context.lineStart,
node = _ref2$context.node,
src = _ref2$context.src,
props = _ref2.props;
if (props.length === 0) return false;
var start = props[0].start;
if (node && start > node.valueRange.start) return false;
if (src[start] !== Char.COMMENT) return false;
for (var i = lineStart; i < start; ++i) {
if (src[i] === '\n') return false;
}
return true;
};
function resolvePairComment(item, pair) {
if (!valueHasPairComment(item)) return;
var comment = item.getPropValue(0, Char.COMMENT, true);
var found = false;
var cb = pair.value.commentBefore;
if (cb && cb.startsWith(comment)) {
pair.value.commentBefore = cb.substr(comment.length + 1);
found = true;
} else {
var cc = pair.value.comment;
if (!item.node && cc && cc.startsWith(comment)) {
pair.value.comment = cc.substr(comment.length + 1);
found = true;
}
}
if (found) pair.comment = comment;
}
function resolveBlockMapItems(doc, cst) {
var comments = [];
var items = [];
var key = undefined;
var keyStart = null;
for (var i = 0; i < cst.items.length; ++i) {
var item = cst.items[i];
switch (item.type) {
case Type.BLANK_LINE:
comments.push({
afterKey: !!key,
before: items.length
});
break;
case Type.COMMENT:
comments.push({
afterKey: !!key,
before: items.length,
comment: item.comment
});
break;
case Type.MAP_KEY:
if (key !== undefined) items.push(new Pair(key));
if (item.error) doc.errors.push(item.error);
key = resolveNode(doc, item.node);
keyStart = null;
break;
case Type.MAP_VALUE:
{
if (key === undefined) key = null;
if (item.error) doc.errors.push(item.error);
if (!item.context.atLineStart && item.node && item.node.type === Type.MAP && !item.node.context.atLineStart) {
var msg = 'Nested mappings are not allowed in compact mappings';
doc.errors.push(new YAMLSemanticError(item.node, msg));
}
var valueNode = item.node;
if (!valueNode && item.props.length > 0) {
// Comments on an empty mapping value need to be preserved, so we
// need to construct a minimal empty node here to use instead of the
// missing `item.node`. -- eemeli/yaml#19
valueNode = new PlainValue(Type.PLAIN, []);
valueNode.context = {
parent: item,
src: item.context.src
};
var pos = item.range.start + 1;
valueNode.range = {
start: pos,
end: pos
};
valueNode.valueRange = {
start: pos,
end: pos
};
if (typeof item.range.origStart === 'number') {
var origPos = item.range.origStart + 1;
valueNode.range.origStart = valueNode.range.origEnd = origPos;
valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
}
}
var pair = new Pair(key, resolveNode(doc, valueNode));
resolvePairComment(item, pair);
items.push(pair);
if (key && typeof keyStart === 'number') {
if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
}
key = undefined;
keyStart = null;
}
break;
default:
if (key !== undefined) items.push(new Pair(key));
key = resolveNode(doc, item);
keyStart = item.range.start;
if (item.error) doc.errors.push(item.error);
next: for (var j = i + 1;; ++j) {
var nextItem = cst.items[j];
switch (nextItem && nextItem.type) {
case Type.BLANK_LINE:
case Type.COMMENT:
continue next;
case Type.MAP_VALUE:
break next;
default:
{
var _msg2 = 'Implicit map keys need to be followed by map values';
doc.errors.push(new YAMLSemanticError(item, _msg2));
break next;
}
}
}
if (item.valueRangeContainsNewline) {
var _msg3 = 'Implicit map keys need to be on a single line';
doc.errors.push(new YAMLSemanticError(item, _msg3));
}
}
}
if (key !== undefined) items.push(new Pair(key));
return {
comments: comments,
items: items
};
}
function resolveFlowMapItems(doc, cst) {
var comments = [];
var items = [];
var key = undefined;
var explicitKey = false;
var next = '{';
for (var i = 0; i < cst.items.length; ++i) {
var item = cst.items[i];
if (typeof item.char === 'string') {
var char = item.char,
offset = item.offset;
if (char === '?' && key === undefined && !explicitKey) {
explicitKey = true;
next = ':';
continue;
}
if (char === ':') {
if (key === undefined) key = null;
if (next === ':') {
next = ',';
continue;
}
} else {
if (explicitKey) {
if (key === undefined && char !== ',') key = null;
explicitKey = false;
}
if (key !== undefined) {
items.push(new Pair(key));
key = undefined;
if (char === ',') {
next = ':';
continue;
}
}
}
if (char === '}') {
if (i === cst.items.length - 1) continue;
} else if (char === next) {
next = ':';
continue;
}
var msg = "Flow map contains an unexpected ".concat(char);
var err = new YAMLSyntaxError(cst, msg);
err.offset = offset;
doc.errors.push(err);
} else if (item.type === Type.BLANK_LINE) {
comments.push({
afterKey: !!key,
before: items.length
});
} else if (item.type === Type.COMMENT) {
checkFlowCommentSpace(doc.errors, item);
comments.push({
afterKey: !!key,
before: items.length,
comment: item.comment
});
} else if (key === undefined) {
if (next === ',') doc.errors.push(new YAMLSemanticError(item, 'Separator , missing in flow map'));
key = resolveNode(doc, item);
} else {
if (next !== ',') doc.errors.push(new YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
items.push(new Pair(key, resolveNode(doc, item)));
key = undefined;
explicitKey = false;
}
}
checkFlowCollectionEnd(doc.errors, cst);
if (key !== undefined) items.push(new Pair(key));
return {
comments: comments,
items: items
};
}
function resolveSeq(doc, cst) {
if (cst.type !== Type.SEQ && cst.type !== Type.FLOW_SEQ) {
var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence");
doc.errors.push(new YAMLSyntaxError(cst, msg));
return null;
}
var _ref = cst.type === Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
comments = _ref.comments,
items = _ref.items;
var seq = new YAMLSeq();
seq.items = items;
resolveComments(seq, comments);
if (!doc.options.mapAsMap && items.some(function (it) {
return it instanceof Pair && it.key instanceof Collection;
})) {
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
doc.warnings.push(new YAMLWarning(cst, warn));
}
cst.resolved = seq;
return seq;
}
function resolveBlockSeqItems(doc, cst) {
var comments = [];
var items = [];
for (var i = 0; i < cst.items.length; ++i) {
var item = cst.items[i];
switch (item.type) {
case Type.BLANK_LINE:
comments.push({
before: items.length
});
break;
case Type.COMMENT:
comments.push({
comment: item.comment,
before: items.length
});
break;
case Type.SEQ_ITEM:
if (item.error) doc.errors.push(item.error);
items.push(resolveNode(doc, item.node));
if (item.hasProps) {
var msg = 'Sequence items cannot have tags or anchors before the - indicator';
doc.errors.push(new YAMLSemanticError(item, msg));
}
break;
default:
if (item.error) doc.errors.push(item.error);
doc.errors.push(new YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence")));
}
}
return {
comments: comments,
items: items
};
}
function resolveFlowSeqItems(doc, cst) {
var comments = [];
var items = [];
var explicitKey = false;
var key = undefined;
var keyStart = null;
var next = '[';
var prevItem = null;
for (var i = 0; i < cst.items.length; ++i) {
var item = cst.items[i];
if (typeof item.char === 'string') {
var char = item.char,
offset = item.offset;
if (char !== ':' && (explicitKey || key !== undefined)) {
if (explicitKey && key === undefined) key = next ? items.pop() : null;
items.push(new Pair(key));
explicitKey = false;
key = undefined;
keyStart = null;
}
if (char === next) {
next = null;
} else if (!next && char === '?') {
explicitKey = true;
} else if (next !== '[' && char === ':' && key === undefined) {
if (next === ',') {
key = items.pop();
if (key instanceof Pair) {
var msg = 'Chaining flow sequence pairs is invalid';
var err = new YAMLSemanticError(cst, msg);
err.offset = offset;
doc.errors.push(err);
}
if (!explicitKey && typeof keyStart === 'number') {
var keyEnd = item.range ? item.range.start : item.offset;
if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
var src = prevItem.context.src;
for (var _i = keyStart; _i < keyEnd; ++_i) {
if (src[_i] === '\n') {
var _msg = 'Implicit keys of flow sequence pairs need to be on a single line';
doc.errors.push(new YAMLSemanticError(prevItem, _msg));
break;
}
}
}
} else {
key = null;
}
keyStart = null;
explicitKey = false;
next = null;
} else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
var _msg2 = "Flow sequence contains an unexpected ".concat(char);
var _err = new YAMLSyntaxError(cst, _msg2);
_err.offset = offset;
doc.errors.push(_err);
}
} else if (item.type === Type.BLANK_LINE) {
comments.push({
before: items.length
});
} else if (item.type === Type.COMMENT) {
checkFlowCommentSpace(doc.errors, item);
comments.push({
comment: item.comment,
before: items.length
});
} else {
if (next) {
var _msg3 = "Expected a ".concat(next, " in flow sequence");
doc.errors.push(new YAMLSemanticError(item, _msg3));
}
var value = resolveNode(doc, item);
if (key === undefined) {
items.push(value);
prevItem = item;
} else {
items.push(new Pair(key, value));
key = undefined;
}
keyStart = item.range.start;
next = ',';
}
}
checkFlowCollectionEnd(doc.errors, cst);
if (key !== undefined) items.push(new Pair(key));
return {
comments: comments,
items: items
};
}
export { Alias as A, Collection as C, Merge as M, Node as N, Pair as P, Scalar as S, YAMLSeq as Y, boolOptions as a, binaryOptions as b, stringifyString as c, YAMLMap as d, isEmptyPath as e, addComment as f, resolveMap as g, resolveSeq as h, intOptions as i, resolveString as j, stringifyNumber as k, findPair as l, nullOptions as n, resolveNode as r, strOptions as s, toJSON as t };