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
@@ -1,355 +0,0 @@
1
- import { Char, Type } from '../constants.js';
2
- import { getLinePos } from './source-utils.js';
3
- import { Range } from './Range.js';
4
-
5
- /** Root class of all nodes */
6
-
7
- class Node {
8
- static addStringTerminator(src, offset, str) {
9
- if (str[str.length - 1] === '\n') return str;
10
- const next = Node.endOfWhiteSpace(src, offset);
11
- return next >= src.length || src[next] === '\n' ? str + '\n' : str;
12
- } // ^(---|...)
13
-
14
-
15
- static atDocumentBoundary(src, offset, sep) {
16
- const ch0 = src[offset];
17
- if (!ch0) return true;
18
- const prev = src[offset - 1];
19
- if (prev && prev !== '\n') return false;
20
-
21
- if (sep) {
22
- if (ch0 !== sep) return false;
23
- } else {
24
- if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false;
25
- }
26
-
27
- const ch1 = src[offset + 1];
28
- const ch2 = src[offset + 2];
29
- if (ch1 !== ch0 || ch2 !== ch0) return false;
30
- const ch3 = src[offset + 3];
31
- return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' ';
32
- }
33
-
34
- static endOfIdentifier(src, offset) {
35
- let ch = src[offset];
36
- const isVerbatim = ch === '<';
37
- const notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ','];
38
-
39
- while (ch && notOk.indexOf(ch) === -1) ch = src[offset += 1];
40
-
41
- if (isVerbatim && ch === '>') offset += 1;
42
- return offset;
43
- }
44
-
45
- static endOfIndent(src, offset) {
46
- let ch = src[offset];
47
-
48
- while (ch === ' ') ch = src[offset += 1];
49
-
50
- return offset;
51
- }
52
-
53
- static endOfLine(src, offset) {
54
- let ch = src[offset];
55
-
56
- while (ch && ch !== '\n') ch = src[offset += 1];
57
-
58
- return offset;
59
- }
60
-
61
- static endOfWhiteSpace(src, offset) {
62
- let ch = src[offset];
63
-
64
- while (ch === '\t' || ch === ' ') ch = src[offset += 1];
65
-
66
- return offset;
67
- }
68
-
69
- static startOfLine(src, offset) {
70
- let ch = src[offset - 1];
71
- if (ch === '\n') return offset;
72
-
73
- while (ch && ch !== '\n') ch = src[offset -= 1];
74
-
75
- return offset + 1;
76
- }
77
- /**
78
- * End of indentation, or null if the line's indent level is not more
79
- * than `indent`
80
- *
81
- * @param {string} src
82
- * @param {number} indent
83
- * @param {number} lineStart
84
- * @returns {?number}
85
- */
86
-
87
-
88
- static endOfBlockIndent(src, indent, lineStart) {
89
- const inEnd = Node.endOfIndent(src, lineStart);
90
-
91
- if (inEnd > lineStart + indent) {
92
- return inEnd;
93
- } else {
94
- const wsEnd = Node.endOfWhiteSpace(src, inEnd);
95
- const ch = src[wsEnd];
96
- if (!ch || ch === '\n') return wsEnd;
97
- }
98
-
99
- return null;
100
- }
101
-
102
- static atBlank(src, offset, endAsBlank) {
103
- const ch = src[offset];
104
- return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch;
105
- }
106
-
107
- static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) {
108
- if (!ch || indentDiff < 0) return false;
109
- if (indentDiff > 0) return true;
110
- return indicatorAsIndent && ch === '-';
111
- } // should be at line or string end, or at next non-whitespace char
112
-
113
-
114
- static normalizeOffset(src, offset) {
115
- const ch = src[offset];
116
- return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset);
117
- } // fold single newline into space, multiple newlines to N - 1 newlines
118
- // presumes src[offset] === '\n'
119
-
120
-
121
- static foldNewline(src, offset, indent) {
122
- let inCount = 0;
123
- let error = false;
124
- let fold = '';
125
- let ch = src[offset + 1];
126
-
127
- while (ch === ' ' || ch === '\t' || ch === '\n') {
128
- switch (ch) {
129
- case '\n':
130
- inCount = 0;
131
- offset += 1;
132
- fold += '\n';
133
- break;
134
-
135
- case '\t':
136
- if (inCount <= indent) error = true;
137
- offset = Node.endOfWhiteSpace(src, offset + 2) - 1;
138
- break;
139
-
140
- case ' ':
141
- inCount += 1;
142
- offset += 1;
143
- break;
144
- }
145
-
146
- ch = src[offset + 1];
147
- }
148
-
149
- if (!fold) fold = ' ';
150
- if (ch && inCount <= indent) error = true;
151
- return {
152
- fold,
153
- offset,
154
- error
155
- };
156
- }
157
-
158
- constructor(type, props, context) {
159
- Object.defineProperty(this, 'context', {
160
- value: context || null,
161
- writable: true
162
- });
163
- this.error = null;
164
- this.range = null;
165
- this.valueRange = null;
166
- this.props = props || [];
167
- this.type = type;
168
- this.value = null;
169
- }
170
-
171
- getPropValue(idx, key, skipKey) {
172
- if (!this.context) return null;
173
- const {
174
- src
175
- } = this.context;
176
- const prop = this.props[idx];
177
- return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null;
178
- }
179
-
180
- get anchor() {
181
- for (let i = 0; i < this.props.length; ++i) {
182
- const anchor = this.getPropValue(i, Char.ANCHOR, true);
183
- if (anchor != null) return anchor;
184
- }
185
-
186
- return null;
187
- }
188
-
189
- get comment() {
190
- const comments = [];
191
-
192
- for (let i = 0; i < this.props.length; ++i) {
193
- const comment = this.getPropValue(i, Char.COMMENT, true);
194
- if (comment != null) comments.push(comment);
195
- }
196
-
197
- return comments.length > 0 ? comments.join('\n') : null;
198
- }
199
-
200
- commentHasRequiredWhitespace(start) {
201
- const {
202
- src
203
- } = this.context;
204
- if (this.header && start === this.header.end) return false;
205
- if (!this.valueRange) return false;
206
- const {
207
- end
208
- } = this.valueRange;
209
- return start !== end || Node.atBlank(src, end - 1);
210
- }
211
-
212
- get hasComment() {
213
- if (this.context) {
214
- const {
215
- src
216
- } = this.context;
217
-
218
- for (let i = 0; i < this.props.length; ++i) {
219
- if (src[this.props[i].start] === Char.COMMENT) return true;
220
- }
221
- }
222
-
223
- return false;
224
- }
225
-
226
- get hasProps() {
227
- if (this.context) {
228
- const {
229
- src
230
- } = this.context;
231
-
232
- for (let i = 0; i < this.props.length; ++i) {
233
- if (src[this.props[i].start] !== Char.COMMENT) return true;
234
- }
235
- }
236
-
237
- return false;
238
- }
239
-
240
- get includesTrailingLines() {
241
- return false;
242
- }
243
-
244
- get jsonLike() {
245
- const jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE];
246
- return jsonLikeTypes.indexOf(this.type) !== -1;
247
- }
248
-
249
- get rangeAsLinePos() {
250
- if (!this.range || !this.context) return undefined;
251
- const start = getLinePos(this.range.start, this.context.root);
252
- if (!start) return undefined;
253
- const end = getLinePos(this.range.end, this.context.root);
254
- return {
255
- start,
256
- end
257
- };
258
- }
259
-
260
- get rawValue() {
261
- if (!this.valueRange || !this.context) return null;
262
- const {
263
- start,
264
- end
265
- } = this.valueRange;
266
- return this.context.src.slice(start, end);
267
- }
268
-
269
- get tag() {
270
- for (let i = 0; i < this.props.length; ++i) {
271
- const tag = this.getPropValue(i, Char.TAG, false);
272
-
273
- if (tag != null) {
274
- if (tag[1] === '<') {
275
- return {
276
- verbatim: tag.slice(2, -1)
277
- };
278
- } else {
279
- // eslint-disable-next-line no-unused-vars
280
- const [_, handle, suffix] = tag.match(/^(.*!)([^!]*)$/);
281
- return {
282
- handle,
283
- suffix
284
- };
285
- }
286
- }
287
- }
288
-
289
- return null;
290
- }
291
-
292
- get valueRangeContainsNewline() {
293
- if (!this.valueRange || !this.context) return false;
294
- const {
295
- start,
296
- end
297
- } = this.valueRange;
298
- const {
299
- src
300
- } = this.context;
301
-
302
- for (let i = start; i < end; ++i) {
303
- if (src[i] === '\n') return true;
304
- }
305
-
306
- return false;
307
- }
308
-
309
- parseComment(start) {
310
- const {
311
- src
312
- } = this.context;
313
-
314
- if (src[start] === Char.COMMENT) {
315
- const end = Node.endOfLine(src, start + 1);
316
- const commentRange = new Range(start, end);
317
- this.props.push(commentRange);
318
- return end;
319
- }
320
-
321
- return start;
322
- }
323
- /**
324
- * Populates the `origStart` and `origEnd` values of all ranges for this
325
- * node. Extended by child classes to handle descendant nodes.
326
- *
327
- * @param {number[]} cr - Positions of dropped CR characters
328
- * @param {number} offset - Starting index of `cr` from the last call
329
- * @returns {number} - The next offset, matching the one found for `origStart`
330
- */
331
-
332
-
333
- setOrigRanges(cr, offset) {
334
- if (this.range) offset = this.range.setOrigRange(cr, offset);
335
- if (this.valueRange) this.valueRange.setOrigRange(cr, offset);
336
- this.props.forEach(prop => prop.setOrigRange(cr, offset));
337
- return offset;
338
- }
339
-
340
- toString() {
341
- const {
342
- context: {
343
- src
344
- },
345
- range,
346
- value
347
- } = this;
348
- if (value != null) return value;
349
- const str = src.slice(range.start, range.end);
350
- return Node.addStringTerminator(src, range.end, str);
351
- }
352
-
353
- }
354
-
355
- export { Node };
@@ -1,234 +0,0 @@
1
- import { defineProperty as _defineProperty } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import { Type, Char } from '../constants.js';
3
- import { YAMLSyntaxError } from '../errors.js';
4
- import { Alias } from './Alias.js';
5
- import { BlockValue } from './BlockValue.js';
6
- import { Collection } from './Collection.js';
7
- import { CollectionItem } from './CollectionItem.js';
8
- import { FlowCollection } from './FlowCollection.js';
9
- import { Node } from './Node.js';
10
- import { PlainValue } from './PlainValue.js';
11
- import { QuoteDouble } from './QuoteDouble.js';
12
- import { QuoteSingle } from './QuoteSingle.js';
13
- import { Range } from './Range.js';
14
-
15
- function createNewNode(type, props) {
16
- switch (type) {
17
- case Type.ALIAS:
18
- return new Alias(type, props);
19
-
20
- case Type.BLOCK_FOLDED:
21
- case Type.BLOCK_LITERAL:
22
- return new BlockValue(type, props);
23
-
24
- case Type.FLOW_MAP:
25
- case Type.FLOW_SEQ:
26
- return new FlowCollection(type, props);
27
-
28
- case Type.MAP_KEY:
29
- case Type.MAP_VALUE:
30
- case Type.SEQ_ITEM:
31
- return new CollectionItem(type, props);
32
-
33
- case Type.COMMENT:
34
- case Type.PLAIN:
35
- return new PlainValue(type, props);
36
-
37
- case Type.QUOTE_DOUBLE:
38
- return new QuoteDouble(type, props);
39
-
40
- case Type.QUOTE_SINGLE:
41
- return new QuoteSingle(type, props);
42
-
43
- /* istanbul ignore next */
44
-
45
- default:
46
- return null;
47
- // should never happen
48
- }
49
- }
50
- /**
51
- * @param {boolean} atLineStart - Node starts at beginning of line
52
- * @param {boolean} inFlow - true if currently in a flow context
53
- * @param {boolean} inCollection - true if currently in a collection context
54
- * @param {number} indent - Current level of indentation
55
- * @param {number} lineStart - Start of the current line
56
- * @param {Node} parent - The parent of the node
57
- * @param {string} src - Source of the YAML document
58
- */
59
-
60
-
61
- class ParseContext {
62
- static parseType(src, offset, inFlow) {
63
- switch (src[offset]) {
64
- case '*':
65
- return Type.ALIAS;
66
-
67
- case '>':
68
- return Type.BLOCK_FOLDED;
69
-
70
- case '|':
71
- return Type.BLOCK_LITERAL;
72
-
73
- case '{':
74
- return Type.FLOW_MAP;
75
-
76
- case '[':
77
- return Type.FLOW_SEQ;
78
-
79
- case '?':
80
- return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_KEY : Type.PLAIN;
81
-
82
- case ':':
83
- return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_VALUE : Type.PLAIN;
84
-
85
- case '-':
86
- return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.SEQ_ITEM : Type.PLAIN;
87
-
88
- case '"':
89
- return Type.QUOTE_DOUBLE;
90
-
91
- case "'":
92
- return Type.QUOTE_SINGLE;
93
-
94
- default:
95
- return Type.PLAIN;
96
- }
97
- }
98
-
99
- constructor(orig = {}, {
100
- atLineStart,
101
- inCollection,
102
- inFlow,
103
- indent,
104
- lineStart,
105
- parent
106
- } = {}) {
107
- _defineProperty(this, "parseNode", (overlay, start) => {
108
- if (Node.atDocumentBoundary(this.src, start)) return null;
109
- const context = new ParseContext(this, overlay);
110
- const {
111
- props,
112
- type,
113
- valueStart
114
- } = context.parseProps(start);
115
- const node = createNewNode(type, props);
116
- let offset = node.parse(context, valueStart);
117
- node.range = new Range(start, offset);
118
- /* istanbul ignore if */
119
-
120
- if (offset <= start) {
121
- // This should never happen, but if it does, let's make sure to at least
122
- // step one character forward to avoid a busy loop.
123
- node.error = new Error("Node#parse consumed no characters");
124
- node.error.parseEnd = offset;
125
- node.error.source = node;
126
- node.range.end = start + 1;
127
- }
128
-
129
- if (context.nodeStartsCollection(node)) {
130
- if (!node.error && !context.atLineStart && context.parent.type === Type.DOCUMENT) {
131
- node.error = new YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)');
132
- }
133
-
134
- const collection = new Collection(node);
135
- offset = collection.parse(new ParseContext(context), offset);
136
- collection.range = new Range(start, offset);
137
- return collection;
138
- }
139
-
140
- return node;
141
- });
142
-
143
- this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false;
144
- this.inCollection = inCollection != null ? inCollection : orig.inCollection || false;
145
- this.inFlow = inFlow != null ? inFlow : orig.inFlow || false;
146
- this.indent = indent != null ? indent : orig.indent;
147
- this.lineStart = lineStart != null ? lineStart : orig.lineStart;
148
- this.parent = parent != null ? parent : orig.parent || {};
149
- this.root = orig.root;
150
- this.src = orig.src;
151
- }
152
-
153
- nodeStartsCollection(node) {
154
- const {
155
- inCollection,
156
- inFlow,
157
- src
158
- } = this;
159
- if (inCollection || inFlow) return false;
160
- if (node instanceof CollectionItem) return true; // check for implicit key
161
-
162
- let offset = node.range.end;
163
- if (src[offset] === '\n' || src[offset - 1] === '\n') return false;
164
- offset = Node.endOfWhiteSpace(src, offset);
165
- return src[offset] === ':';
166
- } // Anchor and tag are before type, which determines the node implementation
167
- // class; hence this intermediate step.
168
-
169
-
170
- parseProps(offset) {
171
- const {
172
- inFlow,
173
- parent,
174
- src
175
- } = this;
176
- const props = [];
177
- let lineHasProps = false;
178
- offset = this.atLineStart ? Node.endOfIndent(src, offset) : Node.endOfWhiteSpace(src, offset);
179
- let ch = src[offset];
180
-
181
- while (ch === Char.ANCHOR || ch === Char.COMMENT || ch === Char.TAG || ch === '\n') {
182
- if (ch === '\n') {
183
- const lineStart = offset + 1;
184
- const inEnd = Node.endOfIndent(src, lineStart);
185
- const indentDiff = inEnd - (lineStart + this.indent);
186
- const noIndicatorAsIndent = parent.type === Type.SEQ_ITEM && parent.context.atLineStart;
187
- if (!Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
188
- this.atLineStart = true;
189
- this.lineStart = lineStart;
190
- lineHasProps = false;
191
- offset = inEnd;
192
- } else if (ch === Char.COMMENT) {
193
- const end = Node.endOfLine(src, offset + 1);
194
- props.push(new Range(offset, end));
195
- offset = end;
196
- } else {
197
- let end = Node.endOfIdentifier(src, offset + 1);
198
-
199
- if (ch === Char.TAG && src[end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, end + 13))) {
200
- // Let's presume we're dealing with a YAML 1.0 domain tag here, rather
201
- // than an empty but 'foo.bar' private-tagged node in a flow collection
202
- // followed without whitespace by a plain string starting with a year
203
- // or date divided by something.
204
- end = Node.endOfIdentifier(src, end + 5);
205
- }
206
-
207
- props.push(new Range(offset, end));
208
- lineHasProps = true;
209
- offset = Node.endOfWhiteSpace(src, end);
210
- }
211
-
212
- ch = src[offset];
213
- } // '- &a : b' has an anchor on an empty node
214
-
215
-
216
- if (lineHasProps && ch === ':' && Node.atBlank(src, offset + 1, true)) offset -= 1;
217
- const type = ParseContext.parseType(src, offset, inFlow);
218
- return {
219
- props,
220
- type,
221
- valueStart: offset
222
- };
223
- }
224
- /**
225
- * Parses a node from the source
226
- * @param {ParseContext} overlay
227
- * @param {number} start - Index of first non-whitespace character for the node
228
- * @returns {?Node} - null if at a document boundary
229
- */
230
-
231
-
232
- }
233
-
234
- export { ParseContext };