yaml 2.0.0-2 → 2.0.0-6

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 (347) 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 +72 -0
  6. package/browser/dist/compose/compose-scalar.js +74 -0
  7. package/browser/dist/compose/composer.js +218 -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 +211 -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 +71 -55
  22. package/browser/dist/doc/directives.js +161 -0
  23. package/browser/dist/errors.js +50 -72
  24. package/browser/dist/index.js +17 -73
  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 +656 -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 +146 -0
  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 +75 -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 +222 -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 +213 -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 +71 -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 +40 -71
  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 +658 -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 +148 -0
  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/ast/visit.js +0 -83
  233. package/browser/dist/constants.js +0 -40
  234. package/browser/dist/cst/Alias.js +0 -26
  235. package/browser/dist/cst/BlankLine.js +0 -34
  236. package/browser/dist/cst/BlockValue.js +0 -240
  237. package/browser/dist/cst/Collection.js +0 -259
  238. package/browser/dist/cst/CollectionItem.js +0 -123
  239. package/browser/dist/cst/Comment.js +0 -27
  240. package/browser/dist/cst/Directive.js +0 -53
  241. package/browser/dist/cst/Document.js +0 -262
  242. package/browser/dist/cst/FlowCollection.js +0 -201
  243. package/browser/dist/cst/Node.js +0 -355
  244. package/browser/dist/cst/ParseContext.js +0 -234
  245. package/browser/dist/cst/PlainValue.js +0 -171
  246. package/browser/dist/cst/QuoteDouble.js +0 -224
  247. package/browser/dist/cst/QuoteSingle.js +0 -100
  248. package/browser/dist/cst/Range.js +0 -56
  249. package/browser/dist/cst/parse.js +0 -46
  250. package/browser/dist/cst/source-utils.js +0 -169
  251. package/browser/dist/doc/Anchors.js +0 -115
  252. package/browser/dist/doc/Schema.js +0 -34
  253. package/browser/dist/doc/getSchemaTags.js +0 -33
  254. package/browser/dist/doc/listTagNames.js +0 -27
  255. package/browser/dist/doc/parseContents.js +0 -60
  256. package/browser/dist/doc/parseDirectives.js +0 -107
  257. package/browser/dist/resolve/collection-utils.js +0 -86
  258. package/browser/dist/resolve/resolveMap.js +0 -315
  259. package/browser/dist/resolve/resolveNode.js +0 -173
  260. package/browser/dist/resolve/resolveScalar.js +0 -20
  261. package/browser/dist/resolve/resolveSeq.js +0 -170
  262. package/browser/dist/resolve/resolveTag.js +0 -107
  263. package/browser/dist/resolve/resolveTagName.js +0 -87
  264. package/browser/dist/stringify/addComment.js +0 -10
  265. package/browser/dist/stringify/stringifyTag.js +0 -28
  266. package/browser/dist/tags/core.js +0 -128
  267. package/browser/dist/tags/failsafe/index.js +0 -7
  268. package/browser/dist/tags/failsafe/map.js +0 -37
  269. package/browser/dist/tags/failsafe/seq.js +0 -34
  270. package/browser/dist/tags/failsafe/string.js +0 -20
  271. package/browser/dist/tags/index.js +0 -39
  272. package/browser/dist/tags/json.js +0 -62
  273. package/browser/dist/tags/options.js +0 -31
  274. package/browser/dist/tags/yaml-1.1/binary.js +0 -83
  275. package/browser/dist/tags/yaml-1.1/index.js +0 -174
  276. package/browser/dist/tags/yaml-1.1/omap.js +0 -86
  277. package/browser/dist/tags/yaml-1.1/pairs.js +0 -62
  278. package/browser/dist/tags/yaml-1.1/set.js +0 -78
  279. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -101
  280. package/browser/dist/types.js +0 -10
  281. package/cst.d.ts +0 -185
  282. package/dist/_virtual/_rollupPluginBabelHelpers.js +0 -18
  283. package/dist/ast/Alias.js +0 -97
  284. package/dist/ast/Collection.js +0 -196
  285. package/dist/ast/Merge.js +0 -74
  286. package/dist/ast/Node.js +0 -5
  287. package/dist/ast/Pair.js +0 -203
  288. package/dist/ast/Scalar.js +0 -24
  289. package/dist/ast/YAMLMap.js +0 -94
  290. package/dist/ast/YAMLSeq.js +0 -69
  291. package/dist/ast/toJS.js +0 -31
  292. package/dist/ast/visit.js +0 -85
  293. package/dist/constants.js +0 -46
  294. package/dist/cst/Alias.js +0 -28
  295. package/dist/cst/BlankLine.js +0 -36
  296. package/dist/cst/BlockValue.js +0 -243
  297. package/dist/cst/Collection.js +0 -262
  298. package/dist/cst/CollectionItem.js +0 -125
  299. package/dist/cst/Comment.js +0 -29
  300. package/dist/cst/Directive.js +0 -55
  301. package/dist/cst/Document.js +0 -264
  302. package/dist/cst/FlowCollection.js +0 -203
  303. package/dist/cst/Node.js +0 -357
  304. package/dist/cst/ParseContext.js +0 -236
  305. package/dist/cst/PlainValue.js +0 -173
  306. package/dist/cst/QuoteDouble.js +0 -226
  307. package/dist/cst/QuoteSingle.js +0 -102
  308. package/dist/cst/Range.js +0 -58
  309. package/dist/cst/parse.js +0 -48
  310. package/dist/cst/source-utils.js +0 -173
  311. package/dist/doc/Anchors.js +0 -117
  312. package/dist/doc/Schema.js +0 -36
  313. package/dist/doc/getSchemaTags.js +0 -35
  314. package/dist/doc/listTagNames.js +0 -29
  315. package/dist/doc/parseContents.js +0 -62
  316. package/dist/doc/parseDirectives.js +0 -109
  317. package/dist/resolve/collection-utils.js +0 -91
  318. package/dist/resolve/resolveMap.js +0 -317
  319. package/dist/resolve/resolveNode.js +0 -175
  320. package/dist/resolve/resolveScalar.js +0 -22
  321. package/dist/resolve/resolveSeq.js +0 -172
  322. package/dist/resolve/resolveTag.js +0 -109
  323. package/dist/resolve/resolveTagName.js +0 -89
  324. package/dist/stringify/addComment.js +0 -13
  325. package/dist/stringify/stringifyTag.js +0 -30
  326. package/dist/tags/core.js +0 -138
  327. package/dist/tags/failsafe/index.js +0 -9
  328. package/dist/tags/failsafe/map.js +0 -39
  329. package/dist/tags/failsafe/seq.js +0 -36
  330. package/dist/tags/failsafe/string.js +0 -22
  331. package/dist/tags/index.js +0 -42
  332. package/dist/tags/json.js +0 -64
  333. package/dist/tags/options.js +0 -37
  334. package/dist/tags/yaml-1.1/binary.js +0 -85
  335. package/dist/tags/yaml-1.1/index.js +0 -176
  336. package/dist/tags/yaml-1.1/omap.js +0 -89
  337. package/dist/tags/yaml-1.1/pairs.js +0 -66
  338. package/dist/tags/yaml-1.1/set.js +0 -81
  339. package/dist/tags/yaml-1.1/timestamp.js +0 -105
  340. package/dist/types.js +0 -29
  341. package/index.d.ts +0 -519
  342. package/index.js +0 -1
  343. package/types.d.ts +0 -379
  344. package/types.js +0 -17
  345. package/types.mjs +0 -17
  346. package/util.d.ts +0 -76
  347. package/util.mjs +0 -15
