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,246 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
- import { Char, Type } from '../constants';
5
- import { YAMLSyntaxError } from '../errors';
6
- import { Alias } from './Alias';
7
- import { BlockValue } from './BlockValue';
8
- import { Collection } from './Collection';
9
- import { CollectionItem } from './CollectionItem';
10
- import { FlowCollection } from './FlowCollection';
11
- import { Node } from './Node';
12
- import { PlainValue } from './PlainValue';
13
- import { QuoteDouble } from './QuoteDouble';
14
- import { QuoteSingle } from './QuoteSingle';
15
- import { Range } from './Range';
16
-
17
- function createNewNode(type, props) {
18
- switch (type) {
19
- case Type.ALIAS:
20
- return new Alias(type, props);
21
-
22
- case Type.BLOCK_FOLDED:
23
- case Type.BLOCK_LITERAL:
24
- return new BlockValue(type, props);
25
-
26
- case Type.FLOW_MAP:
27
- case Type.FLOW_SEQ:
28
- return new FlowCollection(type, props);
29
-
30
- case Type.MAP_KEY:
31
- case Type.MAP_VALUE:
32
- case Type.SEQ_ITEM:
33
- return new CollectionItem(type, props);
34
-
35
- case Type.COMMENT:
36
- case Type.PLAIN:
37
- return new PlainValue(type, props);
38
-
39
- case Type.QUOTE_DOUBLE:
40
- return new QuoteDouble(type, props);
41
-
42
- case Type.QUOTE_SINGLE:
43
- return new QuoteSingle(type, props);
44
-
45
- /* istanbul ignore next */
46
-
47
- default:
48
- return null;
49
- // should never happen
50
- }
51
- }
52
- /**
53
- * @param {boolean} atLineStart - Node starts at beginning of line
54
- * @param {boolean} inFlow - true if currently in a flow context
55
- * @param {boolean} inCollection - true if currently in a collection context
56
- * @param {number} indent - Current level of indentation
57
- * @param {number} lineStart - Start of the current line
58
- * @param {Node} parent - The parent of the node
59
- * @param {string} src - Source of the YAML document
60
- */
61
-
62
-
63
- export var ParseContext = /*#__PURE__*/function () {
64
- _createClass(ParseContext, null, [{
65
- key: "parseType",
66
- value: function parseType(src, offset, inFlow) {
67
- switch (src[offset]) {
68
- case '*':
69
- return Type.ALIAS;
70
-
71
- case '>':
72
- return Type.BLOCK_FOLDED;
73
-
74
- case '|':
75
- return Type.BLOCK_LITERAL;
76
-
77
- case '{':
78
- return Type.FLOW_MAP;
79
-
80
- case '[':
81
- return Type.FLOW_SEQ;
82
-
83
- case '?':
84
- return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_KEY : Type.PLAIN;
85
-
86
- case ':':
87
- return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_VALUE : Type.PLAIN;
88
-
89
- case '-':
90
- return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.SEQ_ITEM : Type.PLAIN;
91
-
92
- case '"':
93
- return Type.QUOTE_DOUBLE;
94
-
95
- case "'":
96
- return Type.QUOTE_SINGLE;
97
-
98
- default:
99
- return Type.PLAIN;
100
- }
101
- }
102
- }]);
103
-
104
- function ParseContext() {
105
- var _this = this;
106
-
107
- var orig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
108
-
109
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
110
- atLineStart = _ref.atLineStart,
111
- inCollection = _ref.inCollection,
112
- inFlow = _ref.inFlow,
113
- indent = _ref.indent,
114
- lineStart = _ref.lineStart,
115
- parent = _ref.parent;
116
-
117
- _classCallCheck(this, ParseContext);
118
-
119
- _defineProperty(this, "parseNode", function (overlay, start) {
120
- if (Node.atDocumentBoundary(_this.src, start)) return null;
121
- var context = new ParseContext(_this, overlay);
122
-
123
- var _context$parseProps = context.parseProps(start),
124
- props = _context$parseProps.props,
125
- type = _context$parseProps.type,
126
- valueStart = _context$parseProps.valueStart;
127
-
128
- var node = createNewNode(type, props);
129
- var offset = node.parse(context, valueStart);
130
- node.range = new Range(start, offset);
131
- /* istanbul ignore if */
132
-
133
- if (offset <= start) {
134
- // This should never happen, but if it does, let's make sure to at least
135
- // step one character forward to avoid a busy loop.
136
- node.error = new Error("Node#parse consumed no characters");
137
- node.error.parseEnd = offset;
138
- node.error.source = node;
139
- node.range.end = start + 1;
140
- }
141
-
142
- if (context.nodeStartsCollection(node)) {
143
- if (!node.error && !context.atLineStart && context.parent.type === Type.DOCUMENT) {
144
- node.error = new YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)');
145
- }
146
-
147
- var collection = new Collection(node);
148
- offset = collection.parse(new ParseContext(context), offset);
149
- collection.range = new Range(start, offset);
150
- return collection;
151
- }
152
-
153
- return node;
154
- });
155
-
156
- this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false;
157
- this.inCollection = inCollection != null ? inCollection : orig.inCollection || false;
158
- this.inFlow = inFlow != null ? inFlow : orig.inFlow || false;
159
- this.indent = indent != null ? indent : orig.indent;
160
- this.lineStart = lineStart != null ? lineStart : orig.lineStart;
161
- this.parent = parent != null ? parent : orig.parent || {};
162
- this.root = orig.root;
163
- this.src = orig.src;
164
- }
165
-
166
- _createClass(ParseContext, [{
167
- key: "nodeStartsCollection",
168
- value: function nodeStartsCollection(node) {
169
- var inCollection = this.inCollection,
170
- inFlow = this.inFlow,
171
- src = this.src;
172
- if (inCollection || inFlow) return false;
173
- if (node instanceof CollectionItem) return true; // check for implicit key
174
-
175
- var offset = node.range.end;
176
- if (src[offset] === '\n' || src[offset - 1] === '\n') return false;
177
- offset = Node.endOfWhiteSpace(src, offset);
178
- return src[offset] === ':';
179
- } // Anchor and tag are before type, which determines the node implementation
180
- // class; hence this intermediate step.
181
-
182
- }, {
183
- key: "parseProps",
184
- value: function parseProps(offset) {
185
- var inFlow = this.inFlow,
186
- parent = this.parent,
187
- src = this.src;
188
- var props = [];
189
- var lineHasProps = false;
190
- offset = Node.endOfWhiteSpace(src, offset);
191
- var ch = src[offset];
192
-
193
- while (ch === Char.ANCHOR || ch === Char.COMMENT || ch === Char.TAG || ch === '\n') {
194
- if (ch === '\n') {
195
- var lineStart = offset + 1;
196
- var inEnd = Node.endOfIndent(src, lineStart);
197
- var indentDiff = inEnd - (lineStart + this.indent);
198
- var noIndicatorAsIndent = parent.type === Type.SEQ_ITEM && parent.context.atLineStart;
199
- if (!Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
200
- this.atLineStart = true;
201
- this.lineStart = lineStart;
202
- lineHasProps = false;
203
- offset = inEnd;
204
- } else if (ch === Char.COMMENT) {
205
- var end = Node.endOfLine(src, offset + 1);
206
- props.push(new Range(offset, end));
207
- offset = end;
208
- } else {
209
- var _end = Node.endOfIdentifier(src, offset + 1);
210
-
211
- if (ch === Char.TAG && src[_end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, _end + 13))) {
212
- // Let's presume we're dealing with a YAML 1.0 domain tag here, rather
213
- // than an empty but 'foo.bar' private-tagged node in a flow collection
214
- // followed without whitespace by a plain string starting with a year
215
- // or date divided by something.
216
- _end = Node.endOfIdentifier(src, _end + 5);
217
- }
218
-
219
- props.push(new Range(offset, _end));
220
- lineHasProps = true;
221
- offset = Node.endOfWhiteSpace(src, _end);
222
- }
223
-
224
- ch = src[offset];
225
- } // '- &a : b' has an anchor on an empty node
226
-
227
-
228
- if (lineHasProps && ch === ':' && Node.atBlank(src, offset + 1, true)) offset -= 1;
229
- var type = ParseContext.parseType(src, offset, inFlow);
230
- return {
231
- props: props,
232
- type: type,
233
- valueStart: offset
234
- };
235
- }
236
- /**
237
- * Parses a node from the source
238
- * @param {ParseContext} overlay
239
- * @param {number} start - Index of first non-whitespace character for the node
240
- * @returns {?Node} - null if at a document boundary
241
- */
242
-
243
- }]);
244
-
245
- return ParseContext;
246
- }();
@@ -1,170 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
-
7
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
-
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
10
-
11
- import { Node } from './Node';
12
- import { Range } from './Range';
13
- export var PlainValue = /*#__PURE__*/function (_Node) {
14
- _inherits(PlainValue, _Node);
15
-
16
- var _super = _createSuper(PlainValue);
17
-
18
- function PlainValue() {
19
- _classCallCheck(this, PlainValue);
20
-
21
- return _super.apply(this, arguments);
22
- }
23
-
24
- _createClass(PlainValue, [{
25
- key: "parseBlockValue",
26
- value: function parseBlockValue(start) {
27
- var _this$context = this.context,
28
- indent = _this$context.indent,
29
- inFlow = _this$context.inFlow,
30
- src = _this$context.src;
31
- var offset = start;
32
- var valueEnd = start;
33
-
34
- for (var ch = src[offset]; ch === '\n'; ch = src[offset]) {
35
- if (Node.atDocumentBoundary(src, offset + 1)) break;
36
- var end = Node.endOfBlockIndent(src, indent, offset + 1);
37
- if (end === null || src[end] === '#') break;
38
-
39
- if (src[end] === '\n') {
40
- offset = end;
41
- } else {
42
- valueEnd = PlainValue.endOfLine(src, end, inFlow);
43
- offset = valueEnd;
44
- }
45
- }
46
-
47
- if (this.valueRange.isEmpty()) this.valueRange.start = start;
48
- this.valueRange.end = valueEnd;
49
- return valueEnd;
50
- }
51
- /**
52
- * Parses a plain value from the source
53
- *
54
- * Accepted forms are:
55
- * ```
56
- * #comment
57
- *
58
- * first line
59
- *
60
- * first line #comment
61
- *
62
- * first line
63
- * block
64
- * lines
65
- *
66
- * #comment
67
- * block
68
- * lines
69
- * ```
70
- * where block lines are empty or have an indent level greater than `indent`.
71
- *
72
- * @param {ParseContext} context
73
- * @param {number} start - Index of first character
74
- * @returns {number} - Index of the character after this scalar, may be `\n`
75
- */
76
-
77
- }, {
78
- key: "parse",
79
- value: function parse(context, start) {
80
- this.context = context;
81
- var inFlow = context.inFlow,
82
- src = context.src;
83
- var offset = start;
84
- var ch = src[offset];
85
-
86
- if (ch && ch !== '#' && ch !== '\n') {
87
- offset = PlainValue.endOfLine(src, start, inFlow);
88
- }
89
-
90
- this.valueRange = new Range(start, offset);
91
- offset = Node.endOfWhiteSpace(src, offset);
92
- offset = this.parseComment(offset);
93
-
94
- if (!this.hasComment || this.valueRange.isEmpty()) {
95
- offset = this.parseBlockValue(offset);
96
- }
97
-
98
- return offset;
99
- }
100
- }, {
101
- key: "strValue",
102
- get: function get() {
103
- if (!this.valueRange || !this.context) return null;
104
- var _this$valueRange = this.valueRange,
105
- start = _this$valueRange.start,
106
- end = _this$valueRange.end;
107
- var src = this.context.src;
108
- var ch = src[end - 1];
109
-
110
- while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) {
111
- ch = src[--end - 1];
112
- }
113
-
114
- ch = src[start];
115
-
116
- while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) {
117
- ch = src[++start];
118
- }
119
-
120
- var str = '';
121
-
122
- for (var i = start; i < end; ++i) {
123
- var _ch = src[i];
124
-
125
- if (_ch === '\n') {
126
- var _Node$foldNewline = Node.foldNewline(src, i, -1),
127
- fold = _Node$foldNewline.fold,
128
- offset = _Node$foldNewline.offset;
129
-
130
- str += fold;
131
- i = offset;
132
- } else if (_ch === ' ' || _ch === '\t') {
133
- // trim trailing whitespace
134
- var wsStart = i;
135
- var next = src[i + 1];
136
-
137
- while (i < end && (next === ' ' || next === '\t')) {
138
- i += 1;
139
- next = src[i + 1];
140
- }
141
-
142
- if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : _ch;
143
- } else {
144
- str += _ch;
145
- }
146
- }
147
-
148
- return str;
149
- }
150
- }], [{
151
- key: "endOfLine",
152
- value: function endOfLine(src, start, inFlow) {
153
- var ch = src[start];
154
- var offset = start;
155
-
156
- while (ch && ch !== '\n') {
157
- if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break;
158
- var next = src[offset + 1];
159
- if (ch === ':' && (!next || next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break;
160
- if ((ch === ' ' || ch === '\t') && next === '#') break;
161
- offset += 1;
162
- ch = next;
163
- }
164
-
165
- return offset;
166
- }
167
- }]);
168
-
169
- return PlainValue;
170
- }(Node);
@@ -1,245 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
-
7
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
-
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
10
-
11
- import { YAMLSemanticError, YAMLSyntaxError } from '../errors';
12
- import { Node } from './Node';
13
- import { Range } from './Range';
14
- export var QuoteDouble = /*#__PURE__*/function (_Node) {
15
- _inherits(QuoteDouble, _Node);
16
-
17
- var _super = _createSuper(QuoteDouble);
18
-
19
- function QuoteDouble() {
20
- _classCallCheck(this, QuoteDouble);
21
-
22
- return _super.apply(this, arguments);
23
- }
24
-
25
- _createClass(QuoteDouble, [{
26
- key: "parseCharCode",
27
- value: function parseCharCode(offset, length, errors) {
28
- var src = this.context.src;
29
- var cc = src.substr(offset, length);
30
- var ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
31
- var code = ok ? parseInt(cc, 16) : NaN;
32
-
33
- if (isNaN(code)) {
34
- errors.push(new YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(offset - 2, length + 2))));
35
- return src.substr(offset - 2, length + 2);
36
- }
37
-
38
- return String.fromCodePoint(code);
39
- }
40
- /**
41
- * Parses a "double quoted" value from the source
42
- *
43
- * @param {ParseContext} context
44
- * @param {number} start - Index of first character
45
- * @returns {number} - Index of the character after this scalar
46
- */
47
-
48
- }, {
49
- key: "parse",
50
- value: function parse(context, start) {
51
- this.context = context;
52
- var src = context.src;
53
- var offset = QuoteDouble.endOfQuote(src, start + 1);
54
- this.valueRange = new Range(start, offset);
55
- offset = Node.endOfWhiteSpace(src, offset);
56
- offset = this.parseComment(offset);
57
- return offset;
58
- }
59
- }, {
60
- key: "strValue",
61
-
62
- /**
63
- * @returns {string | { str: string, errors: YAMLSyntaxError[] }}
64
- */
65
- get: function get() {
66
- if (!this.valueRange || !this.context) return null;
67
- var errors = [];
68
- var _this$valueRange = this.valueRange,
69
- start = _this$valueRange.start,
70
- end = _this$valueRange.end;
71
- var _this$context = this.context,
72
- indent = _this$context.indent,
73
- src = _this$context.src;
74
- if (src[end - 1] !== '"') errors.push(new YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by
75
- // escaped backslashes; also, this should be faster.
76
-
77
- var str = '';
78
-
79
- for (var i = start + 1; i < end - 1; ++i) {
80
- var ch = src[i];
81
-
82
- if (ch === '\n') {
83
- if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
84
-
85
- var _Node$foldNewline = Node.foldNewline(src, i, indent),
86
- fold = _Node$foldNewline.fold,
87
- offset = _Node$foldNewline.offset,
88
- error = _Node$foldNewline.error;
89
-
90
- str += fold;
91
- i = offset;
92
- if (error) errors.push(new YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented'));
93
- } else if (ch === '\\') {
94
- i += 1;
95
-
96
- switch (src[i]) {
97
- case '0':
98
- str += '\0';
99
- break;
100
- // null character
101
-
102
- case 'a':
103
- str += '\x07';
104
- break;
105
- // bell character
106
-
107
- case 'b':
108
- str += '\b';
109
- break;
110
- // backspace
111
-
112
- case 'e':
113
- str += '\x1b';
114
- break;
115
- // escape character
116
-
117
- case 'f':
118
- str += '\f';
119
- break;
120
- // form feed
121
-
122
- case 'n':
123
- str += '\n';
124
- break;
125
- // line feed
126
-
127
- case 'r':
128
- str += '\r';
129
- break;
130
- // carriage return
131
-
132
- case 't':
133
- str += '\t';
134
- break;
135
- // horizontal tab
136
-
137
- case 'v':
138
- str += '\v';
139
- break;
140
- // vertical tab
141
-
142
- case 'N':
143
- str += "\x85";
144
- break;
145
- // Unicode next line
146
-
147
- case '_':
148
- str += "\xA0";
149
- break;
150
- // Unicode non-breaking space
151
-
152
- case 'L':
153
- str += "\u2028";
154
- break;
155
- // Unicode line separator
156
-
157
- case 'P':
158
- str += "\u2029";
159
- break;
160
- // Unicode paragraph separator
161
-
162
- case ' ':
163
- str += ' ';
164
- break;
165
-
166
- case '"':
167
- str += '"';
168
- break;
169
-
170
- case '/':
171
- str += '/';
172
- break;
173
-
174
- case '\\':
175
- str += '\\';
176
- break;
177
-
178
- case '\t':
179
- str += '\t';
180
- break;
181
-
182
- case 'x':
183
- str += this.parseCharCode(i + 1, 2, errors);
184
- i += 2;
185
- break;
186
-
187
- case 'u':
188
- str += this.parseCharCode(i + 1, 4, errors);
189
- i += 4;
190
- break;
191
-
192
- case 'U':
193
- str += this.parseCharCode(i + 1, 8, errors);
194
- i += 8;
195
- break;
196
-
197
- case '\n':
198
- // skip escaped newlines, but still trim the following line
199
- while (src[i + 1] === ' ' || src[i + 1] === '\t') {
200
- i += 1;
201
- }
202
-
203
- break;
204
-
205
- default:
206
- errors.push(new YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(i - 1, 2))));
207
- str += '\\' + src[i];
208
- }
209
- } else if (ch === ' ' || ch === '\t') {
210
- // trim trailing whitespace
211
- var wsStart = i;
212
- var next = src[i + 1];
213
-
214
- while (next === ' ' || next === '\t') {
215
- i += 1;
216
- next = src[i + 1];
217
- }
218
-
219
- if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
220
- } else {
221
- str += ch;
222
- }
223
- }
224
-
225
- return errors.length > 0 ? {
226
- errors: errors,
227
- str: str
228
- } : str;
229
- }
230
- }], [{
231
- key: "endOfQuote",
232
- value: function endOfQuote(src, offset) {
233
- var ch = src[offset];
234
-
235
- while (ch && ch !== '"') {
236
- offset += ch === '\\' ? 2 : 1;
237
- ch = src[offset];
238
- }
239
-
240
- return offset + 1;
241
- }
242
- }]);
243
-
244
- return QuoteDouble;
245
- }(Node);