yaml 1.9.2 → 1.10.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 (160) hide show
  1. package/README.md +4 -4
  2. package/browser/dist/PlainValue-ff5147c6.js +1277 -0
  3. package/browser/dist/Schema-2bf2c74e.js +679 -0
  4. package/browser/dist/index.js +869 -34
  5. package/browser/dist/legacy-exports.js +3 -0
  6. package/browser/dist/parse-cst.js +1904 -0
  7. package/browser/dist/resolveSeq-04825f30.js +2373 -0
  8. package/browser/dist/types.js +4 -0
  9. package/browser/dist/util.js +2 -0
  10. package/browser/dist/warnings-0e4b70d3.js +499 -0
  11. package/browser/index.js +1 -1
  12. package/browser/map.js +2 -4
  13. package/browser/pair.js +2 -4
  14. package/browser/parse-cst.js +1 -1
  15. package/browser/scalar.js +2 -4
  16. package/browser/schema.js +7 -10
  17. package/browser/seq.js +2 -4
  18. package/browser/types/binary.js +7 -5
  19. package/browser/types/omap.js +3 -4
  20. package/browser/types/pairs.js +3 -4
  21. package/browser/types/set.js +3 -4
  22. package/browser/types/timestamp.js +9 -5
  23. package/browser/types.js +1 -13
  24. package/browser/util.js +1 -18
  25. package/dist/Document-2cf6b08c.js +757 -0
  26. package/dist/PlainValue-ec8e588e.js +876 -0
  27. package/dist/Schema-42e9705c.js +522 -0
  28. package/dist/index.js +20 -84
  29. package/dist/legacy-exports.js +16 -0
  30. package/dist/parse-cst.js +1747 -0
  31. package/dist/resolveSeq-4a68b39b.js +2115 -0
  32. package/dist/test-events.js +11 -9
  33. package/dist/types.js +23 -0
  34. package/dist/util.js +19 -0
  35. package/dist/warnings-39684f17.js +416 -0
  36. package/index.d.ts +22 -8
  37. package/map.js +2 -2
  38. package/package.json +22 -39
  39. package/pair.js +2 -2
  40. package/parse-cst.js +1 -1
  41. package/scalar.js +2 -2
  42. package/schema.js +8 -6
  43. package/seq.js +2 -2
  44. package/types/binary.js +3 -2
  45. package/types/omap.js +3 -2
  46. package/types/pairs.js +3 -2
  47. package/types/set.js +3 -2
  48. package/types/timestamp.js +6 -6
  49. package/types.d.ts +113 -99
  50. package/types.js +16 -11
  51. package/types.mjs +15 -19
  52. package/util.js +14 -14
  53. package/util.mjs +13 -20
  54. package/browser/dist/Anchors.js +0 -130
  55. package/browser/dist/Document.js +0 -824
  56. package/browser/dist/addComment.js +0 -8
  57. package/browser/dist/constants.js +0 -26
  58. package/browser/dist/cst/Alias.js +0 -46
  59. package/browser/dist/cst/BlankLine.js +0 -52
  60. package/browser/dist/cst/BlockValue.js +0 -251
  61. package/browser/dist/cst/Collection.js +0 -278
  62. package/browser/dist/cst/CollectionItem.js +0 -140
  63. package/browser/dist/cst/Comment.js +0 -44
  64. package/browser/dist/cst/Directive.js +0 -76
  65. package/browser/dist/cst/Document.js +0 -286
  66. package/browser/dist/cst/FlowCollection.js +0 -220
  67. package/browser/dist/cst/Node.js +0 -386
  68. package/browser/dist/cst/ParseContext.js +0 -246
  69. package/browser/dist/cst/PlainValue.js +0 -170
  70. package/browser/dist/cst/QuoteDouble.js +0 -245
  71. package/browser/dist/cst/QuoteSingle.js +0 -120
  72. package/browser/dist/cst/Range.js +0 -64
  73. package/browser/dist/cst/parse.js +0 -48
  74. package/browser/dist/cst/source-utils.js +0 -168
  75. package/browser/dist/errors.js +0 -127
  76. package/browser/dist/foldFlowLines.js +0 -138
  77. package/browser/dist/listTagNames.js +0 -28
  78. package/browser/dist/schema/Alias.js +0 -135
  79. package/browser/dist/schema/Collection.js +0 -260
  80. package/browser/dist/schema/Map.js +0 -161
  81. package/browser/dist/schema/Merge.js +0 -118
  82. package/browser/dist/schema/Node.js +0 -4
  83. package/browser/dist/schema/Pair.js +0 -194
  84. package/browser/dist/schema/Scalar.js +0 -42
  85. package/browser/dist/schema/Seq.js +0 -116
  86. package/browser/dist/schema/index.js +0 -368
  87. package/browser/dist/schema/parseMap.js +0 -312
  88. package/browser/dist/schema/parseSeq.js +0 -168
  89. package/browser/dist/schema/parseUtils.js +0 -106
  90. package/browser/dist/stringify.js +0 -332
  91. package/browser/dist/tags/core.js +0 -141
  92. package/browser/dist/tags/failsafe/index.js +0 -4
  93. package/browser/dist/tags/failsafe/map.js +0 -53
  94. package/browser/dist/tags/failsafe/seq.js +0 -39
  95. package/browser/dist/tags/failsafe/string.js +0 -28
  96. package/browser/dist/tags/index.js +0 -36
  97. package/browser/dist/tags/json.js +0 -77
  98. package/browser/dist/tags/options.js +0 -26
  99. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  100. package/browser/dist/tags/yaml-1.1/index.js +0 -189
  101. package/browser/dist/tags/yaml-1.1/omap.js +0 -137
  102. package/browser/dist/tags/yaml-1.1/pairs.js +0 -78
  103. package/browser/dist/tags/yaml-1.1/set.js +0 -118
  104. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  105. package/browser/dist/test-events.js +0 -163
  106. package/browser/dist/toJSON.js +0 -19
  107. package/browser/dist/warnings.js +0 -39
  108. package/dist/Anchors.js +0 -120
  109. package/dist/Document.js +0 -714
  110. package/dist/addComment.js +0 -14
  111. package/dist/constants.js +0 -31
  112. package/dist/cst/Alias.js +0 -33
  113. package/dist/cst/BlankLine.js +0 -40
  114. package/dist/cst/BlockValue.js +0 -243
  115. package/dist/cst/Collection.js +0 -266
  116. package/dist/cst/CollectionItem.js +0 -135
  117. package/dist/cst/Comment.js +0 -33
  118. package/dist/cst/Directive.js +0 -59
  119. package/dist/cst/Document.js +0 -276
  120. package/dist/cst/FlowCollection.js +0 -213
  121. package/dist/cst/Node.js +0 -360
  122. package/dist/cst/ParseContext.js +0 -253
  123. package/dist/cst/PlainValue.js +0 -156
  124. package/dist/cst/QuoteDouble.js +0 -232
  125. package/dist/cst/QuoteSingle.js +0 -108
  126. package/dist/cst/Range.js +0 -60
  127. package/dist/cst/parse.js +0 -50
  128. package/dist/cst/source-utils.js +0 -175
  129. package/dist/errors.js +0 -97
  130. package/dist/foldFlowLines.js +0 -143
  131. package/dist/listTagNames.js +0 -33
  132. package/dist/schema/Alias.js +0 -105
  133. package/dist/schema/Collection.js +0 -184
  134. package/dist/schema/Map.js +0 -98
  135. package/dist/schema/Merge.js +0 -75
  136. package/dist/schema/Node.js +0 -7
  137. package/dist/schema/Pair.js +0 -174
  138. package/dist/schema/Scalar.js +0 -26
  139. package/dist/schema/Seq.js +0 -73
  140. package/dist/schema/index.js +0 -310
  141. package/dist/schema/parseMap.js +0 -334
  142. package/dist/schema/parseSeq.js +0 -175
  143. package/dist/schema/parseUtils.js +0 -101
  144. package/dist/stringify.js +0 -352
  145. package/dist/tags/core.js +0 -121
  146. package/dist/tags/failsafe/index.js +0 -12
  147. package/dist/tags/failsafe/map.js +0 -32
  148. package/dist/tags/failsafe/seq.js +0 -29
  149. package/dist/tags/failsafe/string.js +0 -37
  150. package/dist/tags/index.js +0 -53
  151. package/dist/tags/json.js +0 -64
  152. package/dist/tags/options.js +0 -36
  153. package/dist/tags/yaml-1.1/binary.js +0 -94
  154. package/dist/tags/yaml-1.1/index.js +0 -162
  155. package/dist/tags/yaml-1.1/omap.js +0 -100
  156. package/dist/tags/yaml-1.1/pairs.js +0 -75
  157. package/dist/tags/yaml-1.1/set.js +0 -82
  158. package/dist/tags/yaml-1.1/timestamp.js +0 -90
  159. package/dist/toJSON.js +0 -21
  160. package/dist/warnings.js +0 -48
