import { j as _inherits, k as _createSuper, c as _classCallCheck, T as Type, b as _createClass, R as Range, N as Node, g as YAMLSemanticError, l as _get, m as _getPrototypeOf, Y as YAMLSyntaxError, C as Char, e as _defineProperty, P as PlainValue } from './PlainValue-b8036b75.js';
var BlankLine = /*#__PURE__*/function (_Node) {
_inherits(BlankLine, _Node);
var _super = _createSuper(BlankLine);
function BlankLine() {
_classCallCheck(this, BlankLine);
return _super.call(this, Type.BLANK_LINE);
}
/* istanbul ignore next */
_createClass(BlankLine, [{
key: "includesTrailingLines",
get: function get() {
// This is never called from anywhere, but if it were,
// this is the value it should return.
return true;
}
/**
* Parses a blank line from the source
*
* @param {ParseContext} context
* @param {number} start - Index of first \n character
* @returns {number} - Index of the character after this
*/
}, {
key: "parse",
value: function parse(context, start) {
this.context = context;
this.range = new Range(start, start + 1);
return start + 1;
}
}]);
return BlankLine;
}(Node);
var CollectionItem = /*#__PURE__*/function (_Node) {
* @param {number} start - Index of first character
* @returns {number} - Index of the character after this
*/
}, {
key: "parse",
value: function parse(context, start) {
this.context = context;
var parseNode = context.parseNode,
src = context.src;
var atLineStart = context.atLineStart,
lineStart = context.lineStart;
if (!atLineStart && this.type === Type.SEQ_ITEM) this.error = new YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
var indent = atLineStart ? start - lineStart : context.indent;
var offset = Node.endOfWhiteSpace(src, start + 1);
var ch = src[offset];
var inlineComment = ch === '#';
var comments = [];
var blankLine = null;
while (ch === '\n' || ch === '#') {
if (ch === '#') {
var _end = Node.endOfLine(src, offset + 1);
comments.push(new Range(offset, _end));
offset = _end;
} else {
atLineStart = true;
lineStart = offset + 1;
var wsEnd = Node.endOfWhiteSpace(src, lineStart);
if (src[wsEnd] === '\n' && comments.length === 0) {
if (!this.valueRange || !this.context) return null;
var errors = [];
var _this$valueRange = this.valueRange,
start = _this$valueRange.start,
end = _this$valueRange.end;
var _this$context = this.context,
indent = _this$context.indent,
src = _this$context.src;
if (src[end - 1] !== '"') errors.push(new YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by
// escaped backslashes; also, this should be faster.
var str = '';
for (var i = start + 1; i < end - 1; ++i) {
var ch = src[i];
if (ch === '\n') {
if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
var _Node$foldNewline = Node.foldNewline(src, i, indent),
fold = _Node$foldNewline.fold,
offset = _Node$foldNewline.offset,
error = _Node$foldNewline.error;
str += fold;
i = offset;
if (error) errors.push(new YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented'));
} else if (ch === '\\') {
i += 1;
switch (src[i]) {
case '0':
str += '\0';
break;
// null character
case 'a':
str += '\x07';
break;
// bell character
case 'b':
str += '\b';
break;
// backspace
case 'e':
str += '\x1b';
break;
// escape character
case 'f':
str += '\f';
break;
// form feed
case 'n':
str += '\n';
break;
// line feed
case 'r':
str += '\r';
break;
// carriage return
case 't':
str += '\t';
break;
// horizontal tab
case 'v':
str += '\v';
break;
// vertical tab
case 'N':
str += "\x85";
break;
// Unicode next line
case '_':
str += "\xA0";
break;
// Unicode non-breaking space
case 'L':
str += "\u2028";
break;
// Unicode line separator
case 'P':
str += "\u2029";
break;
// Unicode paragraph separator
case ' ':
str += ' ';
break;
case '"':
str += '"';
break;
case '/':
str += '/';
break;
case '\\':
str += '\\';
break;
case '\t':
str += '\t';
break;
case 'x':
str += this.parseCharCode(i + 1, 2, errors);
i += 2;
break;
case 'u':
str += this.parseCharCode(i + 1, 4, errors);
i += 4;
break;
case 'U':
str += this.parseCharCode(i + 1, 8, errors);
i += 8;
break;
case '\n':
// skip escaped newlines, but still trim the following line
if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
var _Node$foldNewline = Node.foldNewline(src, i, indent),
fold = _Node$foldNewline.fold,
offset = _Node$foldNewline.offset,
error = _Node$foldNewline.error;
str += fold;
i = offset;
if (error) errors.push(new YAMLSemanticError(this, 'Multi-line single-quoted string needs to be sufficiently indented'));
} else if (ch === "'") {
str += ch;
i += 1;
if (src[i] !== "'") errors.push(new YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.'));
} else if (ch === ' ' || ch === '\t') {
// trim trailing whitespace
var wsStart = i;
var next = src[i + 1];
while (next === ' ' || next === '\t') {
i += 1;
next = src[i + 1];
}
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
} else {
str += ch;
}
}
return errors.length > 0 ? {
errors: errors,
str: str
} : str;
}
/**
* Parses a 'single quoted' value from the source
*
* @param {ParseContext} context
* @param {number} start - Index of first character
* @returns {number} - Index of the character after this scalar
*/
}, {
key: "parse",
value: function parse(context, start) {
this.context = context;
var src = context.src;
var offset = QuoteSingle.endOfQuote(src, start + 1);
this.valueRange = new Range(start, offset);
offset = Node.endOfWhiteSpace(src, offset);
offset = this.parseComment(offset);
return offset;
}
}], [{
key: "endOfQuote",
value: function endOfQuote(src, offset) {
var ch = src[offset];
while (ch) {
if (ch === "'") {
if (src[offset + 1] !== "'") break;
ch = src[offset += 2];
} else {
ch = src[offset += 1];
}
}
return offset + 1;
}
}]);
return QuoteSingle;
}(Node);
function createNewNode(type, props) {
switch (type) {
case Type.ALIAS:
return new Alias(type, props);
case Type.BLOCK_FOLDED:
case Type.BLOCK_LITERAL:
return new BlockValue(type, props);
case Type.FLOW_MAP:
case Type.FLOW_SEQ:
return new FlowCollection(type, props);
case Type.MAP_KEY:
case Type.MAP_VALUE:
case Type.SEQ_ITEM:
return new CollectionItem(type, props);
case Type.COMMENT:
case Type.PLAIN:
return new PlainValue(type, props);
case Type.QUOTE_DOUBLE:
return new QuoteDouble(type, props);
case Type.QUOTE_SINGLE:
return new QuoteSingle(type, props);
/* istanbul ignore next */
default:
return null;
// should never happen
}
}
/**
* @param {boolean} atLineStart - Node starts at beginning of line
* @param {boolean} inFlow - true if currently in a flow context
* @param {boolean} inCollection - true if currently in a collection context
* @param {number} indent - Current level of indentation
* @param {number} lineStart - Start of the current line
* @param {Node} parent - The parent of the node
* @param {string} src - Source of the YAML document