yaml 1.10.1 → 2.0.0-10

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 (275) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +57 -41
  3. package/browser/dist/compose/compose-collection.js +59 -0
  4. package/browser/dist/compose/compose-doc.js +40 -0
  5. package/browser/dist/compose/compose-node.js +81 -0
  6. package/browser/dist/compose/compose-scalar.js +81 -0
  7. package/browser/dist/compose/composer.js +219 -0
  8. package/browser/dist/compose/resolve-block-map.js +107 -0
  9. package/browser/dist/compose/resolve-block-scalar.js +185 -0
  10. package/browser/dist/compose/resolve-block-seq.js +45 -0
  11. package/browser/dist/compose/resolve-end.js +37 -0
  12. package/browser/dist/compose/resolve-flow-collection.js +200 -0
  13. package/browser/dist/compose/resolve-flow-scalar.js +223 -0
  14. package/browser/dist/compose/resolve-props.js +128 -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-flow-indent-check.js +15 -0
  18. package/browser/dist/compose/util-map-includes.js +17 -0
  19. package/browser/dist/doc/Document.js +321 -0
  20. package/browser/dist/doc/anchors.js +72 -0
  21. package/browser/dist/doc/applyReviver.js +54 -0
  22. package/browser/dist/doc/createNode.js +84 -0
  23. package/browser/dist/doc/directives.js +166 -0
  24. package/browser/dist/errors.js +57 -0
  25. package/browser/dist/index.js +18 -1002
  26. package/browser/dist/log.js +14 -0
  27. package/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
  28. package/browser/dist/nodes/Alias.js +94 -0
  29. package/browser/dist/nodes/Collection.js +146 -0
  30. package/browser/dist/nodes/Node.js +48 -0
  31. package/browser/dist/nodes/Pair.js +36 -0
  32. package/browser/dist/nodes/Scalar.js +23 -0
  33. package/browser/dist/nodes/YAMLMap.js +116 -0
  34. package/browser/dist/nodes/YAMLSeq.js +105 -0
  35. package/browser/dist/nodes/addPairToJSMap.js +104 -0
  36. package/browser/dist/nodes/toJS.js +35 -0
  37. package/browser/dist/options.js +18 -0
  38. package/browser/dist/parse/cst-scalar.js +215 -0
  39. package/browser/dist/parse/cst-stringify.js +61 -0
  40. package/browser/dist/parse/cst-visit.js +97 -0
  41. package/browser/dist/parse/cst.js +98 -0
  42. package/browser/dist/parse/lexer.js +692 -0
  43. package/browser/dist/parse/line-counter.js +39 -0
  44. package/browser/dist/parse/parser.js +882 -0
  45. package/browser/dist/public-api.js +99 -0
  46. package/browser/dist/schema/Schema.js +34 -0
  47. package/browser/dist/schema/common/map.js +42 -0
  48. package/browser/dist/schema/common/null.js +13 -0
  49. package/browser/dist/schema/common/seq.js +33 -0
  50. package/browser/dist/schema/common/string.js +14 -0
  51. package/browser/dist/schema/core/bool.js +19 -0
  52. package/browser/dist/schema/core/float.js +43 -0
  53. package/browser/dist/schema/core/int.js +38 -0
  54. package/browser/dist/schema/core/schema.js +23 -0
  55. package/browser/dist/schema/json/schema.js +62 -0
  56. package/browser/dist/schema/tags.js +83 -0
  57. package/browser/dist/schema/yaml-1.1/binary.js +66 -0
  58. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  59. package/browser/dist/schema/yaml-1.1/float.js +46 -0
  60. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  61. package/browser/dist/schema/yaml-1.1/omap.js +73 -0
  62. package/browser/dist/schema/yaml-1.1/pairs.js +77 -0
  63. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  64. package/browser/dist/schema/yaml-1.1/set.js +87 -0
  65. package/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  66. package/browser/dist/stringify/foldFlowLines.js +135 -0
  67. package/browser/dist/stringify/stringify.js +124 -0
  68. package/browser/dist/stringify/stringifyCollection.js +152 -0
  69. package/browser/dist/stringify/stringifyComment.js +18 -0
  70. package/browser/dist/stringify/stringifyDocument.js +68 -0
  71. package/browser/dist/stringify/stringifyNumber.js +24 -0
  72. package/browser/dist/stringify/stringifyPair.js +122 -0
  73. package/browser/dist/stringify/stringifyString.js +314 -0
  74. package/browser/dist/util.js +9 -2
  75. package/browser/dist/visit.js +146 -0
  76. package/browser/index.js +5 -1
  77. package/browser/package.json +3 -0
  78. package/dist/compose/compose-collection.d.ts +5 -0
  79. package/dist/compose/compose-collection.js +61 -0
  80. package/dist/compose/compose-doc.d.ts +6 -0
  81. package/dist/compose/compose-doc.js +42 -0
  82. package/dist/compose/compose-node.d.ts +26 -0
  83. package/dist/compose/compose-node.js +84 -0
  84. package/dist/compose/compose-scalar.d.ts +5 -0
  85. package/dist/compose/compose-scalar.js +83 -0
  86. package/dist/compose/composer.d.ts +62 -0
  87. package/dist/compose/composer.js +223 -0
  88. package/dist/compose/resolve-block-map.d.ts +6 -0
  89. package/dist/compose/resolve-block-map.js +109 -0
  90. package/dist/compose/resolve-block-scalar.d.ts +10 -0
  91. package/dist/compose/resolve-block-scalar.js +187 -0
  92. package/dist/compose/resolve-block-seq.d.ts +5 -0
  93. package/dist/compose/resolve-block-seq.js +47 -0
  94. package/dist/compose/resolve-end.d.ts +6 -0
  95. package/dist/compose/resolve-end.js +39 -0
  96. package/dist/compose/resolve-flow-collection.d.ts +6 -0
  97. package/dist/compose/resolve-flow-collection.js +202 -0
  98. package/dist/compose/resolve-flow-scalar.d.ts +10 -0
  99. package/dist/compose/resolve-flow-scalar.js +225 -0
  100. package/dist/compose/resolve-props.d.ts +21 -0
  101. package/dist/compose/resolve-props.js +130 -0
  102. package/dist/compose/util-contains-newline.d.ts +2 -0
  103. package/dist/compose/util-contains-newline.js +36 -0
  104. package/dist/compose/util-empty-scalar-position.d.ts +2 -0
  105. package/dist/compose/util-empty-scalar-position.js +29 -0
  106. package/dist/compose/util-flow-indent-check.d.ts +3 -0
  107. package/dist/compose/util-flow-indent-check.js +17 -0
  108. package/dist/compose/util-map-includes.d.ts +4 -0
  109. package/dist/compose/util-map-includes.js +19 -0
  110. package/dist/doc/Document.d.ts +139 -0
  111. package/dist/doc/Document.js +323 -0
  112. package/dist/doc/anchors.d.ts +24 -0
  113. package/dist/doc/anchors.js +77 -0
  114. package/dist/doc/applyReviver.d.ts +9 -0
  115. package/dist/doc/applyReviver.js +56 -0
  116. package/dist/doc/createNode.d.ts +17 -0
  117. package/dist/doc/createNode.js +86 -0
  118. package/dist/doc/directives.d.ts +47 -0
  119. package/dist/doc/directives.js +168 -0
  120. package/dist/errors.d.ts +21 -0
  121. package/dist/errors.js +62 -0
  122. package/dist/index.d.ts +19 -0
  123. package/dist/index.js +49 -77
  124. package/dist/log.d.ts +3 -0
  125. package/dist/log.js +17 -0
  126. package/dist/node_modules/tslib/tslib.es6.js +76 -0
  127. package/dist/nodes/Alias.d.ts +28 -0
  128. package/dist/nodes/Alias.js +96 -0
  129. package/dist/nodes/Collection.d.ts +73 -0
  130. package/dist/nodes/Collection.js +150 -0
  131. package/dist/nodes/Node.d.ts +53 -0
  132. package/dist/nodes/Node.js +66 -0
  133. package/dist/nodes/Pair.d.ts +21 -0
  134. package/dist/nodes/Pair.js +39 -0
  135. package/dist/nodes/Scalar.d.ts +42 -0
  136. package/dist/nodes/Scalar.js +26 -0
  137. package/dist/nodes/YAMLMap.d.ts +41 -0
  138. package/dist/nodes/YAMLMap.js +119 -0
  139. package/dist/nodes/YAMLSeq.d.ts +55 -0
  140. package/dist/nodes/YAMLSeq.js +107 -0
  141. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  142. package/dist/nodes/addPairToJSMap.js +106 -0
  143. package/dist/nodes/toJS.d.ts +30 -0
  144. package/dist/nodes/toJS.js +37 -0
  145. package/dist/options.d.ts +338 -0
  146. package/dist/options.js +20 -0
  147. package/dist/parse/cst-scalar.d.ts +64 -0
  148. package/dist/parse/cst-scalar.js +219 -0
  149. package/dist/parse/cst-stringify.d.ts +8 -0
  150. package/dist/parse/cst-stringify.js +63 -0
  151. package/dist/parse/cst-visit.d.ts +39 -0
  152. package/dist/parse/cst-visit.js +99 -0
  153. package/dist/parse/cst.d.ts +106 -0
  154. package/dist/parse/cst.js +112 -0
  155. package/dist/parse/lexer.d.ts +87 -0
  156. package/dist/parse/lexer.js +694 -0
  157. package/dist/parse/line-counter.d.ts +22 -0
  158. package/dist/parse/line-counter.js +41 -0
  159. package/dist/parse/parser.d.ts +84 -0
  160. package/dist/parse/parser.js +886 -0
  161. package/dist/public-api.d.ts +43 -0
  162. package/dist/public-api.js +104 -0
  163. package/dist/schema/Schema.d.ts +18 -0
  164. package/dist/schema/Schema.js +36 -0
  165. package/dist/schema/common/map.d.ts +2 -0
  166. package/dist/schema/common/map.js +44 -0
  167. package/dist/schema/common/null.d.ts +4 -0
  168. package/dist/schema/common/null.js +15 -0
  169. package/dist/schema/common/seq.d.ts +2 -0
  170. package/dist/schema/common/seq.js +35 -0
  171. package/dist/schema/common/string.d.ts +2 -0
  172. package/dist/schema/common/string.js +16 -0
  173. package/dist/schema/core/bool.d.ts +4 -0
  174. package/dist/schema/core/bool.js +21 -0
  175. package/dist/schema/core/float.d.ts +4 -0
  176. package/dist/schema/core/float.js +47 -0
  177. package/dist/schema/core/int.d.ts +4 -0
  178. package/dist/schema/core/int.js +42 -0
  179. package/dist/schema/core/schema.d.ts +1 -0
  180. package/dist/schema/core/schema.js +25 -0
  181. package/dist/schema/json/schema.d.ts +2 -0
  182. package/dist/schema/json/schema.js +64 -0
  183. package/dist/schema/tags.d.ts +40 -0
  184. package/dist/schema/tags.js +86 -0
  185. package/dist/schema/types.d.ts +82 -0
  186. package/dist/schema/yaml-1.1/binary.d.ts +2 -0
  187. package/dist/schema/yaml-1.1/binary.js +68 -0
  188. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  189. package/dist/schema/yaml-1.1/bool.js +29 -0
  190. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  191. package/dist/schema/yaml-1.1/float.js +50 -0
  192. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  193. package/dist/schema/yaml-1.1/int.js +76 -0
  194. package/dist/schema/yaml-1.1/omap.d.ts +21 -0
  195. package/dist/schema/yaml-1.1/omap.js +76 -0
  196. package/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  197. package/dist/schema/yaml-1.1/pairs.js +81 -0
  198. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  199. package/dist/schema/yaml-1.1/schema.js +39 -0
  200. package/dist/schema/yaml-1.1/set.d.ts +22 -0
  201. package/dist/schema/yaml-1.1/set.js +90 -0
  202. package/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  203. package/dist/schema/yaml-1.1/timestamp.js +105 -0
  204. package/dist/stringify/foldFlowLines.d.ts +34 -0
  205. package/dist/stringify/foldFlowLines.js +140 -0
  206. package/dist/stringify/stringify.d.ts +20 -0
  207. package/dist/stringify/stringify.js +127 -0
  208. package/dist/stringify/stringifyCollection.d.ts +17 -0
  209. package/dist/stringify/stringifyCollection.js +154 -0
  210. package/dist/stringify/stringifyComment.d.ts +10 -0
  211. package/dist/stringify/stringifyComment.js +22 -0
  212. package/dist/stringify/stringifyDocument.d.ts +3 -0
  213. package/dist/stringify/stringifyDocument.js +70 -0
  214. package/dist/stringify/stringifyNumber.d.ts +2 -0
  215. package/dist/stringify/stringifyNumber.js +26 -0
  216. package/dist/stringify/stringifyPair.d.ts +3 -0
  217. package/dist/stringify/stringifyPair.js +124 -0
  218. package/dist/stringify/stringifyString.d.ts +3 -0
  219. package/dist/stringify/stringifyString.js +316 -0
  220. package/dist/test-events.d.ts +4 -0
  221. package/dist/test-events.js +126 -152
  222. package/dist/util.d.ts +9 -0
  223. package/dist/util.js +19 -14
  224. package/dist/visit.d.ts +63 -0
  225. package/dist/visit.js +148 -0
  226. package/package.json +43 -55
  227. package/util.d.ts +3 -86
  228. package/util.js +2 -16
  229. package/browser/dist/PlainValue-b8036b75.js +0 -1275
  230. package/browser/dist/Schema-e94716c8.js +0 -682
  231. package/browser/dist/legacy-exports.js +0 -3
  232. package/browser/dist/package.json +0 -1
  233. package/browser/dist/parse-cst.js +0 -1904
  234. package/browser/dist/resolveSeq-492ab440.js +0 -2419
  235. package/browser/dist/types.js +0 -4
  236. package/browser/dist/warnings-df54cb69.js +0 -499
  237. package/browser/map.js +0 -2
  238. package/browser/pair.js +0 -2
  239. package/browser/parse-cst.js +0 -1
  240. package/browser/scalar.js +0 -2
  241. package/browser/schema.js +0 -9
  242. package/browser/seq.js +0 -2
  243. package/browser/types/binary.js +0 -8
  244. package/browser/types/omap.js +0 -3
  245. package/browser/types/pairs.js +0 -3
  246. package/browser/types/set.js +0 -3
  247. package/browser/types/timestamp.js +0 -10
  248. package/browser/types.js +0 -1
  249. package/browser/util.js +0 -1
  250. package/dist/Document-9b4560a1.js +0 -757
  251. package/dist/PlainValue-ec8e588e.js +0 -876
  252. package/dist/Schema-88e323a7.js +0 -525
  253. package/dist/legacy-exports.js +0 -16
  254. package/dist/parse-cst.js +0 -1753
  255. package/dist/resolveSeq-d03cb037.js +0 -2161
  256. package/dist/types.js +0 -23
  257. package/dist/warnings-1000a372.js +0 -416
  258. package/index.d.ts +0 -372
  259. package/index.js +0 -1
  260. package/map.js +0 -2
  261. package/pair.js +0 -2
  262. package/parse-cst.d.ts +0 -191
  263. package/parse-cst.js +0 -1
  264. package/scalar.js +0 -2
  265. package/schema.js +0 -9
  266. package/seq.js +0 -2
  267. package/types/binary.js +0 -8
  268. package/types/omap.js +0 -3
  269. package/types/pairs.js +0 -3
  270. package/types/set.js +0 -3
  271. package/types/timestamp.js +0 -10
  272. package/types.d.ts +0 -407
  273. package/types.js +0 -17
  274. package/types.mjs +0 -17
  275. package/util.mjs +0 -18
