yaml 2.0.0-3 → 2.0.0-7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (345) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +46 -26
  3. package/browser/dist/compose/compose-collection.js +59 -0
  4. package/browser/dist/compose/compose-doc.js +39 -0
  5. package/browser/dist/compose/compose-node.js +79 -0
  6. package/browser/dist/compose/compose-scalar.js +74 -0
  7. package/browser/dist/compose/composer.js +219 -0
  8. package/browser/dist/compose/resolve-block-map.js +93 -0
  9. package/browser/dist/compose/resolve-block-scalar.js +185 -0
  10. package/browser/dist/compose/resolve-block-seq.js +40 -0
  11. package/browser/dist/compose/resolve-end.js +37 -0
  12. package/browser/dist/compose/resolve-flow-collection.js +189 -0
  13. package/browser/dist/compose/resolve-flow-scalar.js +217 -0
  14. package/browser/dist/compose/resolve-props.js +126 -0
  15. package/browser/dist/compose/util-contains-newline.js +34 -0
  16. package/browser/dist/compose/util-empty-scalar-position.js +27 -0
  17. package/browser/dist/compose/util-map-includes.js +17 -0
  18. package/browser/dist/doc/Document.js +251 -348
  19. package/browser/dist/doc/anchors.js +72 -0
  20. package/browser/dist/doc/applyReviver.js +41 -28
  21. package/browser/dist/doc/createNode.js +75 -55
  22. package/browser/dist/doc/directives.js +161 -0
  23. package/browser/dist/errors.js +50 -72
  24. package/browser/dist/index.js +16 -72
  25. package/browser/dist/log.js +11 -7
  26. package/browser/dist/nodes/Alias.js +94 -0
  27. package/browser/dist/nodes/Collection.js +133 -0
  28. package/browser/dist/nodes/Node.js +41 -0
  29. package/browser/dist/nodes/Pair.js +28 -0
  30. package/browser/dist/nodes/Scalar.js +23 -0
  31. package/browser/dist/nodes/YAMLMap.js +116 -0
  32. package/browser/dist/nodes/YAMLSeq.js +105 -0
  33. package/browser/dist/nodes/addPairToJSMap.js +103 -0
  34. package/browser/dist/nodes/toJS.js +35 -0
  35. package/browser/dist/options.js +14 -95
  36. package/browser/dist/parse/cst-scalar.js +219 -0
  37. package/browser/dist/parse/cst-stringify.js +61 -0
  38. package/browser/dist/parse/cst-visit.js +97 -0
  39. package/browser/dist/parse/cst.js +98 -0
  40. package/browser/dist/parse/lexer.js +674 -0
  41. package/browser/dist/parse/line-counter.js +39 -0
  42. package/browser/dist/parse/parser.js +876 -0
  43. package/browser/dist/public-api.js +101 -0
  44. package/browser/dist/schema/Schema.js +23 -0
  45. package/browser/dist/schema/common/map.js +42 -0
  46. package/browser/dist/schema/common/null.js +13 -0
  47. package/browser/dist/schema/common/seq.js +33 -0
  48. package/browser/dist/schema/common/string.js +14 -0
  49. package/browser/dist/schema/core/bool.js +19 -0
  50. package/browser/dist/schema/core/float.js +40 -0
  51. package/browser/dist/schema/core/int.js +38 -0
  52. package/browser/dist/schema/core/schema.js +23 -0
  53. package/browser/dist/schema/json/schema.js +62 -0
  54. package/browser/dist/schema/tags.js +79 -0
  55. package/browser/dist/schema/yaml-1.1/binary.js +66 -0
  56. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  57. package/browser/dist/schema/yaml-1.1/float.js +43 -0
  58. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  59. package/browser/dist/schema/yaml-1.1/omap.js +73 -0
  60. package/browser/dist/schema/yaml-1.1/pairs.js +77 -0
  61. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  62. package/browser/dist/schema/yaml-1.1/set.js +87 -0
  63. package/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  64. package/browser/dist/stringify/foldFlowLines.js +121 -139
  65. package/browser/dist/stringify/stringify.js +87 -72
  66. package/browser/dist/stringify/stringifyCollection.js +122 -0
  67. package/browser/dist/stringify/stringifyComment.js +14 -0
  68. package/browser/dist/stringify/stringifyDocument.js +64 -0
  69. package/browser/dist/stringify/stringifyNumber.js +20 -23
  70. package/browser/dist/stringify/stringifyPair.js +111 -0
  71. package/browser/dist/stringify/stringifyString.js +295 -322
  72. package/browser/dist/util.js +4 -4
  73. package/browser/dist/visit.js +134 -71
  74. package/browser/index.js +4 -1
  75. package/dist/compose/compose-collection.d.ts +5 -0
  76. package/dist/compose/compose-collection.js +61 -0
  77. package/dist/compose/compose-doc.d.ts +6 -0
  78. package/dist/compose/compose-doc.js +41 -0
  79. package/dist/compose/compose-node.d.ts +25 -0
  80. package/dist/compose/compose-node.js +82 -0
  81. package/dist/compose/compose-scalar.d.ts +5 -0
  82. package/dist/compose/compose-scalar.js +76 -0
  83. package/dist/compose/composer.d.ts +62 -0
  84. package/dist/compose/composer.js +223 -0
  85. package/dist/compose/resolve-block-map.d.ts +6 -0
  86. package/dist/compose/resolve-block-map.js +95 -0
  87. package/dist/compose/resolve-block-scalar.d.ts +10 -0
  88. package/dist/compose/resolve-block-scalar.js +187 -0
  89. package/dist/compose/resolve-block-seq.d.ts +5 -0
  90. package/dist/compose/resolve-block-seq.js +42 -0
  91. package/dist/compose/resolve-end.d.ts +6 -0
  92. package/dist/compose/resolve-end.js +39 -0
  93. package/dist/compose/resolve-flow-collection.d.ts +6 -0
  94. package/dist/compose/resolve-flow-collection.js +191 -0
  95. package/dist/compose/resolve-flow-scalar.d.ts +10 -0
  96. package/dist/compose/resolve-flow-scalar.js +219 -0
  97. package/dist/compose/resolve-props.d.ts +21 -0
  98. package/dist/compose/resolve-props.js +128 -0
  99. package/dist/compose/util-contains-newline.d.ts +2 -0
  100. package/dist/compose/util-contains-newline.js +36 -0
  101. package/dist/compose/util-empty-scalar-position.d.ts +2 -0
  102. package/dist/compose/util-empty-scalar-position.js +29 -0
  103. package/dist/compose/util-map-includes.d.ts +4 -0
  104. package/dist/compose/util-map-includes.js +19 -0
  105. package/dist/doc/Document.d.ts +130 -0
  106. package/dist/doc/Document.js +250 -347
  107. package/dist/doc/anchors.d.ts +24 -0
  108. package/dist/doc/anchors.js +77 -0
  109. package/dist/doc/applyReviver.d.ts +9 -0
  110. package/dist/doc/applyReviver.js +41 -28
  111. package/dist/doc/createNode.d.ts +16 -0
  112. package/dist/doc/createNode.js +75 -55
  113. package/dist/doc/directives.d.ts +46 -0
  114. package/dist/doc/directives.js +163 -0
  115. package/dist/errors.d.ts +21 -0
  116. package/dist/errors.js +51 -74
  117. package/dist/index.d.ts +19 -0
  118. package/dist/index.js +39 -70
  119. package/dist/log.d.ts +3 -0
  120. package/dist/log.js +11 -6
  121. package/dist/nodes/Alias.d.ts +24 -0
  122. package/dist/nodes/Alias.js +96 -0
  123. package/dist/nodes/Collection.d.ts +67 -0
  124. package/dist/nodes/Collection.js +137 -0
  125. package/dist/nodes/Node.d.ts +48 -0
  126. package/dist/nodes/Node.js +59 -0
  127. package/dist/nodes/Pair.d.ts +16 -0
  128. package/dist/nodes/Pair.js +31 -0
  129. package/dist/nodes/Scalar.d.ts +40 -0
  130. package/dist/nodes/Scalar.js +26 -0
  131. package/dist/nodes/YAMLMap.d.ts +39 -0
  132. package/dist/nodes/YAMLMap.js +119 -0
  133. package/dist/nodes/YAMLSeq.d.ts +53 -0
  134. package/dist/nodes/YAMLSeq.js +107 -0
  135. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  136. package/dist/nodes/addPairToJSMap.js +105 -0
  137. package/dist/nodes/toJS.d.ts +30 -0
  138. package/dist/nodes/toJS.js +37 -0
  139. package/dist/options.d.ts +278 -0
  140. package/dist/options.js +13 -96
  141. package/dist/parse/cst-scalar.d.ts +58 -0
  142. package/dist/parse/cst-scalar.js +223 -0
  143. package/dist/parse/cst-stringify.d.ts +8 -0
  144. package/dist/parse/cst-stringify.js +63 -0
  145. package/dist/parse/cst-visit.d.ts +39 -0
  146. package/dist/parse/cst-visit.js +99 -0
  147. package/dist/parse/cst.d.ts +106 -0
  148. package/dist/parse/cst.js +112 -0
  149. package/dist/parse/lexer.d.ts +85 -0
  150. package/dist/parse/lexer.js +676 -0
  151. package/dist/parse/line-counter.d.ts +22 -0
  152. package/dist/parse/line-counter.js +41 -0
  153. package/dist/parse/parser.d.ts +84 -0
  154. package/dist/parse/parser.js +880 -0
  155. package/dist/public-api.d.ts +43 -0
  156. package/dist/public-api.js +106 -0
  157. package/dist/schema/Schema.d.ts +16 -0
  158. package/dist/schema/Schema.js +25 -0
  159. package/dist/schema/common/map.d.ts +2 -0
  160. package/dist/schema/common/map.js +44 -0
  161. package/dist/schema/common/null.d.ts +4 -0
  162. package/dist/schema/common/null.js +15 -0
  163. package/dist/schema/common/seq.d.ts +2 -0
  164. package/dist/schema/common/seq.js +35 -0
  165. package/dist/schema/common/string.d.ts +2 -0
  166. package/dist/schema/common/string.js +16 -0
  167. package/dist/schema/core/bool.d.ts +4 -0
  168. package/dist/schema/core/bool.js +21 -0
  169. package/dist/schema/core/float.d.ts +4 -0
  170. package/dist/schema/core/float.js +44 -0
  171. package/dist/schema/core/int.d.ts +4 -0
  172. package/dist/schema/core/int.js +42 -0
  173. package/dist/schema/core/schema.d.ts +1 -0
  174. package/dist/schema/core/schema.js +25 -0
  175. package/dist/schema/json/schema.d.ts +2 -0
  176. package/dist/schema/json/schema.js +64 -0
  177. package/dist/schema/tags.d.ts +41 -0
  178. package/dist/schema/tags.js +82 -0
  179. package/dist/schema/types.d.ts +82 -0
  180. package/dist/schema/yaml-1.1/binary.d.ts +2 -0
  181. package/dist/schema/yaml-1.1/binary.js +68 -0
  182. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  183. package/dist/schema/yaml-1.1/bool.js +29 -0
  184. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  185. package/dist/schema/yaml-1.1/float.js +47 -0
  186. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  187. package/dist/schema/yaml-1.1/int.js +76 -0
  188. package/dist/schema/yaml-1.1/omap.d.ts +21 -0
  189. package/dist/schema/yaml-1.1/omap.js +76 -0
  190. package/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  191. package/dist/schema/yaml-1.1/pairs.js +81 -0
  192. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  193. package/dist/schema/yaml-1.1/schema.js +39 -0
  194. package/dist/schema/yaml-1.1/set.d.ts +22 -0
  195. package/dist/schema/yaml-1.1/set.js +90 -0
  196. package/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  197. package/dist/schema/yaml-1.1/timestamp.js +105 -0
  198. package/dist/stringify/foldFlowLines.d.ts +34 -0
  199. package/dist/stringify/foldFlowLines.js +121 -139
  200. package/dist/stringify/stringify.d.ts +18 -0
  201. package/dist/stringify/stringify.js +87 -71
  202. package/dist/stringify/stringifyCollection.d.ts +21 -0
  203. package/dist/stringify/stringifyCollection.js +124 -0
  204. package/dist/stringify/stringifyComment.d.ts +2 -0
  205. package/dist/stringify/stringifyComment.js +17 -0
  206. package/dist/stringify/stringifyDocument.d.ts +3 -0
  207. package/dist/stringify/stringifyDocument.js +66 -0
  208. package/dist/stringify/stringifyNumber.d.ts +2 -0
  209. package/dist/stringify/stringifyNumber.js +20 -23
  210. package/dist/stringify/stringifyPair.d.ts +3 -0
  211. package/dist/stringify/stringifyPair.js +113 -0
  212. package/dist/stringify/stringifyString.d.ts +3 -0
  213. package/dist/stringify/stringifyString.js +295 -322
  214. package/dist/test-events.d.ts +4 -0
  215. package/dist/test-events.js +124 -148
  216. package/dist/util.d.ts +6 -0
  217. package/dist/util.js +9 -12
  218. package/dist/visit.d.ts +63 -0
  219. package/dist/visit.js +134 -71
  220. package/package.json +31 -39
  221. package/util.js +2 -14
  222. package/browser/dist/_virtual/_rollupPluginBabelHelpers.js +0 -16
  223. package/browser/dist/ast/Alias.js +0 -95
  224. package/browser/dist/ast/Collection.js +0 -192
  225. package/browser/dist/ast/Merge.js +0 -71
  226. package/browser/dist/ast/Node.js +0 -3
  227. package/browser/dist/ast/Pair.js +0 -200
  228. package/browser/dist/ast/Scalar.js +0 -21
  229. package/browser/dist/ast/YAMLMap.js +0 -91
  230. package/browser/dist/ast/YAMLSeq.js +0 -67
  231. package/browser/dist/ast/toJS.js +0 -29
  232. package/browser/dist/constants.js +0 -40
  233. package/browser/dist/cst/Alias.js +0 -26
  234. package/browser/dist/cst/BlankLine.js +0 -34
  235. package/browser/dist/cst/BlockValue.js +0 -240
  236. package/browser/dist/cst/Collection.js +0 -259
  237. package/browser/dist/cst/CollectionItem.js +0 -123
  238. package/browser/dist/cst/Comment.js +0 -27
  239. package/browser/dist/cst/Directive.js +0 -53
  240. package/browser/dist/cst/Document.js +0 -262
  241. package/browser/dist/cst/FlowCollection.js +0 -201
  242. package/browser/dist/cst/Node.js +0 -355
  243. package/browser/dist/cst/ParseContext.js +0 -234
  244. package/browser/dist/cst/PlainValue.js +0 -171
  245. package/browser/dist/cst/QuoteDouble.js +0 -224
  246. package/browser/dist/cst/QuoteSingle.js +0 -100
  247. package/browser/dist/cst/Range.js +0 -56
  248. package/browser/dist/cst/parse.js +0 -46
  249. package/browser/dist/cst/source-utils.js +0 -169
  250. package/browser/dist/doc/Anchors.js +0 -115
  251. package/browser/dist/doc/Schema.js +0 -34
  252. package/browser/dist/doc/getSchemaTags.js +0 -33
  253. package/browser/dist/doc/listTagNames.js +0 -27
  254. package/browser/dist/doc/parseContents.js +0 -60
  255. package/browser/dist/doc/parseDirectives.js +0 -107
  256. package/browser/dist/resolve/collection-utils.js +0 -86
  257. package/browser/dist/resolve/resolveMap.js +0 -315
  258. package/browser/dist/resolve/resolveNode.js +0 -173
  259. package/browser/dist/resolve/resolveScalar.js +0 -20
  260. package/browser/dist/resolve/resolveSeq.js +0 -170
  261. package/browser/dist/resolve/resolveTag.js +0 -107
  262. package/browser/dist/resolve/resolveTagName.js +0 -87
  263. package/browser/dist/stringify/addComment.js +0 -10
  264. package/browser/dist/stringify/stringifyTag.js +0 -28
  265. package/browser/dist/tags/core.js +0 -128
  266. package/browser/dist/tags/failsafe/index.js +0 -7
  267. package/browser/dist/tags/failsafe/map.js +0 -37
  268. package/browser/dist/tags/failsafe/seq.js +0 -34
  269. package/browser/dist/tags/failsafe/string.js +0 -20
  270. package/browser/dist/tags/index.js +0 -39
  271. package/browser/dist/tags/json.js +0 -62
  272. package/browser/dist/tags/options.js +0 -31
  273. package/browser/dist/tags/yaml-1.1/binary.js +0 -83
  274. package/browser/dist/tags/yaml-1.1/index.js +0 -174
  275. package/browser/dist/tags/yaml-1.1/omap.js +0 -86
  276. package/browser/dist/tags/yaml-1.1/pairs.js +0 -62
  277. package/browser/dist/tags/yaml-1.1/set.js +0 -78
  278. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -101
  279. package/browser/dist/types.js +0 -10
  280. package/cst.d.ts +0 -185
  281. package/dist/_virtual/_rollupPluginBabelHelpers.js +0 -18
  282. package/dist/ast/Alias.js +0 -97
  283. package/dist/ast/Collection.js +0 -196
  284. package/dist/ast/Merge.js +0 -74
  285. package/dist/ast/Node.js +0 -5
  286. package/dist/ast/Pair.js +0 -203
  287. package/dist/ast/Scalar.js +0 -24
  288. package/dist/ast/YAMLMap.js +0 -94
  289. package/dist/ast/YAMLSeq.js +0 -69
  290. package/dist/ast/toJS.js +0 -31
  291. package/dist/constants.js +0 -46
  292. package/dist/cst/Alias.js +0 -28
  293. package/dist/cst/BlankLine.js +0 -36
  294. package/dist/cst/BlockValue.js +0 -243
  295. package/dist/cst/Collection.js +0 -262
  296. package/dist/cst/CollectionItem.js +0 -125
  297. package/dist/cst/Comment.js +0 -29
  298. package/dist/cst/Directive.js +0 -55
  299. package/dist/cst/Document.js +0 -264
  300. package/dist/cst/FlowCollection.js +0 -203
  301. package/dist/cst/Node.js +0 -357
  302. package/dist/cst/ParseContext.js +0 -236
  303. package/dist/cst/PlainValue.js +0 -173
  304. package/dist/cst/QuoteDouble.js +0 -226
  305. package/dist/cst/QuoteSingle.js +0 -102
  306. package/dist/cst/Range.js +0 -58
  307. package/dist/cst/parse.js +0 -48
  308. package/dist/cst/source-utils.js +0 -173
  309. package/dist/doc/Anchors.js +0 -117
  310. package/dist/doc/Schema.js +0 -36
  311. package/dist/doc/getSchemaTags.js +0 -35
  312. package/dist/doc/listTagNames.js +0 -29
  313. package/dist/doc/parseContents.js +0 -62
  314. package/dist/doc/parseDirectives.js +0 -109
  315. package/dist/resolve/collection-utils.js +0 -91
  316. package/dist/resolve/resolveMap.js +0 -317
  317. package/dist/resolve/resolveNode.js +0 -175
  318. package/dist/resolve/resolveScalar.js +0 -22
  319. package/dist/resolve/resolveSeq.js +0 -172
  320. package/dist/resolve/resolveTag.js +0 -109
  321. package/dist/resolve/resolveTagName.js +0 -89
  322. package/dist/stringify/addComment.js +0 -13
  323. package/dist/stringify/stringifyTag.js +0 -30
  324. package/dist/tags/core.js +0 -138
  325. package/dist/tags/failsafe/index.js +0 -9
  326. package/dist/tags/failsafe/map.js +0 -39
  327. package/dist/tags/failsafe/seq.js +0 -36
  328. package/dist/tags/failsafe/string.js +0 -22
  329. package/dist/tags/index.js +0 -42
  330. package/dist/tags/json.js +0 -64
  331. package/dist/tags/options.js +0 -37
  332. package/dist/tags/yaml-1.1/binary.js +0 -85
  333. package/dist/tags/yaml-1.1/index.js +0 -176
  334. package/dist/tags/yaml-1.1/omap.js +0 -89
  335. package/dist/tags/yaml-1.1/pairs.js +0 -66
  336. package/dist/tags/yaml-1.1/set.js +0 -81
  337. package/dist/tags/yaml-1.1/timestamp.js +0 -105
  338. package/dist/types.js +0 -29
  339. package/index.d.ts +0 -519
  340. package/index.js +0 -1
  341. package/types.d.ts +0 -379
  342. package/types.js +0 -17
  343. package/types.mjs +0 -17
  344. package/util.d.ts +0 -76
  345. package/util.mjs +0 -15
