yaml 1.5.1 → 1.6.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.
@@ -52,6 +52,7 @@ function () {
52
52
  this.commentBefore = null;
53
53
  this.comment = null;
54
54
  this.contents = null;
55
+ this.directivesEndMarker = null;
55
56
  this.errors = [];
56
57
  this.options = options;
57
58
  this.schema = null;
@@ -151,6 +152,7 @@ function () {
151
152
  directives = _node$directives === void 0 ? [] : _node$directives,
152
153
  _node$contents = node.contents,
153
154
  contents = _node$contents === void 0 ? [] : _node$contents,
155
+ directivesEndMarker = node.directivesEndMarker,
154
156
  error = node.error,
155
157
  valueRange = node.valueRange;
156
158
 
@@ -160,6 +162,7 @@ function () {
160
162
  }
161
163
 
162
164
  this.parseDirectives(directives, prevDoc);
165
+ if (directivesEndMarker) this.directivesEndMarker = true;
163
166
  this.range = valueRange ? [valueRange.start, valueRange.end] : null;
164
167
  this.setSchema();
165
168
  this.anchors._cstAliases = [];
@@ -719,7 +722,6 @@ function () {
719
722
  if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
720
723
  this.setSchema();
721
724
  var lines = [];
722
- if (this.commentBefore) lines.push(this.commentBefore.replace(/^/gm, '#'), '');
723
725
  var hasDirectives = false;
724
726
 
725
727
  if (this.version) {
@@ -745,7 +747,13 @@ function () {
745
747
  hasDirectives = true;
746
748
  }
747
749
  });
748
- if (hasDirectives) lines.push('---');
750
+ if (hasDirectives || this.directivesEndMarker) lines.push('---');
751
+
752
+ if (this.commentBefore) {
753
+ if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
754
+ lines.unshift(this.commentBefore.replace(/^/gm, '#'));
755
+ }
756
+
749
757
  var ctx = {
750
758
  anchors: {},
751
759
  doc: this,
@@ -756,7 +764,7 @@ function () {
756
764
 
757
765
  if (this.contents) {
758
766
  if (this.contents instanceof _Node.default) {
759
- if (this.contents.spaceBefore && hasDirectives) lines.push('');
767
+ if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
760
768
  if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
761
769
 
762
770
  ctx.forceBlockIndent = !!this.comment;
@@ -56,6 +56,8 @@ function (_Node) {
56
56
  _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Document).call(this, _constants.Type.DOCUMENT));
57
57
  _this.directives = null;
58
58
  _this.contents = null;
59
+ _this.directivesEndMarker = null;
60
+ _this.documentEndMarker = null;
59
61
  return _this;
60
62
  }
61
63
 
@@ -125,7 +127,10 @@ function (_Node) {
125
127
  }
126
128
  }
127
129
 
128
- if (src[offset]) return offset + 3;
130
+ if (src[offset]) {
131
+ this.directivesEndMarker = new _Range.default(offset, offset + 3);
132
+ return offset + 3;
133
+ }
129
134
 
130
135
  if (hasDirectives) {
131
136
  this.error = new _errors.YAMLSemanticError(this, 'Missing directives-end indicator line');
@@ -214,6 +219,7 @@ function (_Node) {
214
219
  this.valueRange.end = offset;
215
220
 
216
221
  if (src[offset]) {
222
+ this.documentEndMarker = new _Range.default(offset, offset + 3);
217
223
  offset += 3;
218
224
 
219
225
  if (src[offset]) {
@@ -269,9 +275,11 @@ function (_Node) {
269
275
  this.directives.forEach(function (node) {
270
276
  offset = node.setOrigRanges(cr, offset);
271
277
  });
278
+ if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset);
272
279
  this.contents.forEach(function (node) {
273
280
  offset = node.setOrigRanges(cr, offset);
274
281
  });
282
+ if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
275
283
  return offset;
276
284
  }
277
285
  }, {
@@ -94,7 +94,15 @@ function (_Node) {
94
94
  }
95
95
 
96
96
  offset = _Node2.default.endOfIndent(src, lineStart);
97
- if (offset - lineStart <= indent) this.error = new _errors.YAMLSemanticError(this, 'Insufficient indentation in flow collection');
97
+
98
+ if (offset <= lineStart + indent) {
99
+ char = src[offset];
100
+
101
+ if (offset < lineStart + indent || char !== ']' && char !== '}') {
102
+ var msg = 'Insufficient indentation in flow collection';
103
+ this.error = new _errors.YAMLSemanticError(this, msg);
104
+ }
105
+ }
98
106
  }
99
107
  break;
100
108
 
package/dist/Document.js CHANGED
@@ -41,6 +41,7 @@ class Document {
41
41
  this.commentBefore = null;
42
42
  this.comment = null;
43
43
  this.contents = null;
44
+ this.directivesEndMarker = null;
44
45
  this.errors = [];
45
46
  this.options = options;
46
47
  this.schema = null;
@@ -124,6 +125,7 @@ class Document {
124
125
  const {
125
126
  directives = [],
126
127
  contents = [],
128
+ directivesEndMarker,
127
129
  error,
128
130
  valueRange
129
131
  } = node;
@@ -134,6 +136,7 @@ class Document {
134
136
  }
135
137
 
136
138
  this.parseDirectives(directives, prevDoc);
139
+ if (directivesEndMarker) this.directivesEndMarker = true;
137
140
  this.range = valueRange ? [valueRange.start, valueRange.end] : null;
138
141
  this.setSchema();
139
142
  this.anchors._cstAliases = [];
@@ -592,7 +595,6 @@ class Document {
592
595
  if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
593
596
  this.setSchema();
594
597
  const lines = [];
595
- if (this.commentBefore) lines.push(this.commentBefore.replace(/^/gm, '#'), '');
596
598
  let hasDirectives = false;
597
599
 
598
600
  if (this.version) {
@@ -616,7 +618,13 @@ class Document {
616
618
  hasDirectives = true;
617
619
  }
618
620
  });
619
- if (hasDirectives) lines.push('---');
621
+ if (hasDirectives || this.directivesEndMarker) lines.push('---');
622
+
623
+ if (this.commentBefore) {
624
+ if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
625
+ lines.unshift(this.commentBefore.replace(/^/gm, '#'));
626
+ }
627
+
620
628
  const ctx = {
621
629
  anchors: {},
622
630
  doc: this,
@@ -627,7 +635,7 @@ class Document {
627
635
 
628
636
  if (this.contents) {
629
637
  if (this.contents instanceof _Node.default) {
630
- if (this.contents.spaceBefore && hasDirectives) lines.push('');
638
+ if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
631
639
  if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
632
640
 
633
641
  ctx.forceBlockIndent = !!this.comment;
@@ -35,6 +35,8 @@ class Document extends _Node.default {
35
35
  super(_constants.Type.DOCUMENT);
36
36
  this.directives = null;
37
37
  this.contents = null;
38
+ this.directivesEndMarker = null;
39
+ this.documentEndMarker = null;
38
40
  }
39
41
 
40
42
  parseDirectives(start) {
@@ -103,7 +105,10 @@ class Document extends _Node.default {
103
105
  }
104
106
  }
105
107
 
106
- if (src[offset]) return offset + 3;
108
+ if (src[offset]) {
109
+ this.directivesEndMarker = new _Range.default(offset, offset + 3);
110
+ return offset + 3;
111
+ }
107
112
 
108
113
  if (hasDirectives) {
109
114
  this.error = new _errors.YAMLSemanticError(this, 'Missing directives-end indicator line');
@@ -190,6 +195,7 @@ class Document extends _Node.default {
190
195
  this.valueRange.end = offset;
191
196
 
192
197
  if (src[offset]) {
198
+ this.documentEndMarker = new _Range.default(offset, offset + 3);
193
199
  offset += 3;
194
200
 
195
201
  if (src[offset]) {
@@ -244,9 +250,11 @@ class Document extends _Node.default {
244
250
  this.directives.forEach(node => {
245
251
  offset = node.setOrigRanges(cr, offset);
246
252
  });
253
+ if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset);
247
254
  this.contents.forEach(node => {
248
255
  offset = node.setOrigRanges(cr, offset);
249
256
  });
257
+ if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
250
258
  return offset;
251
259
  }
252
260
 
@@ -74,7 +74,15 @@ class FlowCollection extends _Node.default {
74
74
  }
75
75
 
76
76
  offset = _Node.default.endOfIndent(src, lineStart);
77
- if (offset - lineStart <= indent) this.error = new _errors.YAMLSemanticError(this, 'Insufficient indentation in flow collection');
77
+
78
+ if (offset <= lineStart + indent) {
79
+ char = src[offset];
80
+
81
+ if (offset < lineStart + indent || char !== ']' && char !== '}') {
82
+ const msg = 'Insufficient indentation in flow collection';
83
+ this.error = new _errors.YAMLSemanticError(this, msg);
84
+ }
85
+ }
78
86
  }
79
87
  break;
80
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
6
  "repository": "github:eemeli/yaml",
@@ -67,23 +67,24 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "@babel/cli": "^7.4.4",
70
- "@babel/core": "^7.4.4",
70
+ "@babel/core": "^7.4.5",
71
71
  "@babel/plugin-proposal-class-properties": "^7.4.4",
72
72
  "@babel/plugin-transform-runtime": "^7.4.4",
73
- "@babel/preset-env": "^7.4.4",
73
+ "@babel/preset-env": "^7.4.5",
74
74
  "babel-eslint": "^10.0.1",
75
75
  "babel-jest": "^24.8.0",
76
76
  "babel-plugin-trace": "^1.1.0",
77
+ "common-tags": "^1.8.0",
77
78
  "cpy-cli": "^2.0.0",
78
79
  "eslint": "^5.16.0",
79
- "eslint-config-prettier": "^4.2.0",
80
- "eslint-plugin-prettier": "^3.0.1",
81
- "fast-check": "^1.14.0",
80
+ "eslint-config-prettier": "^4.3.0",
81
+ "eslint-plugin-prettier": "^3.1.0",
82
+ "fast-check": "^1.15.1",
82
83
  "jest": "^24.8.0",
83
- "prettier": "^1.17.0"
84
+ "prettier": "^1.17.1"
84
85
  },
85
86
  "dependencies": {
86
- "@babel/runtime": "^7.4.4"
87
+ "@babel/runtime": "^7.4.5"
87
88
  },
88
89
  "engines": {
89
90
  "node": ">= 6"