@@ -0,0 +1,223 @@
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 badChar = '';
43
+ switch (source[0]) {
44
+ /* istanbul ignore next should not happen */
45
+ case '\t':
46
+ badChar = 'a tab character';
47
+ break;
48
+ case ',':
49
+ badChar = 'flow indicator character ,';
50
+ break;
51
+ case '%':
52
+ badChar = 'directive indicator character %';
53
+ break;
54
+ case '|':
55
+ case '>': {
56
+ badChar = `block scalar indicator ${source[0]}`;
57
+ break;
58
+ }
59
+ case '@':
60
+ case '`': {
61
+ badChar = `reserved character ${source[0]}`;
62
+ break;
63
+ }
64
+ }
65
+ if (badChar)
66
+ onError(0, 'BAD_SCALAR_START', `Plain value cannot start with ${badChar}`);
67
+ return foldLines(source);
68
+ }
69
+ function singleQuotedValue(source, onError) {
70
+ if (source[source.length - 1] !== "'" || source.length === 1)
71
+ onError(source.length, 'MISSING_CHAR', "Missing closing 'quote");
72
+ return foldLines(source.slice(1, -1)).replace(/''/g, "'");
73
+ }
74
+ function foldLines(source) {
75
+ /**
76
+ * The negative lookbehind here and in the `re` RegExp is to
77
+ * prevent causing a polynomial search time in certain cases.
78
+ *
79
+ * The try-catch is for Safari, which doesn't support this yet:
80
+ * https://caniuse.com/js-regexp-lookbehind
81
+ */
82
+ let first, line;
83
+ try {
84
+ first = new RegExp('(.*?)(?<![ \t])[ \t]*\r?\n', 'sy');
85
+ line = new RegExp('[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n', 'sy');
86
+ }
87
+ catch (_) {
88
+ first = /(.*?)[ \t]*\r?\n/sy;
89
+ line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
90
+ }
91
+ let match = first.exec(source);
92
+ if (!match)
93
+ return source;
94
+ let res = match[1];
95
+ let sep = ' ';
96
+ let pos = first.lastIndex;
97
+ line.lastIndex = pos;
98
+ while ((match = line.exec(source))) {
99
+ if (match[1] === '') {
100
+ if (sep === '\n')
101
+ res += sep;
102
+ else
103
+ sep = '\n';
104
+ }
105
+ else {
106
+ res += sep + match[1];
107
+ sep = ' ';
108
+ }
109
+ pos = line.lastIndex;
110
+ }
111
+ const last = /[ \t]*(.*)/sy;
112
+ last.lastIndex = pos;
113
+ match = last.exec(source);
114
+ return res + sep + ((match && match[1]) || '');
115
+ }
116
+ function doubleQuotedValue(source, onError) {
117
+ let res = '';
118
+ for (let i = 1; i < source.length - 1; ++i) {
119
+ const ch = source[i];
120
+ if (ch === '\r' && source[i + 1] === '\n')
121
+ continue;
122
+ if (ch === '\n') {
123
+ const { fold, offset } = foldNewline(source, i);
124
+ res += fold;
125
+ i = offset;
126
+ }
127
+ else if (ch === '\\') {
128
+ let next = source[++i];
129
+ const cc = escapeCodes[next];
130
+ if (cc)
131
+ res += cc;
132
+ else if (next === '\n') {
133
+ // skip escaped newlines, but still trim the following line
134
+ next = source[i + 1];
135
+ while (next === ' ' || next === '\t')
136
+ next = source[++i + 1];
137
+ }
138
+ else if (next === '\r' && source[i + 1] === '\n') {
139
+ // skip escaped CRLF newlines, but still trim the following line
140
+ next = source[++i + 1];
141
+ while (next === ' ' || next === '\t')
142
+ next = source[++i + 1];
143
+ }
144
+ else if (next === 'x' || next === 'u' || next === 'U') {
145
+ const length = { x: 2, u: 4, U: 8 }[next];
146
+ res += parseCharCode(source, i + 1, length, onError);
147
+ i += length;
148
+ }
149
+ else {
150
+ const raw = source.substr(i - 1, 2);
151
+ onError(i - 1, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
152
+ res += raw;
153
+ }
154
+ }
155
+ else if (ch === ' ' || ch === '\t') {
156
+ // trim trailing whitespace
157
+ const wsStart = i;
158
+ let next = source[i + 1];
159
+ while (next === ' ' || next === '\t')
160
+ next = source[++i + 1];
161
+ if (next !== '\n' && !(next === '\r' && source[i + 2] === '\n'))
162
+ res += i > wsStart ? source.slice(wsStart, i + 1) : ch;
163
+ }
164
+ else {
165
+ res += ch;
166
+ }
167
+ }
168
+ if (source[source.length - 1] !== '"' || source.length === 1)
169
+ onError(source.length, 'MISSING_CHAR', 'Missing closing "quote');
170
+ return res;
171
+ }
172
+ /**
173
+ * Fold a single newline into a space, multiple newlines to N - 1 newlines.
174
+ * Presumes `source[offset] === '\n'`
175
+ */
176
+ function foldNewline(source, offset) {
177
+ let fold = '';
178
+ let ch = source[offset + 1];
179
+ while (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
180
+ if (ch === '\r' && source[offset + 2] !== '\n')
181
+ break;
182
+ if (ch === '\n')
183
+ fold += '\n';
184
+ offset += 1;
185
+ ch = source[offset + 1];
186
+ }
187
+ if (!fold)
188
+ fold = ' ';
189
+ return { fold, offset };
190
+ }
191
+ const escapeCodes = {
192
+ '0': '\0',
193
+ a: '\x07',
194
+ b: '\b',
195
+ e: '\x1b',
196
+ f: '\f',
197
+ n: '\n',
198
+ r: '\r',
199
+ t: '\t',
200
+ v: '\v',
201
+ N: '\u0085',
202
+ _: '\u00a0',
203
+ L: '\u2028',
204
+ P: '\u2029',
205
+ ' ': ' ',
206
+ '"': '"',
207
+ '/': '/',
208
+ '\\': '\\',
209
+ '\t': '\t'
210
+ };
211
+ function parseCharCode(source, offset, length, onError) {
212
+ const cc = source.substr(offset, length);
213
+ const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
214
+ const code = ok ? parseInt(cc, 16) : NaN;
215
+ if (isNaN(code)) {
216
+ const raw = source.substr(offset - 2, length + 2);
217
+ onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
218
+ return raw;
219
+ }
220
+ return String.fromCodePoint(code);
221
+ }
222
+
223
+ export { resolveFlowScalar };
@@ -0,0 +1,128 @@
1
+ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnNewline }) {
2
+ let spaceBefore = false;
3
+ let atNewline = startOnNewline;
4
+ let hasSpace = startOnNewline;
5
+ let comment = '';
6
+ let commentSep = '';
7
+ let hasNewline = false;
8
+ let reqSpace = false;
9
+ let anchor = null;
10
+ let tag = null;
11
+ let comma = null;
12
+ let found = null;
13
+ let start = null;
14
+ for (const token of tokens) {
15
+ if (reqSpace) {
16
+ if (token.type !== 'space' &&
17
+ token.type !== 'newline' &&
18
+ token.type !== 'comma')
19
+ onError(token.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
20
+ reqSpace = false;
21
+ }
22
+ switch (token.type) {
23
+ case 'space':
24
+ // At the doc level, tabs at line start may be parsed
25
+ // as leading white space rather than indentation.
26
+ // In a flow collection, only the parser handles indent.
27
+ if (!flow &&
28
+ atNewline &&
29
+ indicator !== 'doc-start' &&
30
+ token.source[0] === '\t')
31
+ onError(token, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation');
32
+ hasSpace = true;
33
+ break;
34
+ case 'comment': {
35
+ if (!hasSpace)
36
+ onError(token, 'MISSING_CHAR', 'Comments must be separated from other tokens by white space characters');
37
+ const cb = token.source.substring(1) || ' ';
38
+ if (!comment)
39
+ comment = cb;
40
+ else
41
+ comment += commentSep + cb;
42
+ commentSep = '';
43
+ atNewline = false;
44
+ break;
45
+ }
46
+ case 'newline':
47
+ if (atNewline) {
48
+ if (comment)
49
+ comment += token.source;
50
+ else
51
+ spaceBefore = true;
52
+ }
53
+ else
54
+ commentSep += token.source;
55
+ atNewline = true;
56
+ hasNewline = true;
57
+ hasSpace = true;
58
+ break;
59
+ case 'anchor':
60
+ if (anchor)
61
+ onError(token, 'MULTIPLE_ANCHORS', 'A node can have at most one anchor');
62
+ anchor = token;
63
+ if (start === null)
64
+ start = token.offset;
65
+ atNewline = false;
66
+ hasSpace = false;
67
+ reqSpace = true;
68
+ break;
69
+ case 'tag': {
70
+ if (tag)
71
+ onError(token, 'MULTIPLE_TAGS', 'A node can have at most one tag');
72
+ tag = token;
73
+ if (start === null)
74
+ start = token.offset;
75
+ atNewline = false;
76
+ hasSpace = false;
77
+ reqSpace = true;
78
+ break;
79
+ }
80
+ case indicator:
81
+ // Could here handle preceding comments differently
82
+ if (anchor || tag)
83
+ onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
84
+ if (found)
85
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow || 'collection'}`);
86
+ found = token;
87
+ atNewline = false;
88
+ hasSpace = false;
89
+ break;
90
+ case 'comma':
91
+ if (flow) {
92
+ if (comma)
93
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected , in ${flow}`);
94
+ comma = token;
95
+ atNewline = false;
96
+ hasSpace = false;
97
+ break;
98
+ }
99
+ // else fallthrough
100
+ default:
101
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.type} token`);
102
+ atNewline = false;
103
+ hasSpace = false;
104
+ }
105
+ }
106
+ const last = tokens[tokens.length - 1];
107
+ const end = last ? last.offset + last.source.length : offset;
108
+ if (reqSpace &&
109
+ next &&
110
+ next.type !== 'space' &&
111
+ next.type !== 'newline' &&
112
+ next.type !== 'comma' &&
113
+ (next.type !== 'scalar' || next.source !== ''))
114
+ onError(next.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
115
+ return {
116
+ comma,
117
+ found,
118
+ spaceBefore,
119
+ comment,
120
+ hasNewline,
121
+ anchor,
122
+ tag,
123
+ end,
124
+ start: start !== null && start !== void 0 ? start : end
125
+ };
126
+ }
127
+
128
+ export { resolveProps };
@@ -0,0 +1,34 @@
1
+ function containsNewline(key) {
2
+ if (!key)
3
+ return null;
4
+ switch (key.type) {
5
+ case 'alias':
6
+ case 'scalar':
7
+ case 'double-quoted-scalar':
8
+ case 'single-quoted-scalar':
9
+ if (key.source.includes('\n'))
10
+ return true;
11
+ if (key.end)
12
+ for (const st of key.end)
13
+ if (st.type === 'newline')
14
+ return true;
15
+ return false;
16
+ case 'flow-collection':
17
+ for (const it of key.items) {
18
+ for (const st of it.start)
19
+ if (st.type === 'newline')
20
+ return true;
21
+ if (it.sep)
22
+ for (const st of it.sep)
23
+ if (st.type === 'newline')
24
+ return true;
25
+ if (containsNewline(it.key) || containsNewline(it.value))
26
+ return true;
27
+ }
28
+ return false;
29
+ default:
30
+ return true;
31
+ }
32
+ }
33
+
34
+ export { containsNewline };
@@ -0,0 +1,27 @@
1
+ function emptyScalarPosition(offset, before, pos) {
2
+ if (before) {
3
+ if (pos === null)
4
+ pos = before.length;
5
+ for (let i = pos - 1; i >= 0; --i) {
6
+ let st = before[i];
7
+ switch (st.type) {
8
+ case 'space':
9
+ case 'comment':
10
+ case 'newline':
11
+ offset -= st.source.length;
12
+ continue;
13
+ }
14
+ // Technically, an empty scalar is immediately after the last non-empty
15
+ // node, but it's more useful to place it after any whitespace.
16
+ st = before[++i];
17
+ while ((st === null || st === void 0 ? void 0 : st.type) === 'space') {
18
+ offset += st.source.length;
19
+ st = before[++i];
20
+ }
21
+ break;
22
+ }
23
+ }
24
+ return offset;
25
+ }
26
+
27
+ export { emptyScalarPosition };
@@ -0,0 +1,15 @@
1
+ import { containsNewline } from './util-contains-newline.js';
2
+
3
+ function flowIndentCheck(indent, fc, onError) {
4
+ if ((fc === null || fc === void 0 ? void 0 : fc.type) === 'flow-collection') {
5
+ const end = fc.end[0];
6
+ if (end.indent === indent &&
7
+ (end.source === ']' || end.source === '}') &&
8
+ containsNewline(fc)) {
9
+ const msg = 'Flow end indicator should be more indented than parent';
10
+ onError(end, 'BAD_INDENT', msg, true);
11
+ }
12
+ }
13
+ }
14
+
15
+ export { flowIndentCheck };
@@ -0,0 +1,17 @@
1
+ import { isScalar } from '../nodes/Node.js';
2
+
3
+ function mapIncludes(ctx, items, search) {
4
+ const { uniqueKeys } = ctx.options;
5
+ if (uniqueKeys === false)
6
+ return false;
7
+ const isEqual = typeof uniqueKeys === 'function'
8
+ ? uniqueKeys
9
+ : (a, b) => a === b ||
10
+ (isScalar(a) &&
11
+ isScalar(b) &&
12
+ a.value === b.value &&
13
+ !(a.value === '<<' && ctx.schema.merge));
14
+ return items.some(pair => isEqual(pair.key, search));
15
+ }
16
+
17
+ export { mapIncludes };