yaml 2.4.0 → 2.4.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.
@@ -513,7 +513,10 @@ class Parser {
513
513
  return;
514
514
  }
515
515
  if (this.indent >= map.indent) {
516
- const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep;
516
+ const atNextItem = !this.onKeyLine &&
517
+ this.indent === map.indent &&
518
+ it.sep &&
519
+ this.type !== 'seq-item-ind';
517
520
  // For empty nodes, assign newline-separated not indented empty tokens to following node
518
521
  let start = [];
519
522
  if (atNextItem && it.sep && !it.value) {
@@ -28,7 +28,7 @@ function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth =
28
28
  let escStart = -1;
29
29
  let escEnd = -1;
30
30
  if (mode === FOLD_BLOCK) {
31
- i = consumeMoreIndentedLines(text, i);
31
+ i = consumeMoreIndentedLines(text, i, indent.length);
32
32
  if (i !== -1)
33
33
  end = i + endStep;
34
34
  }
@@ -52,8 +52,8 @@ function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth =
52
52
  }
53
53
  if (ch === '\n') {
54
54
  if (mode === FOLD_BLOCK)
55
- i = consumeMoreIndentedLines(text, i);
56
- end = i + endStep;
55
+ i = consumeMoreIndentedLines(text, i, indent.length);
56
+ end = i + indent.length + endStep;
57
57
  split = undefined;
58
58
  }
59
59
  else {
@@ -121,15 +121,24 @@ function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth =
121
121
  * Presumes `i + 1` is at the start of a line
122
122
  * @returns index of last newline in more-indented block
123
123
  */
124
- function consumeMoreIndentedLines(text, i) {
125
- let ch = text[i + 1];
124
+ function consumeMoreIndentedLines(text, i, indent) {
125
+ let end = i;
126
+ let start = i + 1;
127
+ let ch = text[start];
126
128
  while (ch === ' ' || ch === '\t') {
127
- do {
128
- ch = text[(i += 1)];
129
- } while (ch && ch !== '\n');
130
- ch = text[i + 1];
129
+ if (i < start + indent) {
130
+ ch = text[++i];
131
+ }
132
+ else {
133
+ do {
134
+ ch = text[++i];
135
+ } while (ch && ch !== '\n');
136
+ end = i;
137
+ start = i + 1;
138
+ ch = text[start];
139
+ }
131
140
  }
132
- return i;
141
+ return end;
133
142
  }
134
143
 
135
144
  export { FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED, foldFlowLines };
@@ -58,7 +58,7 @@ function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, fl
58
58
  onChompKeep();
59
59
  return str;
60
60
  }
61
- function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemIndent, onComment }) {
61
+ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
62
62
  const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;
63
63
  itemIndent += indentStep;
64
64
  const itemCtx = Object.assign({}, ctx, {
@@ -111,10 +111,9 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
111
111
  lines.push(str);
112
112
  linesAtValue = lines.length;
113
113
  }
114
- let str;
115
114
  const { start, end } = flowChars;
116
115
  if (lines.length === 0) {
117
- str = start + end;
116
+ return start + end;
118
117
  }
119
118
  else {
120
119
  if (!reqNewline) {
@@ -122,21 +121,15 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
122
121
  reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
123
122
  }
124
123
  if (reqNewline) {
125
- str = start;
124
+ let str = start;
126
125
  for (const line of lines)
127
126
  str += line ? `\n${indentStep}${indent}${line}` : '\n';
128
- str += `\n${indent}${end}`;
127
+ return `${str}\n${indent}${end}`;
129
128
  }
130
129
  else {
131
- str = `${start}${fcPadding}${lines.join(' ')}${fcPadding}${end}`;
130
+ return `${start}${fcPadding}${lines.join(' ')}${fcPadding}${end}`;
132
131
  }
133
132
  }
134
- if (comment) {
135
- str += lineComment(str, indent, commentString(comment));
136
- if (onComment)
137
- onComment();
138
- }
139
- return str;
140
133
  }
141
134
  function addCommentBefore({ indent, options: { commentString } }, lines, comment, chompKeep) {
142
135
  if (comment && chompKeep)
@@ -517,7 +517,10 @@ class Parser {
517
517
  return;
518
518
  }
519
519
  if (this.indent >= map.indent) {
520
- const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep;
520
+ const atNextItem = !this.onKeyLine &&
521
+ this.indent === map.indent &&
522
+ it.sep &&
523
+ this.type !== 'seq-item-ind';
521
524
  // For empty nodes, assign newline-separated not indented empty tokens to following node
522
525
  let start = [];
523
526
  if (atNextItem && it.sep && !it.value) {
@@ -30,7 +30,7 @@ function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth =
30
30
  let escStart = -1;
31
31
  let escEnd = -1;
32
32
  if (mode === FOLD_BLOCK) {
33
- i = consumeMoreIndentedLines(text, i);
33
+ i = consumeMoreIndentedLines(text, i, indent.length);
34
34
  if (i !== -1)
35
35
  end = i + endStep;
36
36
  }
@@ -54,8 +54,8 @@ function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth =
54
54
  }
55
55
  if (ch === '\n') {
56
56
  if (mode === FOLD_BLOCK)
57
- i = consumeMoreIndentedLines(text, i);
58
- end = i + endStep;
57
+ i = consumeMoreIndentedLines(text, i, indent.length);
58
+ end = i + indent.length + endStep;
59
59
  split = undefined;
60
60
  }
61
61
  else {
@@ -123,15 +123,24 @@ function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth =
123
123
  * Presumes `i + 1` is at the start of a line
124
124
  * @returns index of last newline in more-indented block
125
125
  */
126
- function consumeMoreIndentedLines(text, i) {
127
- let ch = text[i + 1];
126
+ function consumeMoreIndentedLines(text, i, indent) {
127
+ let end = i;
128
+ let start = i + 1;
129
+ let ch = text[start];
128
130
  while (ch === ' ' || ch === '\t') {
129
- do {
130
- ch = text[(i += 1)];
131
- } while (ch && ch !== '\n');
132
- ch = text[i + 1];
131
+ if (i < start + indent) {
132
+ ch = text[++i];
133
+ }
134
+ else {
135
+ do {
136
+ ch = text[++i];
137
+ } while (ch && ch !== '\n');
138
+ end = i;
139
+ start = i + 1;
140
+ ch = text[start];
141
+ }
133
142
  }
134
- return i;
143
+ return end;
135
144
  }
136
145
 
137
146
  exports.FOLD_BLOCK = FOLD_BLOCK;
@@ -60,7 +60,7 @@ function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, fl
60
60
  onChompKeep();
61
61
  return str;
62
62
  }
63
- function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemIndent, onComment }) {
63
+ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
64
64
  const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;
65
65
  itemIndent += indentStep;
66
66
  const itemCtx = Object.assign({}, ctx, {
@@ -113,10 +113,9 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
113
113
  lines.push(str);
114
114
  linesAtValue = lines.length;
115
115
  }
116
- let str;
117
116
  const { start, end } = flowChars;
118
117
  if (lines.length === 0) {
119
- str = start + end;
118
+ return start + end;
120
119
  }
121
120
  else {
122
121
  if (!reqNewline) {
@@ -124,21 +123,15 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
124
123
  reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
125
124
  }
126
125
  if (reqNewline) {
127
- str = start;
126
+ let str = start;
128
127
  for (const line of lines)
129
128
  str += line ? `\n${indentStep}${indent}${line}` : '\n';
130
- str += `\n${indent}${end}`;
129
+ return `${str}\n${indent}${end}`;
131
130
  }
132
131
  else {
133
- str = `${start}${fcPadding}${lines.join(' ')}${fcPadding}${end}`;
132
+ return `${start}${fcPadding}${lines.join(' ')}${fcPadding}${end}`;
134
133
  }
135
134
  }
136
- if (comment) {
137
- str += stringifyComment.lineComment(str, indent, commentString(comment));
138
- if (onComment)
139
- onComment();
140
- }
141
- return str;
142
135
  }
143
136
  function addCommentBefore({ indent, options: { commentString } }, lines, comment, chompKeep) {
144
137
  if (comment && chompKeep)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
6
  "repository": "github:eemeli/yaml",