diff --git a/dist/js-yaml.js b/dist/js-yaml.js index ee6530a9..228bdd24 100644 --- a/dist/js-yaml.js +++ b/dist/js-yaml.js @@ -1,5 +1,5 @@ -/*! js-yaml 3.14.0 https://github.com/nodeca/js-yaml @license MIT */ +/*! js-yaml 4.0.0 https://github.com/nodeca/js-yaml @license MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -74,6 +74,26 @@ // YAML error class. http://stackoverflow.com/questions/8458984 + + function formatError(exception, compact) { + var where = '', message = exception.reason || '(unknown reason)'; + + if (!exception.mark) return message; + + if (exception.mark.name) { + where += 'in "' + exception.mark.name + '" '; + } + + where += '(' + (exception.mark.line + 1) + ':' + (exception.mark.column + 1) + ')'; + + if (!compact && exception.mark.snippet) { + where += '\n\n' + exception.mark.snippet; + } + + return message + ' ' + where; + } + + function YAMLException(reason, mark) { // Super constructor Error.call(this); @@ -81,7 +101,7 @@ this.name = 'YAMLException'; this.reason = reason; this.mark = mark; - this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : ''); + this.message = formatError(this, false); // Include stack trace in error object if (Error.captureStackTrace) { @@ -100,98 +120,117 @@ YAMLException.prototype.toString = function toString(compact) { - var result = this.name + ': '; + return this.name + ': ' + formatError(this, compact); + }; - result += this.reason || '(unknown reason)'; - if (!compact && this.mark) { - result += ' ' + this.mark.toString(); - } + var exception = YAMLException; - return result; - }; + // get snippet for a single line, respecting maxLength + function getLine(buffer, lineStart, lineEnd, position, maxLineLength) { + var head = ''; + var tail = ''; + var maxHalfLength = Math.floor(maxLineLength / 2) - 1; + if (position - lineStart > maxHalfLength) { + head = ' ... '; + lineStart = position - maxHalfLength + head.length; + } - var exception = YAMLException; + if (lineEnd - position > maxHalfLength) { + tail = ' ...'; + lineEnd = position + maxHalfLength - tail.length; + } - function Mark(name, buffer, position, line, column) { - this.name = name; - this.buffer = buffer; - this.position = position; - this.line = line; - this.column = column; + return { + str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, '→') + tail, + pos: position - lineStart + head.length // relative position + }; } - Mark.prototype.getSnippet = function getSnippet(indent, maxLength) { - var head, start, tail, end, snippet; + function padStart(string, max) { + return common.repeat(' ', max - string.length) + string; + } - if (!this.buffer) return null; - indent = indent || 4; - maxLength = maxLength || 75; + function makeSnippet(mark, options) { + options = Object.create(options || null); - head = ''; - start = this.position; + if (!mark.buffer) return null; - while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) { - start -= 1; - if (this.position - start > (maxLength / 2 - 1)) { - head = ' ... '; - start += 5; - break; - } - } + if (!options.maxLength) options.maxLength = 79; + if (typeof options.indent !== 'number') options.indent = 1; + if (typeof options.linesBefore !== 'number') options.linesBefore = 3; + if (typeof options.linesAfter !== 'number') options.linesAfter = 2; - tail = ''; - end = this.position; + var re = /\r?\n|\r|\0/g; + var lineStarts = [ 0 ]; + var lineEnds = []; + var match; + var foundLineNo = -1; - while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) { - end += 1; - if (end - this.position > (maxLength / 2 - 1)) { - tail = ' ... '; - end -= 5; - break; + while ((match = re.exec(mark.buffer))) { + lineEnds.push(match.index); + lineStarts.push(match.index + match[0].length); + + if (mark.position <= match.index && foundLineNo < 0) { + foundLineNo = lineStarts.length - 2; } } - snippet = this.buffer.slice(start, end); - - return common.repeat(' ', indent) + head + snippet + tail + '\n' + - common.repeat(' ', indent + this.position - start + head.length) + '^'; - }; - + if (foundLineNo < 0) foundLineNo = lineStarts.length - 1; - Mark.prototype.toString = function toString(compact) { - var snippet, where = ''; + var result = '', i, line; + var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length; + var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3); - if (this.name) { - where += 'in "' + this.name + '" '; + for (i = 1; i <= options.linesBefore; i++) { + if (foundLineNo - i < 0) break; + line = getLine( + mark.buffer, + lineStarts[foundLineNo - i], + lineEnds[foundLineNo - i], + mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), + maxLineLength + ); + result = common.repeat(' ', options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + + ' | ' + line.str + '\n' + result; } - where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1); + line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength); + result += common.repeat(' ', options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + + ' | ' + line.str + '\n'; + result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n'; - if (!compact) { - snippet = this.getSnippet(); - - if (snippet) { - where += ':\n' + snippet; - } + for (i = 1; i <= options.linesAfter; i++) { + if (foundLineNo + i >= lineEnds.length) break; + line = getLine( + mark.buffer, + lineStarts[foundLineNo + i], + lineEnds[foundLineNo + i], + mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), + maxLineLength + ); + result += common.repeat(' ', options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + + ' | ' + line.str + '\n'; } - return where; - }; + return result.replace(/\n$/, ''); + } - var mark = Mark; + var snippet = makeSnippet; var TYPE_CONSTRUCTOR_OPTIONS = [ 'kind', + 'multi', 'resolve', 'construct', 'instanceOf', 'predicate', 'represent', + 'representName', 'defaultStyle', 'styleAliases' ]; @@ -226,15 +265,17 @@ }); // TODO: Add tag format check. - this.tag = tag; - this.kind = options['kind'] || null; - this.resolve = options['resolve'] || function () { return true; }; - this.construct = options['construct'] || function (data) { return data; }; - this.instanceOf = options['instanceOf'] || null; - this.predicate = options['predicate'] || null; - this.represent = options['represent'] || null; - this.defaultStyle = options['defaultStyle'] || null; - this.styleAliases = compileStyleAliases(options['styleAliases'] || null); + this.tag = tag; + this.kind = options['kind'] || null; + this.resolve = options['resolve'] || function () { return true; }; + this.construct = options['construct'] || function (data) { return data; }; + this.instanceOf = options['instanceOf'] || null; + this.predicate = options['predicate'] || null; + this.represent = options['represent'] || null; + this.representName = options['representName'] || null; + this.defaultStyle = options['defaultStyle'] || null; + this.multi = options['multi'] || false; + this.styleAliases = compileStyleAliases(options['styleAliases'] || null); if (YAML_NODE_KINDS.indexOf(this.kind) === -1) { throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.'); @@ -254,7 +295,10 @@ schema[name].forEach(function (currentType) { result.forEach(function (previousType, previousIndex) { - if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) { + if (previousType.tag === currentType.tag && + previousType.kind === currentType.kind && + previousType.multi === currentType.multi) { + exclude.push(previousIndex); } }); @@ -273,11 +317,22 @@ scalar: {}, sequence: {}, mapping: {}, - fallback: {} + fallback: {}, + multi: { + scalar: [], + sequence: [], + mapping: [], + fallback: [] + } }, index, length; function collectType(type) { - result[type.kind][type.tag] = result['fallback'][type.tag] = type; + if (type.multi) { + result.multi[type.kind].push(type); + result.multi['fallback'].push(type); + } else { + result[type.kind][type.tag] = result['fallback'][type.tag] = type; + } } for (index = 0, length = arguments.length; index < length; index += 1) { @@ -322,6 +377,10 @@ if (type$1.loadKind && type$1.loadKind !== 'scalar') { throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.'); } + + if (type$1.multi) { + throw new exception('There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.'); + } }); explicit.forEach(function (type$1) { @@ -394,7 +453,8 @@ canonical: function () { return '~'; }, lowercase: function () { return 'null'; }, uppercase: function () { return 'NULL'; }, - camelcase: function () { return 'Null'; } + camelcase: function () { return 'Null'; }, + empty: function () { return ''; } }, defaultStyle: 'lowercase' }); @@ -496,17 +556,22 @@ return hasDigits && ch !== '_'; } - // base 8 - for (; index < max; index++) { - ch = data[index]; - if (ch === '_') continue; - if (!isOctCode(data.charCodeAt(index))) return false; - hasDigits = true; + + if (ch === 'o') { + // base 8 + index++; + + for (; index < max; index++) { + ch = data[index]; + if (ch === '_') continue; + if (!isOctCode(data.charCodeAt(index))) return false; + hasDigits = true; + } + return hasDigits && ch !== '_'; } - return hasDigits && ch !== '_'; } - // base 10 (except 0) or base 60 + // base 10 (except 0) // value should not start with `_`; if (ch === '_') return false; @@ -514,7 +579,6 @@ for (; index < max; index++) { ch = data[index]; if (ch === '_') continue; - if (ch === ':') break; if (!isDecCode(data.charCodeAt(index))) { return false; } @@ -524,15 +588,11 @@ // Should have digits and should not end with `_` if (!hasDigits || ch === '_') return false; - // if !base60 - done; - if (ch !== ':') return true; - - // base60 almost not used, no needs to optimize - return /^(:[0-5]?[0-9])+$/.test(data.slice(index)); + return true; } function constructYamlInteger(data) { - var value = data, sign = 1, ch, base, digits = []; + var value = data, sign = 1, ch; if (value.indexOf('_') !== -1) { value = value.replace(/_/g, ''); @@ -550,25 +610,8 @@ if (ch === '0') { if (value[1] === 'b') return sign * parseInt(value.slice(2), 2); - if (value[1] === 'x') return sign * parseInt(value, 16); - return sign * parseInt(value, 8); - } - - if (value.indexOf(':') !== -1) { - value.split(':').forEach(function (v) { - digits.unshift(parseInt(v, 10)); - }); - - value = 0; - base = 1; - - digits.forEach(function (d) { - value += (d * base); - base *= 60; - }); - - return sign * value; - + if (value[1] === 'x') return sign * parseInt(value.slice(2), 16); + if (value[1] === 'o') return sign * parseInt(value.slice(2), 8); } return sign * parseInt(value, 10); @@ -586,7 +629,7 @@ predicate: isInteger, represent: { binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1); }, - octal: function (obj) { return obj >= 0 ? '0' + obj.toString(8) : '-0' + obj.toString(8).slice(1); }, + octal: function (obj) { return obj >= 0 ? '0o' + obj.toString(8) : '-0o' + obj.toString(8).slice(1); }, decimal: function (obj) { return obj.toString(10); }, /* eslint-disable max-len */ hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1); } @@ -602,12 +645,10 @@ var YAML_FLOAT_PATTERN = new RegExp( // 2.5e4, 2.5 and integers - '^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' + + '^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' + // .2e4, .2 // special case, seems not from spec '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' + - // 20:59 - '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' + // .inf '|[-+]?\\.(?:inf|Inf|INF)' + // .nan @@ -627,11 +668,10 @@ } function constructYamlFloat(data) { - var value, sign, base, digits; + var value, sign; value = data.replace(/_/g, '').toLowerCase(); sign = value[0] === '-' ? -1 : 1; - digits = []; if ('+-'.indexOf(value[0]) >= 0) { value = value.slice(1); @@ -642,22 +682,6 @@ } else if (value === '.nan') { return NaN; - - } else if (value.indexOf(':') >= 0) { - value.split(':').forEach(function (v) { - digits.unshift(parseFloat(v, 10)); - }); - - value = 0.0; - base = 1; - - digits.forEach(function (d) { - value += d * base; - base *= 60; - }); - - return sign * value; - } return sign * parseFloat(value, 10); } @@ -817,19 +841,8 @@ resolve: resolveYamlMerge }); - function commonjsRequire (target) { - throw new Error('Could not dynamically require "' + target + '". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.'); - } - /*eslint-disable no-bitwise*/ - var NodeBuffer; - - try { - // A trick for browserified version, to not include `Buffer` shim - var _require = commonjsRequire; - NodeBuffer = _require('buffer').Buffer; - } catch (__) {} @@ -895,13 +908,7 @@ result.push((bits >> 4) & 0xFF); } - // Wrap into Buffer for NodeJS and leave Array for browser - if (NodeBuffer) { - // Support node 6.+ Buffer API when available - return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result); - } - - return result; + return new Uint8Array(result); } function representYamlBinary(object /*, style*/) { @@ -946,8 +953,8 @@ return result; } - function isBinary(object) { - return NodeBuffer && NodeBuffer.isBuffer(object); + function isBinary(obj) { + return Object.prototype.toString.call(obj) === '[object Uint8Array]'; } var binary = new type('tag:yaml.org,2002:binary', { @@ -1222,7 +1229,10 @@ this.filename = options['filename'] || null; this.schema = options['schema'] || _default; this.onWarning = options['onWarning'] || null; + // (Hidden) Remove? makes the loader to expect YAML 1.1 documents + // if such documents have no explicit %YAML directive this.legacy = options['legacy'] || false; + this.json = options['json'] || false; this.listener = options['listener'] || null; @@ -1235,6 +1245,10 @@ this.lineStart = 0; this.lineIndent = 0; + // position of first leading tab in the current line, + // used to make sure there are no tabs in the indentation + this.firstTabInLine = -1; + this.documents = []; /* @@ -1251,9 +1265,17 @@ function generateError(state, message) { - return new exception( - message, - new mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart))); + var mark = { + name: state.filename, + buffer: state.input.slice(0, -1), // omit trailing \0 + position: state.position, + line: state.line, + column: state.position - state.lineStart + }; + + mark.snippet = snippet(mark); + + return new exception(message, mark); } function throwError(state, message) { @@ -1325,6 +1347,12 @@ throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive'); } + try { + prefix = decodeURIComponent(prefix); + } catch (err) { + throwError(state, 'tag prefix is malformed: ' + prefix); + } + state.tagMap[handle] = prefix; } }; @@ -1371,7 +1399,9 @@ } } - function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) { + function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, + startLine, startLineStart, startPos) { + var index, quantity; // The output is a plain object here, so keys can only be strings. @@ -1418,10 +1448,22 @@ !_hasOwnProperty$2.call(overridableKeys, keyNode) && _hasOwnProperty$2.call(_result, keyNode)) { state.line = startLine || state.line; + state.lineStart = startLineStart || state.lineStart; state.position = startPos || state.position; throwError(state, 'duplicated mapping key'); } - _result[keyNode] = valueNode; + + // used for this specific key only because Object.defineProperty is slow + if (keyNode === '__proto__') { + Object.defineProperty(_result, keyNode, { + configurable: true, + enumerable: true, + writable: true, + value: valueNode + }); + } else { + _result[keyNode] = valueNode; + } delete overridableKeys[keyNode]; } @@ -1446,6 +1488,7 @@ state.line += 1; state.lineStart = state.position; + state.firstTabInLine = -1; } function skipSeparationSpace(state, allowComments, checkIndent) { @@ -1454,6 +1497,9 @@ while (ch !== 0) { while (is_WHITE_SPACE(ch)) { + if (ch === 0x09/* Tab */ && state.firstTabInLine === -1) { + state.firstTabInLine = state.position; + } ch = state.input.charCodeAt(++state.position); } @@ -1755,6 +1801,8 @@ function readFlowCollection(state, nodeIndent) { var readNext = true, _line, + _lineStart, + _pos, _tag = state.tag, _result, _anchor = state.anchor, @@ -1763,7 +1811,7 @@ isPair, isExplicitPair, isMapping, - overridableKeys = {}, + overridableKeys = Object.create(null), keyNode, keyTag, valueNode, @@ -1803,6 +1851,9 @@ return true; } else if (!readNext) { throwError(state, 'missed comma between flow collection entries'); + } else if (ch === 0x2C/* , */) { + // "flow collection entries can never be completely empty", as per YAML 1.2, section 7.4 + throwError(state, "expected the node content, but found ','"); } keyTag = keyNode = valueNode = null; @@ -1818,7 +1869,9 @@ } } - _line = state.line; + _line = state.line; // Save the current line. + _lineStart = state.lineStart; + _pos = state.position; composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true); keyTag = state.tag; keyNode = state.result; @@ -1835,9 +1888,9 @@ } if (isMapping) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos); } else if (isPair) { - _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode)); + _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos)); } else { _result.push(keyNode); } @@ -2009,6 +2062,10 @@ detected = false, ch; + // there is a leading tab before this token, so it can't be a block sequence/mapping; + // it can still be flow sequence/mapping or a scalar + if (state.firstTabInLine !== -1) return false; + if (state.anchor !== null) { state.anchorMap[state.anchor] = _result; } @@ -2016,6 +2073,10 @@ ch = state.input.charCodeAt(state.position); while (ch !== 0) { + if (state.firstTabInLine !== -1) { + state.position = state.firstTabInLine; + throwError(state, 'tab characters must not be used in indentation'); + } if (ch !== 0x2D/* - */) { break; @@ -2066,11 +2127,13 @@ var following, allowCompact, _line, - _pos, + _keyLine, + _keyLineStart, + _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, - overridableKeys = {}, + overridableKeys = Object.create(null), keyTag = null, keyNode = null, valueNode = null, @@ -2078,6 +2141,10 @@ detected = false, ch; + // there is a leading tab before this token, so it can't be a block sequence/mapping; + // it can still be flow sequence/mapping or a scalar + if (state.firstTabInLine !== -1) return false; + if (state.anchor !== null) { state.anchorMap[state.anchor] = _result; } @@ -2085,9 +2152,13 @@ ch = state.input.charCodeAt(state.position); while (ch !== 0) { + if (!atExplicitKey && state.firstTabInLine !== -1) { + state.position = state.firstTabInLine; + throwError(state, 'tab characters must not be used in indentation'); + } + following = state.input.charCodeAt(state.position + 1); _line = state.line; // Save the current line. - _pos = state.position; // // Explicit notation case. There are two separate blocks: @@ -2097,7 +2168,7 @@ if (ch === 0x3F/* ? */) { if (atExplicitKey) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); keyTag = keyNode = valueNode = null; } @@ -2120,7 +2191,16 @@ // // Implicit notation case. Flow-style node as the key first, then ":", and the value. // - } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) { + } else { + _keyLine = state.line; + _keyLineStart = state.lineStart; + _keyPos = state.position; + + if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) { + // Neither implicit nor explicit notation. + // Reading is done. Go to the epilogue. + break; + } if (state.line === _line) { ch = state.input.charCodeAt(state.position); @@ -2137,7 +2217,7 @@ } if (atExplicitKey) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); keyTag = keyNode = valueNode = null; } @@ -2164,15 +2244,18 @@ state.anchor = _anchor; return true; // Keep the result of `composeNode`. } - - } else { - break; // Reading is done. Go to the epilogue. } // // Common reading code for both explicit and implicit notations. // if (state.line === _line || state.lineIndent > nodeIndent) { + if (atExplicitKey) { + _keyLine = state.line; + _keyLineStart = state.lineStart; + _keyPos = state.position; + } + if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) { if (atExplicitKey) { keyNode = state.result; @@ -2182,7 +2265,7 @@ } if (!atExplicitKey) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos); keyTag = keyNode = valueNode = null; } @@ -2190,7 +2273,7 @@ ch = state.input.charCodeAt(state.position); } - if (state.lineIndent > nodeIndent && (ch !== 0)) { + if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) { throwError(state, 'bad indentation of a mapping entry'); } else if (state.lineIndent < nodeIndent) { break; @@ -2203,7 +2286,7 @@ // Special case: last mapping's node contains only the key in explicit notation. if (atExplicitKey) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); } // Expose the resulting mapping. @@ -2292,6 +2375,12 @@ throwError(state, 'tag name cannot contain such characters: ' + tagName); } + try { + tagName = decodeURIComponent(tagName); + } catch (err) { + throwError(state, 'tag name is malformed: ' + tagName); + } + if (isVerbatim) { state.tag = tagName; @@ -2359,7 +2448,7 @@ alias = state.input.slice(_position, state.position); - if (!state.anchorMap.hasOwnProperty(alias)) { + if (!_hasOwnProperty$2.call(state.anchorMap, alias)) { throwError(state, 'unidentified alias "' + alias + '"'); } @@ -2377,6 +2466,7 @@ hasContent = false, typeIndex, typeQuantity, + typeList, type, flowIndent, blockIndent; @@ -2478,48 +2568,66 @@ } } - if (state.tag !== null && state.tag !== '!') { - if (state.tag === '?') { - // Implicit resolving is not allowed for non-scalar types, and '?' - // non-specific tag is only automatically assigned to plain scalars. - // - // We only need to check kind conformity in case user explicitly assigns '?' - // tag, for example like this: "! [0]" - // - if (state.result !== null && state.kind !== 'scalar') { - throwError(state, 'unacceptable node kind for ! tag; it should be "scalar", not "' + state.kind + '"'); - } - - for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) { - type = state.implicitTypes[typeIndex]; + if (state.tag === null) { + if (state.anchor !== null) { + state.anchorMap[state.anchor] = state.result; + } - if (type.resolve(state.result)) { // `state.result` updated in resolver if matched - state.result = type.construct(state.result); - state.tag = type.tag; - if (state.anchor !== null) { - state.anchorMap[state.anchor] = state.result; - } - break; - } - } - } else if (_hasOwnProperty$2.call(state.typeMap[state.kind || 'fallback'], state.tag)) { - type = state.typeMap[state.kind || 'fallback'][state.tag]; + } else if (state.tag === '?') { + // Implicit resolving is not allowed for non-scalar types, and '?' + // non-specific tag is only automatically assigned to plain scalars. + // + // We only need to check kind conformity in case user explicitly assigns '?' + // tag, for example like this: "! [0]" + // + if (state.result !== null && state.kind !== 'scalar') { + throwError(state, 'unacceptable node kind for ! tag; it should be "scalar", not "' + state.kind + '"'); + } - if (state.result !== null && type.kind !== state.kind) { - throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"'); - } + for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) { + type = state.implicitTypes[typeIndex]; - if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched - throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag'); - } else { + if (type.resolve(state.result)) { // `state.result` updated in resolver if matched state.result = type.construct(state.result); + state.tag = type.tag; if (state.anchor !== null) { state.anchorMap[state.anchor] = state.result; } + break; } + } + } else if (state.tag !== '!') { + if (_hasOwnProperty$2.call(state.typeMap[state.kind || 'fallback'], state.tag)) { + type = state.typeMap[state.kind || 'fallback'][state.tag]; } else { + // looking for multi type + type = null; + typeList = state.typeMap.multi[state.kind || 'fallback']; + + for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) { + if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) { + type = typeList[typeIndex]; + break; + } + } + } + + if (!type) { throwError(state, 'unknown tag !<' + state.tag + '>'); } + + if (state.result !== null && type.kind !== state.kind) { + throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"'); + } + + if (!type.resolve(state.result, state.tag)) { // `state.result` updated in resolver if matched + throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag'); + } else { + state.result = type.construct(state.result, state.tag); + if (state.anchor !== null) { + state.anchorMap[state.anchor] = state.result; + } + } } if (state.listener !== null) { @@ -2538,8 +2646,8 @@ state.version = null; state.checkLineBreaks = state.legacy; - state.tagMap = {}; - state.anchorMap = {}; + state.tagMap = Object.create(null); + state.anchorMap = Object.create(null); while ((ch = state.input.charCodeAt(state.position)) !== 0) { skipSeparationSpace(state, true, -1); @@ -2727,6 +2835,7 @@ var _toString$2 = Object.prototype.toString; var _hasOwnProperty$3 = Object.prototype.hasOwnProperty; + var CHAR_BOM = 0xFEFF; var CHAR_TAB = 0x09; /* Tab */ var CHAR_LINE_FEED = 0x0A; /* LF */ var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */ @@ -2775,6 +2884,8 @@ 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF' ]; + var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/; + function compileStyleMap(schema, map) { var result, keys, index, length, tag, style, type; @@ -2823,6 +2934,10 @@ return '\\' + handle + common.repeat('0', length - string.length) + string; } + + var QUOTING_TYPE_SINGLE = 1, + QUOTING_TYPE_DOUBLE = 2; + function State$1(options) { this.schema = options['schema'] || _default; this.indent = Math.max(1, (options['indent'] || 2)); @@ -2835,6 +2950,9 @@ this.noRefs = options['noRefs'] || false; this.noCompatMode = options['noCompatMode'] || false; this.condenseFlow = options['condenseFlow'] || false; + this.quotingType = options['quotingType'] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE; + this.forceQuotes = options['forceQuotes'] || false; + this.replacer = typeof options['replacer'] === 'function' ? options['replacer'] : null; this.implicitTypes = this.schema.compiledImplicit; this.explicitTypes = this.schema.compiledExplicit; @@ -2903,47 +3021,60 @@ function isPrintable(c) { return (0x00020 <= c && c <= 0x00007E) || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029) - || ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF /* BOM */) + || ((0x0E000 <= c && c <= 0x00FFFD) && c !== CHAR_BOM) || (0x10000 <= c && c <= 0x10FFFF); } // [34] ns-char ::= nb-char - s-white // [27] nb-char ::= c-printable - b-char - c-byte-order-mark // [26] b-char ::= b-line-feed | b-carriage-return - // [24] b-line-feed ::= #xA /* LF */ - // [25] b-carriage-return ::= #xD /* CR */ - // [3] c-byte-order-mark ::= #xFEFF - function isNsChar(c) { - return isPrintable(c) && !isWhitespace(c) - // byte-order-mark - && c !== 0xFEFF - // b-char + // Including s-white (for some reason, examples doesn't match specs in this aspect) + // ns-char ::= c-printable - b-line-feed - b-carriage-return - c-byte-order-mark + function isNsCharOrWhitespace(c) { + return isPrintable(c) + && c !== CHAR_BOM + // - b-char && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED; } - // Simplified test for values allowed after the first character in plain style. - function isPlainSafe(c, prev) { - // Uses a subset of nb-char - c-flow-indicator - ":" - "#" - // where nb-char ::= c-printable - b-char - c-byte-order-mark. - return isPrintable(c) && c !== 0xFEFF - // - c-flow-indicator - && c !== CHAR_COMMA - && c !== CHAR_LEFT_SQUARE_BRACKET - && c !== CHAR_RIGHT_SQUARE_BRACKET - && c !== CHAR_LEFT_CURLY_BRACKET - && c !== CHAR_RIGHT_CURLY_BRACKET - // - ":" - "#" - // /* An ns-char preceding */ "#" - && c !== CHAR_COLON - && ((c !== CHAR_SHARP) || (prev && isNsChar(prev))); + // [127] ns-plain-safe(c) ::= c = flow-out ⇒ ns-plain-safe-out + // c = flow-in ⇒ ns-plain-safe-in + // c = block-key ⇒ ns-plain-safe-out + // c = flow-key ⇒ ns-plain-safe-in + // [128] ns-plain-safe-out ::= ns-char + // [129] ns-plain-safe-in ::= ns-char - c-flow-indicator + // [130] ns-plain-char(c) ::= ( ns-plain-safe(c) - “:” - “#” ) + // | ( /* An ns-char preceding */ “#” ) + // | ( “:” /* Followed by an ns-plain-safe(c) */ ) + function isPlainSafe(c, prev, inblock) { + var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c); + var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c); + return ( + // ns-plain-safe + inblock ? // c = flow-in + cIsNsCharOrWhitespace + : cIsNsCharOrWhitespace + // - c-flow-indicator + && c !== CHAR_COMMA + && c !== CHAR_LEFT_SQUARE_BRACKET + && c !== CHAR_RIGHT_SQUARE_BRACKET + && c !== CHAR_LEFT_CURLY_BRACKET + && c !== CHAR_RIGHT_CURLY_BRACKET + ) + // ns-plain-char + && c !== CHAR_SHARP // false on '#' + && !(prev === CHAR_COLON && !cIsNsChar) // false on ': ' + || (isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP) // change to true on '[^ ]#' + || (prev === CHAR_COLON && cIsNsChar); // change to true on ':[^ ]' } // Simplified test for values allowed as the first character in plain style. function isPlainSafeFirst(c) { // Uses a subset of ns-char - c-indicator // where ns-char = nb-char - s-white. - return isPrintable(c) && c !== 0xFEFF + // No support of ( ( “?” | “:” | “-” ) /* Followed by an ns-plain-safe(c)) */ ) part + return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) // - s-white // - (c-indicator ::= // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}” @@ -2971,6 +3102,12 @@ && c !== CHAR_GRAVE_ACCENT; } + // Simplified test for values allowed as the last character in plain style. + function isPlainSafeLast(c) { + // just not whitespace or colon, it will be checked to be plain character later + return !isWhitespace(c) && c !== CHAR_COLON; + } + // Same as 'string'.codePointAt(pos), but works in older browsers. function codePointAt(string, pos) { var first = string.charCodeAt(pos), second; @@ -3003,7 +3140,9 @@ // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string. // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1). // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1). - function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) { + function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, + testAmbiguousType, quotingType, forceQuotes, inblock) { + var i; var char = 0; var prevChar = null; @@ -3012,9 +3151,9 @@ var shouldTrackWidth = lineWidth !== -1; var previousLineBreak = -1; // count the first line correctly var plain = isPlainSafeFirst(codePointAt(string, 0)) - && !isWhitespace(codePointAt(string, string.length - 1)); + && isPlainSafeLast(codePointAt(string, string.length - 1)); - if (singleLineOnly) { + if (singleLineOnly || forceQuotes) { // Case: no block styles. // Check for disallowed characters to rule out plain and single. for (i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) { @@ -3022,7 +3161,7 @@ if (!isPrintable(char)) { return STYLE_DOUBLE; } - plain = plain && isPlainSafe(char, prevChar); + plain = plain && isPlainSafe(char, prevChar, inblock); prevChar = char; } } else { @@ -3042,7 +3181,7 @@ } else if (!isPrintable(char)) { return STYLE_DOUBLE; } - plain = plain && isPlainSafe(char, prevChar); + plain = plain && isPlainSafe(char, prevChar, inblock); prevChar = char; } // in case the end is missing a \n @@ -3056,8 +3195,10 @@ if (!hasLineBreak && !hasFoldableLine) { // Strings interpretable as another type have to be quoted; // e.g. the string 'true' vs. the boolean true. - return plain && !testAmbiguousType(string) - ? STYLE_PLAIN : STYLE_SINGLE; + if (plain && !forceQuotes && !testAmbiguousType(string)) { + return STYLE_PLAIN; + } + return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; } // Edge case: block indentation indicator can only have one digit. if (indentPerLevel > 9 && needIndentIndicator(string)) { @@ -3065,7 +3206,10 @@ } // At this point we know block styles are valid. // Prefer literal style unless we want to fold. - return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL; + if (!forceQuotes) { + return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL; + } + return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; } // Note: line breaking/folding is implemented for only the folded style. @@ -3074,14 +3218,15 @@ // • No ending newline => unaffected; already using strip "-" chomping. // • Ending newline => removed then restored. // Importantly, this keeps the "+" chomp indicator from gaining an extra line. - function writeScalar(state, string, level, iskey) { + function writeScalar(state, string, level, iskey, inblock) { state.dump = (function () { if (string.length === 0) { - return "''"; + return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''"; } - if (!state.noCompatMode && - DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) { - return "'" + string + "'"; + if (!state.noCompatMode) { + if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) { + return state.quotingType === QUOTING_TYPE_DOUBLE ? ('"' + string + '"') : ("'" + string + "'"); + } } var indent = state.indent * Math.max(1, level); // no 0-indent scalars @@ -3103,7 +3248,9 @@ return testImplicitResolving(state, string); } - switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) { + switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, + testAmbiguity, state.quotingType, state.forceQuotes && !iskey, inblock)) { + case STYLE_PLAIN: return string; case STYLE_SINGLE: @@ -3242,12 +3389,22 @@ var _result = '', _tag = state.tag, index, - length; + length, + value; for (index = 0, length = object.length; index < length; index += 1) { - // Write only valid elements. - if (writeNode(state, level, object[index], false, false)) { - if (index !== 0) _result += ',' + (!state.condenseFlow ? ' ' : ''); + value = object[index]; + + if (state.replacer) { + value = state.replacer.call(object, String(index), value); + } + + // Write only valid elements, put null instead of invalid elements. + if (writeNode(state, level, value, false, false) || + (typeof value === 'undefined' && + writeNode(state, level, null, false, false))) { + + if (_result !== '') _result += ',' + (!state.condenseFlow ? ' ' : ''); _result += state.dump; } } @@ -3260,12 +3417,22 @@ var _result = '', _tag = state.tag, index, - length; + length, + value; for (index = 0, length = object.length; index < length; index += 1) { - // Write only valid elements. - if (writeNode(state, level + 1, object[index], true, true, false, true)) { - if (!compact || index !== 0) { + value = object[index]; + + if (state.replacer) { + value = state.replacer.call(object, String(index), value); + } + + // Write only valid elements, put null instead of invalid elements. + if (writeNode(state, level + 1, value, true, true, false, true) || + (typeof value === 'undefined' && + writeNode(state, level + 1, null, true, true, false, true))) { + + if (!compact || _result !== '') { _result += generateNextLine(state, level); } @@ -3296,13 +3463,17 @@ for (index = 0, length = objectKeyList.length; index < length; index += 1) { pairBuffer = ''; - if (index !== 0) pairBuffer += ', '; + if (_result !== '') pairBuffer += ', '; if (state.condenseFlow) pairBuffer += '"'; objectKey = objectKeyList[index]; objectValue = object[objectKey]; + if (state.replacer) { + objectValue = state.replacer.call(object, objectKey, objectValue); + } + if (!writeNode(state, level, objectKey, false, false)) { continue; // Skip this pair because of invalid key; } @@ -3351,13 +3522,17 @@ for (index = 0, length = objectKeyList.length; index < length; index += 1) { pairBuffer = ''; - if (!compact || index !== 0) { + if (!compact || _result !== '') { pairBuffer += generateNextLine(state, level); } objectKey = objectKeyList[index]; objectValue = object[objectKey]; + if (state.replacer) { + objectValue = state.replacer.call(object, objectKey, objectValue); + } + if (!writeNode(state, level + 1, objectKey, true, true, true)) { continue; // Skip this pair because of invalid key. } @@ -3411,7 +3586,15 @@ (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) && (!type.predicate || type.predicate(object))) { - state.tag = explicit ? type.tag : '?'; + if (explicit) { + if (type.multi && type.representName) { + state.tag = type.representName(object); + } else { + state.tag = type.tag; + } + } else { + state.tag = '?'; + } if (type.represent) { style = state.styleMap[type.tag] || type.defaultStyle; @@ -3446,6 +3629,8 @@ } var type = _toString$2.call(state.dump); + var inblock = block; + var tagStr; if (block) { block = (state.flowLevel < 0 || state.flowLevel > level); @@ -3500,15 +3685,42 @@ } } else if (type === '[object String]') { if (state.tag !== '?') { - writeScalar(state, state.dump, level, iskey); + writeScalar(state, state.dump, level, iskey, inblock); } + } else if (type === '[object Undefined]') { + return false; } else { if (state.skipInvalid) return false; throw new exception('unacceptable kind of an object to dump ' + type); } if (state.tag !== null && state.tag !== '?') { - state.dump = '!<' + state.tag + '> ' + state.dump; + // Need to encode all characters except those allowed by the spec: + // + // [35] ns-dec-digit ::= [#x30-#x39] /* 0-9 */ + // [36] ns-hex-digit ::= ns-dec-digit + // | [#x41-#x46] /* A-F */ | [#x61-#x66] /* a-f */ + // [37] ns-ascii-letter ::= [#x41-#x5A] /* A-Z */ | [#x61-#x7A] /* a-z */ + // [38] ns-word-char ::= ns-dec-digit | ns-ascii-letter | “-” + // [39] ns-uri-char ::= “%” ns-hex-digit ns-hex-digit | ns-word-char | “#” + // | “;” | “/” | “?” | “:” | “@” | “&” | “=” | “+” | “$” | “,” + // | “_” | “.” | “!” | “~” | “*” | “'” | “(” | “)” | “[” | “]” + // + // Also need to encode '!' because it has special meaning (end of tag prefix). + // + tagStr = encodeURI( + state.tag[0] === '!' ? state.tag.slice(1) : state.tag + ).replace(/!/g, '%21'); + + if (state.tag[0] === '!') { + tagStr = '!' + tagStr; + } else if (tagStr.slice(0, 18) === 'tag:yaml.org,2002:') { + tagStr = '!!' + tagStr.slice(18); + } else { + tagStr = '!<' + tagStr + '>'; + } + + state.dump = tagStr + ' ' + state.dump; } } @@ -3565,7 +3777,13 @@ if (!state.noRefs) getDuplicateReferences(input, state); - if (writeNode(state, 0, input, true, true)) return state.dump + '\n'; + var value = input; + + if (state.replacer) { + value = state.replacer.call({ '': value }, '', value); + } + + if (writeNode(state, 0, value, true, true)) return state.dump + '\n'; return ''; } diff --git a/dist/js-yaml.min.js b/dist/js-yaml.min.js index 126b033b..6a469523 100644 --- a/dist/js-yaml.min.js +++ b/dist/js-yaml.min.js @@ -1,2 +1,2 @@ -/*! js-yaml 3.14.0 https://github.com/nodeca/js-yaml @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jsyaml={})}(this,(function(t){"use strict";function e(t){return null==t}var n={isNothing:e,isObject:function(t){return"object"==typeof t&&null!==t},toArray:function(t){return Array.isArray(t)?t:e(t)?[]:[t]},repeat:function(t,e){var n,i="";for(n=0;n0&&-1==="\0\r\n…\u2028\u2029".indexOf(this.buffer.charAt(r-1));)if(r-=1,this.position-r>e/2-1){i=" ... ",r+=5;break}for(o="",a=this.position;ae/2-1){o=" ... ",a-=5;break}return l=this.buffer.slice(r,a),n.repeat(" ",t)+i+l+o+"\n"+n.repeat(" ",t+this.position-r+i.length)+"^"},o.prototype.toString=function(t){var e,n="";return this.name&&(n+='in "'+this.name+'" '),n+="at line "+(this.line+1)+", column "+(this.column+1),t||(e=this.getSnippet())&&(n+=":\n"+e),n};var a=o,l=["kind","resolve","construct","instanceOf","predicate","represent","defaultStyle","styleAliases"],s=["scalar","sequence","mapping"];var c=function(t,e){if(e=e||{},Object.keys(e).forEach((function(e){if(-1===l.indexOf(e))throw new r('Unknown option "'+e+'" is met in definition of "'+t+'" YAML type.')})),this.tag=t,this.kind=e.kind||null,this.resolve=e.resolve||function(){return!0},this.construct=e.construct||function(t){return t},this.instanceOf=e.instanceOf||null,this.predicate=e.predicate||null,this.represent=e.represent||null,this.defaultStyle=e.defaultStyle||null,this.styleAliases=function(t){var e={};return null!==t&&Object.keys(t).forEach((function(n){t[n].forEach((function(t){e[String(t)]=n}))})),e}(e.styleAliases||null),-1===s.indexOf(this.kind))throw new r('Unknown kind "'+this.kind+'" is specified for "'+t+'" YAML type.')};function u(t,e,n){var i=[];return t[e].forEach((function(t){n.forEach((function(e,n){e.tag===t.tag&&e.kind===t.kind&&i.push(n)})),n.push(t)})),n.filter((function(t,e){return-1===i.indexOf(e)}))}function p(t){return this.extend(t)}p.prototype.extend=function(t){var e=[],n=[];if(t instanceof c)n.push(t);else if(Array.isArray(t))n=n.concat(t);else{if(!t||!Array.isArray(t.implicit)&&!Array.isArray(t.explicit))throw new r("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");t.implicit&&(e=e.concat(t.implicit)),t.explicit&&(n=n.concat(t.explicit))}e.forEach((function(t){if(!(t instanceof c))throw new r("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(t.loadKind&&"scalar"!==t.loadKind)throw new r("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.")})),n.forEach((function(t){if(!(t instanceof c))throw new r("Specified list of YAML types (or a single Type object) contains a non-Type object.")}));var i=Object.create(p.prototype);return i.implicit=(this.implicit||[]).concat(e),i.explicit=(this.explicit||[]).concat(n),i.compiledImplicit=u(i,"implicit",[]),i.compiledExplicit=u(i,"explicit",[]),i.compiledTypeMap=function(){var t,e,n={scalar:{},sequence:{},mapping:{},fallback:{}};function i(t){n[t.kind][t.tag]=n.fallback[t.tag]=t}for(t=0,e=arguments.length;t=0?"0b"+t.toString(2):"-0b"+t.toString(2).slice(1)},octal:function(t){return t>=0?"0"+t.toString(8):"-0"+t.toString(8).slice(1)},decimal:function(t){return t.toString(10)},hexadecimal:function(t){return t>=0?"0x"+t.toString(16).toUpperCase():"-0x"+t.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),v=new RegExp("^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var b=/^[-+]?[0-9]+e/;var w=new c("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(t){return null!==t&&!(!v.test(t)||"_"===t[t.length-1])},construct:function(t){var e,n,i,r;return n="-"===(e=t.replace(/_/g,"").toLowerCase())[0]?-1:1,r=[],"+-".indexOf(e[0])>=0&&(e=e.slice(1)),".inf"===e?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===e?NaN:e.indexOf(":")>=0?(e.split(":").forEach((function(t){r.unshift(parseFloat(t,10))})),e=0,i=1,r.forEach((function(t){e+=t*i,i*=60})),n*e):n*parseFloat(e,10)},predicate:function(t){return"[object Number]"===Object.prototype.toString.call(t)&&(t%1!=0||n.isNegativeZero(t))},represent:function(t,e){var i;if(isNaN(t))switch(e){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===t)switch(e){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===t)switch(e){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(n.isNegativeZero(t))return"-0.0";return i=t.toString(10),b.test(i)?i.replace("e",".e"):i},defaultStyle:"lowercase"}),C=d.extend({implicit:[h,g,A,w]}),k=C,x=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),I=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var O=new c("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(t){return null!==t&&(null!==x.exec(t)||null!==I.exec(t))},construct:function(t){var e,n,i,r,o,a,l,s,c=0,u=null;if(null===(e=x.exec(t))&&(e=I.exec(t)),null===e)throw new Error("Date resolve error");if(n=+e[1],i=+e[2]-1,r=+e[3],!e[4])return new Date(Date.UTC(n,i,r));if(o=+e[4],a=+e[5],l=+e[6],e[7]){for(c=e[7].slice(0,3);c.length<3;)c+="0";c=+c}return e[9]&&(u=6e4*(60*+e[10]+ +(e[11]||0)),"-"===e[9]&&(u=-u)),s=new Date(Date.UTC(n,i,r,o,a,l,c)),u&&s.setTime(s.getTime()-u),s},instanceOf:Date,represent:function(t){return t.toISOString()}});var S,j=new c("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(t){return"<<"===t||null===t}});try{S=function(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.')}("buffer").Buffer}catch(t){}var E="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var F=new c("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(t){if(null===t)return!1;var e,n,i=0,r=t.length,o=E;for(n=0;n64)){if(e<0)return!1;i+=6}return i%8==0},construct:function(t){var e,n,i=t.replace(/[\r\n=]/g,""),r=i.length,o=E,a=0,l=[];for(e=0;e>16&255),l.push(a>>8&255),l.push(255&a)),a=a<<6|o.indexOf(i.charAt(e));return 0===(n=r%4*6)?(l.push(a>>16&255),l.push(a>>8&255),l.push(255&a)):18===n?(l.push(a>>10&255),l.push(a>>2&255)):12===n&&l.push(a>>4&255),S?S.from?S.from(l):new S(l):l},predicate:function(t){return S&&S.isBuffer(t)},represent:function(t){var e,n,i="",r=0,o=t.length,a=E;for(e=0;e>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]),r=(r<<8)+t[e];return 0===(n=o%3)?(i+=a[r>>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]):2===n?(i+=a[r>>10&63],i+=a[r>>4&63],i+=a[r<<2&63],i+=a[64]):1===n&&(i+=a[r>>2&63],i+=a[r<<4&63],i+=a[64],i+=a[64]),i}}),N=Object.prototype.hasOwnProperty,T=Object.prototype.toString;var M=new c("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(t){if(null===t)return!0;var e,n,i,r,o,a=[],l=t;for(e=0,n=l.length;e>10),56320+(t-65536&1023))}for(var X=new Array(256),tt=new Array(256),et=0;et<256;et++)X[et]=z(et)?1:0,tt[et]=z(et);function nt(t,e){this.input=t,this.filename=e.filename||null,this.schema=e.schema||q,this.onWarning=e.onWarning||null,this.legacy=e.legacy||!1,this.json=e.json||!1,this.listener=e.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=t.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.documents=[]}function it(t,e){return new r(e,new a(t.filename,t.input,t.position,t.line,t.position-t.lineStart))}function rt(t,e){throw it(t,e)}function ot(t,e){t.onWarning&&t.onWarning.call(null,it(t,e))}var at={YAML:function(t,e,n){var i,r,o;null!==t.version&&rt(t,"duplication of %YAML directive"),1!==n.length&&rt(t,"YAML directive accepts exactly one argument"),null===(i=/^([0-9]+)\.([0-9]+)$/.exec(n[0]))&&rt(t,"ill-formed argument of the YAML directive"),r=parseInt(i[1],10),o=parseInt(i[2],10),1!==r&&rt(t,"unacceptable YAML version of the document"),t.version=n[0],t.checkLineBreaks=o<2,1!==o&&2!==o&&ot(t,"unsupported YAML version of the document")},TAG:function(t,e,n){var i,r;2!==n.length&&rt(t,"TAG directive accepts exactly two arguments"),i=n[0],r=n[1],K.test(i)||rt(t,"ill-formed tag handle (first argument) of the TAG directive"),U.call(t.tagMap,i)&&rt(t,'there is a previously declared suffix for "'+i+'" tag handle'),W.test(r)||rt(t,"ill-formed tag prefix (second argument) of the TAG directive"),t.tagMap[i]=r}};function lt(t,e,n,i){var r,o,a,l;if(e1&&(t.result+=n.repeat("\n",e-1))}function ht(t,e){var n,i,r=t.tag,o=t.anchor,a=[],l=!1;for(null!==t.anchor&&(t.anchorMap[t.anchor]=a),i=t.input.charCodeAt(t.position);0!==i&&45===i&&V(t.input.charCodeAt(t.position+1));)if(l=!0,t.position++,pt(t,!0,-1)&&t.lineIndent<=e)a.push(null),i=t.input.charCodeAt(t.position);else if(n=t.line,yt(t,e,3,!1,!0),a.push(t.result),pt(t,!0,-1),i=t.input.charCodeAt(t.position),(t.line===n||t.lineIndent>e)&&0!==i)rt(t,"bad indentation of a sequence entry");else if(t.lineIndente?h=1:t.lineIndent===e?h=0:t.lineIndente?h=1:t.lineIndent===e?h=0:t.lineIndente)&&(yt(t,e,4,!0,r)&&(g?d=t.result:h=t.result),g||(ct(t,u,p,f,d,h,o,a),f=d=h=null),pt(t,!0,-1),l=t.input.charCodeAt(t.position)),t.lineIndent>e&&0!==l)rt(t,"bad indentation of a mapping entry");else if(t.lineIndent=0))break;0===o?rt(t,"bad explicit indentation width of a block scalar; it cannot be less than one"):u?rt(t,"repeat of an indentation width identifier"):(p=e+o-1,u=!0)}if($(a)){do{a=t.input.charCodeAt(++t.position)}while($(a));if(35===a)do{a=t.input.charCodeAt(++t.position)}while(!G(a)&&0!==a)}for(;0!==a;){for(ut(t),t.lineIndent=0,a=t.input.charCodeAt(t.position);(!u||t.lineIndentp&&(p=t.lineIndent),G(a))f++;else{if(t.lineIndent0){for(r=a,o=0;r>0;r--)(a=J(l=t.input.charCodeAt(++t.position)))>=0?o=(o<<4)+a:rt(t,"expected hexadecimal character");t.result+=Q(o),t.position++}else rt(t,"unknown escape sequence");n=i=t.position}else G(l)?(lt(t,n,i,!0),dt(t,pt(t,!1,e)),n=i=t.position):t.position===t.lineStart&&ft(t)?rt(t,"unexpected end of the document within a double quoted scalar"):(t.position++,i=t.position)}rt(t,"unexpected end of the stream within a double quoted scalar")}(t,f)?m=!0:!function(t){var e,n,i;if(42!==(i=t.input.charCodeAt(t.position)))return!1;for(i=t.input.charCodeAt(++t.position),e=t.position;0!==i&&!V(i)&&!Z(i);)i=t.input.charCodeAt(++t.position);return t.position===e&&rt(t,"name of an alias node must contain at least one character"),n=t.input.slice(e,t.position),t.anchorMap.hasOwnProperty(n)||rt(t,'unidentified alias "'+n+'"'),t.result=t.anchorMap[n],pt(t,!0,-1),!0}(t)?function(t,e,n){var i,r,o,a,l,s,c,u,p=t.kind,f=t.result;if(V(u=t.input.charCodeAt(t.position))||Z(u)||35===u||38===u||42===u||33===u||124===u||62===u||39===u||34===u||37===u||64===u||96===u)return!1;if((63===u||45===u)&&(V(i=t.input.charCodeAt(t.position+1))||n&&Z(i)))return!1;for(t.kind="scalar",t.result="",r=o=t.position,a=!1;0!==u;){if(58===u){if(V(i=t.input.charCodeAt(t.position+1))||n&&Z(i))break}else if(35===u){if(V(t.input.charCodeAt(t.position-1)))break}else{if(t.position===t.lineStart&&ft(t)||n&&Z(u))break;if(G(u)){if(l=t.line,s=t.lineStart,c=t.lineIndent,pt(t,!1,-1),t.lineIndent>=e){a=!0,u=t.input.charCodeAt(t.position);continue}t.position=o,t.line=l,t.lineStart=s,t.lineIndent=c;break}}a&&(lt(t,r,o,!1),dt(t,t.line-l),r=o=t.position,a=!1),$(u)||(o=t.position+1),u=t.input.charCodeAt(++t.position)}return lt(t,r,o,!1),!!t.result||(t.kind=p,t.result=f,!1)}(t,f,1===i)&&(m=!0,null===t.tag&&(t.tag="?")):(m=!0,null===t.tag&&null===t.anchor||rt(t,"alias node should not have any properties")),null!==t.anchor&&(t.anchorMap[t.anchor]=t.result)):0===h&&(m=s&&ht(t,d))),null!==t.tag&&"!"!==t.tag)if("?"===t.tag){for(null!==t.result&&"scalar"!==t.kind&&rt(t,'unacceptable node kind for ! tag; it should be "scalar", not "'+t.kind+'"'),c=0,u=t.implicitTypes.length;c tag; it should be "'+p.kind+'", not "'+t.kind+'"'),p.resolve(t.result)?(t.result=p.construct(t.result),null!==t.anchor&&(t.anchorMap[t.anchor]=t.result)):rt(t,"cannot resolve a node with !<"+t.tag+"> explicit tag")):rt(t,"unknown tag !<"+t.tag+">");return null!==t.listener&&t.listener("close",t),null!==t.tag||null!==t.anchor||m}function At(t){var e,n,i,r,o=t.position,a=!1;for(t.version=null,t.checkLineBreaks=t.legacy,t.tagMap={},t.anchorMap={};0!==(r=t.input.charCodeAt(t.position))&&(pt(t,!0,-1),r=t.input.charCodeAt(t.position),!(t.lineIndent>0||37!==r));){for(a=!0,r=t.input.charCodeAt(++t.position),e=t.position;0!==r&&!V(r);)r=t.input.charCodeAt(++t.position);for(i=[],(n=t.input.slice(e,t.position)).length<1&&rt(t,"directive name must not be less than one character in length");0!==r;){for(;$(r);)r=t.input.charCodeAt(++t.position);if(35===r){do{r=t.input.charCodeAt(++t.position)}while(0!==r&&!G(r));break}if(G(r))break;for(e=t.position;0!==r&&!V(r);)r=t.input.charCodeAt(++t.position);i.push(t.input.slice(e,t.position))}0!==r&&ut(t),U.call(at,n)?at[n](t,n,i):ot(t,'unknown document directive "'+n+'"')}pt(t,!0,-1),0===t.lineIndent&&45===t.input.charCodeAt(t.position)&&45===t.input.charCodeAt(t.position+1)&&45===t.input.charCodeAt(t.position+2)?(t.position+=3,pt(t,!0,-1)):a&&rt(t,"directives end mark is expected"),yt(t,t.lineIndent-1,4,!1,!0),pt(t,!0,-1),t.checkLineBreaks&&P.test(t.input.slice(o,t.position))&&ot(t,"non-ASCII line breaks are interpreted as content"),t.documents.push(t.result),t.position===t.lineStart&&ft(t)?46===t.input.charCodeAt(t.position)&&(t.position+=3,pt(t,!0,-1)):t.position=55296&&i<=56319&&e+1=56320&&n<=57343?1024*(i-55296)+n-56320+65536:i}function Mt(t){return/^\n* /.test(t)}function Lt(t,e,n,i,r){var o,a,l=0,s=null,c=!1,u=!1,p=-1!==i,f=-1,d=Ft(a=Tt(t,0))&&65279!==a&&!Et(a)&&45!==a&&63!==a&&58!==a&&44!==a&&91!==a&&93!==a&&123!==a&&125!==a&&35!==a&&38!==a&&42!==a&&33!==a&&124!==a&&61!==a&&62!==a&&39!==a&&34!==a&&37!==a&&64!==a&&96!==a&&!Et(Tt(t,t.length-1));if(e)for(o=0;o=65536?o+=2:o++){if(!Ft(l=Tt(t,o)))return 5;d=d&&Nt(l,s),s=l}else{for(o=0;o=65536?o+=2:o++){if(10===(l=Tt(t,o)))c=!0,p&&(u=u||o-f-1>i&&" "!==t[f+1],f=o);else if(!Ft(l))return 5;d=d&&Nt(l,s),s=l}u=u||p&&o-f-1>i&&" "!==t[f+1]}return c||u?n>9&&Mt(t)?5:u?4:3:d&&!r(t)?1:2}function _t(t,e,n,i){t.dump=function(){if(0===e.length)return"''";if(!t.noCompatMode&&-1!==xt.indexOf(e))return"'"+e+"'";var o=t.indent*Math.max(1,n),a=-1===t.lineWidth?-1:Math.max(Math.min(t.lineWidth,40),t.lineWidth-o),l=i||t.flowLevel>-1&&n>=t.flowLevel;switch(Lt(e,l,t.indent,a,(function(e){return function(t,e){var n,i;for(n=0,i=t.implicitTypes.length;n"+Dt(e,t.indent)+Yt(St(function(t,e){var n,i,r=/(\n+)([^\n]*)/g,o=(l=t.indexOf("\n"),l=-1!==l?l:t.length,r.lastIndex=l,qt(t.slice(0,l),e)),a="\n"===t[0]||" "===t[0];var l;for(;i=r.exec(t);){var s=i[1],c=i[2];n=" "===c[0],o+=s+(a||n||""===c?"":"\n")+qt(c,e),a=n}return o}(e,a),o));case 5:return'"'+function(t){for(var e,n="",i=0,r=0;r=65536?r+=2:r++)i=Tt(t,r),!(e=kt[i])&&Ft(i)?(n+=t[r],i>=65536&&(n+=t[r+1])):n+=e||It(i);return n}(e)+'"';default:throw new r("impossible error: invalid scalar style")}}()}function Dt(t,e){var n=Mt(t)?String(e):"",i="\n"===t[t.length-1];return n+(i&&("\n"===t[t.length-2]||"\n"===t)?"+":i?"":"-")+"\n"}function Yt(t){return"\n"===t[t.length-1]?t.slice(0,-1):t}function qt(t,e){if(""===t||" "===t[0])return t;for(var n,i,r=/ [^ ]/g,o=0,a=0,l=0,s="";n=r.exec(t);)(l=n.index)-o>e&&(i=a>o?a:l,s+="\n"+t.slice(o,i),o=i+1),a=l;return s+="\n",t.length-o>e&&a>o?s+=t.slice(o,a)+"\n"+t.slice(a+1):s+=t.slice(o),s.slice(1)}function Ut(t,e,n,i){var r,o,a="",l=t.tag;for(r=0,o=n.length;r tag resolver accepts not "'+c+'" style');i=s.represent[c](e,c)}t.dump=i}return!0}return!1}function Pt(t,e,n,i,o,a,l){t.tag=null,t.dump=n,Rt(t,n,!1)||Rt(t,n,!0);var s=wt.call(t.dump);i&&(i=t.flowLevel<0||t.flowLevel>e);var c,u,p="[object Object]"===s||"[object Array]"===s;if(p&&(u=-1!==(c=t.duplicates.indexOf(n))),(null!==t.tag&&"?"!==t.tag||u||2!==t.indent&&e>0)&&(o=!1),u&&t.usedDuplicates[c])t.dump="*ref_"+c;else{if(p&&u&&!t.usedDuplicates[c]&&(t.usedDuplicates[c]=!0),"[object Object]"===s)i&&0!==Object.keys(t.dump).length?(!function(t,e,n,i){var o,a,l,s,c,u,p="",f=t.tag,d=Object.keys(n);if(!0===t.sortKeys)d.sort();else if("function"==typeof t.sortKeys)d.sort(t.sortKeys);else if(t.sortKeys)throw new r("sortKeys must be a boolean or a function");for(o=0,a=d.length;o1024)&&(t.dump&&10===t.dump.charCodeAt(0)?u+="?":u+="? "),u+=t.dump,c&&(u+=jt(t,e)),Pt(t,e+1,s,!0,c)&&(t.dump&&10===t.dump.charCodeAt(0)?u+=":":u+=": ",p+=u+=t.dump));t.tag=f,t.dump=p||"{}"}(t,e,t.dump,o),u&&(t.dump="&ref_"+c+t.dump)):(!function(t,e,n){var i,r,o,a,l,s="",c=t.tag,u=Object.keys(n);for(i=0,r=u.length;i1024&&(l+="? "),l+=t.dump+(t.condenseFlow?'"':"")+":"+(t.condenseFlow?"":" "),Pt(t,e,a,!1,!1)&&(s+=l+=t.dump));t.tag=c,t.dump="{"+s+"}"}(t,e,t.dump),u&&(t.dump="&ref_"+c+" "+t.dump));else if("[object Array]"===s)i&&0!==t.dump.length?(t.noArrayIndent&&!l&&e>0?Ut(t,e-1,t.dump,o):Ut(t,e,t.dump,o),u&&(t.dump="&ref_"+c+t.dump)):(!function(t,e,n){var i,r,o="",a=t.tag;for(i=0,r=n.length;i "+t.dump)}return!0}function Bt(t,e){var n,i,r=[],o=[];for(Kt(t,r,o),n=0,i=o.length;nl&&(t=i-l+(o=" ... ").length),n-i>l&&(n=i+l-(a=" ...").length),{str:o+e.slice(t,n).replace(/\t/g,"→")+a,pos:i-t+o.length}}function l(e,t){return n.repeat(" ",t-e.length)+e}var c=function(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),"number"!=typeof t.indent&&(t.indent=1),"number"!=typeof t.linesBefore&&(t.linesBefore=3),"number"!=typeof t.linesAfter&&(t.linesAfter=2);for(var i,r=/\r?\n|\r|\0/g,o=[0],c=[],s=-1;i=r.exec(e.buffer);)c.push(i.index),o.push(i.index+i[0].length),e.position<=i.index&&s<0&&(s=o.length-2);s<0&&(s=o.length-1);var u,p,f="",d=Math.min(e.line+t.linesAfter,c.length).toString().length,h=t.maxLength-(t.indent+d+3);for(u=1;u<=t.linesBefore&&!(s-u<0);u++)p=a(e.buffer,o[s-u],c[s-u],e.position-(o[s]-o[s-u]),h),f=n.repeat(" ",t.indent)+l((e.line-u+1).toString(),d)+" | "+p.str+"\n"+f;for(p=a(e.buffer,o[s],c[s],e.position,h),f+=n.repeat(" ",t.indent)+l((e.line+1).toString(),d)+" | "+p.str+"\n",f+=n.repeat("-",t.indent+d+3+p.pos)+"^\n",u=1;u<=t.linesAfter&&!(s+u>=c.length);u++)p=a(e.buffer,o[s+u],c[s+u],e.position-(o[s]-o[s+u]),h),f+=n.repeat(" ",t.indent)+l((e.line+u+1).toString(),d)+" | "+p.str+"\n";return f.replace(/\n$/,"")},s=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],u=["scalar","sequence","mapping"];var p=function(e,t){if(t=t||{},Object.keys(t).forEach((function(t){if(-1===s.indexOf(t))throw new o('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')})),this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=function(e){var t={};return null!==e&&Object.keys(e).forEach((function(n){e[n].forEach((function(e){t[String(e)]=n}))})),t}(t.styleAliases||null),-1===u.indexOf(this.kind))throw new o('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function f(e,t,n){var i=[];return e[t].forEach((function(e){n.forEach((function(t,n){t.tag===e.tag&&t.kind===e.kind&&t.multi===e.multi&&i.push(n)})),n.push(e)})),n.filter((function(e,t){return-1===i.indexOf(t)}))}function d(e){return this.extend(e)}d.prototype.extend=function(e){var t=[],n=[];if(e instanceof p)n.push(e);else if(Array.isArray(e))n=n.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new o("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit))}t.forEach((function(e){if(!(e instanceof p))throw new o("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new o("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new o("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")})),n.forEach((function(e){if(!(e instanceof p))throw new o("Specified list of YAML types (or a single Type object) contains a non-Type object.")}));var i=Object.create(d.prototype);return i.implicit=(this.implicit||[]).concat(t),i.explicit=(this.explicit||[]).concat(n),i.compiledImplicit=f(i,"implicit",[]),i.compiledExplicit=f(i,"explicit",[]),i.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function i(e){e.multi?(n.multi[e.kind].push(e),n.multi.fallback.push(e)):n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),w=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var k=/^[-+]?[0-9]+e/;var C=new p("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!w.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n;return n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:n*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||n.isNegativeZero(e))},represent:function(e,t){var i;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(n.isNegativeZero(e))return"-0.0";return i=e.toString(10),k.test(i)?i.replace("e",".e"):i},defaultStyle:"lowercase"}),x=g.extend({implicit:[m,y,v,C]}),I=x,S=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),O=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var j=new p("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==S.exec(e)||null!==O.exec(e))},construct:function(e){var t,n,i,r,o,a,l,c,s=0,u=null;if(null===(t=S.exec(e))&&(t=O.exec(e)),null===t)throw new Error("Date resolve error");if(n=+t[1],i=+t[2]-1,r=+t[3],!t[4])return new Date(Date.UTC(n,i,r));if(o=+t[4],a=+t[5],l=+t[6],t[7]){for(s=t[7].slice(0,3);s.length<3;)s+="0";s=+s}return t[9]&&(u=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(u=-u)),c=new Date(Date.UTC(n,i,r,o,a,l,s)),u&&c.setTime(c.getTime()-u),c},instanceOf:Date,represent:function(e){return e.toISOString()}});var T=new p("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),N="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var F=new p("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,i=0,r=e.length,o=N;for(n=0;n64)){if(t<0)return!1;i+=6}return i%8==0},construct:function(e){var t,n,i=e.replace(/[\r\n=]/g,""),r=i.length,o=N,a=0,l=[];for(t=0;t>16&255),l.push(a>>8&255),l.push(255&a)),a=a<<6|o.indexOf(i.charAt(t));return 0===(n=r%4*6)?(l.push(a>>16&255),l.push(a>>8&255),l.push(255&a)):18===n?(l.push(a>>10&255),l.push(a>>2&255)):12===n&&l.push(a>>4&255),new Uint8Array(l)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,n,i="",r=0,o=e.length,a=N;for(t=0;t>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]),r=(r<<8)+e[t];return 0===(n=o%3)?(i+=a[r>>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]):2===n?(i+=a[r>>10&63],i+=a[r>>4&63],i+=a[r<<2&63],i+=a[64]):1===n&&(i+=a[r>>2&63],i+=a[r<<4&63],i+=a[64],i+=a[64]),i}}),E=Object.prototype.hasOwnProperty,M=Object.prototype.toString;var L=new p("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,i,r,o,a=[],l=e;for(t=0,n=l.length;t>10),56320+(e-65536&1023))}for(var ee=new Array(256),te=new Array(256),ne=0;ne<256;ne++)ee[ne]=z(ne)?1:0,te[ne]=z(ne);function ie(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||q,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function re(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=c(n),new o(t,n)}function oe(e,t){throw re(e,t)}function ae(e,t){e.onWarning&&e.onWarning.call(null,re(e,t))}var le={YAML:function(e,t,n){var i,r,o;null!==e.version&&oe(e,"duplication of %YAML directive"),1!==n.length&&oe(e,"YAML directive accepts exactly one argument"),null===(i=/^([0-9]+)\.([0-9]+)$/.exec(n[0]))&&oe(e,"ill-formed argument of the YAML directive"),r=parseInt(i[1],10),o=parseInt(i[2],10),1!==r&&oe(e,"unacceptable YAML version of the document"),e.version=n[0],e.checkLineBreaks=o<2,1!==o&&2!==o&&ae(e,"unsupported YAML version of the document")},TAG:function(e,t,n){var i,r;2!==n.length&&oe(e,"TAG directive accepts exactly two arguments"),i=n[0],r=n[1],W.test(i)||oe(e,"ill-formed tag handle (first argument) of the TAG directive"),R.call(e.tagMap,i)&&oe(e,'there is a previously declared suffix for "'+i+'" tag handle'),H.test(r)||oe(e,"ill-formed tag prefix (second argument) of the TAG directive");try{r=decodeURIComponent(r)}catch(t){oe(e,"tag prefix is malformed: "+r)}e.tagMap[i]=r}};function ce(e,t,n,i){var r,o,a,l;if(t1&&(e.result+=n.repeat("\n",t-1))}function ge(e,t){var n,i,r=e.tag,o=e.anchor,a=[],l=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),i=e.input.charCodeAt(e.position);0!==i&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,oe(e,"tab characters must not be used in indentation")),45===i)&&Z(e.input.charCodeAt(e.position+1));)if(l=!0,e.position++,fe(e,!0,-1)&&e.lineIndent<=t)a.push(null),i=e.input.charCodeAt(e.position);else if(n=e.line,be(e,t,3,!1,!0),a.push(e.result),fe(e,!0,-1),i=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==i)oe(e,"bad indentation of a sequence entry");else if(e.lineIndentt?g=1:e.lineIndent===t?g=0:e.lineIndentt?g=1:e.lineIndent===t?g=0:e.lineIndentt)&&(y&&(a=e.line,l=e.lineStart,c=e.position),be(e,t,4,!0,r)&&(y?g=e.result:m=e.result),y||(ue(e,f,d,h,g,m,a,l,c),h=g=m=null),fe(e,!0,-1),s=e.input.charCodeAt(e.position)),(e.line===o||e.lineIndent>t)&&0!==s)oe(e,"bad indentation of a mapping entry");else if(e.lineIndent=0))break;0===o?oe(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):u?oe(e,"repeat of an indentation width identifier"):(p=t+o-1,u=!0)}if(V(a)){do{a=e.input.charCodeAt(++e.position)}while(V(a));if(35===a)do{a=e.input.charCodeAt(++e.position)}while(!G(a)&&0!==a)}for(;0!==a;){for(pe(e),e.lineIndent=0,a=e.input.charCodeAt(e.position);(!u||e.lineIndentp&&(p=e.lineIndent),G(a))f++;else{if(e.lineIndent0){for(r=a,o=0;r>0;r--)(a=Q(l=e.input.charCodeAt(++e.position)))>=0?o=(o<<4)+a:oe(e,"expected hexadecimal character");e.result+=X(o),e.position++}else oe(e,"unknown escape sequence");n=i=e.position}else G(l)?(ce(e,n,i,!0),he(e,fe(e,!1,t)),n=i=e.position):e.position===e.lineStart&&de(e)?oe(e,"unexpected end of the document within a double quoted scalar"):(e.position++,i=e.position)}oe(e,"unexpected end of the stream within a double quoted scalar")}(e,d)?y=!0:!function(e){var t,n,i;if(42!==(i=e.input.charCodeAt(e.position)))return!1;for(i=e.input.charCodeAt(++e.position),t=e.position;0!==i&&!Z(i)&&!J(i);)i=e.input.charCodeAt(++e.position);return e.position===t&&oe(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),R.call(e.anchorMap,n)||oe(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],fe(e,!0,-1),!0}(e)?function(e,t,n){var i,r,o,a,l,c,s,u,p=e.kind,f=e.result;if(Z(u=e.input.charCodeAt(e.position))||J(u)||35===u||38===u||42===u||33===u||124===u||62===u||39===u||34===u||37===u||64===u||96===u)return!1;if((63===u||45===u)&&(Z(i=e.input.charCodeAt(e.position+1))||n&&J(i)))return!1;for(e.kind="scalar",e.result="",r=o=e.position,a=!1;0!==u;){if(58===u){if(Z(i=e.input.charCodeAt(e.position+1))||n&&J(i))break}else if(35===u){if(Z(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&de(e)||n&&J(u))break;if(G(u)){if(l=e.line,c=e.lineStart,s=e.lineIndent,fe(e,!1,-1),e.lineIndent>=t){a=!0,u=e.input.charCodeAt(e.position);continue}e.position=o,e.line=l,e.lineStart=c,e.lineIndent=s;break}}a&&(ce(e,r,o,!1),he(e,e.line-l),r=o=e.position,a=!1),V(u)||(o=e.position+1),u=e.input.charCodeAt(++e.position)}return ce(e,r,o,!1),!!e.result||(e.kind=p,e.result=f,!1)}(e,d,1===i)&&(y=!0,null===e.tag&&(e.tag="?")):(y=!0,null===e.tag&&null===e.anchor||oe(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===g&&(y=c&&ge(e,h))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&oe(e,'unacceptable node kind for ! tag; it should be "scalar", not "'+e.kind+'"'),s=0,u=e.implicitTypes.length;s"),null!==e.result&&f.kind!==e.kind&&oe(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+f.kind+'", not "'+e.kind+'"'),f.resolve(e.result,e.tag)?(e.result=f.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):oe(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||y}function Ae(e){var t,n,i,r,o=e.position,a=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(r=e.input.charCodeAt(e.position))&&(fe(e,!0,-1),r=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==r));){for(a=!0,r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!Z(r);)r=e.input.charCodeAt(++e.position);for(i=[],(n=e.input.slice(t,e.position)).length<1&&oe(e,"directive name must not be less than one character in length");0!==r;){for(;V(r);)r=e.input.charCodeAt(++e.position);if(35===r){do{r=e.input.charCodeAt(++e.position)}while(0!==r&&!G(r));break}if(G(r))break;for(t=e.position;0!==r&&!Z(r);)r=e.input.charCodeAt(++e.position);i.push(e.input.slice(t,e.position))}0!==r&&pe(e),R.call(le,n)?le[n](e,n,i):ae(e,'unknown document directive "'+n+'"')}fe(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,fe(e,!0,-1)):a&&oe(e,"directives end mark is expected"),be(e,e.lineIndent-1,4,!1,!0),fe(e,!0,-1),e.checkLineBreaks&&K.test(e.input.slice(o,e.position))&&ae(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&de(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,fe(e,!0,-1)):e.position=55296&&i<=56319&&t+1=56320&&n<=57343?1024*(i-55296)+n-56320+65536:i}function Ue(e){return/^\n* /.test(e)}function Ye(e,t,n,i,r,o,a,l){var c,s,u=0,p=null,f=!1,d=!1,h=-1!==i,g=-1,m=Me(s=De(e,0))&&s!==xe&&!Ee(s)&&45!==s&&63!==s&&58!==s&&44!==s&&91!==s&&93!==s&&123!==s&&125!==s&&35!==s&&38!==s&&42!==s&&33!==s&&124!==s&&61!==s&&62!==s&&39!==s&&34!==s&&37!==s&&64!==s&&96!==s&&function(e){return!Ee(e)&&58!==e}(De(e,e.length-1));if(t||a)for(c=0;c=65536?c+=2:c++){if(!Me(u=De(e,c)))return 5;m=m&&_e(u,p,l),p=u}else{for(c=0;c=65536?c+=2:c++){if(10===(u=De(e,c)))f=!0,h&&(d=d||c-g-1>i&&" "!==e[g+1],g=c);else if(!Me(u))return 5;m=m&&_e(u,p,l),p=u}d=d||h&&c-g-1>i&&" "!==e[g+1]}return f||d?n>9&&Ue(e)?5:a?2===o?5:2:d?4:3:!m||a||r(e)?2===o?5:2:1}function qe(e,t,n,i,r){e.dump=function(){if(0===t.length)return 2===e.quotingType?'""':"''";if(!e.noCompatMode&&(-1!==Se.indexOf(t)||Oe.test(t)))return 2===e.quotingType?'"'+t+'"':"'"+t+"'";var a=e.indent*Math.max(1,n),l=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-a),c=i||e.flowLevel>-1&&n>=e.flowLevel;switch(Ye(t,c,e.indent,l,(function(t){return function(e,t){var n,i;for(n=0,i=e.implicitTypes.length;n"+Re(t,e.indent)+Be(Ne(function(e,t){var n,i,r=/(\n+)([^\n]*)/g,o=(l=e.indexOf("\n"),l=-1!==l?l:e.length,r.lastIndex=l,Ke(e.slice(0,l),t)),a="\n"===e[0]||" "===e[0];var l;for(;i=r.exec(e);){var c=i[1],s=i[2];n=" "===s[0],o+=c+(a||n||""===s?"":"\n")+Ke(s,t),a=n}return o}(t,l),a));case 5:return'"'+function(e){for(var t,n="",i=0,r=0;r=65536?r+=2:r++)i=De(e,r),!(t=Ie[i])&&Me(i)?(n+=e[r],i>=65536&&(n+=e[r+1])):n+=t||je(i);return n}(t)+'"';default:throw new o("impossible error: invalid scalar style")}}()}function Re(e,t){var n=Ue(e)?String(t):"",i="\n"===e[e.length-1];return n+(i&&("\n"===e[e.length-2]||"\n"===e)?"+":i?"":"-")+"\n"}function Be(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function Ke(e,t){if(""===e||" "===e[0])return e;for(var n,i,r=/ [^ ]/g,o=0,a=0,l=0,c="";n=r.exec(e);)(l=n.index)-o>t&&(i=a>o?a:l,c+="\n"+e.slice(o,i),o=i+1),a=l;return c+="\n",e.length-o>t&&a>o?c+=e.slice(o,a)+"\n"+e.slice(a+1):c+=e.slice(o),c.slice(1)}function Pe(e,t,n,i){var r,o,a,l="",c=e.tag;for(r=0,o=n.length;r tag resolver accepts not "'+s+'" style');i=c.represent[s](t,s)}e.dump=i}return!0}return!1}function He(e,t,n,i,r,a,l){e.tag=null,e.dump=n,We(e,n,!1)||We(e,n,!0);var c,s=ke.call(e.dump),u=i;i&&(i=e.flowLevel<0||e.flowLevel>t);var p,f,d="[object Object]"===s||"[object Array]"===s;if(d&&(f=-1!==(p=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||f||2!==e.indent&&t>0)&&(r=!1),f&&e.usedDuplicates[p])e.dump="*ref_"+p;else{if(d&&f&&!e.usedDuplicates[p]&&(e.usedDuplicates[p]=!0),"[object Object]"===s)i&&0!==Object.keys(e.dump).length?(!function(e,t,n,i){var r,a,l,c,s,u,p="",f=e.tag,d=Object.keys(n);if(!0===e.sortKeys)d.sort();else if("function"==typeof e.sortKeys)d.sort(e.sortKeys);else if(e.sortKeys)throw new o("sortKeys must be a boolean or a function");for(r=0,a=d.length;r1024)&&(e.dump&&10===e.dump.charCodeAt(0)?u+="?":u+="? "),u+=e.dump,s&&(u+=Fe(e,t)),He(e,t+1,c,!0,s)&&(e.dump&&10===e.dump.charCodeAt(0)?u+=":":u+=": ",p+=u+=e.dump));e.tag=f,e.dump=p||"{}"}(e,t,e.dump,r),f&&(e.dump="&ref_"+p+e.dump)):(!function(e,t,n){var i,r,o,a,l,c="",s=e.tag,u=Object.keys(n);for(i=0,r=u.length;i1024&&(l+="? "),l+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),He(e,t,a,!1,!1)&&(c+=l+=e.dump));e.tag=s,e.dump="{"+c+"}"}(e,t,e.dump),f&&(e.dump="&ref_"+p+" "+e.dump));else if("[object Array]"===s)i&&0!==e.dump.length?(e.noArrayIndent&&!l&&t>0?Pe(e,t-1,e.dump,r):Pe(e,t,e.dump,r),f&&(e.dump="&ref_"+p+e.dump)):(!function(e,t,n){var i,r,o,a="",l=e.tag;for(i=0,r=n.length;i",e.dump=c+" "+e.dump)}return!0}function $e(e,t){var n,i,r=[],o=[];for(Ge(e,r,o),n=0,i=o.length;n maxHalfLength) { + head = ' ... '; + lineStart = position - maxHalfLength + head.length; + } -var exception = YAMLException; + if (lineEnd - position > maxHalfLength) { + tail = ' ...'; + lineEnd = position + maxHalfLength - tail.length; + } -function Mark(name, buffer, position, line, column) { - this.name = name; - this.buffer = buffer; - this.position = position; - this.line = line; - this.column = column; + return { + str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, '→') + tail, + pos: position - lineStart + head.length // relative position + }; } -Mark.prototype.getSnippet = function getSnippet(indent, maxLength) { - var head, start, tail, end, snippet; +function padStart(string, max) { + return common.repeat(' ', max - string.length) + string; +} - if (!this.buffer) return null; - indent = indent || 4; - maxLength = maxLength || 75; +function makeSnippet(mark, options) { + options = Object.create(options || null); - head = ''; - start = this.position; + if (!mark.buffer) return null; - while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) { - start -= 1; - if (this.position - start > (maxLength / 2 - 1)) { - head = ' ... '; - start += 5; - break; - } - } + if (!options.maxLength) options.maxLength = 79; + if (typeof options.indent !== 'number') options.indent = 1; + if (typeof options.linesBefore !== 'number') options.linesBefore = 3; + if (typeof options.linesAfter !== 'number') options.linesAfter = 2; - tail = ''; - end = this.position; + var re = /\r?\n|\r|\0/g; + var lineStarts = [ 0 ]; + var lineEnds = []; + var match; + var foundLineNo = -1; - while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) { - end += 1; - if (end - this.position > (maxLength / 2 - 1)) { - tail = ' ... '; - end -= 5; - break; + while ((match = re.exec(mark.buffer))) { + lineEnds.push(match.index); + lineStarts.push(match.index + match[0].length); + + if (mark.position <= match.index && foundLineNo < 0) { + foundLineNo = lineStarts.length - 2; } } - snippet = this.buffer.slice(start, end); - - return common.repeat(' ', indent) + head + snippet + tail + '\n' + - common.repeat(' ', indent + this.position - start + head.length) + '^'; -}; - + if (foundLineNo < 0) foundLineNo = lineStarts.length - 1; -Mark.prototype.toString = function toString(compact) { - var snippet, where = ''; + var result = '', i, line; + var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length; + var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3); - if (this.name) { - where += 'in "' + this.name + '" '; + for (i = 1; i <= options.linesBefore; i++) { + if (foundLineNo - i < 0) break; + line = getLine( + mark.buffer, + lineStarts[foundLineNo - i], + lineEnds[foundLineNo - i], + mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), + maxLineLength + ); + result = common.repeat(' ', options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + + ' | ' + line.str + '\n' + result; } - where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1); + line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength); + result += common.repeat(' ', options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + + ' | ' + line.str + '\n'; + result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n'; - if (!compact) { - snippet = this.getSnippet(); - - if (snippet) { - where += ':\n' + snippet; - } + for (i = 1; i <= options.linesAfter; i++) { + if (foundLineNo + i >= lineEnds.length) break; + line = getLine( + mark.buffer, + lineStarts[foundLineNo + i], + lineEnds[foundLineNo + i], + mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), + maxLineLength + ); + result += common.repeat(' ', options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + + ' | ' + line.str + '\n'; } - return where; -}; + return result.replace(/\n$/, ''); +} -var mark = Mark; +var snippet = makeSnippet; var TYPE_CONSTRUCTOR_OPTIONS = [ 'kind', + 'multi', 'resolve', 'construct', 'instanceOf', 'predicate', 'represent', + 'representName', 'defaultStyle', 'styleAliases' ]; @@ -220,15 +259,17 @@ function Type(tag, options) { }); // TODO: Add tag format check. - this.tag = tag; - this.kind = options['kind'] || null; - this.resolve = options['resolve'] || function () { return true; }; - this.construct = options['construct'] || function (data) { return data; }; - this.instanceOf = options['instanceOf'] || null; - this.predicate = options['predicate'] || null; - this.represent = options['represent'] || null; - this.defaultStyle = options['defaultStyle'] || null; - this.styleAliases = compileStyleAliases(options['styleAliases'] || null); + this.tag = tag; + this.kind = options['kind'] || null; + this.resolve = options['resolve'] || function () { return true; }; + this.construct = options['construct'] || function (data) { return data; }; + this.instanceOf = options['instanceOf'] || null; + this.predicate = options['predicate'] || null; + this.represent = options['represent'] || null; + this.representName = options['representName'] || null; + this.defaultStyle = options['defaultStyle'] || null; + this.multi = options['multi'] || false; + this.styleAliases = compileStyleAliases(options['styleAliases'] || null); if (YAML_NODE_KINDS.indexOf(this.kind) === -1) { throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.'); @@ -248,7 +289,10 @@ function compileList(schema, name, result) { schema[name].forEach(function (currentType) { result.forEach(function (previousType, previousIndex) { - if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) { + if (previousType.tag === currentType.tag && + previousType.kind === currentType.kind && + previousType.multi === currentType.multi) { + exclude.push(previousIndex); } }); @@ -267,11 +311,22 @@ function compileMap(/* lists... */) { scalar: {}, sequence: {}, mapping: {}, - fallback: {} + fallback: {}, + multi: { + scalar: [], + sequence: [], + mapping: [], + fallback: [] + } }, index, length; function collectType(type) { - result[type.kind][type.tag] = result['fallback'][type.tag] = type; + if (type.multi) { + result.multi[type.kind].push(type); + result.multi['fallback'].push(type); + } else { + result[type.kind][type.tag] = result['fallback'][type.tag] = type; + } } for (index = 0, length = arguments.length; index < length; index += 1) { @@ -316,6 +371,10 @@ Schema.prototype.extend = function extend(definition) { if (type$1.loadKind && type$1.loadKind !== 'scalar') { throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.'); } + + if (type$1.multi) { + throw new exception('There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.'); + } }); explicit.forEach(function (type$1) { @@ -388,7 +447,8 @@ var _null = new type('tag:yaml.org,2002:null', { canonical: function () { return '~'; }, lowercase: function () { return 'null'; }, uppercase: function () { return 'NULL'; }, - camelcase: function () { return 'Null'; } + camelcase: function () { return 'Null'; }, + empty: function () { return ''; } }, defaultStyle: 'lowercase' }); @@ -490,17 +550,22 @@ function resolveYamlInteger(data) { return hasDigits && ch !== '_'; } - // base 8 - for (; index < max; index++) { - ch = data[index]; - if (ch === '_') continue; - if (!isOctCode(data.charCodeAt(index))) return false; - hasDigits = true; + + if (ch === 'o') { + // base 8 + index++; + + for (; index < max; index++) { + ch = data[index]; + if (ch === '_') continue; + if (!isOctCode(data.charCodeAt(index))) return false; + hasDigits = true; + } + return hasDigits && ch !== '_'; } - return hasDigits && ch !== '_'; } - // base 10 (except 0) or base 60 + // base 10 (except 0) // value should not start with `_`; if (ch === '_') return false; @@ -508,7 +573,6 @@ function resolveYamlInteger(data) { for (; index < max; index++) { ch = data[index]; if (ch === '_') continue; - if (ch === ':') break; if (!isDecCode(data.charCodeAt(index))) { return false; } @@ -518,15 +582,11 @@ function resolveYamlInteger(data) { // Should have digits and should not end with `_` if (!hasDigits || ch === '_') return false; - // if !base60 - done; - if (ch !== ':') return true; - - // base60 almost not used, no needs to optimize - return /^(:[0-5]?[0-9])+$/.test(data.slice(index)); + return true; } function constructYamlInteger(data) { - var value = data, sign = 1, ch, base, digits = []; + var value = data, sign = 1, ch; if (value.indexOf('_') !== -1) { value = value.replace(/_/g, ''); @@ -544,25 +604,8 @@ function constructYamlInteger(data) { if (ch === '0') { if (value[1] === 'b') return sign * parseInt(value.slice(2), 2); - if (value[1] === 'x') return sign * parseInt(value, 16); - return sign * parseInt(value, 8); - } - - if (value.indexOf(':') !== -1) { - value.split(':').forEach(function (v) { - digits.unshift(parseInt(v, 10)); - }); - - value = 0; - base = 1; - - digits.forEach(function (d) { - value += (d * base); - base *= 60; - }); - - return sign * value; - + if (value[1] === 'x') return sign * parseInt(value.slice(2), 16); + if (value[1] === 'o') return sign * parseInt(value.slice(2), 8); } return sign * parseInt(value, 10); @@ -580,7 +623,7 @@ var int = new type('tag:yaml.org,2002:int', { predicate: isInteger, represent: { binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1); }, - octal: function (obj) { return obj >= 0 ? '0' + obj.toString(8) : '-0' + obj.toString(8).slice(1); }, + octal: function (obj) { return obj >= 0 ? '0o' + obj.toString(8) : '-0o' + obj.toString(8).slice(1); }, decimal: function (obj) { return obj.toString(10); }, /* eslint-disable max-len */ hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1); } @@ -596,12 +639,10 @@ var int = new type('tag:yaml.org,2002:int', { var YAML_FLOAT_PATTERN = new RegExp( // 2.5e4, 2.5 and integers - '^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' + + '^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' + // .2e4, .2 // special case, seems not from spec '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' + - // 20:59 - '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' + // .inf '|[-+]?\\.(?:inf|Inf|INF)' + // .nan @@ -621,11 +662,10 @@ function resolveYamlFloat(data) { } function constructYamlFloat(data) { - var value, sign, base, digits; + var value, sign; value = data.replace(/_/g, '').toLowerCase(); sign = value[0] === '-' ? -1 : 1; - digits = []; if ('+-'.indexOf(value[0]) >= 0) { value = value.slice(1); @@ -636,22 +676,6 @@ function constructYamlFloat(data) { } else if (value === '.nan') { return NaN; - - } else if (value.indexOf(':') >= 0) { - value.split(':').forEach(function (v) { - digits.unshift(parseFloat(v, 10)); - }); - - value = 0.0; - base = 1; - - digits.forEach(function (d) { - value += d * base; - base *= 60; - }); - - return sign * value; - } return sign * parseFloat(value, 10); } @@ -811,19 +835,8 @@ var merge = new type('tag:yaml.org,2002:merge', { resolve: resolveYamlMerge }); -function commonjsRequire (target) { - throw new Error('Could not dynamically require "' + target + '". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.'); -} - /*eslint-disable no-bitwise*/ -var NodeBuffer; - -try { - // A trick for browserified version, to not include `Buffer` shim - var _require = commonjsRequire; - NodeBuffer = _require('buffer').Buffer; -} catch (__) {} @@ -889,13 +902,7 @@ function constructYamlBinary(data) { result.push((bits >> 4) & 0xFF); } - // Wrap into Buffer for NodeJS and leave Array for browser - if (NodeBuffer) { - // Support node 6.+ Buffer API when available - return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result); - } - - return result; + return new Uint8Array(result); } function representYamlBinary(object /*, style*/) { @@ -940,8 +947,8 @@ function representYamlBinary(object /*, style*/) { return result; } -function isBinary(object) { - return NodeBuffer && NodeBuffer.isBuffer(object); +function isBinary(obj) { + return Object.prototype.toString.call(obj) === '[object Uint8Array]'; } var binary = new type('tag:yaml.org,2002:binary', { @@ -1216,7 +1223,10 @@ function State(input, options) { this.filename = options['filename'] || null; this.schema = options['schema'] || _default; this.onWarning = options['onWarning'] || null; + // (Hidden) Remove? makes the loader to expect YAML 1.1 documents + // if such documents have no explicit %YAML directive this.legacy = options['legacy'] || false; + this.json = options['json'] || false; this.listener = options['listener'] || null; @@ -1229,6 +1239,10 @@ function State(input, options) { this.lineStart = 0; this.lineIndent = 0; + // position of first leading tab in the current line, + // used to make sure there are no tabs in the indentation + this.firstTabInLine = -1; + this.documents = []; /* @@ -1245,9 +1259,17 @@ function State(input, options) { function generateError(state, message) { - return new exception( - message, - new mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart))); + var mark = { + name: state.filename, + buffer: state.input.slice(0, -1), // omit trailing \0 + position: state.position, + line: state.line, + column: state.position - state.lineStart + }; + + mark.snippet = snippet(mark); + + return new exception(message, mark); } function throwError(state, message) { @@ -1319,6 +1341,12 @@ var directiveHandlers = { throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive'); } + try { + prefix = decodeURIComponent(prefix); + } catch (err) { + throwError(state, 'tag prefix is malformed: ' + prefix); + } + state.tagMap[handle] = prefix; } }; @@ -1365,7 +1393,9 @@ function mergeMappings(state, destination, source, overridableKeys) { } } -function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) { +function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, + startLine, startLineStart, startPos) { + var index, quantity; // The output is a plain object here, so keys can only be strings. @@ -1412,10 +1442,22 @@ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valu !_hasOwnProperty$2.call(overridableKeys, keyNode) && _hasOwnProperty$2.call(_result, keyNode)) { state.line = startLine || state.line; + state.lineStart = startLineStart || state.lineStart; state.position = startPos || state.position; throwError(state, 'duplicated mapping key'); } - _result[keyNode] = valueNode; + + // used for this specific key only because Object.defineProperty is slow + if (keyNode === '__proto__') { + Object.defineProperty(_result, keyNode, { + configurable: true, + enumerable: true, + writable: true, + value: valueNode + }); + } else { + _result[keyNode] = valueNode; + } delete overridableKeys[keyNode]; } @@ -1440,6 +1482,7 @@ function readLineBreak(state) { state.line += 1; state.lineStart = state.position; + state.firstTabInLine = -1; } function skipSeparationSpace(state, allowComments, checkIndent) { @@ -1448,6 +1491,9 @@ function skipSeparationSpace(state, allowComments, checkIndent) { while (ch !== 0) { while (is_WHITE_SPACE(ch)) { + if (ch === 0x09/* Tab */ && state.firstTabInLine === -1) { + state.firstTabInLine = state.position; + } ch = state.input.charCodeAt(++state.position); } @@ -1749,6 +1795,8 @@ function readDoubleQuotedScalar(state, nodeIndent) { function readFlowCollection(state, nodeIndent) { var readNext = true, _line, + _lineStart, + _pos, _tag = state.tag, _result, _anchor = state.anchor, @@ -1757,7 +1805,7 @@ function readFlowCollection(state, nodeIndent) { isPair, isExplicitPair, isMapping, - overridableKeys = {}, + overridableKeys = Object.create(null), keyNode, keyTag, valueNode, @@ -1797,6 +1845,9 @@ function readFlowCollection(state, nodeIndent) { return true; } else if (!readNext) { throwError(state, 'missed comma between flow collection entries'); + } else if (ch === 0x2C/* , */) { + // "flow collection entries can never be completely empty", as per YAML 1.2, section 7.4 + throwError(state, "expected the node content, but found ','"); } keyTag = keyNode = valueNode = null; @@ -1812,7 +1863,9 @@ function readFlowCollection(state, nodeIndent) { } } - _line = state.line; + _line = state.line; // Save the current line. + _lineStart = state.lineStart; + _pos = state.position; composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true); keyTag = state.tag; keyNode = state.result; @@ -1829,9 +1882,9 @@ function readFlowCollection(state, nodeIndent) { } if (isMapping) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos); } else if (isPair) { - _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode)); + _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos)); } else { _result.push(keyNode); } @@ -2003,6 +2056,10 @@ function readBlockSequence(state, nodeIndent) { detected = false, ch; + // there is a leading tab before this token, so it can't be a block sequence/mapping; + // it can still be flow sequence/mapping or a scalar + if (state.firstTabInLine !== -1) return false; + if (state.anchor !== null) { state.anchorMap[state.anchor] = _result; } @@ -2010,6 +2067,10 @@ function readBlockSequence(state, nodeIndent) { ch = state.input.charCodeAt(state.position); while (ch !== 0) { + if (state.firstTabInLine !== -1) { + state.position = state.firstTabInLine; + throwError(state, 'tab characters must not be used in indentation'); + } if (ch !== 0x2D/* - */) { break; @@ -2060,11 +2121,13 @@ function readBlockMapping(state, nodeIndent, flowIndent) { var following, allowCompact, _line, - _pos, + _keyLine, + _keyLineStart, + _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, - overridableKeys = {}, + overridableKeys = Object.create(null), keyTag = null, keyNode = null, valueNode = null, @@ -2072,6 +2135,10 @@ function readBlockMapping(state, nodeIndent, flowIndent) { detected = false, ch; + // there is a leading tab before this token, so it can't be a block sequence/mapping; + // it can still be flow sequence/mapping or a scalar + if (state.firstTabInLine !== -1) return false; + if (state.anchor !== null) { state.anchorMap[state.anchor] = _result; } @@ -2079,9 +2146,13 @@ function readBlockMapping(state, nodeIndent, flowIndent) { ch = state.input.charCodeAt(state.position); while (ch !== 0) { + if (!atExplicitKey && state.firstTabInLine !== -1) { + state.position = state.firstTabInLine; + throwError(state, 'tab characters must not be used in indentation'); + } + following = state.input.charCodeAt(state.position + 1); _line = state.line; // Save the current line. - _pos = state.position; // // Explicit notation case. There are two separate blocks: @@ -2091,7 +2162,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) { if (ch === 0x3F/* ? */) { if (atExplicitKey) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); keyTag = keyNode = valueNode = null; } @@ -2114,7 +2185,16 @@ function readBlockMapping(state, nodeIndent, flowIndent) { // // Implicit notation case. Flow-style node as the key first, then ":", and the value. // - } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) { + } else { + _keyLine = state.line; + _keyLineStart = state.lineStart; + _keyPos = state.position; + + if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) { + // Neither implicit nor explicit notation. + // Reading is done. Go to the epilogue. + break; + } if (state.line === _line) { ch = state.input.charCodeAt(state.position); @@ -2131,7 +2211,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) { } if (atExplicitKey) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); keyTag = keyNode = valueNode = null; } @@ -2158,15 +2238,18 @@ function readBlockMapping(state, nodeIndent, flowIndent) { state.anchor = _anchor; return true; // Keep the result of `composeNode`. } - - } else { - break; // Reading is done. Go to the epilogue. } // // Common reading code for both explicit and implicit notations. // if (state.line === _line || state.lineIndent > nodeIndent) { + if (atExplicitKey) { + _keyLine = state.line; + _keyLineStart = state.lineStart; + _keyPos = state.position; + } + if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) { if (atExplicitKey) { keyNode = state.result; @@ -2176,7 +2259,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) { } if (!atExplicitKey) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos); keyTag = keyNode = valueNode = null; } @@ -2184,7 +2267,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) { ch = state.input.charCodeAt(state.position); } - if (state.lineIndent > nodeIndent && (ch !== 0)) { + if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) { throwError(state, 'bad indentation of a mapping entry'); } else if (state.lineIndent < nodeIndent) { break; @@ -2197,7 +2280,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) { // Special case: last mapping's node contains only the key in explicit notation. if (atExplicitKey) { - storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null); + storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); } // Expose the resulting mapping. @@ -2286,6 +2369,12 @@ function readTagProperty(state) { throwError(state, 'tag name cannot contain such characters: ' + tagName); } + try { + tagName = decodeURIComponent(tagName); + } catch (err) { + throwError(state, 'tag name is malformed: ' + tagName); + } + if (isVerbatim) { state.tag = tagName; @@ -2353,7 +2442,7 @@ function readAlias(state) { alias = state.input.slice(_position, state.position); - if (!state.anchorMap.hasOwnProperty(alias)) { + if (!_hasOwnProperty$2.call(state.anchorMap, alias)) { throwError(state, 'unidentified alias "' + alias + '"'); } @@ -2371,6 +2460,7 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact hasContent = false, typeIndex, typeQuantity, + typeList, type, flowIndent, blockIndent; @@ -2472,48 +2562,66 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact } } - if (state.tag !== null && state.tag !== '!') { - if (state.tag === '?') { - // Implicit resolving is not allowed for non-scalar types, and '?' - // non-specific tag is only automatically assigned to plain scalars. - // - // We only need to check kind conformity in case user explicitly assigns '?' - // tag, for example like this: "! [0]" - // - if (state.result !== null && state.kind !== 'scalar') { - throwError(state, 'unacceptable node kind for ! tag; it should be "scalar", not "' + state.kind + '"'); - } - - for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) { - type = state.implicitTypes[typeIndex]; + if (state.tag === null) { + if (state.anchor !== null) { + state.anchorMap[state.anchor] = state.result; + } - if (type.resolve(state.result)) { // `state.result` updated in resolver if matched - state.result = type.construct(state.result); - state.tag = type.tag; - if (state.anchor !== null) { - state.anchorMap[state.anchor] = state.result; - } - break; - } - } - } else if (_hasOwnProperty$2.call(state.typeMap[state.kind || 'fallback'], state.tag)) { - type = state.typeMap[state.kind || 'fallback'][state.tag]; + } else if (state.tag === '?') { + // Implicit resolving is not allowed for non-scalar types, and '?' + // non-specific tag is only automatically assigned to plain scalars. + // + // We only need to check kind conformity in case user explicitly assigns '?' + // tag, for example like this: "! [0]" + // + if (state.result !== null && state.kind !== 'scalar') { + throwError(state, 'unacceptable node kind for ! tag; it should be "scalar", not "' + state.kind + '"'); + } - if (state.result !== null && type.kind !== state.kind) { - throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"'); - } + for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) { + type = state.implicitTypes[typeIndex]; - if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched - throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag'); - } else { + if (type.resolve(state.result)) { // `state.result` updated in resolver if matched state.result = type.construct(state.result); + state.tag = type.tag; if (state.anchor !== null) { state.anchorMap[state.anchor] = state.result; } + break; } + } + } else if (state.tag !== '!') { + if (_hasOwnProperty$2.call(state.typeMap[state.kind || 'fallback'], state.tag)) { + type = state.typeMap[state.kind || 'fallback'][state.tag]; } else { + // looking for multi type + type = null; + typeList = state.typeMap.multi[state.kind || 'fallback']; + + for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) { + if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) { + type = typeList[typeIndex]; + break; + } + } + } + + if (!type) { throwError(state, 'unknown tag !<' + state.tag + '>'); } + + if (state.result !== null && type.kind !== state.kind) { + throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"'); + } + + if (!type.resolve(state.result, state.tag)) { // `state.result` updated in resolver if matched + throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag'); + } else { + state.result = type.construct(state.result, state.tag); + if (state.anchor !== null) { + state.anchorMap[state.anchor] = state.result; + } + } } if (state.listener !== null) { @@ -2532,8 +2640,8 @@ function readDocument(state) { state.version = null; state.checkLineBreaks = state.legacy; - state.tagMap = {}; - state.anchorMap = {}; + state.tagMap = Object.create(null); + state.anchorMap = Object.create(null); while ((ch = state.input.charCodeAt(state.position)) !== 0) { skipSeparationSpace(state, true, -1); @@ -2721,6 +2829,7 @@ var loader = { var _toString$2 = Object.prototype.toString; var _hasOwnProperty$3 = Object.prototype.hasOwnProperty; +var CHAR_BOM = 0xFEFF; var CHAR_TAB = 0x09; /* Tab */ var CHAR_LINE_FEED = 0x0A; /* LF */ var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */ @@ -2769,6 +2878,8 @@ var DEPRECATED_BOOLEANS_SYNTAX = [ 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF' ]; +var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/; + function compileStyleMap(schema, map) { var result, keys, index, length, tag, style, type; @@ -2817,6 +2928,10 @@ function encodeHex(character) { return '\\' + handle + common.repeat('0', length - string.length) + string; } + +var QUOTING_TYPE_SINGLE = 1, + QUOTING_TYPE_DOUBLE = 2; + function State$1(options) { this.schema = options['schema'] || _default; this.indent = Math.max(1, (options['indent'] || 2)); @@ -2829,6 +2944,9 @@ function State$1(options) { this.noRefs = options['noRefs'] || false; this.noCompatMode = options['noCompatMode'] || false; this.condenseFlow = options['condenseFlow'] || false; + this.quotingType = options['quotingType'] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE; + this.forceQuotes = options['forceQuotes'] || false; + this.replacer = typeof options['replacer'] === 'function' ? options['replacer'] : null; this.implicitTypes = this.schema.compiledImplicit; this.explicitTypes = this.schema.compiledExplicit; @@ -2897,47 +3015,60 @@ function isWhitespace(c) { function isPrintable(c) { return (0x00020 <= c && c <= 0x00007E) || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029) - || ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF /* BOM */) + || ((0x0E000 <= c && c <= 0x00FFFD) && c !== CHAR_BOM) || (0x10000 <= c && c <= 0x10FFFF); } // [34] ns-char ::= nb-char - s-white // [27] nb-char ::= c-printable - b-char - c-byte-order-mark // [26] b-char ::= b-line-feed | b-carriage-return -// [24] b-line-feed ::= #xA /* LF */ -// [25] b-carriage-return ::= #xD /* CR */ -// [3] c-byte-order-mark ::= #xFEFF -function isNsChar(c) { - return isPrintable(c) && !isWhitespace(c) - // byte-order-mark - && c !== 0xFEFF - // b-char +// Including s-white (for some reason, examples doesn't match specs in this aspect) +// ns-char ::= c-printable - b-line-feed - b-carriage-return - c-byte-order-mark +function isNsCharOrWhitespace(c) { + return isPrintable(c) + && c !== CHAR_BOM + // - b-char && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED; } -// Simplified test for values allowed after the first character in plain style. -function isPlainSafe(c, prev) { - // Uses a subset of nb-char - c-flow-indicator - ":" - "#" - // where nb-char ::= c-printable - b-char - c-byte-order-mark. - return isPrintable(c) && c !== 0xFEFF - // - c-flow-indicator - && c !== CHAR_COMMA - && c !== CHAR_LEFT_SQUARE_BRACKET - && c !== CHAR_RIGHT_SQUARE_BRACKET - && c !== CHAR_LEFT_CURLY_BRACKET - && c !== CHAR_RIGHT_CURLY_BRACKET - // - ":" - "#" - // /* An ns-char preceding */ "#" - && c !== CHAR_COLON - && ((c !== CHAR_SHARP) || (prev && isNsChar(prev))); +// [127] ns-plain-safe(c) ::= c = flow-out ⇒ ns-plain-safe-out +// c = flow-in ⇒ ns-plain-safe-in +// c = block-key ⇒ ns-plain-safe-out +// c = flow-key ⇒ ns-plain-safe-in +// [128] ns-plain-safe-out ::= ns-char +// [129] ns-plain-safe-in ::= ns-char - c-flow-indicator +// [130] ns-plain-char(c) ::= ( ns-plain-safe(c) - “:” - “#” ) +// | ( /* An ns-char preceding */ “#” ) +// | ( “:” /* Followed by an ns-plain-safe(c) */ ) +function isPlainSafe(c, prev, inblock) { + var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c); + var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c); + return ( + // ns-plain-safe + inblock ? // c = flow-in + cIsNsCharOrWhitespace + : cIsNsCharOrWhitespace + // - c-flow-indicator + && c !== CHAR_COMMA + && c !== CHAR_LEFT_SQUARE_BRACKET + && c !== CHAR_RIGHT_SQUARE_BRACKET + && c !== CHAR_LEFT_CURLY_BRACKET + && c !== CHAR_RIGHT_CURLY_BRACKET + ) + // ns-plain-char + && c !== CHAR_SHARP // false on '#' + && !(prev === CHAR_COLON && !cIsNsChar) // false on ': ' + || (isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP) // change to true on '[^ ]#' + || (prev === CHAR_COLON && cIsNsChar); // change to true on ':[^ ]' } // Simplified test for values allowed as the first character in plain style. function isPlainSafeFirst(c) { // Uses a subset of ns-char - c-indicator // where ns-char = nb-char - s-white. - return isPrintable(c) && c !== 0xFEFF + // No support of ( ( “?” | “:” | “-” ) /* Followed by an ns-plain-safe(c)) */ ) part + return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) // - s-white // - (c-indicator ::= // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}” @@ -2965,6 +3096,12 @@ function isPlainSafeFirst(c) { && c !== CHAR_GRAVE_ACCENT; } +// Simplified test for values allowed as the last character in plain style. +function isPlainSafeLast(c) { + // just not whitespace or colon, it will be checked to be plain character later + return !isWhitespace(c) && c !== CHAR_COLON; +} + // Same as 'string'.codePointAt(pos), but works in older browsers. function codePointAt(string, pos) { var first = string.charCodeAt(pos), second; @@ -2997,7 +3134,9 @@ var STYLE_PLAIN = 1, // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string. // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1). // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1). -function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) { +function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, + testAmbiguousType, quotingType, forceQuotes, inblock) { + var i; var char = 0; var prevChar = null; @@ -3006,9 +3145,9 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te var shouldTrackWidth = lineWidth !== -1; var previousLineBreak = -1; // count the first line correctly var plain = isPlainSafeFirst(codePointAt(string, 0)) - && !isWhitespace(codePointAt(string, string.length - 1)); + && isPlainSafeLast(codePointAt(string, string.length - 1)); - if (singleLineOnly) { + if (singleLineOnly || forceQuotes) { // Case: no block styles. // Check for disallowed characters to rule out plain and single. for (i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) { @@ -3016,7 +3155,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te if (!isPrintable(char)) { return STYLE_DOUBLE; } - plain = plain && isPlainSafe(char, prevChar); + plain = plain && isPlainSafe(char, prevChar, inblock); prevChar = char; } } else { @@ -3036,7 +3175,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te } else if (!isPrintable(char)) { return STYLE_DOUBLE; } - plain = plain && isPlainSafe(char, prevChar); + plain = plain && isPlainSafe(char, prevChar, inblock); prevChar = char; } // in case the end is missing a \n @@ -3050,8 +3189,10 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te if (!hasLineBreak && !hasFoldableLine) { // Strings interpretable as another type have to be quoted; // e.g. the string 'true' vs. the boolean true. - return plain && !testAmbiguousType(string) - ? STYLE_PLAIN : STYLE_SINGLE; + if (plain && !forceQuotes && !testAmbiguousType(string)) { + return STYLE_PLAIN; + } + return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; } // Edge case: block indentation indicator can only have one digit. if (indentPerLevel > 9 && needIndentIndicator(string)) { @@ -3059,7 +3200,10 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te } // At this point we know block styles are valid. // Prefer literal style unless we want to fold. - return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL; + if (!forceQuotes) { + return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL; + } + return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; } // Note: line breaking/folding is implemented for only the folded style. @@ -3068,14 +3212,15 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te // • No ending newline => unaffected; already using strip "-" chomping. // • Ending newline => removed then restored. // Importantly, this keeps the "+" chomp indicator from gaining an extra line. -function writeScalar(state, string, level, iskey) { +function writeScalar(state, string, level, iskey, inblock) { state.dump = (function () { if (string.length === 0) { - return "''"; + return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''"; } - if (!state.noCompatMode && - DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) { - return "'" + string + "'"; + if (!state.noCompatMode) { + if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) { + return state.quotingType === QUOTING_TYPE_DOUBLE ? ('"' + string + '"') : ("'" + string + "'"); + } } var indent = state.indent * Math.max(1, level); // no 0-indent scalars @@ -3097,7 +3242,9 @@ function writeScalar(state, string, level, iskey) { return testImplicitResolving(state, string); } - switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) { + switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, + testAmbiguity, state.quotingType, state.forceQuotes && !iskey, inblock)) { + case STYLE_PLAIN: return string; case STYLE_SINGLE: @@ -3236,12 +3383,22 @@ function writeFlowSequence(state, level, object) { var _result = '', _tag = state.tag, index, - length; + length, + value; for (index = 0, length = object.length; index < length; index += 1) { - // Write only valid elements. - if (writeNode(state, level, object[index], false, false)) { - if (index !== 0) _result += ',' + (!state.condenseFlow ? ' ' : ''); + value = object[index]; + + if (state.replacer) { + value = state.replacer.call(object, String(index), value); + } + + // Write only valid elements, put null instead of invalid elements. + if (writeNode(state, level, value, false, false) || + (typeof value === 'undefined' && + writeNode(state, level, null, false, false))) { + + if (_result !== '') _result += ',' + (!state.condenseFlow ? ' ' : ''); _result += state.dump; } } @@ -3254,12 +3411,22 @@ function writeBlockSequence(state, level, object, compact) { var _result = '', _tag = state.tag, index, - length; + length, + value; for (index = 0, length = object.length; index < length; index += 1) { - // Write only valid elements. - if (writeNode(state, level + 1, object[index], true, true, false, true)) { - if (!compact || index !== 0) { + value = object[index]; + + if (state.replacer) { + value = state.replacer.call(object, String(index), value); + } + + // Write only valid elements, put null instead of invalid elements. + if (writeNode(state, level + 1, value, true, true, false, true) || + (typeof value === 'undefined' && + writeNode(state, level + 1, null, true, true, false, true))) { + + if (!compact || _result !== '') { _result += generateNextLine(state, level); } @@ -3290,13 +3457,17 @@ function writeFlowMapping(state, level, object) { for (index = 0, length = objectKeyList.length; index < length; index += 1) { pairBuffer = ''; - if (index !== 0) pairBuffer += ', '; + if (_result !== '') pairBuffer += ', '; if (state.condenseFlow) pairBuffer += '"'; objectKey = objectKeyList[index]; objectValue = object[objectKey]; + if (state.replacer) { + objectValue = state.replacer.call(object, objectKey, objectValue); + } + if (!writeNode(state, level, objectKey, false, false)) { continue; // Skip this pair because of invalid key; } @@ -3345,13 +3516,17 @@ function writeBlockMapping(state, level, object, compact) { for (index = 0, length = objectKeyList.length; index < length; index += 1) { pairBuffer = ''; - if (!compact || index !== 0) { + if (!compact || _result !== '') { pairBuffer += generateNextLine(state, level); } objectKey = objectKeyList[index]; objectValue = object[objectKey]; + if (state.replacer) { + objectValue = state.replacer.call(object, objectKey, objectValue); + } + if (!writeNode(state, level + 1, objectKey, true, true, true)) { continue; // Skip this pair because of invalid key. } @@ -3405,7 +3580,15 @@ function detectType(state, object, explicit) { (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) && (!type.predicate || type.predicate(object))) { - state.tag = explicit ? type.tag : '?'; + if (explicit) { + if (type.multi && type.representName) { + state.tag = type.representName(object); + } else { + state.tag = type.tag; + } + } else { + state.tag = '?'; + } if (type.represent) { style = state.styleMap[type.tag] || type.defaultStyle; @@ -3440,6 +3623,8 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) { } var type = _toString$2.call(state.dump); + var inblock = block; + var tagStr; if (block) { block = (state.flowLevel < 0 || state.flowLevel > level); @@ -3494,15 +3679,42 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) { } } else if (type === '[object String]') { if (state.tag !== '?') { - writeScalar(state, state.dump, level, iskey); + writeScalar(state, state.dump, level, iskey, inblock); } + } else if (type === '[object Undefined]') { + return false; } else { if (state.skipInvalid) return false; throw new exception('unacceptable kind of an object to dump ' + type); } if (state.tag !== null && state.tag !== '?') { - state.dump = '!<' + state.tag + '> ' + state.dump; + // Need to encode all characters except those allowed by the spec: + // + // [35] ns-dec-digit ::= [#x30-#x39] /* 0-9 */ + // [36] ns-hex-digit ::= ns-dec-digit + // | [#x41-#x46] /* A-F */ | [#x61-#x66] /* a-f */ + // [37] ns-ascii-letter ::= [#x41-#x5A] /* A-Z */ | [#x61-#x7A] /* a-z */ + // [38] ns-word-char ::= ns-dec-digit | ns-ascii-letter | “-” + // [39] ns-uri-char ::= “%” ns-hex-digit ns-hex-digit | ns-word-char | “#” + // | “;” | “/” | “?” | “:” | “@” | “&” | “=” | “+” | “$” | “,” + // | “_” | “.” | “!” | “~” | “*” | “'” | “(” | “)” | “[” | “]” + // + // Also need to encode '!' because it has special meaning (end of tag prefix). + // + tagStr = encodeURI( + state.tag[0] === '!' ? state.tag.slice(1) : state.tag + ).replace(/!/g, '%21'); + + if (state.tag[0] === '!') { + tagStr = '!' + tagStr; + } else if (tagStr.slice(0, 18) === 'tag:yaml.org,2002:') { + tagStr = '!!' + tagStr.slice(18); + } else { + tagStr = '!<' + tagStr + '>'; + } + + state.dump = tagStr + ' ' + state.dump; } } @@ -3559,7 +3771,13 @@ function dump(input, options) { if (!state.noRefs) getDuplicateReferences(input, state); - if (writeNode(state, 0, input, true, true)) return state.dump + '\n'; + var value = input; + + if (state.replacer) { + value = state.replacer.call({ '': value }, '', value); + } + + if (writeNode(state, 0, value, true, true)) return state.dump + '\n'; return ''; }