Comparing version 1.7.2 to 1.8.0
@@ -1,10 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.addCommentBefore = addCommentBefore; | ||
exports.default = addComment; | ||
function addCommentBefore(str, indent, comment) { | ||
export function addCommentBefore(str, indent, comment) { | ||
if (!comment) return str; | ||
@@ -14,5 +6,4 @@ var cc = comment.replace(/[\s\S]^/gm, "$&".concat(indent, "#")); | ||
} | ||
function addComment(str, indent, comment) { | ||
export default function addComment(str, indent, comment) { | ||
return !comment ? str : comment.indexOf('\n') === -1 ? "".concat(str, " #").concat(comment) : "".concat(str, "\n") + comment.replace(/^/gm, "".concat(indent || '', "#")); | ||
} |
@@ -1,33 +0,15 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import Alias from './schema/Alias'; | ||
import Map from './schema/Map'; | ||
import Merge from './schema/Merge'; | ||
import Scalar from './schema/Scalar'; | ||
import Seq from './schema/Seq'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _Alias = _interopRequireDefault(require("./schema/Alias")); | ||
var _Map = _interopRequireDefault(require("./schema/Map")); | ||
var _Merge = _interopRequireDefault(require("./schema/Merge")); | ||
var _Scalar = _interopRequireDefault(require("./schema/Scalar")); | ||
var _Seq = _interopRequireDefault(require("./schema/Seq")); | ||
var Anchors = | ||
/*#__PURE__*/ | ||
function () { | ||
(0, _createClass2.default)(Anchors, null, [{ | ||
var Anchors = /*#__PURE__*/function () { | ||
_createClass(Anchors, null, [{ | ||
key: "validAnchorNode", | ||
value: function validAnchorNode(node) { | ||
return node instanceof _Scalar.default || node instanceof _Seq.default || node instanceof _Map.default; | ||
return node instanceof Scalar || node instanceof Seq || node instanceof Map; | ||
} | ||
@@ -37,12 +19,14 @@ }]); | ||
function Anchors(prefix) { | ||
(0, _classCallCheck2.default)(this, Anchors); | ||
(0, _defineProperty2.default)(this, "map", {}); | ||
_classCallCheck(this, Anchors); | ||
_defineProperty(this, "map", {}); | ||
this.prefix = prefix; | ||
} | ||
(0, _createClass2.default)(Anchors, [{ | ||
_createClass(Anchors, [{ | ||
key: "createAlias", | ||
value: function createAlias(node, name) { | ||
this.setAnchor(node, name); | ||
return new _Alias.default(node); | ||
return new Alias(node); | ||
} | ||
@@ -54,3 +38,3 @@ }, { | ||
var merge = new _Merge.default(); | ||
var merge = new Merge(); | ||
@@ -62,5 +46,5 @@ for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) { | ||
merge.value.items = sources.map(function (s) { | ||
if (s instanceof _Alias.default) { | ||
if (s.source instanceof _Map.default) return s; | ||
} else if (s instanceof _Map.default) { | ||
if (s instanceof Alias) { | ||
if (s.source instanceof Map) return s; | ||
} else if (s instanceof Map) { | ||
return _this.createAlias(s); | ||
@@ -148,5 +132,6 @@ } | ||
}]); | ||
return Anchors; | ||
}(); | ||
exports.default = Anchors; | ||
export { Anchors as default }; |
@@ -1,8 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Type = exports.Char = void 0; | ||
var Char = { | ||
export var Char = { | ||
ANCHOR: '&', | ||
@@ -14,4 +8,3 @@ COMMENT: '#', | ||
}; | ||
exports.Char = Char; | ||
var Type = { | ||
export var Type = { | ||
ALIAS: 'ALIAS', | ||
@@ -34,3 +27,2 @@ BLANK_LINE: 'BLANK_LINE', | ||
SEQ_ITEM: 'SEQ_ITEM' | ||
}; | ||
exports.Type = Type; | ||
}; |
@@ -1,35 +0,19 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var Alias = /*#__PURE__*/function (_Node) { | ||
_inherits(Alias, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function Alias() { | ||
_classCallCheck(this, Alias); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var Alias = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(Alias, _Node); | ||
function Alias() { | ||
(0, _classCallCheck2.default)(this, Alias); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Alias).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(Alias).apply(this, arguments)); | ||
} | ||
(0, _createClass2.default)(Alias, [{ | ||
_createClass(Alias, [{ | ||
key: "parse", | ||
@@ -47,7 +31,5 @@ | ||
var src = context.src; | ||
var offset = _Node2.default.endOfIdentifier(src, start + 1); | ||
this.valueRange = new _Range.default(start + 1, offset); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
var offset = Node.endOfIdentifier(src, start + 1); | ||
this.valueRange = new Range(start + 1, offset); | ||
offset = Node.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
@@ -57,5 +39,6 @@ return offset; | ||
}]); | ||
return Alias; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = Alias; | ||
export { Alias as default }; |
@@ -1,37 +0,22 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { Type } from '../constants'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var BlankLine = /*#__PURE__*/function (_Node) { | ||
_inherits(BlankLine, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function BlankLine() { | ||
_classCallCheck(this, BlankLine); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(BlankLine).call(this, Type.BLANK_LINE)); | ||
} | ||
/* istanbul ignore next */ | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _constants = require("../constants"); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var BlankLine = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(BlankLine, _Node); | ||
function BlankLine() { | ||
(0, _classCallCheck2.default)(this, BlankLine); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BlankLine).call(this, _constants.Type.BLANK_LINE)); | ||
} | ||
(0, _createClass2.default)(BlankLine, [{ | ||
_createClass(BlankLine, [{ | ||
key: "parse", | ||
@@ -51,9 +36,8 @@ | ||
while (_Node2.default.atBlank(src, offset)) { | ||
var lineEnd = _Node2.default.endOfWhiteSpace(src, offset); | ||
while (Node.atBlank(src, offset)) { | ||
var lineEnd = Node.endOfWhiteSpace(src, offset); | ||
if (lineEnd === '\n') offset = lineEnd + 1;else break; | ||
} | ||
this.range = new _Range.default(start, offset); | ||
this.range = new Range(start, offset); | ||
return offset; | ||
@@ -64,8 +48,11 @@ } | ||
get: function get() { | ||
// This is never called from anywhere, but if it were, | ||
// this is the value it should return. | ||
return true; | ||
} | ||
}]); | ||
return BlankLine; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = BlankLine; | ||
export { BlankLine as default }; |
@@ -1,29 +0,11 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.Chomp = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _constants = require("../constants"); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var Chomp = { | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _get from "@babel/runtime/helpers/get"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { Type } from '../constants'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
export var Chomp = { | ||
CLIP: 'CLIP', | ||
@@ -33,8 +15,5 @@ KEEP: 'KEEP', | ||
}; | ||
exports.Chomp = Chomp; | ||
var BlockValue = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(BlockValue, _Node); | ||
var BlockValue = /*#__PURE__*/function (_Node) { | ||
_inherits(BlockValue, _Node); | ||
@@ -44,4 +23,5 @@ function BlockValue(type, props) { | ||
(0, _classCallCheck2.default)(this, BlockValue); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BlockValue).call(this, type, props)); | ||
_classCallCheck(this, BlockValue); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BlockValue).call(this, type, props)); | ||
_this.blockIndent = null; | ||
@@ -53,3 +33,3 @@ _this.chomping = Chomp.CLIP; | ||
(0, _createClass2.default)(BlockValue, [{ | ||
_createClass(BlockValue, [{ | ||
key: "parseBlockHeader", | ||
@@ -88,3 +68,3 @@ value: function parseBlockHeader(start) { | ||
this.blockIndent = Number(bi) || null; | ||
this.header = new _Range.default(start, offset); | ||
this.header = new Range(start, offset); | ||
return offset; | ||
@@ -109,7 +89,5 @@ } | ||
offset += 1; | ||
if (_Node2.default.atDocumentBoundary(src, offset)) break; | ||
if (Node.atDocumentBoundary(src, offset)) break; | ||
var end = Node.endOfBlockIndent(src, bi, offset); // should not include tab? | ||
var end = _Node2.default.endOfBlockIndent(src, bi, offset); // should not include tab? | ||
if (end === null) break; | ||
@@ -139,3 +117,3 @@ | ||
} else { | ||
offset = valueEnd = _Node2.default.endOfLine(src, end); | ||
offset = valueEnd = Node.endOfLine(src, end); | ||
} | ||
@@ -148,3 +126,3 @@ } | ||
this.valueRange = new _Range.default(start + 1, offset); | ||
this.valueRange = new Range(start + 1, offset); | ||
return offset; | ||
@@ -179,3 +157,3 @@ } | ||
var offset = this.parseBlockHeader(start); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
offset = Node.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
@@ -188,3 +166,3 @@ offset = this.parseBlockValue(offset); | ||
value: function setOrigRanges(cr, offset) { | ||
offset = (0, _get2.default)((0, _getPrototypeOf2.default)(BlockValue.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
offset = _get(_getPrototypeOf(BlockValue.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
return this.header ? this.header.setOrigRange(cr, offset) : offset; | ||
@@ -215,3 +193,3 @@ } | ||
if (end <= start) { | ||
if (this.chomping === Chomp.KEEP) break;else return ''; | ||
if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens | ||
} | ||
@@ -235,3 +213,3 @@ | ||
var bi = indent + this.blockIndent; | ||
var folded = this.type === _constants.Type.BLOCK_FOLDED; | ||
var folded = this.type === Type.BLOCK_FOLDED; | ||
var atStart = true; | ||
@@ -253,4 +231,3 @@ var str = ''; | ||
} else { | ||
var lineEnd = _Node2.default.endOfLine(src, i); | ||
var lineEnd = Node.endOfLine(src, i); | ||
var line = src.slice(i, lineEnd); | ||
@@ -278,5 +255,6 @@ i = lineEnd; | ||
}]); | ||
return BlockValue; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = BlockValue; | ||
export { BlockValue as default }; |
@@ -1,39 +0,17 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.grabCollectionEndComments = grabCollectionEndComments; | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _constants = require("../constants"); | ||
var _BlankLine = _interopRequireDefault(require("./BlankLine")); | ||
var _CollectionItem = _interopRequireDefault(require("./CollectionItem")); | ||
var _Comment = _interopRequireDefault(require("./Comment")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
function grabCollectionEndComments(node) { | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _get from "@babel/runtime/helpers/get"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { Type } from '../constants'; | ||
import BlankLine from './BlankLine'; | ||
import CollectionItem from './CollectionItem'; | ||
import Comment from './Comment'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
export function grabCollectionEndComments(node) { | ||
var cnode = node; | ||
while (cnode instanceof _CollectionItem.default) { | ||
while (cnode instanceof CollectionItem) { | ||
cnode = cnode.node; | ||
@@ -49,3 +27,3 @@ } | ||
if (n.type === _constants.Type.COMMENT) { | ||
if (n.type === Type.COMMENT) { | ||
// Keep sufficiently indented comments with preceding node | ||
@@ -57,3 +35,3 @@ var _n$context = n.context, | ||
ci = i; | ||
} else if (n.type === _constants.Type.BLANK_LINE) ci = i;else break; | ||
} else if (n.type === Type.BLANK_LINE) ci = i;else break; | ||
} | ||
@@ -75,11 +53,10 @@ | ||
var Collection = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(Collection, _Node); | ||
(0, _createClass2.default)(Collection, null, [{ | ||
var Collection = /*#__PURE__*/function (_Node) { | ||
_inherits(Collection, _Node); | ||
_createClass(Collection, null, [{ | ||
key: "nextContentHasIndent", | ||
value: function nextContentHasIndent(src, offset, indent) { | ||
var lineStart = _Node2.default.endOfLine(src, offset) + 1; | ||
offset = _Node2.default.endOfWhiteSpace(src, lineStart); | ||
var lineStart = Node.endOfLine(src, offset) + 1; | ||
offset = Node.endOfWhiteSpace(src, lineStart); | ||
var ch = src[offset]; | ||
@@ -96,5 +73,6 @@ if (!ch) return false; | ||
(0, _classCallCheck2.default)(this, Collection); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Collection).call(this, firstItem.type === _constants.Type.SEQ_ITEM ? _constants.Type.SEQ : _constants.Type.MAP)); | ||
_classCallCheck(this, Collection); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Collection).call(this, firstItem.type === Type.SEQ_ITEM ? Type.SEQ : Type.MAP)); | ||
for (var i = firstItem.props.length - 1; i >= 0; --i) { | ||
@@ -117,3 +95,3 @@ if (firstItem.props[i].start < firstItem.context.lineStart) { | ||
(0, _createClass2.default)(Collection, [{ | ||
_createClass(Collection, [{ | ||
key: "parse", | ||
@@ -132,4 +110,3 @@ | ||
var lineStart = _Node2.default.startOfLine(src, start); | ||
var lineStart = Node.startOfLine(src, start); | ||
var firstItem = this.items[0]; // First-item context needs to be correct for later comment handling | ||
@@ -139,8 +116,8 @@ // -- eemeli/yaml#17 | ||
firstItem.context.parent = this; | ||
this.valueRange = _Range.default.copy(firstItem.valueRange); | ||
this.valueRange = Range.copy(firstItem.valueRange); | ||
var indent = firstItem.range.start - firstItem.context.lineStart; | ||
var offset = start; | ||
offset = _Node2.default.normalizeOffset(src, offset); | ||
offset = Node.normalizeOffset(src, offset); | ||
var ch = src[offset]; | ||
var atLineStart = _Node2.default.endOfWhiteSpace(src, lineStart) === offset; | ||
var atLineStart = Node.endOfWhiteSpace(src, lineStart) === offset; | ||
var prevIncludesTrailingLines = false; | ||
@@ -151,3 +128,3 @@ | ||
if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) { | ||
var blankLine = new _BlankLine.default(); | ||
var blankLine = new BlankLine(); | ||
offset = blankLine.parse({ | ||
@@ -170,3 +147,3 @@ src: src | ||
var comment = new _Comment.default(); | ||
var comment = new Comment(); | ||
offset = comment.parse({ | ||
@@ -187,7 +164,6 @@ indent: indent, | ||
lineStart = offset + 1; | ||
offset = _Node2.default.endOfIndent(src, lineStart); | ||
offset = Node.endOfIndent(src, lineStart); | ||
if (_Node2.default.atBlank(src, offset)) { | ||
var wsEnd = _Node2.default.endOfWhiteSpace(src, offset); | ||
if (Node.atBlank(src, offset)) { | ||
var wsEnd = Node.endOfWhiteSpace(src, offset); | ||
var next = src[wsEnd]; | ||
@@ -213,3 +189,3 @@ | ||
if (firstItem.type === _constants.Type.SEQ_ITEM !== (ch === '-')) { | ||
if (firstItem.type === Type.SEQ_ITEM !== (ch === '-')) { | ||
var typeswitch = true; | ||
@@ -240,3 +216,3 @@ | ||
this.valueRange.end = node.valueRange.end; | ||
offset = _Node2.default.normalizeOffset(src, node.range.end); | ||
offset = Node.normalizeOffset(src, node.range.end); | ||
ch = src[offset]; | ||
@@ -271,3 +247,3 @@ atLineStart = false; | ||
value: function setOrigRanges(cr, offset) { | ||
offset = (0, _get2.default)((0, _getPrototypeOf2.default)(Collection.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
offset = _get(_getPrototypeOf(Collection.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
this.items.forEach(function (node) { | ||
@@ -299,3 +275,3 @@ offset = node.setOrigRanges(cr, offset); | ||
return _Node2.default.addStringTerminator(src, range.end, str); | ||
return Node.addStringTerminator(src, range.end, str); | ||
} | ||
@@ -308,5 +284,6 @@ }, { | ||
}]); | ||
return Collection; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = Collection; | ||
export { Collection as default }; |
@@ -1,42 +0,22 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _get from "@babel/runtime/helpers/get"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { Type } from '../constants'; | ||
import { YAMLSemanticError } from '../errors'; | ||
import BlankLine from './BlankLine'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var CollectionItem = /*#__PURE__*/function (_Node) { | ||
_inherits(CollectionItem, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _constants = require("../constants"); | ||
var _errors = require("../errors"); | ||
var _BlankLine = _interopRequireDefault(require("./BlankLine")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var CollectionItem = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(CollectionItem, _Node); | ||
function CollectionItem(type, props) { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, CollectionItem); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(CollectionItem).call(this, type, props)); | ||
_classCallCheck(this, CollectionItem); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(CollectionItem).call(this, type, props)); | ||
_this.node = null; | ||
@@ -46,3 +26,3 @@ return _this; | ||
(0, _createClass2.default)(CollectionItem, [{ | ||
_createClass(CollectionItem, [{ | ||
key: "parse", | ||
@@ -61,7 +41,5 @@ | ||
lineStart = context.lineStart; | ||
if (!atLineStart && this.type === _constants.Type.SEQ_ITEM) this.error = new _errors.YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line'); | ||
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 = _Node2.default.endOfWhiteSpace(src, start + 1); | ||
var offset = Node.endOfWhiteSpace(src, start + 1); | ||
var ch = src[offset]; | ||
@@ -74,5 +52,5 @@ var inlineComment = ch === '#'; | ||
if (ch === '#') { | ||
var _end = _Node2.default.endOfLine(src, offset + 1); | ||
var _end = Node.endOfLine(src, offset + 1); | ||
comments.push(new _Range.default(offset, _end)); | ||
comments.push(new Range(offset, _end)); | ||
offset = _end; | ||
@@ -82,7 +60,6 @@ } else { | ||
lineStart = offset + 1; | ||
var wsEnd = Node.endOfWhiteSpace(src, lineStart); | ||
var wsEnd = _Node2.default.endOfWhiteSpace(src, lineStart); | ||
if (src[wsEnd] === '\n' && comments.length === 0) { | ||
blankLine = new _BlankLine.default(); | ||
blankLine = new BlankLine(); | ||
lineStart = blankLine.parse({ | ||
@@ -93,3 +70,3 @@ src: src | ||
offset = _Node2.default.endOfIndent(src, lineStart); | ||
offset = Node.endOfIndent(src, lineStart); | ||
} | ||
@@ -100,3 +77,3 @@ | ||
if (_Node2.default.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== _constants.Type.SEQ_ITEM)) { | ||
if (Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== Type.SEQ_ITEM)) { | ||
this.node = parseNode({ | ||
@@ -130,3 +107,3 @@ atLineStart: atLineStart, | ||
} else { | ||
offset = _Node2.default.endOfLine(src, start + 1); | ||
offset = Node.endOfLine(src, start + 1); | ||
} | ||
@@ -136,3 +113,3 @@ } | ||
var end = this.node ? this.node.valueRange.end : offset; | ||
this.valueRange = new _Range.default(start, end); | ||
this.valueRange = new Range(start, end); | ||
return offset; | ||
@@ -143,3 +120,3 @@ } | ||
value: function setOrigRanges(cr, offset) { | ||
offset = (0, _get2.default)((0, _getPrototypeOf2.default)(CollectionItem.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
offset = _get(_getPrototypeOf(CollectionItem.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
return this.node ? this.node.setOrigRanges(cr, offset) : offset; | ||
@@ -156,3 +133,3 @@ } | ||
var str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end); | ||
return _Node2.default.addStringTerminator(src, range.end, str); | ||
return Node.addStringTerminator(src, range.end, str); | ||
} | ||
@@ -165,5 +142,6 @@ }, { | ||
}]); | ||
return CollectionItem; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = CollectionItem; | ||
export { CollectionItem as default }; |
@@ -1,34 +0,17 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { Type } from '../constants'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var Comment = /*#__PURE__*/function (_Node) { | ||
_inherits(Comment, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function Comment() { | ||
_classCallCheck(this, Comment); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _constants = require("../constants"); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var Comment = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(Comment, _Node); | ||
function Comment() { | ||
(0, _classCallCheck2.default)(this, Comment); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Comment).call(this, _constants.Type.COMMENT)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(Comment).call(this, Type.COMMENT)); | ||
} | ||
@@ -44,3 +27,3 @@ /** | ||
(0, _createClass2.default)(Comment, [{ | ||
_createClass(Comment, [{ | ||
key: "parse", | ||
@@ -50,9 +33,10 @@ value: function parse(context, start) { | ||
var offset = this.parseComment(start); | ||
this.range = new _Range.default(start, offset); | ||
this.range = new Range(start, offset); | ||
return offset; | ||
} | ||
}]); | ||
return Comment; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = Comment; | ||
export { Comment as default }; |
@@ -1,56 +0,19 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { Type } from '../constants'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var Directive = /*#__PURE__*/function (_Node) { | ||
_inherits(Directive, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _constants = require("../constants"); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var Directive = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(Directive, _Node); | ||
(0, _createClass2.default)(Directive, null, [{ | ||
key: "endOfDirective", | ||
value: function endOfDirective(src, offset) { | ||
var ch = src[offset]; | ||
while (ch && ch !== '\n' && ch !== '#') { | ||
ch = src[offset += 1]; | ||
} // last char can't be whitespace | ||
ch = src[offset - 1]; | ||
while (ch === ' ' || ch === '\t') { | ||
offset -= 1; | ||
ch = src[offset - 1]; | ||
} | ||
return offset; | ||
} | ||
}]); | ||
function Directive() { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, Directive); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Directive).call(this, _constants.Type.DIRECTIVE)); | ||
_classCallCheck(this, Directive); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Directive).call(this, Type.DIRECTIVE)); | ||
_this.name = null; | ||
@@ -60,3 +23,3 @@ return _this; | ||
(0, _createClass2.default)(Directive, [{ | ||
_createClass(Directive, [{ | ||
key: "parseName", | ||
@@ -86,3 +49,3 @@ value: function parseName(start) { | ||
this.valueRange = new _Range.default(start, offset); | ||
this.valueRange = new Range(start, offset); | ||
return offset; | ||
@@ -97,3 +60,3 @@ } | ||
offset = this.parseComment(offset); | ||
this.range = new _Range.default(start, offset); | ||
this.range = new Range(start, offset); | ||
return offset; | ||
@@ -108,5 +71,6 @@ } | ||
}]); | ||
return Directive; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = Directive; | ||
export { Directive as default }; |
@@ -1,47 +0,23 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _get from "@babel/runtime/helpers/get"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { Char, Type } from '../constants'; | ||
import { YAMLSemanticError, YAMLSyntaxError } from '../errors'; | ||
import BlankLine from './BlankLine'; | ||
import { grabCollectionEndComments } from './Collection'; | ||
import Comment from './Comment'; | ||
import Directive from './Directive'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var Document = /*#__PURE__*/function (_Node) { | ||
_inherits(Document, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _constants = require("../constants"); | ||
var _errors = require("../errors"); | ||
var _BlankLine = _interopRequireDefault(require("./BlankLine")); | ||
var _Collection = require("./Collection"); | ||
var _Comment = _interopRequireDefault(require("./Comment")); | ||
var _Directive = _interopRequireDefault(require("./Directive")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var Document = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(Document, _Node); | ||
(0, _createClass2.default)(Document, null, [{ | ||
_createClass(Document, null, [{ | ||
key: "startCommentOrEndBlankLine", | ||
value: function startCommentOrEndBlankLine(src, start) { | ||
var offset = _Node2.default.endOfWhiteSpace(src, start); | ||
var offset = Node.endOfWhiteSpace(src, start); | ||
var ch = src[offset]; | ||
@@ -55,4 +31,5 @@ return ch === '#' || ch === '\n' ? offset : start; | ||
(0, _classCallCheck2.default)(this, Document); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Document).call(this, _constants.Type.DOCUMENT)); | ||
_classCallCheck(this, Document); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Document).call(this, Type.DOCUMENT)); | ||
_this.directives = null; | ||
@@ -65,3 +42,3 @@ _this.contents = null; | ||
(0, _createClass2.default)(Document, [{ | ||
_createClass(Document, [{ | ||
key: "parseDirectives", | ||
@@ -75,3 +52,3 @@ value: function parseDirectives(start) { | ||
while (!_Node2.default.atDocumentBoundary(src, offset, _constants.Char.DIRECTIVES_END)) { | ||
while (!Node.atDocumentBoundary(src, offset, Char.DIRECTIVES_END)) { | ||
offset = Document.startCommentOrEndBlankLine(src, offset); | ||
@@ -82,3 +59,3 @@ | ||
if (atLineStart) { | ||
var blankLine = new _BlankLine.default(); | ||
var blankLine = new BlankLine(); | ||
offset = blankLine.parse({ | ||
@@ -100,3 +77,3 @@ src: src | ||
{ | ||
var comment = new _Comment.default(); | ||
var comment = new Comment(); | ||
offset = comment.parse({ | ||
@@ -112,3 +89,3 @@ src: src | ||
{ | ||
var directive = new _Directive.default(); | ||
var directive = new Directive(); | ||
offset = directive.parse({ | ||
@@ -126,3 +103,3 @@ parent: this, | ||
if (hasDirectives) { | ||
this.error = new _errors.YAMLSemanticError(this, 'Missing directives-end indicator line'); | ||
this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line'); | ||
} else if (this.directives.length > 0) { | ||
@@ -138,3 +115,3 @@ this.contents = this.directives; | ||
if (src[offset]) { | ||
this.directivesEndMarker = new _Range.default(offset, offset + 3); | ||
this.directivesEndMarker = new Range(offset, offset + 3); | ||
return offset + 3; | ||
@@ -144,3 +121,3 @@ } | ||
if (hasDirectives) { | ||
this.error = new _errors.YAMLSemanticError(this, 'Missing directives-end indicator line'); | ||
this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line'); | ||
} else if (this.directives.length > 0) { | ||
@@ -166,12 +143,11 @@ this.contents = this.directives; | ||
var offset = _Node2.default.endOfWhiteSpace(src, start); | ||
var offset = Node.endOfWhiteSpace(src, start); | ||
var atLineStart = lineStart === start; | ||
this.valueRange = new _Range.default(offset); | ||
this.valueRange = new Range(offset); | ||
while (!_Node2.default.atDocumentBoundary(src, offset, _constants.Char.DOCUMENT_END)) { | ||
while (!Node.atDocumentBoundary(src, offset, Char.DOCUMENT_END)) { | ||
switch (src[offset]) { | ||
case '\n': | ||
if (atLineStart) { | ||
var blankLine = new _BlankLine.default(); | ||
var blankLine = new BlankLine(); | ||
offset = blankLine.parse({ | ||
@@ -194,3 +170,3 @@ src: src | ||
{ | ||
var comment = new _Comment.default(); | ||
var comment = new Comment(); | ||
offset = comment.parse({ | ||
@@ -206,4 +182,3 @@ src: src | ||
{ | ||
var iEnd = _Node2.default.endOfIndent(src, offset); | ||
var iEnd = Node.endOfIndent(src, offset); | ||
var context = { | ||
@@ -223,3 +198,3 @@ atLineStart: atLineStart, | ||
atLineStart = false; | ||
var ec = (0, _Collection.grabCollectionEndComments)(node); | ||
var ec = grabCollectionEndComments(node); | ||
if (ec) Array.prototype.push.apply(this.contents, ec); | ||
@@ -235,10 +210,10 @@ } | ||
if (src[offset]) { | ||
this.documentEndMarker = new _Range.default(offset, offset + 3); | ||
this.documentEndMarker = new Range(offset, offset + 3); | ||
offset += 3; | ||
if (src[offset]) { | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
offset = Node.endOfWhiteSpace(src, offset); | ||
if (src[offset] === '#') { | ||
var _comment = new _Comment.default(); | ||
var _comment = new Comment(); | ||
@@ -260,3 +235,3 @@ offset = _comment.parse({ | ||
default: | ||
this.error = new _errors.YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix'); | ||
this.error = new YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix'); | ||
} | ||
@@ -289,3 +264,3 @@ } | ||
value: function setOrigRanges(cr, offset) { | ||
offset = (0, _get2.default)((0, _getPrototypeOf2.default)(Document.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
offset = _get(_getPrototypeOf(Document.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
this.directives.forEach(function (node) { | ||
@@ -311,3 +286,3 @@ offset = node.setOrigRanges(cr, offset); | ||
if (contents.length > 0) { | ||
if (directives.length > 0 || contents[0].type === _constants.Type.COMMENT) str += '---\n'; | ||
if (directives.length > 0 || contents[0].type === Type.COMMENT) str += '---\n'; | ||
str += contents.join(''); | ||
@@ -320,5 +295,6 @@ } | ||
}]); | ||
return Document; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = Document; | ||
export { Document as default }; |
@@ -1,44 +0,23 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _get from "@babel/runtime/helpers/get"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { Type } from '../constants'; | ||
import { YAMLSemanticError } from '../errors'; | ||
import BlankLine from './BlankLine'; | ||
import Comment from './Comment'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var FlowCollection = /*#__PURE__*/function (_Node) { | ||
_inherits(FlowCollection, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _constants = require("../constants"); | ||
var _errors = require("../errors"); | ||
var _BlankLine = _interopRequireDefault(require("./BlankLine")); | ||
var _Comment = _interopRequireDefault(require("./Comment")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var FlowCollection = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(FlowCollection, _Node); | ||
function FlowCollection(type, props) { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, FlowCollection); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(FlowCollection).call(this, type, props)); | ||
_classCallCheck(this, FlowCollection); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(FlowCollection).call(this, type, props)); | ||
_this.items = null; | ||
@@ -48,3 +27,3 @@ return _this; | ||
(0, _createClass2.default)(FlowCollection, [{ | ||
_createClass(FlowCollection, [{ | ||
key: "prevNodeIsJsonLike", | ||
@@ -54,3 +33,3 @@ value: function prevNodeIsJsonLike() { | ||
var node = this.items[idx - 1]; | ||
return !!node && (node.jsonLike || node.type === _constants.Type.COMMENT && this.nodeIsJsonLike(idx - 1)); | ||
return !!node && (node.jsonLike || node.type === Type.COMMENT && this.nodeIsJsonLike(idx - 1)); | ||
} | ||
@@ -77,5 +56,3 @@ /** | ||
}]; | ||
var offset = _Node2.default.endOfWhiteSpace(src, start + 1); | ||
var offset = Node.endOfWhiteSpace(src, start + 1); | ||
char = src[offset]; | ||
@@ -88,7 +65,6 @@ | ||
lineStart = offset + 1; | ||
var wsEnd = Node.endOfWhiteSpace(src, lineStart); | ||
var wsEnd = _Node2.default.endOfWhiteSpace(src, lineStart); | ||
if (src[wsEnd] === '\n') { | ||
var blankLine = new _BlankLine.default(); | ||
var blankLine = new BlankLine(); | ||
lineStart = blankLine.parse({ | ||
@@ -100,3 +76,3 @@ src: src | ||
offset = _Node2.default.endOfIndent(src, lineStart); | ||
offset = Node.endOfIndent(src, lineStart); | ||
@@ -108,3 +84,3 @@ if (offset <= lineStart + indent) { | ||
var msg = 'Insufficient indentation in flow collection'; | ||
this.error = new _errors.YAMLSemanticError(this, msg); | ||
this.error = new YAMLSemanticError(this, msg); | ||
} | ||
@@ -127,3 +103,3 @@ } | ||
{ | ||
var comment = new _Comment.default(); | ||
var comment = new Comment(); | ||
offset = comment.parse({ | ||
@@ -166,3 +142,3 @@ src: src | ||
// at next document start | ||
this.valueRange = new _Range.default(start, offset); | ||
this.valueRange = new Range(start, offset); | ||
return offset; | ||
@@ -172,11 +148,11 @@ } | ||
this.items.push(node); | ||
offset = _Node2.default.normalizeOffset(src, node.range.end); | ||
offset = Node.normalizeOffset(src, node.range.end); | ||
} | ||
} | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
offset = Node.endOfWhiteSpace(src, offset); | ||
char = src[offset]; | ||
} | ||
this.valueRange = new _Range.default(start, offset + 1); | ||
this.valueRange = new Range(start, offset + 1); | ||
@@ -188,3 +164,3 @@ if (char) { | ||
}); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset + 1); | ||
offset = Node.endOfWhiteSpace(src, offset + 1); | ||
offset = this.parseComment(offset); | ||
@@ -198,5 +174,5 @@ } | ||
value: function setOrigRanges(cr, offset) { | ||
offset = (0, _get2.default)((0, _getPrototypeOf2.default)(FlowCollection.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
offset = _get(_getPrototypeOf(FlowCollection.prototype), "setOrigRanges", this).call(this, cr, offset); | ||
this.items.forEach(function (node) { | ||
if (node instanceof _Node2.default) { | ||
if (node instanceof Node) { | ||
offset = node.setOrigRanges(cr, offset); | ||
@@ -227,3 +203,3 @@ } else if (cr.length === 0) { | ||
var nodes = items.filter(function (item) { | ||
return item instanceof _Node2.default; | ||
return item instanceof Node; | ||
}); | ||
@@ -245,8 +221,9 @@ var str = ''; | ||
str += src.slice(prevEnd, range.end); | ||
return _Node2.default.addStringTerminator(src, range.end, str); | ||
return Node.addStringTerminator(src, range.end, str); | ||
} | ||
}]); | ||
return FlowCollection; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = FlowCollection; | ||
export { FlowCollection as default }; |
@@ -1,27 +0,11 @@ | ||
"use strict"; | ||
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import { Char, Type } from '../constants'; | ||
import { getLinePos } from './source-utils'; | ||
import Range from './Range'; | ||
/** Root class of all nodes */ | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _constants = require("../constants"); | ||
var _sourceUtils = require("./source-utils"); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
/** Root class of all nodes */ | ||
var Node = | ||
/*#__PURE__*/ | ||
function () { | ||
(0, _createClass2.default)(Node, null, [{ | ||
var Node = /*#__PURE__*/function () { | ||
_createClass(Node, null, [{ | ||
key: "addStringTerminator", | ||
@@ -45,3 +29,3 @@ value: function addStringTerminator(src, offset, str) { | ||
} else { | ||
if (ch0 !== _constants.Char.DIRECTIVES_END && ch0 !== _constants.Char.DOCUMENT_END) return false; | ||
if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false; | ||
} | ||
@@ -146,8 +130,2 @@ | ||
}, { | ||
key: "atCollectionItem", | ||
value: function atCollectionItem(src, offset) { | ||
var ch = src[offset]; | ||
return (ch === '?' || ch === ':' || ch === '-') && Node.atBlank(src, offset + 1, true); | ||
} | ||
}, { | ||
key: "nextNodeIsIndented", | ||
@@ -209,3 +187,4 @@ value: function nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) { | ||
function Node(type, props, context) { | ||
(0, _classCallCheck2.default)(this, Node); | ||
_classCallCheck(this, Node); | ||
Object.defineProperty(this, 'context', { | ||
@@ -223,3 +202,3 @@ value: context || null, | ||
(0, _createClass2.default)(Node, [{ | ||
_createClass(Node, [{ | ||
key: "getPropValue", | ||
@@ -246,5 +225,5 @@ value: function getPropValue(idx, key, skipKey) { | ||
if (src[start] === _constants.Char.COMMENT) { | ||
if (src[start] === Char.COMMENT) { | ||
var end = Node.endOfLine(src, start + 1); | ||
var commentRange = new _Range.default(start, end); | ||
var commentRange = new Range(start, end); | ||
this.props.push(commentRange); | ||
@@ -289,3 +268,3 @@ return end; | ||
for (var i = 0; i < this.props.length; ++i) { | ||
var anchor = this.getPropValue(i, _constants.Char.ANCHOR, true); | ||
var anchor = this.getPropValue(i, Char.ANCHOR, true); | ||
if (anchor != null) return anchor; | ||
@@ -302,3 +281,3 @@ } | ||
for (var i = 0; i < this.props.length; ++i) { | ||
var comment = this.getPropValue(i, _constants.Char.COMMENT, true); | ||
var comment = this.getPropValue(i, Char.COMMENT, true); | ||
if (comment != null) comments.push(comment); | ||
@@ -316,3 +295,3 @@ } | ||
for (var i = 0; i < this.props.length; ++i) { | ||
if (src[this.props[i].start] === _constants.Char.COMMENT) return true; | ||
if (src[this.props[i].start] === Char.COMMENT) return true; | ||
} | ||
@@ -330,3 +309,3 @@ } | ||
for (var i = 0; i < this.props.length; ++i) { | ||
if (src[this.props[i].start] !== _constants.Char.COMMENT) return true; | ||
if (src[this.props[i].start] !== Char.COMMENT) return true; | ||
} | ||
@@ -345,3 +324,3 @@ } | ||
get: function get() { | ||
var jsonLikeTypes = [_constants.Type.FLOW_MAP, _constants.Type.FLOW_SEQ, _constants.Type.QUOTE_DOUBLE, _constants.Type.QUOTE_SINGLE]; | ||
var jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE]; | ||
return jsonLikeTypes.indexOf(this.type) !== -1; | ||
@@ -353,5 +332,5 @@ } | ||
if (!this.range || !this.context) return undefined; | ||
var start = (0, _sourceUtils.getLinePos)(this.range.start, this.context.root); | ||
var start = getLinePos(this.range.start, this.context.root); | ||
if (!start) return undefined; | ||
var end = (0, _sourceUtils.getLinePos)(this.range.end, this.context.root); | ||
var end = getLinePos(this.range.end, this.context.root); | ||
return { | ||
@@ -375,3 +354,3 @@ start: start, | ||
for (var i = 0; i < this.props.length; ++i) { | ||
var tag = this.getPropValue(i, _constants.Char.TAG, false); | ||
var tag = this.getPropValue(i, Char.TAG, false); | ||
@@ -386,3 +365,3 @@ if (tag != null) { | ||
var _tag$match = tag.match(/^(.*!)([^!]*)$/), | ||
_tag$match2 = (0, _slicedToArray2.default)(_tag$match, 3), | ||
_tag$match2 = _slicedToArray(_tag$match, 3), | ||
_ = _tag$match2[0], | ||
@@ -418,5 +397,6 @@ handle = _tag$match2[1], | ||
}]); | ||
return Node; | ||
}(); | ||
exports.default = Node; | ||
export { Node as default }; |
@@ -1,16 +0,5 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = parse; | ||
var _Document = _interopRequireDefault(require("./Document")); | ||
var _ParseContext = _interopRequireDefault(require("./ParseContext")); | ||
// Published as 'yaml/parse-cst' | ||
function parse(src) { | ||
import Document from './Document'; | ||
import ParseContext from './ParseContext'; | ||
export default function parse(src) { | ||
var cr = []; | ||
@@ -29,4 +18,4 @@ | ||
do { | ||
var doc = new _Document.default(); | ||
var context = new _ParseContext.default({ | ||
var doc = new Document(); | ||
var context = new ParseContext({ | ||
src: src | ||
@@ -33,0 +22,0 @@ }); |
@@ -1,40 +0,52 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import { Char, Type } from '../constants'; | ||
import { YAMLSyntaxError } from '../errors'; | ||
import Alias from './Alias'; | ||
import BlockValue from './BlockValue'; | ||
import Collection from './Collection'; | ||
import CollectionItem from './CollectionItem'; | ||
import FlowCollection from './FlowCollection'; | ||
import Node from './Node'; | ||
import PlainValue from './PlainValue'; | ||
import QuoteDouble from './QuoteDouble'; | ||
import QuoteSingle from './QuoteSingle'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
function createNewNode(type, props) { | ||
switch (type) { | ||
case Type.ALIAS: | ||
return new Alias(type, props); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
case Type.BLOCK_FOLDED: | ||
case Type.BLOCK_LITERAL: | ||
return new BlockValue(type, props); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
case Type.FLOW_MAP: | ||
case Type.FLOW_SEQ: | ||
return new FlowCollection(type, props); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
case Type.MAP_KEY: | ||
case Type.MAP_VALUE: | ||
case Type.SEQ_ITEM: | ||
return new CollectionItem(type, props); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
case Type.COMMENT: | ||
case Type.PLAIN: | ||
return new PlainValue(type, props); | ||
var _constants = require("../constants"); | ||
case Type.QUOTE_DOUBLE: | ||
return new QuoteDouble(type, props); | ||
var _errors = require("../errors"); | ||
case Type.QUOTE_SINGLE: | ||
return new QuoteSingle(type, props); | ||
var _Alias = _interopRequireDefault(require("./Alias")); | ||
/* istanbul ignore next */ | ||
var _BlockValue = _interopRequireDefault(require("./BlockValue")); | ||
var _Collection = _interopRequireDefault(require("./Collection")); | ||
var _CollectionItem = _interopRequireDefault(require("./CollectionItem")); | ||
var _FlowCollection = _interopRequireDefault(require("./FlowCollection")); | ||
var _Node = _interopRequireDefault(require("./Node")); | ||
var _PlainValue = _interopRequireDefault(require("./PlainValue")); | ||
var _QuoteDouble = _interopRequireDefault(require("./QuoteDouble")); | ||
var _QuoteSingle = _interopRequireDefault(require("./QuoteSingle")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
default: | ||
return null; | ||
// should never happen | ||
} | ||
} | ||
/** | ||
@@ -49,6 +61,6 @@ * @param {boolean} atLineStart - Node starts at beginning of line | ||
*/ | ||
var ParseContext = | ||
/*#__PURE__*/ | ||
function () { | ||
(0, _createClass2.default)(ParseContext, null, [{ | ||
var ParseContext = /*#__PURE__*/function () { | ||
_createClass(ParseContext, null, [{ | ||
key: "parseType", | ||
@@ -58,33 +70,33 @@ value: function parseType(src, offset, inFlow) { | ||
case '*': | ||
return _constants.Type.ALIAS; | ||
return Type.ALIAS; | ||
case '>': | ||
return _constants.Type.BLOCK_FOLDED; | ||
return Type.BLOCK_FOLDED; | ||
case '|': | ||
return _constants.Type.BLOCK_LITERAL; | ||
return Type.BLOCK_LITERAL; | ||
case '{': | ||
return _constants.Type.FLOW_MAP; | ||
return Type.FLOW_MAP; | ||
case '[': | ||
return _constants.Type.FLOW_SEQ; | ||
return Type.FLOW_SEQ; | ||
case '?': | ||
return !inFlow && _Node.default.atBlank(src, offset + 1, true) ? _constants.Type.MAP_KEY : _constants.Type.PLAIN; | ||
return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_KEY : Type.PLAIN; | ||
case ':': | ||
return !inFlow && _Node.default.atBlank(src, offset + 1, true) ? _constants.Type.MAP_VALUE : _constants.Type.PLAIN; | ||
return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_VALUE : Type.PLAIN; | ||
case '-': | ||
return !inFlow && _Node.default.atBlank(src, offset + 1, true) ? _constants.Type.SEQ_ITEM : _constants.Type.PLAIN; | ||
return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.SEQ_ITEM : Type.PLAIN; | ||
case '"': | ||
return _constants.Type.QUOTE_DOUBLE; | ||
return Type.QUOTE_DOUBLE; | ||
case "'": | ||
return _constants.Type.QUOTE_SINGLE; | ||
return Type.QUOTE_SINGLE; | ||
default: | ||
return _constants.Type.PLAIN; | ||
return Type.PLAIN; | ||
} | ||
@@ -107,5 +119,6 @@ } | ||
(0, _classCallCheck2.default)(this, ParseContext); | ||
(0, _defineProperty2.default)(this, "parseNode", function (overlay, start) { | ||
if (_Node.default.atDocumentBoundary(_this.src, start)) return null; | ||
_classCallCheck(this, ParseContext); | ||
_defineProperty(this, "parseNode", function (overlay, start) { | ||
if (Node.atDocumentBoundary(_this.src, start)) return null; | ||
var context = new ParseContext(_this, overlay); | ||
@@ -118,48 +131,10 @@ | ||
var node; | ||
switch (type) { | ||
case _constants.Type.ALIAS: | ||
node = new _Alias.default(type, props); | ||
break; | ||
case _constants.Type.BLOCK_FOLDED: | ||
case _constants.Type.BLOCK_LITERAL: | ||
node = new _BlockValue.default(type, props); | ||
break; | ||
case _constants.Type.FLOW_MAP: | ||
case _constants.Type.FLOW_SEQ: | ||
node = new _FlowCollection.default(type, props); | ||
break; | ||
case _constants.Type.MAP_KEY: | ||
case _constants.Type.MAP_VALUE: | ||
case _constants.Type.SEQ_ITEM: | ||
node = new _CollectionItem.default(type, props); | ||
break; | ||
case _constants.Type.COMMENT: | ||
case _constants.Type.PLAIN: | ||
node = new _PlainValue.default(type, props); | ||
break; | ||
case _constants.Type.QUOTE_DOUBLE: | ||
node = new _QuoteDouble.default(type, props); | ||
break; | ||
case _constants.Type.QUOTE_SINGLE: | ||
node = new _QuoteSingle.default(type, props); | ||
break; | ||
default: | ||
node.error = new _errors.YAMLSyntaxError(node, "Unknown node type: ".concat(JSON.stringify(type))); | ||
node.range = new _Range.default(start, start + 1); | ||
return node; | ||
} | ||
var node = createNewNode(type, props); | ||
var offset = node.parse(context, valueStart); | ||
node.range = new _Range.default(start, offset); | ||
node.range = new Range(start, offset); | ||
/* istanbul ignore if */ | ||
if (offset <= start) { | ||
// This should never happen, but if it does, let's make sure to at least | ||
// step one character forward to avoid a busy loop. | ||
node.error = new Error("Node#parse consumed no characters"); | ||
@@ -172,9 +147,9 @@ node.error.parseEnd = offset; | ||
if (context.nodeStartsCollection(node)) { | ||
if (!node.error && !context.atLineStart && context.parent.type === _constants.Type.DOCUMENT) { | ||
node.error = new _errors.YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)'); | ||
if (!node.error && !context.atLineStart && context.parent.type === Type.DOCUMENT) { | ||
node.error = new YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)'); | ||
} | ||
var collection = new _Collection.default(node); | ||
var collection = new Collection(node); | ||
offset = collection.parse(new ParseContext(context), offset); | ||
collection.range = new _Range.default(start, offset); | ||
collection.range = new Range(start, offset); | ||
return collection; | ||
@@ -185,2 +160,3 @@ } | ||
}); | ||
this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false; | ||
@@ -194,6 +170,5 @@ this.inCollection = inCollection != null ? inCollection : orig.inCollection || false; | ||
this.src = orig.src; | ||
} // for logging | ||
} | ||
(0, _createClass2.default)(ParseContext, [{ | ||
_createClass(ParseContext, [{ | ||
key: "nodeStartsCollection", | ||
@@ -205,7 +180,7 @@ value: function nodeStartsCollection(node) { | ||
if (inCollection || inFlow) return false; | ||
if (node instanceof _CollectionItem.default) return true; // check for implicit key | ||
if (node instanceof CollectionItem) return true; // check for implicit key | ||
var offset = node.range.end; | ||
if (src[offset] === '\n' || src[offset - 1] === '\n') return false; | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
offset = Node.endOfWhiteSpace(src, offset); | ||
return src[offset] === ':'; | ||
@@ -223,14 +198,12 @@ } // Anchor and tag are before type, which determines the node implementation | ||
var lineHasProps = false; | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
offset = Node.endOfWhiteSpace(src, offset); | ||
var ch = src[offset]; | ||
while (ch === _constants.Char.ANCHOR || ch === _constants.Char.COMMENT || ch === _constants.Char.TAG || ch === '\n') { | ||
while (ch === Char.ANCHOR || ch === Char.COMMENT || ch === Char.TAG || ch === '\n') { | ||
if (ch === '\n') { | ||
var lineStart = offset + 1; | ||
var inEnd = _Node.default.endOfIndent(src, lineStart); | ||
var inEnd = Node.endOfIndent(src, lineStart); | ||
var indentDiff = inEnd - (lineStart + this.indent); | ||
var noIndicatorAsIndent = parent.type === _constants.Type.SEQ_ITEM && parent.context.atLineStart; | ||
if (!_Node.default.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break; | ||
var noIndicatorAsIndent = parent.type === Type.SEQ_ITEM && parent.context.atLineStart; | ||
if (!Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break; | ||
this.atLineStart = true; | ||
@@ -240,11 +213,10 @@ this.lineStart = lineStart; | ||
offset = inEnd; | ||
} else if (ch === _constants.Char.COMMENT) { | ||
var end = _Node.default.endOfLine(src, offset + 1); | ||
props.push(new _Range.default(offset, end)); | ||
} else if (ch === Char.COMMENT) { | ||
var end = Node.endOfLine(src, offset + 1); | ||
props.push(new Range(offset, end)); | ||
offset = end; | ||
} else { | ||
var _end = _Node.default.endOfIdentifier(src, offset + 1); | ||
var _end = Node.endOfIdentifier(src, offset + 1); | ||
if (ch === _constants.Char.TAG && src[_end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, _end + 13))) { | ||
if (ch === Char.TAG && src[_end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, _end + 13))) { | ||
// Let's presume we're dealing with a YAML 1.0 domain tag here, rather | ||
@@ -254,8 +226,8 @@ // than an empty but 'foo.bar' private-tagged node in a flow collection | ||
// or date divided by something. | ||
_end = _Node.default.endOfIdentifier(src, _end + 5); | ||
_end = Node.endOfIdentifier(src, _end + 5); | ||
} | ||
props.push(new _Range.default(offset, _end)); | ||
props.push(new Range(offset, _end)); | ||
lineHasProps = true; | ||
offset = _Node.default.endOfWhiteSpace(src, _end); | ||
offset = Node.endOfWhiteSpace(src, _end); | ||
} | ||
@@ -267,3 +239,3 @@ | ||
if (lineHasProps && ch === ':' && _Node.default.atBlank(src, offset + 1, true)) offset -= 1; | ||
if (lineHasProps && ch === ':' && Node.atBlank(src, offset + 1, true)) offset -= 1; | ||
var type = ParseContext.parseType(src, offset, inFlow); | ||
@@ -283,19 +255,7 @@ return { | ||
}, { | ||
key: "pretty", | ||
get: function get() { | ||
var obj = { | ||
start: "".concat(this.lineStart, " + ").concat(this.indent), | ||
in: [], | ||
parent: this.parent.type | ||
}; | ||
if (!this.atLineStart) obj.start += ' + N'; | ||
if (this.inCollection) obj.in.push('collection'); | ||
if (this.inFlow) obj.in.push('flow'); | ||
return obj; | ||
} | ||
}]); | ||
return ParseContext; | ||
}(); | ||
exports.default = ParseContext; | ||
export { ParseContext as default }; |
@@ -1,35 +0,19 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var PlainValue = /*#__PURE__*/function (_Node) { | ||
_inherits(PlainValue, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function PlainValue() { | ||
_classCallCheck(this, PlainValue); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var PlainValue = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(PlainValue, _Node); | ||
function PlainValue() { | ||
(0, _classCallCheck2.default)(this, PlainValue); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(PlainValue).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(PlainValue).apply(this, arguments)); | ||
} | ||
(0, _createClass2.default)(PlainValue, [{ | ||
_createClass(PlainValue, [{ | ||
key: "parseBlockValue", | ||
@@ -45,6 +29,4 @@ value: function parseBlockValue(start) { | ||
for (var ch = src[offset]; ch === '\n'; ch = src[offset]) { | ||
if (_Node2.default.atDocumentBoundary(src, offset + 1)) break; | ||
var end = _Node2.default.endOfBlockIndent(src, indent, offset + 1); | ||
if (Node.atDocumentBoundary(src, offset + 1)) break; | ||
var end = Node.endOfBlockIndent(src, indent, offset + 1); | ||
if (end === null || src[end] === '#') break; | ||
@@ -103,4 +85,4 @@ | ||
this.valueRange = new _Range.default(start, offset); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
this.valueRange = new Range(start, offset); | ||
offset = Node.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
@@ -140,3 +122,3 @@ | ||
if (_ch === '\n') { | ||
var _Node$foldNewline = _Node2.default.foldNewline(src, i, -1), | ||
var _Node$foldNewline = Node.foldNewline(src, i, -1), | ||
fold = _Node$foldNewline.fold, | ||
@@ -183,5 +165,6 @@ offset = _Node$foldNewline.offset; | ||
}]); | ||
return PlainValue; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = PlainValue; | ||
export { PlainValue as default }; |
@@ -1,37 +0,20 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { YAMLSemanticError, YAMLSyntaxError } from '../errors'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var QuoteDouble = /*#__PURE__*/function (_Node) { | ||
_inherits(QuoteDouble, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function QuoteDouble() { | ||
_classCallCheck(this, QuoteDouble); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _errors = require("../errors"); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var QuoteDouble = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(QuoteDouble, _Node); | ||
function QuoteDouble() { | ||
(0, _classCallCheck2.default)(this, QuoteDouble); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(QuoteDouble).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(QuoteDouble).apply(this, arguments)); | ||
} | ||
(0, _createClass2.default)(QuoteDouble, [{ | ||
_createClass(QuoteDouble, [{ | ||
key: "parseCharCode", | ||
@@ -45,3 +28,3 @@ value: function parseCharCode(offset, length, errors) { | ||
if (isNaN(code)) { | ||
errors.push(new _errors.YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(offset - 2, length + 2)))); | ||
errors.push(new YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(offset - 2, length + 2)))); | ||
return src.substr(offset - 2, length + 2); | ||
@@ -66,4 +49,4 @@ } | ||
var offset = QuoteDouble.endOfQuote(src, start + 1); | ||
this.valueRange = new _Range.default(start, offset); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
this.valueRange = new Range(start, offset); | ||
offset = Node.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
@@ -87,3 +70,3 @@ return offset; | ||
src = _this$context.src; | ||
if (src[end - 1] !== '"') errors.push(new _errors.YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by | ||
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. | ||
@@ -97,5 +80,5 @@ | ||
if (ch === '\n') { | ||
if (_Node2.default.atDocumentBoundary(src, i + 1)) errors.push(new _errors.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); | ||
if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); | ||
var _Node$foldNewline = _Node2.default.foldNewline(src, i, indent), | ||
var _Node$foldNewline = Node.foldNewline(src, i, indent), | ||
fold = _Node$foldNewline.fold, | ||
@@ -107,3 +90,3 @@ offset = _Node$foldNewline.offset, | ||
i = offset; | ||
if (error) errors.push(new _errors.YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented')); | ||
if (error) errors.push(new YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented')); | ||
} else if (ch === '\\') { | ||
@@ -222,3 +205,3 @@ i += 1; | ||
default: | ||
errors.push(new _errors.YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(i - 1, 2)))); | ||
errors.push(new YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(i - 1, 2)))); | ||
str += '\\' + src[i]; | ||
@@ -260,5 +243,6 @@ } | ||
}]); | ||
return QuoteDouble; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = QuoteDouble; | ||
export { QuoteDouble as default }; |
@@ -1,37 +0,20 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import { YAMLSemanticError, YAMLSyntaxError } from '../errors'; | ||
import Node from './Node'; | ||
import Range from './Range'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var QuoteSingle = /*#__PURE__*/function (_Node) { | ||
_inherits(QuoteSingle, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function QuoteSingle() { | ||
_classCallCheck(this, QuoteSingle); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _errors = require("../errors"); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Range = _interopRequireDefault(require("./Range")); | ||
var QuoteSingle = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(QuoteSingle, _Node); | ||
function QuoteSingle() { | ||
(0, _classCallCheck2.default)(this, QuoteSingle); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(QuoteSingle).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(QuoteSingle).apply(this, arguments)); | ||
} | ||
(0, _createClass2.default)(QuoteSingle, [{ | ||
_createClass(QuoteSingle, [{ | ||
key: "parse", | ||
@@ -50,4 +33,4 @@ | ||
var offset = QuoteSingle.endOfQuote(src, start + 1); | ||
this.valueRange = new _Range.default(start, offset); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
this.valueRange = new Range(start, offset); | ||
offset = Node.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
@@ -71,3 +54,3 @@ return offset; | ||
src = _this$context.src; | ||
if (src[end - 1] !== "'") errors.push(new _errors.YAMLSyntaxError(this, "Missing closing 'quote")); | ||
if (src[end - 1] !== "'") errors.push(new YAMLSyntaxError(this, "Missing closing 'quote")); | ||
var str = ''; | ||
@@ -79,5 +62,5 @@ | ||
if (ch === '\n') { | ||
if (_Node2.default.atDocumentBoundary(src, i + 1)) errors.push(new _errors.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); | ||
if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); | ||
var _Node$foldNewline = _Node2.default.foldNewline(src, i, indent), | ||
var _Node$foldNewline = Node.foldNewline(src, i, indent), | ||
fold = _Node$foldNewline.fold, | ||
@@ -89,7 +72,7 @@ offset = _Node$foldNewline.offset, | ||
i = offset; | ||
if (error) errors.push(new _errors.YAMLSemanticError(this, 'Multi-line single-quoted string needs to be sufficiently indented')); | ||
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 _errors.YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.')); | ||
if (src[i] !== "'") errors.push(new YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.')); | ||
} else if (ch === ' ' || ch === '\t') { | ||
@@ -133,5 +116,6 @@ // trim trailing whitespace | ||
}]); | ||
return QuoteSingle; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = QuoteSingle; | ||
export { QuoteSingle as default }; |
@@ -1,18 +0,6 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var Range = | ||
/*#__PURE__*/ | ||
function () { | ||
(0, _createClass2.default)(Range, null, [{ | ||
var Range = /*#__PURE__*/function () { | ||
_createClass(Range, null, [{ | ||
key: "copy", | ||
@@ -25,3 +13,4 @@ value: function copy(orig) { | ||
function Range(start, end) { | ||
(0, _classCallCheck2.default)(this, Range); | ||
_classCallCheck(this, Range); | ||
this.start = start; | ||
@@ -31,3 +20,3 @@ this.end = end || start; | ||
(0, _createClass2.default)(Range, [{ | ||
_createClass(Range, [{ | ||
key: "isEmpty", | ||
@@ -76,5 +65,6 @@ value: function isEmpty() { | ||
}]); | ||
return Range; | ||
}(); | ||
exports.default = Range; | ||
export { Range as default }; |
@@ -1,10 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getLinePos = getLinePos; | ||
exports.getLine = getLine; | ||
exports.getPrettyContext = getPrettyContext; | ||
function findLineStarts(src) { | ||
@@ -66,3 +57,3 @@ var ls = [0]; | ||
function getLinePos(offset, cst) { | ||
export function getLinePos(offset, cst) { | ||
if (typeof offset !== 'number' || offset < 0) return null; | ||
@@ -112,4 +103,3 @@ | ||
function getLine(line, cst) { | ||
export function getLine(line, cst) { | ||
var _getSrcInfo2 = getSrcInfo(cst), | ||
@@ -146,4 +136,3 @@ lineStarts = _getSrcInfo2.lineStarts, | ||
function getPrettyContext(_ref, cst) { | ||
export function getPrettyContext(_ref, cst) { | ||
var start = _ref.start, | ||
@@ -150,0 +139,0 @@ end = _ref.end; |
@@ -1,52 +0,26 @@ | ||
"use strict"; | ||
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import addComment from './addComment'; | ||
import Anchors from './Anchors'; | ||
import { Char, Type } from './constants'; | ||
import { YAMLError, YAMLReferenceError, YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from './errors'; | ||
import listTagNames from './listTagNames'; | ||
import Schema from './schema'; | ||
import Alias from './schema/Alias'; | ||
import Collection, { isEmptyPath } from './schema/Collection'; | ||
import Node from './schema/Node'; | ||
import Scalar from './schema/Scalar'; | ||
import _toJSON from './toJSON'; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _addComment = _interopRequireDefault(require("./addComment")); | ||
var _Anchors = _interopRequireDefault(require("./Anchors")); | ||
var _constants = require("./constants"); | ||
var _errors = require("./errors"); | ||
var _listTagNames = _interopRequireDefault(require("./listTagNames")); | ||
var _schema = _interopRequireDefault(require("./schema")); | ||
var _Alias = _interopRequireDefault(require("./schema/Alias")); | ||
var _Collection = _interopRequireWildcard(require("./schema/Collection")); | ||
var _Node = _interopRequireDefault(require("./schema/Node")); | ||
var _Scalar = _interopRequireDefault(require("./schema/Scalar")); | ||
var _toJSON2 = _interopRequireDefault(require("./toJSON")); | ||
var isCollectionItem = function isCollectionItem(node) { | ||
return node && [_constants.Type.MAP_KEY, _constants.Type.MAP_VALUE, _constants.Type.SEQ_ITEM].includes(node.type); | ||
return node && [Type.MAP_KEY, Type.MAP_VALUE, Type.SEQ_ITEM].includes(node.type); | ||
}; | ||
var Document = | ||
/*#__PURE__*/ | ||
function () { | ||
var Document = /*#__PURE__*/function () { | ||
function Document(options) { | ||
(0, _classCallCheck2.default)(this, Document); | ||
this.anchors = new _Anchors.default(options.anchorPrefix); | ||
_classCallCheck(this, Document); | ||
this.anchors = new Anchors(options.anchorPrefix); | ||
this.commentBefore = null; | ||
@@ -64,6 +38,6 @@ this.comment = null; | ||
(0, _createClass2.default)(Document, [{ | ||
_createClass(Document, [{ | ||
key: "assertCollectionContents", | ||
value: function assertCollectionContents() { | ||
if (this.contents instanceof _Collection.default) return true; | ||
if (this.contents instanceof Collection) return true; | ||
throw new Error('Expected a YAML collection as document contents'); | ||
@@ -92,3 +66,3 @@ } | ||
value: function deleteIn(path) { | ||
if ((0, _Collection.isEmptyPath)(path)) { | ||
if (isEmptyPath(path)) { | ||
if (this.contents == null) return false; | ||
@@ -110,3 +84,3 @@ this.contents = null; | ||
value: function get(key, keepScalar) { | ||
return this.contents instanceof _Collection.default ? this.contents.get(key, keepScalar) : undefined; | ||
return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined; | ||
} | ||
@@ -116,4 +90,4 @@ }, { | ||
value: function getIn(path, keepScalar) { | ||
if ((0, _Collection.isEmptyPath)(path)) return !keepScalar && this.contents instanceof _Scalar.default ? this.contents.value : this.contents; | ||
return this.contents instanceof _Collection.default ? this.contents.getIn(path, keepScalar) : undefined; | ||
if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents; | ||
return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined; | ||
} | ||
@@ -123,3 +97,3 @@ }, { | ||
value: function has(key) { | ||
return this.contents instanceof _Collection.default ? this.contents.has(key) : false; | ||
return this.contents instanceof Collection ? this.contents.has(key) : false; | ||
} | ||
@@ -129,4 +103,4 @@ }, { | ||
value: function hasIn(path) { | ||
if ((0, _Collection.isEmptyPath)(path)) return this.contents !== undefined; | ||
return this.contents instanceof _Collection.default ? this.contents.hasIn(path) : false; | ||
if (isEmptyPath(path)) return this.contents !== undefined; | ||
return this.contents instanceof Collection ? this.contents.hasIn(path) : false; | ||
} | ||
@@ -142,3 +116,3 @@ }, { | ||
value: function setIn(path, value) { | ||
if ((0, _Collection.isEmptyPath)(path)) this.contents = value;else { | ||
if (isEmptyPath(path)) this.contents = value;else { | ||
this.assertCollectionContents(); | ||
@@ -163,3 +137,3 @@ this.contents.setIn(path, value); | ||
var opt = Object.assign({}, this.getDefaults(), this.options); | ||
this.schema = new _schema.default(opt); | ||
this.schema = new Schema(opt); | ||
} | ||
@@ -200,3 +174,3 @@ }, { | ||
var _error = _step.value; | ||
if (_error instanceof _errors.YAMLError) _error.makePretty(); | ||
if (_error instanceof YAMLError) _error.makePretty(); | ||
} | ||
@@ -225,3 +199,3 @@ } catch (err) { | ||
var warn = _step2.value; | ||
if (warn instanceof _errors.YAMLError) warn.makePretty(); | ||
if (warn instanceof YAMLError) warn.makePretty(); | ||
} | ||
@@ -275,3 +249,3 @@ } catch (err) { | ||
_this.warnings.push(new _errors.YAMLWarning(directive, msg)); | ||
_this.warnings.push(new YAMLWarning(directive, msg)); | ||
} | ||
@@ -316,3 +290,3 @@ | ||
_this2.errors.push(new _errors.YAMLSyntaxError(node, msg)); | ||
_this2.errors.push(new YAMLSyntaxError(node, msg)); | ||
} | ||
@@ -331,3 +305,3 @@ | ||
cc.push(node.comment); | ||
} else if (node.type === _constants.Type.BLANK_LINE) { | ||
} else if (node.type === Type.BLANK_LINE) { | ||
spaceBefore = true; | ||
@@ -356,3 +330,3 @@ | ||
if (cb) { | ||
var cbNode = this.contents instanceof _Collection.default && this.contents.items[0] ? this.contents.items[0] : this.contents; | ||
var cbNode = this.contents instanceof Collection && this.contents.items[0] ? this.contents.items[0] : this.contents; | ||
cbNode.commentBefore = cbNode.commentBefore ? "".concat(cb, "\n").concat(cbNode.commentBefore) : cb; | ||
@@ -382,3 +356,3 @@ } | ||
value: function resolveTagDirective(directive) { | ||
var _directive$parameters = (0, _slicedToArray2.default)(directive.parameters, 2), | ||
var _directive$parameters = _slicedToArray(directive.parameters, 2), | ||
handle = _directive$parameters[0], | ||
@@ -397,7 +371,7 @@ prefix = _directive$parameters[1]; | ||
var msg = 'The %TAG directive must only be given at most once per handle in the same document.'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, msg)); | ||
this.errors.push(new YAMLSemanticError(directive, msg)); | ||
} | ||
} else { | ||
var _msg = 'Insufficient parameters given for %TAG directive'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, _msg)); | ||
this.errors.push(new YAMLSemanticError(directive, _msg)); | ||
} | ||
@@ -408,3 +382,3 @@ } | ||
value: function resolveYamlDirective(directive) { | ||
var _directive$parameters2 = (0, _slicedToArray2.default)(directive.parameters, 1), | ||
var _directive$parameters2 = _slicedToArray(directive.parameters, 1), | ||
version = _directive$parameters2[0]; | ||
@@ -416,3 +390,3 @@ | ||
var msg = 'The %YAML directive must only be given at most once per document.'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, msg)); | ||
this.errors.push(new YAMLSemanticError(directive, msg)); | ||
} | ||
@@ -422,3 +396,3 @@ | ||
var _msg2 = 'Insufficient parameters given for %YAML directive'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, _msg2)); | ||
this.errors.push(new YAMLSemanticError(directive, _msg2)); | ||
} else { | ||
@@ -430,3 +404,3 @@ if (!Document.defaults[version]) { | ||
this.warnings.push(new _errors.YAMLWarning(directive, _msg3)); | ||
this.warnings.push(new YAMLWarning(directive, _msg3)); | ||
} | ||
@@ -452,3 +426,3 @@ | ||
var msg = "Verbatim tags aren't resolved, so ".concat(verbatim, " is invalid."); | ||
this.errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
this.errors.push(new YAMLSemanticError(node, msg)); | ||
} else if (handle === '!' && !suffix) { | ||
@@ -483,7 +457,7 @@ nonSpecific = true; | ||
this.errors.push(new _errors.YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix."))); | ||
this.errors.push(new YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix."))); | ||
} else { | ||
var _msg4 = "The ".concat(handle, " tag handle is non-default and was not declared."); | ||
this.errors.push(new _errors.YAMLSemanticError(node, _msg4)); | ||
this.errors.push(new YAMLSemanticError(node, _msg4)); | ||
} | ||
@@ -494,18 +468,18 @@ } | ||
switch (type) { | ||
case _constants.Type.BLOCK_FOLDED: | ||
case _constants.Type.BLOCK_LITERAL: | ||
case _constants.Type.QUOTE_DOUBLE: | ||
case _constants.Type.QUOTE_SINGLE: | ||
return _schema.default.defaultTags.STR; | ||
case Type.BLOCK_FOLDED: | ||
case Type.BLOCK_LITERAL: | ||
case Type.QUOTE_DOUBLE: | ||
case Type.QUOTE_SINGLE: | ||
return Schema.defaultTags.STR; | ||
case _constants.Type.FLOW_MAP: | ||
case _constants.Type.MAP: | ||
return _schema.default.defaultTags.MAP; | ||
case Type.FLOW_MAP: | ||
case Type.MAP: | ||
return Schema.defaultTags.MAP; | ||
case _constants.Type.FLOW_SEQ: | ||
case _constants.Type.SEQ: | ||
return _schema.default.defaultTags.SEQ; | ||
case Type.FLOW_SEQ: | ||
case Type.SEQ: | ||
return Schema.defaultTags.SEQ; | ||
case _constants.Type.PLAIN: | ||
return nonSpecific ? _schema.default.defaultTags.STR : null; | ||
case Type.PLAIN: | ||
return nonSpecific ? Schema.defaultTags.STR : null; | ||
@@ -541,7 +515,7 @@ default: | ||
switch (node.context.src[start]) { | ||
case _constants.Char.COMMENT: | ||
case Char.COMMENT: | ||
{ | ||
if (!node.commentHasRequiredWhitespace(start)) { | ||
var _msg7 = 'Comments must be separated from other tokens by white space characters'; | ||
errors.push(new _errors.YAMLSemanticError(node, _msg7)); | ||
errors.push(new YAMLSemanticError(node, _msg7)); | ||
} | ||
@@ -561,6 +535,6 @@ | ||
case _constants.Char.ANCHOR: | ||
case Char.ANCHOR: | ||
if (hasAnchor) { | ||
var _msg8 = 'A node can have at most one anchor'; | ||
errors.push(new _errors.YAMLSemanticError(node, _msg8)); | ||
errors.push(new YAMLSemanticError(node, _msg8)); | ||
} | ||
@@ -571,6 +545,6 @@ | ||
case _constants.Char.TAG: | ||
case Char.TAG: | ||
if (hasTag) { | ||
var _msg9 = 'A node can have at most one tag'; | ||
errors.push(new _errors.YAMLSemanticError(node, _msg9)); | ||
errors.push(new YAMLSemanticError(node, _msg9)); | ||
} | ||
@@ -611,6 +585,6 @@ | ||
if (node.type === _constants.Type.ALIAS) { | ||
if (node.type === Type.ALIAS) { | ||
if (hasAnchor || hasTag) { | ||
var msg = 'An alias node must not specify any properties'; | ||
errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
errors.push(new YAMLSemanticError(node, msg)); | ||
} | ||
@@ -624,3 +598,3 @@ | ||
errors.push(new _errors.YAMLReferenceError(node, _msg5)); | ||
errors.push(new YAMLReferenceError(node, _msg5)); | ||
return null; | ||
@@ -630,3 +604,3 @@ } // Lazy resolution for circular references | ||
res = new _Alias.default(src); | ||
res = new Alias(src); | ||
@@ -640,6 +614,6 @@ anchors._cstAliases.push(res); | ||
} else { | ||
if (node.type !== _constants.Type.PLAIN) { | ||
if (node.type !== Type.PLAIN) { | ||
var _msg6 = "Failed to resolve ".concat(node.type, " node here"); | ||
errors.push(new _errors.YAMLSyntaxError(node, _msg6)); | ||
errors.push(new YAMLSyntaxError(node, _msg6)); | ||
return null; | ||
@@ -677,4 +651,4 @@ } | ||
value: function listNonDefaultTags() { | ||
return (0, _listTagNames.default)(this.contents).filter(function (t) { | ||
return t.indexOf(_schema.default.defaultPrefix) !== 0; | ||
return listTagNames(this.contents).filter(function (t) { | ||
return t.indexOf(Schema.defaultPrefix) !== 0; | ||
}); | ||
@@ -744,3 +718,3 @@ } | ||
maxAliasCount = _this$options.maxAliasCount; | ||
var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default)); | ||
var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar)); | ||
var ctx = { | ||
@@ -761,3 +735,3 @@ doc: this, | ||
}); | ||
return (0, _toJSON2.default)(this.contents, arg, ctx); | ||
return _toJSON(this.contents, arg, ctx); | ||
} | ||
@@ -811,3 +785,3 @@ }, { | ||
if (this.contents) { | ||
if (this.contents instanceof _Node.default) { | ||
if (this.contents instanceof Node) { | ||
if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push(''); | ||
@@ -826,3 +800,3 @@ if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment | ||
}, onChompKeep); | ||
lines.push((0, _addComment.default)(body, '', contentComment)); | ||
lines.push(addComment(body, '', contentComment)); | ||
} else if (this.contents !== undefined) { | ||
@@ -840,7 +814,7 @@ lines.push(this.schema.stringify(this.contents, ctx)); | ||
}]); | ||
return Document; | ||
}(); | ||
exports.default = Document; | ||
(0, _defineProperty2.default)(Document, "defaults", { | ||
_defineProperty(Document, "defaults", { | ||
'1.0': { | ||
@@ -851,3 +825,3 @@ schema: 'yaml-1.1', | ||
handle: '!', | ||
prefix: _schema.default.defaultPrefix | ||
prefix: Schema.defaultPrefix | ||
}, { | ||
@@ -866,3 +840,3 @@ handle: '!!', | ||
handle: '!!', | ||
prefix: _schema.default.defaultPrefix | ||
prefix: Schema.defaultPrefix | ||
}] | ||
@@ -878,5 +852,7 @@ }, | ||
handle: '!!', | ||
prefix: _schema.default.defaultPrefix | ||
prefix: Schema.defaultPrefix | ||
}] | ||
} | ||
}); | ||
}); | ||
export { Document as default }; |
@@ -1,39 +0,20 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper"; | ||
import Node from './cst/Node'; | ||
import { getLinePos, getPrettyContext } from './cst/source-utils'; | ||
import Range from './cst/Range'; | ||
export var YAMLError = /*#__PURE__*/function (_Error) { | ||
_inherits(YAMLError, _Error); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.YAMLWarning = exports.YAMLSyntaxError = exports.YAMLSemanticError = exports.YAMLReferenceError = exports.YAMLError = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper")); | ||
var _Node = _interopRequireDefault(require("./cst/Node")); | ||
var _sourceUtils = require("./cst/source-utils"); | ||
var _Range = _interopRequireDefault(require("./cst/Range")); | ||
var YAMLError = | ||
/*#__PURE__*/ | ||
function (_Error) { | ||
(0, _inherits2.default)(YAMLError, _Error); | ||
function YAMLError(name, source, message) { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, YAMLError); | ||
if (!message || !(source instanceof _Node.default)) throw new Error("Invalid arguments for new ".concat(name)); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLError).call(this)); | ||
_classCallCheck(this, YAMLError); | ||
if (!message || !(source instanceof Node)) throw new Error("Invalid arguments for new ".concat(name)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(YAMLError).call(this)); | ||
_this.name = name; | ||
@@ -45,3 +26,3 @@ _this.message = message; | ||
(0, _createClass2.default)(YAMLError, [{ | ||
_createClass(YAMLError, [{ | ||
key: "makePretty", | ||
@@ -54,4 +35,4 @@ value: function makePretty() { | ||
if (typeof this.offset === 'number') { | ||
this.range = new _Range.default(this.offset, this.offset + 1); | ||
var start = cst && (0, _sourceUtils.getLinePos)(this.offset, cst); | ||
this.range = new Range(this.offset, this.offset + 1); | ||
var start = cst && getLinePos(this.offset, cst); | ||
@@ -80,3 +61,3 @@ if (start) { | ||
this.message += " at line ".concat(line, ", column ").concat(col); | ||
var ctx = cst && (0, _sourceUtils.getPrettyContext)(this.linePos, cst); | ||
var ctx = cst && getPrettyContext(this.linePos, cst); | ||
if (ctx) this.message += ":\n\n".concat(ctx, "\n"); | ||
@@ -88,15 +69,12 @@ } | ||
}]); | ||
return YAMLError; | ||
}((0, _wrapNativeSuper2.default)(Error)); | ||
}( /*#__PURE__*/_wrapNativeSuper(Error)); | ||
export var YAMLReferenceError = /*#__PURE__*/function (_YAMLError) { | ||
_inherits(YAMLReferenceError, _YAMLError); | ||
exports.YAMLError = YAMLError; | ||
function YAMLReferenceError(source, message) { | ||
_classCallCheck(this, YAMLReferenceError); | ||
var YAMLReferenceError = | ||
/*#__PURE__*/ | ||
function (_YAMLError) { | ||
(0, _inherits2.default)(YAMLReferenceError, _YAMLError); | ||
function YAMLReferenceError(source, message) { | ||
(0, _classCallCheck2.default)(this, YAMLReferenceError); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLReferenceError).call(this, 'YAMLReferenceError', source, message)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(YAMLReferenceError).call(this, 'YAMLReferenceError', source, message)); | ||
} | ||
@@ -106,13 +84,9 @@ | ||
}(YAMLError); | ||
export var YAMLSemanticError = /*#__PURE__*/function (_YAMLError2) { | ||
_inherits(YAMLSemanticError, _YAMLError2); | ||
exports.YAMLReferenceError = YAMLReferenceError; | ||
function YAMLSemanticError(source, message) { | ||
_classCallCheck(this, YAMLSemanticError); | ||
var YAMLSemanticError = | ||
/*#__PURE__*/ | ||
function (_YAMLError2) { | ||
(0, _inherits2.default)(YAMLSemanticError, _YAMLError2); | ||
function YAMLSemanticError(source, message) { | ||
(0, _classCallCheck2.default)(this, YAMLSemanticError); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLSemanticError).call(this, 'YAMLSemanticError', source, message)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(YAMLSemanticError).call(this, 'YAMLSemanticError', source, message)); | ||
} | ||
@@ -122,13 +96,9 @@ | ||
}(YAMLError); | ||
export var YAMLSyntaxError = /*#__PURE__*/function (_YAMLError3) { | ||
_inherits(YAMLSyntaxError, _YAMLError3); | ||
exports.YAMLSemanticError = YAMLSemanticError; | ||
function YAMLSyntaxError(source, message) { | ||
_classCallCheck(this, YAMLSyntaxError); | ||
var YAMLSyntaxError = | ||
/*#__PURE__*/ | ||
function (_YAMLError3) { | ||
(0, _inherits2.default)(YAMLSyntaxError, _YAMLError3); | ||
function YAMLSyntaxError(source, message) { | ||
(0, _classCallCheck2.default)(this, YAMLSyntaxError); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLSyntaxError).call(this, 'YAMLSyntaxError', source, message)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(YAMLSyntaxError).call(this, 'YAMLSyntaxError', source, message)); | ||
} | ||
@@ -138,18 +108,12 @@ | ||
}(YAMLError); | ||
export var YAMLWarning = /*#__PURE__*/function (_YAMLError4) { | ||
_inherits(YAMLWarning, _YAMLError4); | ||
exports.YAMLSyntaxError = YAMLSyntaxError; | ||
function YAMLWarning(source, message) { | ||
_classCallCheck(this, YAMLWarning); | ||
var YAMLWarning = | ||
/*#__PURE__*/ | ||
function (_YAMLError4) { | ||
(0, _inherits2.default)(YAMLWarning, _YAMLError4); | ||
function YAMLWarning(source, message) { | ||
(0, _classCallCheck2.default)(this, YAMLWarning); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLWarning).call(this, 'YAMLWarning', source, message)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(YAMLWarning).call(this, 'YAMLWarning', source, message)); | ||
} | ||
return YAMLWarning; | ||
}(YAMLError); | ||
exports.YAMLWarning = YAMLWarning; | ||
}(YAMLError); |
@@ -1,17 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = foldFlowLines; | ||
exports.FOLD_QUOTED = exports.FOLD_BLOCK = exports.FOLD_FLOW = void 0; | ||
var FOLD_FLOW = 'flow'; | ||
exports.FOLD_FLOW = FOLD_FLOW; | ||
var FOLD_BLOCK = 'block'; | ||
exports.FOLD_BLOCK = FOLD_BLOCK; | ||
var FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line | ||
export var FOLD_FLOW = 'flow'; | ||
export var FOLD_BLOCK = 'block'; | ||
export var FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line | ||
// returns index of last newline in more-indented block | ||
exports.FOLD_QUOTED = FOLD_QUOTED; | ||
var consumeMoreIndentedLines = function consumeMoreIndentedLines(text, i) { | ||
@@ -52,3 +41,3 @@ var ch = text[i + 1]; | ||
function foldFlowLines(text, indent, mode, _ref) { | ||
export default function foldFlowLines(text, indent, mode, _ref) { | ||
var indentAtStart = _ref.indentAtStart, | ||
@@ -55,0 +44,0 @@ _ref$lineWidth = _ref.lineWidth, |
@@ -1,28 +0,10 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _parse = _interopRequireDefault(require("./cst/parse")); | ||
var _Document = _interopRequireDefault(require("./Document")); | ||
var _errors = require("./errors"); | ||
var _schema = _interopRequireDefault(require("./schema")); | ||
var _warnings = require("./warnings"); | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import parseCST from './cst/parse'; | ||
import YAMLDocument from './Document'; | ||
import { YAMLSemanticError } from './errors'; | ||
import Schema from './schema'; | ||
import { warn } from './warnings'; | ||
var defaultOptions = { | ||
@@ -51,19 +33,18 @@ anchorPrefix: 'a', | ||
var options = Object.assign({}, _Document.default.defaults[defaultOptions.version], defaultOptions); | ||
var schema = new _schema.default(options); | ||
var options = Object.assign({}, YAMLDocument.defaults[defaultOptions.version], defaultOptions); | ||
var schema = new Schema(options); | ||
return schema.createNode(value, wrapScalars, tag); | ||
} | ||
var Document = | ||
/*#__PURE__*/ | ||
function (_YAMLDocument) { | ||
(0, _inherits2.default)(Document, _YAMLDocument); | ||
var Document = /*#__PURE__*/function (_YAMLDocument) { | ||
_inherits(Document, _YAMLDocument); | ||
function Document(options) { | ||
(0, _classCallCheck2.default)(this, Document); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Document).call(this, Object.assign({}, defaultOptions, options))); | ||
_classCallCheck(this, Document); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(Document).call(this, Object.assign({}, defaultOptions, options))); | ||
} | ||
return Document; | ||
}(_Document.default); | ||
}(YAMLDocument); | ||
@@ -78,3 +59,3 @@ function parseAllDocuments(src, options) { | ||
try { | ||
for (var _iterator = (0, _parse.default)(src)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
for (var _iterator = parseCST(src)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var cstDoc = _step.value; | ||
@@ -105,3 +86,3 @@ var doc = new Document(options); | ||
function parseDocument(src, options) { | ||
var cst = (0, _parse.default)(src); | ||
var cst = parseCST(src); | ||
var doc = new Document(options).parse(cst[0]); | ||
@@ -111,3 +92,3 @@ | ||
var errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()'; | ||
doc.errors.unshift(new _errors.YAMLSemanticError(cst[1], errMsg)); | ||
doc.errors.unshift(new YAMLSemanticError(cst[1], errMsg)); | ||
} | ||
@@ -121,3 +102,3 @@ | ||
doc.warnings.forEach(function (warning) { | ||
return (0, _warnings.warn)(warning); | ||
return warn(warning); | ||
}); | ||
@@ -134,3 +115,3 @@ if (doc.errors.length > 0) throw doc.errors[0]; | ||
var _default = { | ||
export default { | ||
createNode: createNode, | ||
@@ -141,6 +122,5 @@ defaultOptions: defaultOptions, | ||
parseAllDocuments: parseAllDocuments, | ||
parseCST: _parse.default, | ||
parseCST: parseCST, | ||
parseDocument: parseDocument, | ||
stringify: stringify | ||
}; | ||
exports.default = _default; | ||
}; |
@@ -1,23 +0,11 @@ | ||
"use strict"; | ||
import _typeof from "@babel/runtime/helpers/typeof"; | ||
import Collection from './schema/Collection'; | ||
import Pair from './schema/Pair'; | ||
import Scalar from './schema/Scalar'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _Collection = _interopRequireDefault(require("./schema/Collection")); | ||
var _Pair = _interopRequireDefault(require("./schema/Pair")); | ||
var _Scalar = _interopRequireDefault(require("./schema/Scalar")); | ||
var visit = function visit(node, tags) { | ||
if (node && (0, _typeof2.default)(node) === 'object') { | ||
if (node && _typeof(node) === 'object') { | ||
var tag = node.tag; | ||
if (node instanceof _Collection.default) { | ||
if (node instanceof Collection) { | ||
if (tag) tags[tag] = true; | ||
@@ -27,6 +15,6 @@ node.items.forEach(function (n) { | ||
}); | ||
} else if (node instanceof _Pair.default) { | ||
} else if (node instanceof Pair) { | ||
visit(node.key, tags); | ||
visit(node.value, tags); | ||
} else if (node instanceof _Scalar.default) { | ||
} else if (node instanceof Scalar) { | ||
if (tag) tags[tag] = true; | ||
@@ -39,6 +27,4 @@ } | ||
var _default = function _default(node) { | ||
export default (function (node) { | ||
return Object.keys(visit(node, {})); | ||
}; | ||
exports.default = _default; | ||
}); |
@@ -1,34 +0,14 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import { Type } from '../constants'; | ||
import { YAMLReferenceError } from '../errors'; | ||
import _toJSON from '../toJSON'; | ||
import Collection from './Collection'; | ||
import Node from './Node'; | ||
import Pair from './Pair'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _constants = require("../constants"); | ||
var _errors = require("../errors"); | ||
var _toJSON2 = _interopRequireDefault(require("../toJSON")); | ||
var _Collection = _interopRequireDefault(require("./Collection")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Pair = _interopRequireDefault(require("./Pair")); | ||
var getAliasCount = function getAliasCount(node, anchors) { | ||
@@ -40,3 +20,3 @@ if (node instanceof Alias) { | ||
return anchor.count * anchor.aliasCount; | ||
} else if (node instanceof _Collection.default) { | ||
} else if (node instanceof Collection) { | ||
var count = 0; | ||
@@ -69,3 +49,3 @@ var _iteratorNormalCompletion = true; | ||
return count; | ||
} else if (node instanceof _Pair.default) { | ||
} else if (node instanceof Pair) { | ||
var kc = getAliasCount(node.key, anchors); | ||
@@ -79,7 +59,6 @@ var vc = getAliasCount(node.value, anchors); | ||
var Alias = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(Alias, _Node); | ||
(0, _createClass2.default)(Alias, null, [{ | ||
var Alias = /*#__PURE__*/function (_Node) { | ||
_inherits(Alias, _Node); | ||
_createClass(Alias, null, [{ | ||
key: "stringify", | ||
@@ -106,10 +85,11 @@ value: function stringify(_ref, _ref2) { | ||
(0, _classCallCheck2.default)(this, Alias); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Alias).call(this)); | ||
_classCallCheck(this, Alias); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Alias).call(this)); | ||
_this.source = source; | ||
_this.type = _constants.Type.ALIAS; | ||
_this.type = Type.ALIAS; | ||
return _this; | ||
} | ||
(0, _createClass2.default)(Alias, [{ | ||
_createClass(Alias, [{ | ||
key: "toJSON", | ||
@@ -119,3 +99,3 @@ value: function toJSON(arg, ctx) { | ||
if (!ctx) return (0, _toJSON2.default)(this.source, arg, ctx); | ||
if (!ctx) return _toJSON(this.source, arg, ctx); | ||
var anchors = ctx.anchors, | ||
@@ -126,6 +106,7 @@ maxAliasCount = ctx.maxAliasCount; | ||
}); | ||
/* istanbul ignore if */ | ||
if (!anchor || anchor.res === undefined) { | ||
var msg = 'This should not happen: Alias anchor was not resolved?'; | ||
if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg); | ||
if (this.cstNode) throw new YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg); | ||
} | ||
@@ -139,3 +120,3 @@ | ||
var _msg = 'Excessive alias count indicates a resource exhaustion attack'; | ||
if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, _msg);else throw new ReferenceError(_msg); | ||
if (this.cstNode) throw new YAMLReferenceError(this.cstNode, _msg);else throw new ReferenceError(_msg); | ||
} | ||
@@ -159,6 +140,8 @@ } | ||
}]); | ||
return Alias; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = Alias; | ||
(0, _defineProperty2.default)(Alias, "default", true); | ||
_defineProperty(Alias, "default", true); | ||
export { Alias as default }; |
@@ -1,69 +0,54 @@ | ||
"use strict"; | ||
import _toArray from "@babel/runtime/helpers/toArray"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import _typeof from "@babel/runtime/helpers/typeof"; | ||
import addComment from '../addComment'; | ||
import Node from './Node'; | ||
import Pair from './Pair'; | ||
import Scalar from './Scalar'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
function collectionFromPath(schema, path, value) { | ||
var v = value; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.isEmptyPath = void 0; | ||
for (var i = path.length - 1; i >= 0; --i) { | ||
var k = path[i]; | ||
var o = Number.isInteger(k) && k >= 0 ? [] : {}; | ||
o[k] = v; | ||
v = o; | ||
} | ||
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray")); | ||
return schema.createNode(v, false); | ||
} // null, undefined, or an empty non-string iterable (e.g. []) | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _addComment = _interopRequireDefault(require("../addComment")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Pair = _interopRequireDefault(require("./Pair")); | ||
var _Scalar = _interopRequireDefault(require("./Scalar")); | ||
// null, undefined, or an empty non-string iterable (e.g. []) | ||
var isEmptyPath = function isEmptyPath(path) { | ||
return path == null || (0, _typeof2.default)(path) === 'object' && path[Symbol.iterator]().next().done; | ||
export var isEmptyPath = function isEmptyPath(path) { | ||
return path == null || _typeof(path) === 'object' && path[Symbol.iterator]().next().done; | ||
}; | ||
exports.isEmptyPath = isEmptyPath; | ||
var Collection = /*#__PURE__*/function (_Node) { | ||
_inherits(Collection, _Node); | ||
var Collection = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(Collection, _Node); | ||
function Collection(schema) { | ||
var _this; | ||
function Collection() { | ||
var _getPrototypeOf2; | ||
_classCallCheck(this, Collection); | ||
var _this; | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Collection).call(this)); | ||
(0, _classCallCheck2.default)(this, Collection); | ||
_defineProperty(_assertThisInitialized(_this), "items", []); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(Collection)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "items", []); | ||
_this.schema = schema; | ||
return _this; | ||
} | ||
(0, _createClass2.default)(Collection, [{ | ||
_createClass(Collection, [{ | ||
key: "addIn", | ||
value: function addIn(path, value) { | ||
if (isEmptyPath(path)) this.add(value);else { | ||
var _path = (0, _toArray2.default)(path), | ||
var _path = _toArray(path), | ||
key = _path[0], | ||
@@ -73,3 +58,3 @@ rest = _path.slice(1); | ||
var node = this.get(key, true); | ||
if (node instanceof Collection) node.addIn(rest, value);else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest)); | ||
if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest)); | ||
} | ||
@@ -80,3 +65,3 @@ } | ||
value: function deleteIn(_ref) { | ||
var _ref2 = (0, _toArray2.default)(_ref), | ||
var _ref2 = _toArray(_ref), | ||
key = _ref2[0], | ||
@@ -92,3 +77,3 @@ rest = _ref2.slice(1); | ||
value: function getIn(_ref3, keepScalar) { | ||
var _ref4 = (0, _toArray2.default)(_ref3), | ||
var _ref4 = _toArray(_ref3), | ||
key = _ref4[0], | ||
@@ -98,3 +83,3 @@ rest = _ref4.slice(1); | ||
var node = this.get(key, true); | ||
if (rest.length === 0) return !keepScalar && node instanceof _Scalar.default ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined; | ||
if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined; | ||
} | ||
@@ -105,5 +90,5 @@ }, { | ||
return this.items.every(function (node) { | ||
if (!(node instanceof _Pair.default)) return false; | ||
if (!(node instanceof Pair)) return false; | ||
var n = node.value; | ||
return n == null || n instanceof _Scalar.default && n.value == null && !n.commentBefore && !n.comment && !n.tag; | ||
return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag; | ||
}); | ||
@@ -114,3 +99,3 @@ } | ||
value: function hasIn(_ref5) { | ||
var _ref6 = (0, _toArray2.default)(_ref5), | ||
var _ref6 = _toArray(_ref5), | ||
key = _ref6[0], | ||
@@ -126,3 +111,3 @@ rest = _ref6.slice(1); | ||
value: function setIn(_ref7, value) { | ||
var _ref8 = (0, _toArray2.default)(_ref7), | ||
var _ref8 = _toArray(_ref7), | ||
key = _ref8[0], | ||
@@ -135,6 +120,8 @@ rest = _ref8.slice(1); | ||
var node = this.get(key, true); | ||
if (node instanceof Collection) node.setIn(rest, value);else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest)); | ||
if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest)); | ||
} | ||
} // overridden in implementations | ||
/* istanbul ignore next */ | ||
}, { | ||
@@ -194,3 +181,3 @@ key: "toJSON", | ||
if (inFlow && i < _this2.items.length - 1) str += ','; | ||
str = (0, _addComment.default)(str, itemIndent, comment); | ||
str = addComment(str, itemIndent, comment); | ||
if (chompKeep && (comment || inFlow)) chompKeep = false; | ||
@@ -283,6 +270,8 @@ nodes.push({ | ||
}]); | ||
return Collection; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = Collection; | ||
(0, _defineProperty2.default)(Collection, "maxFlowStringSingleLineLength", 60); | ||
_defineProperty(Collection, "maxFlowStringSingleLineLength", 60); | ||
export { Collection as default }; |
@@ -1,43 +0,20 @@ | ||
"use strict"; | ||
import _typeof from "@babel/runtime/helpers/typeof"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import { warnOptionDeprecation } from '../warnings'; | ||
import { Type } from '../constants'; | ||
import { YAMLReferenceError, YAMLWarning } from '../errors'; | ||
import { stringifyString } from '../stringify'; | ||
import { schemas, tags } from '../tags'; | ||
import { resolveString } from '../tags/failsafe/string'; | ||
import Alias from './Alias'; | ||
import Collection from './Collection'; | ||
import Node from './Node'; | ||
import Pair from './Pair'; | ||
import Scalar from './Scalar'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _warnings = require("../warnings"); | ||
var _constants = require("../constants"); | ||
var _errors = require("../errors"); | ||
var _stringify = require("../stringify"); | ||
var _tags = require("../tags"); | ||
var _string = require("../tags/failsafe/string"); | ||
var _Alias = _interopRequireDefault(require("./Alias")); | ||
var _Collection = _interopRequireDefault(require("./Collection")); | ||
var _Node = _interopRequireDefault(require("./Node")); | ||
var _Pair = _interopRequireDefault(require("./Pair")); | ||
var _Scalar = _interopRequireDefault(require("./Scalar")); | ||
var isMap = function isMap(_ref) { | ||
var type = _ref.type; | ||
return type === _constants.Type.FLOW_MAP || type === _constants.Type.MAP; | ||
return type === Type.FLOW_MAP || type === Type.MAP; | ||
}; | ||
@@ -47,8 +24,6 @@ | ||
var type = _ref2.type; | ||
return type === _constants.Type.FLOW_SEQ || type === _constants.Type.SEQ; | ||
return type === Type.FLOW_SEQ || type === Type.SEQ; | ||
}; | ||
var Schema = | ||
/*#__PURE__*/ | ||
function () { | ||
var Schema = /*#__PURE__*/function () { | ||
function Schema(_ref3) { | ||
@@ -58,10 +33,16 @@ var customTags = _ref3.customTags, | ||
schema = _ref3.schema, | ||
sortMapEntries = _ref3.sortMapEntries, | ||
deprecatedCustomTags = _ref3.tags; | ||
(0, _classCallCheck2.default)(this, Schema); | ||
_classCallCheck(this, Schema); | ||
this.merge = !!merge; | ||
this.name = schema; | ||
this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11' | ||
this.sortMapEntries = sortMapEntries === true ? function (a, b) { | ||
return a.key < b.key ? -1 : a.key > b.key ? 1 : 0; | ||
} : sortMapEntries || null; | ||
this.tags = schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11' | ||
if (!this.tags) { | ||
var keys = Object.keys(_tags.schemas).map(function (key) { | ||
var keys = Object.keys(schemas).map(function (key) { | ||
return JSON.stringify(key); | ||
@@ -74,3 +55,3 @@ }).join(', '); | ||
customTags = deprecatedCustomTags; | ||
(0, _warnings.warnOptionDeprecation)('tags', 'customTags'); | ||
warnOptionDeprecation('tags', 'customTags'); | ||
} | ||
@@ -110,6 +91,6 @@ | ||
if (typeof _tag === 'string') { | ||
var tagObj = _tags.tags[_tag]; | ||
var tagObj = tags[_tag]; | ||
if (!tagObj) { | ||
var _keys = Object.keys(_tags.tags).map(function (key) { | ||
var _keys = Object.keys(tags).map(function (key) { | ||
return JSON.stringify(key); | ||
@@ -126,6 +107,6 @@ }).join(', '); | ||
(0, _createClass2.default)(Schema, [{ | ||
_createClass(Schema, [{ | ||
key: "createNode", | ||
value: function createNode(value, wrapScalars, tag, ctx) { | ||
if (value instanceof _Node.default) return value; | ||
if (value instanceof Node) return value; | ||
var tagObj; | ||
@@ -150,4 +131,4 @@ | ||
if (typeof value.toJSON === 'function') value = value.toJSON(); | ||
if ((0, _typeof2.default)(value) !== 'object') return wrapScalars ? new _Scalar.default(value) : value; | ||
tagObj = value instanceof Map ? _tags.tags.map : value[Symbol.iterator] ? _tags.tags.seq : _tags.tags.map; | ||
if (_typeof(value) !== 'object') return wrapScalars ? new Scalar(value) : value; | ||
tagObj = value instanceof Map ? tags.map : value[Symbol.iterator] ? tags.seq : tags.map; | ||
} | ||
@@ -167,9 +148,7 @@ } | ||
if (value && (0, _typeof2.default)(value) === 'object' && ctx.prevObjects) { | ||
var prev = ctx.prevObjects.find(function (o) { | ||
return o.value === value; | ||
}); | ||
if (value && _typeof(value) === 'object' && ctx.prevObjects) { | ||
var prev = ctx.prevObjects.get(value); | ||
if (prev) { | ||
var alias = new _Alias.default(prev); // leaves source dirty; must be cleaned by caller | ||
var alias = new Alias(prev); // leaves source dirty; must be cleaned by caller | ||
@@ -181,6 +160,7 @@ ctx.aliasNodes.push(alias); | ||
obj.value = value; | ||
ctx.prevObjects.push(obj); | ||
ctx.prevObjects.set(value, obj); | ||
} | ||
obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value; | ||
obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new Scalar(value) : value; | ||
if (tag && obj.node instanceof Node) obj.node.tag = tag; | ||
return obj.node; | ||
@@ -193,3 +173,3 @@ } | ||
var v = this.createNode(value, ctx.wrapScalars, null, ctx); | ||
return new _Pair.default(k, v); | ||
return new Pair(k, v); | ||
} // falls back to string on no match | ||
@@ -213,3 +193,3 @@ | ||
var res = resolve.apply(null, match); | ||
if (!(res instanceof _Scalar.default)) res = new _Scalar.default(res); | ||
if (!(res instanceof Scalar)) res = new Scalar(res); | ||
if (format) res.format = format; | ||
@@ -222,3 +202,3 @@ return res; | ||
if (this.tags.scalarFallback) str = this.tags.scalarFallback(str); | ||
return new _Scalar.default(str); | ||
return new Scalar(str); | ||
} // sets node.resolved on success | ||
@@ -242,6 +222,6 @@ | ||
var res = generic.resolve(doc, node); | ||
if (!(res instanceof _Collection.default)) res = new _Scalar.default(res); | ||
if (!(res instanceof Collection)) res = new Scalar(res); | ||
node.resolved = res; | ||
} else { | ||
var str = (0, _string.resolveString)(doc, node); | ||
var str = resolveString(doc, node); | ||
@@ -253,2 +233,3 @@ if (typeof str === 'string' && tags.length > 0) { | ||
} catch (error) { | ||
/* istanbul ignore if */ | ||
if (!error.source) error.source = node; | ||
@@ -269,5 +250,6 @@ doc.errors.push(error); | ||
var fallback = isMap(node) ? Schema.defaultTags.MAP : isSeq(node) ? Schema.defaultTags.SEQ : Schema.defaultTags.STR; | ||
/* istanbul ignore else */ | ||
if (fallback) { | ||
doc.warnings.push(new _errors.YAMLWarning(node, "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback))); | ||
doc.warnings.push(new YAMLWarning(node, "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback))); | ||
@@ -279,6 +261,5 @@ var _res = this.resolveNode(doc, node, fallback); | ||
} else { | ||
doc.errors.push(new _errors.YAMLReferenceError(node, "The tag ".concat(tagName, " is unavailable"))); | ||
doc.errors.push(new YAMLReferenceError(node, "The tag ".concat(tagName, " is unavailable"))); | ||
return null; | ||
} | ||
return null; | ||
} | ||
@@ -288,3 +269,3 @@ }, { | ||
value: function getTagObject(item) { | ||
if (item instanceof _Alias.default) return _Alias.default; | ||
if (item instanceof Alias) return Alias; | ||
@@ -302,3 +283,3 @@ if (item.tag) { | ||
if (item instanceof _Scalar.default) { | ||
if (item instanceof Scalar) { | ||
obj = item.value; // TODO: deprecate/remove class check | ||
@@ -323,3 +304,3 @@ | ||
if (!tagObj) { | ||
var name = obj && obj.constructor ? obj.constructor.name : (0, _typeof2.default)(obj); | ||
var name = obj && obj.constructor ? obj.constructor.name : _typeof(obj); | ||
throw new Error("Tag not resolved for ".concat(name, " value")); | ||
@@ -357,3 +338,3 @@ } | ||
if (!(item instanceof _Node.default)) { | ||
if (!(item instanceof Node)) { | ||
var createCtx = { | ||
@@ -364,3 +345,3 @@ aliasNodes: [], | ||
}, | ||
prevObjects: [] | ||
prevObjects: new Map() | ||
}; | ||
@@ -401,18 +382,22 @@ item = this.createNode(item, true, null, createCtx); | ||
ctx.tags = this; | ||
if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep); | ||
if (item instanceof Pair) return item.toString(ctx, onComment, onChompKeep); | ||
if (!tagObj) tagObj = this.getTagObject(item); | ||
var props = this.stringifyProps(item, tagObj, ctx); | ||
var str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof _Collection.default ? item.toString(ctx, onComment, onChompKeep) : (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep); | ||
return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? "".concat(props, "\n").concat(ctx.indent).concat(str) : "".concat(props, " ").concat(str) : str; | ||
if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1; | ||
var str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof Collection ? item.toString(ctx, onComment, onChompKeep) : stringifyString(item, ctx, onComment, onChompKeep); | ||
return props ? item instanceof Collection && str[0] !== '{' && str[0] !== '[' ? "".concat(props, "\n").concat(ctx.indent).concat(str) : "".concat(props, " ").concat(str) : str; | ||
} | ||
}]); | ||
return Schema; | ||
}(); | ||
exports.default = Schema; | ||
(0, _defineProperty2.default)(Schema, "defaultPrefix", 'tag:yaml.org,2002:'); | ||
(0, _defineProperty2.default)(Schema, "defaultTags", { | ||
_defineProperty(Schema, "defaultPrefix", 'tag:yaml.org,2002:'); | ||
_defineProperty(Schema, "defaultTags", { | ||
MAP: 'tag:yaml.org,2002:map', | ||
SEQ: 'tag:yaml.org,2002:seq', | ||
STR: 'tag:yaml.org,2002:str' | ||
}); | ||
}); | ||
export { Schema as default }; |
@@ -1,31 +0,12 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.findPair = findPair; | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _Collection2 = _interopRequireDefault(require("./Collection")); | ||
var _Pair = _interopRequireDefault(require("./Pair")); | ||
var _Scalar = _interopRequireDefault(require("./Scalar")); | ||
function findPair(items, key) { | ||
var k = key instanceof _Scalar.default ? key.value : key; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _get from "@babel/runtime/helpers/get"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import Collection from './Collection'; | ||
import Pair from './Pair'; | ||
import Scalar from './Scalar'; | ||
export function findPair(items, key) { | ||
var k = key instanceof Scalar ? key.value : key; | ||
var _iteratorNormalCompletion = true; | ||
@@ -39,3 +20,3 @@ var _didIteratorError = false; | ||
if (it instanceof _Pair.default) { | ||
if (it instanceof Pair) { | ||
if (it.key === key || it.key === k) return it; | ||
@@ -63,19 +44,28 @@ if (it.key && it.key.value === k) return it; | ||
var YAMLMap = | ||
/*#__PURE__*/ | ||
function (_Collection) { | ||
(0, _inherits2.default)(YAMLMap, _Collection); | ||
var YAMLMap = /*#__PURE__*/function (_Collection) { | ||
_inherits(YAMLMap, _Collection); | ||
function YAMLMap() { | ||
(0, _classCallCheck2.default)(this, YAMLMap); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLMap).apply(this, arguments)); | ||
_classCallCheck(this, YAMLMap); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(YAMLMap).apply(this, arguments)); | ||
} | ||
(0, _createClass2.default)(YAMLMap, [{ | ||
_createClass(YAMLMap, [{ | ||
key: "add", | ||
value: function add(pair) { | ||
if (!pair) pair = new _Pair.default(pair);else if (!(pair instanceof _Pair.default)) pair = new _Pair.default(pair.key || pair, pair.value); | ||
value: function add(pair, overwrite) { | ||
if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value); | ||
var prev = findPair(this.items, pair.key); | ||
if (prev) throw new Error("Key ".concat(pair.key, " already set")); | ||
this.items.push(pair); | ||
var sortEntries = this.schema && this.schema.sortMapEntries; | ||
if (prev) { | ||
if (overwrite) prev.value = pair.value;else throw new Error("Key ".concat(pair.key, " already set")); | ||
} else if (sortEntries) { | ||
var i = this.items.findIndex(function (item) { | ||
return sortEntries(pair, item) < 0; | ||
}); | ||
if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair); | ||
} else { | ||
this.items.push(pair); | ||
} | ||
} | ||
@@ -95,3 +85,3 @@ }, { | ||
var node = it && it.value; | ||
return !keepScalar && node instanceof _Scalar.default ? node.value : node; | ||
return !keepScalar && node instanceof Scalar ? node.value : node; | ||
} | ||
@@ -106,4 +96,3 @@ }, { | ||
value: function set(key, value) { | ||
var prev = findPair(this.items, key); | ||
if (prev) prev.value = value;else this.items.push(new _Pair.default(key, value)); | ||
this.add(new Pair(key, value), true); | ||
} | ||
@@ -159,3 +148,3 @@ /** | ||
var item = _step3.value; | ||
if (!(item instanceof _Pair.default)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead")); | ||
if (!(item instanceof Pair)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead")); | ||
} | ||
@@ -177,3 +166,3 @@ } catch (err) { | ||
return (0, _get2.default)((0, _getPrototypeOf2.default)(YAMLMap.prototype), "toString", this).call(this, ctx, { | ||
return _get(_getPrototypeOf(YAMLMap.prototype), "toString", this).call(this, ctx, { | ||
blockItem: function blockItem(n) { | ||
@@ -191,5 +180,6 @@ return n.str; | ||
}]); | ||
return YAMLMap; | ||
}(_Collection2.default); | ||
}(Collection); | ||
exports.default = YAMLMap; | ||
export { YAMLMap as default }; |
@@ -1,50 +0,27 @@ | ||
"use strict"; | ||
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _get from "@babel/runtime/helpers/get"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import YAMLMap from './Map'; | ||
import Pair from './Pair'; | ||
import Scalar from './Scalar'; | ||
import Seq from './Seq'; | ||
export var MERGE_KEY = '<<'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var Merge = /*#__PURE__*/function (_Pair) { | ||
_inherits(Merge, _Pair); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.MERGE_KEY = void 0; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _Map = _interopRequireDefault(require("./Map")); | ||
var _Pair2 = _interopRequireDefault(require("./Pair")); | ||
var _Scalar = _interopRequireDefault(require("./Scalar")); | ||
var _Seq = _interopRequireDefault(require("./Seq")); | ||
var MERGE_KEY = '<<'; | ||
exports.MERGE_KEY = MERGE_KEY; | ||
var Merge = | ||
/*#__PURE__*/ | ||
function (_Pair) { | ||
(0, _inherits2.default)(Merge, _Pair); | ||
function Merge(pair) { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, Merge); | ||
_classCallCheck(this, Merge); | ||
if (pair instanceof _Pair2.default) { | ||
if (pair instanceof Pair) { | ||
var seq = pair.value; | ||
if (!(seq instanceof _Seq.default)) { | ||
seq = new _Seq.default(); | ||
if (!(seq instanceof Seq)) { | ||
seq = new Seq(); | ||
seq.items.push(pair.value); | ||
@@ -54,10 +31,10 @@ seq.range = pair.value.range; | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Merge).call(this, pair.key, seq)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Merge).call(this, pair.key, seq)); | ||
_this.range = pair.range; | ||
} else { | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Merge).call(this, new _Scalar.default(MERGE_KEY), new _Seq.default())); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Merge).call(this, new Scalar(MERGE_KEY), new Seq())); | ||
} | ||
_this.type = 'MERGE_PAIR'; | ||
return (0, _possibleConstructorReturn2.default)(_this); | ||
return _possibleConstructorReturn(_this); | ||
} // If the value associated with a merge key is a single mapping node, each of | ||
@@ -72,3 +49,3 @@ // its key/value pairs is inserted into the current mapping, unless the key | ||
(0, _createClass2.default)(Merge, [{ | ||
_createClass(Merge, [{ | ||
key: "addToJSMap", | ||
@@ -83,3 +60,3 @@ value: function addToJSMap(ctx, map) { | ||
var source = _step.value.source; | ||
if (!(source instanceof _Map.default)) throw new Error('Merge sources must be maps'); | ||
if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps'); | ||
var srcMap = source.toJSON(null, ctx, Map); | ||
@@ -92,3 +69,3 @@ var _iteratorNormalCompletion2 = true; | ||
for (var _iterator2 = srcMap[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2), | ||
var _step2$value = _slicedToArray(_step2.value, 2), | ||
key = _step2$value[0], | ||
@@ -141,5 +118,7 @@ value = _step2$value[1]; | ||
var seq = this.value; | ||
if (seq.items.length > 1) return (0, _get2.default)((0, _getPrototypeOf2.default)(Merge.prototype), "toString", this).call(this, ctx, onComment); | ||
if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment); | ||
this.value = seq.items[0]; | ||
var str = (0, _get2.default)((0, _getPrototypeOf2.default)(Merge.prototype), "toString", this).call(this, ctx, onComment); | ||
var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment); | ||
this.value = seq; | ||
@@ -149,5 +128,6 @@ return str; | ||
}]); | ||
return Merge; | ||
}(_Pair2.default); | ||
}(Pair); | ||
exports.default = Merge; | ||
export { Merge as default }; |
@@ -1,16 +0,7 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var Node = function Node() { | ||
(0, _classCallCheck2.default)(this, Node); | ||
_classCallCheck(this, Node); | ||
}; | ||
exports.default = Node; | ||
export { Node as default }; |
@@ -1,39 +0,19 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import _typeof from "@babel/runtime/helpers/typeof"; | ||
// Published as 'yaml/pair' | ||
import addComment from '../addComment'; | ||
import { Type } from '../constants'; | ||
import toJSON from '../toJSON'; | ||
import Collection from './Collection'; | ||
import Node from './Node'; | ||
import Scalar from './Scalar'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _addComment = _interopRequireDefault(require("../addComment")); | ||
var _constants = require("../constants"); | ||
var _toJSON = _interopRequireDefault(require("../toJSON")); | ||
var _Collection = _interopRequireDefault(require("./Collection")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Scalar = _interopRequireDefault(require("./Scalar")); | ||
// Published as 'yaml/pair' | ||
var stringifyKey = function stringifyKey(key, jsKey, ctx) { | ||
if (jsKey === null) return ''; | ||
if ((0, _typeof2.default)(jsKey) !== 'object') return String(jsKey); | ||
if (key instanceof _Node2.default && ctx && ctx.doc) return key.toString({ | ||
if (_typeof(jsKey) !== 'object') return String(jsKey); | ||
if (key instanceof Node && ctx && ctx.doc) return key.toString({ | ||
anchors: {}, | ||
@@ -48,6 +28,4 @@ doc: ctx.doc, | ||
var Pair = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(Pair, _Node); | ||
var Pair = /*#__PURE__*/function (_Node) { | ||
_inherits(Pair, _Node); | ||
@@ -58,4 +36,6 @@ function Pair(key) { | ||
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
(0, _classCallCheck2.default)(this, Pair); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Pair).call(this)); | ||
_classCallCheck(this, Pair); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Pair).call(this)); | ||
_this.key = key; | ||
@@ -67,9 +47,9 @@ _this.value = value; | ||
(0, _createClass2.default)(Pair, [{ | ||
_createClass(Pair, [{ | ||
key: "addToJSMap", | ||
value: function addToJSMap(ctx, map) { | ||
var key = (0, _toJSON.default)(this.key, '', ctx); | ||
var key = toJSON(this.key, '', ctx); | ||
if (map instanceof Map) { | ||
var value = (0, _toJSON.default)(this.value, key, ctx); | ||
var value = toJSON(this.value, key, ctx); | ||
map.set(key, value); | ||
@@ -80,3 +60,3 @@ } else if (map instanceof Set) { | ||
var stringKey = stringifyKey(this.key, key, ctx); | ||
map[stringKey] = (0, _toJSON.default)(this.value, stringKey, ctx); | ||
map[stringKey] = toJSON(this.value, stringKey, ctx); | ||
} | ||
@@ -99,3 +79,3 @@ | ||
value = this.value; | ||
var keyComment = key instanceof _Node2.default && key.comment; | ||
var keyComment = key instanceof Node && key.comment; | ||
@@ -107,3 +87,3 @@ if (simpleKeys) { | ||
if (key instanceof _Collection.default) { | ||
if (key instanceof Collection) { | ||
var msg = 'With simple keys, collection cannot be used as a key value'; | ||
@@ -114,3 +94,3 @@ throw new Error(msg); | ||
var explicitKey = !simpleKeys && (!key || keyComment || key instanceof _Collection.default || key.type === _constants.Type.BLOCK_FOLDED || key.type === _constants.Type.BLOCK_LITERAL); | ||
var explicitKey = !simpleKeys && (!key || keyComment || key instanceof Collection || key.type === Type.BLOCK_FOLDED || key.type === Type.BLOCK_LITERAL); | ||
var _ctx = ctx, | ||
@@ -129,7 +109,7 @@ doc = _ctx.doc, | ||
}); | ||
str = (0, _addComment.default)(str, ctx.indent, keyComment); | ||
str = addComment(str, ctx.indent, keyComment); | ||
if (ctx.allNullValues && !simpleKeys) { | ||
if (this.comment) { | ||
str = (0, _addComment.default)(str, ctx.indent, this.comment); | ||
str = addComment(str, ctx.indent, this.comment); | ||
if (onComment) onComment(); | ||
@@ -145,3 +125,3 @@ } else if (chompKeep && !keyComment && onChompKeep) onChompKeep(); | ||
// expected (but not strictly required) to be a single-line comment | ||
str = (0, _addComment.default)(str, ctx.indent, this.comment); | ||
str = addComment(str, ctx.indent, this.comment); | ||
if (onComment) onComment(); | ||
@@ -153,3 +133,3 @@ } | ||
if (value instanceof _Node2.default) { | ||
if (value instanceof Node) { | ||
if (value.spaceBefore) vcb = '\n'; | ||
@@ -163,3 +143,3 @@ | ||
valueComment = value.comment; | ||
} else if (value && (0, _typeof2.default)(value) === 'object') { | ||
} else if (value && _typeof(value) === 'object') { | ||
value = doc.schema.createNode(value, true); | ||
@@ -169,2 +149,3 @@ } | ||
ctx.implicitKey = false; | ||
if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1; | ||
chompKeep = false; | ||
@@ -180,3 +161,3 @@ var valueStr = doc.schema.stringify(value, ctx, function () { | ||
ws = "".concat(vcb, "\n").concat(ctx.indent); | ||
} else if (!explicitKey && value instanceof _Collection.default) { | ||
} else if (!explicitKey && value instanceof Collection) { | ||
var flow = valueStr[0] === '[' || valueStr[0] === '{'; | ||
@@ -187,3 +168,3 @@ if (!flow || valueStr.includes('\n')) ws = "\n".concat(ctx.indent); | ||
if (chompKeep && !valueComment && onChompKeep) onChompKeep(); | ||
return (0, _addComment.default)(str + ws + valueStr, ctx.indent, valueComment); | ||
return addComment(str + ws + valueStr, ctx.indent, valueComment); | ||
} | ||
@@ -196,9 +177,10 @@ }, { | ||
set: function set(cb) { | ||
if (this.key == null) this.key = new _Scalar.default(null); | ||
if (this.key == null) this.key = new Scalar(null); | ||
this.key.commentBefore = cb; | ||
} | ||
}]); | ||
return Pair; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = Pair; | ||
export { Pair as default }; |
@@ -1,44 +0,24 @@ | ||
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = parseMap; | ||
var _constants = require("../constants"); | ||
var _PlainValue = _interopRequireDefault(require("../cst/PlainValue")); | ||
var _errors = require("../errors"); | ||
var _Map = _interopRequireDefault(require("./Map")); | ||
var _Merge = _interopRequireWildcard(require("./Merge")); | ||
var _Pair = _interopRequireDefault(require("./Pair")); | ||
var _parseUtils = require("./parseUtils"); | ||
var _Alias = _interopRequireDefault(require("./Alias")); | ||
var _Collection = _interopRequireDefault(require("./Collection")); | ||
function parseMap(doc, cst) { | ||
if (cst.type !== _constants.Type.MAP && cst.type !== _constants.Type.FLOW_MAP) { | ||
import { Char, Type } from '../constants'; | ||
import PlainValue from '../cst/PlainValue'; | ||
import { YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from '../errors'; | ||
import Map from './Map'; | ||
import Merge, { MERGE_KEY } from './Merge'; | ||
import Pair from './Pair'; | ||
import { checkFlowCollectionEnd, checkKeyLength, resolveComments } from './parseUtils'; | ||
import Alias from './Alias'; | ||
import Collection from './Collection'; | ||
export default function parseMap(doc, cst) { | ||
if (cst.type !== Type.MAP && cst.type !== Type.FLOW_MAP) { | ||
var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping"); | ||
doc.errors.push(new _errors.YAMLSyntaxError(cst, msg)); | ||
doc.errors.push(new YAMLSyntaxError(cst, msg)); | ||
return null; | ||
} | ||
var _ref = cst.type === _constants.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst), | ||
var _ref = cst.type === Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst), | ||
comments = _ref.comments, | ||
items = _ref.items; | ||
var map = new _Map.default(); | ||
var map = new Map(); | ||
map.items = items; | ||
(0, _parseUtils.resolveComments)(map, comments); | ||
resolveComments(map, comments); | ||
var hasCollectionKey = false; | ||
@@ -48,14 +28,14 @@ | ||
var iKey = items[i].key; | ||
if (iKey instanceof _Collection.default) hasCollectionKey = true; | ||
if (iKey instanceof Collection) hasCollectionKey = true; | ||
if (doc.schema.merge && iKey && iKey.value === _Merge.MERGE_KEY) { | ||
items[i] = new _Merge.default(items[i]); | ||
if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) { | ||
items[i] = new Merge(items[i]); | ||
var sources = items[i].value.items; | ||
var error = null; | ||
sources.some(function (node) { | ||
if (node instanceof _Alias.default) { | ||
if (node instanceof Alias) { | ||
// During parsing, alias sources are CST nodes; to account for | ||
// circular references their resolved values can't be used here. | ||
var type = node.source.type; | ||
if (type === _constants.Type.MAP || type === _constants.Type.FLOW_MAP) return false; | ||
if (type === Type.MAP || type === Type.FLOW_MAP) return false; | ||
return error = 'Merge nodes aliases can only point to maps'; | ||
@@ -66,3 +46,3 @@ } | ||
}); | ||
if (error) doc.errors.push(new _errors.YAMLSemanticError(cst, error)); | ||
if (error) doc.errors.push(new YAMLSemanticError(cst, error)); | ||
} else { | ||
@@ -75,3 +55,3 @@ for (var j = i + 1; j < items.length; ++j) { | ||
doc.errors.push(new _errors.YAMLSemanticError(cst, _msg)); | ||
doc.errors.push(new YAMLSemanticError(cst, _msg)); | ||
break; | ||
@@ -85,3 +65,3 @@ } | ||
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.'; | ||
doc.warnings.push(new _errors.YAMLWarning(cst, warn)); | ||
doc.warnings.push(new YAMLWarning(cst, warn)); | ||
} | ||
@@ -102,3 +82,3 @@ | ||
if (node && start > node.valueRange.start) return false; | ||
if (src[start] !== _constants.Char.COMMENT) return false; | ||
if (src[start] !== Char.COMMENT) return false; | ||
@@ -114,3 +94,3 @@ for (var i = lineStart; i < start; ++i) { | ||
if (!valueHasPairComment(item)) return; | ||
var comment = item.getPropValue(0, _constants.Char.COMMENT, true); | ||
var comment = item.getPropValue(0, Char.COMMENT, true); | ||
var found = false; | ||
@@ -144,3 +124,3 @@ var cb = pair.value.commentBefore; | ||
switch (item.type) { | ||
case _constants.Type.BLANK_LINE: | ||
case Type.BLANK_LINE: | ||
comments.push({ | ||
@@ -152,3 +132,3 @@ afterKey: !!key, | ||
case _constants.Type.COMMENT: | ||
case Type.COMMENT: | ||
comments.push({ | ||
@@ -161,4 +141,4 @@ afterKey: !!key, | ||
case _constants.Type.MAP_KEY: | ||
if (key !== undefined) items.push(new _Pair.default(key)); | ||
case Type.MAP_KEY: | ||
if (key !== undefined) items.push(new Pair(key)); | ||
if (item.error) doc.errors.push(item.error); | ||
@@ -169,3 +149,3 @@ key = doc.resolveNode(item.node); | ||
case _constants.Type.MAP_VALUE: | ||
case Type.MAP_VALUE: | ||
{ | ||
@@ -175,5 +155,5 @@ if (key === undefined) key = null; | ||
if (!item.context.atLineStart && item.node && item.node.type === _constants.Type.MAP && !item.node.context.atLineStart) { | ||
if (!item.context.atLineStart && item.node && item.node.type === Type.MAP && !item.node.context.atLineStart) { | ||
var msg = 'Nested mappings are not allowed in compact mappings'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item.node, msg)); | ||
doc.errors.push(new YAMLSemanticError(item.node, msg)); | ||
} | ||
@@ -187,3 +167,3 @@ | ||
// missing `item.node`. -- eemeli/yaml#19 | ||
valueNode = new _PlainValue.default(_constants.Type.PLAIN, []); | ||
valueNode = new PlainValue(Type.PLAIN, []); | ||
valueNode.context = { | ||
@@ -210,6 +190,6 @@ parent: item, | ||
var pair = new _Pair.default(key, doc.resolveNode(valueNode)); | ||
var pair = new Pair(key, doc.resolveNode(valueNode)); | ||
resolvePairComment(item, pair); | ||
items.push(pair); | ||
(0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart); | ||
checkKeyLength(doc.errors, cst, i, key, keyStart); | ||
key = undefined; | ||
@@ -221,3 +201,3 @@ keyStart = null; | ||
default: | ||
if (key !== undefined) items.push(new _Pair.default(key)); | ||
if (key !== undefined) items.push(new Pair(key)); | ||
key = doc.resolveNode(item); | ||
@@ -231,11 +211,11 @@ keyStart = item.range.start; | ||
switch (nextItem && nextItem.type) { | ||
case _constants.Type.BLANK_LINE: | ||
case _constants.Type.COMMENT: | ||
case Type.BLANK_LINE: | ||
case Type.COMMENT: | ||
continue next; | ||
case _constants.Type.MAP_VALUE: | ||
case Type.MAP_VALUE: | ||
break next; | ||
default: | ||
doc.errors.push(new _errors.YAMLSemanticError(item, 'Implicit map keys need to be followed by map values')); | ||
doc.errors.push(new YAMLSemanticError(item, 'Implicit map keys need to be followed by map values')); | ||
break next; | ||
@@ -247,3 +227,3 @@ } | ||
var _msg2 = 'Implicit map keys need to be on a single line'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item, _msg2)); | ||
doc.errors.push(new YAMLSemanticError(item, _msg2)); | ||
} | ||
@@ -254,3 +234,3 @@ | ||
if (key !== undefined) items.push(new _Pair.default(key)); | ||
if (key !== undefined) items.push(new Pair(key)); | ||
return { | ||
@@ -271,3 +251,3 @@ comments: comments, | ||
for (var i = 0; i < cst.items.length; ++i) { | ||
(0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart); | ||
checkKeyLength(doc.errors, cst, i, key, keyStart); | ||
var item = cst.items[i]; | ||
@@ -299,3 +279,3 @@ | ||
if (key !== undefined) { | ||
items.push(new _Pair.default(key)); | ||
items.push(new Pair(key)); | ||
key = undefined; | ||
@@ -319,6 +299,6 @@ keyStart = null; | ||
var msg = "Flow map contains an unexpected ".concat(char); | ||
var err = new _errors.YAMLSyntaxError(cst, msg); | ||
var err = new YAMLSyntaxError(cst, msg); | ||
err.offset = offset; | ||
doc.errors.push(err); | ||
} else if (item.type === _constants.Type.BLANK_LINE) { | ||
} else if (item.type === Type.BLANK_LINE) { | ||
comments.push({ | ||
@@ -328,3 +308,3 @@ afterKey: !!key, | ||
}); | ||
} else if (item.type === _constants.Type.COMMENT) { | ||
} else if (item.type === Type.COMMENT) { | ||
comments.push({ | ||
@@ -336,8 +316,8 @@ afterKey: !!key, | ||
} else if (key === undefined) { | ||
if (next === ',') doc.errors.push(new _errors.YAMLSemanticError(item, 'Separator , missing in flow map')); | ||
if (next === ',') doc.errors.push(new YAMLSemanticError(item, 'Separator , missing in flow map')); | ||
key = doc.resolveNode(item); | ||
keyStart = explicitKey ? null : item.range.start; // TODO: add error for non-explicit multiline plain key | ||
} else { | ||
if (next !== ',') doc.errors.push(new _errors.YAMLSemanticError(item, 'Indicator : missing in flow map entry')); | ||
items.push(new _Pair.default(key, doc.resolveNode(item))); | ||
if (next !== ',') doc.errors.push(new YAMLSemanticError(item, 'Indicator : missing in flow map entry')); | ||
items.push(new Pair(key, doc.resolveNode(item))); | ||
key = undefined; | ||
@@ -348,4 +328,4 @@ explicitKey = false; | ||
(0, _parseUtils.checkFlowCollectionEnd)(doc.errors, cst); | ||
if (key !== undefined) items.push(new _Pair.default(key)); | ||
checkFlowCollectionEnd(doc.errors, cst); | ||
if (key !== undefined) items.push(new Pair(key)); | ||
return { | ||
@@ -352,0 +332,0 @@ comments: comments, |
@@ -1,42 +0,27 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = parseSeq; | ||
var _constants = require("../constants"); | ||
var _errors = require("../errors"); | ||
var _Pair = _interopRequireDefault(require("./Pair")); | ||
var _parseUtils = require("./parseUtils"); | ||
var _Seq = _interopRequireDefault(require("./Seq")); | ||
var _Collection = _interopRequireDefault(require("./Collection")); | ||
function parseSeq(doc, cst) { | ||
if (cst.type !== _constants.Type.SEQ && cst.type !== _constants.Type.FLOW_SEQ) { | ||
import { Type } from '../constants'; | ||
import { YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from '../errors'; | ||
import Pair from './Pair'; | ||
import { checkFlowCollectionEnd, checkKeyLength, resolveComments } from './parseUtils'; | ||
import Seq from './Seq'; | ||
import Collection from './Collection'; | ||
export default function parseSeq(doc, cst) { | ||
if (cst.type !== Type.SEQ && cst.type !== Type.FLOW_SEQ) { | ||
var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence"); | ||
doc.errors.push(new _errors.YAMLSyntaxError(cst, msg)); | ||
doc.errors.push(new YAMLSyntaxError(cst, msg)); | ||
return null; | ||
} | ||
var _ref = cst.type === _constants.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst), | ||
var _ref = cst.type === Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst), | ||
comments = _ref.comments, | ||
items = _ref.items; | ||
var seq = new _Seq.default(); | ||
var seq = new Seq(); | ||
seq.items = items; | ||
(0, _parseUtils.resolveComments)(seq, comments); | ||
resolveComments(seq, comments); | ||
if (!doc.options.mapAsMap && items.some(function (it) { | ||
return it instanceof _Pair.default && it.key instanceof _Collection.default; | ||
return it instanceof Pair && it.key instanceof Collection; | ||
})) { | ||
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.'; | ||
doc.warnings.push(new _errors.YAMLWarning(cst, warn)); | ||
doc.warnings.push(new YAMLWarning(cst, warn)); | ||
} | ||
@@ -56,3 +41,3 @@ | ||
switch (item.type) { | ||
case _constants.Type.BLANK_LINE: | ||
case Type.BLANK_LINE: | ||
comments.push({ | ||
@@ -63,3 +48,3 @@ before: items.length | ||
case _constants.Type.COMMENT: | ||
case Type.COMMENT: | ||
comments.push({ | ||
@@ -71,3 +56,3 @@ comment: item.comment, | ||
case _constants.Type.SEQ_ITEM: | ||
case Type.SEQ_ITEM: | ||
if (item.error) doc.errors.push(item.error); | ||
@@ -78,3 +63,3 @@ items.push(doc.resolveNode(item.node)); | ||
var msg = 'Sequence items cannot have tags or anchors before the - indicator'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item, msg)); | ||
doc.errors.push(new YAMLSemanticError(item, msg)); | ||
} | ||
@@ -86,3 +71,3 @@ | ||
if (item.error) doc.errors.push(item.error); | ||
doc.errors.push(new _errors.YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence"))); | ||
doc.errors.push(new YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence"))); | ||
} | ||
@@ -114,3 +99,3 @@ } | ||
if (explicitKey && key === undefined) key = next ? items.pop() : null; | ||
items.push(new _Pair.default(key)); | ||
items.push(new Pair(key)); | ||
explicitKey = false; | ||
@@ -129,5 +114,5 @@ key = undefined; | ||
if (key instanceof _Pair.default) { | ||
if (key instanceof Pair) { | ||
var msg = 'Chaining flow sequence pairs is invalid'; | ||
var err = new _errors.YAMLSemanticError(cst, msg); | ||
var err = new YAMLSemanticError(cst, msg); | ||
err.offset = offset; | ||
@@ -137,3 +122,3 @@ doc.errors.push(err); | ||
if (!explicitKey) (0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart); | ||
if (!explicitKey) checkKeyLength(doc.errors, cst, i, key, keyStart); | ||
} else { | ||
@@ -150,3 +135,3 @@ key = null; | ||
var _err = new _errors.YAMLSyntaxError(cst, _msg); | ||
var _err = new YAMLSyntaxError(cst, _msg); | ||
@@ -156,7 +141,7 @@ _err.offset = offset; | ||
} | ||
} else if (item.type === _constants.Type.BLANK_LINE) { | ||
} else if (item.type === Type.BLANK_LINE) { | ||
comments.push({ | ||
before: items.length | ||
}); | ||
} else if (item.type === _constants.Type.COMMENT) { | ||
} else if (item.type === Type.COMMENT) { | ||
comments.push({ | ||
@@ -170,3 +155,3 @@ comment: item.comment, | ||
doc.errors.push(new _errors.YAMLSemanticError(item, _msg2)); | ||
doc.errors.push(new YAMLSemanticError(item, _msg2)); | ||
} | ||
@@ -179,3 +164,3 @@ | ||
} else { | ||
items.push(new _Pair.default(key, value)); | ||
items.push(new Pair(key, value)); | ||
key = undefined; | ||
@@ -189,4 +174,4 @@ } | ||
(0, _parseUtils.checkFlowCollectionEnd)(doc.errors, cst); | ||
if (key !== undefined) items.push(new _Pair.default(key)); | ||
checkFlowCollectionEnd(doc.errors, cst); | ||
if (key !== undefined) items.push(new Pair(key)); | ||
return { | ||
@@ -193,0 +178,0 @@ comments: comments, |
@@ -1,19 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.checkFlowCollectionEnd = checkFlowCollectionEnd; | ||
exports.checkKeyLength = checkKeyLength; | ||
exports.resolveComments = resolveComments; | ||
var _errors = require("../errors"); | ||
var _constants = require("../constants"); | ||
function checkFlowCollectionEnd(errors, cst) { | ||
import { YAMLSemanticError } from '../errors'; | ||
import { Type } from '../constants'; | ||
export function checkFlowCollectionEnd(errors, cst) { | ||
var char, name; | ||
switch (cst.type) { | ||
case _constants.Type.FLOW_MAP: | ||
case Type.FLOW_MAP: | ||
char = '}'; | ||
@@ -23,3 +12,3 @@ name = 'flow map'; | ||
case _constants.Type.FLOW_SEQ: | ||
case Type.FLOW_SEQ: | ||
char = ']'; | ||
@@ -30,3 +19,3 @@ name = 'flow sequence'; | ||
default: | ||
errors.push(new _errors.YAMLSemanticError(cst, 'Not a flow collection!?')); | ||
errors.push(new YAMLSemanticError(cst, 'Not a flow collection!?')); | ||
return; | ||
@@ -40,3 +29,3 @@ } | ||
if (!item || item.type !== _constants.Type.COMMENT) { | ||
if (!item || item.type !== Type.COMMENT) { | ||
lastItem = item; | ||
@@ -52,6 +41,6 @@ break; | ||
if (typeof lastItem.offset === 'number') { | ||
err = new _errors.YAMLSemanticError(cst, msg); | ||
err = new YAMLSemanticError(cst, msg); | ||
err.offset = lastItem.offset + 1; | ||
} else { | ||
err = new _errors.YAMLSemanticError(lastItem, msg); | ||
err = new YAMLSemanticError(lastItem, msg); | ||
if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start; | ||
@@ -63,4 +52,3 @@ } | ||
} | ||
function checkKeyLength(errors, node, itemIdx, key, keyStart) { | ||
export function checkKeyLength(errors, node, itemIdx, key, keyStart) { | ||
if (!key || typeof keyStart !== 'number') return; | ||
@@ -83,7 +71,6 @@ var item = node.items[itemIdx]; | ||
var k = String(key).substr(0, 8) + '...' + String(key).substr(-8); | ||
errors.push(new _errors.YAMLSemanticError(node, "The \"".concat(k, "\" key is too long"))); | ||
errors.push(new YAMLSemanticError(node, "The \"".concat(k, "\" key is too long"))); | ||
} | ||
} | ||
function resolveComments(collection, comments) { | ||
export function resolveComments(collection, comments) { | ||
var _iteratorNormalCompletion = true; | ||
@@ -90,0 +77,0 @@ var _didIteratorError = false; |
@@ -1,35 +0,19 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
// Published as 'yaml/scalar' | ||
import _toJSON from '../toJSON'; | ||
import Node from './Node'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var Scalar = /*#__PURE__*/function (_Node) { | ||
_inherits(Scalar, _Node); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _toJSON2 = _interopRequireDefault(require("../toJSON")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
// Published as 'yaml/scalar' | ||
var Scalar = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
(0, _inherits2.default)(Scalar, _Node); | ||
function Scalar(value) { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, Scalar); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Scalar).call(this)); | ||
_classCallCheck(this, Scalar); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Scalar).call(this)); | ||
_this.value = value; | ||
@@ -39,6 +23,6 @@ return _this; | ||
(0, _createClass2.default)(Scalar, [{ | ||
_createClass(Scalar, [{ | ||
key: "toJSON", | ||
value: function toJSON(arg, ctx) { | ||
return ctx && ctx.keep ? this.value : (0, _toJSON2.default)(this.value, arg, ctx); | ||
return ctx && ctx.keep ? this.value : _toJSON(this.value, arg, ctx); | ||
} | ||
@@ -51,5 +35,6 @@ }, { | ||
}]); | ||
return Scalar; | ||
}(_Node2.default); | ||
}(Node); | ||
exports.default = Scalar; | ||
export { Scalar as default }; |
@@ -1,31 +0,14 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _get from "@babel/runtime/helpers/get"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
// Published as 'yaml/seq' | ||
import _toJSON from '../toJSON'; | ||
import Collection from './Collection'; | ||
import Scalar from './Scalar'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _toJSON2 = _interopRequireDefault(require("../toJSON")); | ||
var _Collection2 = _interopRequireDefault(require("./Collection")); | ||
var _Scalar = _interopRequireDefault(require("./Scalar")); | ||
// Published as 'yaml/seq' | ||
function asItemIndex(key) { | ||
var idx = key instanceof _Scalar.default ? key.value : key; | ||
var idx = key instanceof Scalar ? key.value : key; | ||
if (idx && typeof idx === 'string') idx = Number(idx); | ||
@@ -35,13 +18,12 @@ return Number.isInteger(idx) && idx >= 0 ? idx : null; | ||
var YAMLSeq = | ||
/*#__PURE__*/ | ||
function (_Collection) { | ||
(0, _inherits2.default)(YAMLSeq, _Collection); | ||
var YAMLSeq = /*#__PURE__*/function (_Collection) { | ||
_inherits(YAMLSeq, _Collection); | ||
function YAMLSeq() { | ||
(0, _classCallCheck2.default)(this, YAMLSeq); | ||
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLSeq).apply(this, arguments)); | ||
_classCallCheck(this, YAMLSeq); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(YAMLSeq).apply(this, arguments)); | ||
} | ||
(0, _createClass2.default)(YAMLSeq, [{ | ||
_createClass(YAMLSeq, [{ | ||
key: "add", | ||
@@ -65,3 +47,3 @@ value: function add(value) { | ||
var it = this.items[idx]; | ||
return !keepScalar && it instanceof _Scalar.default ? it.value : it; | ||
return !keepScalar && it instanceof Scalar ? it.value : it; | ||
} | ||
@@ -94,3 +76,3 @@ }, { | ||
var item = _step.value; | ||
seq.push((0, _toJSON2.default)(item, String(i++), ctx)); | ||
seq.push(_toJSON(item, String(i++), ctx)); | ||
} | ||
@@ -118,3 +100,3 @@ } catch (err) { | ||
if (!ctx) return JSON.stringify(this); | ||
return (0, _get2.default)((0, _getPrototypeOf2.default)(YAMLSeq.prototype), "toString", this).call(this, ctx, { | ||
return _get(_getPrototypeOf(YAMLSeq.prototype), "toString", this).call(this, ctx, { | ||
blockItem: function blockItem(n) { | ||
@@ -132,5 +114,6 @@ return n.type === 'comment' ? n.str : "- ".concat(n.str); | ||
}]); | ||
return YAMLSeq; | ||
}(_Collection2.default); | ||
}(Collection); | ||
exports.default = YAMLSeq; | ||
export { YAMLSeq as default }; |
@@ -1,24 +0,18 @@ | ||
"use strict"; | ||
import { addCommentBefore } from './addComment'; | ||
import { Type } from './constants'; | ||
import foldFlowLines, { FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED } from './foldFlowLines'; | ||
import { strOptions } from './tags/options'; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var getFoldOptions = function getFoldOptions(_ref) { | ||
var indentAtStart = _ref.indentAtStart; | ||
return indentAtStart ? Object.assign({ | ||
indentAtStart: indentAtStart | ||
}, strOptions.fold) : strOptions.fold; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.stringifyNumber = stringifyNumber; | ||
exports.stringifyString = stringifyString; | ||
var _addComment = require("./addComment"); | ||
var _constants = require("./constants"); | ||
var _foldFlowLines = _interopRequireWildcard(require("./foldFlowLines")); | ||
var _options = require("./tags/options"); | ||
function stringifyNumber(_ref) { | ||
var format = _ref.format, | ||
minFractionDigits = _ref.minFractionDigits, | ||
tag = _ref.tag, | ||
value = _ref.value; | ||
export function stringifyNumber(_ref2) { | ||
var format = _ref2.format, | ||
minFractionDigits = _ref2.minFractionDigits, | ||
tag = _ref2.tag, | ||
value = _ref2.value; | ||
if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf'; | ||
@@ -60,6 +54,6 @@ var n = JSON.stringify(value); | ||
function doubleQuotedString(value, _ref2) { | ||
var implicitKey = _ref2.implicitKey, | ||
indent = _ref2.indent; | ||
var _strOptions$doubleQuo = _options.strOptions.doubleQuoted, | ||
function doubleQuotedString(value, ctx) { | ||
var implicitKey = ctx.implicitKey, | ||
indent = ctx.indent; | ||
var _strOptions$doubleQuo = strOptions.doubleQuoted, | ||
jsonEncoding = _strOptions$doubleQuo.jsonEncoding, | ||
@@ -156,3 +150,3 @@ minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength; | ||
str = start ? str + json.slice(start) : json; | ||
return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, _options.strOptions.fold); | ||
return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx)); | ||
} | ||
@@ -172,3 +166,3 @@ | ||
var res = "'" + value.replace(/'/g, "''").replace(/\n+/g, "$&\n".concat(indent)) + "'"; | ||
return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold); | ||
return implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx)); | ||
} | ||
@@ -190,3 +184,3 @@ | ||
var literal = type === _constants.Type.BLOCK_FOLDED ? false : type === _constants.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, _options.strOptions.fold.lineWidth - indent.length); | ||
var literal = type === Type.BLOCK_FOLDED ? false : type === Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length); | ||
var header = literal ? '|' : '>'; | ||
@@ -239,3 +233,3 @@ if (!value) return header + '\n'; | ||
.replace(/\n+/g, "$&".concat(indent)); | ||
var body = (0, _foldFlowLines.default)("".concat(wsStart).concat(value).concat(wsEnd), indent, _foldFlowLines.FOLD_BLOCK, _options.strOptions.fold); | ||
var body = foldFlowLines("".concat(wsStart).concat(value).concat(wsEnd), indent, FOLD_BLOCK, strOptions.fold); | ||
return "".concat(header, "\n").concat(indent).concat(body); | ||
@@ -268,3 +262,3 @@ } | ||
if (!implicitKey && !inFlow && type !== _constants.Type.PLAIN && value.indexOf('\n') !== -1) { | ||
if (!implicitKey && !inFlow && type !== Type.PLAIN && value.indexOf('\n') !== -1) { | ||
// Where allowed & type not set explicitly, prefer block style for multiline strings | ||
@@ -282,7 +276,7 @@ return blockString(item, ctx, onComment, onChompKeep); | ||
var body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold); | ||
var body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx)); | ||
if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) { | ||
if (onComment) onComment(); | ||
return (0, _addComment.addCommentBefore)(body, indent, comment); | ||
return addCommentBefore(body, indent, comment); | ||
} | ||
@@ -293,4 +287,4 @@ | ||
function stringifyString(item, ctx, onComment, onChompKeep) { | ||
var defaultType = _options.strOptions.defaultType; | ||
export function stringifyString(item, ctx, onComment, onChompKeep) { | ||
var defaultType = strOptions.defaultType; | ||
var implicitKey = ctx.implicitKey, | ||
@@ -311,13 +305,13 @@ inFlow = ctx.inFlow; | ||
switch (_type) { | ||
case _constants.Type.BLOCK_FOLDED: | ||
case _constants.Type.BLOCK_LITERAL: | ||
case Type.BLOCK_FOLDED: | ||
case Type.BLOCK_LITERAL: | ||
return blockString(item, ctx, onComment, onChompKeep); | ||
case _constants.Type.QUOTE_DOUBLE: | ||
case Type.QUOTE_DOUBLE: | ||
return doubleQuotedString(value, ctx); | ||
case _constants.Type.QUOTE_SINGLE: | ||
case Type.QUOTE_SINGLE: | ||
return singleQuotedString(value, ctx); | ||
case _constants.Type.PLAIN: | ||
case Type.PLAIN: | ||
return plainString(item, ctx, onComment, onChompKeep); | ||
@@ -330,8 +324,8 @@ | ||
if (type !== _constants.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) { | ||
if (type !== Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) { | ||
// force double quotes on control characters | ||
type = _constants.Type.QUOTE_DOUBLE; | ||
} else if ((implicitKey || inFlow) && (type === _constants.Type.BLOCK_FOLDED || type === _constants.Type.BLOCK_LITERAL)) { | ||
type = Type.QUOTE_DOUBLE; | ||
} else if ((implicitKey || inFlow) && (type === Type.BLOCK_FOLDED || type === Type.BLOCK_LITERAL)) { | ||
// should not happen; blocks are not valid inside flow containers | ||
type = _constants.Type.QUOTE_DOUBLE; | ||
type = Type.QUOTE_DOUBLE; | ||
} | ||
@@ -338,0 +332,0 @@ |
@@ -1,19 +0,6 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _Scalar = _interopRequireDefault(require("../schema/Scalar")); | ||
var _stringify = require("../stringify"); | ||
var _failsafe = _interopRequireDefault(require("./failsafe")); | ||
var _options = require("./options"); | ||
var _default = _failsafe.default.concat([{ | ||
import Scalar from '../schema/Scalar'; | ||
import { stringifyNumber } from '../stringify'; | ||
import failsafe from './failsafe'; | ||
import { boolOptions, nullOptions } from './options'; | ||
export var nullObj = { | ||
identify: function identify(value) { | ||
@@ -23,3 +10,3 @@ return value == null; | ||
createNode: function createNode(schema, value, ctx) { | ||
return ctx.wrapScalars ? new _Scalar.default(null) : null; | ||
return ctx.wrapScalars ? new Scalar(null) : null; | ||
}, | ||
@@ -32,7 +19,8 @@ default: true, | ||
}, | ||
options: _options.nullOptions, | ||
options: nullOptions, | ||
stringify: function stringify() { | ||
return _options.nullOptions.nullStr; | ||
return nullOptions.nullStr; | ||
} | ||
}, { | ||
}; | ||
export var boolObj = { | ||
identify: function identify(value) { | ||
@@ -47,8 +35,9 @@ return typeof value === 'boolean'; | ||
}, | ||
options: _options.boolOptions, | ||
options: boolOptions, | ||
stringify: function stringify(_ref) { | ||
var value = _ref.value; | ||
return value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr; | ||
return value ? boolOptions.trueStr : boolOptions.falseStr; | ||
} | ||
}, { | ||
}; | ||
export var octObj = { | ||
identify: function identify(value) { | ||
@@ -68,3 +57,4 @@ return typeof value === 'number'; | ||
} | ||
}, { | ||
}; | ||
export var intObj = { | ||
identify: function identify(value) { | ||
@@ -79,4 +69,5 @@ return typeof value === 'number'; | ||
}, | ||
stringify: _stringify.stringifyNumber | ||
}, { | ||
stringify: stringifyNumber | ||
}; | ||
export var hexObj = { | ||
identify: function identify(value) { | ||
@@ -96,3 +87,4 @@ return typeof value === 'number'; | ||
} | ||
}, { | ||
}; | ||
export var nanObj = { | ||
identify: function identify(value) { | ||
@@ -107,4 +99,5 @@ return typeof value === 'number'; | ||
}, | ||
stringify: _stringify.stringifyNumber | ||
}, { | ||
stringify: stringifyNumber | ||
}; | ||
export var expObj = { | ||
identify: function identify(value) { | ||
@@ -124,3 +117,4 @@ return typeof value === 'number'; | ||
} | ||
}, { | ||
}; | ||
export var floatObj = { | ||
identify: function identify(value) { | ||
@@ -133,9 +127,8 @@ return typeof value === 'number'; | ||
resolve: function resolve(str, frac) { | ||
var node = new _Scalar.default(parseFloat(str)); | ||
var node = new Scalar(parseFloat(str)); | ||
if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length; | ||
return node; | ||
}, | ||
stringify: _stringify.stringifyNumber | ||
}]); | ||
exports.default = _default; | ||
stringify: stringifyNumber | ||
}; | ||
export default failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]); |
@@ -1,17 +0,4 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _map = _interopRequireDefault(require("./map")); | ||
var _seq = _interopRequireDefault(require("./seq")); | ||
var _string = _interopRequireDefault(require("./string")); | ||
var _default = [_map.default, _seq.default, _string.default]; | ||
exports.default = _default; | ||
import map from './map'; | ||
import seq from './seq'; | ||
import str from './string'; | ||
export default [map, seq, str]; |
@@ -1,20 +0,8 @@ | ||
"use strict"; | ||
import _typeof from "@babel/runtime/helpers/typeof"; | ||
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
import YAMLMap from '../../schema/Map'; | ||
import parseMap from '../../schema/parseMap'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _Map = _interopRequireDefault(require("../../schema/Map")); | ||
var _parseMap = _interopRequireDefault(require("../../schema/parseMap")); | ||
function createMap(schema, obj, ctx) { | ||
var map = new _Map.default(); | ||
var map = new YAMLMap(schema); | ||
@@ -28,3 +16,3 @@ if (obj instanceof Map) { | ||
for (var _iterator = obj[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _step$value = (0, _slicedToArray2.default)(_step.value, 2), | ||
var _step$value = _slicedToArray(_step.value, 2), | ||
key = _step$value[0], | ||
@@ -49,3 +37,3 @@ value = _step$value[1]; | ||
} | ||
} else if (obj && (0, _typeof2.default)(obj) === 'object') { | ||
} else if (obj && _typeof(obj) === 'object') { | ||
for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) { | ||
@@ -57,12 +45,15 @@ var _key = _Object$keys[_i]; | ||
if (typeof schema.sortMapEntries === 'function') { | ||
map.items.sort(schema.sortMapEntries); | ||
} | ||
return map; | ||
} | ||
var _default = { | ||
export default { | ||
createNode: createMap, | ||
default: true, | ||
nodeClass: _Map.default, | ||
nodeClass: YAMLMap, | ||
tag: 'tag:yaml.org,2002:map', | ||
resolve: _parseMap.default | ||
}; | ||
exports.default = _default; | ||
resolve: parseMap | ||
}; |
@@ -1,16 +0,6 @@ | ||
"use strict"; | ||
import parseSeq from '../../schema/parseSeq'; | ||
import YAMLSeq from '../../schema/Seq'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _parseSeq = _interopRequireDefault(require("../../schema/parseSeq")); | ||
var _Seq = _interopRequireDefault(require("../../schema/Seq")); | ||
function createSeq(schema, obj, ctx) { | ||
var seq = new _Seq.default(); | ||
var seq = new YAMLSeq(schema); | ||
@@ -47,9 +37,8 @@ if (obj && obj[Symbol.iterator]) { | ||
var _default = { | ||
export default { | ||
createNode: createSeq, | ||
default: true, | ||
nodeClass: _Seq.default, | ||
nodeClass: YAMLSeq, | ||
tag: 'tag:yaml.org,2002:seq', | ||
resolve: _parseSeq.default | ||
}; | ||
exports.default = _default; | ||
resolve: parseSeq | ||
}; |
@@ -1,13 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.resolveString = void 0; | ||
var _stringify = require("../../stringify"); | ||
var _options = require("../options"); | ||
var resolveString = function resolveString(doc, node) { | ||
import { stringifyString } from '../../stringify'; | ||
import { strOptions } from '../options'; | ||
export var resolveString = function resolveString(doc, node) { | ||
// on error, will return { str: string, errors: Error[] } | ||
@@ -23,5 +14,3 @@ var res = node.strValue; | ||
}; | ||
exports.resolveString = resolveString; | ||
var _default = { | ||
export default { | ||
identify: function identify(value) { | ||
@@ -37,6 +26,5 @@ return typeof value === 'string'; | ||
}, ctx); | ||
return (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep); | ||
return stringifyString(item, ctx, onComment, onChompKeep); | ||
}, | ||
options: _options.strOptions | ||
}; | ||
exports.default = _default; | ||
options: strOptions | ||
}; |
@@ -1,50 +0,36 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.tags = exports.schemas = void 0; | ||
var _core = _interopRequireDefault(require("./core")); | ||
var _failsafe = _interopRequireDefault(require("./failsafe")); | ||
var _json = _interopRequireDefault(require("./json")); | ||
var _yaml = _interopRequireDefault(require("./yaml-1.1")); | ||
var _map = _interopRequireDefault(require("./failsafe/map")); | ||
var _seq = _interopRequireDefault(require("./failsafe/seq")); | ||
var _binary = _interopRequireDefault(require("./yaml-1.1/binary")); | ||
var _omap = _interopRequireDefault(require("./yaml-1.1/omap")); | ||
var _pairs = _interopRequireDefault(require("./yaml-1.1/pairs")); | ||
var _set = _interopRequireDefault(require("./yaml-1.1/set")); | ||
var _timestamp = require("./yaml-1.1/timestamp"); | ||
var schemas = { | ||
core: _core.default, | ||
failsafe: _failsafe.default, | ||
json: _json.default, | ||
yaml11: _yaml.default | ||
import core, { nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj } from './core'; | ||
import failsafe from './failsafe'; | ||
import json from './json'; | ||
import yaml11 from './yaml-1.1'; | ||
import map from './failsafe/map'; | ||
import seq from './failsafe/seq'; | ||
import binary from './yaml-1.1/binary'; | ||
import omap from './yaml-1.1/omap'; | ||
import pairs from './yaml-1.1/pairs'; | ||
import set from './yaml-1.1/set'; | ||
import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp'; | ||
export var schemas = { | ||
core: core, | ||
failsafe: failsafe, | ||
json: json, | ||
yaml11: yaml11 | ||
}; | ||
exports.schemas = schemas; | ||
var tags = { | ||
binary: _binary.default, | ||
floatTime: _timestamp.floatTime, | ||
intTime: _timestamp.intTime, | ||
map: _map.default, | ||
omap: _omap.default, | ||
pairs: _pairs.default, | ||
seq: _seq.default, | ||
set: _set.default, | ||
timestamp: _timestamp.timestamp | ||
}; | ||
exports.tags = tags; | ||
export var tags = { | ||
binary: binary, | ||
bool: boolObj, | ||
float: floatObj, | ||
floatExp: expObj, | ||
floatNaN: nanObj, | ||
floatTime: floatTime, | ||
int: intObj, | ||
intHex: hexObj, | ||
intOct: octObj, | ||
intTime: intTime, | ||
map: map, | ||
null: nullObj, | ||
omap: omap, | ||
pairs: pairs, | ||
seq: seq, | ||
set: set, | ||
timestamp: timestamp | ||
}; |
@@ -1,19 +0,6 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _map = _interopRequireDefault(require("./failsafe/map")); | ||
var _seq = _interopRequireDefault(require("./failsafe/seq")); | ||
var _Scalar = _interopRequireDefault(require("../schema/Scalar")); | ||
var _string = require("./failsafe/string"); | ||
var schema = [_map.default, _seq.default, { | ||
import map from './failsafe/map'; | ||
import seq from './failsafe/seq'; | ||
import Scalar from '../schema/Scalar'; | ||
import { resolveString } from './failsafe/string'; | ||
var schema = [map, seq, { | ||
identify: function identify(value) { | ||
@@ -24,3 +11,3 @@ return typeof value === 'string'; | ||
tag: 'tag:yaml.org,2002:str', | ||
resolve: _string.resolveString, | ||
resolve: resolveString, | ||
stringify: function stringify(value) { | ||
@@ -34,3 +21,3 @@ return JSON.stringify(value); | ||
createNode: function createNode(schema, value, ctx) { | ||
return ctx.wrapScalars ? new _Scalar.default(null) : null; | ||
return ctx.wrapScalars ? new Scalar(null) : null; | ||
}, | ||
@@ -52,5 +39,5 @@ default: true, | ||
tag: 'tag:yaml.org,2002:bool', | ||
test: /^true$/, | ||
resolve: function resolve() { | ||
return true; | ||
test: /^true|false$/, | ||
resolve: function resolve(str) { | ||
return str === 'true'; | ||
}, | ||
@@ -62,15 +49,2 @@ stringify: function stringify(value) { | ||
identify: function identify(value) { | ||
return typeof value === 'boolean'; | ||
}, | ||
default: true, | ||
tag: 'tag:yaml.org,2002:bool', | ||
test: /^false$/, | ||
resolve: function resolve() { | ||
return false; | ||
}, | ||
stringify: function stringify(value) { | ||
return JSON.stringify(value); | ||
} | ||
}, { | ||
identify: function identify(value) { | ||
return typeof value === 'number'; | ||
@@ -106,3 +80,2 @@ }, | ||
var _default = schema; | ||
exports.default = _default; | ||
export default schema; |
@@ -1,26 +0,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.strOptions = exports.nullOptions = exports.boolOptions = exports.binaryOptions = void 0; | ||
var _constants = require("../constants"); | ||
var binaryOptions = { | ||
defaultType: _constants.Type.BLOCK_LITERAL, | ||
import { Type } from '../constants'; | ||
export var binaryOptions = { | ||
defaultType: Type.BLOCK_LITERAL, | ||
lineWidth: 76 | ||
}; | ||
exports.binaryOptions = binaryOptions; | ||
var boolOptions = { | ||
export var boolOptions = { | ||
trueStr: 'true', | ||
falseStr: 'false' | ||
}; | ||
exports.boolOptions = boolOptions; | ||
var nullOptions = { | ||
export var nullOptions = { | ||
nullStr: 'null' | ||
}; | ||
exports.nullOptions = nullOptions; | ||
var strOptions = { | ||
defaultType: _constants.Type.PLAIN, | ||
export var strOptions = { | ||
defaultType: Type.PLAIN, | ||
doubleQuoted: { | ||
@@ -34,3 +23,2 @@ jsonEncoding: false, | ||
} | ||
}; | ||
exports.strOptions = strOptions; | ||
}; |
@@ -1,20 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _constants = require("../../constants"); | ||
var _errors = require("../../errors"); | ||
var _stringify = require("../../stringify"); | ||
var _string = require("../failsafe/string"); | ||
var _options = require("../options"); | ||
/* global atob, btoa, Buffer */ | ||
var _default = { | ||
import { Type } from '../../constants'; | ||
import { YAMLReferenceError } from '../../errors'; | ||
import { stringifyString } from '../../stringify'; | ||
import { resolveString } from '../failsafe/string'; | ||
import { binaryOptions as options } from '../options'; | ||
export default { | ||
identify: function identify(value) { | ||
@@ -37,6 +25,6 @@ return value instanceof Uint8Array; | ||
if (typeof Buffer === 'function') { | ||
var src = (0, _string.resolveString)(doc, node); | ||
var src = resolveString(doc, node); | ||
return Buffer.from(src, 'base64'); | ||
} else if (typeof atob === 'function') { | ||
var _src = atob((0, _string.resolveString)(doc, node)); | ||
var _src = atob(resolveString(doc, node)); | ||
@@ -51,7 +39,7 @@ var buffer = new Uint8Array(_src.length); | ||
} else { | ||
doc.errors.push(new _errors.YAMLReferenceError(node, 'This environment does not support reading binary tags; either Buffer or atob is required')); | ||
doc.errors.push(new YAMLReferenceError(node, 'This environment does not support reading binary tags; either Buffer or atob is required')); | ||
return null; | ||
} | ||
}, | ||
options: _options.binaryOptions, | ||
options: options, | ||
stringify: function stringify(_ref, ctx, onComment, onChompKeep) { | ||
@@ -77,8 +65,8 @@ var comment = _ref.comment, | ||
if (!type) type = _options.binaryOptions.defaultType; | ||
if (!type) type = options.defaultType; | ||
if (type === _constants.Type.QUOTE_DOUBLE) { | ||
if (type === Type.QUOTE_DOUBLE) { | ||
value = src; | ||
} else { | ||
var lineWidth = _options.binaryOptions.lineWidth; | ||
var lineWidth = options.lineWidth; | ||
var n = Math.ceil(src.length / lineWidth); | ||
@@ -91,6 +79,6 @@ var lines = new Array(n); | ||
value = lines.join(type === _constants.Type.BLOCK_LITERAL ? '\n' : ' '); | ||
value = lines.join(type === Type.BLOCK_LITERAL ? '\n' : ' '); | ||
} | ||
return (0, _stringify.stringifyString)({ | ||
return stringifyString({ | ||
comment: comment, | ||
@@ -101,3 +89,2 @@ type: type, | ||
} | ||
}; | ||
exports.default = _default; | ||
}; |
@@ -1,29 +0,17 @@ | ||
"use strict"; | ||
import Scalar from '../../schema/Scalar'; | ||
import { stringifyNumber } from '../../stringify'; | ||
import failsafe from '../failsafe'; | ||
import { boolOptions, nullOptions } from '../options'; | ||
import binary from './binary'; | ||
import omap from './omap'; | ||
import pairs from './pairs'; | ||
import set from './set'; | ||
import { intTime, floatTime, timestamp } from './timestamp'; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var boolStringify = function boolStringify(_ref) { | ||
var value = _ref.value; | ||
return value ? boolOptions.trueStr : boolOptions.falseStr; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _Scalar = _interopRequireDefault(require("../../schema/Scalar")); | ||
var _stringify = require("../../stringify"); | ||
var _failsafe = _interopRequireDefault(require("../failsafe")); | ||
var _options = require("../options"); | ||
var _binary = _interopRequireDefault(require("./binary")); | ||
var _omap = _interopRequireDefault(require("./omap")); | ||
var _pairs = _interopRequireDefault(require("./pairs")); | ||
var _set = _interopRequireDefault(require("./set")); | ||
var _timestamp = require("./timestamp"); | ||
var _default = _failsafe.default.concat([{ | ||
export default failsafe.concat([{ | ||
identify: function identify(value) { | ||
@@ -33,3 +21,3 @@ return value == null; | ||
createNode: function createNode(schema, value, ctx) { | ||
return ctx.wrapScalars ? new _Scalar.default(null) : null; | ||
return ctx.wrapScalars ? new Scalar(null) : null; | ||
}, | ||
@@ -42,5 +30,5 @@ default: true, | ||
}, | ||
options: _options.nullOptions, | ||
options: nullOptions, | ||
stringify: function stringify() { | ||
return _options.nullOptions.nullStr; | ||
return nullOptions.nullStr; | ||
} | ||
@@ -57,7 +45,4 @@ }, { | ||
}, | ||
options: _options.boolOptions, | ||
stringify: function stringify(_ref) { | ||
var value = _ref.value; | ||
return value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr; | ||
} | ||
options: boolOptions, | ||
stringify: boolStringify | ||
}, { | ||
@@ -73,7 +58,4 @@ identify: function identify(value) { | ||
}, | ||
options: _options.boolOptions, | ||
stringify: function stringify(_ref2) { | ||
var value = _ref2.value; | ||
return value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr; | ||
} | ||
options: boolOptions, | ||
stringify: boolStringify | ||
}, { | ||
@@ -90,4 +72,4 @@ identify: function identify(value) { | ||
}, | ||
stringify: function stringify(_ref3) { | ||
var value = _ref3.value; | ||
stringify: function stringify(_ref2) { | ||
var value = _ref2.value; | ||
return '0b' + value.toString(2); | ||
@@ -106,4 +88,4 @@ } | ||
}, | ||
stringify: function stringify(_ref4) { | ||
var value = _ref4.value; | ||
stringify: function stringify(_ref3) { | ||
var value = _ref3.value; | ||
return (value < 0 ? '-0' : '0') + value.toString(8); | ||
@@ -121,3 +103,3 @@ } | ||
}, | ||
stringify: _stringify.stringifyNumber | ||
stringify: stringifyNumber | ||
}, { | ||
@@ -134,4 +116,4 @@ identify: function identify(value) { | ||
}, | ||
stringify: function stringify(_ref5) { | ||
var value = _ref5.value; | ||
stringify: function stringify(_ref4) { | ||
var value = _ref4.value; | ||
return (value < 0 ? '-0x' : '0x') + value.toString(16); | ||
@@ -149,3 +131,3 @@ } | ||
}, | ||
stringify: _stringify.stringifyNumber | ||
stringify: stringifyNumber | ||
}, { | ||
@@ -162,4 +144,4 @@ identify: function identify(value) { | ||
}, | ||
stringify: function stringify(_ref6) { | ||
var value = _ref6.value; | ||
stringify: function stringify(_ref5) { | ||
var value = _ref5.value; | ||
return Number(value).toExponential(); | ||
@@ -175,3 +157,3 @@ } | ||
resolve: function resolve(str, frac) { | ||
var node = new _Scalar.default(parseFloat(str.replace(/_/g, ''))); | ||
var node = new Scalar(parseFloat(str.replace(/_/g, ''))); | ||
@@ -185,5 +167,3 @@ if (frac) { | ||
}, | ||
stringify: _stringify.stringifyNumber | ||
}], _binary.default, _omap.default, _pairs.default, _set.default, _timestamp.intTime, _timestamp.floatTime, _timestamp.timestamp); | ||
exports.default = _default; | ||
stringify: stringifyNumber | ||
}], binary, omap, pairs, set, intTime, floatTime, timestamp); |
@@ -1,53 +0,35 @@ | ||
"use strict"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import { YAMLSemanticError } from '../../errors'; | ||
import _toJSON from '../../toJSON'; | ||
import YAMLMap from '../../schema/Map'; | ||
import Pair from '../../schema/Pair'; | ||
import Scalar from '../../schema/Scalar'; | ||
import YAMLSeq from '../../schema/Seq'; | ||
import { createPairs, parsePairs } from './pairs'; | ||
export var YAMLOMap = /*#__PURE__*/function (_YAMLSeq) { | ||
_inherits(YAMLOMap, _YAMLSeq); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
function YAMLOMap() { | ||
var _this; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.YAMLOMap = void 0; | ||
_classCallCheck(this, YAMLOMap); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(YAMLOMap).call(this)); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
_defineProperty(_assertThisInitialized(_this), "add", YAMLMap.prototype.add.bind(_assertThisInitialized(_this))); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
_defineProperty(_assertThisInitialized(_this), "delete", YAMLMap.prototype.delete.bind(_assertThisInitialized(_this))); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
_defineProperty(_assertThisInitialized(_this), "get", YAMLMap.prototype.get.bind(_assertThisInitialized(_this))); | ||
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); | ||
_defineProperty(_assertThisInitialized(_this), "has", YAMLMap.prototype.has.bind(_assertThisInitialized(_this))); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
_defineProperty(_assertThisInitialized(_this), "set", YAMLMap.prototype.set.bind(_assertThisInitialized(_this))); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _errors = require("../../errors"); | ||
var _toJSON2 = _interopRequireDefault(require("../../toJSON")); | ||
var _Map = _interopRequireDefault(require("../../schema/Map")); | ||
var _Pair = _interopRequireDefault(require("../../schema/Pair")); | ||
var _Scalar = _interopRequireDefault(require("../../schema/Scalar")); | ||
var _Seq = _interopRequireDefault(require("../../schema/Seq")); | ||
var _pairs = require("./pairs"); | ||
var YAMLOMap = | ||
/*#__PURE__*/ | ||
function (_YAMLSeq) { | ||
(0, _inherits2.default)(YAMLOMap, _YAMLSeq); | ||
function YAMLOMap() { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, YAMLOMap); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLOMap).call(this)); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "add", _Map.default.prototype.add.bind((0, _assertThisInitialized2.default)(_this))); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "delete", _Map.default.prototype.delete.bind((0, _assertThisInitialized2.default)(_this))); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "get", _Map.default.prototype.get.bind((0, _assertThisInitialized2.default)(_this))); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "has", _Map.default.prototype.has.bind((0, _assertThisInitialized2.default)(_this))); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "set", _Map.default.prototype.set.bind((0, _assertThisInitialized2.default)(_this))); | ||
_this.tag = YAMLOMap.tag; | ||
@@ -57,3 +39,3 @@ return _this; | ||
(0, _createClass2.default)(YAMLOMap, [{ | ||
_createClass(YAMLOMap, [{ | ||
key: "toJSON", | ||
@@ -73,7 +55,7 @@ value: function toJSON(_, ctx) { | ||
if (pair instanceof _Pair.default) { | ||
key = (0, _toJSON2.default)(pair.key, '', ctx); | ||
value = (0, _toJSON2.default)(pair.value, key, ctx); | ||
if (pair instanceof Pair) { | ||
key = _toJSON(pair.key, '', ctx); | ||
value = _toJSON(pair.value, key, ctx); | ||
} else { | ||
key = (0, _toJSON2.default)(pair, '', ctx); | ||
key = _toJSON(pair, '', ctx); | ||
} | ||
@@ -102,10 +84,10 @@ | ||
}]); | ||
return YAMLOMap; | ||
}(_Seq.default); | ||
}(YAMLSeq); | ||
exports.YAMLOMap = YAMLOMap; | ||
(0, _defineProperty2.default)(YAMLOMap, "tag", 'tag:yaml.org,2002:omap'); | ||
_defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap'); | ||
function parseOMap(doc, cst) { | ||
var pairs = (0, _pairs.parsePairs)(doc, cst); | ||
var pairs = parsePairs(doc, cst); | ||
var seenKeys = []; | ||
@@ -120,6 +102,6 @@ var _iteratorNormalCompletion2 = true; | ||
if (key instanceof _Scalar.default) { | ||
if (key instanceof Scalar) { | ||
if (seenKeys.includes(key.value)) { | ||
var msg = 'Ordered maps must not include duplicate keys'; | ||
throw new _errors.YAMLSemanticError(cst, msg); | ||
throw new YAMLSemanticError(cst, msg); | ||
} else { | ||
@@ -149,3 +131,3 @@ seenKeys.push(key.value); | ||
function createOMap(schema, iterable, ctx) { | ||
var pairs = (0, _pairs.createPairs)(schema, iterable, ctx); | ||
var pairs = createPairs(schema, iterable, ctx); | ||
var omap = new YAMLOMap(); | ||
@@ -156,3 +138,3 @@ omap.items = pairs.items; | ||
var _default = { | ||
export default { | ||
identify: function identify(value) { | ||
@@ -166,3 +148,2 @@ return value instanceof Map; | ||
createNode: createOMap | ||
}; | ||
exports.default = _default; | ||
}; |
@@ -1,34 +0,18 @@ | ||
"use strict"; | ||
import { YAMLSemanticError } from '../../errors'; | ||
import YAMLMap from '../../schema/Map'; | ||
import Pair from '../../schema/Pair'; | ||
import parseSeq from '../../schema/parseSeq'; | ||
import YAMLSeq from '../../schema/Seq'; | ||
export function parsePairs(doc, cst) { | ||
var seq = parseSeq(doc, cst); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.parsePairs = parsePairs; | ||
exports.createPairs = createPairs; | ||
exports.default = void 0; | ||
var _errors = require("../../errors"); | ||
var _Map = _interopRequireDefault(require("../../schema/Map")); | ||
var _Pair = _interopRequireDefault(require("../../schema/Pair")); | ||
var _parseSeq = _interopRequireDefault(require("../../schema/parseSeq")); | ||
var _Seq = _interopRequireDefault(require("../../schema/Seq")); | ||
function parsePairs(doc, cst) { | ||
var seq = (0, _parseSeq.default)(doc, cst); | ||
for (var i = 0; i < seq.items.length; ++i) { | ||
var item = seq.items[i]; | ||
if (item instanceof _Pair.default) continue;else if (item instanceof _Map.default) { | ||
if (item instanceof Pair) continue;else if (item instanceof YAMLMap) { | ||
if (item.items.length > 1) { | ||
var msg = 'Each pair must have its own sequence indicator'; | ||
throw new _errors.YAMLSemanticError(cst, msg); | ||
throw new YAMLSemanticError(cst, msg); | ||
} | ||
var pair = item.items[0] || new _Pair.default(); | ||
var pair = item.items[0] || new Pair(); | ||
if (item.commentBefore) pair.commentBefore = pair.commentBefore ? "".concat(item.commentBefore, "\n").concat(pair.commentBefore) : item.commentBefore; | ||
@@ -38,3 +22,3 @@ if (item.comment) pair.comment = pair.comment ? "".concat(item.comment, "\n").concat(pair.comment) : item.comment; | ||
} | ||
seq.items[i] = item instanceof _Pair.default ? item : new _Pair.default(item); | ||
seq.items[i] = item instanceof Pair ? item : new Pair(item); | ||
} | ||
@@ -44,5 +28,4 @@ | ||
} | ||
function createPairs(schema, iterable, ctx) { | ||
var pairs = new _Seq.default(); | ||
export function createPairs(schema, iterable, ctx) { | ||
var pairs = new YAMLSeq(schema); | ||
pairs.tag = 'tag:yaml.org,2002:pairs'; | ||
@@ -95,4 +78,3 @@ var _iteratorNormalCompletion = true; | ||
} | ||
var _default = { | ||
export default { | ||
default: false, | ||
@@ -102,3 +84,2 @@ tag: 'tag:yaml.org,2002:pairs', | ||
createNode: createPairs | ||
}; | ||
exports.default = _default; | ||
}; |
@@ -1,48 +0,23 @@ | ||
"use strict"; | ||
import _typeof from "@babel/runtime/helpers/typeof"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _get from "@babel/runtime/helpers/get"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import { YAMLSemanticError } from '../../errors'; | ||
import YAMLMap, { findPair } from '../../schema/Map'; | ||
import Pair from '../../schema/Pair'; | ||
import parseMap from '../../schema/parseMap'; | ||
import Scalar from '../../schema/Scalar'; | ||
export var YAMLSet = /*#__PURE__*/function (_YAMLMap) { | ||
_inherits(YAMLSet, _YAMLMap); | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.YAMLSet = void 0; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _errors = require("../../errors"); | ||
var _Map = _interopRequireWildcard(require("../../schema/Map")); | ||
var _Pair = _interopRequireDefault(require("../../schema/Pair")); | ||
var _parseMap = _interopRequireDefault(require("../../schema/parseMap")); | ||
var _Scalar = _interopRequireDefault(require("../../schema/Scalar")); | ||
var YAMLSet = | ||
/*#__PURE__*/ | ||
function (_YAMLMap) { | ||
(0, _inherits2.default)(YAMLSet, _YAMLMap); | ||
function YAMLSet() { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, YAMLSet); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLSet).call(this)); | ||
_classCallCheck(this, YAMLSet); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(YAMLSet).call(this)); | ||
_this.tag = YAMLSet.tag; | ||
@@ -52,7 +27,7 @@ return _this; | ||
(0, _createClass2.default)(YAMLSet, [{ | ||
_createClass(YAMLSet, [{ | ||
key: "add", | ||
value: function add(key) { | ||
var pair = key instanceof _Pair.default ? key : new _Pair.default(key); | ||
var prev = (0, _Map.findPair)(this.items, pair.key); | ||
var pair = key instanceof Pair ? key : new Pair(key); | ||
var prev = findPair(this.items, pair.key); | ||
if (!prev) this.items.push(pair); | ||
@@ -63,4 +38,4 @@ } | ||
value: function get(key, keepPair) { | ||
var pair = (0, _Map.findPair)(this.items, key); | ||
return !keepPair && pair instanceof _Pair.default ? pair.key instanceof _Scalar.default ? pair.key.value : pair.key : pair; | ||
var pair = findPair(this.items, key); | ||
return !keepPair && pair instanceof Pair ? pair.key instanceof Scalar ? pair.key.value : pair.key : pair; | ||
} | ||
@@ -70,4 +45,4 @@ }, { | ||
value: function set(key, value) { | ||
if (typeof value !== 'boolean') throw new Error("Expected boolean value for set(key, value) in a YAML set, not ".concat((0, _typeof2.default)(value))); | ||
var prev = (0, _Map.findPair)(this.items, key); | ||
if (typeof value !== 'boolean') throw new Error("Expected boolean value for set(key, value) in a YAML set, not ".concat(_typeof(value))); | ||
var prev = findPair(this.items, key); | ||
@@ -77,3 +52,3 @@ if (prev && !value) { | ||
} else if (!prev && value) { | ||
this.items.push(new _Pair.default(key)); | ||
this.items.push(new Pair(key)); | ||
} | ||
@@ -84,3 +59,3 @@ } | ||
value: function toJSON(_, ctx) { | ||
return (0, _get2.default)((0, _getPrototypeOf2.default)(YAMLSet.prototype), "toJSON", this).call(this, _, ctx, Set); | ||
return _get(_getPrototypeOf(YAMLSet.prototype), "toJSON", this).call(this, _, ctx, Set); | ||
} | ||
@@ -91,14 +66,14 @@ }, { | ||
if (!ctx) return JSON.stringify(this); | ||
if (this.hasAllNullValues()) return (0, _get2.default)((0, _getPrototypeOf2.default)(YAMLSet.prototype), "toString", this).call(this, ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values'); | ||
if (this.hasAllNullValues()) return _get(_getPrototypeOf(YAMLSet.prototype), "toString", this).call(this, ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values'); | ||
} | ||
}]); | ||
return YAMLSet; | ||
}(_Map.default); | ||
}(YAMLMap); | ||
exports.YAMLSet = YAMLSet; | ||
(0, _defineProperty2.default)(YAMLSet, "tag", 'tag:yaml.org,2002:set'); | ||
_defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set'); | ||
function parseSet(doc, cst) { | ||
var map = (0, _parseMap.default)(doc, cst); | ||
if (!map.hasAllNullValues()) throw new _errors.YAMLSemanticError(cst, 'Set items must all have null values'); | ||
var map = parseMap(doc, cst); | ||
if (!map.hasAllNullValues()) throw new YAMLSemanticError(cst, 'Set items must all have null values'); | ||
return Object.assign(new YAMLSet(), map); | ||
@@ -136,3 +111,3 @@ } | ||
var _default = { | ||
export default { | ||
identify: function identify(value) { | ||
@@ -146,3 +121,2 @@ return value instanceof Set; | ||
createNode: createSet | ||
}; | ||
exports.default = _default; | ||
}; |
@@ -1,10 +0,3 @@ | ||
"use strict"; | ||
import { stringifyNumber } from '../../stringify'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.timestamp = exports.floatTime = exports.intTime = void 0; | ||
var _stringify = require("../../stringify"); | ||
var parseSexagesimal = function parseSexagesimal(sign, parts) { | ||
@@ -20,3 +13,3 @@ var n = parts.split(':').reduce(function (n, p) { | ||
var value = _ref.value; | ||
if (isNaN(value) || !isFinite(value)) return (0, _stringify.stringifyNumber)(value); | ||
if (isNaN(value) || !isFinite(value)) return stringifyNumber(value); | ||
var sign = ''; | ||
@@ -49,3 +42,3 @@ | ||
var intTime = { | ||
export var intTime = { | ||
identify: function identify(value) { | ||
@@ -63,4 +56,3 @@ return typeof value === 'number'; | ||
}; | ||
exports.intTime = intTime; | ||
var floatTime = { | ||
export var floatTime = { | ||
identify: function identify(value) { | ||
@@ -78,4 +70,3 @@ return typeof value === 'number'; | ||
}; | ||
exports.floatTime = floatTime; | ||
var timestamp = { | ||
export var timestamp = { | ||
identify: function identify(value) { | ||
@@ -110,3 +101,2 @@ return value instanceof Date; | ||
} | ||
}; | ||
exports.timestamp = timestamp; | ||
}; |
@@ -1,18 +0,6 @@ | ||
"use strict"; | ||
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
import parseCST from './cst/parse'; | ||
import Document from './Document'; // test harness for yaml-test-suite event tests | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = testEvents; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _parse = _interopRequireDefault(require("./cst/parse")); | ||
var _Document = _interopRequireDefault(require("./Document")); | ||
// test harness for yaml-test-suite event tests | ||
function testEvents(src, options) { | ||
export default function testEvents(src, options) { | ||
var opt = Object.assign({ | ||
@@ -23,4 +11,4 @@ keepCstNodes: true, | ||
}, options); | ||
var docs = (0, _parse.default)(src).map(function (cstDoc) { | ||
return new _Document.default(opt).parse(cstDoc); | ||
var docs = parseCST(src).map(function (cstDoc) { | ||
return new Document(opt).parse(cstDoc); | ||
}); | ||
@@ -40,3 +28,3 @@ var errDoc = docs.find(function (doc) { | ||
var _ref = doc.range || [0, 0], | ||
_ref2 = (0, _slicedToArray2.default)(_ref, 2), | ||
_ref2 = _slicedToArray(_ref, 2), | ||
rootStart = _ref2[0], | ||
@@ -43,0 +31,0 @@ rootEnd = _ref2[1]; |
@@ -1,9 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = toJSON; | ||
function toJSON(value, arg, ctx) { | ||
export default function toJSON(value, arg, ctx) { | ||
if (Array.isArray(value)) return value.map(function (v, i) { | ||
@@ -10,0 +3,0 @@ return toJSON(v, String(i), ctx); |
@@ -1,12 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.warn = warn; | ||
exports.warnFileDeprecation = warnFileDeprecation; | ||
exports.warnOptionDeprecation = warnOptionDeprecation; | ||
/* global global, console */ | ||
function warn(warning, type) { | ||
export function warn(warning, type) { | ||
if (global && global._YAML_SILENCE_WARNINGS) return; | ||
@@ -24,4 +15,3 @@ | ||
} | ||
function warnFileDeprecation(filename) { | ||
export function warnFileDeprecation(filename) { | ||
if (global && global._YAML_SILENCE_DEPRECATION_WARNINGS) return; | ||
@@ -31,6 +21,4 @@ var path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/'); | ||
} | ||
var warned = {}; | ||
function warnOptionDeprecation(name, alternative) { | ||
export function warnOptionDeprecation(name, alternative) { | ||
if (global && global._YAML_SILENCE_DEPRECATION_WARNINGS) return; | ||
@@ -37,0 +25,0 @@ if (warned[name]) return; |
@@ -20,4 +20,8 @@ "use strict"; | ||
} | ||
/* istanbul ignore next */ | ||
get includesTrailingLines() { | ||
// This is never called from anywhere, but if it were, | ||
// this is the value it should return. | ||
return true; | ||
@@ -24,0 +28,0 @@ } |
@@ -53,3 +53,3 @@ "use strict"; | ||
if (end <= start) { | ||
if (this.chomping === Chomp.KEEP) break;else return ''; | ||
if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens | ||
} | ||
@@ -56,0 +56,0 @@ |
@@ -17,18 +17,2 @@ "use strict"; | ||
class Directive extends _Node.default { | ||
static endOfDirective(src, offset) { | ||
let ch = src[offset]; | ||
while (ch && ch !== '\n' && ch !== '#') ch = src[offset += 1]; // last char can't be whitespace | ||
ch = src[offset - 1]; | ||
while (ch === ' ' || ch === '\t') { | ||
offset -= 1; | ||
ch = src[offset - 1]; | ||
} | ||
return offset; | ||
} | ||
constructor() { | ||
@@ -35,0 +19,0 @@ super(_constants.Type.DIRECTIVE); |
@@ -117,7 +117,2 @@ "use strict"; | ||
static atCollectionItem(src, offset) { | ||
const ch = src[offset]; | ||
return (ch === '?' || ch === ':' || ch === '-') && Node.atBlank(src, offset + 1, true); | ||
} | ||
static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) { | ||
@@ -124,0 +119,0 @@ if (!ch || indentDiff < 0) return false; |
@@ -36,2 +36,37 @@ "use strict"; | ||
function createNewNode(type, props) { | ||
switch (type) { | ||
case _constants.Type.ALIAS: | ||
return new _Alias.default(type, props); | ||
case _constants.Type.BLOCK_FOLDED: | ||
case _constants.Type.BLOCK_LITERAL: | ||
return new _BlockValue.default(type, props); | ||
case _constants.Type.FLOW_MAP: | ||
case _constants.Type.FLOW_SEQ: | ||
return new _FlowCollection.default(type, props); | ||
case _constants.Type.MAP_KEY: | ||
case _constants.Type.MAP_VALUE: | ||
case _constants.Type.SEQ_ITEM: | ||
return new _CollectionItem.default(type, props); | ||
case _constants.Type.COMMENT: | ||
case _constants.Type.PLAIN: | ||
return new _PlainValue.default(type, props); | ||
case _constants.Type.QUOTE_DOUBLE: | ||
return new _QuoteDouble.default(type, props); | ||
case _constants.Type.QUOTE_SINGLE: | ||
return new _QuoteSingle.default(type, props); | ||
/* istanbul ignore next */ | ||
default: | ||
return null; | ||
// should never happen | ||
} | ||
} | ||
/** | ||
@@ -46,2 +81,4 @@ * @param {boolean} atLineStart - Node starts at beginning of line | ||
*/ | ||
class ParseContext { | ||
@@ -101,48 +138,10 @@ static parseType(src, offset, inFlow) { | ||
} = context.parseProps(start); | ||
let node; | ||
switch (type) { | ||
case _constants.Type.ALIAS: | ||
node = new _Alias.default(type, props); | ||
break; | ||
case _constants.Type.BLOCK_FOLDED: | ||
case _constants.Type.BLOCK_LITERAL: | ||
node = new _BlockValue.default(type, props); | ||
break; | ||
case _constants.Type.FLOW_MAP: | ||
case _constants.Type.FLOW_SEQ: | ||
node = new _FlowCollection.default(type, props); | ||
break; | ||
case _constants.Type.MAP_KEY: | ||
case _constants.Type.MAP_VALUE: | ||
case _constants.Type.SEQ_ITEM: | ||
node = new _CollectionItem.default(type, props); | ||
break; | ||
case _constants.Type.COMMENT: | ||
case _constants.Type.PLAIN: | ||
node = new _PlainValue.default(type, props); | ||
break; | ||
case _constants.Type.QUOTE_DOUBLE: | ||
node = new _QuoteDouble.default(type, props); | ||
break; | ||
case _constants.Type.QUOTE_SINGLE: | ||
node = new _QuoteSingle.default(type, props); | ||
break; | ||
default: | ||
node.error = new _errors.YAMLSyntaxError(node, `Unknown node type: ${JSON.stringify(type)}`); | ||
node.range = new _Range.default(start, start + 1); | ||
return node; | ||
} | ||
const node = createNewNode(type, props); | ||
let offset = node.parse(context, valueStart); | ||
node.range = new _Range.default(start, offset); | ||
/* istanbul ignore if */ | ||
if (offset <= start) { | ||
// This should never happen, but if it does, let's make sure to at least | ||
// step one character forward to avoid a busy loop. | ||
node.error = new Error(`Node#parse consumed no characters`); | ||
@@ -176,15 +175,2 @@ node.error.parseEnd = offset; | ||
this.src = orig.src; | ||
} // for logging | ||
get pretty() { | ||
const obj = { | ||
start: `${this.lineStart} + ${this.indent}`, | ||
in: [], | ||
parent: this.parent.type | ||
}; | ||
if (!this.atLineStart) obj.start += ' + N'; | ||
if (this.inCollection) obj.in.push('collection'); | ||
if (this.inFlow) obj.in.push('flow'); | ||
return obj; | ||
} | ||
@@ -191,0 +177,0 @@ |
@@ -32,3 +32,3 @@ "use strict"; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
@@ -35,0 +35,0 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -80,2 +80,3 @@ "use strict"; | ||
const anchor = anchors.find(a => a.node === this.source); | ||
/* istanbul ignore if */ | ||
@@ -82,0 +83,0 @@ if (!anchor || anchor.res === undefined) { |
@@ -20,3 +20,16 @@ "use strict"; | ||
// null, undefined, or an empty non-string iterable (e.g. []) | ||
function collectionFromPath(schema, path, value) { | ||
let v = value; | ||
for (let i = path.length - 1; i >= 0; --i) { | ||
const k = path[i]; | ||
const o = Number.isInteger(k) && k >= 0 ? [] : {}; | ||
o[k] = v; | ||
v = o; | ||
} | ||
return schema.createNode(v, false); | ||
} // null, undefined, or an empty non-string iterable (e.g. []) | ||
const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done; | ||
@@ -27,6 +40,8 @@ | ||
class Collection extends _Node.default { | ||
constructor(...args) { | ||
super(...args); | ||
constructor(schema) { | ||
super(); | ||
_defineProperty(this, "items", []); | ||
this.schema = schema; | ||
} | ||
@@ -38,3 +53,3 @@ | ||
const node = this.get(key, true); | ||
if (node instanceof Collection) node.addIn(rest, value);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`); | ||
if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`); | ||
} | ||
@@ -73,7 +88,9 @@ } | ||
const node = this.get(key, true); | ||
if (node instanceof Collection) node.setIn(rest, value);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`); | ||
if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`); | ||
} | ||
} // overridden in implementations | ||
/* istanbul ignore next */ | ||
toJSON() { | ||
@@ -80,0 +97,0 @@ return null; |
@@ -47,2 +47,3 @@ "use strict"; | ||
schema, | ||
sortMapEntries, | ||
tags: deprecatedCustomTags | ||
@@ -52,2 +53,3 @@ }) { | ||
this.name = schema; | ||
this.sortMapEntries = sortMapEntries === true ? (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0 : sortMapEntries || null; | ||
this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11' | ||
@@ -119,3 +121,3 @@ | ||
if (value && typeof value === 'object' && ctx.prevObjects) { | ||
const prev = ctx.prevObjects.find(o => o.value === value); | ||
const prev = ctx.prevObjects.get(value); | ||
@@ -130,6 +132,7 @@ if (prev) { | ||
obj.value = value; | ||
ctx.prevObjects.push(obj); | ||
ctx.prevObjects.set(value, obj); | ||
} | ||
obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value; | ||
if (tag && obj.node instanceof _Node.default) obj.node.tag = tag; | ||
return obj.node; | ||
@@ -194,2 +197,3 @@ } | ||
} catch (error) { | ||
/* istanbul ignore if */ | ||
if (!error.source) error.source = node; | ||
@@ -209,2 +213,3 @@ doc.errors.push(error); | ||
const fallback = isMap(node) ? Schema.defaultTags.MAP : isSeq(node) ? Schema.defaultTags.SEQ : Schema.defaultTags.STR; | ||
/* istanbul ignore else */ | ||
@@ -218,5 +223,4 @@ if (fallback) { | ||
doc.errors.push(new _errors.YAMLReferenceError(node, `The tag ${tagName} is unavailable`)); | ||
return null; | ||
} | ||
return null; | ||
} | ||
@@ -281,3 +285,3 @@ | ||
onTagObj: o => tagObj = o, | ||
prevObjects: [] | ||
prevObjects: new Map() | ||
}; | ||
@@ -304,2 +308,3 @@ item = this.createNode(item, true, null, createCtx); | ||
const props = this.stringifyProps(item, tagObj, ctx); | ||
if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1; | ||
const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof _Collection.default ? item.toString(ctx, onComment, onChompKeep) : (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep); | ||
@@ -306,0 +311,0 @@ return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? `${props}\n${ctx.indent}${str}` : `${props} ${str}` : str; |
@@ -31,7 +31,15 @@ "use strict"; | ||
class YAMLMap extends _Collection.default { | ||
add(pair) { | ||
add(pair, overwrite) { | ||
if (!pair) pair = new _Pair.default(pair);else if (!(pair instanceof _Pair.default)) pair = new _Pair.default(pair.key || pair, pair.value); | ||
const prev = findPair(this.items, pair.key); | ||
if (prev) throw new Error(`Key ${pair.key} already set`); | ||
this.items.push(pair); | ||
const sortEntries = this.schema && this.schema.sortMapEntries; | ||
if (prev) { | ||
if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`); | ||
} else if (sortEntries) { | ||
const i = this.items.findIndex(item => sortEntries(pair, item) < 0); | ||
if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair); | ||
} else { | ||
this.items.push(pair); | ||
} | ||
} | ||
@@ -57,4 +65,3 @@ | ||
set(key, value) { | ||
const prev = findPair(this.items, key); | ||
if (prev) prev.value = value;else this.items.push(new _Pair.default(key, value)); | ||
this.add(new _Pair.default(key, value), true); | ||
} | ||
@@ -61,0 +68,0 @@ /** |
@@ -143,2 +143,3 @@ "use strict"; | ||
ctx.implicitKey = false; | ||
if (!explicitKey && !this.comment && value instanceof _Scalar.default) ctx.indentAtStart = str.length + 1; | ||
chompKeep = false; | ||
@@ -145,0 +146,0 @@ const valueStr = doc.schema.stringify(value, ctx, () => valueComment = null, () => chompKeep = true); |
@@ -28,3 +28,3 @@ "use strict"; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
@@ -31,0 +31,0 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -19,4 +19,10 @@ "use strict"; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const getFoldOptions = ({ | ||
indentAtStart | ||
}) => indentAtStart ? Object.assign({ | ||
indentAtStart | ||
}, _options.strOptions.fold) : _options.strOptions.fold; | ||
function stringifyNumber({ | ||
@@ -62,7 +68,8 @@ format, | ||
function doubleQuotedString(value, { | ||
implicitKey, | ||
indent | ||
}) { | ||
function doubleQuotedString(value, ctx) { | ||
const { | ||
implicitKey, | ||
indent | ||
} = ctx; | ||
const { | ||
jsonEncoding, | ||
@@ -160,3 +167,3 @@ minMultiLineLength | ||
str = start ? str + json.slice(start) : json; | ||
return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, _options.strOptions.fold); | ||
return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx)); | ||
} | ||
@@ -178,3 +185,3 @@ | ||
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'"; | ||
return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold); | ||
return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx)); | ||
} | ||
@@ -289,3 +296,3 @@ | ||
const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold); | ||
const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx)); | ||
@@ -292,0 +299,0 @@ if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) { |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports.default = exports.floatObj = exports.expObj = exports.nanObj = exports.hexObj = exports.intObj = exports.octObj = exports.boolObj = exports.nullObj = void 0; | ||
@@ -19,3 +19,3 @@ var _Scalar = _interopRequireDefault(require("../schema/Scalar")); | ||
var _default = _failsafe.default.concat([{ | ||
const nullObj = { | ||
identify: value => value == null, | ||
@@ -29,3 +29,5 @@ createNode: (schema, value, ctx) => ctx.wrapScalars ? new _Scalar.default(null) : null, | ||
stringify: () => _options.nullOptions.nullStr | ||
}, { | ||
}; | ||
exports.nullObj = nullObj; | ||
const boolObj = { | ||
identify: value => typeof value === 'boolean', | ||
@@ -40,3 +42,5 @@ default: true, | ||
}) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr | ||
}, { | ||
}; | ||
exports.boolObj = boolObj; | ||
const octObj = { | ||
identify: value => typeof value === 'number', | ||
@@ -51,3 +55,5 @@ default: true, | ||
}) => '0o' + value.toString(8) | ||
}, { | ||
}; | ||
exports.octObj = octObj; | ||
const intObj = { | ||
identify: value => typeof value === 'number', | ||
@@ -59,3 +65,5 @@ default: true, | ||
stringify: _stringify.stringifyNumber | ||
}, { | ||
}; | ||
exports.intObj = intObj; | ||
const hexObj = { | ||
identify: value => typeof value === 'number', | ||
@@ -70,3 +78,5 @@ default: true, | ||
}) => '0x' + value.toString(16) | ||
}, { | ||
}; | ||
exports.hexObj = hexObj; | ||
const nanObj = { | ||
identify: value => typeof value === 'number', | ||
@@ -78,3 +88,5 @@ default: true, | ||
stringify: _stringify.stringifyNumber | ||
}, { | ||
}; | ||
exports.nanObj = nanObj; | ||
const expObj = { | ||
identify: value => typeof value === 'number', | ||
@@ -89,3 +101,5 @@ default: true, | ||
}) => Number(value).toExponential() | ||
}, { | ||
}; | ||
exports.expObj = expObj; | ||
const floatObj = { | ||
identify: value => typeof value === 'number', | ||
@@ -103,4 +117,7 @@ default: true, | ||
stringify: _stringify.stringifyNumber | ||
}]); | ||
}; | ||
exports.floatObj = floatObj; | ||
var _default = _failsafe.default.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]); | ||
exports.default = _default; |
@@ -15,3 +15,3 @@ "use strict"; | ||
function createMap(schema, obj, ctx) { | ||
const map = new _Map.default(); | ||
const map = new _Map.default(schema); | ||
@@ -24,2 +24,6 @@ if (obj instanceof Map) { | ||
if (typeof schema.sortMapEntries === 'function') { | ||
map.items.sort(schema.sortMapEntries); | ||
} | ||
return map; | ||
@@ -26,0 +30,0 @@ } |
@@ -15,3 +15,3 @@ "use strict"; | ||
function createSeq(schema, obj, ctx) { | ||
const seq = new _Seq.default(); | ||
const seq = new _Seq.default(schema); | ||
@@ -18,0 +18,0 @@ if (obj && obj[Symbol.iterator]) { |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _core = _interopRequireDefault(require("./core")); | ||
var _core = _interopRequireWildcard(require("./core")); | ||
@@ -33,2 +33,6 @@ var _failsafe = _interopRequireDefault(require("./failsafe")); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const schemas = { | ||
@@ -43,5 +47,13 @@ core: _core.default, | ||
binary: _binary.default, | ||
bool: _core.boolObj, | ||
float: _core.floatObj, | ||
floatExp: _core.expObj, | ||
floatNaN: _core.nanObj, | ||
floatTime: _timestamp.floatTime, | ||
int: _core.intObj, | ||
intHex: _core.hexObj, | ||
intOct: _core.octObj, | ||
intTime: _timestamp.intTime, | ||
map: _map.default, | ||
null: _core.nullObj, | ||
omap: _omap.default, | ||
@@ -48,0 +60,0 @@ pairs: _pairs.default, |
@@ -36,13 +36,6 @@ "use strict"; | ||
tag: 'tag:yaml.org,2002:bool', | ||
test: /^true$/, | ||
resolve: () => true, | ||
test: /^true|false$/, | ||
resolve: str => str === 'true', | ||
stringify: value => JSON.stringify(value) | ||
}, { | ||
identify: value => typeof value === 'boolean', | ||
default: true, | ||
tag: 'tag:yaml.org,2002:bool', | ||
test: /^false$/, | ||
resolve: () => false, | ||
stringify: value => JSON.stringify(value) | ||
}, { | ||
identify: value => typeof value === 'number', | ||
@@ -49,0 +42,0 @@ default: true, |
@@ -28,2 +28,6 @@ "use strict"; | ||
const boolStringify = ({ | ||
value | ||
}) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr; | ||
var _default = _failsafe.default.concat([{ | ||
@@ -45,5 +49,3 @@ identify: value => value == null, | ||
options: _options.boolOptions, | ||
stringify: ({ | ||
value | ||
}) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr | ||
stringify: boolStringify | ||
}, { | ||
@@ -56,5 +58,3 @@ identify: value => typeof value === 'boolean', | ||
options: _options.boolOptions, | ||
stringify: ({ | ||
value | ||
}) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr | ||
stringify: boolStringify | ||
}, { | ||
@@ -61,0 +61,0 @@ identify: value => typeof value === 'number', |
@@ -45,3 +45,3 @@ "use strict"; | ||
function createPairs(schema, iterable, ctx) { | ||
const pairs = new _Seq.default(); | ||
const pairs = new _Seq.default(schema); | ||
pairs.tag = 'tag:yaml.org,2002:pairs'; | ||
@@ -48,0 +48,0 @@ |
@@ -22,3 +22,3 @@ "use strict"; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
@@ -25,0 +25,0 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
{ | ||
"name": "yaml", | ||
"version": "1.7.2", | ||
"version": "1.8.0", | ||
"license": "ISC", | ||
@@ -19,4 +19,6 @@ "author": "Eemeli Aro <eemeli@gmail.com>", | ||
"*.js", | ||
"*.mjs", | ||
"!.*.js" | ||
], | ||
"type": "commonjs", | ||
"main": "./index.js", | ||
@@ -39,2 +41,14 @@ "browser": { | ||
}, | ||
"exports": { | ||
".": "./index.js", | ||
"./parse-cst": "./parse-cst.js", | ||
"./types": { | ||
"require": "./types.js", | ||
"import": "./types.mjs" | ||
}, | ||
"./util": { | ||
"require": "./util.js", | ||
"import": "./util.mjs" | ||
} | ||
}, | ||
"scripts": { | ||
@@ -59,2 +73,5 @@ "browser:build": "BABEL_ENV=browser babel src/ --out-dir browser/dist/", | ||
"jest": { | ||
"collectCoverageFrom": [ | ||
"src/**/*.js" | ||
], | ||
"testMatch": [ | ||
@@ -73,21 +90,21 @@ "**/tests/**/*.js" | ||
"devDependencies": { | ||
"@babel/cli": "^7.6.4", | ||
"@babel/core": "^7.6.4", | ||
"@babel/plugin-proposal-class-properties": "^7.5.5", | ||
"@babel/plugin-transform-runtime": "^7.6.2", | ||
"@babel/preset-env": "^7.6.3", | ||
"babel-eslint": "^10.0.3", | ||
"babel-jest": "^24.9.0", | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.8.7", | ||
"@babel/plugin-proposal-class-properties": "^7.8.3", | ||
"@babel/plugin-transform-runtime": "^7.8.3", | ||
"@babel/preset-env": "^7.8.7", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^25.1.0", | ||
"babel-plugin-trace": "^1.1.0", | ||
"common-tags": "^1.8.0", | ||
"cpy-cli": "^2.0.0", | ||
"eslint": "^6.5.1", | ||
"eslint-config-prettier": "^6.4.0", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"fast-check": "^1.17.0", | ||
"jest": "^24.9.0", | ||
"prettier": "^1.18.2" | ||
"cpy-cli": "^3.1.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.10.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"fast-check": "^1.23.0", | ||
"jest": "^25.1.0", | ||
"prettier": "^1.19.1" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.6.3" | ||
"@babel/runtime": "^7.8.7" | ||
}, | ||
@@ -94,0 +111,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143
453256
12689
Updated@babel/runtime@^7.8.7