@@ -0,0 +1,223 @@
1
+ 'use strict';
2
+
3
+ var directives = require('../doc/directives.js');
4
+ var Document = require('../doc/Document.js');
5
+ var errors = require('../errors.js');
6
+ var Node = require('../nodes/Node.js');
7
+ var options = require('../options.js');
8
+ var composeDoc = require('./compose-doc.js');
9
+ var resolveEnd = require('./resolve-end.js');
10
+
11
+ function getErrorPos(src) {
12
+ if (typeof src === 'number')
13
+ return [src, src + 1];
14
+ if (Array.isArray(src))
15
+ return src.length === 2 ? src : [src[0], src[1]];
16
+ const { offset, source } = src;
17
+ return [offset, offset + (typeof source === 'string' ? source.length : 1)];
18
+ }
19
+ function parsePrelude(prelude) {
20
+ var _a;
21
+ let comment = '';
22
+ let atComment = false;
23
+ let afterEmptyLine = false;
24
+ for (let i = 0; i < prelude.length; ++i) {
25
+ const source = prelude[i];
26
+ switch (source[0]) {
27
+ case '#':
28
+ comment +=
29
+ (comment === '' ? '' : afterEmptyLine ? '\n\n' : '\n') +
30
+ (source.substring(1) || ' ');
31
+ atComment = true;
32
+ afterEmptyLine = false;
33
+ break;
34
+ case '%':
35
+ if (((_a = prelude[i + 1]) === null || _a === void 0 ? void 0 : _a[0]) !== '#')
36
+ i += 1;
37
+ atComment = false;
38
+ break;
39
+ default:
40
+ // This may be wrong after doc-end, but in that case it doesn't matter
41
+ if (!atComment)
42
+ afterEmptyLine = true;
43
+ atComment = false;
44
+ }
45
+ }
46
+ return { comment, afterEmptyLine };
47
+ }
48
+ /**
49
+ * Compose a stream of CST nodes into a stream of YAML Documents.
50
+ *
51
+ * ```ts
52
+ * import { Composer, Parser } from 'yaml'
53
+ *
54
+ * const src: string = ...
55
+ * const tokens = new Parser().parse(src)
56
+ * const docs = new Composer().compose(tokens)
57
+ * ```
58
+ */
59
+ class Composer {
60
+ constructor(options$1 = {}) {
61
+ this.doc = null;
62
+ this.atDirectives = false;
63
+ this.prelude = [];
64
+ this.errors = [];
65
+ this.warnings = [];
66
+ this.onError = (source, code, message, warning) => {
67
+ const pos = getErrorPos(source);
68
+ if (warning)
69
+ this.warnings.push(new errors.YAMLWarning(pos, code, message));
70
+ else
71
+ this.errors.push(new errors.YAMLParseError(pos, code, message));
72
+ };
73
+ this.directives = new directives.Directives({
74
+ version: options$1.version || options.defaultOptions.version
75
+ });
76
+ this.options = options$1;
77
+ }
78
+ decorate(doc, afterDoc) {
79
+ const { comment, afterEmptyLine } = parsePrelude(this.prelude);
80
+ //console.log({ dc: doc.comment, prelude, comment })
81
+ if (comment) {
82
+ const dc = doc.contents;
83
+ if (afterDoc) {
84
+ doc.comment = doc.comment ? `${doc.comment}\n${comment}` : comment;
85
+ }
86
+ else if (afterEmptyLine || doc.directives.marker || !dc) {
87
+ doc.commentBefore = comment;
88
+ }
89
+ else if (Node.isCollection(dc) && !dc.flow && dc.items.length > 0) {
90
+ let it = dc.items[0];
91
+ if (Node.isPair(it))
92
+ it = it.key;
93
+ const cb = it.commentBefore;
94
+ it.commentBefore = cb ? `${comment}\n${cb}` : comment;
95
+ }
96
+ else {
97
+ const cb = dc.commentBefore;
98
+ dc.commentBefore = cb ? `${comment}\n${cb}` : comment;
99
+ }
100
+ }
101
+ if (afterDoc) {
102
+ Array.prototype.push.apply(doc.errors, this.errors);
103
+ Array.prototype.push.apply(doc.warnings, this.warnings);
104
+ }
105
+ else {
106
+ doc.errors = this.errors;
107
+ doc.warnings = this.warnings;
108
+ }
109
+ this.prelude = [];
110
+ this.errors = [];
111
+ this.warnings = [];
112
+ }
113
+ /**
114
+ * Current stream status information.
115
+ *
116
+ * Mostly useful at the end of input for an empty stream.
117
+ */
118
+ streamInfo() {
119
+ return {
120
+ comment: parsePrelude(this.prelude).comment,
121
+ directives: this.directives,
122
+ errors: this.errors,
123
+ warnings: this.warnings
124
+ };
125
+ }
126
+ /**
127
+ * Compose tokens into documents.
128
+ *
129
+ * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
130
+ * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
131
+ */
132
+ *compose(tokens, forceDoc = false, endOffset = -1) {
133
+ for (const token of tokens)
134
+ yield* this.next(token);
135
+ yield* this.end(forceDoc, endOffset);
136
+ }
137
+ /** Advance the composer by one CST token. */
138
+ *next(token) {
139
+ if (process.env.LOG_STREAM)
140
+ console.dir(token, { depth: null });
141
+ switch (token.type) {
142
+ case 'directive':
143
+ this.directives.add(token.source, (offset, message, warning) => {
144
+ const pos = getErrorPos(token);
145
+ pos[0] += offset;
146
+ this.onError(pos, 'BAD_DIRECTIVE', message, warning);
147
+ });
148
+ this.prelude.push(token.source);
149
+ this.atDirectives = true;
150
+ break;
151
+ case 'document': {
152
+ const doc = composeDoc.composeDoc(this.options, this.directives, token, this.onError);
153
+ if (this.atDirectives && !doc.directives.marker)
154
+ this.onError(token, 'MISSING_CHAR', 'Missing directives-end indicator line');
155
+ this.decorate(doc, false);
156
+ if (this.doc)
157
+ yield this.doc;
158
+ this.doc = doc;
159
+ this.atDirectives = false;
160
+ break;
161
+ }
162
+ case 'byte-order-mark':
163
+ case 'space':
164
+ break;
165
+ case 'comment':
166
+ case 'newline':
167
+ this.prelude.push(token.source);
168
+ break;
169
+ case 'error': {
170
+ const msg = token.source
171
+ ? `${token.message}: ${JSON.stringify(token.source)}`
172
+ : token.message;
173
+ const error = new errors.YAMLParseError(getErrorPos(token), 'UNEXPECTED_TOKEN', msg);
174
+ if (this.atDirectives || !this.doc)
175
+ this.errors.push(error);
176
+ else
177
+ this.doc.errors.push(error);
178
+ break;
179
+ }
180
+ case 'doc-end': {
181
+ if (!this.doc) {
182
+ const msg = 'Unexpected doc-end without preceding document';
183
+ this.errors.push(new errors.YAMLParseError(getErrorPos(token), 'UNEXPECTED_TOKEN', msg));
184
+ break;
185
+ }
186
+ const end = resolveEnd.resolveEnd(token.end, token.offset + token.source.length, this.doc.options.strict, this.onError);
187
+ this.decorate(this.doc, true);
188
+ if (end.comment) {
189
+ const dc = this.doc.comment;
190
+ this.doc.comment = dc ? `${dc}\n${end.comment}` : end.comment;
191
+ }
192
+ this.doc.range[2] = end.offset;
193
+ break;
194
+ }
195
+ default:
196
+ this.errors.push(new errors.YAMLParseError(getErrorPos(token), 'UNEXPECTED_TOKEN', `Unsupported token ${token.type}`));
197
+ }
198
+ }
199
+ /**
200
+ * Call at end of input to yield any remaining document.
201
+ *
202
+ * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
203
+ * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
204
+ */
205
+ *end(forceDoc = false, endOffset = -1) {
206
+ if (this.doc) {
207
+ this.decorate(this.doc, true);
208
+ yield this.doc;
209
+ this.doc = null;
210
+ }
211
+ else if (forceDoc) {
212
+ const opts = Object.assign({ directives: this.directives }, this.options);
213
+ const doc = new Document.Document(undefined, opts);
214
+ if (this.atDirectives)
215
+ this.onError(endOffset, 'MISSING_CHAR', 'Missing directives-end indicator line');
216
+ doc.range = [0, endOffset, endOffset];
217
+ this.decorate(doc, false);
218
+ yield doc;
219
+ }
220
+ }
221
+ }
222
+
223
+ exports.Composer = Composer;
@@ -0,0 +1,6 @@
1
+ import type { ParsedNode } from '../nodes/Node.js';
2
+ import { YAMLMap } from '../nodes/YAMLMap.js';
3
+ import type { BlockMap } from '../parse/cst.js';
4
+ import type { ComposeContext, ComposeNode } from './compose-node.js';
5
+ import type { ComposeErrorHandler } from './composer.js';
6
+ export declare function resolveBlockMap({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bm: BlockMap, onError: ComposeErrorHandler): YAMLMap.Parsed<ParsedNode, ParsedNode | null>;
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ var Pair = require('../nodes/Pair.js');
4
+ var YAMLMap = require('../nodes/YAMLMap.js');
5
+ var resolveProps = require('./resolve-props.js');
6
+ var utilContainsNewline = require('./util-contains-newline.js');
7
+ var utilMapIncludes = require('./util-map-includes.js');
8
+
9
+ const startColMsg = 'All mapping items must start at the same column';
10
+ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
11
+ var _a;
12
+ const map = new YAMLMap.YAMLMap(ctx.schema);
13
+ let offset = bm.offset;
14
+ for (const { start, key, sep, value } of bm.items) {
15
+ // key properties
16
+ const keyProps = resolveProps.resolveProps(start, {
17
+ indicator: 'explicit-key-ind',
18
+ next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
19
+ offset,
20
+ onError,
21
+ startOnNewline: true
22
+ });
23
+ const implicitKey = !keyProps.found;
24
+ if (implicitKey) {
25
+ if (key) {
26
+ if (key.type === 'block-seq')
27
+ onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'A block sequence may not be used as an implicit map key');
28
+ else if ('indent' in key && key.indent !== bm.indent)
29
+ onError(offset, 'BAD_INDENT', startColMsg);
30
+ }
31
+ if (!keyProps.anchor && !keyProps.tag && !sep) {
32
+ // TODO: assert being at last item?
33
+ if (keyProps.comment) {
34
+ if (map.comment)
35
+ map.comment += '\n' + keyProps.comment;
36
+ else
37
+ map.comment = keyProps.comment;
38
+ }
39
+ continue;
40
+ }
41
+ }
42
+ else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent)
43
+ onError(offset, 'BAD_INDENT', startColMsg);
44
+ if (implicitKey && utilContainsNewline.containsNewline(key))
45
+ onError(key, // checked by containsNewline()
46
+ 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
47
+ // key value
48
+ const keyStart = keyProps.end;
49
+ const keyNode = key
50
+ ? composeNode(ctx, key, keyProps, onError)
51
+ : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
52
+ if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
53
+ onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
54
+ // value properties
55
+ const valueProps = resolveProps.resolveProps(sep || [], {
56
+ indicator: 'map-value-ind',
57
+ next: value,
58
+ offset: keyNode.range[2],
59
+ onError,
60
+ startOnNewline: !key || key.type === 'block-scalar'
61
+ });
62
+ offset = valueProps.end;
63
+ if (valueProps.found) {
64
+ if (implicitKey) {
65
+ if ((value === null || value === void 0 ? void 0 : value.type) === 'block-map' && !valueProps.hasNewline)
66
+ onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
67
+ if (ctx.options.strict &&
68
+ keyProps.start < valueProps.found.offset - 1024)
69
+ onError(keyNode.range, 'KEY_OVER_1024_CHARS', 'The : indicator must be at most 1024 chars after the start of an implicit block mapping key');
70
+ }
71
+ // value value
72
+ const valueNode = value
73
+ ? composeNode(ctx, value, valueProps, onError)
74
+ : composeEmptyNode(ctx, offset, sep, null, valueProps, onError);
75
+ offset = valueNode.range[2];
76
+ map.items.push(new Pair.Pair(keyNode, valueNode));
77
+ }
78
+ else {
79
+ // key with no value
80
+ if (implicitKey)
81
+ onError(keyNode.range, 'MISSING_CHAR', 'Implicit map keys need to be followed by map values');
82
+ if (valueProps.comment) {
83
+ if (keyNode.comment)
84
+ keyNode.comment += '\n' + valueProps.comment;
85
+ else
86
+ keyNode.comment = valueProps.comment;
87
+ }
88
+ map.items.push(new Pair.Pair(keyNode));
89
+ }
90
+ }
91
+ map.range = [bm.offset, offset, offset];
92
+ return map;
93
+ }
94
+
95
+ exports.resolveBlockMap = resolveBlockMap;
@@ -0,0 +1,10 @@
1
+ import { Range } from '../nodes/Node.js';
2
+ import { Scalar } from '../nodes/Scalar.js';
3
+ import type { BlockScalar } from '../parse/cst.js';
4
+ import type { ComposeErrorHandler } from './composer.js';
5
+ export declare function resolveBlockScalar(scalar: BlockScalar, strict: boolean, onError: ComposeErrorHandler): {
6
+ value: string;
7
+ type: Scalar.BLOCK_FOLDED | Scalar.BLOCK_LITERAL | null;
8
+ comment: string;
9
+ range: Range;
10
+ };
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+
3
+ var Scalar = require('../nodes/Scalar.js');
4
+
5
+ function resolveBlockScalar(scalar, strict, onError) {
6
+ const start = scalar.offset;
7
+ const header = parseBlockScalarHeader(scalar, strict, onError);
8
+ if (!header)
9
+ return { value: '', type: null, comment: '', range: [start, start, start] };
10
+ const type = header.mode === '>' ? Scalar.Scalar.BLOCK_FOLDED : Scalar.Scalar.BLOCK_LITERAL;
11
+ const lines = scalar.source ? splitLines(scalar.source) : [];
12
+ // determine the end of content & start of chomping
13
+ let chompStart = lines.length;
14
+ for (let i = lines.length - 1; i >= 0; --i) {
15
+ const content = lines[i][1];
16
+ if (content === '' || content === '\r')
17
+ chompStart = i;
18
+ else
19
+ break;
20
+ }
21
+ // shortcut for empty contents
22
+ if (!scalar.source || chompStart === 0) {
23
+ const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
24
+ let end = start + header.length;
25
+ if (scalar.source)
26
+ end += scalar.source.length;
27
+ return { value, type, comment: header.comment, range: [start, end, end] };
28
+ }
29
+ // find the indentation level to trim from start
30
+ let trimIndent = scalar.indent + header.indent;
31
+ let offset = scalar.offset + header.length;
32
+ let contentStart = 0;
33
+ for (let i = 0; i < chompStart; ++i) {
34
+ const [indent, content] = lines[i];
35
+ if (content === '' || content === '\r') {
36
+ if (header.indent === 0 && indent.length > trimIndent)
37
+ trimIndent = indent.length;
38
+ }
39
+ else {
40
+ if (indent.length < trimIndent) {
41
+ const message = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
42
+ onError(offset + indent.length, 'MISSING_CHAR', message);
43
+ }
44
+ if (header.indent === 0)
45
+ trimIndent = indent.length;
46
+ contentStart = i;
47
+ break;
48
+ }
49
+ offset += indent.length + content.length + 1;
50
+ }
51
+ let value = '';
52
+ let sep = '';
53
+ let prevMoreIndented = false;
54
+ // leading whitespace is kept intact
55
+ for (let i = 0; i < contentStart; ++i)
56
+ value += lines[i][0].slice(trimIndent) + '\n';
57
+ for (let i = contentStart; i < chompStart; ++i) {
58
+ let [indent, content] = lines[i];
59
+ offset += indent.length + content.length + 1;
60
+ const crlf = content[content.length - 1] === '\r';
61
+ if (crlf)
62
+ content = content.slice(0, -1);
63
+ /* istanbul ignore if already caught in lexer */
64
+ if (content && indent.length < trimIndent) {
65
+ const src = header.indent
66
+ ? 'explicit indentation indicator'
67
+ : 'first line';
68
+ const message = `Block scalar lines must not be less indented than their ${src}`;
69
+ onError(offset - content.length - (crlf ? 2 : 1), 'BAD_INDENT', message);
70
+ indent = '';
71
+ }
72
+ if (type === Scalar.Scalar.BLOCK_LITERAL) {
73
+ value += sep + indent.slice(trimIndent) + content;
74
+ sep = '\n';
75
+ }
76
+ else if (indent.length > trimIndent || content[0] === '\t') {
77
+ // more-indented content within a folded block
78
+ if (sep === ' ')
79
+ sep = '\n';
80
+ else if (!prevMoreIndented && sep === '\n')
81
+ sep = '\n\n';
82
+ value += sep + indent.slice(trimIndent) + content;
83
+ sep = '\n';
84
+ prevMoreIndented = true;
85
+ }
86
+ else if (content === '') {
87
+ // empty line
88
+ if (sep === '\n')
89
+ value += '\n';
90
+ else
91
+ sep = '\n';
92
+ }
93
+ else {
94
+ value += sep + content;
95
+ sep = ' ';
96
+ prevMoreIndented = false;
97
+ }
98
+ }
99
+ switch (header.chomp) {
100
+ case '-':
101
+ break;
102
+ case '+':
103
+ for (let i = chompStart; i < lines.length; ++i)
104
+ value += '\n' + lines[i][0].slice(trimIndent);
105
+ if (value[value.length - 1] !== '\n')
106
+ value += '\n';
107
+ break;
108
+ default:
109
+ value += '\n';
110
+ }
111
+ const end = start + header.length + scalar.source.length;
112
+ return { value, type, comment: header.comment, range: [start, end, end] };
113
+ }
114
+ function parseBlockScalarHeader({ offset, props }, strict, onError) {
115
+ /* istanbul ignore if should not happen */
116
+ if (props[0].type !== 'block-scalar-header') {
117
+ onError(props[0], 'IMPOSSIBLE', 'Block scalar header not found');
118
+ return null;
119
+ }
120
+ const { source } = props[0];
121
+ const mode = source[0];
122
+ let indent = 0;
123
+ let chomp = '';
124
+ let error = -1;
125
+ for (let i = 1; i < source.length; ++i) {
126
+ const ch = source[i];
127
+ if (!chomp && (ch === '-' || ch === '+'))
128
+ chomp = ch;
129
+ else {
130
+ const n = Number(ch);
131
+ if (!indent && n)
132
+ indent = n;
133
+ else if (error === -1)
134
+ error = offset + i;
135
+ }
136
+ }
137
+ if (error !== -1)
138
+ onError(error, 'UNEXPECTED_TOKEN', `Block scalar header includes extra characters: ${source}`);
139
+ let hasSpace = false;
140
+ let comment = '';
141
+ let length = source.length;
142
+ for (let i = 1; i < props.length; ++i) {
143
+ const token = props[i];
144
+ switch (token.type) {
145
+ case 'space':
146
+ hasSpace = true;
147
+ // fallthrough
148
+ case 'newline':
149
+ length += token.source.length;
150
+ break;
151
+ case 'comment':
152
+ if (strict && !hasSpace) {
153
+ const message = 'Comments must be separated from other tokens by white space characters';
154
+ onError(token, 'MISSING_CHAR', message);
155
+ }
156
+ length += token.source.length;
157
+ comment = token.source.substring(1);
158
+ break;
159
+ case 'error':
160
+ onError(token, 'UNEXPECTED_TOKEN', token.message);
161
+ length += token.source.length;
162
+ break;
163
+ /* istanbul ignore next should not happen */
164
+ default: {
165
+ const message = `Unexpected token in block scalar header: ${token.type}`;
166
+ onError(token, 'UNEXPECTED_TOKEN', message);
167
+ const ts = token.source;
168
+ if (ts && typeof ts === 'string')
169
+ length += ts.length;
170
+ }
171
+ }
172
+ }
173
+ return { mode, indent, chomp, comment, length };
174
+ }
175
+ /** @returns Array of lines split up as `[indent, content]` */
176
+ function splitLines(source) {
177
+ const split = source.split(/\n( *)/);
178
+ const first = split[0];
179
+ const m = first.match(/^( *)/);
180
+ const line0 = m && m[1] ? [m[1], first.slice(m[1].length)] : ['', first];
181
+ const lines = [line0];
182
+ for (let i = 1; i < split.length; i += 2)
183
+ lines.push([split[i], split[i + 1]]);
184
+ return lines;
185
+ }
186
+
187
+ exports.resolveBlockScalar = resolveBlockScalar;
@@ -0,0 +1,5 @@
1
+ import { YAMLSeq } from '../nodes/YAMLSeq.js';
2
+ import type { BlockSequence } from '../parse/cst.js';
3
+ import type { ComposeContext, ComposeNode } from './compose-node.js';
4
+ import type { ComposeErrorHandler } from './composer.js';
5
+ export declare function resolveBlockSeq({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bs: BlockSequence, onError: ComposeErrorHandler): YAMLSeq.Parsed<import("../index.js").ParsedNode>;
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ var YAMLSeq = require('../nodes/YAMLSeq.js');
4
+ var resolveProps = require('./resolve-props.js');
5
+
6
+ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
7
+ const seq = new YAMLSeq.YAMLSeq(ctx.schema);
8
+ let offset = bs.offset;
9
+ for (const { start, value } of bs.items) {
10
+ const props = resolveProps.resolveProps(start, {
11
+ indicator: 'seq-item-ind',
12
+ next: value,
13
+ offset,
14
+ onError,
15
+ startOnNewline: true
16
+ });
17
+ offset = props.end;
18
+ if (!props.found) {
19
+ if (props.anchor || props.tag || value) {
20
+ if (value && value.type === 'block-seq')
21
+ onError(offset, 'BAD_INDENT', 'All sequence items must start at the same column');
22
+ else
23
+ onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
24
+ }
25
+ else {
26
+ // TODO: assert being at last item?
27
+ if (props.comment)
28
+ seq.comment = props.comment;
29
+ continue;
30
+ }
31
+ }
32
+ const node = value
33
+ ? composeNode(ctx, value, props, onError)
34
+ : composeEmptyNode(ctx, offset, start, null, props, onError);
35
+ offset = node.range[2];
36
+ seq.items.push(node);
37
+ }
38
+ seq.range = [bs.offset, offset, offset];
39
+ return seq;
40
+ }
41
+
42
+ exports.resolveBlockSeq = resolveBlockSeq;
@@ -0,0 +1,6 @@
1
+ import type { SourceToken } from '../parse/cst.js';
2
+ import type { ComposeErrorHandler } from './composer.js';
3
+ export declare function resolveEnd(end: SourceToken[] | undefined, offset: number, reqSpace: boolean, onError: ComposeErrorHandler): {
4
+ comment: string;
5
+ offset: number;
6
+ };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ function resolveEnd(end, offset, reqSpace, onError) {
4
+ let comment = '';
5
+ if (end) {
6
+ let hasSpace = false;
7
+ let sep = '';
8
+ for (const token of end) {
9
+ const { source, type } = token;
10
+ switch (type) {
11
+ case 'space':
12
+ hasSpace = true;
13
+ break;
14
+ case 'comment': {
15
+ if (reqSpace && !hasSpace)
16
+ onError(token, 'MISSING_CHAR', 'Comments must be separated from other tokens by white space characters');
17
+ const cb = source.substring(1) || ' ';
18
+ if (!comment)
19
+ comment = cb;
20
+ else
21
+ comment += sep + cb;
22
+ sep = '';
23
+ break;
24
+ }
25
+ case 'newline':
26
+ if (comment)
27
+ sep += source;
28
+ hasSpace = true;
29
+ break;
30
+ default:
31
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${type} at node end`);
32
+ }
33
+ offset += source.length;
34
+ }
35
+ }
36
+ return { comment, offset };
37
+ }
38
+
39
+ exports.resolveEnd = resolveEnd;
@@ -0,0 +1,6 @@
1
+ import { YAMLMap } from '../nodes/YAMLMap.js';
2
+ import { YAMLSeq } from '../nodes/YAMLSeq.js';
3
+ import type { FlowCollection } from '../parse/cst.js';
4
+ import type { ComposeContext, ComposeNode } from './compose-node.js';
5
+ import type { ComposeErrorHandler } from './composer.js';
6
+ export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../nodes/Node.js").ParsedNode, import("../nodes/Node.js").ParsedNode | null> | YAMLSeq.Parsed<import("../nodes/Node.js").ParsedNode>;