@@ -0,0 +1,185 @@
1
+ import { Scalar } from '../nodes/Scalar.js';
2
+
3
+ function resolveBlockScalar(scalar, strict, onError) {
4
+ const start = scalar.offset;
5
+ const header = parseBlockScalarHeader(scalar, strict, onError);
6
+ if (!header)
7
+ return { value: '', type: null, comment: '', range: [start, start, start] };
8
+ const type = header.mode === '>' ? Scalar.BLOCK_FOLDED : Scalar.BLOCK_LITERAL;
9
+ const lines = scalar.source ? splitLines(scalar.source) : [];
10
+ // determine the end of content & start of chomping
11
+ let chompStart = lines.length;
12
+ for (let i = lines.length - 1; i >= 0; --i) {
13
+ const content = lines[i][1];
14
+ if (content === '' || content === '\r')
15
+ chompStart = i;
16
+ else
17
+ break;
18
+ }
19
+ // shortcut for empty contents
20
+ if (!scalar.source || chompStart === 0) {
21
+ const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
22
+ let end = start + header.length;
23
+ if (scalar.source)
24
+ end += scalar.source.length;
25
+ return { value, type, comment: header.comment, range: [start, end, end] };
26
+ }
27
+ // find the indentation level to trim from start
28
+ let trimIndent = scalar.indent + header.indent;
29
+ let offset = scalar.offset + header.length;
30
+ let contentStart = 0;
31
+ for (let i = 0; i < chompStart; ++i) {
32
+ const [indent, content] = lines[i];
33
+ if (content === '' || content === '\r') {
34
+ if (header.indent === 0 && indent.length > trimIndent)
35
+ trimIndent = indent.length;
36
+ }
37
+ else {
38
+ if (indent.length < trimIndent) {
39
+ const message = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
40
+ onError(offset + indent.length, 'MISSING_CHAR', message);
41
+ }
42
+ if (header.indent === 0)
43
+ trimIndent = indent.length;
44
+ contentStart = i;
45
+ break;
46
+ }
47
+ offset += indent.length + content.length + 1;
48
+ }
49
+ let value = '';
50
+ let sep = '';
51
+ let prevMoreIndented = false;
52
+ // leading whitespace is kept intact
53
+ for (let i = 0; i < contentStart; ++i)
54
+ value += lines[i][0].slice(trimIndent) + '\n';
55
+ for (let i = contentStart; i < chompStart; ++i) {
56
+ let [indent, content] = lines[i];
57
+ offset += indent.length + content.length + 1;
58
+ const crlf = content[content.length - 1] === '\r';
59
+ if (crlf)
60
+ content = content.slice(0, -1);
61
+ /* istanbul ignore if already caught in lexer */
62
+ if (content && indent.length < trimIndent) {
63
+ const src = header.indent
64
+ ? 'explicit indentation indicator'
65
+ : 'first line';
66
+ const message = `Block scalar lines must not be less indented than their ${src}`;
67
+ onError(offset - content.length - (crlf ? 2 : 1), 'BAD_INDENT', message);
68
+ indent = '';
69
+ }
70
+ if (type === Scalar.BLOCK_LITERAL) {
71
+ value += sep + indent.slice(trimIndent) + content;
72
+ sep = '\n';
73
+ }
74
+ else if (indent.length > trimIndent || content[0] === '\t') {
75
+ // more-indented content within a folded block
76
+ if (sep === ' ')
77
+ sep = '\n';
78
+ else if (!prevMoreIndented && sep === '\n')
79
+ sep = '\n\n';
80
+ value += sep + indent.slice(trimIndent) + content;
81
+ sep = '\n';
82
+ prevMoreIndented = true;
83
+ }
84
+ else if (content === '') {
85
+ // empty line
86
+ if (sep === '\n')
87
+ value += '\n';
88
+ else
89
+ sep = '\n';
90
+ }
91
+ else {
92
+ value += sep + content;
93
+ sep = ' ';
94
+ prevMoreIndented = false;
95
+ }
96
+ }
97
+ switch (header.chomp) {
98
+ case '-':
99
+ break;
100
+ case '+':
101
+ for (let i = chompStart; i < lines.length; ++i)
102
+ value += '\n' + lines[i][0].slice(trimIndent);
103
+ if (value[value.length - 1] !== '\n')
104
+ value += '\n';
105
+ break;
106
+ default:
107
+ value += '\n';
108
+ }
109
+ const end = start + header.length + scalar.source.length;
110
+ return { value, type, comment: header.comment, range: [start, end, end] };
111
+ }
112
+ function parseBlockScalarHeader({ offset, props }, strict, onError) {
113
+ /* istanbul ignore if should not happen */
114
+ if (props[0].type !== 'block-scalar-header') {
115
+ onError(props[0], 'IMPOSSIBLE', 'Block scalar header not found');
116
+ return null;
117
+ }
118
+ const { source } = props[0];
119
+ const mode = source[0];
120
+ let indent = 0;
121
+ let chomp = '';
122
+ let error = -1;
123
+ for (let i = 1; i < source.length; ++i) {
124
+ const ch = source[i];
125
+ if (!chomp && (ch === '-' || ch === '+'))
126
+ chomp = ch;
127
+ else {
128
+ const n = Number(ch);
129
+ if (!indent && n)
130
+ indent = n;
131
+ else if (error === -1)
132
+ error = offset + i;
133
+ }
134
+ }
135
+ if (error !== -1)
136
+ onError(error, 'UNEXPECTED_TOKEN', `Block scalar header includes extra characters: ${source}`);
137
+ let hasSpace = false;
138
+ let comment = '';
139
+ let length = source.length;
140
+ for (let i = 1; i < props.length; ++i) {
141
+ const token = props[i];
142
+ switch (token.type) {
143
+ case 'space':
144
+ hasSpace = true;
145
+ // fallthrough
146
+ case 'newline':
147
+ length += token.source.length;
148
+ break;
149
+ case 'comment':
150
+ if (strict && !hasSpace) {
151
+ const message = 'Comments must be separated from other tokens by white space characters';
152
+ onError(token, 'MISSING_CHAR', message);
153
+ }
154
+ length += token.source.length;
155
+ comment = token.source.substring(1);
156
+ break;
157
+ case 'error':
158
+ onError(token, 'UNEXPECTED_TOKEN', token.message);
159
+ length += token.source.length;
160
+ break;
161
+ /* istanbul ignore next should not happen */
162
+ default: {
163
+ const message = `Unexpected token in block scalar header: ${token.type}`;
164
+ onError(token, 'UNEXPECTED_TOKEN', message);
165
+ const ts = token.source;
166
+ if (ts && typeof ts === 'string')
167
+ length += ts.length;
168
+ }
169
+ }
170
+ }
171
+ return { mode, indent, chomp, comment, length };
172
+ }
173
+ /** @returns Array of lines split up as `[indent, content]` */
174
+ function splitLines(source) {
175
+ const split = source.split(/\n( *)/);
176
+ const first = split[0];
177
+ const m = first.match(/^( *)/);
178
+ const line0 = m && m[1] ? [m[1], first.slice(m[1].length)] : ['', first];
179
+ const lines = [line0];
180
+ for (let i = 1; i < split.length; i += 2)
181
+ lines.push([split[i], split[i + 1]]);
182
+ return lines;
183
+ }
184
+
185
+ export { resolveBlockScalar };
@@ -0,0 +1,40 @@
1
+ import { YAMLSeq } from '../nodes/YAMLSeq.js';
2
+ import { resolveProps } from './resolve-props.js';
3
+
4
+ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
5
+ const seq = new YAMLSeq(ctx.schema);
6
+ let offset = bs.offset;
7
+ for (const { start, value } of bs.items) {
8
+ const props = resolveProps(start, {
9
+ indicator: 'seq-item-ind',
10
+ next: value,
11
+ offset,
12
+ onError,
13
+ startOnNewline: true
14
+ });
15
+ offset = props.end;
16
+ if (!props.found) {
17
+ if (props.anchor || props.tag || value) {
18
+ if (value && value.type === 'block-seq')
19
+ onError(offset, 'BAD_INDENT', 'All sequence items must start at the same column');
20
+ else
21
+ onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
22
+ }
23
+ else {
24
+ // TODO: assert being at last item?
25
+ if (props.comment)
26
+ seq.comment = props.comment;
27
+ continue;
28
+ }
29
+ }
30
+ const node = value
31
+ ? composeNode(ctx, value, props, onError)
32
+ : composeEmptyNode(ctx, offset, start, null, props, onError);
33
+ offset = node.range[2];
34
+ seq.items.push(node);
35
+ }
36
+ seq.range = [bs.offset, offset, offset];
37
+ return seq;
38
+ }
39
+
40
+ export { resolveBlockSeq };
@@ -0,0 +1,37 @@
1
+ function resolveEnd(end, offset, reqSpace, onError) {
2
+ let comment = '';
3
+ if (end) {
4
+ let hasSpace = false;
5
+ let sep = '';
6
+ for (const token of end) {
7
+ const { source, type } = token;
8
+ switch (type) {
9
+ case 'space':
10
+ hasSpace = true;
11
+ break;
12
+ case 'comment': {
13
+ if (reqSpace && !hasSpace)
14
+ onError(token, 'MISSING_CHAR', 'Comments must be separated from other tokens by white space characters');
15
+ const cb = source.substring(1) || ' ';
16
+ if (!comment)
17
+ comment = cb;
18
+ else
19
+ comment += sep + cb;
20
+ sep = '';
21
+ break;
22
+ }
23
+ case 'newline':
24
+ if (comment)
25
+ sep += source;
26
+ hasSpace = true;
27
+ break;
28
+ default:
29
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${type} at node end`);
30
+ }
31
+ offset += source.length;
32
+ }
33
+ }
34
+ return { comment, offset };
35
+ }
36
+
37
+ export { resolveEnd };
@@ -0,0 +1,189 @@
1
+ import { isPair } from '../nodes/Node.js';
2
+ import { Pair } from '../nodes/Pair.js';
3
+ import { YAMLMap } from '../nodes/YAMLMap.js';
4
+ import { YAMLSeq } from '../nodes/YAMLSeq.js';
5
+ import { resolveEnd } from './resolve-end.js';
6
+ import { resolveProps } from './resolve-props.js';
7
+ import { containsNewline } from './util-contains-newline.js';
8
+ import { mapIncludes } from './util-map-includes.js';
9
+
10
+ const blockMsg = 'Block collections are not allowed within flow collections';
11
+ const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq');
12
+ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) {
13
+ const isMap = fc.start.source === '{';
14
+ const fcName = isMap ? 'flow map' : 'flow sequence';
15
+ const coll = isMap
16
+ ? new YAMLMap(ctx.schema)
17
+ : new YAMLSeq(ctx.schema);
18
+ coll.flow = true;
19
+ let offset = fc.offset;
20
+ for (let i = 0; i < fc.items.length; ++i) {
21
+ const { start, key, sep, value } = fc.items[i];
22
+ const props = resolveProps(start, {
23
+ flow: fcName,
24
+ indicator: 'explicit-key-ind',
25
+ next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
26
+ offset,
27
+ onError,
28
+ startOnNewline: false
29
+ });
30
+ if (!props.found) {
31
+ if (!props.anchor && !props.tag && !sep && !value) {
32
+ if (i === 0 && props.comma)
33
+ onError(props.comma, 'UNEXPECTED_TOKEN', `Unexpected , in ${fcName}`);
34
+ else if (i < fc.items.length - 1)
35
+ onError(props.start, 'UNEXPECTED_TOKEN', `Unexpected empty item in ${fcName}`);
36
+ if (props.comment) {
37
+ if (coll.comment)
38
+ coll.comment += '\n' + props.comment;
39
+ else
40
+ coll.comment = props.comment;
41
+ }
42
+ continue;
43
+ }
44
+ if (!isMap && ctx.options.strict && containsNewline(key))
45
+ onError(key, // checked by containsNewline()
46
+ 'MULTILINE_IMPLICIT_KEY', 'Implicit keys of flow sequence pairs need to be on a single line');
47
+ }
48
+ if (i === 0) {
49
+ if (props.comma)
50
+ onError(props.comma, 'UNEXPECTED_TOKEN', `Unexpected , in ${fcName}`);
51
+ }
52
+ else {
53
+ if (!props.comma)
54
+ onError(props.start, 'MISSING_CHAR', `Missing , between ${fcName} items`);
55
+ if (props.comment) {
56
+ let prevItemComment = '';
57
+ loop: for (const st of start) {
58
+ switch (st.type) {
59
+ case 'comma':
60
+ case 'space':
61
+ break;
62
+ case 'comment':
63
+ prevItemComment = st.source.substring(1);
64
+ break loop;
65
+ default:
66
+ break loop;
67
+ }
68
+ }
69
+ if (prevItemComment) {
70
+ let prev = coll.items[coll.items.length - 1];
71
+ if (isPair(prev))
72
+ prev = prev.value || prev.key;
73
+ if (prev.comment)
74
+ prev.comment += '\n' + prevItemComment;
75
+ else
76
+ prev.comment = prevItemComment;
77
+ props.comment = props.comment.substring(prevItemComment.length + 1);
78
+ }
79
+ }
80
+ }
81
+ if (!isMap && !sep && !props.found) {
82
+ // item is a value in a seq
83
+ // → key & sep are empty, start does not include ? or :
84
+ const valueNode = value
85
+ ? composeNode(ctx, value, props, onError)
86
+ : composeEmptyNode(ctx, props.end, sep, null, props, onError);
87
+ coll.items.push(valueNode);
88
+ offset = valueNode.range[2];
89
+ if (isBlock(value))
90
+ onError(valueNode.range, 'BLOCK_IN_FLOW', blockMsg);
91
+ }
92
+ else {
93
+ // item is a key+value pair
94
+ // key value
95
+ const keyStart = props.end;
96
+ const keyNode = key
97
+ ? composeNode(ctx, key, props, onError)
98
+ : composeEmptyNode(ctx, keyStart, start, null, props, onError);
99
+ if (isBlock(key))
100
+ onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
101
+ // value properties
102
+ const valueProps = resolveProps(sep || [], {
103
+ flow: fcName,
104
+ indicator: 'map-value-ind',
105
+ next: value,
106
+ offset: keyNode.range[2],
107
+ onError,
108
+ startOnNewline: false
109
+ });
110
+ if (valueProps.found) {
111
+ if (!isMap && !props.found && ctx.options.strict) {
112
+ if (sep)
113
+ for (const st of sep) {
114
+ if (st === valueProps.found)
115
+ break;
116
+ if (st.type === 'newline') {
117
+ onError(st, 'MULTILINE_IMPLICIT_KEY', 'Implicit keys of flow sequence pairs need to be on a single line');
118
+ break;
119
+ }
120
+ }
121
+ if (props.start < valueProps.found.offset - 1024)
122
+ onError(valueProps.found, 'KEY_OVER_1024_CHARS', 'The : indicator must be at most 1024 chars after the start of an implicit flow sequence key');
123
+ }
124
+ }
125
+ else if (value) {
126
+ if ('source' in value && value.source && value.source[0] === ':')
127
+ onError(value, 'MISSING_CHAR', `Missing space after : in ${fcName}`);
128
+ else
129
+ onError(valueProps.start, 'MISSING_CHAR', `Missing , or : between ${fcName} items`);
130
+ }
131
+ // value value
132
+ const valueNode = value
133
+ ? composeNode(ctx, value, valueProps, onError)
134
+ : valueProps.found
135
+ ? composeEmptyNode(ctx, valueProps.end, sep, null, valueProps, onError)
136
+ : null;
137
+ if (valueNode) {
138
+ if (isBlock(value))
139
+ onError(valueNode.range, 'BLOCK_IN_FLOW', blockMsg);
140
+ }
141
+ else if (valueProps.comment) {
142
+ if (keyNode.comment)
143
+ keyNode.comment += '\n' + valueProps.comment;
144
+ else
145
+ keyNode.comment = valueProps.comment;
146
+ }
147
+ const pair = new Pair(keyNode, valueNode);
148
+ if (isMap) {
149
+ const map = coll;
150
+ if (mapIncludes(ctx, map.items, keyNode))
151
+ onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
152
+ map.items.push(pair);
153
+ }
154
+ else {
155
+ const map = new YAMLMap(ctx.schema);
156
+ map.flow = true;
157
+ map.items.push(pair);
158
+ coll.items.push(map);
159
+ }
160
+ offset = valueNode ? valueNode.range[2] : valueProps.end;
161
+ }
162
+ }
163
+ const expectedEnd = isMap ? '}' : ']';
164
+ const [ce, ...ee] = fc.end;
165
+ let cePos = offset;
166
+ if (ce && ce.source === expectedEnd)
167
+ cePos = ce.offset + ce.source.length;
168
+ else {
169
+ onError(offset + 1, 'MISSING_CHAR', `Expected ${fcName} to end with ${expectedEnd}`);
170
+ if (ce && ce.source.length !== 1)
171
+ ee.unshift(ce);
172
+ }
173
+ if (ee.length > 0) {
174
+ const end = resolveEnd(ee, cePos, ctx.options.strict, onError);
175
+ if (end.comment) {
176
+ if (coll.comment)
177
+ coll.comment += '\n' + end.comment;
178
+ else
179
+ coll.comment = end.comment;
180
+ }
181
+ coll.range = [fc.offset, cePos, end.offset];
182
+ }
183
+ else {
184
+ coll.range = [fc.offset, cePos, cePos];
185
+ }
186
+ return coll;
187
+ }
188
+
189
+ export { resolveFlowCollection };
@@ -0,0 +1,211 @@
1
+ import { Scalar } from '../nodes/Scalar.js';
2
+ import { resolveEnd } from './resolve-end.js';
3
+
4
+ function resolveFlowScalar(scalar, strict, onError) {
5
+ const { offset, type, source, end } = scalar;
6
+ let _type;
7
+ let value;
8
+ const _onError = (rel, code, msg) => onError(offset + rel, code, msg);
9
+ switch (type) {
10
+ case 'scalar':
11
+ _type = Scalar.PLAIN;
12
+ value = plainValue(source, _onError);
13
+ break;
14
+ case 'single-quoted-scalar':
15
+ _type = Scalar.QUOTE_SINGLE;
16
+ value = singleQuotedValue(source, _onError);
17
+ break;
18
+ case 'double-quoted-scalar':
19
+ _type = Scalar.QUOTE_DOUBLE;
20
+ value = doubleQuotedValue(source, _onError);
21
+ break;
22
+ /* istanbul ignore next should not happen */
23
+ default:
24
+ onError(scalar, 'UNEXPECTED_TOKEN', `Expected a flow scalar value, but found: ${type}`);
25
+ return {
26
+ value: '',
27
+ type: null,
28
+ comment: '',
29
+ range: [offset, offset + source.length, offset + source.length]
30
+ };
31
+ }
32
+ const valueEnd = offset + source.length;
33
+ const re = resolveEnd(end, valueEnd, strict, onError);
34
+ return {
35
+ value,
36
+ type: _type,
37
+ comment: re.comment,
38
+ range: [offset, valueEnd, re.offset]
39
+ };
40
+ }
41
+ function plainValue(source, onError) {
42
+ let message = '';
43
+ switch (source[0]) {
44
+ /* istanbul ignore next should not happen */
45
+ case '\t':
46
+ message = 'Plain value cannot start with a tab character';
47
+ break;
48
+ case '|':
49
+ case '>': {
50
+ message = `Plain value cannot start with block scalar indicator ${source[0]}`;
51
+ break;
52
+ }
53
+ case '@':
54
+ case '`': {
55
+ message = `Plain value cannot start with reserved character ${source[0]}`;
56
+ break;
57
+ }
58
+ }
59
+ if (message)
60
+ onError(0, 'BAD_SCALAR_START', message);
61
+ return foldLines(source);
62
+ }
63
+ function singleQuotedValue(source, onError) {
64
+ if (source[source.length - 1] !== "'" || source.length === 1)
65
+ onError(source.length, 'MISSING_CHAR', "Missing closing 'quote");
66
+ return foldLines(source.slice(1, -1)).replace(/''/g, "'");
67
+ }
68
+ function foldLines(source) {
69
+ /**
70
+ * The negative lookbehind here and in the `re` RegExp is to
71
+ * prevent causing a polynomial search time in certain cases.
72
+ *
73
+ * The try-catch is for Safari, which doesn't support this yet:
74
+ * https://caniuse.com/js-regexp-lookbehind
75
+ */
76
+ let first, line;
77
+ try {
78
+ first = new RegExp('(.*?)(?<![ \t])[ \t]*\r?\n', 'sy');
79
+ line = new RegExp('[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n', 'sy');
80
+ }
81
+ catch (_) {
82
+ first = /(.*?)[ \t]*\r?\n/sy;
83
+ line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
84
+ }
85
+ let match = first.exec(source);
86
+ if (!match)
87
+ return source;
88
+ let res = match[1];
89
+ let sep = ' ';
90
+ let pos = first.lastIndex;
91
+ line.lastIndex = pos;
92
+ while ((match = line.exec(source))) {
93
+ if (match[1] === '') {
94
+ if (sep === '\n')
95
+ res += sep;
96
+ else
97
+ sep = '\n';
98
+ }
99
+ else {
100
+ res += sep + match[1];
101
+ sep = ' ';
102
+ }
103
+ pos = line.lastIndex;
104
+ }
105
+ const last = /[ \t]*(.*)/sy;
106
+ last.lastIndex = pos;
107
+ match = last.exec(source);
108
+ return res + sep + ((match && match[1]) || '');
109
+ }
110
+ function doubleQuotedValue(source, onError) {
111
+ let res = '';
112
+ for (let i = 1; i < source.length - 1; ++i) {
113
+ const ch = source[i];
114
+ if (ch === '\r' && source[i + 1] === '\n')
115
+ continue;
116
+ if (ch === '\n') {
117
+ const { fold, offset } = foldNewline(source, i);
118
+ res += fold;
119
+ i = offset;
120
+ }
121
+ else if (ch === '\\') {
122
+ let next = source[++i];
123
+ const cc = escapeCodes[next];
124
+ if (cc)
125
+ res += cc;
126
+ else if (next === '\n') {
127
+ // skip escaped newlines, but still trim the following line
128
+ next = source[i + 1];
129
+ while (next === ' ' || next === '\t')
130
+ next = source[++i + 1];
131
+ }
132
+ else if (next === 'x' || next === 'u' || next === 'U') {
133
+ const length = { x: 2, u: 4, U: 8 }[next];
134
+ res += parseCharCode(source, i + 1, length, onError);
135
+ i += length;
136
+ }
137
+ else {
138
+ const raw = source.substr(i - 1, 2);
139
+ onError(i - 1, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
140
+ res += raw;
141
+ }
142
+ }
143
+ else if (ch === ' ' || ch === '\t') {
144
+ // trim trailing whitespace
145
+ const wsStart = i;
146
+ let next = source[i + 1];
147
+ while (next === ' ' || next === '\t')
148
+ next = source[++i + 1];
149
+ if (next !== '\n')
150
+ res += i > wsStart ? source.slice(wsStart, i + 1) : ch;
151
+ }
152
+ else {
153
+ res += ch;
154
+ }
155
+ }
156
+ if (source[source.length - 1] !== '"' || source.length === 1)
157
+ onError(source.length, 'MISSING_CHAR', 'Missing closing "quote');
158
+ return res;
159
+ }
160
+ /**
161
+ * Fold a single newline into a space, multiple newlines to N - 1 newlines.
162
+ * Presumes `source[offset] === '\n'`
163
+ */
164
+ function foldNewline(source, offset) {
165
+ let fold = '';
166
+ let ch = source[offset + 1];
167
+ while (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
168
+ if (ch === '\r' && source[offset + 2] !== '\n')
169
+ break;
170
+ if (ch === '\n')
171
+ fold += '\n';
172
+ offset += 1;
173
+ ch = source[offset + 1];
174
+ }
175
+ if (!fold)
176
+ fold = ' ';
177
+ return { fold, offset };
178
+ }
179
+ const escapeCodes = {
180
+ '0': '\0',
181
+ a: '\x07',
182
+ b: '\b',
183
+ e: '\x1b',
184
+ f: '\f',
185
+ n: '\n',
186
+ r: '\r',
187
+ t: '\t',
188
+ v: '\v',
189
+ N: '\u0085',
190
+ _: '\u00a0',
191
+ L: '\u2028',
192
+ P: '\u2029',
193
+ ' ': ' ',
194
+ '"': '"',
195
+ '/': '/',
196
+ '\\': '\\',
197
+ '\t': '\t'
198
+ };
199
+ function parseCharCode(source, offset, length, onError) {
200
+ const cc = source.substr(offset, length);
201
+ const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
202
+ const code = ok ? parseInt(cc, 16) : NaN;
203
+ if (isNaN(code)) {
204
+ const raw = source.substr(offset - 2, length + 2);
205
+ onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
206
+ return raw;
207
+ }
208
+ return String.fromCodePoint(code);
209
+ }
210
+
211
+ export { resolveFlowScalar };