@@ -1,175 +0,0 @@
1
- "use strict";
2
-
3
- exports.getLinePos = getLinePos;
4
- exports.getLine = getLine;
5
- exports.getPrettyContext = getPrettyContext;
6
-
7
- function findLineStarts(src) {
8
- const ls = [0];
9
- let offset = src.indexOf('\n');
10
-
11
- while (offset !== -1) {
12
- offset += 1;
13
- ls.push(offset);
14
- offset = src.indexOf('\n', offset);
15
- }
16
-
17
- return ls;
18
- }
19
-
20
- function getSrcInfo(cst) {
21
- let lineStarts, src;
22
-
23
- if (typeof cst === 'string') {
24
- lineStarts = findLineStarts(cst);
25
- src = cst;
26
- } else {
27
- if (Array.isArray(cst)) cst = cst[0];
28
-
29
- if (cst && cst.context) {
30
- if (!cst.lineStarts) cst.lineStarts = findLineStarts(cst.context.src);
31
- lineStarts = cst.lineStarts;
32
- src = cst.context.src;
33
- }
34
- }
35
-
36
- return {
37
- lineStarts,
38
- src
39
- };
40
- }
41
- /**
42
- * @typedef {Object} LinePos - One-indexed position in the source
43
- * @property {number} line
44
- * @property {number} col
45
- */
46
-
47
- /**
48
- * Determine the line/col position matching a character offset.
49
- *
50
- * Accepts a source string or a CST document as the second parameter. With
51
- * the latter, starting indices for lines are cached in the document as
52
- * `lineStarts: number[]`.
53
- *
54
- * Returns a one-indexed `{ line, col }` location if found, or
55
- * `undefined` otherwise.
56
- *
57
- * @param {number} offset
58
- * @param {string|Document|Document[]} cst
59
- * @returns {?LinePos}
60
- */
61
-
62
-
63
- function getLinePos(offset, cst) {
64
- if (typeof offset !== 'number' || offset < 0) return null;
65
- const {
66
- lineStarts,
67
- src
68
- } = getSrcInfo(cst);
69
- if (!lineStarts || !src || offset > src.length) return null;
70
-
71
- for (let i = 0; i < lineStarts.length; ++i) {
72
- const start = lineStarts[i];
73
-
74
- if (offset < start) {
75
- return {
76
- line: i,
77
- col: offset - lineStarts[i - 1] + 1
78
- };
79
- }
80
-
81
- if (offset === start) return {
82
- line: i + 1,
83
- col: 1
84
- };
85
- }
86
-
87
- const line = lineStarts.length;
88
- return {
89
- line,
90
- col: offset - lineStarts[line - 1] + 1
91
- };
92
- }
93
- /**
94
- * Get a specified line from the source.
95
- *
96
- * Accepts a source string or a CST document as the second parameter. With
97
- * the latter, starting indices for lines are cached in the document as
98
- * `lineStarts: number[]`.
99
- *
100
- * Returns the line as a string if found, or `null` otherwise.
101
- *
102
- * @param {number} line One-indexed line number
103
- * @param {string|Document|Document[]} cst
104
- * @returns {?string}
105
- */
106
-
107
-
108
- function getLine(line, cst) {
109
- const {
110
- lineStarts,
111
- src
112
- } = getSrcInfo(cst);
113
- if (!lineStarts || !(line >= 1) || line > lineStarts.length) return null;
114
- const start = lineStarts[line - 1];
115
- let end = lineStarts[line]; // undefined for last line; that's ok for slice()
116
-
117
- while (end && end > start && src[end - 1] === '\n') --end;
118
-
119
- return src.slice(start, end);
120
- }
121
- /**
122
- * Pretty-print the starting line from the source indicated by the range `pos`
123
- *
124
- * Trims output to `maxWidth` chars while keeping the starting column visible,
125
- * using `…` at either end to indicate dropped characters.
126
- *
127
- * Returns a two-line string (or `null`) with `\n` as separator; the second line
128
- * will hold appropriately indented `^` marks indicating the column range.
129
- *
130
- * @param {Object} pos
131
- * @param {LinePos} pos.start
132
- * @param {LinePos} [pos.end]
133
- * @param {string|Document|Document[]*} cst
134
- * @param {number} [maxWidth=80]
135
- * @returns {?string}
136
- */
137
-
138
-
139
- function getPrettyContext({
140
- start,
141
- end
142
- }, cst, maxWidth = 80) {
143
- let src = getLine(start.line, cst);
144
- if (!src) return null;
145
- let {
146
- col
147
- } = start;
148
-
149
- if (src.length > maxWidth) {
150
- if (col <= maxWidth - 10) {
151
- src = src.substr(0, maxWidth - 1) + '…';
152
- } else {
153
- const halfWidth = Math.round(maxWidth / 2);
154
- if (src.length > col + halfWidth) src = src.substr(0, col + halfWidth - 1) + '…';
155
- col -= src.length - maxWidth;
156
- src = '…' + src.substr(1 - maxWidth);
157
- }
158
- }
159
-
160
- let errLen = 1;
161
- let errEnd = '';
162
-
163
- if (end) {
164
- if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) {
165
- errLen = end.col - start.col;
166
- } else {
167
- errLen = Math.min(src.length + 1, maxWidth) - col;
168
- errEnd = '…';
169
- }
170
- }
171
-
172
- const offset = col > 1 ? ' '.repeat(col - 1) : '';
173
- const err = '^'.repeat(errLen);
174
- return `${src}\n${offset}${err}${errEnd}`;
175
- }
package/dist/errors.js DELETED
@@ -1,97 +0,0 @@
1
- "use strict";
2
-
3
- exports.YAMLWarning = exports.YAMLSyntaxError = exports.YAMLSemanticError = exports.YAMLReferenceError = exports.YAMLError = void 0;
4
-
5
- var _Node = require("./cst/Node");
6
-
7
- var _sourceUtils = require("./cst/source-utils");
8
-
9
- var _Range = require("./cst/Range");
10
-
11
- class YAMLError extends Error {
12
- constructor(name, source, message) {
13
- if (!message || !(source instanceof _Node.Node)) throw new Error(`Invalid arguments for new ${name}`);
14
- super();
15
- this.name = name;
16
- this.message = message;
17
- this.source = source;
18
- }
19
-
20
- makePretty() {
21
- if (!this.source) return;
22
- this.nodeType = this.source.type;
23
- const cst = this.source.context && this.source.context.root;
24
-
25
- if (typeof this.offset === 'number') {
26
- this.range = new _Range.Range(this.offset, this.offset + 1);
27
- const start = cst && (0, _sourceUtils.getLinePos)(this.offset, cst);
28
-
29
- if (start) {
30
- const end = {
31
- line: start.line,
32
- col: start.col + 1
33
- };
34
- this.linePos = {
35
- start,
36
- end
37
- };
38
- }
39
-
40
- delete this.offset;
41
- } else {
42
- this.range = this.source.range;
43
- this.linePos = this.source.rangeAsLinePos;
44
- }
45
-
46
- if (this.linePos) {
47
- const {
48
- line,
49
- col
50
- } = this.linePos.start;
51
- this.message += ` at line ${line}, column ${col}`;
52
- const ctx = cst && (0, _sourceUtils.getPrettyContext)(this.linePos, cst);
53
- if (ctx) this.message += `:\n\n${ctx}\n`;
54
- }
55
-
56
- delete this.source;
57
- }
58
-
59
- }
60
-
61
- exports.YAMLError = YAMLError;
62
-
63
- class YAMLReferenceError extends YAMLError {
64
- constructor(source, message) {
65
- super('YAMLReferenceError', source, message);
66
- }
67
-
68
- }
69
-
70
- exports.YAMLReferenceError = YAMLReferenceError;
71
-
72
- class YAMLSemanticError extends YAMLError {
73
- constructor(source, message) {
74
- super('YAMLSemanticError', source, message);
75
- }
76
-
77
- }
78
-
79
- exports.YAMLSemanticError = YAMLSemanticError;
80
-
81
- class YAMLSyntaxError extends YAMLError {
82
- constructor(source, message) {
83
- super('YAMLSyntaxError', source, message);
84
- }
85
-
86
- }
87
-
88
- exports.YAMLSyntaxError = YAMLSyntaxError;
89
-
90
- class YAMLWarning extends YAMLError {
91
- constructor(source, message) {
92
- super('YAMLWarning', source, message);
93
- }
94
-
95
- }
96
-
97
- exports.YAMLWarning = YAMLWarning;
@@ -1,143 +0,0 @@
1
- "use strict";
2
-
3
- exports.foldFlowLines = foldFlowLines;
4
- exports.FOLD_QUOTED = exports.FOLD_BLOCK = exports.FOLD_FLOW = void 0;
5
- const FOLD_FLOW = 'flow';
6
- exports.FOLD_FLOW = FOLD_FLOW;
7
- const FOLD_BLOCK = 'block';
8
- exports.FOLD_BLOCK = FOLD_BLOCK;
9
- const FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line
10
- // returns index of last newline in more-indented block
11
-
12
- exports.FOLD_QUOTED = FOLD_QUOTED;
13
-
14
- const consumeMoreIndentedLines = (text, i) => {
15
- let ch = text[i + 1];
16
-
17
- while (ch === ' ' || ch === '\t') {
18
- do {
19
- ch = text[i += 1];
20
- } while (ch && ch !== '\n');
21
-
22
- ch = text[i + 1];
23
- }
24
-
25
- return i;
26
- };
27
- /**
28
- * Tries to keep input at up to `lineWidth` characters, splitting only on spaces
29
- * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
30
- * terminated with `\n` and started with `indent`.
31
- *
32
- * @param {string} text
33
- * @param {string} indent
34
- * @param {string} [mode='flow'] `'block'` prevents more-indented lines
35
- * from being folded; `'quoted'` allows for `\` escapes, including escaped
36
- * newlines
37
- * @param {Object} options
38
- * @param {number} [options.indentAtStart] Accounts for leading contents on
39
- * the first line, defaulting to `indent.length`
40
- * @param {number} [options.lineWidth=80]
41
- * @param {number} [options.minContentWidth=20] Allow highly indented lines to
42
- * stretch the line width
43
- * @param {function} options.onFold Called once if the text is folded
44
- * @param {function} options.onFold Called once if any line of text exceeds
45
- * lineWidth characters
46
- */
47
-
48
-
49
- function foldFlowLines(text, indent, mode, {
50
- indentAtStart,
51
- lineWidth = 80,
52
- minContentWidth = 20,
53
- onFold,
54
- onOverflow
55
- }) {
56
- if (!lineWidth || lineWidth < 0) return text;
57
- const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
58
- if (text.length <= endStep) return text;
59
- const folds = [];
60
- const escapedFolds = {};
61
- let end = lineWidth - (typeof indentAtStart === 'number' ? indentAtStart : indent.length);
62
- let split = undefined;
63
- let prev = undefined;
64
- let overflow = false;
65
- let i = -1;
66
-
67
- if (mode === FOLD_BLOCK) {
68
- i = consumeMoreIndentedLines(text, i);
69
- if (i !== -1) end = i + endStep;
70
- }
71
-
72
- for (let ch; ch = text[i += 1];) {
73
- if (mode === FOLD_QUOTED && ch === '\\') {
74
- switch (text[i + 1]) {
75
- case 'x':
76
- i += 3;
77
- break;
78
-
79
- case 'u':
80
- i += 5;
81
- break;
82
-
83
- case 'U':
84
- i += 9;
85
- break;
86
-
87
- default:
88
- i += 1;
89
- }
90
- }
91
-
92
- if (ch === '\n') {
93
- if (mode === FOLD_BLOCK) i = consumeMoreIndentedLines(text, i);
94
- end = i + endStep;
95
- split = undefined;
96
- } else {
97
- if (ch === ' ' && prev && prev !== ' ' && prev !== '\n' && prev !== '\t') {
98
- // space surrounded by non-space can be replaced with newline + indent
99
- const next = text[i + 1];
100
- if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i;
101
- }
102
-
103
- if (i >= end) {
104
- if (split) {
105
- folds.push(split);
106
- end = split + endStep;
107
- split = undefined;
108
- } else if (mode === FOLD_QUOTED) {
109
- // white-space collected at end may stretch past lineWidth
110
- while (prev === ' ' || prev === '\t') {
111
- prev = ch;
112
- ch = text[i += 1];
113
- overflow = true;
114
- } // i - 2 accounts for not-dropped last char + newline-escaping \
115
-
116
-
117
- folds.push(i - 2);
118
- escapedFolds[i - 2] = true;
119
- end = i - 2 + endStep;
120
- split = undefined;
121
- } else {
122
- overflow = true;
123
- }
124
- }
125
- }
126
-
127
- prev = ch;
128
- }
129
-
130
- if (overflow && onOverflow) onOverflow();
131
- if (folds.length === 0) return text;
132
- if (onFold) onFold();
133
- let res = text.slice(0, folds[0]);
134
-
135
- for (let i = 0; i < folds.length; ++i) {
136
- const fold = folds[i];
137
- const end = folds[i + 1] || text.length;
138
- if (mode === FOLD_QUOTED && escapedFolds[fold]) res += `${text[fold]}\\`;
139
- res += `\n${indent}${text.slice(fold + 1, end)}`;
140
- }
141
-
142
- return res;
143
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- exports.listTagNames = void 0;
4
-
5
- var _Collection = require("./schema/Collection");
6
-
7
- var _Pair = require("./schema/Pair");
8
-
9
- var _Scalar = require("./schema/Scalar");
10
-
11
- const visit = (node, tags) => {
12
- if (node && typeof node === 'object') {
13
- const {
14
- tag
15
- } = node;
16
-
17
- if (node instanceof _Collection.Collection) {
18
- if (tag) tags[tag] = true;
19
- node.items.forEach(n => visit(n, tags));
20
- } else if (node instanceof _Pair.Pair) {
21
- visit(node.key, tags);
22
- visit(node.value, tags);
23
- } else if (node instanceof _Scalar.Scalar) {
24
- if (tag) tags[tag] = true;
25
- }
26
- }
27
-
28
- return tags;
29
- };
30
-
31
- const listTagNames = node => Object.keys(visit(node, {}));
32
-
33
- exports.listTagNames = listTagNames;
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- exports.Alias = void 0;
4
-
5
- var _constants = require("../constants");
6
-
7
- var _errors = require("../errors");
8
-
9
- var _toJSON = require("../toJSON");
10
-
11
- var _Collection = require("./Collection");
12
-
13
- var _Node = require("./Node");
14
-
15
- var _Pair = require("./Pair");
16
-
17
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
-
19
- const getAliasCount = (node, anchors) => {
20
- if (node instanceof Alias) {
21
- const anchor = anchors.get(node.source);
22
- return anchor.count * anchor.aliasCount;
23
- } else if (node instanceof _Collection.Collection) {
24
- let count = 0;
25
-
26
- for (const item of node.items) {
27
- const c = getAliasCount(item, anchors);
28
- if (c > count) count = c;
29
- }
30
-
31
- return count;
32
- } else if (node instanceof _Pair.Pair) {
33
- const kc = getAliasCount(node.key, anchors);
34
- const vc = getAliasCount(node.value, anchors);
35
- return Math.max(kc, vc);
36
- }
37
-
38
- return 1;
39
- };
40
-
41
- class Alias extends _Node.Node {
42
- static stringify({
43
- range,
44
- source
45
- }, {
46
- anchors,
47
- doc,
48
- implicitKey,
49
- inStringifyKey
50
- }) {
51
- let anchor = Object.keys(anchors).find(a => anchors[a] === source);
52
- if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
53
- if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`;
54
- const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
55
- throw new Error(`${msg} [${range}]`);
56
- }
57
-
58
- constructor(source) {
59
- super();
60
- this.source = source;
61
- this.type = _constants.Type.ALIAS;
62
- }
63
-
64
- set tag(t) {
65
- throw new Error('Alias nodes cannot have tags');
66
- }
67
-
68
- toJSON(arg, ctx) {
69
- if (!ctx) return (0, _toJSON.toJSON)(this.source, arg, ctx);
70
- const {
71
- anchors,
72
- maxAliasCount
73
- } = ctx;
74
- const anchor = anchors.get(this.source);
75
- /* istanbul ignore if */
76
-
77
- if (!anchor || anchor.res === undefined) {
78
- const msg = 'This should not happen: Alias anchor was not resolved?';
79
- if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
80
- }
81
-
82
- if (maxAliasCount >= 0) {
83
- anchor.count += 1;
84
- if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
85
-
86
- if (anchor.count * anchor.aliasCount > maxAliasCount) {
87
- const msg = 'Excessive alias count indicates a resource exhaustion attack';
88
- if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
89
- }
90
- }
91
-
92
- return anchor.res;
93
- } // Only called when stringifying an alias mapping key while constructing
94
- // Object output.
95
-
96
-
97
- toString(ctx) {
98
- return Alias.stringify(this, ctx);
99
- }
100
-
101
- }
102
-
103
- exports.Alias = Alias;
104
-
105
- _defineProperty(Alias, "default", true);