yaml 2.2.0 → 2.2.2
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.
- package/browser/dist/errors.js +1 -1
- package/browser/dist/stringify/stringifyCollection.js +1 -1
- package/browser/dist/stringify/stringifyString.js +15 -10
- package/dist/errors.js +1 -1
- package/dist/stringify/stringifyCollection.js +1 -1
- package/dist/stringify/stringifyString.js +15 -10
- package/package.json +1 -1
package/browser/dist/errors.js
CHANGED
|
@@ -47,7 +47,7 @@ const prettifyError = (src, lc) => (error) => {
|
|
|
47
47
|
let count = 1;
|
|
48
48
|
const end = error.linePos[1];
|
|
49
49
|
if (end && end.line === line && end.col > col) {
|
|
50
|
-
count = Math.min(end.col - col, 80 - ci);
|
|
50
|
+
count = Math.max(1, Math.min(end.col - col, 80 - ci));
|
|
51
51
|
}
|
|
52
52
|
const pointer = ' '.repeat(ci) + '^'.repeat(count);
|
|
53
53
|
error.message += `:\n\n${lineStr}\n${pointer}\n`;
|
|
@@ -133,7 +133,7 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
if (comment) {
|
|
136
|
-
str += lineComment(str, commentString(comment)
|
|
136
|
+
str += lineComment(str, indent, commentString(comment));
|
|
137
137
|
if (onComment)
|
|
138
138
|
onComment();
|
|
139
139
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Scalar } from '../nodes/Scalar.js';
|
|
2
2
|
import { foldFlowLines, FOLD_QUOTED, FOLD_FLOW, FOLD_BLOCK } from './foldFlowLines.js';
|
|
3
3
|
|
|
4
|
-
const getFoldOptions = (ctx) => ({
|
|
5
|
-
indentAtStart: ctx.indentAtStart,
|
|
4
|
+
const getFoldOptions = (ctx, isBlock) => ({
|
|
5
|
+
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
|
|
6
6
|
lineWidth: ctx.options.lineWidth,
|
|
7
7
|
minContentWidth: ctx.options.minContentWidth
|
|
8
8
|
});
|
|
@@ -115,7 +115,7 @@ function doubleQuotedString(value, ctx) {
|
|
|
115
115
|
str = start ? str + json.slice(start) : json;
|
|
116
116
|
return implicitKey
|
|
117
117
|
? str
|
|
118
|
-
: foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
|
|
118
|
+
: foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));
|
|
119
119
|
}
|
|
120
120
|
function singleQuotedString(value, ctx) {
|
|
121
121
|
if (ctx.options.singleQuote === false ||
|
|
@@ -127,7 +127,7 @@ function singleQuotedString(value, ctx) {
|
|
|
127
127
|
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
|
|
128
128
|
return ctx.implicitKey
|
|
129
129
|
? res
|
|
130
|
-
: foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
130
|
+
: foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
131
131
|
}
|
|
132
132
|
function quotedString(value, ctx) {
|
|
133
133
|
const { singleQuote } = ctx.options;
|
|
@@ -225,12 +225,12 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
|
|
|
225
225
|
.replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
|
|
226
226
|
// ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
|
|
227
227
|
.replace(/\n+/g, `$&${indent}`);
|
|
228
|
-
const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx));
|
|
228
|
+
const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx, true));
|
|
229
229
|
return `${header}\n${indent}${body}`;
|
|
230
230
|
}
|
|
231
231
|
function plainString(item, ctx, onComment, onChompKeep) {
|
|
232
232
|
const { type, value } = item;
|
|
233
|
-
const { actualString, implicitKey, indent, inFlow } = ctx;
|
|
233
|
+
const { actualString, implicitKey, indent, indentStep, inFlow } = ctx;
|
|
234
234
|
if ((implicitKey && /[\n[\]{},]/.test(value)) ||
|
|
235
235
|
(inFlow && /[[\]{},]/.test(value))) {
|
|
236
236
|
return quotedString(value, ctx);
|
|
@@ -254,9 +254,14 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
254
254
|
// Where allowed & type not set explicitly, prefer block style for multiline strings
|
|
255
255
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
256
256
|
}
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
|
|
257
|
+
if (containsDocumentMarker(value)) {
|
|
258
|
+
if (indent === '') {
|
|
259
|
+
ctx.forceBlockIndent = true;
|
|
260
|
+
return blockString(item, ctx, onComment, onChompKeep);
|
|
261
|
+
}
|
|
262
|
+
else if (implicitKey && indent === indentStep) {
|
|
263
|
+
return quotedString(value, ctx);
|
|
264
|
+
}
|
|
260
265
|
}
|
|
261
266
|
const str = value.replace(/\n+/g, `$&\n${indent}`);
|
|
262
267
|
// Verify that output will be parsed as a string, as e.g. plain numbers and
|
|
@@ -270,7 +275,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
270
275
|
}
|
|
271
276
|
return implicitKey
|
|
272
277
|
? str
|
|
273
|
-
: foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
278
|
+
: foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));
|
|
274
279
|
}
|
|
275
280
|
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
276
281
|
const { implicitKey, inFlow } = ctx;
|
package/dist/errors.js
CHANGED
|
@@ -49,7 +49,7 @@ const prettifyError = (src, lc) => (error) => {
|
|
|
49
49
|
let count = 1;
|
|
50
50
|
const end = error.linePos[1];
|
|
51
51
|
if (end && end.line === line && end.col > col) {
|
|
52
|
-
count = Math.min(end.col - col, 80 - ci);
|
|
52
|
+
count = Math.max(1, Math.min(end.col - col, 80 - ci));
|
|
53
53
|
}
|
|
54
54
|
const pointer = ' '.repeat(ci) + '^'.repeat(count);
|
|
55
55
|
error.message += `:\n\n${lineStr}\n${pointer}\n`;
|
|
@@ -135,7 +135,7 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
if (comment) {
|
|
138
|
-
str += stringifyComment.lineComment(str, commentString(comment)
|
|
138
|
+
str += stringifyComment.lineComment(str, indent, commentString(comment));
|
|
139
139
|
if (onComment)
|
|
140
140
|
onComment();
|
|
141
141
|
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var Scalar = require('../nodes/Scalar.js');
|
|
4
4
|
var foldFlowLines = require('./foldFlowLines.js');
|
|
5
5
|
|
|
6
|
-
const getFoldOptions = (ctx) => ({
|
|
7
|
-
indentAtStart: ctx.indentAtStart,
|
|
6
|
+
const getFoldOptions = (ctx, isBlock) => ({
|
|
7
|
+
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
|
|
8
8
|
lineWidth: ctx.options.lineWidth,
|
|
9
9
|
minContentWidth: ctx.options.minContentWidth
|
|
10
10
|
});
|
|
@@ -117,7 +117,7 @@ function doubleQuotedString(value, ctx) {
|
|
|
117
117
|
str = start ? str + json.slice(start) : json;
|
|
118
118
|
return implicitKey
|
|
119
119
|
? str
|
|
120
|
-
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx));
|
|
120
|
+
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false));
|
|
121
121
|
}
|
|
122
122
|
function singleQuotedString(value, ctx) {
|
|
123
123
|
if (ctx.options.singleQuote === false ||
|
|
@@ -129,7 +129,7 @@ function singleQuotedString(value, ctx) {
|
|
|
129
129
|
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
|
|
130
130
|
return ctx.implicitKey
|
|
131
131
|
? res
|
|
132
|
-
: foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
|
|
132
|
+
: foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
|
|
133
133
|
}
|
|
134
134
|
function quotedString(value, ctx) {
|
|
135
135
|
const { singleQuote } = ctx.options;
|
|
@@ -227,12 +227,12 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
|
|
|
227
227
|
.replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
|
|
228
228
|
// ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
|
|
229
229
|
.replace(/\n+/g, `$&${indent}`);
|
|
230
|
-
const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx));
|
|
230
|
+
const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx, true));
|
|
231
231
|
return `${header}\n${indent}${body}`;
|
|
232
232
|
}
|
|
233
233
|
function plainString(item, ctx, onComment, onChompKeep) {
|
|
234
234
|
const { type, value } = item;
|
|
235
|
-
const { actualString, implicitKey, indent, inFlow } = ctx;
|
|
235
|
+
const { actualString, implicitKey, indent, indentStep, inFlow } = ctx;
|
|
236
236
|
if ((implicitKey && /[\n[\]{},]/.test(value)) ||
|
|
237
237
|
(inFlow && /[[\]{},]/.test(value))) {
|
|
238
238
|
return quotedString(value, ctx);
|
|
@@ -256,9 +256,14 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
256
256
|
// Where allowed & type not set explicitly, prefer block style for multiline strings
|
|
257
257
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
258
258
|
}
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
if (containsDocumentMarker(value)) {
|
|
260
|
+
if (indent === '') {
|
|
261
|
+
ctx.forceBlockIndent = true;
|
|
262
|
+
return blockString(item, ctx, onComment, onChompKeep);
|
|
263
|
+
}
|
|
264
|
+
else if (implicitKey && indent === indentStep) {
|
|
265
|
+
return quotedString(value, ctx);
|
|
266
|
+
}
|
|
262
267
|
}
|
|
263
268
|
const str = value.replace(/\n+/g, `$&\n${indent}`);
|
|
264
269
|
// Verify that output will be parsed as a string, as e.g. plain numbers and
|
|
@@ -272,7 +277,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
272
277
|
}
|
|
273
278
|
return implicitKey
|
|
274
279
|
? str
|
|
275
|
-
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
|
|
280
|
+
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
|
|
276
281
|
}
|
|
277
282
|
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
278
283
|
const { implicitKey, inFlow } = ctx;
|