step-node-agent 3.25.4 → 3.26.0

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 (289) hide show
  1. package/AgentConf.yaml +13 -0
  2. package/api/controllers/controller.js +4 -0
  3. package/api/routes/routes.js +1 -0
  4. package/node_modules/aws4/aws4.js +1 -1
  5. package/node_modules/aws4/package.json +2 -2
  6. package/node_modules/body-parser/HISTORY.md +7 -0
  7. package/node_modules/body-parser/README.md +11 -0
  8. package/node_modules/body-parser/lib/types/urlencoded.js +30 -7
  9. package/node_modules/body-parser/package.json +2 -2
  10. package/node_modules/encodeurl/README.md +19 -38
  11. package/node_modules/encodeurl/index.js +1 -1
  12. package/node_modules/encodeurl/package.json +7 -7
  13. package/node_modules/express/History.md +27 -0
  14. package/node_modules/express/Readme.md +100 -6
  15. package/node_modules/express/lib/response.js +11 -10
  16. package/node_modules/express/package.json +11 -11
  17. package/node_modules/finalhandler/HISTORY.md +15 -0
  18. package/node_modules/finalhandler/README.md +2 -2
  19. package/node_modules/finalhandler/index.js +7 -2
  20. package/node_modules/finalhandler/package.json +8 -7
  21. package/node_modules/get-fqdn/LICENSE +21 -0
  22. package/node_modules/get-fqdn/README.md +83 -0
  23. package/node_modules/get-fqdn/index.js +17 -0
  24. package/node_modules/get-fqdn/package.json +73 -0
  25. package/node_modules/is-core-module/CHANGELOG.md +10 -0
  26. package/node_modules/is-core-module/core.json +2 -2
  27. package/node_modules/is-core-module/package.json +4 -4
  28. package/node_modules/is-core-module/test/index.js +17 -1
  29. package/node_modules/merge-descriptors/README.md +4 -3
  30. package/node_modules/merge-descriptors/index.js +3 -3
  31. package/node_modules/merge-descriptors/package.json +14 -7
  32. package/node_modules/path-to-regexp/index.js +57 -40
  33. package/node_modules/path-to-regexp/package.json +2 -2
  34. package/node_modules/qs/.editorconfig +3 -0
  35. package/node_modules/qs/.eslintrc +2 -2
  36. package/node_modules/qs/CHANGELOG.md +59 -5
  37. package/node_modules/qs/README.md +133 -49
  38. package/node_modules/qs/dist/qs.js +56 -2020
  39. package/node_modules/qs/lib/parse.js +46 -13
  40. package/node_modules/qs/lib/stringify.js +53 -28
  41. package/node_modules/qs/lib/utils.js +47 -34
  42. package/node_modules/qs/package.json +26 -12
  43. package/node_modules/qs/test/empty-keys-cases.js +267 -0
  44. package/node_modules/qs/test/parse.js +347 -32
  45. package/node_modules/qs/test/stringify.js +436 -47
  46. package/node_modules/send/HISTORY.md +5 -0
  47. package/node_modules/send/index.js +1 -2
  48. package/node_modules/send/node_modules/encodeurl/LICENSE +22 -0
  49. package/node_modules/send/node_modules/encodeurl/README.md +128 -0
  50. package/node_modules/send/node_modules/encodeurl/index.js +60 -0
  51. package/node_modules/send/node_modules/encodeurl/package.json +40 -0
  52. package/node_modules/send/package.json +1 -1
  53. package/node_modules/serve-static/HISTORY.md +16 -0
  54. package/node_modules/serve-static/index.js +1 -2
  55. package/node_modules/serve-static/package.json +3 -3
  56. package/node_modules/yaml/LICENSE +13 -0
  57. package/node_modules/yaml/README.md +155 -0
  58. package/node_modules/yaml/bin.mjs +11 -0
  59. package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
  60. package/node_modules/yaml/browser/dist/compose/compose-doc.js +42 -0
  61. package/node_modules/yaml/browser/dist/compose/compose-node.js +92 -0
  62. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +80 -0
  63. package/node_modules/yaml/browser/dist/compose/composer.js +217 -0
  64. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +113 -0
  65. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
  66. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +47 -0
  67. package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
  68. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +203 -0
  69. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +223 -0
  70. package/node_modules/yaml/browser/dist/compose/resolve-props.js +148 -0
  71. package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
  72. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +27 -0
  73. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  74. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +17 -0
  75. package/node_modules/yaml/browser/dist/doc/Document.js +334 -0
  76. package/node_modules/yaml/browser/dist/doc/anchors.js +72 -0
  77. package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
  78. package/node_modules/yaml/browser/dist/doc/createNode.js +89 -0
  79. package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
  80. package/node_modules/yaml/browser/dist/errors.js +57 -0
  81. package/node_modules/yaml/browser/dist/index.js +17 -0
  82. package/node_modules/yaml/browser/dist/log.js +14 -0
  83. package/node_modules/yaml/browser/dist/nodes/Alias.js +101 -0
  84. package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
  85. package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
  86. package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
  87. package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
  88. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
  89. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
  90. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +104 -0
  91. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  92. package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
  93. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
  94. package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
  95. package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
  96. package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
  97. package/node_modules/yaml/browser/dist/parse/lexer.js +717 -0
  98. package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
  99. package/node_modules/yaml/browser/dist/parse/parser.js +954 -0
  100. package/node_modules/yaml/browser/dist/public-api.js +99 -0
  101. package/node_modules/yaml/browser/dist/schema/Schema.js +38 -0
  102. package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
  103. package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
  104. package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
  105. package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
  106. package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
  107. package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
  108. package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
  109. package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
  110. package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
  111. package/node_modules/yaml/browser/dist/schema/tags.js +83 -0
  112. package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +66 -0
  113. package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
  114. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
  115. package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
  116. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
  117. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
  118. package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +37 -0
  119. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
  120. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  121. package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
  122. package/node_modules/yaml/browser/dist/stringify/stringify.js +124 -0
  123. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +143 -0
  124. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
  125. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
  126. package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +24 -0
  127. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
  128. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +328 -0
  129. package/node_modules/yaml/browser/dist/util.js +11 -0
  130. package/node_modules/yaml/browser/dist/visit.js +233 -0
  131. package/node_modules/yaml/browser/index.js +5 -0
  132. package/node_modules/yaml/browser/package.json +3 -0
  133. package/node_modules/yaml/dist/cli.d.ts +8 -0
  134. package/node_modules/yaml/dist/cli.mjs +199 -0
  135. package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
  136. package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
  137. package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
  138. package/node_modules/yaml/dist/compose/compose-doc.js +44 -0
  139. package/node_modules/yaml/dist/compose/compose-node.d.ts +28 -0
  140. package/node_modules/yaml/dist/compose/compose-node.js +95 -0
  141. package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
  142. package/node_modules/yaml/dist/compose/compose-scalar.js +82 -0
  143. package/node_modules/yaml/dist/compose/composer.d.ts +62 -0
  144. package/node_modules/yaml/dist/compose/composer.js +221 -0
  145. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  146. package/node_modules/yaml/dist/compose/resolve-block-map.js +115 -0
  147. package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  148. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
  149. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  150. package/node_modules/yaml/dist/compose/resolve-block-seq.js +49 -0
  151. package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
  152. package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
  153. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  154. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +205 -0
  155. package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  156. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +225 -0
  157. package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
  158. package/node_modules/yaml/dist/compose/resolve-props.js +150 -0
  159. package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  160. package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
  161. package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  162. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +29 -0
  163. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  164. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  165. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
  166. package/node_modules/yaml/dist/compose/util-map-includes.js +19 -0
  167. package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
  168. package/node_modules/yaml/dist/doc/Document.js +336 -0
  169. package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
  170. package/node_modules/yaml/dist/doc/anchors.js +77 -0
  171. package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
  172. package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
  173. package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
  174. package/node_modules/yaml/dist/doc/createNode.js +91 -0
  175. package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
  176. package/node_modules/yaml/dist/doc/directives.js +178 -0
  177. package/node_modules/yaml/dist/errors.d.ts +21 -0
  178. package/node_modules/yaml/dist/errors.js +62 -0
  179. package/node_modules/yaml/dist/index.d.ts +22 -0
  180. package/node_modules/yaml/dist/index.js +50 -0
  181. package/node_modules/yaml/dist/log.d.ts +3 -0
  182. package/node_modules/yaml/dist/log.js +17 -0
  183. package/node_modules/yaml/dist/nodes/Alias.d.ts +28 -0
  184. package/node_modules/yaml/dist/nodes/Alias.js +103 -0
  185. package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
  186. package/node_modules/yaml/dist/nodes/Collection.js +151 -0
  187. package/node_modules/yaml/dist/nodes/Node.d.ts +47 -0
  188. package/node_modules/yaml/dist/nodes/Node.js +40 -0
  189. package/node_modules/yaml/dist/nodes/Pair.d.ts +21 -0
  190. package/node_modules/yaml/dist/nodes/Pair.js +39 -0
  191. package/node_modules/yaml/dist/nodes/Scalar.d.ts +42 -0
  192. package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
  193. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  194. package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
  195. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  196. package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
  197. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  198. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +106 -0
  199. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  200. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  201. package/node_modules/yaml/dist/nodes/toJS.d.ts +27 -0
  202. package/node_modules/yaml/dist/nodes/toJS.js +39 -0
  203. package/node_modules/yaml/dist/options.d.ts +338 -0
  204. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
  205. package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
  206. package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
  207. package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
  208. package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
  209. package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
  210. package/node_modules/yaml/dist/parse/cst.d.ts +108 -0
  211. package/node_modules/yaml/dist/parse/cst.js +112 -0
  212. package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
  213. package/node_modules/yaml/dist/parse/lexer.js +719 -0
  214. package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
  215. package/node_modules/yaml/dist/parse/line-counter.js +41 -0
  216. package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
  217. package/node_modules/yaml/dist/parse/parser.js +958 -0
  218. package/node_modules/yaml/dist/public-api.d.ts +43 -0
  219. package/node_modules/yaml/dist/public-api.js +104 -0
  220. package/node_modules/yaml/dist/schema/Schema.d.ts +18 -0
  221. package/node_modules/yaml/dist/schema/Schema.js +40 -0
  222. package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
  223. package/node_modules/yaml/dist/schema/common/map.js +19 -0
  224. package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
  225. package/node_modules/yaml/dist/schema/common/null.js +17 -0
  226. package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
  227. package/node_modules/yaml/dist/schema/common/seq.js +19 -0
  228. package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
  229. package/node_modules/yaml/dist/schema/common/string.js +16 -0
  230. package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
  231. package/node_modules/yaml/dist/schema/core/bool.js +21 -0
  232. package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
  233. package/node_modules/yaml/dist/schema/core/float.js +47 -0
  234. package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
  235. package/node_modules/yaml/dist/schema/core/int.js +42 -0
  236. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
  237. package/node_modules/yaml/dist/schema/core/schema.js +25 -0
  238. package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
  239. package/node_modules/yaml/dist/schema/json/schema.js +64 -0
  240. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  241. package/node_modules/yaml/dist/schema/tags.d.ts +40 -0
  242. package/node_modules/yaml/dist/schema/tags.js +86 -0
  243. package/node_modules/yaml/dist/schema/types.d.ts +90 -0
  244. package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  245. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +68 -0
  246. package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  247. package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  248. package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  249. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
  250. package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  251. package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
  252. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +28 -0
  253. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  254. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  255. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  256. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  257. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +39 -0
  258. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  259. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
  260. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  261. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  262. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  263. package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
  264. package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
  265. package/node_modules/yaml/dist/stringify/stringify.js +127 -0
  266. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  267. package/node_modules/yaml/dist/stringify/stringifyCollection.js +145 -0
  268. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  269. package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
  270. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  271. package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
  272. package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  273. package/node_modules/yaml/dist/stringify/stringifyNumber.js +26 -0
  274. package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  275. package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
  276. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
  277. package/node_modules/yaml/dist/stringify/stringifyString.js +330 -0
  278. package/node_modules/yaml/dist/test-events.d.ts +4 -0
  279. package/node_modules/yaml/dist/test-events.js +134 -0
  280. package/node_modules/yaml/dist/util.d.ts +12 -0
  281. package/node_modules/yaml/dist/util.js +28 -0
  282. package/node_modules/yaml/dist/visit.d.ts +102 -0
  283. package/node_modules/yaml/dist/visit.js +236 -0
  284. package/node_modules/yaml/package.json +96 -0
  285. package/node_modules/yaml/util.js +2 -0
  286. package/package.json +7 -3
  287. package/server.js +50 -23
  288. package/node_modules/path-to-regexp/History.md +0 -36
  289. /package/node_modules/{encodeurl → send/node_modules/encodeurl}/HISTORY.md +0 -0
