@digipair/skill-yaml 0.113.1 → 0.114.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/README.md +7 -0
- package/{index.cjs.js → dist/index.cjs.js} +432 -445
- package/{index.esm.js → dist/index.esm.js} +432 -443
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{libs/skill-yaml → dist}/src/lib/skill-yaml.d.ts +1 -0
- package/dist/src/lib/skill-yaml.d.ts.map +1 -0
- package/package.json +26 -5
- package/index.d.ts +0 -1
- package/libs/skill-yaml/src/index.d.ts +0 -1
- /package/{index.cjs.d.ts → dist/index.d.ts} +0 -0
- /package/{schema.fr.json → dist/schema.fr.json} +0 -0
- /package/{schema.json → dist/schema.json} +0 -0
|
@@ -5,11 +5,15 @@
|
|
|
5
5
|
return left instanceof right;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
+
function _type_of(obj) {
|
|
9
|
+
"@swc/helpers - typeof";
|
|
10
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
11
|
+
}
|
|
8
12
|
function isNothing(subject) {
|
|
9
|
-
return typeof subject ===
|
|
13
|
+
return typeof subject === 'undefined' || subject === null;
|
|
10
14
|
}
|
|
11
15
|
function isObject(subject) {
|
|
12
|
-
return typeof subject === "
|
|
16
|
+
return (typeof subject === "undefined" ? "undefined" : _type_of(subject)) === 'object' && subject !== null;
|
|
13
17
|
}
|
|
14
18
|
function toArray(sequence) {
|
|
15
19
|
if (Array.isArray(sequence)) return sequence;
|
|
@@ -30,7 +34,7 @@ function extend(target, source) {
|
|
|
30
34
|
return target;
|
|
31
35
|
}
|
|
32
36
|
function repeat(string, count) {
|
|
33
|
-
var result =
|
|
37
|
+
var result = '', cycle;
|
|
34
38
|
for(cycle = 0; cycle < count; cycle += 1){
|
|
35
39
|
result += string;
|
|
36
40
|
}
|
|
@@ -55,21 +59,21 @@ var common = {
|
|
|
55
59
|
};
|
|
56
60
|
// YAML error class. http://stackoverflow.com/questions/8458984
|
|
57
61
|
function formatError(exception, compact) {
|
|
58
|
-
var where =
|
|
62
|
+
var where = '', message = exception.reason || '(unknown reason)';
|
|
59
63
|
if (!exception.mark) return message;
|
|
60
64
|
if (exception.mark.name) {
|
|
61
65
|
where += 'in "' + exception.mark.name + '" ';
|
|
62
66
|
}
|
|
63
|
-
where +=
|
|
67
|
+
where += '(' + (exception.mark.line + 1) + ':' + (exception.mark.column + 1) + ')';
|
|
64
68
|
if (!compact && exception.mark.snippet) {
|
|
65
|
-
where +=
|
|
69
|
+
where += '\n\n' + exception.mark.snippet;
|
|
66
70
|
}
|
|
67
|
-
return message +
|
|
71
|
+
return message + ' ' + where;
|
|
68
72
|
}
|
|
69
73
|
function YAMLException$1(reason, mark) {
|
|
70
74
|
// Super constructor
|
|
71
75
|
Error.call(this);
|
|
72
|
-
this.name =
|
|
76
|
+
this.name = 'YAMLException';
|
|
73
77
|
this.reason = reason;
|
|
74
78
|
this.mark = mark;
|
|
75
79
|
this.message = formatError(this, false);
|
|
@@ -79,44 +83,44 @@ function YAMLException$1(reason, mark) {
|
|
|
79
83
|
Error.captureStackTrace(this, this.constructor);
|
|
80
84
|
} else {
|
|
81
85
|
// FF, IE 10+ and Safari 6+. Fallback for others
|
|
82
|
-
this.stack = new Error().stack ||
|
|
86
|
+
this.stack = new Error().stack || '';
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
// Inherit from Error
|
|
86
90
|
YAMLException$1.prototype = Object.create(Error.prototype);
|
|
87
91
|
YAMLException$1.prototype.constructor = YAMLException$1;
|
|
88
92
|
YAMLException$1.prototype.toString = function toString(compact) {
|
|
89
|
-
return this.name +
|
|
93
|
+
return this.name + ': ' + formatError(this, compact);
|
|
90
94
|
};
|
|
91
95
|
var exception = YAMLException$1;
|
|
92
96
|
// get snippet for a single line, respecting maxLength
|
|
93
97
|
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
94
|
-
var head =
|
|
95
|
-
var tail =
|
|
98
|
+
var head = '';
|
|
99
|
+
var tail = '';
|
|
96
100
|
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
97
101
|
if (position - lineStart > maxHalfLength) {
|
|
98
|
-
head =
|
|
102
|
+
head = ' ... ';
|
|
99
103
|
lineStart = position - maxHalfLength + head.length;
|
|
100
104
|
}
|
|
101
105
|
if (lineEnd - position > maxHalfLength) {
|
|
102
|
-
tail =
|
|
106
|
+
tail = ' ...';
|
|
103
107
|
lineEnd = position + maxHalfLength - tail.length;
|
|
104
108
|
}
|
|
105
109
|
return {
|
|
106
|
-
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g,
|
|
110
|
+
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, '→') + tail,
|
|
107
111
|
pos: position - lineStart + head.length // relative position
|
|
108
112
|
};
|
|
109
113
|
}
|
|
110
114
|
function padStart(string, max) {
|
|
111
|
-
return common.repeat(
|
|
115
|
+
return common.repeat(' ', max - string.length) + string;
|
|
112
116
|
}
|
|
113
117
|
function makeSnippet(mark, options) {
|
|
114
118
|
options = Object.create(options || null);
|
|
115
119
|
if (!mark.buffer) return null;
|
|
116
120
|
if (!options.maxLength) options.maxLength = 79;
|
|
117
|
-
if (typeof options.indent !==
|
|
118
|
-
if (typeof options.linesBefore !==
|
|
119
|
-
if (typeof options.linesAfter !==
|
|
121
|
+
if (typeof options.indent !== 'number') options.indent = 1;
|
|
122
|
+
if (typeof options.linesBefore !== 'number') options.linesBefore = 3;
|
|
123
|
+
if (typeof options.linesAfter !== 'number') options.linesAfter = 2;
|
|
120
124
|
var re = /\r?\n|\r|\0/g;
|
|
121
125
|
var lineStarts = [
|
|
122
126
|
0
|
|
@@ -132,41 +136,41 @@ function makeSnippet(mark, options) {
|
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
138
|
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
|
|
135
|
-
var result =
|
|
139
|
+
var result = '', i, line;
|
|
136
140
|
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
|
|
137
141
|
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
|
|
138
142
|
for(i = 1; i <= options.linesBefore; i++){
|
|
139
143
|
if (foundLineNo - i < 0) break;
|
|
140
144
|
line = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
|
|
141
|
-
result = common.repeat(
|
|
145
|
+
result = common.repeat(' ', options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + ' | ' + line.str + '\n' + result;
|
|
142
146
|
}
|
|
143
147
|
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
144
|
-
result += common.repeat(
|
|
145
|
-
result += common.repeat(
|
|
148
|
+
result += common.repeat(' ', options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + ' | ' + line.str + '\n';
|
|
149
|
+
result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n';
|
|
146
150
|
for(i = 1; i <= options.linesAfter; i++){
|
|
147
151
|
if (foundLineNo + i >= lineEnds.length) break;
|
|
148
152
|
line = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
|
|
149
|
-
result += common.repeat(
|
|
153
|
+
result += common.repeat(' ', options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + ' | ' + line.str + '\n';
|
|
150
154
|
}
|
|
151
|
-
return result.replace(/\n$/,
|
|
155
|
+
return result.replace(/\n$/, '');
|
|
152
156
|
}
|
|
153
157
|
var snippet = makeSnippet;
|
|
154
158
|
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
'kind',
|
|
160
|
+
'multi',
|
|
161
|
+
'resolve',
|
|
162
|
+
'construct',
|
|
163
|
+
'instanceOf',
|
|
164
|
+
'predicate',
|
|
165
|
+
'represent',
|
|
166
|
+
'representName',
|
|
167
|
+
'defaultStyle',
|
|
168
|
+
'styleAliases'
|
|
165
169
|
];
|
|
166
170
|
var YAML_NODE_KINDS = [
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
171
|
+
'scalar',
|
|
172
|
+
'sequence',
|
|
173
|
+
'mapping'
|
|
170
174
|
];
|
|
171
175
|
function compileStyleAliases(map) {
|
|
172
176
|
var result = {};
|
|
@@ -189,20 +193,20 @@ function Type$1(tag, options) {
|
|
|
189
193
|
// TODO: Add tag format check.
|
|
190
194
|
this.options = options; // keep original options in case user wants to extend this type later
|
|
191
195
|
this.tag = tag;
|
|
192
|
-
this.kind = options[
|
|
193
|
-
this.resolve = options[
|
|
196
|
+
this.kind = options['kind'] || null;
|
|
197
|
+
this.resolve = options['resolve'] || function() {
|
|
194
198
|
return true;
|
|
195
199
|
};
|
|
196
|
-
this.construct = options[
|
|
200
|
+
this.construct = options['construct'] || function(data) {
|
|
197
201
|
return data;
|
|
198
202
|
};
|
|
199
|
-
this.instanceOf = options[
|
|
200
|
-
this.predicate = options[
|
|
201
|
-
this.represent = options[
|
|
202
|
-
this.representName = options[
|
|
203
|
-
this.defaultStyle = options[
|
|
204
|
-
this.multi = options[
|
|
205
|
-
this.styleAliases = compileStyleAliases(options[
|
|
203
|
+
this.instanceOf = options['instanceOf'] || null;
|
|
204
|
+
this.predicate = options['predicate'] || null;
|
|
205
|
+
this.represent = options['represent'] || null;
|
|
206
|
+
this.representName = options['representName'] || null;
|
|
207
|
+
this.defaultStyle = options['defaultStyle'] || null;
|
|
208
|
+
this.multi = options['multi'] || false;
|
|
209
|
+
this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
|
|
206
210
|
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
207
211
|
throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
208
212
|
}
|
|
@@ -237,9 +241,9 @@ function compileMap() {
|
|
|
237
241
|
function collectType(type) {
|
|
238
242
|
if (type.multi) {
|
|
239
243
|
result.multi[type.kind].push(type);
|
|
240
|
-
result.multi[
|
|
244
|
+
result.multi['fallback'].push(type);
|
|
241
245
|
} else {
|
|
242
|
-
result[type.kind][type.tag] = result[
|
|
246
|
+
result[type.kind][type.tag] = result['fallback'][type.tag] = type;
|
|
243
247
|
}
|
|
244
248
|
}
|
|
245
249
|
for(index = 0, length = arguments.length; index < length; index += 1){
|
|
@@ -264,47 +268,47 @@ Schema$1.prototype.extend = function extend(definition) {
|
|
|
264
268
|
if (definition.implicit) implicit = implicit.concat(definition.implicit);
|
|
265
269
|
if (definition.explicit) explicit = explicit.concat(definition.explicit);
|
|
266
270
|
} else {
|
|
267
|
-
throw new exception(
|
|
271
|
+
throw new exception('Schema.extend argument should be a Type, [ Type ], ' + 'or a schema definition ({ implicit: [...], explicit: [...] })');
|
|
268
272
|
}
|
|
269
273
|
implicit.forEach(function(type$1) {
|
|
270
274
|
if (!_instanceof(type$1, type)) {
|
|
271
|
-
throw new exception(
|
|
275
|
+
throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
|
|
272
276
|
}
|
|
273
|
-
if (type$1.loadKind && type$1.loadKind !==
|
|
274
|
-
throw new exception(
|
|
277
|
+
if (type$1.loadKind && type$1.loadKind !== 'scalar') {
|
|
278
|
+
throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
|
|
275
279
|
}
|
|
276
280
|
if (type$1.multi) {
|
|
277
|
-
throw new exception(
|
|
281
|
+
throw new exception('There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.');
|
|
278
282
|
}
|
|
279
283
|
});
|
|
280
284
|
explicit.forEach(function(type$1) {
|
|
281
285
|
if (!_instanceof(type$1, type)) {
|
|
282
|
-
throw new exception(
|
|
286
|
+
throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
|
|
283
287
|
}
|
|
284
288
|
});
|
|
285
289
|
var result = Object.create(Schema$1.prototype);
|
|
286
290
|
result.implicit = (this.implicit || []).concat(implicit);
|
|
287
291
|
result.explicit = (this.explicit || []).concat(explicit);
|
|
288
|
-
result.compiledImplicit = compileList(result,
|
|
289
|
-
result.compiledExplicit = compileList(result,
|
|
292
|
+
result.compiledImplicit = compileList(result, 'implicit');
|
|
293
|
+
result.compiledExplicit = compileList(result, 'explicit');
|
|
290
294
|
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
|
|
291
295
|
return result;
|
|
292
296
|
};
|
|
293
297
|
var schema = Schema$1;
|
|
294
|
-
var str = new type(
|
|
295
|
-
kind:
|
|
298
|
+
var str = new type('tag:yaml.org,2002:str', {
|
|
299
|
+
kind: 'scalar',
|
|
296
300
|
construct: function construct(data) {
|
|
297
|
-
return data !== null ? data :
|
|
301
|
+
return data !== null ? data : '';
|
|
298
302
|
}
|
|
299
303
|
});
|
|
300
|
-
var seq = new type(
|
|
301
|
-
kind:
|
|
304
|
+
var seq = new type('tag:yaml.org,2002:seq', {
|
|
305
|
+
kind: 'sequence',
|
|
302
306
|
construct: function construct(data) {
|
|
303
307
|
return data !== null ? data : [];
|
|
304
308
|
}
|
|
305
309
|
});
|
|
306
|
-
var map = new type(
|
|
307
|
-
kind:
|
|
310
|
+
var map = new type('tag:yaml.org,2002:map', {
|
|
311
|
+
kind: 'mapping',
|
|
308
312
|
construct: function construct(data) {
|
|
309
313
|
return data !== null ? data : {};
|
|
310
314
|
}
|
|
@@ -319,7 +323,7 @@ var failsafe = new schema({
|
|
|
319
323
|
function resolveYamlNull(data) {
|
|
320
324
|
if (data === null) return true;
|
|
321
325
|
var max = data.length;
|
|
322
|
-
return max === 1 && data ===
|
|
326
|
+
return max === 1 && data === '~' || max === 4 && (data === 'null' || data === 'Null' || data === 'NULL');
|
|
323
327
|
}
|
|
324
328
|
function constructYamlNull() {
|
|
325
329
|
return null;
|
|
@@ -327,58 +331,58 @@ function constructYamlNull() {
|
|
|
327
331
|
function isNull(object) {
|
|
328
332
|
return object === null;
|
|
329
333
|
}
|
|
330
|
-
var _null = new type(
|
|
331
|
-
kind:
|
|
334
|
+
var _null = new type('tag:yaml.org,2002:null', {
|
|
335
|
+
kind: 'scalar',
|
|
332
336
|
resolve: resolveYamlNull,
|
|
333
337
|
construct: constructYamlNull,
|
|
334
338
|
predicate: isNull,
|
|
335
339
|
represent: {
|
|
336
340
|
canonical: function canonical() {
|
|
337
|
-
return
|
|
341
|
+
return '~';
|
|
338
342
|
},
|
|
339
343
|
lowercase: function lowercase() {
|
|
340
|
-
return
|
|
344
|
+
return 'null';
|
|
341
345
|
},
|
|
342
346
|
uppercase: function uppercase() {
|
|
343
|
-
return
|
|
347
|
+
return 'NULL';
|
|
344
348
|
},
|
|
345
349
|
camelcase: function camelcase() {
|
|
346
|
-
return
|
|
350
|
+
return 'Null';
|
|
347
351
|
},
|
|
348
352
|
empty: function empty() {
|
|
349
|
-
return
|
|
353
|
+
return '';
|
|
350
354
|
}
|
|
351
355
|
},
|
|
352
|
-
defaultStyle:
|
|
356
|
+
defaultStyle: 'lowercase'
|
|
353
357
|
});
|
|
354
358
|
function resolveYamlBoolean(data) {
|
|
355
359
|
if (data === null) return false;
|
|
356
360
|
var max = data.length;
|
|
357
|
-
return max === 4 && (data ===
|
|
361
|
+
return max === 4 && (data === 'true' || data === 'True' || data === 'TRUE') || max === 5 && (data === 'false' || data === 'False' || data === 'FALSE');
|
|
358
362
|
}
|
|
359
363
|
function constructYamlBoolean(data) {
|
|
360
|
-
return data ===
|
|
364
|
+
return data === 'true' || data === 'True' || data === 'TRUE';
|
|
361
365
|
}
|
|
362
366
|
function isBoolean(object) {
|
|
363
|
-
return Object.prototype.toString.call(object) ===
|
|
367
|
+
return Object.prototype.toString.call(object) === '[object Boolean]';
|
|
364
368
|
}
|
|
365
|
-
var bool = new type(
|
|
366
|
-
kind:
|
|
369
|
+
var bool = new type('tag:yaml.org,2002:bool', {
|
|
370
|
+
kind: 'scalar',
|
|
367
371
|
resolve: resolveYamlBoolean,
|
|
368
372
|
construct: constructYamlBoolean,
|
|
369
373
|
predicate: isBoolean,
|
|
370
374
|
represent: {
|
|
371
375
|
lowercase: function lowercase(object) {
|
|
372
|
-
return object ?
|
|
376
|
+
return object ? 'true' : 'false';
|
|
373
377
|
},
|
|
374
378
|
uppercase: function uppercase(object) {
|
|
375
|
-
return object ?
|
|
379
|
+
return object ? 'TRUE' : 'FALSE';
|
|
376
380
|
},
|
|
377
381
|
camelcase: function camelcase(object) {
|
|
378
|
-
return object ?
|
|
382
|
+
return object ? 'True' : 'False';
|
|
379
383
|
}
|
|
380
384
|
},
|
|
381
|
-
defaultStyle:
|
|
385
|
+
defaultStyle: 'lowercase'
|
|
382
386
|
});
|
|
383
387
|
function isHexCode(c) {
|
|
384
388
|
return 0x30 /* 0 */ <= c && c <= 0x39 /* 9 */ || 0x41 /* A */ <= c && c <= 0x46 /* F */ || 0x61 /* a */ <= c && c <= 0x66 /* f */ ;
|
|
@@ -395,149 +399,149 @@ function resolveYamlInteger(data) {
|
|
|
395
399
|
if (!max) return false;
|
|
396
400
|
ch = data[index];
|
|
397
401
|
// sign
|
|
398
|
-
if (ch ===
|
|
402
|
+
if (ch === '-' || ch === '+') {
|
|
399
403
|
ch = data[++index];
|
|
400
404
|
}
|
|
401
|
-
if (ch ===
|
|
405
|
+
if (ch === '0') {
|
|
402
406
|
// 0
|
|
403
407
|
if (index + 1 === max) return true;
|
|
404
408
|
ch = data[++index];
|
|
405
409
|
// base 2, base 8, base 16
|
|
406
|
-
if (ch ===
|
|
410
|
+
if (ch === 'b') {
|
|
407
411
|
// base 2
|
|
408
412
|
index++;
|
|
409
413
|
for(; index < max; index++){
|
|
410
414
|
ch = data[index];
|
|
411
|
-
if (ch ===
|
|
412
|
-
if (ch !==
|
|
415
|
+
if (ch === '_') continue;
|
|
416
|
+
if (ch !== '0' && ch !== '1') return false;
|
|
413
417
|
hasDigits = true;
|
|
414
418
|
}
|
|
415
|
-
return hasDigits && ch !==
|
|
419
|
+
return hasDigits && ch !== '_';
|
|
416
420
|
}
|
|
417
|
-
if (ch ===
|
|
421
|
+
if (ch === 'x') {
|
|
418
422
|
// base 16
|
|
419
423
|
index++;
|
|
420
424
|
for(; index < max; index++){
|
|
421
425
|
ch = data[index];
|
|
422
|
-
if (ch ===
|
|
426
|
+
if (ch === '_') continue;
|
|
423
427
|
if (!isHexCode(data.charCodeAt(index))) return false;
|
|
424
428
|
hasDigits = true;
|
|
425
429
|
}
|
|
426
|
-
return hasDigits && ch !==
|
|
430
|
+
return hasDigits && ch !== '_';
|
|
427
431
|
}
|
|
428
|
-
if (ch ===
|
|
432
|
+
if (ch === 'o') {
|
|
429
433
|
// base 8
|
|
430
434
|
index++;
|
|
431
435
|
for(; index < max; index++){
|
|
432
436
|
ch = data[index];
|
|
433
|
-
if (ch ===
|
|
437
|
+
if (ch === '_') continue;
|
|
434
438
|
if (!isOctCode(data.charCodeAt(index))) return false;
|
|
435
439
|
hasDigits = true;
|
|
436
440
|
}
|
|
437
|
-
return hasDigits && ch !==
|
|
441
|
+
return hasDigits && ch !== '_';
|
|
438
442
|
}
|
|
439
443
|
}
|
|
440
444
|
// base 10 (except 0)
|
|
441
445
|
// value should not start with `_`;
|
|
442
|
-
if (ch ===
|
|
446
|
+
if (ch === '_') return false;
|
|
443
447
|
for(; index < max; index++){
|
|
444
448
|
ch = data[index];
|
|
445
|
-
if (ch ===
|
|
449
|
+
if (ch === '_') continue;
|
|
446
450
|
if (!isDecCode(data.charCodeAt(index))) {
|
|
447
451
|
return false;
|
|
448
452
|
}
|
|
449
453
|
hasDigits = true;
|
|
450
454
|
}
|
|
451
455
|
// Should have digits and should not end with `_`
|
|
452
|
-
if (!hasDigits || ch ===
|
|
456
|
+
if (!hasDigits || ch === '_') return false;
|
|
453
457
|
return true;
|
|
454
458
|
}
|
|
455
459
|
function constructYamlInteger(data) {
|
|
456
460
|
var value = data, sign = 1, ch;
|
|
457
|
-
if (value.indexOf(
|
|
458
|
-
value = value.replace(/_/g,
|
|
461
|
+
if (value.indexOf('_') !== -1) {
|
|
462
|
+
value = value.replace(/_/g, '');
|
|
459
463
|
}
|
|
460
464
|
ch = value[0];
|
|
461
|
-
if (ch ===
|
|
462
|
-
if (ch ===
|
|
465
|
+
if (ch === '-' || ch === '+') {
|
|
466
|
+
if (ch === '-') sign = -1;
|
|
463
467
|
value = value.slice(1);
|
|
464
468
|
ch = value[0];
|
|
465
469
|
}
|
|
466
|
-
if (value ===
|
|
467
|
-
if (ch ===
|
|
468
|
-
if (value[1] ===
|
|
469
|
-
if (value[1] ===
|
|
470
|
-
if (value[1] ===
|
|
470
|
+
if (value === '0') return 0;
|
|
471
|
+
if (ch === '0') {
|
|
472
|
+
if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
|
|
473
|
+
if (value[1] === 'x') return sign * parseInt(value.slice(2), 16);
|
|
474
|
+
if (value[1] === 'o') return sign * parseInt(value.slice(2), 8);
|
|
471
475
|
}
|
|
472
476
|
return sign * parseInt(value, 10);
|
|
473
477
|
}
|
|
474
478
|
function isInteger(object) {
|
|
475
|
-
return Object.prototype.toString.call(object) ===
|
|
479
|
+
return Object.prototype.toString.call(object) === '[object Number]' && object % 1 === 0 && !common.isNegativeZero(object);
|
|
476
480
|
}
|
|
477
|
-
var int = new type(
|
|
478
|
-
kind:
|
|
481
|
+
var int = new type('tag:yaml.org,2002:int', {
|
|
482
|
+
kind: 'scalar',
|
|
479
483
|
resolve: resolveYamlInteger,
|
|
480
484
|
construct: constructYamlInteger,
|
|
481
485
|
predicate: isInteger,
|
|
482
486
|
represent: {
|
|
483
487
|
binary: function binary(obj) {
|
|
484
|
-
return obj >= 0 ?
|
|
488
|
+
return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1);
|
|
485
489
|
},
|
|
486
490
|
octal: function octal(obj) {
|
|
487
|
-
return obj >= 0 ?
|
|
491
|
+
return obj >= 0 ? '0o' + obj.toString(8) : '-0o' + obj.toString(8).slice(1);
|
|
488
492
|
},
|
|
489
493
|
decimal: function decimal(obj) {
|
|
490
494
|
return obj.toString(10);
|
|
491
495
|
},
|
|
492
496
|
/* eslint-disable max-len */ hexadecimal: function hexadecimal(obj) {
|
|
493
|
-
return obj >= 0 ?
|
|
497
|
+
return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1);
|
|
494
498
|
}
|
|
495
499
|
},
|
|
496
|
-
defaultStyle:
|
|
500
|
+
defaultStyle: 'decimal',
|
|
497
501
|
styleAliases: {
|
|
498
502
|
binary: [
|
|
499
503
|
2,
|
|
500
|
-
|
|
504
|
+
'bin'
|
|
501
505
|
],
|
|
502
506
|
octal: [
|
|
503
507
|
8,
|
|
504
|
-
|
|
508
|
+
'oct'
|
|
505
509
|
],
|
|
506
510
|
decimal: [
|
|
507
511
|
10,
|
|
508
|
-
|
|
512
|
+
'dec'
|
|
509
513
|
],
|
|
510
514
|
hexadecimal: [
|
|
511
515
|
16,
|
|
512
|
-
|
|
516
|
+
'hex'
|
|
513
517
|
]
|
|
514
518
|
}
|
|
515
519
|
});
|
|
516
520
|
var YAML_FLOAT_PATTERN = new RegExp(// 2.5e4, 2.5 and integers
|
|
517
|
-
|
|
521
|
+
'^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' + // .2e4, .2
|
|
518
522
|
// special case, seems not from spec
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
523
|
+
'|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' + // .inf
|
|
524
|
+
'|[-+]?\\.(?:inf|Inf|INF)' + // .nan
|
|
525
|
+
'|\\.(?:nan|NaN|NAN))$');
|
|
522
526
|
function resolveYamlFloat(data) {
|
|
523
527
|
if (data === null) return false;
|
|
524
528
|
if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
|
|
525
529
|
// Probably should update regexp & check speed
|
|
526
|
-
data[data.length - 1] ===
|
|
530
|
+
data[data.length - 1] === '_') {
|
|
527
531
|
return false;
|
|
528
532
|
}
|
|
529
533
|
return true;
|
|
530
534
|
}
|
|
531
535
|
function constructYamlFloat(data) {
|
|
532
536
|
var value, sign;
|
|
533
|
-
value = data.replace(/_/g,
|
|
534
|
-
sign = value[0] ===
|
|
535
|
-
if (
|
|
537
|
+
value = data.replace(/_/g, '').toLowerCase();
|
|
538
|
+
sign = value[0] === '-' ? -1 : 1;
|
|
539
|
+
if ('+-'.indexOf(value[0]) >= 0) {
|
|
536
540
|
value = value.slice(1);
|
|
537
541
|
}
|
|
538
|
-
if (value ===
|
|
542
|
+
if (value === '.inf') {
|
|
539
543
|
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
540
|
-
} else if (value ===
|
|
544
|
+
} else if (value === '.nan') {
|
|
541
545
|
return NaN;
|
|
542
546
|
}
|
|
543
547
|
return sign * parseFloat(value, 10);
|
|
@@ -547,49 +551,49 @@ function representYamlFloat(object, style) {
|
|
|
547
551
|
var res;
|
|
548
552
|
if (isNaN(object)) {
|
|
549
553
|
switch(style){
|
|
550
|
-
case
|
|
551
|
-
return
|
|
552
|
-
case
|
|
553
|
-
return
|
|
554
|
-
case
|
|
555
|
-
return
|
|
554
|
+
case 'lowercase':
|
|
555
|
+
return '.nan';
|
|
556
|
+
case 'uppercase':
|
|
557
|
+
return '.NAN';
|
|
558
|
+
case 'camelcase':
|
|
559
|
+
return '.NaN';
|
|
556
560
|
}
|
|
557
561
|
} else if (Number.POSITIVE_INFINITY === object) {
|
|
558
562
|
switch(style){
|
|
559
|
-
case
|
|
560
|
-
return
|
|
561
|
-
case
|
|
562
|
-
return
|
|
563
|
-
case
|
|
564
|
-
return
|
|
563
|
+
case 'lowercase':
|
|
564
|
+
return '.inf';
|
|
565
|
+
case 'uppercase':
|
|
566
|
+
return '.INF';
|
|
567
|
+
case 'camelcase':
|
|
568
|
+
return '.Inf';
|
|
565
569
|
}
|
|
566
570
|
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
567
571
|
switch(style){
|
|
568
|
-
case
|
|
569
|
-
return
|
|
570
|
-
case
|
|
571
|
-
return
|
|
572
|
-
case
|
|
573
|
-
return
|
|
572
|
+
case 'lowercase':
|
|
573
|
+
return '-.inf';
|
|
574
|
+
case 'uppercase':
|
|
575
|
+
return '-.INF';
|
|
576
|
+
case 'camelcase':
|
|
577
|
+
return '-.Inf';
|
|
574
578
|
}
|
|
575
579
|
} else if (common.isNegativeZero(object)) {
|
|
576
|
-
return
|
|
580
|
+
return '-0.0';
|
|
577
581
|
}
|
|
578
582
|
res = object.toString(10);
|
|
579
583
|
// JS stringifier can build scientific format without dots: 5e-100,
|
|
580
584
|
// while YAML requres dot: 5.e-100. Fix it with simple hack
|
|
581
|
-
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace(
|
|
585
|
+
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
|
|
582
586
|
}
|
|
583
587
|
function isFloat(object) {
|
|
584
|
-
return Object.prototype.toString.call(object) ===
|
|
588
|
+
return Object.prototype.toString.call(object) === '[object Number]' && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
585
589
|
}
|
|
586
|
-
var float = new type(
|
|
587
|
-
kind:
|
|
590
|
+
var float = new type('tag:yaml.org,2002:float', {
|
|
591
|
+
kind: 'scalar',
|
|
588
592
|
resolve: resolveYamlFloat,
|
|
589
593
|
construct: constructYamlFloat,
|
|
590
594
|
predicate: isFloat,
|
|
591
595
|
represent: representYamlFloat,
|
|
592
|
-
defaultStyle:
|
|
596
|
+
defaultStyle: 'lowercase'
|
|
593
597
|
});
|
|
594
598
|
var json = failsafe.extend({
|
|
595
599
|
implicit: [
|
|
@@ -600,19 +604,19 @@ var json = failsafe.extend({
|
|
|
600
604
|
]
|
|
601
605
|
});
|
|
602
606
|
var core = json;
|
|
603
|
-
var YAML_DATE_REGEXP = new RegExp(
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
var YAML_TIMESTAMP_REGEXP = new RegExp(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
607
|
+
var YAML_DATE_REGEXP = new RegExp('^([0-9][0-9][0-9][0-9])' + // [1] year
|
|
608
|
+
'-([0-9][0-9])' + // [2] month
|
|
609
|
+
'-([0-9][0-9])$'); // [3] day
|
|
610
|
+
var YAML_TIMESTAMP_REGEXP = new RegExp('^([0-9][0-9][0-9][0-9])' + // [1] year
|
|
611
|
+
'-([0-9][0-9]?)' + // [2] month
|
|
612
|
+
'-([0-9][0-9]?)' + // [3] day
|
|
613
|
+
'(?:[Tt]|[ \\t]+)' + // ...
|
|
614
|
+
'([0-9][0-9]?)' + // [4] hour
|
|
615
|
+
':([0-9][0-9])' + // [5] minute
|
|
616
|
+
':([0-9][0-9])' + // [6] second
|
|
617
|
+
'(?:\\.([0-9]*))?' + // [7] fraction
|
|
618
|
+
'(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
|
|
619
|
+
'(?::([0-9][0-9]))?))?$'); // [11] tz_minute
|
|
616
620
|
function resolveYamlTimestamp(data) {
|
|
617
621
|
if (data === null) return false;
|
|
618
622
|
if (YAML_DATE_REGEXP.exec(data) !== null) return true;
|
|
@@ -623,7 +627,7 @@ function constructYamlTimestamp(data) {
|
|
|
623
627
|
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
624
628
|
match = YAML_DATE_REGEXP.exec(data);
|
|
625
629
|
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
626
|
-
if (match === null) throw new Error(
|
|
630
|
+
if (match === null) throw new Error('Date resolve error');
|
|
627
631
|
// match: [1] year [2] month [3] day
|
|
628
632
|
year = +match[1];
|
|
629
633
|
month = +match[2] - 1; // JS month starts with 0
|
|
@@ -638,7 +642,7 @@ function constructYamlTimestamp(data) {
|
|
|
638
642
|
if (match[7]) {
|
|
639
643
|
fraction = match[7].slice(0, 3);
|
|
640
644
|
while(fraction.length < 3){
|
|
641
|
-
fraction +=
|
|
645
|
+
fraction += '0';
|
|
642
646
|
}
|
|
643
647
|
fraction = +fraction;
|
|
644
648
|
}
|
|
@@ -647,7 +651,7 @@ function constructYamlTimestamp(data) {
|
|
|
647
651
|
tz_hour = +match[10];
|
|
648
652
|
tz_minute = +(match[11] || 0);
|
|
649
653
|
delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
|
|
650
|
-
if (match[9] ===
|
|
654
|
+
if (match[9] === '-') delta = -delta;
|
|
651
655
|
}
|
|
652
656
|
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
653
657
|
if (delta) date.setTime(date.getTime() - delta);
|
|
@@ -656,22 +660,22 @@ function constructYamlTimestamp(data) {
|
|
|
656
660
|
function representYamlTimestamp(object /*, style*/ ) {
|
|
657
661
|
return object.toISOString();
|
|
658
662
|
}
|
|
659
|
-
var timestamp = new type(
|
|
660
|
-
kind:
|
|
663
|
+
var timestamp = new type('tag:yaml.org,2002:timestamp', {
|
|
664
|
+
kind: 'scalar',
|
|
661
665
|
resolve: resolveYamlTimestamp,
|
|
662
666
|
construct: constructYamlTimestamp,
|
|
663
667
|
instanceOf: Date,
|
|
664
668
|
represent: representYamlTimestamp
|
|
665
669
|
});
|
|
666
670
|
function resolveYamlMerge(data) {
|
|
667
|
-
return data ===
|
|
671
|
+
return data === '<<' || data === null;
|
|
668
672
|
}
|
|
669
|
-
var merge = new type(
|
|
670
|
-
kind:
|
|
673
|
+
var merge = new type('tag:yaml.org,2002:merge', {
|
|
674
|
+
kind: 'scalar',
|
|
671
675
|
resolve: resolveYamlMerge
|
|
672
676
|
});
|
|
673
677
|
/*eslint-disable no-bitwise*/ // [ 64, 65, 66 ] -> [ padding, CR, LF ]
|
|
674
|
-
var BASE64_MAP =
|
|
678
|
+
var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
|
|
675
679
|
function resolveYamlBinary(data) {
|
|
676
680
|
if (data === null) return false;
|
|
677
681
|
var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
|
|
@@ -688,7 +692,7 @@ function resolveYamlBinary(data) {
|
|
|
688
692
|
return bitlen % 8 === 0;
|
|
689
693
|
}
|
|
690
694
|
function constructYamlBinary(data) {
|
|
691
|
-
var idx, tailbits, input = data.replace(/[\r\n=]/g,
|
|
695
|
+
var idx, tailbits, input = data.replace(/[\r\n=]/g, ''), max = input.length, map = BASE64_MAP, bits = 0, result = [];
|
|
692
696
|
// Collect by 6*4 bits (3 bytes)
|
|
693
697
|
for(idx = 0; idx < max; idx++){
|
|
694
698
|
if (idx % 4 === 0 && idx) {
|
|
@@ -713,7 +717,7 @@ function constructYamlBinary(data) {
|
|
|
713
717
|
return new Uint8Array(result);
|
|
714
718
|
}
|
|
715
719
|
function representYamlBinary(object /*, style*/ ) {
|
|
716
|
-
var result =
|
|
720
|
+
var result = '', bits = 0, idx, tail, max = object.length, map = BASE64_MAP;
|
|
717
721
|
// Convert every three bytes to 4 ASCII characters.
|
|
718
722
|
for(idx = 0; idx < max; idx++){
|
|
719
723
|
if (idx % 3 === 0 && idx) {
|
|
@@ -745,10 +749,10 @@ function representYamlBinary(object /*, style*/ ) {
|
|
|
745
749
|
return result;
|
|
746
750
|
}
|
|
747
751
|
function isBinary(obj) {
|
|
748
|
-
return Object.prototype.toString.call(obj) ===
|
|
752
|
+
return Object.prototype.toString.call(obj) === '[object Uint8Array]';
|
|
749
753
|
}
|
|
750
|
-
var binary = new type(
|
|
751
|
-
kind:
|
|
754
|
+
var binary = new type('tag:yaml.org,2002:binary', {
|
|
755
|
+
kind: 'scalar',
|
|
752
756
|
resolve: resolveYamlBinary,
|
|
753
757
|
construct: constructYamlBinary,
|
|
754
758
|
predicate: isBinary,
|
|
@@ -762,7 +766,7 @@ function resolveYamlOmap(data) {
|
|
|
762
766
|
for(index = 0, length = object.length; index < length; index += 1){
|
|
763
767
|
pair = object[index];
|
|
764
768
|
pairHasKey = false;
|
|
765
|
-
if (_toString$2.call(pair) !==
|
|
769
|
+
if (_toString$2.call(pair) !== '[object Object]') return false;
|
|
766
770
|
for(pairKey in pair){
|
|
767
771
|
if (_hasOwnProperty$3.call(pair, pairKey)) {
|
|
768
772
|
if (!pairHasKey) pairHasKey = true;
|
|
@@ -778,8 +782,8 @@ function resolveYamlOmap(data) {
|
|
|
778
782
|
function constructYamlOmap(data) {
|
|
779
783
|
return data !== null ? data : [];
|
|
780
784
|
}
|
|
781
|
-
var omap = new type(
|
|
782
|
-
kind:
|
|
785
|
+
var omap = new type('tag:yaml.org,2002:omap', {
|
|
786
|
+
kind: 'sequence',
|
|
783
787
|
resolve: resolveYamlOmap,
|
|
784
788
|
construct: constructYamlOmap
|
|
785
789
|
});
|
|
@@ -790,7 +794,7 @@ function resolveYamlPairs(data) {
|
|
|
790
794
|
result = new Array(object.length);
|
|
791
795
|
for(index = 0, length = object.length; index < length; index += 1){
|
|
792
796
|
pair = object[index];
|
|
793
|
-
if (_toString$1.call(pair) !==
|
|
797
|
+
if (_toString$1.call(pair) !== '[object Object]') return false;
|
|
794
798
|
keys = Object.keys(pair);
|
|
795
799
|
if (keys.length !== 1) return false;
|
|
796
800
|
result[index] = [
|
|
@@ -814,8 +818,8 @@ function constructYamlPairs(data) {
|
|
|
814
818
|
}
|
|
815
819
|
return result;
|
|
816
820
|
}
|
|
817
|
-
var pairs = new type(
|
|
818
|
-
kind:
|
|
821
|
+
var pairs = new type('tag:yaml.org,2002:pairs', {
|
|
822
|
+
kind: 'sequence',
|
|
819
823
|
resolve: resolveYamlPairs,
|
|
820
824
|
construct: constructYamlPairs
|
|
821
825
|
});
|
|
@@ -833,8 +837,8 @@ function resolveYamlSet(data) {
|
|
|
833
837
|
function constructYamlSet(data) {
|
|
834
838
|
return data !== null ? data : {};
|
|
835
839
|
}
|
|
836
|
-
var set = new type(
|
|
837
|
-
kind:
|
|
840
|
+
var set = new type('tag:yaml.org,2002:set', {
|
|
841
|
+
kind: 'mapping',
|
|
838
842
|
resolve: resolveYamlSet,
|
|
839
843
|
construct: constructYamlSet
|
|
840
844
|
});
|
|
@@ -908,7 +912,7 @@ function fromDecimalCode(c) {
|
|
|
908
912
|
return -1;
|
|
909
913
|
}
|
|
910
914
|
function simpleEscapeSequence(c) {
|
|
911
|
-
/* eslint-disable indent */ return c === 0x30 /* 0 */ ?
|
|
915
|
+
/* eslint-disable indent */ return c === 0x30 /* 0 */ ? '\x00' : c === 0x61 /* a */ ? '\x07' : c === 0x62 /* b */ ? '\x08' : c === 0x74 /* t */ ? '\x09' : c === 0x09 /* Tab */ ? '\x09' : c === 0x6E /* n */ ? '\x0A' : c === 0x76 /* v */ ? '\x0B' : c === 0x66 /* f */ ? '\x0C' : c === 0x72 /* r */ ? '\x0D' : c === 0x65 /* e */ ? '\x1B' : c === 0x20 /* Space */ ? ' ' : c === 0x22 /* " */ ? '\x22' : c === 0x2F /* / */ ? '/' : c === 0x5C /* \ */ ? '\x5C' : c === 0x4E /* N */ ? '\x85' : c === 0x5F /* _ */ ? '\xA0' : c === 0x4C /* L */ ? '\u2028' : c === 0x50 /* P */ ? '\u2029' : '';
|
|
912
916
|
}
|
|
913
917
|
function charFromCodepoint(c) {
|
|
914
918
|
if (c <= 0xFFFF) {
|
|
@@ -926,14 +930,14 @@ for(var i = 0; i < 256; i++){
|
|
|
926
930
|
}
|
|
927
931
|
function State$1(input, options) {
|
|
928
932
|
this.input = input;
|
|
929
|
-
this.filename = options[
|
|
930
|
-
this.schema = options[
|
|
931
|
-
this.onWarning = options[
|
|
933
|
+
this.filename = options['filename'] || null;
|
|
934
|
+
this.schema = options['schema'] || _default;
|
|
935
|
+
this.onWarning = options['onWarning'] || null;
|
|
932
936
|
// (Hidden) Remove? makes the loader to expect YAML 1.1 documents
|
|
933
937
|
// if such documents have no explicit %YAML directive
|
|
934
|
-
this.legacy = options[
|
|
935
|
-
this.json = options[
|
|
936
|
-
this.listener = options[
|
|
938
|
+
this.legacy = options['legacy'] || false;
|
|
939
|
+
this.json = options['json'] || false;
|
|
940
|
+
this.listener = options['listener'] || null;
|
|
937
941
|
this.implicitTypes = this.schema.compiledImplicit;
|
|
938
942
|
this.typeMap = this.schema.compiledTypeMap;
|
|
939
943
|
this.length = input.length;
|
|
@@ -977,46 +981,46 @@ var directiveHandlers = {
|
|
|
977
981
|
YAML: function handleYamlDirective(state, name, args) {
|
|
978
982
|
var match, major, minor;
|
|
979
983
|
if (state.version !== null) {
|
|
980
|
-
throwError(state,
|
|
984
|
+
throwError(state, 'duplication of %YAML directive');
|
|
981
985
|
}
|
|
982
986
|
if (args.length !== 1) {
|
|
983
|
-
throwError(state,
|
|
987
|
+
throwError(state, 'YAML directive accepts exactly one argument');
|
|
984
988
|
}
|
|
985
989
|
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
986
990
|
if (match === null) {
|
|
987
|
-
throwError(state,
|
|
991
|
+
throwError(state, 'ill-formed argument of the YAML directive');
|
|
988
992
|
}
|
|
989
993
|
major = parseInt(match[1], 10);
|
|
990
994
|
minor = parseInt(match[2], 10);
|
|
991
995
|
if (major !== 1) {
|
|
992
|
-
throwError(state,
|
|
996
|
+
throwError(state, 'unacceptable YAML version of the document');
|
|
993
997
|
}
|
|
994
998
|
state.version = args[0];
|
|
995
999
|
state.checkLineBreaks = minor < 2;
|
|
996
1000
|
if (minor !== 1 && minor !== 2) {
|
|
997
|
-
throwWarning(state,
|
|
1001
|
+
throwWarning(state, 'unsupported YAML version of the document');
|
|
998
1002
|
}
|
|
999
1003
|
},
|
|
1000
1004
|
TAG: function handleTagDirective(state, name, args) {
|
|
1001
1005
|
var handle, prefix;
|
|
1002
1006
|
if (args.length !== 2) {
|
|
1003
|
-
throwError(state,
|
|
1007
|
+
throwError(state, 'TAG directive accepts exactly two arguments');
|
|
1004
1008
|
}
|
|
1005
1009
|
handle = args[0];
|
|
1006
1010
|
prefix = args[1];
|
|
1007
1011
|
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
1008
|
-
throwError(state,
|
|
1012
|
+
throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
|
|
1009
1013
|
}
|
|
1010
1014
|
if (_hasOwnProperty$1.call(state.tagMap, handle)) {
|
|
1011
1015
|
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
1012
1016
|
}
|
|
1013
1017
|
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
1014
|
-
throwError(state,
|
|
1018
|
+
throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
|
|
1015
1019
|
}
|
|
1016
1020
|
try {
|
|
1017
1021
|
prefix = decodeURIComponent(prefix);
|
|
1018
1022
|
} catch (err) {
|
|
1019
|
-
throwError(state,
|
|
1023
|
+
throwError(state, 'tag prefix is malformed: ' + prefix);
|
|
1020
1024
|
}
|
|
1021
1025
|
state.tagMap[handle] = prefix;
|
|
1022
1026
|
}
|
|
@@ -1029,11 +1033,11 @@ function captureSegment(state, start, end, checkJson) {
|
|
|
1029
1033
|
for(_position = 0, _length = _result.length; _position < _length; _position += 1){
|
|
1030
1034
|
_character = _result.charCodeAt(_position);
|
|
1031
1035
|
if (!(_character === 0x09 || 0x20 <= _character && _character <= 0x10FFFF)) {
|
|
1032
|
-
throwError(state,
|
|
1036
|
+
throwError(state, 'expected valid JSON character');
|
|
1033
1037
|
}
|
|
1034
1038
|
}
|
|
1035
1039
|
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
1036
|
-
throwError(state,
|
|
1040
|
+
throwError(state, 'the stream contains non-printable characters');
|
|
1037
1041
|
}
|
|
1038
1042
|
state.result += _result;
|
|
1039
1043
|
}
|
|
@@ -1041,7 +1045,7 @@ function captureSegment(state, start, end, checkJson) {
|
|
|
1041
1045
|
function mergeMappings(state, destination, source, overridableKeys) {
|
|
1042
1046
|
var sourceKeys, key, index, quantity;
|
|
1043
1047
|
if (!common.isObject(source)) {
|
|
1044
|
-
throwError(state,
|
|
1048
|
+
throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
|
|
1045
1049
|
}
|
|
1046
1050
|
sourceKeys = Object.keys(source);
|
|
1047
1051
|
for(index = 0, quantity = sourceKeys.length; index < quantity; index += 1){
|
|
@@ -1061,24 +1065,24 @@ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valu
|
|
|
1061
1065
|
keyNode = Array.prototype.slice.call(keyNode);
|
|
1062
1066
|
for(index = 0, quantity = keyNode.length; index < quantity; index += 1){
|
|
1063
1067
|
if (Array.isArray(keyNode[index])) {
|
|
1064
|
-
throwError(state,
|
|
1068
|
+
throwError(state, 'nested arrays are not supported inside keys');
|
|
1065
1069
|
}
|
|
1066
|
-
if (typeof keyNode === "
|
|
1067
|
-
keyNode[index] =
|
|
1070
|
+
if ((typeof keyNode === "undefined" ? "undefined" : _type_of(keyNode)) === 'object' && _class(keyNode[index]) === '[object Object]') {
|
|
1071
|
+
keyNode[index] = '[object Object]';
|
|
1068
1072
|
}
|
|
1069
1073
|
}
|
|
1070
1074
|
}
|
|
1071
1075
|
// Avoid code execution in load() via toString property
|
|
1072
1076
|
// (still use its own toString for arrays, timestamps,
|
|
1073
1077
|
// and whatever user schema extensions happen to have @@toStringTag)
|
|
1074
|
-
if (typeof keyNode === "
|
|
1075
|
-
keyNode =
|
|
1078
|
+
if ((typeof keyNode === "undefined" ? "undefined" : _type_of(keyNode)) === 'object' && _class(keyNode) === '[object Object]') {
|
|
1079
|
+
keyNode = '[object Object]';
|
|
1076
1080
|
}
|
|
1077
1081
|
keyNode = String(keyNode);
|
|
1078
1082
|
if (_result === null) {
|
|
1079
1083
|
_result = {};
|
|
1080
1084
|
}
|
|
1081
|
-
if (keyTag ===
|
|
1085
|
+
if (keyTag === 'tag:yaml.org,2002:merge') {
|
|
1082
1086
|
if (Array.isArray(valueNode)) {
|
|
1083
1087
|
for(index = 0, quantity = valueNode.length; index < quantity; index += 1){
|
|
1084
1088
|
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
@@ -1091,10 +1095,10 @@ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valu
|
|
|
1091
1095
|
state.line = startLine || state.line;
|
|
1092
1096
|
state.lineStart = startLineStart || state.lineStart;
|
|
1093
1097
|
state.position = startPos || state.position;
|
|
1094
|
-
throwError(state,
|
|
1098
|
+
throwError(state, 'duplicated mapping key');
|
|
1095
1099
|
}
|
|
1096
1100
|
// used for this specific key only because Object.defineProperty is slow
|
|
1097
|
-
if (keyNode ===
|
|
1101
|
+
if (keyNode === '__proto__') {
|
|
1098
1102
|
Object.defineProperty(_result, keyNode, {
|
|
1099
1103
|
configurable: true,
|
|
1100
1104
|
enumerable: true,
|
|
@@ -1119,7 +1123,7 @@ function readLineBreak(state) {
|
|
|
1119
1123
|
state.position++;
|
|
1120
1124
|
}
|
|
1121
1125
|
} else {
|
|
1122
|
-
throwError(state,
|
|
1126
|
+
throwError(state, 'a line break is expected');
|
|
1123
1127
|
}
|
|
1124
1128
|
state.line += 1;
|
|
1125
1129
|
state.lineStart = state.position;
|
|
@@ -1153,7 +1157,7 @@ function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
|
1153
1157
|
}
|
|
1154
1158
|
}
|
|
1155
1159
|
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
1156
|
-
throwWarning(state,
|
|
1160
|
+
throwWarning(state, 'deficient indentation');
|
|
1157
1161
|
}
|
|
1158
1162
|
return lineBreaks;
|
|
1159
1163
|
}
|
|
@@ -1173,9 +1177,9 @@ function testDocumentSeparator(state) {
|
|
|
1173
1177
|
}
|
|
1174
1178
|
function writeFoldedLines(state, count) {
|
|
1175
1179
|
if (count === 1) {
|
|
1176
|
-
state.result +=
|
|
1180
|
+
state.result += ' ';
|
|
1177
1181
|
} else if (count > 1) {
|
|
1178
|
-
state.result += common.repeat(
|
|
1182
|
+
state.result += common.repeat('\n', count - 1);
|
|
1179
1183
|
}
|
|
1180
1184
|
}
|
|
1181
1185
|
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
@@ -1190,8 +1194,8 @@ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
|
1190
1194
|
return false;
|
|
1191
1195
|
}
|
|
1192
1196
|
}
|
|
1193
|
-
state.kind =
|
|
1194
|
-
state.result =
|
|
1197
|
+
state.kind = 'scalar';
|
|
1198
|
+
state.result = '';
|
|
1195
1199
|
captureStart = captureEnd = state.position;
|
|
1196
1200
|
hasPendingContent = false;
|
|
1197
1201
|
while(ch !== 0){
|
|
@@ -1249,8 +1253,8 @@ function readSingleQuotedScalar(state, nodeIndent) {
|
|
|
1249
1253
|
if (ch !== 0x27 /* ' */ ) {
|
|
1250
1254
|
return false;
|
|
1251
1255
|
}
|
|
1252
|
-
state.kind =
|
|
1253
|
-
state.result =
|
|
1256
|
+
state.kind = 'scalar';
|
|
1257
|
+
state.result = '';
|
|
1254
1258
|
state.position++;
|
|
1255
1259
|
captureStart = captureEnd = state.position;
|
|
1256
1260
|
while((ch = state.input.charCodeAt(state.position)) !== 0){
|
|
@@ -1269,13 +1273,13 @@ function readSingleQuotedScalar(state, nodeIndent) {
|
|
|
1269
1273
|
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1270
1274
|
captureStart = captureEnd = state.position;
|
|
1271
1275
|
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1272
|
-
throwError(state,
|
|
1276
|
+
throwError(state, 'unexpected end of the document within a single quoted scalar');
|
|
1273
1277
|
} else {
|
|
1274
1278
|
state.position++;
|
|
1275
1279
|
captureEnd = state.position;
|
|
1276
1280
|
}
|
|
1277
1281
|
}
|
|
1278
|
-
throwError(state,
|
|
1282
|
+
throwError(state, 'unexpected end of the stream within a single quoted scalar');
|
|
1279
1283
|
}
|
|
1280
1284
|
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
1281
1285
|
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
@@ -1283,8 +1287,8 @@ function readDoubleQuotedScalar(state, nodeIndent) {
|
|
|
1283
1287
|
if (ch !== 0x22 /* " */ ) {
|
|
1284
1288
|
return false;
|
|
1285
1289
|
}
|
|
1286
|
-
state.kind =
|
|
1287
|
-
state.result =
|
|
1290
|
+
state.kind = 'scalar';
|
|
1291
|
+
state.result = '';
|
|
1288
1292
|
state.position++;
|
|
1289
1293
|
captureStart = captureEnd = state.position;
|
|
1290
1294
|
while((ch = state.input.charCodeAt(state.position)) !== 0){
|
|
@@ -1309,13 +1313,13 @@ function readDoubleQuotedScalar(state, nodeIndent) {
|
|
|
1309
1313
|
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
1310
1314
|
hexResult = (hexResult << 4) + tmp;
|
|
1311
1315
|
} else {
|
|
1312
|
-
throwError(state,
|
|
1316
|
+
throwError(state, 'expected hexadecimal character');
|
|
1313
1317
|
}
|
|
1314
1318
|
}
|
|
1315
1319
|
state.result += charFromCodepoint(hexResult);
|
|
1316
1320
|
state.position++;
|
|
1317
1321
|
} else {
|
|
1318
|
-
throwError(state,
|
|
1322
|
+
throwError(state, 'unknown escape sequence');
|
|
1319
1323
|
}
|
|
1320
1324
|
captureStart = captureEnd = state.position;
|
|
1321
1325
|
} else if (is_EOL(ch)) {
|
|
@@ -1323,13 +1327,13 @@ function readDoubleQuotedScalar(state, nodeIndent) {
|
|
|
1323
1327
|
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1324
1328
|
captureStart = captureEnd = state.position;
|
|
1325
1329
|
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1326
|
-
throwError(state,
|
|
1330
|
+
throwError(state, 'unexpected end of the document within a double quoted scalar');
|
|
1327
1331
|
} else {
|
|
1328
1332
|
state.position++;
|
|
1329
1333
|
captureEnd = state.position;
|
|
1330
1334
|
}
|
|
1331
1335
|
}
|
|
1332
|
-
throwError(state,
|
|
1336
|
+
throwError(state, 'unexpected end of the stream within a double quoted scalar');
|
|
1333
1337
|
}
|
|
1334
1338
|
function readFlowCollection(state, nodeIndent) {
|
|
1335
1339
|
var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = Object.create(null), keyNode, keyTag, valueNode, ch;
|
|
@@ -1356,11 +1360,11 @@ function readFlowCollection(state, nodeIndent) {
|
|
|
1356
1360
|
state.position++;
|
|
1357
1361
|
state.tag = _tag;
|
|
1358
1362
|
state.anchor = _anchor;
|
|
1359
|
-
state.kind = isMapping ?
|
|
1363
|
+
state.kind = isMapping ? 'mapping' : 'sequence';
|
|
1360
1364
|
state.result = _result;
|
|
1361
1365
|
return true;
|
|
1362
1366
|
} else if (!readNext) {
|
|
1363
|
-
throwError(state,
|
|
1367
|
+
throwError(state, 'missed comma between flow collection entries');
|
|
1364
1368
|
} else if (ch === 0x2C /* , */ ) {
|
|
1365
1369
|
// "flow collection entries can never be completely empty", as per YAML 1.2, section 7.4
|
|
1366
1370
|
throwError(state, "expected the node content, but found ','");
|
|
@@ -1406,7 +1410,7 @@ function readFlowCollection(state, nodeIndent) {
|
|
|
1406
1410
|
readNext = false;
|
|
1407
1411
|
}
|
|
1408
1412
|
}
|
|
1409
|
-
throwError(state,
|
|
1413
|
+
throwError(state, 'unexpected end of the stream within a flow collection');
|
|
1410
1414
|
}
|
|
1411
1415
|
function readBlockScalar(state, nodeIndent) {
|
|
1412
1416
|
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
@@ -1418,24 +1422,24 @@ function readBlockScalar(state, nodeIndent) {
|
|
|
1418
1422
|
} else {
|
|
1419
1423
|
return false;
|
|
1420
1424
|
}
|
|
1421
|
-
state.kind =
|
|
1422
|
-
state.result =
|
|
1425
|
+
state.kind = 'scalar';
|
|
1426
|
+
state.result = '';
|
|
1423
1427
|
while(ch !== 0){
|
|
1424
1428
|
ch = state.input.charCodeAt(++state.position);
|
|
1425
1429
|
if (ch === 0x2B /* + */ || ch === 0x2D /* - */ ) {
|
|
1426
1430
|
if (CHOMPING_CLIP === chomping) {
|
|
1427
1431
|
chomping = ch === 0x2B /* + */ ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
1428
1432
|
} else {
|
|
1429
|
-
throwError(state,
|
|
1433
|
+
throwError(state, 'repeat of a chomping mode identifier');
|
|
1430
1434
|
}
|
|
1431
1435
|
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
1432
1436
|
if (tmp === 0) {
|
|
1433
|
-
throwError(state,
|
|
1437
|
+
throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
|
|
1434
1438
|
} else if (!detectedIndent) {
|
|
1435
1439
|
textIndent = nodeIndent + tmp - 1;
|
|
1436
1440
|
detectedIndent = true;
|
|
1437
1441
|
} else {
|
|
1438
|
-
throwError(state,
|
|
1442
|
+
throwError(state, 'repeat of an indentation width identifier');
|
|
1439
1443
|
}
|
|
1440
1444
|
} else {
|
|
1441
1445
|
break;
|
|
@@ -1470,10 +1474,10 @@ function readBlockScalar(state, nodeIndent) {
|
|
|
1470
1474
|
if (state.lineIndent < textIndent) {
|
|
1471
1475
|
// Perform the chomping.
|
|
1472
1476
|
if (chomping === CHOMPING_KEEP) {
|
|
1473
|
-
state.result += common.repeat(
|
|
1477
|
+
state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
|
1474
1478
|
} else if (chomping === CHOMPING_CLIP) {
|
|
1475
1479
|
if (didReadContent) {
|
|
1476
|
-
state.result +=
|
|
1480
|
+
state.result += '\n';
|
|
1477
1481
|
}
|
|
1478
1482
|
}
|
|
1479
1483
|
break;
|
|
@@ -1484,24 +1488,24 @@ function readBlockScalar(state, nodeIndent) {
|
|
|
1484
1488
|
if (is_WHITE_SPACE(ch)) {
|
|
1485
1489
|
atMoreIndented = true;
|
|
1486
1490
|
// except for the first content line (cf. Example 8.1)
|
|
1487
|
-
state.result += common.repeat(
|
|
1491
|
+
state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
|
1488
1492
|
// End of more-indented block.
|
|
1489
1493
|
} else if (atMoreIndented) {
|
|
1490
1494
|
atMoreIndented = false;
|
|
1491
|
-
state.result += common.repeat(
|
|
1495
|
+
state.result += common.repeat('\n', emptyLines + 1);
|
|
1492
1496
|
// Just one line break - perceive as the same line.
|
|
1493
1497
|
} else if (emptyLines === 0) {
|
|
1494
1498
|
if (didReadContent) {
|
|
1495
|
-
state.result +=
|
|
1499
|
+
state.result += ' ';
|
|
1496
1500
|
}
|
|
1497
1501
|
// Several line breaks - perceive as different lines.
|
|
1498
1502
|
} else {
|
|
1499
|
-
state.result += common.repeat(
|
|
1503
|
+
state.result += common.repeat('\n', emptyLines);
|
|
1500
1504
|
}
|
|
1501
1505
|
// Literal style: just add exact number of line breaks between content lines.
|
|
1502
1506
|
} else {
|
|
1503
1507
|
// Keep all line breaks except the header line break.
|
|
1504
|
-
state.result += common.repeat(
|
|
1508
|
+
state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
|
1505
1509
|
}
|
|
1506
1510
|
didReadContent = true;
|
|
1507
1511
|
detectedIndent = true;
|
|
@@ -1526,7 +1530,7 @@ function readBlockSequence(state, nodeIndent) {
|
|
|
1526
1530
|
while(ch !== 0){
|
|
1527
1531
|
if (state.firstTabInLine !== -1) {
|
|
1528
1532
|
state.position = state.firstTabInLine;
|
|
1529
|
-
throwError(state,
|
|
1533
|
+
throwError(state, 'tab characters must not be used in indentation');
|
|
1530
1534
|
}
|
|
1531
1535
|
if (ch !== 0x2D /* - */ ) {
|
|
1532
1536
|
break;
|
|
@@ -1550,7 +1554,7 @@ function readBlockSequence(state, nodeIndent) {
|
|
|
1550
1554
|
skipSeparationSpace(state, true, -1);
|
|
1551
1555
|
ch = state.input.charCodeAt(state.position);
|
|
1552
1556
|
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1553
|
-
throwError(state,
|
|
1557
|
+
throwError(state, 'bad indentation of a sequence entry');
|
|
1554
1558
|
} else if (state.lineIndent < nodeIndent) {
|
|
1555
1559
|
break;
|
|
1556
1560
|
}
|
|
@@ -1558,7 +1562,7 @@ function readBlockSequence(state, nodeIndent) {
|
|
|
1558
1562
|
if (detected) {
|
|
1559
1563
|
state.tag = _tag;
|
|
1560
1564
|
state.anchor = _anchor;
|
|
1561
|
-
state.kind =
|
|
1565
|
+
state.kind = 'sequence';
|
|
1562
1566
|
state.result = _result;
|
|
1563
1567
|
return true;
|
|
1564
1568
|
}
|
|
@@ -1576,7 +1580,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1576
1580
|
while(ch !== 0){
|
|
1577
1581
|
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
1578
1582
|
state.position = state.firstTabInLine;
|
|
1579
|
-
throwError(state,
|
|
1583
|
+
throwError(state, 'tab characters must not be used in indentation');
|
|
1580
1584
|
}
|
|
1581
1585
|
following = state.input.charCodeAt(state.position + 1);
|
|
1582
1586
|
_line = state.line; // Save the current line.
|
|
@@ -1598,7 +1602,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1598
1602
|
atExplicitKey = false;
|
|
1599
1603
|
allowCompact = true;
|
|
1600
1604
|
} else {
|
|
1601
|
-
throwError(state,
|
|
1605
|
+
throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
|
|
1602
1606
|
}
|
|
1603
1607
|
state.position += 1;
|
|
1604
1608
|
ch = following;
|
|
@@ -1620,7 +1624,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1620
1624
|
if (ch === 0x3A /* : */ ) {
|
|
1621
1625
|
ch = state.input.charCodeAt(++state.position);
|
|
1622
1626
|
if (!is_WS_OR_EOL(ch)) {
|
|
1623
|
-
throwError(state,
|
|
1627
|
+
throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
|
|
1624
1628
|
}
|
|
1625
1629
|
if (atExplicitKey) {
|
|
1626
1630
|
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
@@ -1632,14 +1636,14 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1632
1636
|
keyTag = state.tag;
|
|
1633
1637
|
keyNode = state.result;
|
|
1634
1638
|
} else if (detected) {
|
|
1635
|
-
throwError(state,
|
|
1639
|
+
throwError(state, 'can not read an implicit mapping pair; a colon is missed');
|
|
1636
1640
|
} else {
|
|
1637
1641
|
state.tag = _tag;
|
|
1638
1642
|
state.anchor = _anchor;
|
|
1639
1643
|
return true; // Keep the result of `composeNode`.
|
|
1640
1644
|
}
|
|
1641
1645
|
} else if (detected) {
|
|
1642
|
-
throwError(state,
|
|
1646
|
+
throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
|
|
1643
1647
|
} else {
|
|
1644
1648
|
state.tag = _tag;
|
|
1645
1649
|
state.anchor = _anchor;
|
|
@@ -1670,7 +1674,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1670
1674
|
ch = state.input.charCodeAt(state.position);
|
|
1671
1675
|
}
|
|
1672
1676
|
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1673
|
-
throwError(state,
|
|
1677
|
+
throwError(state, 'bad indentation of a mapping entry');
|
|
1674
1678
|
} else if (state.lineIndent < nodeIndent) {
|
|
1675
1679
|
break;
|
|
1676
1680
|
}
|
|
@@ -1686,7 +1690,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1686
1690
|
if (detected) {
|
|
1687
1691
|
state.tag = _tag;
|
|
1688
1692
|
state.anchor = _anchor;
|
|
1689
|
-
state.kind =
|
|
1693
|
+
state.kind = 'mapping';
|
|
1690
1694
|
state.result = _result;
|
|
1691
1695
|
}
|
|
1692
1696
|
return detected;
|
|
@@ -1696,7 +1700,7 @@ function readTagProperty(state) {
|
|
|
1696
1700
|
ch = state.input.charCodeAt(state.position);
|
|
1697
1701
|
if (ch !== 0x21 /* ! */ ) return false;
|
|
1698
1702
|
if (state.tag !== null) {
|
|
1699
|
-
throwError(state,
|
|
1703
|
+
throwError(state, 'duplication of a tag property');
|
|
1700
1704
|
}
|
|
1701
1705
|
ch = state.input.charCodeAt(++state.position);
|
|
1702
1706
|
if (ch === 0x3C /* < */ ) {
|
|
@@ -1704,10 +1708,10 @@ function readTagProperty(state) {
|
|
|
1704
1708
|
ch = state.input.charCodeAt(++state.position);
|
|
1705
1709
|
} else if (ch === 0x21 /* ! */ ) {
|
|
1706
1710
|
isNamed = true;
|
|
1707
|
-
tagHandle =
|
|
1711
|
+
tagHandle = '!!';
|
|
1708
1712
|
ch = state.input.charCodeAt(++state.position);
|
|
1709
1713
|
} else {
|
|
1710
|
-
tagHandle =
|
|
1714
|
+
tagHandle = '!';
|
|
1711
1715
|
}
|
|
1712
1716
|
_position = state.position;
|
|
1713
1717
|
if (isVerbatim) {
|
|
@@ -1718,7 +1722,7 @@ function readTagProperty(state) {
|
|
|
1718
1722
|
tagName = state.input.slice(_position, state.position);
|
|
1719
1723
|
ch = state.input.charCodeAt(++state.position);
|
|
1720
1724
|
} else {
|
|
1721
|
-
throwError(state,
|
|
1725
|
+
throwError(state, 'unexpected end of the stream within a verbatim tag');
|
|
1722
1726
|
}
|
|
1723
1727
|
} else {
|
|
1724
1728
|
while(ch !== 0 && !is_WS_OR_EOL(ch)){
|
|
@@ -1726,37 +1730,37 @@ function readTagProperty(state) {
|
|
|
1726
1730
|
if (!isNamed) {
|
|
1727
1731
|
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
1728
1732
|
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
1729
|
-
throwError(state,
|
|
1733
|
+
throwError(state, 'named tag handle cannot contain such characters');
|
|
1730
1734
|
}
|
|
1731
1735
|
isNamed = true;
|
|
1732
1736
|
_position = state.position + 1;
|
|
1733
1737
|
} else {
|
|
1734
|
-
throwError(state,
|
|
1738
|
+
throwError(state, 'tag suffix cannot contain exclamation marks');
|
|
1735
1739
|
}
|
|
1736
1740
|
}
|
|
1737
1741
|
ch = state.input.charCodeAt(++state.position);
|
|
1738
1742
|
}
|
|
1739
1743
|
tagName = state.input.slice(_position, state.position);
|
|
1740
1744
|
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
1741
|
-
throwError(state,
|
|
1745
|
+
throwError(state, 'tag suffix cannot contain flow indicator characters');
|
|
1742
1746
|
}
|
|
1743
1747
|
}
|
|
1744
1748
|
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
1745
|
-
throwError(state,
|
|
1749
|
+
throwError(state, 'tag name cannot contain such characters: ' + tagName);
|
|
1746
1750
|
}
|
|
1747
1751
|
try {
|
|
1748
1752
|
tagName = decodeURIComponent(tagName);
|
|
1749
1753
|
} catch (err) {
|
|
1750
|
-
throwError(state,
|
|
1754
|
+
throwError(state, 'tag name is malformed: ' + tagName);
|
|
1751
1755
|
}
|
|
1752
1756
|
if (isVerbatim) {
|
|
1753
1757
|
state.tag = tagName;
|
|
1754
1758
|
} else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
|
|
1755
1759
|
state.tag = state.tagMap[tagHandle] + tagName;
|
|
1756
|
-
} else if (tagHandle ===
|
|
1757
|
-
state.tag =
|
|
1758
|
-
} else if (tagHandle ===
|
|
1759
|
-
state.tag =
|
|
1760
|
+
} else if (tagHandle === '!') {
|
|
1761
|
+
state.tag = '!' + tagName;
|
|
1762
|
+
} else if (tagHandle === '!!') {
|
|
1763
|
+
state.tag = 'tag:yaml.org,2002:' + tagName;
|
|
1760
1764
|
} else {
|
|
1761
1765
|
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
1762
1766
|
}
|
|
@@ -1767,7 +1771,7 @@ function readAnchorProperty(state) {
|
|
|
1767
1771
|
ch = state.input.charCodeAt(state.position);
|
|
1768
1772
|
if (ch !== 0x26 /* & */ ) return false;
|
|
1769
1773
|
if (state.anchor !== null) {
|
|
1770
|
-
throwError(state,
|
|
1774
|
+
throwError(state, 'duplication of an anchor property');
|
|
1771
1775
|
}
|
|
1772
1776
|
ch = state.input.charCodeAt(++state.position);
|
|
1773
1777
|
_position = state.position;
|
|
@@ -1775,7 +1779,7 @@ function readAnchorProperty(state) {
|
|
|
1775
1779
|
ch = state.input.charCodeAt(++state.position);
|
|
1776
1780
|
}
|
|
1777
1781
|
if (state.position === _position) {
|
|
1778
|
-
throwError(state,
|
|
1782
|
+
throwError(state, 'name of an anchor node must contain at least one character');
|
|
1779
1783
|
}
|
|
1780
1784
|
state.anchor = state.input.slice(_position, state.position);
|
|
1781
1785
|
return true;
|
|
@@ -1790,7 +1794,7 @@ function readAlias(state) {
|
|
|
1790
1794
|
ch = state.input.charCodeAt(++state.position);
|
|
1791
1795
|
}
|
|
1792
1796
|
if (state.position === _position) {
|
|
1793
|
-
throwError(state,
|
|
1797
|
+
throwError(state, 'name of an alias node must contain at least one character');
|
|
1794
1798
|
}
|
|
1795
1799
|
alias = state.input.slice(_position, state.position);
|
|
1796
1800
|
if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
|
|
@@ -1803,7 +1807,7 @@ function readAlias(state) {
|
|
|
1803
1807
|
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
1804
1808
|
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type, flowIndent, blockIndent;
|
|
1805
1809
|
if (state.listener !== null) {
|
|
1806
|
-
state.listener(
|
|
1810
|
+
state.listener('open', state);
|
|
1807
1811
|
}
|
|
1808
1812
|
state.tag = null;
|
|
1809
1813
|
state.anchor = null;
|
|
@@ -1858,12 +1862,12 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1858
1862
|
} else if (readAlias(state)) {
|
|
1859
1863
|
hasContent = true;
|
|
1860
1864
|
if (state.tag !== null || state.anchor !== null) {
|
|
1861
|
-
throwError(state,
|
|
1865
|
+
throwError(state, 'alias node should not have any properties');
|
|
1862
1866
|
}
|
|
1863
1867
|
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
1864
1868
|
hasContent = true;
|
|
1865
1869
|
if (state.tag === null) {
|
|
1866
|
-
state.tag =
|
|
1870
|
+
state.tag = '?';
|
|
1867
1871
|
}
|
|
1868
1872
|
}
|
|
1869
1873
|
if (state.anchor !== null) {
|
|
@@ -1880,14 +1884,14 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1880
1884
|
if (state.anchor !== null) {
|
|
1881
1885
|
state.anchorMap[state.anchor] = state.result;
|
|
1882
1886
|
}
|
|
1883
|
-
} else if (state.tag ===
|
|
1887
|
+
} else if (state.tag === '?') {
|
|
1884
1888
|
// Implicit resolving is not allowed for non-scalar types, and '?'
|
|
1885
1889
|
// non-specific tag is only automatically assigned to plain scalars.
|
|
1886
1890
|
//
|
|
1887
1891
|
// We only need to check kind conformity in case user explicitly assigns '?'
|
|
1888
1892
|
// tag, for example like this: "!<?> [0]"
|
|
1889
1893
|
//
|
|
1890
|
-
if (state.result !== null && state.kind !==
|
|
1894
|
+
if (state.result !== null && state.kind !== 'scalar') {
|
|
1891
1895
|
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
1892
1896
|
}
|
|
1893
1897
|
for(typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1){
|
|
@@ -1901,13 +1905,13 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1901
1905
|
break;
|
|
1902
1906
|
}
|
|
1903
1907
|
}
|
|
1904
|
-
} else if (state.tag !==
|
|
1905
|
-
if (_hasOwnProperty$1.call(state.typeMap[state.kind ||
|
|
1906
|
-
type = state.typeMap[state.kind ||
|
|
1908
|
+
} else if (state.tag !== '!') {
|
|
1909
|
+
if (_hasOwnProperty$1.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
|
|
1910
|
+
type = state.typeMap[state.kind || 'fallback'][state.tag];
|
|
1907
1911
|
} else {
|
|
1908
1912
|
// looking for multi type
|
|
1909
1913
|
type = null;
|
|
1910
|
-
typeList = state.typeMap.multi[state.kind ||
|
|
1914
|
+
typeList = state.typeMap.multi[state.kind || 'fallback'];
|
|
1911
1915
|
for(typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1){
|
|
1912
1916
|
if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
|
|
1913
1917
|
type = typeList[typeIndex];
|
|
@@ -1916,13 +1920,13 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1916
1920
|
}
|
|
1917
1921
|
}
|
|
1918
1922
|
if (!type) {
|
|
1919
|
-
throwError(state,
|
|
1923
|
+
throwError(state, 'unknown tag !<' + state.tag + '>');
|
|
1920
1924
|
}
|
|
1921
1925
|
if (state.result !== null && type.kind !== state.kind) {
|
|
1922
|
-
throwError(state,
|
|
1926
|
+
throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
|
|
1923
1927
|
}
|
|
1924
1928
|
if (!type.resolve(state.result, state.tag)) {
|
|
1925
|
-
throwError(state,
|
|
1929
|
+
throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
|
|
1926
1930
|
} else {
|
|
1927
1931
|
state.result = type.construct(state.result, state.tag);
|
|
1928
1932
|
if (state.anchor !== null) {
|
|
@@ -1931,7 +1935,7 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1931
1935
|
}
|
|
1932
1936
|
}
|
|
1933
1937
|
if (state.listener !== null) {
|
|
1934
|
-
state.listener(
|
|
1938
|
+
state.listener('close', state);
|
|
1935
1939
|
}
|
|
1936
1940
|
return state.tag !== null || state.anchor !== null || hasContent;
|
|
1937
1941
|
}
|
|
@@ -1956,7 +1960,7 @@ function readDocument(state) {
|
|
|
1956
1960
|
directiveName = state.input.slice(_position, state.position);
|
|
1957
1961
|
directiveArgs = [];
|
|
1958
1962
|
if (directiveName.length < 1) {
|
|
1959
|
-
throwError(state,
|
|
1963
|
+
throwError(state, 'directive name must not be less than one character in length');
|
|
1960
1964
|
}
|
|
1961
1965
|
while(ch !== 0){
|
|
1962
1966
|
while(is_WHITE_SPACE(ch)){
|
|
@@ -1987,12 +1991,12 @@ function readDocument(state) {
|
|
|
1987
1991
|
state.position += 3;
|
|
1988
1992
|
skipSeparationSpace(state, true, -1);
|
|
1989
1993
|
} else if (hasDirectives) {
|
|
1990
|
-
throwError(state,
|
|
1994
|
+
throwError(state, 'directives end mark is expected');
|
|
1991
1995
|
}
|
|
1992
1996
|
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
1993
1997
|
skipSeparationSpace(state, true, -1);
|
|
1994
1998
|
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
1995
|
-
throwWarning(state,
|
|
1999
|
+
throwWarning(state, 'non-ASCII line breaks are interpreted as content');
|
|
1996
2000
|
}
|
|
1997
2001
|
state.documents.push(state.result);
|
|
1998
2002
|
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
@@ -2003,7 +2007,7 @@ function readDocument(state) {
|
|
|
2003
2007
|
return;
|
|
2004
2008
|
}
|
|
2005
2009
|
if (state.position < state.length - 1) {
|
|
2006
|
-
throwError(state,
|
|
2010
|
+
throwError(state, 'end of the stream or a document separator is expected');
|
|
2007
2011
|
} else {
|
|
2008
2012
|
return;
|
|
2009
2013
|
}
|
|
@@ -2014,7 +2018,7 @@ function loadDocuments(input, options) {
|
|
|
2014
2018
|
if (input.length !== 0) {
|
|
2015
2019
|
// Add tailing `\n` if not exists
|
|
2016
2020
|
if (input.charCodeAt(input.length - 1) !== 0x0A /* LF */ && input.charCodeAt(input.length - 1) !== 0x0D /* CR */ ) {
|
|
2017
|
-
input +=
|
|
2021
|
+
input += '\n';
|
|
2018
2022
|
}
|
|
2019
2023
|
// Strip BOM
|
|
2020
2024
|
if (input.charCodeAt(0) === 0xFEFF) {
|
|
@@ -2022,13 +2026,13 @@ function loadDocuments(input, options) {
|
|
|
2022
2026
|
}
|
|
2023
2027
|
}
|
|
2024
2028
|
var state = new State$1(input, options);
|
|
2025
|
-
var nullpos = input.indexOf(
|
|
2029
|
+
var nullpos = input.indexOf('\0');
|
|
2026
2030
|
if (nullpos !== -1) {
|
|
2027
2031
|
state.position = nullpos;
|
|
2028
|
-
throwError(state,
|
|
2032
|
+
throwError(state, 'null byte is not allowed in input');
|
|
2029
2033
|
}
|
|
2030
2034
|
// Use 0 as string terminator. That significantly simplifies bounds check.
|
|
2031
|
-
state.input +=
|
|
2035
|
+
state.input += '\0';
|
|
2032
2036
|
while(state.input.charCodeAt(state.position) === 0x20 /* Space */ ){
|
|
2033
2037
|
state.lineIndent += 1;
|
|
2034
2038
|
state.position += 1;
|
|
@@ -2038,19 +2042,6 @@ function loadDocuments(input, options) {
|
|
|
2038
2042
|
}
|
|
2039
2043
|
return state.documents;
|
|
2040
2044
|
}
|
|
2041
|
-
function loadAll$1(input, iterator, options) {
|
|
2042
|
-
if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
|
|
2043
|
-
options = iterator;
|
|
2044
|
-
iterator = null;
|
|
2045
|
-
}
|
|
2046
|
-
var documents = loadDocuments(input, options);
|
|
2047
|
-
if (typeof iterator !== "function") {
|
|
2048
|
-
return documents;
|
|
2049
|
-
}
|
|
2050
|
-
for(var index = 0, length = documents.length; index < length; index += 1){
|
|
2051
|
-
iterator(documents[index]);
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
2045
|
function load$1(input, options) {
|
|
2055
2046
|
var documents = loadDocuments(input, options);
|
|
2056
2047
|
if (documents.length === 0) {
|
|
@@ -2058,12 +2049,10 @@ function load$1(input, options) {
|
|
|
2058
2049
|
} else if (documents.length === 1) {
|
|
2059
2050
|
return documents[0];
|
|
2060
2051
|
}
|
|
2061
|
-
throw new exception(
|
|
2052
|
+
throw new exception('expected a single document in the stream, but found more');
|
|
2062
2053
|
}
|
|
2063
|
-
var loadAll_1 = loadAll$1;
|
|
2064
2054
|
var load_1 = load$1;
|
|
2065
2055
|
var loader = {
|
|
2066
|
-
loadAll: loadAll_1,
|
|
2067
2056
|
load: load_1
|
|
2068
2057
|
};
|
|
2069
2058
|
/*eslint-disable no-use-before-define*/ var _toString = Object.prototype.toString;
|
|
@@ -2094,38 +2083,38 @@ var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
|
|
|
2094
2083
|
var CHAR_VERTICAL_LINE = 0x7C; /* | */
|
|
2095
2084
|
var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
|
|
2096
2085
|
var ESCAPE_SEQUENCES = {};
|
|
2097
|
-
ESCAPE_SEQUENCES[0x00] =
|
|
2098
|
-
ESCAPE_SEQUENCES[0x07] =
|
|
2099
|
-
ESCAPE_SEQUENCES[0x08] =
|
|
2100
|
-
ESCAPE_SEQUENCES[0x09] =
|
|
2101
|
-
ESCAPE_SEQUENCES[0x0A] =
|
|
2102
|
-
ESCAPE_SEQUENCES[0x0B] =
|
|
2103
|
-
ESCAPE_SEQUENCES[0x0C] =
|
|
2104
|
-
ESCAPE_SEQUENCES[0x0D] =
|
|
2105
|
-
ESCAPE_SEQUENCES[0x1B] =
|
|
2086
|
+
ESCAPE_SEQUENCES[0x00] = '\\0';
|
|
2087
|
+
ESCAPE_SEQUENCES[0x07] = '\\a';
|
|
2088
|
+
ESCAPE_SEQUENCES[0x08] = '\\b';
|
|
2089
|
+
ESCAPE_SEQUENCES[0x09] = '\\t';
|
|
2090
|
+
ESCAPE_SEQUENCES[0x0A] = '\\n';
|
|
2091
|
+
ESCAPE_SEQUENCES[0x0B] = '\\v';
|
|
2092
|
+
ESCAPE_SEQUENCES[0x0C] = '\\f';
|
|
2093
|
+
ESCAPE_SEQUENCES[0x0D] = '\\r';
|
|
2094
|
+
ESCAPE_SEQUENCES[0x1B] = '\\e';
|
|
2106
2095
|
ESCAPE_SEQUENCES[0x22] = '\\"';
|
|
2107
|
-
ESCAPE_SEQUENCES[0x5C] =
|
|
2108
|
-
ESCAPE_SEQUENCES[0x85] =
|
|
2109
|
-
ESCAPE_SEQUENCES[0xA0] =
|
|
2110
|
-
ESCAPE_SEQUENCES[0x2028] =
|
|
2111
|
-
ESCAPE_SEQUENCES[0x2029] =
|
|
2096
|
+
ESCAPE_SEQUENCES[0x5C] = '\\\\';
|
|
2097
|
+
ESCAPE_SEQUENCES[0x85] = '\\N';
|
|
2098
|
+
ESCAPE_SEQUENCES[0xA0] = '\\_';
|
|
2099
|
+
ESCAPE_SEQUENCES[0x2028] = '\\L';
|
|
2100
|
+
ESCAPE_SEQUENCES[0x2029] = '\\P';
|
|
2112
2101
|
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2102
|
+
'y',
|
|
2103
|
+
'Y',
|
|
2104
|
+
'yes',
|
|
2105
|
+
'Yes',
|
|
2106
|
+
'YES',
|
|
2107
|
+
'on',
|
|
2108
|
+
'On',
|
|
2109
|
+
'ON',
|
|
2110
|
+
'n',
|
|
2111
|
+
'N',
|
|
2112
|
+
'no',
|
|
2113
|
+
'No',
|
|
2114
|
+
'NO',
|
|
2115
|
+
'off',
|
|
2116
|
+
'Off',
|
|
2117
|
+
'OFF'
|
|
2129
2118
|
];
|
|
2130
2119
|
var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
|
|
2131
2120
|
function compileStyleMap(schema, map) {
|
|
@@ -2136,10 +2125,10 @@ function compileStyleMap(schema, map) {
|
|
|
2136
2125
|
for(index = 0, length = keys.length; index < length; index += 1){
|
|
2137
2126
|
tag = keys[index];
|
|
2138
2127
|
style = String(map[tag]);
|
|
2139
|
-
if (tag.slice(0, 2) ===
|
|
2140
|
-
tag =
|
|
2128
|
+
if (tag.slice(0, 2) === '!!') {
|
|
2129
|
+
tag = 'tag:yaml.org,2002:' + tag.slice(2);
|
|
2141
2130
|
}
|
|
2142
|
-
type = schema.compiledTypeMap[
|
|
2131
|
+
type = schema.compiledTypeMap['fallback'][tag];
|
|
2143
2132
|
if (type && _hasOwnProperty.call(type.styleAliases, style)) {
|
|
2144
2133
|
style = type.styleAliases[style];
|
|
2145
2134
|
}
|
|
@@ -2151,47 +2140,47 @@ function encodeHex(character) {
|
|
|
2151
2140
|
var string, handle, length;
|
|
2152
2141
|
string = character.toString(16).toUpperCase();
|
|
2153
2142
|
if (character <= 0xFF) {
|
|
2154
|
-
handle =
|
|
2143
|
+
handle = 'x';
|
|
2155
2144
|
length = 2;
|
|
2156
2145
|
} else if (character <= 0xFFFF) {
|
|
2157
|
-
handle =
|
|
2146
|
+
handle = 'u';
|
|
2158
2147
|
length = 4;
|
|
2159
2148
|
} else if (character <= 0xFFFFFFFF) {
|
|
2160
|
-
handle =
|
|
2149
|
+
handle = 'U';
|
|
2161
2150
|
length = 8;
|
|
2162
2151
|
} else {
|
|
2163
|
-
throw new exception(
|
|
2152
|
+
throw new exception('code point within a string may not be greater than 0xFFFFFFFF');
|
|
2164
2153
|
}
|
|
2165
|
-
return
|
|
2154
|
+
return '\\' + handle + common.repeat('0', length - string.length) + string;
|
|
2166
2155
|
}
|
|
2167
2156
|
var QUOTING_TYPE_SINGLE = 1, QUOTING_TYPE_DOUBLE = 2;
|
|
2168
2157
|
function State(options) {
|
|
2169
|
-
this.schema = options[
|
|
2170
|
-
this.indent = Math.max(1, options[
|
|
2171
|
-
this.noArrayIndent = options[
|
|
2172
|
-
this.skipInvalid = options[
|
|
2173
|
-
this.flowLevel = common.isNothing(options[
|
|
2174
|
-
this.styleMap = compileStyleMap(this.schema, options[
|
|
2175
|
-
this.sortKeys = options[
|
|
2176
|
-
this.lineWidth = options[
|
|
2177
|
-
this.noRefs = options[
|
|
2178
|
-
this.noCompatMode = options[
|
|
2179
|
-
this.condenseFlow = options[
|
|
2180
|
-
this.quotingType = options[
|
|
2181
|
-
this.forceQuotes = options[
|
|
2182
|
-
this.replacer = typeof options[
|
|
2158
|
+
this.schema = options['schema'] || _default;
|
|
2159
|
+
this.indent = Math.max(1, options['indent'] || 2);
|
|
2160
|
+
this.noArrayIndent = options['noArrayIndent'] || false;
|
|
2161
|
+
this.skipInvalid = options['skipInvalid'] || false;
|
|
2162
|
+
this.flowLevel = common.isNothing(options['flowLevel']) ? -1 : options['flowLevel'];
|
|
2163
|
+
this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
|
|
2164
|
+
this.sortKeys = options['sortKeys'] || false;
|
|
2165
|
+
this.lineWidth = options['lineWidth'] || 80;
|
|
2166
|
+
this.noRefs = options['noRefs'] || false;
|
|
2167
|
+
this.noCompatMode = options['noCompatMode'] || false;
|
|
2168
|
+
this.condenseFlow = options['condenseFlow'] || false;
|
|
2169
|
+
this.quotingType = options['quotingType'] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
|
|
2170
|
+
this.forceQuotes = options['forceQuotes'] || false;
|
|
2171
|
+
this.replacer = typeof options['replacer'] === 'function' ? options['replacer'] : null;
|
|
2183
2172
|
this.implicitTypes = this.schema.compiledImplicit;
|
|
2184
2173
|
this.explicitTypes = this.schema.compiledExplicit;
|
|
2185
2174
|
this.tag = null;
|
|
2186
|
-
this.result =
|
|
2175
|
+
this.result = '';
|
|
2187
2176
|
this.duplicates = [];
|
|
2188
2177
|
this.usedDuplicates = null;
|
|
2189
2178
|
}
|
|
2190
2179
|
// Indents every line in a string. Empty lines (\n only) are not indented.
|
|
2191
2180
|
function indentString(string, spaces) {
|
|
2192
|
-
var ind = common.repeat(
|
|
2181
|
+
var ind = common.repeat(' ', spaces), position = 0, next = -1, result = '', line, length = string.length;
|
|
2193
2182
|
while(position < length){
|
|
2194
|
-
next = string.indexOf(
|
|
2183
|
+
next = string.indexOf('\n', position);
|
|
2195
2184
|
if (next === -1) {
|
|
2196
2185
|
line = string.slice(position);
|
|
2197
2186
|
position = length;
|
|
@@ -2199,13 +2188,13 @@ function indentString(string, spaces) {
|
|
|
2199
2188
|
line = string.slice(position, next + 1);
|
|
2200
2189
|
position = next + 1;
|
|
2201
2190
|
}
|
|
2202
|
-
if (line.length && line !==
|
|
2191
|
+
if (line.length && line !== '\n') result += ind;
|
|
2203
2192
|
result += line;
|
|
2204
2193
|
}
|
|
2205
2194
|
return result;
|
|
2206
2195
|
}
|
|
2207
2196
|
function generateNextLine(state, level) {
|
|
2208
|
-
return
|
|
2197
|
+
return '\n' + common.repeat(' ', state.indent * level);
|
|
2209
2198
|
}
|
|
2210
2199
|
function testImplicitResolving(state, str) {
|
|
2211
2200
|
var index, length, type;
|
|
@@ -2321,7 +2310,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
|
|
|
2321
2310
|
// Check if any line can be folded.
|
|
2322
2311
|
if (shouldTrackWidth) {
|
|
2323
2312
|
hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
|
|
2324
|
-
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !==
|
|
2313
|
+
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== ' ';
|
|
2325
2314
|
previousLineBreak = i;
|
|
2326
2315
|
}
|
|
2327
2316
|
} else if (!isPrintable(char)) {
|
|
@@ -2331,7 +2320,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
|
|
|
2331
2320
|
prevChar = char;
|
|
2332
2321
|
}
|
|
2333
2322
|
// in case the end is missing a \n
|
|
2334
|
-
hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !==
|
|
2323
|
+
hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== ' ';
|
|
2335
2324
|
}
|
|
2336
2325
|
// Although every style can represent \n without escaping, prefer block styles
|
|
2337
2326
|
// for multiline, since they're more readable and they don't add empty lines.
|
|
@@ -2391,28 +2380,28 @@ function writeScalar(state, string, level, iskey, inblock) {
|
|
|
2391
2380
|
case STYLE_SINGLE:
|
|
2392
2381
|
return "'" + string.replace(/'/g, "''") + "'";
|
|
2393
2382
|
case STYLE_LITERAL:
|
|
2394
|
-
return
|
|
2383
|
+
return '|' + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
2395
2384
|
case STYLE_FOLDED:
|
|
2396
|
-
return
|
|
2385
|
+
return '>' + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2397
2386
|
case STYLE_DOUBLE:
|
|
2398
2387
|
return '"' + escapeString(string) + '"';
|
|
2399
2388
|
default:
|
|
2400
|
-
throw new exception(
|
|
2389
|
+
throw new exception('impossible error: invalid scalar style');
|
|
2401
2390
|
}
|
|
2402
2391
|
}();
|
|
2403
2392
|
}
|
|
2404
2393
|
// Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
|
|
2405
2394
|
function blockHeader(string, indentPerLevel) {
|
|
2406
|
-
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) :
|
|
2395
|
+
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : '';
|
|
2407
2396
|
// note the special case: the string '\n' counts as a "trailing" empty line.
|
|
2408
|
-
var clip = string[string.length - 1] ===
|
|
2409
|
-
var keep = clip && (string[string.length - 2] ===
|
|
2410
|
-
var chomp = keep ?
|
|
2411
|
-
return indentIndicator + chomp +
|
|
2397
|
+
var clip = string[string.length - 1] === '\n';
|
|
2398
|
+
var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
|
|
2399
|
+
var chomp = keep ? '+' : clip ? '' : '-';
|
|
2400
|
+
return indentIndicator + chomp + '\n';
|
|
2412
2401
|
}
|
|
2413
2402
|
// (See the note for writeScalar.)
|
|
2414
2403
|
function dropEndingNewline(string) {
|
|
2415
|
-
return string[string.length - 1] ===
|
|
2404
|
+
return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
|
|
2416
2405
|
}
|
|
2417
2406
|
// Note: a long line without a suitable break point will exceed the width limit.
|
|
2418
2407
|
// Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
|
|
@@ -2424,20 +2413,20 @@ function foldString(string, width) {
|
|
|
2424
2413
|
var lineRe = /(\n+)([^\n]*)/g;
|
|
2425
2414
|
// first line (possibly an empty line)
|
|
2426
2415
|
var result = function() {
|
|
2427
|
-
var nextLF = string.indexOf(
|
|
2416
|
+
var nextLF = string.indexOf('\n');
|
|
2428
2417
|
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
2429
2418
|
lineRe.lastIndex = nextLF;
|
|
2430
2419
|
return foldLine(string.slice(0, nextLF), width);
|
|
2431
2420
|
}();
|
|
2432
2421
|
// If we haven't reached the first content line yet, don't add an extra \n.
|
|
2433
|
-
var prevMoreIndented = string[0] ===
|
|
2422
|
+
var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
|
|
2434
2423
|
var moreIndented;
|
|
2435
2424
|
// rest of the lines
|
|
2436
2425
|
var match;
|
|
2437
2426
|
while(match = lineRe.exec(string)){
|
|
2438
2427
|
var prefix = match[1], line = match[2];
|
|
2439
|
-
moreIndented = line[0] ===
|
|
2440
|
-
result += prefix + (!prevMoreIndented && !moreIndented && line !==
|
|
2428
|
+
moreIndented = line[0] === ' ';
|
|
2429
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== '' ? '\n' : '') + foldLine(line, width);
|
|
2441
2430
|
prevMoreIndented = moreIndented;
|
|
2442
2431
|
}
|
|
2443
2432
|
return result;
|
|
@@ -2447,13 +2436,13 @@ function foldString(string, width) {
|
|
|
2447
2436
|
// otherwise settles for the shortest line over the limit.
|
|
2448
2437
|
// NB. More-indented lines *cannot* be folded, as that would add an extra \n.
|
|
2449
2438
|
function foldLine(line, width) {
|
|
2450
|
-
if (line ===
|
|
2439
|
+
if (line === '' || line[0] === ' ') return line;
|
|
2451
2440
|
// Since a more-indented line adds a \n, breaks can't be followed by a space.
|
|
2452
2441
|
var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
|
|
2453
2442
|
var match;
|
|
2454
2443
|
// start is an inclusive index. end, curr, and next are exclusive.
|
|
2455
2444
|
var start = 0, end, curr = 0, next = 0;
|
|
2456
|
-
var result =
|
|
2445
|
+
var result = '';
|
|
2457
2446
|
// Invariants: 0 <= start <= length-1.
|
|
2458
2447
|
// 0 <= curr <= next <= max(0, length-2). curr - start <= width.
|
|
2459
2448
|
// Inside the loop:
|
|
@@ -2463,7 +2452,7 @@ function foldLine(line, width) {
|
|
|
2463
2452
|
// maintain invariant: curr - start <= width
|
|
2464
2453
|
if (next - start > width) {
|
|
2465
2454
|
end = curr > start ? curr : next; // derive end <= length-2
|
|
2466
|
-
result +=
|
|
2455
|
+
result += '\n' + line.slice(start, end);
|
|
2467
2456
|
// skip the space that was output as \n
|
|
2468
2457
|
start = end + 1; // derive start <= length-1
|
|
2469
2458
|
}
|
|
@@ -2471,10 +2460,10 @@ function foldLine(line, width) {
|
|
|
2471
2460
|
}
|
|
2472
2461
|
// By the invariants, start <= length-1, so there is something left over.
|
|
2473
2462
|
// It is either the whole string or a part starting from non-whitespace.
|
|
2474
|
-
result +=
|
|
2463
|
+
result += '\n';
|
|
2475
2464
|
// Insert a break if the remainder is too long and there is a break available.
|
|
2476
2465
|
if (line.length - start > width && curr > start) {
|
|
2477
|
-
result += line.slice(start, curr) +
|
|
2466
|
+
result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
|
|
2478
2467
|
} else {
|
|
2479
2468
|
result += line.slice(start);
|
|
2480
2469
|
}
|
|
@@ -2482,7 +2471,7 @@ function foldLine(line, width) {
|
|
|
2482
2471
|
}
|
|
2483
2472
|
// Escapes a double-quoted string.
|
|
2484
2473
|
function escapeString(string) {
|
|
2485
|
-
var result =
|
|
2474
|
+
var result = '';
|
|
2486
2475
|
var char = 0;
|
|
2487
2476
|
var escapeSeq;
|
|
2488
2477
|
for(var i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++){
|
|
@@ -2498,49 +2487,49 @@ function escapeString(string) {
|
|
|
2498
2487
|
return result;
|
|
2499
2488
|
}
|
|
2500
2489
|
function writeFlowSequence(state, level, object) {
|
|
2501
|
-
var _result =
|
|
2490
|
+
var _result = '', _tag = state.tag, index, length, value;
|
|
2502
2491
|
for(index = 0, length = object.length; index < length; index += 1){
|
|
2503
2492
|
value = object[index];
|
|
2504
2493
|
if (state.replacer) {
|
|
2505
2494
|
value = state.replacer.call(object, String(index), value);
|
|
2506
2495
|
}
|
|
2507
2496
|
// Write only valid elements, put null instead of invalid elements.
|
|
2508
|
-
if (writeNode(state, level, value, false, false) || typeof value ===
|
|
2509
|
-
if (_result !==
|
|
2497
|
+
if (writeNode(state, level, value, false, false) || typeof value === 'undefined' && writeNode(state, level, null, false, false)) {
|
|
2498
|
+
if (_result !== '') _result += ',' + (!state.condenseFlow ? ' ' : '');
|
|
2510
2499
|
_result += state.dump;
|
|
2511
2500
|
}
|
|
2512
2501
|
}
|
|
2513
2502
|
state.tag = _tag;
|
|
2514
|
-
state.dump =
|
|
2503
|
+
state.dump = '[' + _result + ']';
|
|
2515
2504
|
}
|
|
2516
2505
|
function writeBlockSequence(state, level, object, compact) {
|
|
2517
|
-
var _result =
|
|
2506
|
+
var _result = '', _tag = state.tag, index, length, value;
|
|
2518
2507
|
for(index = 0, length = object.length; index < length; index += 1){
|
|
2519
2508
|
value = object[index];
|
|
2520
2509
|
if (state.replacer) {
|
|
2521
2510
|
value = state.replacer.call(object, String(index), value);
|
|
2522
2511
|
}
|
|
2523
2512
|
// Write only valid elements, put null instead of invalid elements.
|
|
2524
|
-
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value ===
|
|
2525
|
-
if (!compact || _result !==
|
|
2513
|
+
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === 'undefined' && writeNode(state, level + 1, null, true, true, false, true)) {
|
|
2514
|
+
if (!compact || _result !== '') {
|
|
2526
2515
|
_result += generateNextLine(state, level);
|
|
2527
2516
|
}
|
|
2528
2517
|
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2529
|
-
_result +=
|
|
2518
|
+
_result += '-';
|
|
2530
2519
|
} else {
|
|
2531
|
-
_result +=
|
|
2520
|
+
_result += '- ';
|
|
2532
2521
|
}
|
|
2533
2522
|
_result += state.dump;
|
|
2534
2523
|
}
|
|
2535
2524
|
}
|
|
2536
2525
|
state.tag = _tag;
|
|
2537
|
-
state.dump = _result ||
|
|
2526
|
+
state.dump = _result || '[]'; // Empty sequence if no valid values.
|
|
2538
2527
|
}
|
|
2539
2528
|
function writeFlowMapping(state, level, object) {
|
|
2540
|
-
var _result =
|
|
2529
|
+
var _result = '', _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
2541
2530
|
for(index = 0, length = objectKeyList.length; index < length; index += 1){
|
|
2542
|
-
pairBuffer =
|
|
2543
|
-
if (_result !==
|
|
2531
|
+
pairBuffer = '';
|
|
2532
|
+
if (_result !== '') pairBuffer += ', ';
|
|
2544
2533
|
if (state.condenseFlow) pairBuffer += '"';
|
|
2545
2534
|
objectKey = objectKeyList[index];
|
|
2546
2535
|
objectValue = object[objectKey];
|
|
@@ -2550,8 +2539,8 @@ function writeFlowMapping(state, level, object) {
|
|
|
2550
2539
|
if (!writeNode(state, level, objectKey, false, false)) {
|
|
2551
2540
|
continue; // Skip this pair because of invalid key;
|
|
2552
2541
|
}
|
|
2553
|
-
if (state.dump.length > 1024) pairBuffer +=
|
|
2554
|
-
pairBuffer += state.dump + (state.condenseFlow ? '"' :
|
|
2542
|
+
if (state.dump.length > 1024) pairBuffer += '? ';
|
|
2543
|
+
pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
|
|
2555
2544
|
if (!writeNode(state, level, objectValue, false, false)) {
|
|
2556
2545
|
continue; // Skip this pair because of invalid value.
|
|
2557
2546
|
}
|
|
@@ -2560,24 +2549,24 @@ function writeFlowMapping(state, level, object) {
|
|
|
2560
2549
|
_result += pairBuffer;
|
|
2561
2550
|
}
|
|
2562
2551
|
state.tag = _tag;
|
|
2563
|
-
state.dump =
|
|
2552
|
+
state.dump = '{' + _result + '}';
|
|
2564
2553
|
}
|
|
2565
2554
|
function writeBlockMapping(state, level, object, compact) {
|
|
2566
|
-
var _result =
|
|
2555
|
+
var _result = '', _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
2567
2556
|
// Allow sorting keys so that the output file is deterministic
|
|
2568
2557
|
if (state.sortKeys === true) {
|
|
2569
2558
|
// Default sorting
|
|
2570
2559
|
objectKeyList.sort();
|
|
2571
|
-
} else if (typeof state.sortKeys ===
|
|
2560
|
+
} else if (typeof state.sortKeys === 'function') {
|
|
2572
2561
|
// Custom sort function
|
|
2573
2562
|
objectKeyList.sort(state.sortKeys);
|
|
2574
2563
|
} else if (state.sortKeys) {
|
|
2575
2564
|
// Something is wrong
|
|
2576
|
-
throw new exception(
|
|
2565
|
+
throw new exception('sortKeys must be a boolean or a function');
|
|
2577
2566
|
}
|
|
2578
2567
|
for(index = 0, length = objectKeyList.length; index < length; index += 1){
|
|
2579
|
-
pairBuffer =
|
|
2580
|
-
if (!compact || _result !==
|
|
2568
|
+
pairBuffer = '';
|
|
2569
|
+
if (!compact || _result !== '') {
|
|
2581
2570
|
pairBuffer += generateNextLine(state, level);
|
|
2582
2571
|
}
|
|
2583
2572
|
objectKey = objectKeyList[index];
|
|
@@ -2588,12 +2577,12 @@ function writeBlockMapping(state, level, object, compact) {
|
|
|
2588
2577
|
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
2589
2578
|
continue; // Skip this pair because of invalid key.
|
|
2590
2579
|
}
|
|
2591
|
-
explicitPair = state.tag !== null && state.tag !==
|
|
2580
|
+
explicitPair = state.tag !== null && state.tag !== '?' || state.dump && state.dump.length > 1024;
|
|
2592
2581
|
if (explicitPair) {
|
|
2593
2582
|
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2594
|
-
pairBuffer +=
|
|
2583
|
+
pairBuffer += '?';
|
|
2595
2584
|
} else {
|
|
2596
|
-
pairBuffer +=
|
|
2585
|
+
pairBuffer += '? ';
|
|
2597
2586
|
}
|
|
2598
2587
|
}
|
|
2599
2588
|
pairBuffer += state.dump;
|
|
@@ -2604,23 +2593,23 @@ function writeBlockMapping(state, level, object, compact) {
|
|
|
2604
2593
|
continue; // Skip this pair because of invalid value.
|
|
2605
2594
|
}
|
|
2606
2595
|
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2607
|
-
pairBuffer +=
|
|
2596
|
+
pairBuffer += ':';
|
|
2608
2597
|
} else {
|
|
2609
|
-
pairBuffer +=
|
|
2598
|
+
pairBuffer += ': ';
|
|
2610
2599
|
}
|
|
2611
2600
|
pairBuffer += state.dump;
|
|
2612
2601
|
// Both key and value are valid.
|
|
2613
2602
|
_result += pairBuffer;
|
|
2614
2603
|
}
|
|
2615
2604
|
state.tag = _tag;
|
|
2616
|
-
state.dump = _result ||
|
|
2605
|
+
state.dump = _result || '{}'; // Empty mapping if no valid pairs.
|
|
2617
2606
|
}
|
|
2618
2607
|
function detectType(state, object, explicit) {
|
|
2619
2608
|
var _result, typeList, index, length, type, style;
|
|
2620
2609
|
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
2621
2610
|
for(index = 0, length = typeList.length; index < length; index += 1){
|
|
2622
2611
|
type = typeList[index];
|
|
2623
|
-
if ((type.instanceOf || type.predicate) && (!type.instanceOf || typeof object === "
|
|
2612
|
+
if ((type.instanceOf || type.predicate) && (!type.instanceOf || (typeof object === "undefined" ? "undefined" : _type_of(object)) === 'object' && _instanceof(object, type.instanceOf)) && (!type.predicate || type.predicate(object))) {
|
|
2624
2613
|
if (explicit) {
|
|
2625
2614
|
if (type.multi && type.representName) {
|
|
2626
2615
|
state.tag = type.representName(object);
|
|
@@ -2628,16 +2617,16 @@ function detectType(state, object, explicit) {
|
|
|
2628
2617
|
state.tag = type.tag;
|
|
2629
2618
|
}
|
|
2630
2619
|
} else {
|
|
2631
|
-
state.tag =
|
|
2620
|
+
state.tag = '?';
|
|
2632
2621
|
}
|
|
2633
2622
|
if (type.represent) {
|
|
2634
2623
|
style = state.styleMap[type.tag] || type.defaultStyle;
|
|
2635
|
-
if (_toString.call(type.represent) ===
|
|
2624
|
+
if (_toString.call(type.represent) === '[object Function]') {
|
|
2636
2625
|
_result = type.represent(object, style);
|
|
2637
2626
|
} else if (_hasOwnProperty.call(type.represent, style)) {
|
|
2638
2627
|
_result = type.represent[style](object, style);
|
|
2639
2628
|
} else {
|
|
2640
|
-
throw new exception(
|
|
2629
|
+
throw new exception('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
|
|
2641
2630
|
}
|
|
2642
2631
|
state.dump = _result;
|
|
2643
2632
|
}
|
|
@@ -2661,33 +2650,33 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
|
2661
2650
|
if (block) {
|
|
2662
2651
|
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
2663
2652
|
}
|
|
2664
|
-
var objectOrArray = type ===
|
|
2653
|
+
var objectOrArray = type === '[object Object]' || type === '[object Array]', duplicateIndex, duplicate;
|
|
2665
2654
|
if (objectOrArray) {
|
|
2666
2655
|
duplicateIndex = state.duplicates.indexOf(object);
|
|
2667
2656
|
duplicate = duplicateIndex !== -1;
|
|
2668
2657
|
}
|
|
2669
|
-
if (state.tag !== null && state.tag !==
|
|
2658
|
+
if (state.tag !== null && state.tag !== '?' || duplicate || state.indent !== 2 && level > 0) {
|
|
2670
2659
|
compact = false;
|
|
2671
2660
|
}
|
|
2672
2661
|
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
2673
|
-
state.dump =
|
|
2662
|
+
state.dump = '*ref_' + duplicateIndex;
|
|
2674
2663
|
} else {
|
|
2675
2664
|
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
2676
2665
|
state.usedDuplicates[duplicateIndex] = true;
|
|
2677
2666
|
}
|
|
2678
|
-
if (type ===
|
|
2667
|
+
if (type === '[object Object]') {
|
|
2679
2668
|
if (block && Object.keys(state.dump).length !== 0) {
|
|
2680
2669
|
writeBlockMapping(state, level, state.dump, compact);
|
|
2681
2670
|
if (duplicate) {
|
|
2682
|
-
state.dump =
|
|
2671
|
+
state.dump = '&ref_' + duplicateIndex + state.dump;
|
|
2683
2672
|
}
|
|
2684
2673
|
} else {
|
|
2685
2674
|
writeFlowMapping(state, level, state.dump);
|
|
2686
2675
|
if (duplicate) {
|
|
2687
|
-
state.dump =
|
|
2676
|
+
state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
|
|
2688
2677
|
}
|
|
2689
2678
|
}
|
|
2690
|
-
} else if (type ===
|
|
2679
|
+
} else if (type === '[object Array]') {
|
|
2691
2680
|
if (block && state.dump.length !== 0) {
|
|
2692
2681
|
if (state.noArrayIndent && !isblockseq && level > 0) {
|
|
2693
2682
|
writeBlockSequence(state, level - 1, state.dump, compact);
|
|
@@ -2695,25 +2684,25 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
|
2695
2684
|
writeBlockSequence(state, level, state.dump, compact);
|
|
2696
2685
|
}
|
|
2697
2686
|
if (duplicate) {
|
|
2698
|
-
state.dump =
|
|
2687
|
+
state.dump = '&ref_' + duplicateIndex + state.dump;
|
|
2699
2688
|
}
|
|
2700
2689
|
} else {
|
|
2701
2690
|
writeFlowSequence(state, level, state.dump);
|
|
2702
2691
|
if (duplicate) {
|
|
2703
|
-
state.dump =
|
|
2692
|
+
state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
|
|
2704
2693
|
}
|
|
2705
2694
|
}
|
|
2706
|
-
} else if (type ===
|
|
2707
|
-
if (state.tag !==
|
|
2695
|
+
} else if (type === '[object String]') {
|
|
2696
|
+
if (state.tag !== '?') {
|
|
2708
2697
|
writeScalar(state, state.dump, level, iskey, inblock);
|
|
2709
2698
|
}
|
|
2710
|
-
} else if (type ===
|
|
2699
|
+
} else if (type === '[object Undefined]') {
|
|
2711
2700
|
return false;
|
|
2712
2701
|
} else {
|
|
2713
2702
|
if (state.skipInvalid) return false;
|
|
2714
|
-
throw new exception(
|
|
2703
|
+
throw new exception('unacceptable kind of an object to dump ' + type);
|
|
2715
2704
|
}
|
|
2716
|
-
if (state.tag !== null && state.tag !==
|
|
2705
|
+
if (state.tag !== null && state.tag !== '?') {
|
|
2717
2706
|
// Need to encode all characters except those allowed by the spec:
|
|
2718
2707
|
//
|
|
2719
2708
|
// [35] ns-dec-digit ::= [#x30-#x39] /* 0-9 */
|
|
@@ -2727,15 +2716,15 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
|
2727
2716
|
//
|
|
2728
2717
|
// Also need to encode '!' because it has special meaning (end of tag prefix).
|
|
2729
2718
|
//
|
|
2730
|
-
tagStr = encodeURI(state.tag[0] ===
|
|
2731
|
-
if (state.tag[0] ===
|
|
2732
|
-
tagStr =
|
|
2733
|
-
} else if (tagStr.slice(0, 18) ===
|
|
2734
|
-
tagStr =
|
|
2719
|
+
tagStr = encodeURI(state.tag[0] === '!' ? state.tag.slice(1) : state.tag).replace(/!/g, '%21');
|
|
2720
|
+
if (state.tag[0] === '!') {
|
|
2721
|
+
tagStr = '!' + tagStr;
|
|
2722
|
+
} else if (tagStr.slice(0, 18) === 'tag:yaml.org,2002:') {
|
|
2723
|
+
tagStr = '!!' + tagStr.slice(18);
|
|
2735
2724
|
} else {
|
|
2736
|
-
tagStr =
|
|
2725
|
+
tagStr = '!<' + tagStr + '>';
|
|
2737
2726
|
}
|
|
2738
|
-
state.dump = tagStr +
|
|
2727
|
+
state.dump = tagStr + ' ' + state.dump;
|
|
2739
2728
|
}
|
|
2740
2729
|
}
|
|
2741
2730
|
return true;
|
|
@@ -2750,7 +2739,7 @@ function getDuplicateReferences(object, state) {
|
|
|
2750
2739
|
}
|
|
2751
2740
|
function inspectNode(object, objects, duplicatesIndexes) {
|
|
2752
2741
|
var objectKeyList, index, length;
|
|
2753
|
-
if (object !== null && typeof object === "object
|
|
2742
|
+
if (object !== null && (typeof object === "undefined" ? "undefined" : _type_of(object)) === 'object') {
|
|
2754
2743
|
index = objects.indexOf(object);
|
|
2755
2744
|
if (index !== -1) {
|
|
2756
2745
|
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
@@ -2778,11 +2767,11 @@ function dump$1(input, options) {
|
|
|
2778
2767
|
var value = input;
|
|
2779
2768
|
if (state.replacer) {
|
|
2780
2769
|
value = state.replacer.call({
|
|
2781
|
-
|
|
2782
|
-
},
|
|
2770
|
+
'': value
|
|
2771
|
+
}, '', value);
|
|
2783
2772
|
}
|
|
2784
|
-
if (writeNode(state, 0, value, true, true)) return state.dump +
|
|
2785
|
-
return
|
|
2773
|
+
if (writeNode(state, 0, value, true, true)) return state.dump + '\n';
|
|
2774
|
+
return '';
|
|
2786
2775
|
}
|
|
2787
2776
|
var dump_1 = dump$1;
|
|
2788
2777
|
var dumper = {
|