yaml 1.5.0 → 1.5.1

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.
@@ -144,9 +144,7 @@ function () {
144
144
  }
145
145
  }, {
146
146
  key: "parse",
147
- value: function parse(node) {
148
- var _this = this;
149
-
147
+ value: function parse(node, prevDoc) {
150
148
  if (this.options.keepCstNodes) this.cstNode = node;
151
149
  if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
152
150
  var _node$directives = node.directives,
@@ -161,7 +159,72 @@ function () {
161
159
  this.errors.push(error);
162
160
  }
163
161
 
162
+ this.parseDirectives(directives, prevDoc);
163
+ this.range = valueRange ? [valueRange.start, valueRange.end] : null;
164
+ this.setSchema();
165
+ this.anchors._cstAliases = [];
166
+ this.parseContents(contents);
167
+ this.anchors.resolveNodes();
168
+
169
+ if (this.options.prettyErrors) {
170
+ var _iteratorNormalCompletion = true;
171
+ var _didIteratorError = false;
172
+ var _iteratorError = undefined;
173
+
174
+ try {
175
+ for (var _iterator = this.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
176
+ var _error = _step.value;
177
+ if (_error instanceof _errors.YAMLError) _error.makePretty();
178
+ }
179
+ } catch (err) {
180
+ _didIteratorError = true;
181
+ _iteratorError = err;
182
+ } finally {
183
+ try {
184
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
185
+ _iterator.return();
186
+ }
187
+ } finally {
188
+ if (_didIteratorError) {
189
+ throw _iteratorError;
190
+ }
191
+ }
192
+ }
193
+
194
+ var _iteratorNormalCompletion2 = true;
195
+ var _didIteratorError2 = false;
196
+ var _iteratorError2 = undefined;
197
+
198
+ try {
199
+ for (var _iterator2 = this.warnings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
200
+ var warn = _step2.value;
201
+ if (warn instanceof _errors.YAMLError) warn.makePretty();
202
+ }
203
+ } catch (err) {
204
+ _didIteratorError2 = true;
205
+ _iteratorError2 = err;
206
+ } finally {
207
+ try {
208
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
209
+ _iterator2.return();
210
+ }
211
+ } finally {
212
+ if (_didIteratorError2) {
213
+ throw _iteratorError2;
214
+ }
215
+ }
216
+ }
217
+ }
218
+
219
+ return this;
220
+ }
221
+ }, {
222
+ key: "parseDirectives",
223
+ value: function parseDirectives(directives, prevDoc) {
224
+ var _this = this;
225
+
164
226
  var directiveComments = [];
227
+ var hasDirectives = false;
165
228
  directives.forEach(function (directive) {
166
229
  var comment = directive.comment,
167
230
  name = directive.name;
@@ -170,12 +233,14 @@ function () {
170
233
  case 'TAG':
171
234
  _this.resolveTagDirective(directive);
172
235
 
236
+ hasDirectives = true;
173
237
  break;
174
238
 
175
239
  case 'YAML':
176
240
  case 'YAML:1.0':
177
241
  _this.resolveYamlDirective(directive);
178
242
 
243
+ hasDirectives = true;
179
244
  break;
180
245
 
181
246
  default:
@@ -189,10 +254,28 @@ function () {
189
254
 
190
255
  if (comment) directiveComments.push(comment);
191
256
  });
192
- this.range = valueRange ? [valueRange.start, valueRange.end] : null;
193
- this.setSchema();
194
- this.anchors._cstAliases = [];
257
+
258
+ if (prevDoc && !hasDirectives && '1.1' === (this.version || prevDoc.version || this.options.version)) {
259
+ var copyTagPrefix = function copyTagPrefix(_ref) {
260
+ var handle = _ref.handle,
261
+ prefix = _ref.prefix;
262
+ return {
263
+ handle: handle,
264
+ prefix: prefix
265
+ };
266
+ };
267
+
268
+ this.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
269
+ this.version = prevDoc.version;
270
+ }
271
+
195
272
  this.commentBefore = directiveComments.join('\n') || null;
273
+ }
274
+ }, {
275
+ key: "parseContents",
276
+ value: function parseContents(contents) {
277
+ var _this2 = this;
278
+
196
279
  var comments = {
197
280
  before: [],
198
281
  after: []
@@ -204,10 +287,10 @@ function () {
204
287
  if (contentNodes.length === 1) {
205
288
  var msg = 'Document is not valid YAML (bad indentation?)';
206
289
 
207
- _this.errors.push(new _errors.YAMLSyntaxError(node, msg));
290
+ _this2.errors.push(new _errors.YAMLSyntaxError(node, msg));
208
291
  }
209
292
 
210
- var res = _this.resolveNode(node);
293
+ var res = _this2.resolveNode(node);
211
294
 
212
295
  if (spaceBefore) {
213
296
  res.spaceBefore = true;
@@ -221,9 +304,9 @@ function () {
221
304
  } else if (node.type === _constants.Type.BLANK_LINE) {
222
305
  spaceBefore = true;
223
306
 
224
- if (contentNodes.length === 0 && comments.before.length > 0 && !_this.commentBefore) {
307
+ if (contentNodes.length === 0 && comments.before.length > 0 && !_this2.commentBefore) {
225
308
  // space-separated comments at start are parsed as document comments
226
- _this.commentBefore = comments.before.join('\n');
309
+ _this2.commentBefore = comments.before.join('\n');
227
310
  comments.before = [];
228
311
  }
229
312
  }
@@ -263,59 +346,6 @@ function () {
263
346
  }
264
347
 
265
348
  this.comment = comments.after.join('\n') || null;
266
- this.anchors.resolveNodes();
267
-
268
- if (this.options.prettyErrors) {
269
- var _iteratorNormalCompletion = true;
270
- var _didIteratorError = false;
271
- var _iteratorError = undefined;
272
-
273
- try {
274
- for (var _iterator = this.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
275
- var _error = _step.value;
276
- if (_error instanceof _errors.YAMLError) _error.makePretty();
277
- }
278
- } catch (err) {
279
- _didIteratorError = true;
280
- _iteratorError = err;
281
- } finally {
282
- try {
283
- if (!_iteratorNormalCompletion && _iterator.return != null) {
284
- _iterator.return();
285
- }
286
- } finally {
287
- if (_didIteratorError) {
288
- throw _iteratorError;
289
- }
290
- }
291
- }
292
-
293
- var _iteratorNormalCompletion2 = true;
294
- var _didIteratorError2 = false;
295
- var _iteratorError2 = undefined;
296
-
297
- try {
298
- for (var _iterator2 = this.warnings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
299
- var warn = _step2.value;
300
- if (warn instanceof _errors.YAMLError) warn.makePretty();
301
- }
302
- } catch (err) {
303
- _didIteratorError2 = true;
304
- _iteratorError2 = err;
305
- } finally {
306
- try {
307
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
308
- _iterator2.return();
309
- }
310
- } finally {
311
- if (_didIteratorError2) {
312
- throw _iteratorError2;
313
- }
314
- }
315
- }
316
- }
317
-
318
- return this;
319
349
  }
320
350
  }, {
321
351
  key: "resolveTagDirective",
@@ -659,7 +689,7 @@ function () {
659
689
  }, {
660
690
  key: "toJSON",
661
691
  value: function toJSON(arg) {
662
- var _this2 = this;
692
+ var _this3 = this;
663
693
 
664
694
  var _this$options = this.options,
665
695
  keepBlobsInJSON = _this$options.keepBlobsInJSON,
@@ -678,7 +708,7 @@ function () {
678
708
  alias: [],
679
709
  aliasCount: 0,
680
710
  count: 1,
681
- node: _this2.anchors.map[name]
711
+ node: _this3.anchors.map[name]
682
712
  };
683
713
  });
684
714
  return (0, _toJSON2.default)(this.contents, arg, ctx);
@@ -704,9 +734,9 @@ function () {
704
734
  }
705
735
 
706
736
  var tagNames = this.listNonDefaultTags();
707
- this.tagPrefixes.forEach(function (_ref) {
708
- var handle = _ref.handle,
709
- prefix = _ref.prefix;
737
+ this.tagPrefixes.forEach(function (_ref2) {
738
+ var handle = _ref2.handle,
739
+ prefix = _ref2.prefix;
710
740
 
711
741
  if (tagNames.some(function (t) {
712
742
  return t.indexOf(prefix) === 0;
@@ -65,9 +65,36 @@ function (_YAMLDocument) {
65
65
  }(_Document.default);
66
66
 
67
67
  function parseAllDocuments(src, options) {
68
- return (0, _parse.default)(src).map(function (cstDoc) {
69
- return new Document(options).parse(cstDoc);
70
- });
68
+ var stream = [];
69
+ var prev;
70
+ var _iteratorNormalCompletion = true;
71
+ var _didIteratorError = false;
72
+ var _iteratorError = undefined;
73
+
74
+ try {
75
+ for (var _iterator = (0, _parse.default)(src)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
76
+ var cstDoc = _step.value;
77
+ var doc = new Document(options);
78
+ doc.parse(cstDoc, prev);
79
+ stream.push(doc);
80
+ prev = doc;
81
+ }
82
+ } catch (err) {
83
+ _didIteratorError = true;
84
+ _iteratorError = err;
85
+ } finally {
86
+ try {
87
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
88
+ _iterator.return();
89
+ }
90
+ } finally {
91
+ if (_didIteratorError) {
92
+ throw _iteratorError;
93
+ }
94
+ }
95
+ }
96
+
97
+ return stream;
71
98
  }
72
99
 
73
100
  function parseDocument(src, options) {
package/browser/util.js CHANGED
@@ -6,7 +6,7 @@ var str = require('./dist/stringify')
6
6
  exports.stringifyNumber = str.stringifyNumber
7
7
  exports.stringifyString = str.stringifyString
8
8
  exports.toJSON = require('./dist/toJSON').default
9
- exports.Type = require('./dist/cst/Node').Type
9
+ exports.Type = require('./dist/constants').Type
10
10
 
11
11
  var err = require('./dist/errors')
12
12
  exports.YAMLReferenceError = err.YAMLReferenceError
package/dist/Document.js CHANGED
@@ -118,7 +118,7 @@ class Document {
118
118
  if (!this.schema) this.schema = new _schema.default(Object.assign({}, this.getDefaults(), this.options));
119
119
  }
120
120
 
121
- parse(node) {
121
+ parse(node, prevDoc) {
122
122
  if (this.options.keepCstNodes) this.cstNode = node;
123
123
  if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
124
124
  const {
@@ -133,7 +133,25 @@ class Document {
133
133
  this.errors.push(error);
134
134
  }
135
135
 
136
+ this.parseDirectives(directives, prevDoc);
137
+ this.range = valueRange ? [valueRange.start, valueRange.end] : null;
138
+ this.setSchema();
139
+ this.anchors._cstAliases = [];
140
+ this.parseContents(contents);
141
+ this.anchors.resolveNodes();
142
+
143
+ if (this.options.prettyErrors) {
144
+ for (const error of this.errors) if (error instanceof _errors.YAMLError) error.makePretty();
145
+
146
+ for (const warn of this.warnings) if (warn instanceof _errors.YAMLError) warn.makePretty();
147
+ }
148
+
149
+ return this;
150
+ }
151
+
152
+ parseDirectives(directives, prevDoc) {
136
153
  const directiveComments = [];
154
+ let hasDirectives = false;
137
155
  directives.forEach(directive => {
138
156
  const {
139
157
  comment,
@@ -143,11 +161,13 @@ class Document {
143
161
  switch (name) {
144
162
  case 'TAG':
145
163
  this.resolveTagDirective(directive);
164
+ hasDirectives = true;
146
165
  break;
147
166
 
148
167
  case 'YAML':
149
168
  case 'YAML:1.0':
150
169
  this.resolveYamlDirective(directive);
170
+ hasDirectives = true;
151
171
  break;
152
172
 
153
173
  default:
@@ -160,10 +180,24 @@ class Document {
160
180
 
161
181
  if (comment) directiveComments.push(comment);
162
182
  });
163
- this.range = valueRange ? [valueRange.start, valueRange.end] : null;
164
- this.setSchema();
165
- this.anchors._cstAliases = [];
183
+
184
+ if (prevDoc && !hasDirectives && '1.1' === (this.version || prevDoc.version || this.options.version)) {
185
+ const copyTagPrefix = ({
186
+ handle,
187
+ prefix
188
+ }) => ({
189
+ handle,
190
+ prefix
191
+ });
192
+
193
+ this.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
194
+ this.version = prevDoc.version;
195
+ }
196
+
166
197
  this.commentBefore = directiveComments.join('\n') || null;
198
+ }
199
+
200
+ parseContents(contents) {
167
201
  const comments = {
168
202
  before: [],
169
203
  after: []
@@ -233,15 +267,6 @@ class Document {
233
267
  }
234
268
 
235
269
  this.comment = comments.after.join('\n') || null;
236
- this.anchors.resolveNodes();
237
-
238
- if (this.options.prettyErrors) {
239
- for (const error of this.errors) if (error instanceof _errors.YAMLError) error.makePretty();
240
-
241
- for (const warn of this.warnings) if (warn instanceof _errors.YAMLError) warn.makePretty();
242
- }
243
-
244
- return this;
245
270
  }
246
271
 
247
272
  resolveTagDirective(directive) {
package/dist/index.js CHANGED
@@ -48,7 +48,17 @@ class Document extends _Document.default {
48
48
  }
49
49
 
50
50
  function parseAllDocuments(src, options) {
51
- return (0, _parse.default)(src).map(cstDoc => new Document(options).parse(cstDoc));
51
+ const stream = [];
52
+ let prev;
53
+
54
+ for (const cstDoc of (0, _parse.default)(src)) {
55
+ const doc = new Document(options);
56
+ doc.parse(cstDoc, prev);
57
+ stream.push(doc);
58
+ prev = doc;
59
+ }
60
+
61
+ return stream;
52
62
  }
53
63
 
54
64
  function parseDocument(src, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
6
  "repository": "github:eemeli/yaml",
@@ -66,24 +66,24 @@
66
66
  "singleQuote": true
67
67
  },
68
68
  "devDependencies": {
69
- "@babel/cli": "^7.4.3",
70
- "@babel/core": "^7.4.3",
71
- "@babel/plugin-proposal-class-properties": "^7.4.0",
72
- "@babel/plugin-transform-runtime": "^7.4.3",
73
- "@babel/preset-env": "^7.4.3",
69
+ "@babel/cli": "^7.4.4",
70
+ "@babel/core": "^7.4.4",
71
+ "@babel/plugin-proposal-class-properties": "^7.4.4",
72
+ "@babel/plugin-transform-runtime": "^7.4.4",
73
+ "@babel/preset-env": "^7.4.4",
74
74
  "babel-eslint": "^10.0.1",
75
- "babel-jest": "^24.7.1",
75
+ "babel-jest": "^24.8.0",
76
76
  "babel-plugin-trace": "^1.1.0",
77
77
  "cpy-cli": "^2.0.0",
78
78
  "eslint": "^5.16.0",
79
- "eslint-config-prettier": "^4.1.0",
79
+ "eslint-config-prettier": "^4.2.0",
80
80
  "eslint-plugin-prettier": "^3.0.1",
81
- "fast-check": "^1.13.0",
82
- "jest": "^24.7.1",
83
- "prettier": "^1.16.4"
81
+ "fast-check": "^1.14.0",
82
+ "jest": "^24.8.0",
83
+ "prettier": "^1.17.0"
84
84
  },
85
85
  "dependencies": {
86
- "@babel/runtime": "^7.4.3"
86
+ "@babel/runtime": "^7.4.4"
87
87
  },
88
88
  "engines": {
89
89
  "node": ">= 6"
package/util.js CHANGED
@@ -6,7 +6,7 @@ var str = require('./dist/stringify')
6
6
  exports.stringifyNumber = str.stringifyNumber
7
7
  exports.stringifyString = str.stringifyString
8
8
  exports.toJSON = require('./dist/toJSON').default
9
- exports.Type = require('./dist/cst/Node').Type
9
+ exports.Type = require('./dist/constants').Type
10
10
 
11
11
  var err = require('./dist/errors')
12
12
  exports.YAMLReferenceError = err.YAMLReferenceError