@@ -0,0 +1,958 @@
1
+ 'use strict';
2
+
3
+ var cst = require('./cst.js');
4
+ var lexer = require('./lexer.js');
5
+
6
+ function includesToken(list, type) {
7
+ for (let i = 0; i < list.length; ++i)
8
+ if (list[i].type === type)
9
+ return true;
10
+ return false;
11
+ }
12
+ function findNonEmptyIndex(list) {
13
+ for (let i = 0; i < list.length; ++i) {
14
+ switch (list[i].type) {
15
+ case 'space':
16
+ case 'comment':
17
+ case 'newline':
18
+ break;
19
+ default:
20
+ return i;
21
+ }
22
+ }
23
+ return -1;
24
+ }
25
+ function isFlowToken(token) {
26
+ switch (token?.type) {
27
+ case 'alias':
28
+ case 'scalar':
29
+ case 'single-quoted-scalar':
30
+ case 'double-quoted-scalar':
31
+ case 'flow-collection':
32
+ return true;
33
+ default:
34
+ return false;
35
+ }
36
+ }
37
+ function getPrevProps(parent) {
38
+ switch (parent.type) {
39
+ case 'document':
40
+ return parent.start;
41
+ case 'block-map': {
42
+ const it = parent.items[parent.items.length - 1];
43
+ return it.sep ?? it.start;
44
+ }
45
+ case 'block-seq':
46
+ return parent.items[parent.items.length - 1].start;
47
+ /* istanbul ignore next should not happen */
48
+ default:
49
+ return [];
50
+ }
51
+ }
52
+ /** Note: May modify input array */
53
+ function getFirstKeyStartProps(prev) {
54
+ if (prev.length === 0)
55
+ return [];
56
+ let i = prev.length;
57
+ loop: while (--i >= 0) {
58
+ switch (prev[i].type) {
59
+ case 'doc-start':
60
+ case 'explicit-key-ind':
61
+ case 'map-value-ind':
62
+ case 'seq-item-ind':
63
+ case 'newline':
64
+ break loop;
65
+ }
66
+ }
67
+ while (prev[++i]?.type === 'space') {
68
+ /* loop */
69
+ }
70
+ return prev.splice(i, prev.length);
71
+ }
72
+ function fixFlowSeqItems(fc) {
73
+ if (fc.start.type === 'flow-seq-start') {
74
+ for (const it of fc.items) {
75
+ if (it.sep &&
76
+ !it.value &&
77
+ !includesToken(it.start, 'explicit-key-ind') &&
78
+ !includesToken(it.sep, 'map-value-ind')) {
79
+ if (it.key)
80
+ it.value = it.key;
81
+ delete it.key;
82
+ if (isFlowToken(it.value)) {
83
+ if (it.value.end)
84
+ Array.prototype.push.apply(it.value.end, it.sep);
85
+ else
86
+ it.value.end = it.sep;
87
+ }
88
+ else
89
+ Array.prototype.push.apply(it.start, it.sep);
90
+ delete it.sep;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ /**
96
+ * A YAML concrete syntax tree (CST) parser
97
+ *
98
+ * ```ts
99
+ * const src: string = ...
100
+ * for (const token of new Parser().parse(src)) {
101
+ * // token: Token
102
+ * }
103
+ * ```
104
+ *
105
+ * To use the parser with a user-provided lexer:
106
+ *
107
+ * ```ts
108
+ * function* parse(source: string, lexer: Lexer) {
109
+ * const parser = new Parser()
110
+ * for (const lexeme of lexer.lex(source))
111
+ * yield* parser.next(lexeme)
112
+ * yield* parser.end()
113
+ * }
114
+ *
115
+ * const src: string = ...
116
+ * const lexer = new Lexer()
117
+ * for (const token of parse(src, lexer)) {
118
+ * // token: Token
119
+ * }
120
+ * ```
121
+ */
122
+ class Parser {
123
+ /**
124
+ * @param onNewLine - If defined, called separately with the start position of
125
+ * each new line (in `parse()`, including the start of input).
126
+ */
127
+ constructor(onNewLine) {
128
+ /** If true, space and sequence indicators count as indentation */
129
+ this.atNewLine = true;
130
+ /** If true, next token is a scalar value */
131
+ this.atScalar = false;
132
+ /** Current indentation level */
133
+ this.indent = 0;
134
+ /** Current offset since the start of parsing */
135
+ this.offset = 0;
136
+ /** On the same line with a block map key */
137
+ this.onKeyLine = false;
138
+ /** Top indicates the node that's currently being built */
139
+ this.stack = [];
140
+ /** The source of the current token, set in parse() */
141
+ this.source = '';
142
+ /** The type of the current token, set in parse() */
143
+ this.type = '';
144
+ // Must be defined after `next()`
145
+ this.lexer = new lexer.Lexer();
146
+ this.onNewLine = onNewLine;
147
+ }
148
+ /**
149
+ * Parse `source` as a YAML stream.
150
+ * If `incomplete`, a part of the last line may be left as a buffer for the next call.
151
+ *
152
+ * Errors are not thrown, but yielded as `{ type: 'error', message }` tokens.
153
+ *
154
+ * @returns A generator of tokens representing each directive, document, and other structure.
155
+ */
156
+ *parse(source, incomplete = false) {
157
+ if (this.onNewLine && this.offset === 0)
158
+ this.onNewLine(0);
159
+ for (const lexeme of this.lexer.lex(source, incomplete))
160
+ yield* this.next(lexeme);
161
+ if (!incomplete)
162
+ yield* this.end();
163
+ }
164
+ /**
165
+ * Advance the parser by the `source` of one lexical token.
166
+ */
167
+ *next(source) {
168
+ this.source = source;
169
+ if (process.env.LOG_TOKENS)
170
+ console.log('|', cst.prettyToken(source));
171
+ if (this.atScalar) {
172
+ this.atScalar = false;
173
+ yield* this.step();
174
+ this.offset += source.length;
175
+ return;
176
+ }
177
+ const type = cst.tokenType(source);
178
+ if (!type) {
179
+ const message = `Not a YAML token: ${source}`;
180
+ yield* this.pop({ type: 'error', offset: this.offset, message, source });
181
+ this.offset += source.length;
182
+ }
183
+ else if (type === 'scalar') {
184
+ this.atNewLine = false;
185
+ this.atScalar = true;
186
+ this.type = 'scalar';
187
+ }
188
+ else {
189
+ this.type = type;
190
+ yield* this.step();
191
+ switch (type) {
192
+ case 'newline':
193
+ this.atNewLine = true;
194
+ this.indent = 0;
195
+ if (this.onNewLine)
196
+ this.onNewLine(this.offset + source.length);
197
+ break;
198
+ case 'space':
199
+ if (this.atNewLine && source[0] === ' ')
200
+ this.indent += source.length;
201
+ break;
202
+ case 'explicit-key-ind':
203
+ case 'map-value-ind':
204
+ case 'seq-item-ind':
205
+ if (this.atNewLine)
206
+ this.indent += source.length;
207
+ break;
208
+ case 'doc-mode':
209
+ case 'flow-error-end':
210
+ return;
211
+ default:
212
+ this.atNewLine = false;
213
+ }
214
+ this.offset += source.length;
215
+ }
216
+ }
217
+ /** Call at end of input to push out any remaining constructions */
218
+ *end() {
219
+ while (this.stack.length > 0)
220
+ yield* this.pop();
221
+ }
222
+ get sourceToken() {
223
+ const st = {
224
+ type: this.type,
225
+ offset: this.offset,
226
+ indent: this.indent,
227
+ source: this.source
228
+ };
229
+ return st;
230
+ }
231
+ *step() {
232
+ const top = this.peek(1);
233
+ if (this.type === 'doc-end' && (!top || top.type !== 'doc-end')) {
234
+ while (this.stack.length > 0)
235
+ yield* this.pop();
236
+ this.stack.push({
237
+ type: 'doc-end',
238
+ offset: this.offset,
239
+ source: this.source
240
+ });
241
+ return;
242
+ }
243
+ if (!top)
244
+ return yield* this.stream();
245
+ switch (top.type) {
246
+ case 'document':
247
+ return yield* this.document(top);
248
+ case 'alias':
249
+ case 'scalar':
250
+ case 'single-quoted-scalar':
251
+ case 'double-quoted-scalar':
252
+ return yield* this.scalar(top);
253
+ case 'block-scalar':
254
+ return yield* this.blockScalar(top);
255
+ case 'block-map':
256
+ return yield* this.blockMap(top);
257
+ case 'block-seq':
258
+ return yield* this.blockSequence(top);
259
+ case 'flow-collection':
260
+ return yield* this.flowCollection(top);
261
+ case 'doc-end':
262
+ return yield* this.documentEnd(top);
263
+ }
264
+ /* istanbul ignore next should not happen */
265
+ yield* this.pop();
266
+ }
267
+ peek(n) {
268
+ return this.stack[this.stack.length - n];
269
+ }
270
+ *pop(error) {
271
+ const token = error ?? this.stack.pop();
272
+ /* istanbul ignore if should not happen */
273
+ if (!token) {
274
+ const message = 'Tried to pop an empty stack';
275
+ yield { type: 'error', offset: this.offset, source: '', message };
276
+ }
277
+ else if (this.stack.length === 0) {
278
+ yield token;
279
+ }
280
+ else {
281
+ const top = this.peek(1);
282
+ if (token.type === 'block-scalar') {
283
+ // Block scalars use their parent rather than header indent
284
+ token.indent = 'indent' in top ? top.indent : 0;
285
+ }
286
+ else if (token.type === 'flow-collection' && top.type === 'document') {
287
+ // Ignore all indent for top-level flow collections
288
+ token.indent = 0;
289
+ }
290
+ if (token.type === 'flow-collection')
291
+ fixFlowSeqItems(token);
292
+ switch (top.type) {
293
+ case 'document':
294
+ top.value = token;
295
+ break;
296
+ case 'block-scalar':
297
+ top.props.push(token); // error
298
+ break;
299
+ case 'block-map': {
300
+ const it = top.items[top.items.length - 1];
301
+ if (it.value) {
302
+ top.items.push({ start: [], key: token, sep: [] });
303
+ this.onKeyLine = true;
304
+ return;
305
+ }
306
+ else if (it.sep) {
307
+ it.value = token;
308
+ }
309
+ else {
310
+ Object.assign(it, { key: token, sep: [] });
311
+ this.onKeyLine = !it.explicitKey;
312
+ return;
313
+ }
314
+ break;
315
+ }
316
+ case 'block-seq': {
317
+ const it = top.items[top.items.length - 1];
318
+ if (it.value)
319
+ top.items.push({ start: [], value: token });
320
+ else
321
+ it.value = token;
322
+ break;
323
+ }
324
+ case 'flow-collection': {
325
+ const it = top.items[top.items.length - 1];
326
+ if (!it || it.value)
327
+ top.items.push({ start: [], key: token, sep: [] });
328
+ else if (it.sep)
329
+ it.value = token;
330
+ else
331
+ Object.assign(it, { key: token, sep: [] });
332
+ return;
333
+ }
334
+ /* istanbul ignore next should not happen */
335
+ default:
336
+ yield* this.pop();
337
+ yield* this.pop(token);
338
+ }
339
+ if ((top.type === 'document' ||
340
+ top.type === 'block-map' ||
341
+ top.type === 'block-seq') &&
342
+ (token.type === 'block-map' || token.type === 'block-seq')) {
343
+ const last = token.items[token.items.length - 1];
344
+ if (last &&
345
+ !last.sep &&
346
+ !last.value &&
347
+ last.start.length > 0 &&
348
+ findNonEmptyIndex(last.start) === -1 &&
349
+ (token.indent === 0 ||
350
+ last.start.every(st => st.type !== 'comment' || st.indent < token.indent))) {
351
+ if (top.type === 'document')
352
+ top.end = last.start;
353
+ else
354
+ top.items.push({ start: last.start });
355
+ token.items.splice(-1, 1);
356
+ }
357
+ }
358
+ }
359
+ }
360
+ *stream() {
361
+ switch (this.type) {
362
+ case 'directive-line':
363
+ yield { type: 'directive', offset: this.offset, source: this.source };
364
+ return;
365
+ case 'byte-order-mark':
366
+ case 'space':
367
+ case 'comment':
368
+ case 'newline':
369
+ yield this.sourceToken;
370
+ return;
371
+ case 'doc-mode':
372
+ case 'doc-start': {
373
+ const doc = {
374
+ type: 'document',
375
+ offset: this.offset,
376
+ start: []
377
+ };
378
+ if (this.type === 'doc-start')
379
+ doc.start.push(this.sourceToken);
380
+ this.stack.push(doc);
381
+ return;
382
+ }
383
+ }
384
+ yield {
385
+ type: 'error',
386
+ offset: this.offset,
387
+ message: `Unexpected ${this.type} token in YAML stream`,
388
+ source: this.source
389
+ };
390
+ }
391
+ *document(doc) {
392
+ if (doc.value)
393
+ return yield* this.lineEnd(doc);
394
+ switch (this.type) {
395
+ case 'doc-start': {
396
+ if (findNonEmptyIndex(doc.start) !== -1) {
397
+ yield* this.pop();
398
+ yield* this.step();
399
+ }
400
+ else
401
+ doc.start.push(this.sourceToken);
402
+ return;
403
+ }
404
+ case 'anchor':
405
+ case 'tag':
406
+ case 'space':
407
+ case 'comment':
408
+ case 'newline':
409
+ doc.start.push(this.sourceToken);
410
+ return;
411
+ }
412
+ const bv = this.startBlockValue(doc);
413
+ if (bv)
414
+ this.stack.push(bv);
415
+ else {
416
+ yield {
417
+ type: 'error',
418
+ offset: this.offset,
419
+ message: `Unexpected ${this.type} token in YAML document`,
420
+ source: this.source
421
+ };
422
+ }
423
+ }
424
+ *scalar(scalar) {
425
+ if (this.type === 'map-value-ind') {
426
+ const prev = getPrevProps(this.peek(2));
427
+ const start = getFirstKeyStartProps(prev);
428
+ let sep;
429
+ if (scalar.end) {
430
+ sep = scalar.end;
431
+ sep.push(this.sourceToken);
432
+ delete scalar.end;
433
+ }
434
+ else
435
+ sep = [this.sourceToken];
436
+ const map = {
437
+ type: 'block-map',
438
+ offset: scalar.offset,
439
+ indent: scalar.indent,
440
+ items: [{ start, key: scalar, sep }]
441
+ };
442
+ this.onKeyLine = true;
443
+ this.stack[this.stack.length - 1] = map;
444
+ }
445
+ else
446
+ yield* this.lineEnd(scalar);
447
+ }
448
+ *blockScalar(scalar) {
449
+ switch (this.type) {
450
+ case 'space':
451
+ case 'comment':
452
+ case 'newline':
453
+ scalar.props.push(this.sourceToken);
454
+ return;
455
+ case 'scalar':
456
+ scalar.source = this.source;
457
+ // block-scalar source includes trailing newline
458
+ this.atNewLine = true;
459
+ this.indent = 0;
460
+ if (this.onNewLine) {
461
+ let nl = this.source.indexOf('\n') + 1;
462
+ while (nl !== 0) {
463
+ this.onNewLine(this.offset + nl);
464
+ nl = this.source.indexOf('\n', nl) + 1;
465
+ }
466
+ }
467
+ yield* this.pop();
468
+ break;
469
+ /* istanbul ignore next should not happen */
470
+ default:
471
+ yield* this.pop();
472
+ yield* this.step();
473
+ }
474
+ }
475
+ *blockMap(map) {
476
+ const it = map.items[map.items.length - 1];
477
+ // it.sep is true-ish if pair already has key or : separator
478
+ switch (this.type) {
479
+ case 'newline':
480
+ this.onKeyLine = false;
481
+ if (it.value) {
482
+ const end = 'end' in it.value ? it.value.end : undefined;
483
+ const last = Array.isArray(end) ? end[end.length - 1] : undefined;
484
+ if (last?.type === 'comment')
485
+ end?.push(this.sourceToken);
486
+ else
487
+ map.items.push({ start: [this.sourceToken] });
488
+ }
489
+ else if (it.sep) {
490
+ it.sep.push(this.sourceToken);
491
+ }
492
+ else {
493
+ it.start.push(this.sourceToken);
494
+ }
495
+ return;
496
+ case 'space':
497
+ case 'comment':
498
+ if (it.value) {
499
+ map.items.push({ start: [this.sourceToken] });
500
+ }
501
+ else if (it.sep) {
502
+ it.sep.push(this.sourceToken);
503
+ }
504
+ else {
505
+ if (this.atIndentedComment(it.start, map.indent)) {
506
+ const prev = map.items[map.items.length - 2];
507
+ const end = prev?.value?.end;
508
+ if (Array.isArray(end)) {
509
+ Array.prototype.push.apply(end, it.start);
510
+ end.push(this.sourceToken);
511
+ map.items.pop();
512
+ return;
513
+ }
514
+ }
515
+ it.start.push(this.sourceToken);
516
+ }
517
+ return;
518
+ }
519
+ if (this.indent >= map.indent) {
520
+ const atMapIndent = !this.onKeyLine && this.indent === map.indent;
521
+ const atNextItem = atMapIndent &&
522
+ (it.sep || it.explicitKey) &&
523
+ this.type !== 'seq-item-ind';
524
+ // For empty nodes, assign newline-separated not indented empty tokens to following node
525
+ let start = [];
526
+ if (atNextItem && it.sep && !it.value) {
527
+ const nl = [];
528
+ for (let i = 0; i < it.sep.length; ++i) {
529
+ const st = it.sep[i];
530
+ switch (st.type) {
531
+ case 'newline':
532
+ nl.push(i);
533
+ break;
534
+ case 'space':
535
+ break;
536
+ case 'comment':
537
+ if (st.indent > map.indent)
538
+ nl.length = 0;
539
+ break;
540
+ default:
541
+ nl.length = 0;
542
+ }
543
+ }
544
+ if (nl.length >= 2)
545
+ start = it.sep.splice(nl[1]);
546
+ }
547
+ switch (this.type) {
548
+ case 'anchor':
549
+ case 'tag':
550
+ if (atNextItem || it.value) {
551
+ start.push(this.sourceToken);
552
+ map.items.push({ start });
553
+ this.onKeyLine = true;
554
+ }
555
+ else if (it.sep) {
556
+ it.sep.push(this.sourceToken);
557
+ }
558
+ else {
559
+ it.start.push(this.sourceToken);
560
+ }
561
+ return;
562
+ case 'explicit-key-ind':
563
+ if (!it.sep && !it.explicitKey) {
564
+ it.start.push(this.sourceToken);
565
+ it.explicitKey = true;
566
+ }
567
+ else if (atNextItem || it.value) {
568
+ start.push(this.sourceToken);
569
+ map.items.push({ start, explicitKey: true });
570
+ }
571
+ else {
572
+ this.stack.push({
573
+ type: 'block-map',
574
+ offset: this.offset,
575
+ indent: this.indent,
576
+ items: [{ start: [this.sourceToken], explicitKey: true }]
577
+ });
578
+ }
579
+ this.onKeyLine = true;
580
+ return;
581
+ case 'map-value-ind':
582
+ if (it.explicitKey) {
583
+ if (!it.sep) {
584
+ if (includesToken(it.start, 'newline')) {
585
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
586
+ }
587
+ else {
588
+ const start = getFirstKeyStartProps(it.start);
589
+ this.stack.push({
590
+ type: 'block-map',
591
+ offset: this.offset,
592
+ indent: this.indent,
593
+ items: [{ start, key: null, sep: [this.sourceToken] }]
594
+ });
595
+ }
596
+ }
597
+ else if (it.value) {
598
+ map.items.push({ start: [], key: null, sep: [this.sourceToken] });
599
+ }
600
+ else if (includesToken(it.sep, 'map-value-ind')) {
601
+ this.stack.push({
602
+ type: 'block-map',
603
+ offset: this.offset,
604
+ indent: this.indent,
605
+ items: [{ start, key: null, sep: [this.sourceToken] }]
606
+ });
607
+ }
608
+ else if (isFlowToken(it.key) &&
609
+ !includesToken(it.sep, 'newline')) {
610
+ const start = getFirstKeyStartProps(it.start);
611
+ const key = it.key;
612
+ const sep = it.sep;
613
+ sep.push(this.sourceToken);
614
+ // @ts-expect-error type guard is wrong here
615
+ delete it.key;
616
+ // @ts-expect-error type guard is wrong here
617
+ delete it.sep;
618
+ this.stack.push({
619
+ type: 'block-map',
620
+ offset: this.offset,
621
+ indent: this.indent,
622
+ items: [{ start, key, sep }]
623
+ });
624
+ }
625
+ else if (start.length > 0) {
626
+ // Not actually at next item
627
+ it.sep = it.sep.concat(start, this.sourceToken);
628
+ }
629
+ else {
630
+ it.sep.push(this.sourceToken);
631
+ }
632
+ }
633
+ else {
634
+ if (!it.sep) {
635
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
636
+ }
637
+ else if (it.value || atNextItem) {
638
+ map.items.push({ start, key: null, sep: [this.sourceToken] });
639
+ }
640
+ else if (includesToken(it.sep, 'map-value-ind')) {
641
+ this.stack.push({
642
+ type: 'block-map',
643
+ offset: this.offset,
644
+ indent: this.indent,
645
+ items: [{ start: [], key: null, sep: [this.sourceToken] }]
646
+ });
647
+ }
648
+ else {
649
+ it.sep.push(this.sourceToken);
650
+ }
651
+ }
652
+ this.onKeyLine = true;
653
+ return;
654
+ case 'alias':
655
+ case 'scalar':
656
+ case 'single-quoted-scalar':
657
+ case 'double-quoted-scalar': {
658
+ const fs = this.flowScalar(this.type);
659
+ if (atNextItem || it.value) {
660
+ map.items.push({ start, key: fs, sep: [] });
661
+ this.onKeyLine = true;
662
+ }
663
+ else if (it.sep) {
664
+ this.stack.push(fs);
665
+ }
666
+ else {
667
+ Object.assign(it, { key: fs, sep: [] });
668
+ this.onKeyLine = true;
669
+ }
670
+ return;
671
+ }
672
+ default: {
673
+ const bv = this.startBlockValue(map);
674
+ if (bv) {
675
+ if (atMapIndent && bv.type !== 'block-seq') {
676
+ map.items.push({ start });
677
+ }
678
+ this.stack.push(bv);
679
+ return;
680
+ }
681
+ }
682
+ }
683
+ }
684
+ yield* this.pop();
685
+ yield* this.step();
686
+ }
687
+ *blockSequence(seq) {
688
+ const it = seq.items[seq.items.length - 1];
689
+ switch (this.type) {
690
+ case 'newline':
691
+ if (it.value) {
692
+ const end = 'end' in it.value ? it.value.end : undefined;
693
+ const last = Array.isArray(end) ? end[end.length - 1] : undefined;
694
+ if (last?.type === 'comment')
695
+ end?.push(this.sourceToken);
696
+ else
697
+ seq.items.push({ start: [this.sourceToken] });
698
+ }
699
+ else
700
+ it.start.push(this.sourceToken);
701
+ return;
702
+ case 'space':
703
+ case 'comment':
704
+ if (it.value)
705
+ seq.items.push({ start: [this.sourceToken] });
706
+ else {
707
+ if (this.atIndentedComment(it.start, seq.indent)) {
708
+ const prev = seq.items[seq.items.length - 2];
709
+ const end = prev?.value?.end;
710
+ if (Array.isArray(end)) {
711
+ Array.prototype.push.apply(end, it.start);
712
+ end.push(this.sourceToken);
713
+ seq.items.pop();
714
+ return;
715
+ }
716
+ }
717
+ it.start.push(this.sourceToken);
718
+ }
719
+ return;
720
+ case 'anchor':
721
+ case 'tag':
722
+ if (it.value || this.indent <= seq.indent)
723
+ break;
724
+ it.start.push(this.sourceToken);
725
+ return;
726
+ case 'seq-item-ind':
727
+ if (this.indent !== seq.indent)
728
+ break;
729
+ if (it.value || includesToken(it.start, 'seq-item-ind'))
730
+ seq.items.push({ start: [this.sourceToken] });
731
+ else
732
+ it.start.push(this.sourceToken);
733
+ return;
734
+ }
735
+ if (this.indent > seq.indent) {
736
+ const bv = this.startBlockValue(seq);
737
+ if (bv) {
738
+ this.stack.push(bv);
739
+ return;
740
+ }
741
+ }
742
+ yield* this.pop();
743
+ yield* this.step();
744
+ }
745
+ *flowCollection(fc) {
746
+ const it = fc.items[fc.items.length - 1];
747
+ if (this.type === 'flow-error-end') {
748
+ let top;
749
+ do {
750
+ yield* this.pop();
751
+ top = this.peek(1);
752
+ } while (top && top.type === 'flow-collection');
753
+ }
754
+ else if (fc.end.length === 0) {
755
+ switch (this.type) {
756
+ case 'comma':
757
+ case 'explicit-key-ind':
758
+ if (!it || it.sep)
759
+ fc.items.push({ start: [this.sourceToken] });
760
+ else
761
+ it.start.push(this.sourceToken);
762
+ return;
763
+ case 'map-value-ind':
764
+ if (!it || it.value)
765
+ fc.items.push({ start: [], key: null, sep: [this.sourceToken] });
766
+ else if (it.sep)
767
+ it.sep.push(this.sourceToken);
768
+ else
769
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
770
+ return;
771
+ case 'space':
772
+ case 'comment':
773
+ case 'newline':
774
+ case 'anchor':
775
+ case 'tag':
776
+ if (!it || it.value)
777
+ fc.items.push({ start: [this.sourceToken] });
778
+ else if (it.sep)
779
+ it.sep.push(this.sourceToken);
780
+ else
781
+ it.start.push(this.sourceToken);
782
+ return;
783
+ case 'alias':
784
+ case 'scalar':
785
+ case 'single-quoted-scalar':
786
+ case 'double-quoted-scalar': {
787
+ const fs = this.flowScalar(this.type);
788
+ if (!it || it.value)
789
+ fc.items.push({ start: [], key: fs, sep: [] });
790
+ else if (it.sep)
791
+ this.stack.push(fs);
792
+ else
793
+ Object.assign(it, { key: fs, sep: [] });
794
+ return;
795
+ }
796
+ case 'flow-map-end':
797
+ case 'flow-seq-end':
798
+ fc.end.push(this.sourceToken);
799
+ return;
800
+ }
801
+ const bv = this.startBlockValue(fc);
802
+ /* istanbul ignore else should not happen */
803
+ if (bv)
804
+ this.stack.push(bv);
805
+ else {
806
+ yield* this.pop();
807
+ yield* this.step();
808
+ }
809
+ }
810
+ else {
811
+ const parent = this.peek(2);
812
+ if (parent.type === 'block-map' &&
813
+ ((this.type === 'map-value-ind' && parent.indent === fc.indent) ||
814
+ (this.type === 'newline' &&
815
+ !parent.items[parent.items.length - 1].sep))) {
816
+ yield* this.pop();
817
+ yield* this.step();
818
+ }
819
+ else if (this.type === 'map-value-ind' &&
820
+ parent.type !== 'flow-collection') {
821
+ const prev = getPrevProps(parent);
822
+ const start = getFirstKeyStartProps(prev);
823
+ fixFlowSeqItems(fc);
824
+ const sep = fc.end.splice(1, fc.end.length);
825
+ sep.push(this.sourceToken);
826
+ const map = {
827
+ type: 'block-map',
828
+ offset: fc.offset,
829
+ indent: fc.indent,
830
+ items: [{ start, key: fc, sep }]
831
+ };
832
+ this.onKeyLine = true;
833
+ this.stack[this.stack.length - 1] = map;
834
+ }
835
+ else {
836
+ yield* this.lineEnd(fc);
837
+ }
838
+ }
839
+ }
840
+ flowScalar(type) {
841
+ if (this.onNewLine) {
842
+ let nl = this.source.indexOf('\n') + 1;
843
+ while (nl !== 0) {
844
+ this.onNewLine(this.offset + nl);
845
+ nl = this.source.indexOf('\n', nl) + 1;
846
+ }
847
+ }
848
+ return {
849
+ type,
850
+ offset: this.offset,
851
+ indent: this.indent,
852
+ source: this.source
853
+ };
854
+ }
855
+ startBlockValue(parent) {
856
+ switch (this.type) {
857
+ case 'alias':
858
+ case 'scalar':
859
+ case 'single-quoted-scalar':
860
+ case 'double-quoted-scalar':
861
+ return this.flowScalar(this.type);
862
+ case 'block-scalar-header':
863
+ return {
864
+ type: 'block-scalar',
865
+ offset: this.offset,
866
+ indent: this.indent,
867
+ props: [this.sourceToken],
868
+ source: ''
869
+ };
870
+ case 'flow-map-start':
871
+ case 'flow-seq-start':
872
+ return {
873
+ type: 'flow-collection',
874
+ offset: this.offset,
875
+ indent: this.indent,
876
+ start: this.sourceToken,
877
+ items: [],
878
+ end: []
879
+ };
880
+ case 'seq-item-ind':
881
+ return {
882
+ type: 'block-seq',
883
+ offset: this.offset,
884
+ indent: this.indent,
885
+ items: [{ start: [this.sourceToken] }]
886
+ };
887
+ case 'explicit-key-ind': {
888
+ this.onKeyLine = true;
889
+ const prev = getPrevProps(parent);
890
+ const start = getFirstKeyStartProps(prev);
891
+ start.push(this.sourceToken);
892
+ return {
893
+ type: 'block-map',
894
+ offset: this.offset,
895
+ indent: this.indent,
896
+ items: [{ start, explicitKey: true }]
897
+ };
898
+ }
899
+ case 'map-value-ind': {
900
+ this.onKeyLine = true;
901
+ const prev = getPrevProps(parent);
902
+ const start = getFirstKeyStartProps(prev);
903
+ return {
904
+ type: 'block-map',
905
+ offset: this.offset,
906
+ indent: this.indent,
907
+ items: [{ start, key: null, sep: [this.sourceToken] }]
908
+ };
909
+ }
910
+ }
911
+ return null;
912
+ }
913
+ atIndentedComment(start, indent) {
914
+ if (this.type !== 'comment')
915
+ return false;
916
+ if (this.indent <= indent)
917
+ return false;
918
+ return start.every(st => st.type === 'newline' || st.type === 'space');
919
+ }
920
+ *documentEnd(docEnd) {
921
+ if (this.type !== 'doc-mode') {
922
+ if (docEnd.end)
923
+ docEnd.end.push(this.sourceToken);
924
+ else
925
+ docEnd.end = [this.sourceToken];
926
+ if (this.type === 'newline')
927
+ yield* this.pop();
928
+ }
929
+ }
930
+ *lineEnd(token) {
931
+ switch (this.type) {
932
+ case 'comma':
933
+ case 'doc-start':
934
+ case 'doc-end':
935
+ case 'flow-seq-end':
936
+ case 'flow-map-end':
937
+ case 'map-value-ind':
938
+ yield* this.pop();
939
+ yield* this.step();
940
+ break;
941
+ case 'newline':
942
+ this.onKeyLine = false;
943
+ // fallthrough
944
+ case 'space':
945
+ case 'comment':
946
+ default:
947
+ // all other values are errors
948
+ if (token.end)
949
+ token.end.push(this.sourceToken);
950
+ else
951
+ token.end = [this.sourceToken];
952
+ if (this.type === 'newline')
953
+ yield* this.pop();
954
+ }
955
+ }
956
+ }
957
+
958
+ exports.Parser = Parser;