Comparing version 1.0.0-rc.7 to 1.0.0-rc.8
@@ -11,8 +11,8 @@ "use strict"; | ||
if (!comment) return str; | ||
var cc = comment.replace(/[\s\S]^/gm, "$&".concat(indent, "#")); | ||
return "#".concat(cc, "\n").concat(indent).concat(str); | ||
const cc = comment.replace(/[\s\S]^/gm, `$&${indent}#`); | ||
return `#${cc}\n${indent}${str}`; | ||
} | ||
function addComment(str, indent, comment) { | ||
return !comment ? str : comment.indexOf('\n') === -1 ? "".concat(str, " #").concat(comment) : "".concat(str, "\n") + comment.replace(/^/gm, "".concat(indent || '', "#")); | ||
return !comment ? str : comment.indexOf('\n') === -1 ? `${str} #${comment}` : `${str}\n` + comment.replace(/^/gm, `${indent || ''}#`); | ||
} |
@@ -20,130 +20,98 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
class Anchors { | ||
constructor() { | ||
_defineProperty(this, "map", {}); | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
static validAnchorNode(node) { | ||
return node instanceof _Scalar.default || node instanceof _Seq.default || node instanceof _Map.default; | ||
} | ||
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; } | ||
createAlias(node, name) { | ||
this.setAnchor(node, name); | ||
return new _Alias.default(node); | ||
} | ||
var Anchors = | ||
/*#__PURE__*/ | ||
function () { | ||
function Anchors() { | ||
_classCallCheck(this, Anchors); | ||
createMergePair(...sources) { | ||
const merge = new _Merge.default(); | ||
merge.value.items = sources.map(s => { | ||
if (s instanceof _Alias.default) { | ||
if (s.source instanceof _Map.default) return s; | ||
} else if (s instanceof _Map.default) { | ||
return this.createAlias(s); | ||
} | ||
_defineProperty(this, "map", {}); | ||
throw new Error('Merge sources must be Map nodes or their Aliases'); | ||
}); | ||
return merge; | ||
} | ||
_createClass(Anchors, [{ | ||
key: "createAlias", | ||
value: function createAlias(node, name) { | ||
this.setAnchor(node, name); | ||
return new _Alias.default(node); | ||
} | ||
}, { | ||
key: "createMergePair", | ||
value: function createMergePair() { | ||
var _this = this; | ||
getName(node) { | ||
const map = this.map; | ||
return Object.keys(map).find(a => map[a] === node); | ||
} | ||
var merge = new _Merge.default(); | ||
getNode(name) { | ||
return this.map[name]; | ||
} | ||
for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) { | ||
sources[_key] = arguments[_key]; | ||
} | ||
newName(prefix) { | ||
const names = Object.keys(this.map); | ||
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) { | ||
return _this.createAlias(s); | ||
} | ||
throw new Error('Merge sources must be Map nodes or their Aliases'); | ||
}); | ||
return merge; | ||
for (let i = 1; true; ++i) { | ||
const name = `${prefix}${i}`; | ||
if (!names.includes(name)) return name; | ||
} | ||
}, { | ||
key: "getName", | ||
value: function getName(node) { | ||
var map = this.map; | ||
return Object.keys(map).find(function (a) { | ||
return map[a] === node; | ||
}); | ||
} | ||
}, { | ||
key: "getNode", | ||
value: function getNode(name) { | ||
return this.map[name]; | ||
} | ||
}, { | ||
key: "newName", | ||
value: function newName(prefix) { | ||
var names = Object.keys(this.map); | ||
} // During parsing, map & aliases contain CST nodes | ||
for (var i = 1; true; ++i) { | ||
var name = "".concat(prefix).concat(i); | ||
if (!names.includes(name)) return name; | ||
} | ||
} // During parsing, map & aliases contain CST nodes | ||
}, { | ||
key: "resolveNodes", | ||
value: function resolveNodes() { | ||
var map = this.map, | ||
resolveNodes() { | ||
const map = this.map, | ||
_cstAliases = this._cstAliases; | ||
Object.keys(map).forEach(function (a) { | ||
map[a] = map[a].resolved; | ||
}); | ||
Object.keys(map).forEach(a => { | ||
map[a] = map[a].resolved; | ||
}); | ||
_cstAliases.forEach(function (a) { | ||
a.source = a.source.resolved; | ||
}); | ||
_cstAliases.forEach(a => { | ||
a.source = a.source.resolved; | ||
}); | ||
delete this._cstAliases; | ||
delete this._cstAliases; | ||
} | ||
setAnchor(node, name) { | ||
if (node != null && !Anchors.validAnchorNode(node)) { | ||
throw new Error('Anchors may only be set for Scalar, Seq and Map nodes'); | ||
} | ||
}, { | ||
key: "setAnchor", | ||
value: function setAnchor(node, name) { | ||
if (node != null && !Anchors.validAnchorNode(node)) { | ||
throw new Error('Anchors may only be set for Scalar, Seq and Map nodes'); | ||
} | ||
if (name && /[\x00-\x19\s,[\]{}]/.test(name)) { | ||
throw new Error('Anchor names must not contain whitespace or control characters'); | ||
} | ||
if (name && /[\x00-\x19\s,[\]{}]/.test(name)) { | ||
throw new Error('Anchor names must not contain whitespace or control characters'); | ||
} | ||
var map = this.map; | ||
var prev = node && Object.keys(map).find(function (a) { | ||
return map[a] === node; | ||
}); | ||
const map = this.map; | ||
const prev = node && Object.keys(map).find(a => map[a] === node); | ||
if (prev) { | ||
if (!name) { | ||
return prev; | ||
} else if (prev !== name) { | ||
delete map[prev]; | ||
map[name] = node; | ||
} | ||
} else { | ||
if (!name) { | ||
if (!node) return null; | ||
name = this.newName('a'); | ||
} | ||
if (prev) { | ||
if (!name) { | ||
return prev; | ||
} else if (prev !== name) { | ||
delete map[prev]; | ||
map[name] = node; | ||
} | ||
} else { | ||
if (!name) { | ||
if (!node) return null; | ||
name = this.newName('a'); | ||
} | ||
return name; | ||
map[name] = node; | ||
} | ||
}], [{ | ||
key: "validAnchorNode", | ||
value: function validAnchorNode(node) { | ||
return node instanceof _Scalar.default || node instanceof _Seq.default || node instanceof _Map.default; | ||
} | ||
}]); | ||
return Anchors; | ||
}(); | ||
return name; | ||
} | ||
} | ||
exports.default = Anchors; |
@@ -18,20 +18,15 @@ "use strict"; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function createNode(value) { | ||
var wrapScalars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
function createNode(value, wrapScalars = true) { | ||
if (value == null) return new _Scalar.default(null); | ||
if (_typeof(value) !== 'object') return wrapScalars ? new _Scalar.default(value) : value; | ||
if (typeof value !== 'object') return wrapScalars ? new _Scalar.default(value) : value; | ||
if (Array.isArray(value)) { | ||
var seq = new _Seq.default(); | ||
seq.items = value.map(function (v) { | ||
return createNode(v, wrapScalars); | ||
}); | ||
const seq = new _Seq.default(); | ||
seq.items = value.map(v => createNode(v, wrapScalars)); | ||
return seq; | ||
} else { | ||
var map = new _Map.default(); | ||
map.items = Object.keys(value).map(function (key) { | ||
var k = createNode(key, wrapScalars); | ||
var v = createNode(value[key], wrapScalars); | ||
const map = new _Map.default(); | ||
map.items = Object.keys(value).map(key => { | ||
const k = createNode(key, wrapScalars); | ||
const v = createNode(value[key], wrapScalars); | ||
return new _Pair.default(k, v); | ||
@@ -38,0 +33,0 @@ }); |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Node = _interopRequireDefault(require("./Node")); | ||
@@ -15,57 +15,24 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
class Alias extends _Node.default { | ||
/** | ||
* Parses an *alias from the source | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this scalar | ||
*/ | ||
parse(context, start) { | ||
this.context = context; | ||
const src = context.src; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
let offset = _Node.default.endOfIdentifier(src, start + 1); | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var Alias = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(Alias, _Node); | ||
function Alias() { | ||
_classCallCheck(this, Alias); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(Alias).apply(this, arguments)); | ||
this.valueRange = new _Range.default(start + 1, offset); | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
return offset; | ||
} | ||
_createClass(Alias, [{ | ||
key: "parse", | ||
} | ||
/** | ||
* Parses an *alias from the source | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this scalar | ||
*/ | ||
value: function parse(context, start) { | ||
this.context = context; | ||
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); | ||
offset = this.parseComment(offset); | ||
return offset; | ||
} | ||
}]); | ||
return Alias; | ||
}(_Node2.default); | ||
exports.default = Alias; |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _Node2 = _interopRequireWildcard(require("./Node")); | ||
var _Node = _interopRequireWildcard(require("./Node")); | ||
@@ -17,21 +17,3 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var Chomp = { | ||
const Chomp = { | ||
CLIP: 'CLIP', | ||
@@ -43,219 +25,208 @@ KEEP: 'KEEP', | ||
var BlockValue = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(BlockValue, _Node); | ||
function BlockValue(type, props) { | ||
var _this; | ||
_classCallCheck(this, BlockValue); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BlockValue).call(this, type, props)); | ||
_this.blockIndent = null; | ||
_this.chomping = Chomp.CLIP; | ||
_this.header = null; | ||
return _this; | ||
class BlockValue extends _Node.default { | ||
constructor(type, props) { | ||
super(type, props); | ||
this.blockIndent = null; | ||
this.chomping = Chomp.CLIP; | ||
this.header = null; | ||
} | ||
_createClass(BlockValue, [{ | ||
key: "parseBlockHeader", | ||
value: function parseBlockHeader(start) { | ||
var src = this.context.src; | ||
var offset = start + 1; | ||
var bi = ''; | ||
get strValue() { | ||
if (!this.valueRange || !this.context) return null; | ||
let _this$valueRange = this.valueRange, | ||
start = _this$valueRange.start, | ||
end = _this$valueRange.end; | ||
const _this$context = this.context, | ||
indent = _this$context.indent, | ||
src = _this$context.src; | ||
if (this.valueRange.isEmpty()) return ''; | ||
let lastNewLine = null; | ||
let ch = src[end - 1]; | ||
while (true) { | ||
var ch = src[offset]; | ||
while (ch === '\n' || ch === '\t' || ch === ' ') { | ||
end -= 1; | ||
switch (ch) { | ||
case '-': | ||
this.chomping = Chomp.STRIP; | ||
break; | ||
if (end <= start) { | ||
if (this.chomping === Chomp.KEEP) break;else return ''; | ||
} | ||
case '+': | ||
this.chomping = Chomp.KEEP; | ||
break; | ||
if (ch === '\n') lastNewLine = end; | ||
ch = src[end - 1]; | ||
} | ||
case '0': | ||
case '1': | ||
case '2': | ||
case '3': | ||
case '4': | ||
case '5': | ||
case '6': | ||
case '7': | ||
case '8': | ||
case '9': | ||
bi += ch; | ||
break; | ||
let keepStart = end + 1; | ||
default: | ||
this.blockIndent = Number(bi) || null; | ||
this.header = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
offset += 1; | ||
if (lastNewLine) { | ||
if (this.chomping === Chomp.KEEP) { | ||
keepStart = lastNewLine; | ||
end = this.valueRange.end; | ||
} else { | ||
end = lastNewLine; | ||
} | ||
} | ||
}, { | ||
key: "parseBlockValue", | ||
value: function parseBlockValue(start) { | ||
var _this$context = this.context, | ||
indent = _this$context.indent, | ||
inFlow = _this$context.inFlow, | ||
src = _this$context.src; | ||
var offset = start; | ||
var bi = this.blockIndent ? indent + this.blockIndent - 1 : indent; | ||
var minBlockIndent = 1; | ||
for (var ch = src[offset]; ch === '\n'; ch = src[offset]) { | ||
offset += 1; | ||
if (_Node2.default.atDocumentBoundary(src, offset)) break; | ||
const bi = indent + this.blockIndent; | ||
const folded = this.type === _Node.Type.BLOCK_FOLDED; | ||
let atStart = true; | ||
let str = ''; | ||
let sep = ''; | ||
let prevMoreIndented = false; | ||
var end = _Node2.default.endOfBlockIndent(src, bi, offset); // should not include tab? | ||
for (let i = start; i < end; ++i) { | ||
for (let j = 0; j < bi; ++j) { | ||
if (src[i] !== ' ') break; | ||
i += 1; | ||
} | ||
let ch = src[i]; | ||
if (end === null) break; | ||
if (ch === '\n') { | ||
if (sep === '\n') str += '\n';else sep = '\n'; | ||
} else { | ||
const lineEnd = _Node.default.endOfLine(src, i); | ||
if (!this.blockIndent) { | ||
// no explicit block indent, none yet detected | ||
var lineIndent = end - (offset + indent); | ||
const line = src.slice(i, lineEnd); | ||
i = lineEnd; | ||
if (src[end] !== '\n') { | ||
// first line with non-whitespace content | ||
if (lineIndent < minBlockIndent) { | ||
offset -= 1; | ||
break; | ||
} | ||
if (folded && (ch === ' ' || ch === '\t') && i < keepStart) { | ||
if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n'; | ||
str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '') | ||
this.blockIndent = lineIndent; | ||
bi = indent + this.blockIndent - 1; | ||
} else if (lineIndent > minBlockIndent) { | ||
// empty line with more whitespace | ||
minBlockIndent = lineIndent; | ||
} | ||
sep = lineEnd < end && src[lineEnd] || ''; | ||
prevMoreIndented = true; | ||
} else { | ||
str += sep + line; | ||
sep = folded && i < keepStart ? ' ' : '\n'; | ||
prevMoreIndented = false; | ||
} | ||
offset = _Node2.default.endOfLine(src, end); | ||
if (atStart && line !== '') atStart = false; | ||
} | ||
this.valueRange = new _Range.default(start + 1, offset); | ||
return offset; | ||
} | ||
/** | ||
* Parses a block value from the source | ||
* | ||
* Accepted forms are: | ||
* ``` | ||
* BS | ||
* block | ||
* lines | ||
* | ||
* BS #comment | ||
* block | ||
* lines | ||
* ``` | ||
* where the block style BS matches the regexp `[|>][-+1-9]*` and block lines | ||
* are empty or have an indent level greater than `indent`. | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this block | ||
*/ | ||
}, { | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var src = context.src; | ||
var offset = this.parseBlockHeader(start); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
offset = this.parseBlockValue(offset); | ||
return offset; | ||
} | ||
}, { | ||
key: "strValue", | ||
get: function get() { | ||
if (!this.valueRange || !this.context) return null; | ||
var _this$valueRange = this.valueRange, | ||
start = _this$valueRange.start, | ||
end = _this$valueRange.end; | ||
var _this$context2 = this.context, | ||
indent = _this$context2.indent, | ||
src = _this$context2.src; | ||
if (this.valueRange.isEmpty) return ''; | ||
var lastNewLine = null; | ||
var ch = src[end - 1]; | ||
return this.chomping === Chomp.STRIP ? str : str + '\n'; | ||
} | ||
while (ch === '\n' || ch === '\t' || ch === ' ') { | ||
end -= 1; | ||
parseBlockHeader(start) { | ||
const src = this.context.src; | ||
let offset = start + 1; | ||
let bi = ''; | ||
if (end <= start) { | ||
if (this.chomping === Chomp.KEEP) break;else return ''; | ||
} | ||
while (true) { | ||
let ch = src[offset]; | ||
if (ch === '\n') lastNewLine = end; | ||
ch = src[end - 1]; | ||
} | ||
switch (ch) { | ||
case '-': | ||
this.chomping = Chomp.STRIP; | ||
break; | ||
var keepStart = end + 1; | ||
case '+': | ||
this.chomping = Chomp.KEEP; | ||
break; | ||
if (lastNewLine) { | ||
if (this.chomping === Chomp.KEEP) { | ||
keepStart = lastNewLine; | ||
end = this.valueRange.end; | ||
} else { | ||
end = lastNewLine; | ||
} | ||
case '0': | ||
case '1': | ||
case '2': | ||
case '3': | ||
case '4': | ||
case '5': | ||
case '6': | ||
case '7': | ||
case '8': | ||
case '9': | ||
bi += ch; | ||
break; | ||
default: | ||
this.blockIndent = Number(bi) || null; | ||
this.header = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
var bi = indent + this.blockIndent; | ||
var folded = this.type === _Node2.Type.BLOCK_FOLDED; | ||
var atStart = true; | ||
var str = ''; | ||
var sep = ''; | ||
var prevMoreIndented = false; | ||
offset += 1; | ||
} | ||
} | ||
for (var i = start; i < end; ++i) { | ||
for (var j = 0; j < bi; ++j) { | ||
if (src[i] !== ' ') break; | ||
i += 1; | ||
} | ||
parseBlockValue(start) { | ||
const _this$context2 = this.context, | ||
indent = _this$context2.indent, | ||
inFlow = _this$context2.inFlow, | ||
src = _this$context2.src; | ||
let offset = start; | ||
let bi = this.blockIndent ? indent + this.blockIndent - 1 : indent; | ||
let minBlockIndent = 1; | ||
var _ch = src[i]; | ||
for (let ch = src[offset]; ch === '\n'; ch = src[offset]) { | ||
offset += 1; | ||
if (_Node.default.atDocumentBoundary(src, offset)) break; | ||
if (_ch === '\n') { | ||
if (sep === '\n') str += '\n';else sep = '\n'; | ||
} else { | ||
var lineEnd = _Node2.default.endOfLine(src, i); | ||
const end = _Node.default.endOfBlockIndent(src, bi, offset); // should not include tab? | ||
var line = src.slice(i, lineEnd); | ||
i = lineEnd; | ||
if (folded && (_ch === ' ' || _ch === '\t') && i < keepStart) { | ||
if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n'; | ||
str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '') | ||
if (end === null) break; | ||
sep = lineEnd < end && src[lineEnd] || ''; | ||
prevMoreIndented = true; | ||
} else { | ||
str += sep + line; | ||
sep = folded && i < keepStart ? ' ' : '\n'; | ||
prevMoreIndented = false; | ||
if (!this.blockIndent) { | ||
// no explicit block indent, none yet detected | ||
const lineIndent = end - (offset + indent); | ||
if (src[end] !== '\n') { | ||
// first line with non-whitespace content | ||
if (lineIndent < minBlockIndent) { | ||
offset -= 1; | ||
break; | ||
} | ||
if (atStart && line !== '') atStart = false; | ||
this.blockIndent = lineIndent; | ||
bi = indent + this.blockIndent - 1; | ||
} else if (lineIndent > minBlockIndent) { | ||
// empty line with more whitespace | ||
minBlockIndent = lineIndent; | ||
} | ||
} | ||
return this.chomping === Chomp.STRIP ? str : str + '\n'; | ||
offset = _Node.default.endOfLine(src, end); | ||
} | ||
}]); | ||
return BlockValue; | ||
}(_Node2.default); | ||
this.valueRange = new _Range.default(start + 1, offset); | ||
return offset; | ||
} | ||
/** | ||
* Parses a block value from the source | ||
* | ||
* Accepted forms are: | ||
* ``` | ||
* BS | ||
* block | ||
* lines | ||
* | ||
* BS #comment | ||
* block | ||
* lines | ||
* ``` | ||
* where the block style BS matches the regexp `[|>][-+1-9]*` and block lines | ||
* are empty or have an indent level greater than `indent`. | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this block | ||
*/ | ||
parse(context, start) { | ||
this.context = context; | ||
const src = context.src; | ||
let offset = this.parseBlockHeader(start); | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
offset = this.parseBlockValue(offset); | ||
return offset; | ||
} | ||
setOrigRanges(cr, offset) { | ||
offset = super.setOrigRanges(cr, offset); | ||
return this.header ? this.header.setOrigRange(cr, offset) : offset; | ||
} | ||
} | ||
exports.default = BlockValue; |
@@ -12,3 +12,3 @@ "use strict"; | ||
var _Node2 = _interopRequireWildcard(require("./Node")); | ||
var _Node = _interopRequireWildcard(require("./Node")); | ||
@@ -21,39 +21,13 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
class Collection extends _Node.default { | ||
constructor(firstItem) { | ||
super(firstItem.type === _Node.Type.SEQ_ITEM ? _Node.Type.SEQ : _Node.Type.MAP); | ||
this.items = [firstItem]; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var Collection = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(Collection, _Node); | ||
function Collection(firstItem) { | ||
var _this; | ||
_classCallCheck(this, Collection); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Collection).call(this, firstItem.type === _Node2.Type.SEQ_ITEM ? _Node2.Type.SEQ : _Node2.Type.MAP)); | ||
_this.items = [firstItem]; | ||
for (var i = firstItem.props.length - 1; i >= 0; --i) { | ||
for (let i = firstItem.props.length - 1; i >= 0; --i) { | ||
if (firstItem.props[i].start < firstItem.context.lineStart) { | ||
// props on previous line are assumed by the collection | ||
_this.props = firstItem.props.slice(0, i + 1); | ||
this.props = firstItem.props.slice(0, i + 1); | ||
firstItem.props = firstItem.props.slice(i + 1); | ||
var itemRange = firstItem.props[0] || firstItem.valueRange; | ||
const itemRange = firstItem.props[0] || firstItem.valueRange; | ||
firstItem.range.start = itemRange.start; | ||
@@ -63,4 +37,2 @@ break; | ||
} | ||
return _this; | ||
} | ||
@@ -74,138 +46,141 @@ /** | ||
_createClass(Collection, [{ | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var parseNode = context.parseNode, | ||
parse(context, start) { | ||
this.context = context; | ||
const parseNode = context.parseNode, | ||
src = context.src; // It's easier to recalculate lineStart here rather than tracking down the | ||
// last context from which to read it -- eemeli/yaml#2 | ||
// last context from which to read it -- eemeli/yaml#2 | ||
var lineStart = _Node2.default.startOfLine(src, start); | ||
let lineStart = _Node.default.startOfLine(src, start); | ||
var firstItem = this.items[0]; // First-item context needs to be correct for later comment handling | ||
// -- eemeli/yaml#17 | ||
const firstItem = this.items[0]; // First-item context needs to be correct for later comment handling | ||
// -- eemeli/yaml#17 | ||
firstItem.context.parent = this; | ||
this.valueRange = _Range.default.copy(firstItem.valueRange); | ||
var indent = firstItem.range.start - firstItem.context.lineStart; | ||
var offset = start; | ||
offset = _Node2.default.normalizeOffset(src, offset); | ||
var ch = src[offset]; | ||
var atLineStart = _Node2.default.endOfWhiteSpace(src, lineStart) === offset; | ||
firstItem.context.parent = this; | ||
this.valueRange = _Range.default.copy(firstItem.valueRange); | ||
const indent = firstItem.range.start - firstItem.context.lineStart; | ||
let offset = start; | ||
offset = _Node.default.normalizeOffset(src, offset); | ||
let ch = src[offset]; | ||
let atLineStart = _Node.default.endOfWhiteSpace(src, lineStart) === offset; | ||
while (ch) { | ||
while (ch === '\n' || ch === '#') { | ||
if (ch === '#') { | ||
var comment = new _Comment.default(); | ||
offset = comment.parse({ | ||
src: src | ||
}, offset); | ||
this.items.push(comment); | ||
this.valueRange.end = offset; | ||
while (ch) { | ||
while (ch === '\n' || ch === '#') { | ||
if (ch === '#') { | ||
const comment = new _Comment.default(); | ||
offset = comment.parse({ | ||
src | ||
}, offset); | ||
this.items.push(comment); | ||
this.valueRange.end = offset; | ||
if (offset >= src.length) { | ||
ch = null; | ||
break; | ||
} | ||
if (offset >= src.length) { | ||
ch = null; | ||
break; | ||
} | ||
} | ||
lineStart = offset + 1; | ||
offset = _Node2.default.endOfIndent(src, lineStart); | ||
lineStart = offset + 1; | ||
offset = _Node.default.endOfIndent(src, lineStart); | ||
if (_Node2.default.atBlank(src, offset)) { | ||
var wsEnd = _Node2.default.endOfWhiteSpace(src, offset); | ||
if (_Node.default.atBlank(src, offset)) { | ||
const wsEnd = _Node.default.endOfWhiteSpace(src, offset); | ||
var next = src[wsEnd]; | ||
const next = src[wsEnd]; | ||
if (!next || next === '\n' || next === '#') { | ||
offset = wsEnd; | ||
} | ||
if (!next || next === '\n' || next === '#') { | ||
offset = wsEnd; | ||
} | ||
ch = src[offset]; | ||
atLineStart = true; | ||
} | ||
if (!ch) { | ||
break; | ||
ch = src[offset]; | ||
atLineStart = true; | ||
} | ||
if (!ch) { | ||
break; | ||
} | ||
if (offset !== lineStart + indent && (atLineStart || ch !== ':')) { | ||
if (lineStart > start) offset = lineStart; | ||
break; | ||
} | ||
if (firstItem.type === _Node.Type.SEQ_ITEM !== (ch === '-')) { | ||
let typeswitch = true; | ||
if (ch === '-') { | ||
// map key may start with -, as long as it's followed by a non-whitespace char | ||
const next = src[offset + 1]; | ||
typeswitch = !next || next === '\n' || next === '\t' || next === ' '; | ||
} | ||
if (offset !== lineStart + indent && (atLineStart || ch !== ':')) { | ||
if (typeswitch) { | ||
if (lineStart > start) offset = lineStart; | ||
break; | ||
} | ||
} | ||
if (firstItem.type === _Node2.Type.SEQ_ITEM !== (ch === '-')) { | ||
var typeswitch = true; | ||
const node = parseNode({ | ||
atLineStart, | ||
inCollection: true, | ||
indent, | ||
lineStart, | ||
parent: this | ||
}, offset); | ||
if (!node) return offset; // at next document start | ||
if (ch === '-') { | ||
// map key may start with -, as long as it's followed by a non-whitespace char | ||
var _next = src[offset + 1]; | ||
typeswitch = !_next || _next === '\n' || _next === '\t' || _next === ' '; | ||
} | ||
this.items.push(node); | ||
this.valueRange.end = node.valueRange.end; | ||
offset = _Node.default.normalizeOffset(src, node.range.end); | ||
ch = src[offset]; | ||
atLineStart = false; // Need to reset lineStart and atLineStart here if preceding node's range | ||
// has advanced to check the current line's indentation level | ||
// -- eemeli/yaml#10 & eemeli/yaml#38 | ||
if (typeswitch) { | ||
if (lineStart > start) offset = lineStart; | ||
break; | ||
} | ||
} | ||
if (ch && ch !== '\n' && ch !== '#') { | ||
let ls = offset - 1; | ||
let prev = src[ls]; | ||
var node = parseNode({ | ||
atLineStart: atLineStart, | ||
inCollection: true, | ||
indent: indent, | ||
lineStart: lineStart, | ||
parent: this | ||
}, offset); | ||
if (!node) return offset; // at next document start | ||
while (prev === ' ' || prev === '\t') prev = src[--ls]; | ||
this.items.push(node); | ||
this.valueRange.end = node.valueRange.end; | ||
offset = _Node2.default.normalizeOffset(src, node.range.end); | ||
ch = src[offset]; | ||
atLineStart = false; // Need to reset lineStart here if preceding node's range has advanced to | ||
// check the current line's indentation level -- eemeli/yaml#10 | ||
if (prev === '\n') { | ||
lineStart = ls + 1; | ||
atLineStart = true; | ||
} | ||
} | ||
} | ||
if (ch && ch !== '\n' && ch !== '#') { | ||
var ls = offset - 1; | ||
var prev = src[ls]; | ||
return offset; | ||
} | ||
while (prev === ' ' || prev === '\t') { | ||
prev = src[--ls]; | ||
} | ||
setOrigRanges(cr, offset) { | ||
offset = super.setOrigRanges(cr, offset); | ||
this.items.forEach(node => { | ||
offset = node.setOrigRanges(cr, offset); | ||
}); | ||
return offset; | ||
} | ||
if (prev === '\n') lineStart = ls + 1; | ||
} | ||
} | ||
return offset; | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
var src = this.context.src, | ||
toString() { | ||
const src = this.context.src, | ||
items = this.items, | ||
range = this.range, | ||
value = this.value; | ||
if (value != null) return value; | ||
var str = src.slice(range.start, items[0].range.start) + String(items[0]); | ||
if (value != null) return value; | ||
let str = src.slice(range.start, items[0].range.start) + String(items[0]); | ||
for (var i = 1; i < items.length; ++i) { | ||
var item = items[i]; | ||
var _item$context = item.context, | ||
for (let i = 1; i < items.length; ++i) { | ||
const item = items[i]; | ||
const _item$context = item.context, | ||
atLineStart = _item$context.atLineStart, | ||
indent = _item$context.indent; | ||
if (atLineStart) for (var _i = 0; _i < indent; ++_i) { | ||
str += ' '; | ||
} | ||
str += String(item); | ||
} | ||
return _Node2.default.addStringTerminator(src, range.end, str); | ||
if (atLineStart) for (let i = 0; i < indent; ++i) str += ' '; | ||
str += String(item); | ||
} | ||
}]); | ||
return Collection; | ||
}(_Node2.default); | ||
return _Node.default.addStringTerminator(src, range.end, str); | ||
} | ||
} | ||
exports.default = Collection; |
@@ -10,3 +10,3 @@ "use strict"; | ||
var _Node2 = _interopRequireWildcard(require("./Node")); | ||
var _Node = _interopRequireWildcard(require("./Node")); | ||
@@ -19,33 +19,6 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var CollectionItem = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(CollectionItem, _Node); | ||
function CollectionItem(type, props) { | ||
var _this; | ||
_classCallCheck(this, CollectionItem); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(CollectionItem).call(this, type, props)); | ||
_this.node = null; | ||
return _this; | ||
class CollectionItem extends _Node.default { | ||
constructor(type, props) { | ||
super(type, props); | ||
this.node = null; | ||
} | ||
@@ -59,67 +32,67 @@ /** | ||
_createClass(CollectionItem, [{ | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var parseNode = context.parseNode, | ||
parse(context, start) { | ||
this.context = context; | ||
const parseNode = context.parseNode, | ||
src = context.src; | ||
var atLineStart = context.atLineStart, | ||
lineStart = context.lineStart; | ||
if (!atLineStart && this.type === _Node2.Type.SEQ_ITEM) this.error = new _errors.YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line'); | ||
var indent = atLineStart ? start - lineStart : context.indent; | ||
let atLineStart = context.atLineStart, | ||
lineStart = context.lineStart; | ||
if (!atLineStart && this.type === _Node.Type.SEQ_ITEM) this.error = new _errors.YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line'); | ||
const indent = atLineStart ? start - lineStart : context.indent; | ||
var offset = _Node2.default.endOfWhiteSpace(src, start + 1); | ||
let offset = _Node.default.endOfWhiteSpace(src, start + 1); | ||
var ch = src[offset]; | ||
let ch = src[offset]; | ||
while (ch === '\n' || ch === '#') { | ||
var next = offset + 1; | ||
while (ch === '\n' || ch === '#') { | ||
const next = offset + 1; | ||
if (ch === '#') { | ||
var _end = _Node2.default.endOfLine(src, next); | ||
if (ch === '#') { | ||
const end = _Node.default.endOfLine(src, next); | ||
this.props.push(new _Range.default(offset, _end)); | ||
offset = _end; | ||
} else { | ||
atLineStart = true; | ||
lineStart = next; | ||
offset = _Node2.default.endOfWhiteSpace(src, next); // against spec, to match \t allowed after indicator | ||
} | ||
ch = src[offset]; | ||
this.props.push(new _Range.default(offset, end)); | ||
offset = end; | ||
} else { | ||
atLineStart = true; | ||
lineStart = next; | ||
offset = _Node.default.endOfWhiteSpace(src, next); // against spec, to match \t allowed after indicator | ||
} | ||
if (_Node2.default.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== _Node2.Type.SEQ_ITEM)) { | ||
this.node = parseNode({ | ||
atLineStart: atLineStart, | ||
inCollection: false, | ||
indent: indent, | ||
lineStart: lineStart, | ||
parent: this | ||
}, offset); | ||
if (this.node) offset = this.node.range.end; | ||
} else if (lineStart > start + 1) { | ||
offset = lineStart - 1; | ||
} | ||
ch = src[offset]; | ||
} | ||
var end = this.node ? this.node.valueRange.end : offset; | ||
this.valueRange = new _Range.default(start, end); | ||
return offset; | ||
if (_Node.default.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== _Node.Type.SEQ_ITEM)) { | ||
this.node = parseNode({ | ||
atLineStart, | ||
inCollection: false, | ||
indent, | ||
lineStart, | ||
parent: this | ||
}, offset); | ||
if (this.node) offset = this.node.range.end; | ||
} else if (ch && lineStart > start + 1) { | ||
offset = lineStart - 1; | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
var src = this.context.src, | ||
const end = this.node ? this.node.valueRange.end : offset; | ||
this.valueRange = new _Range.default(start, end); | ||
return offset; | ||
} | ||
setOrigRanges(cr, offset) { | ||
offset = super.setOrigRanges(cr, offset); | ||
return this.node ? this.node.setOrigRanges(cr, offset) : offset; | ||
} | ||
toString() { | ||
const src = this.context.src, | ||
node = this.node, | ||
range = this.range, | ||
value = this.value; | ||
if (value != null) return value; | ||
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); | ||
} | ||
}]); | ||
if (value != null) return value; | ||
const str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end); | ||
return _Node.default.addStringTerminator(src, range.end, str); | ||
} | ||
return CollectionItem; | ||
}(_Node2.default); | ||
} | ||
exports.default = CollectionItem; |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _Node2 = _interopRequireWildcard(require("./Node")); | ||
var _Node = _interopRequireWildcard(require("./Node")); | ||
@@ -17,29 +17,5 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var Comment = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(Comment, _Node); | ||
function Comment() { | ||
_classCallCheck(this, Comment); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(Comment).call(this, _Node2.Type.COMMENT)); | ||
class Comment extends _Node.default { | ||
constructor() { | ||
super(_Node.Type.COMMENT); | ||
} | ||
@@ -55,16 +31,12 @@ /** | ||
_createClass(Comment, [{ | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var src = context.src; | ||
var offset = this.parseComment(start); | ||
this.range = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
}]); | ||
parse(context, start) { | ||
this.context = context; | ||
const src = context.src; | ||
let offset = this.parseComment(start); | ||
this.range = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
return Comment; | ||
}(_Node2.default); | ||
} | ||
exports.default = Comment; |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _Node2 = _interopRequireWildcard(require("./Node")); | ||
var _Node = _interopRequireWildcard(require("./Node")); | ||
@@ -17,106 +17,63 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
class Directive extends _Node.default { | ||
static endOfDirective(src, offset) { | ||
let ch = src[offset]; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
while (ch && ch !== '\n' && ch !== '#') ch = src[offset += 1]; // last char can't be whitespace | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
ch = src[offset - 1]; | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
while (ch === ' ' || ch === '\t') { | ||
offset -= 1; | ||
ch = src[offset - 1]; | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
return offset; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
constructor() { | ||
super(_Node.Type.DIRECTIVE); | ||
this.name = null; | ||
} | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
get parameters() { | ||
const raw = this.rawValue; | ||
return raw ? raw.trim().split(/[ \t]+/) : []; | ||
} | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
parseName(start) { | ||
const src = this.context.src; | ||
let offset = start; | ||
let ch = src[offset]; | ||
var Directive = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(Directive, _Node); | ||
while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') ch = src[offset += 1]; | ||
_createClass(Directive, null, [{ | ||
key: "endOfDirective", | ||
value: function endOfDirective(src, offset) { | ||
var ch = src[offset]; | ||
this.name = src.slice(start, offset); | ||
return offset; | ||
} | ||
while (ch && ch !== '\n' && ch !== '#') { | ||
ch = src[offset += 1]; | ||
} // last char can't be whitespace | ||
parseParameters(start) { | ||
const src = this.context.src; | ||
let offset = start; | ||
let ch = src[offset]; | ||
while (ch && ch !== '\n' && ch !== '#') ch = src[offset += 1]; | ||
ch = src[offset - 1]; | ||
this.valueRange = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
while (ch === ' ' || ch === '\t') { | ||
offset -= 1; | ||
ch = src[offset - 1]; | ||
} | ||
return offset; | ||
} | ||
}]); | ||
function Directive() { | ||
var _this; | ||
_classCallCheck(this, Directive); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Directive).call(this, _Node2.Type.DIRECTIVE)); | ||
_this.name = null; | ||
return _this; | ||
parse(context, start) { | ||
this.context = context; | ||
const src = context.src; | ||
let offset = this.parseName(start + 1); | ||
offset = this.parseParameters(offset); | ||
offset = this.parseComment(offset); | ||
this.range = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
_createClass(Directive, [{ | ||
key: "parseName", | ||
value: function parseName(start) { | ||
var src = this.context.src; | ||
var offset = start; | ||
var ch = src[offset]; | ||
} | ||
while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') { | ||
ch = src[offset += 1]; | ||
} | ||
this.name = src.slice(start, offset); | ||
return offset; | ||
} | ||
}, { | ||
key: "parseParameters", | ||
value: function parseParameters(start) { | ||
var src = this.context.src; | ||
var offset = start; | ||
var ch = src[offset]; | ||
while (ch && ch !== '\n' && ch !== '#') { | ||
ch = src[offset += 1]; | ||
} | ||
this.valueRange = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
}, { | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var src = context.src; | ||
var offset = this.parseName(start + 1); | ||
offset = this.parseParameters(offset); | ||
offset = this.parseComment(offset); | ||
this.range = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
}, { | ||
key: "parameters", | ||
get: function get() { | ||
var raw = this.rawValue; | ||
return raw ? raw.trim().split(/[ \t]+/) : []; | ||
} | ||
}]); | ||
return Directive; | ||
}(_Node2.default); | ||
exports.default = Directive; |
@@ -14,3 +14,3 @@ "use strict"; | ||
var _Node2 = _interopRequireWildcard(require("./Node")); | ||
var _Node = _interopRequireWildcard(require("./Node")); | ||
@@ -23,239 +23,211 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
class Document extends _Node.default { | ||
static startCommentOrEndBlankLine(src, start) { | ||
const offset = _Node.default.endOfWhiteSpace(src, start); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
const ch = src[offset]; | ||
return ch === '#' || ch === '\n' ? offset : start; | ||
} | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
constructor() { | ||
super(_Node.Type.DOCUMENT); | ||
this.directives = null; | ||
this.contents = null; | ||
} | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
parseDirectives(start) { | ||
const src = this.context.src; | ||
this.directives = []; | ||
let hasDirectives = false; | ||
let offset = start; | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
while (!_Node.default.atDocumentBoundary(src, offset, _Node.Char.DIRECTIVES_END)) { | ||
offset = Document.startCommentOrEndBlankLine(src, offset); | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
switch (src[offset]) { | ||
case '\n': | ||
offset += 1; | ||
break; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
case '#': | ||
{ | ||
const comment = new _Comment.default(); | ||
offset = comment.parse({ | ||
src | ||
}, offset); | ||
this.directives.push(comment); | ||
} | ||
break; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
case '%': | ||
{ | ||
const directive = new _Directive.default(); | ||
offset = directive.parse({ | ||
parent: this, | ||
src | ||
}, offset); | ||
this.directives.push(directive); | ||
hasDirectives = true; | ||
} | ||
break; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
default: | ||
if (hasDirectives) { | ||
this.error = new _errors.YAMLSemanticError(this, 'Missing directives-end indicator line'); | ||
} else if (this.directives.length > 0) { | ||
this.contents = this.directives; | ||
this.directives = []; | ||
} | ||
var Document = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(Document, _Node); | ||
return offset; | ||
} | ||
} | ||
_createClass(Document, null, [{ | ||
key: "startCommentOrEndBlankLine", | ||
value: function startCommentOrEndBlankLine(src, start) { | ||
var offset = _Node2.default.endOfWhiteSpace(src, start); | ||
if (src[offset]) return offset + 3; | ||
var ch = src[offset]; | ||
return ch === '#' || ch === '\n' ? offset : start; | ||
if (hasDirectives) { | ||
this.error = new _errors.YAMLSemanticError(this, 'Missing directives-end indicator line'); | ||
} else if (this.directives.length > 0) { | ||
this.contents = this.directives; | ||
this.directives = []; | ||
} | ||
}]); | ||
function Document() { | ||
var _this; | ||
_classCallCheck(this, Document); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Document).call(this, _Node2.Type.DOCUMENT)); | ||
_this.directives = null; | ||
_this.contents = null; | ||
return _this; | ||
return offset; | ||
} | ||
_createClass(Document, [{ | ||
key: "parseDirectives", | ||
value: function parseDirectives(start) { | ||
var src = this.context.src; | ||
this.directives = []; | ||
var hasDirectives = false; | ||
var offset = start; | ||
parseContents(start) { | ||
const _this$context = this.context, | ||
parseNode = _this$context.parseNode, | ||
src = _this$context.src; | ||
if (!this.contents) this.contents = []; | ||
let lineStart = start; | ||
while (!_Node2.default.atDocumentBoundary(src, offset, _Node2.Char.DIRECTIVES_END)) { | ||
offset = Document.startCommentOrEndBlankLine(src, offset); | ||
while (src[lineStart - 1] === '-') lineStart -= 1; | ||
switch (src[offset]) { | ||
case '\n': | ||
offset += 1; | ||
break; | ||
let offset = _Node.default.endOfWhiteSpace(src, start); | ||
case '#': | ||
{ | ||
var comment = new _Comment.default(); | ||
offset = comment.parse({ | ||
src: src | ||
}, offset); | ||
this.directives.push(comment); | ||
} | ||
break; | ||
let atLineStart = lineStart === start; | ||
this.valueRange = new _Range.default(offset); | ||
case '%': | ||
{ | ||
var directive = new _Directive.default(); | ||
offset = directive.parse({ | ||
parent: this, | ||
src: src | ||
}, offset); | ||
this.directives.push(directive); | ||
hasDirectives = true; | ||
} | ||
break; | ||
while (!_Node.default.atDocumentBoundary(src, offset, _Node.Char.DOCUMENT_END)) { | ||
switch (src[offset]) { | ||
case '\n': | ||
offset += 1; | ||
lineStart = offset; | ||
atLineStart = true; | ||
break; | ||
default: | ||
if (hasDirectives) { | ||
this.error = new _errors.YAMLSemanticError(this, 'Missing directives-end indicator line'); | ||
} else if (this.directives.length > 0) { | ||
this.contents = this.directives; | ||
this.directives = []; | ||
} | ||
case '#': | ||
{ | ||
const comment = new _Comment.default(); | ||
offset = comment.parse({ | ||
src | ||
}, offset); | ||
this.contents.push(comment); | ||
} | ||
break; | ||
return offset; | ||
} | ||
} | ||
default: | ||
{ | ||
const iEnd = _Node.default.endOfIndent(src, offset); | ||
if (src[offset]) return offset + 3; | ||
const context = { | ||
atLineStart, | ||
indent: -1, | ||
inFlow: false, | ||
inCollection: false, | ||
lineStart, | ||
parent: this | ||
}; | ||
const node = parseNode(context, iEnd); | ||
if (!node) return this.valueRange.end = iEnd; // at next document start | ||
if (hasDirectives) { | ||
this.error = new _errors.YAMLSemanticError(this, 'Missing directives-end indicator line'); | ||
} else if (this.directives.length > 0) { | ||
this.contents = this.directives; | ||
this.directives = []; | ||
this.contents.push(node); | ||
offset = node.range.end; | ||
atLineStart = false; | ||
} | ||
} | ||
return offset; | ||
offset = Document.startCommentOrEndBlankLine(src, offset); | ||
} | ||
}, { | ||
key: "parseContents", | ||
value: function parseContents(start) { | ||
var _this$context = this.context, | ||
parseNode = _this$context.parseNode, | ||
src = _this$context.src; | ||
if (!this.contents) this.contents = []; | ||
var lineStart = start; | ||
while (src[lineStart - 1] === '-') { | ||
lineStart -= 1; | ||
} | ||
this.valueRange.end = offset; | ||
var offset = _Node2.default.endOfWhiteSpace(src, start); | ||
if (src[offset]) { | ||
offset += 3; | ||
var atLineStart = lineStart === start; | ||
this.valueRange = new _Range.default(offset); | ||
if (src[offset]) { | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
while (!_Node2.default.atDocumentBoundary(src, offset, _Node2.Char.DOCUMENT_END)) { | ||
if (src[offset] === '#') { | ||
const comment = new _Comment.default(); | ||
offset = comment.parse({ | ||
src | ||
}, offset); | ||
this.contents.push(comment); | ||
} | ||
switch (src[offset]) { | ||
case '\n': | ||
offset += 1; | ||
lineStart = offset; | ||
atLineStart = true; | ||
break; | ||
case '#': | ||
{ | ||
var comment = new _Comment.default(); | ||
offset = comment.parse({ | ||
src: src | ||
}, offset); | ||
this.contents.push(comment); | ||
} | ||
case undefined: | ||
break; | ||
default: | ||
{ | ||
var iEnd = _Node2.default.endOfIndent(src, offset); | ||
var context = { | ||
atLineStart: atLineStart, | ||
indent: -1, | ||
inFlow: false, | ||
inCollection: false, | ||
lineStart: lineStart, | ||
parent: this | ||
}; | ||
var node = parseNode(context, iEnd); | ||
if (!node) return iEnd; // at next document start | ||
this.contents.push(node); | ||
this.valueRange.end = node.valueRange.end; | ||
offset = node.range.end; | ||
atLineStart = false; | ||
} | ||
this.error = new _errors.YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix'); | ||
} | ||
offset = Document.startCommentOrEndBlankLine(src, offset); | ||
} | ||
} | ||
if (src[offset]) { | ||
offset += 3; | ||
return offset; | ||
} | ||
/** | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this | ||
*/ | ||
if (src[offset]) { | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
if (src[offset] === '#') { | ||
var _comment = new _Comment.default(); | ||
parse(context, start) { | ||
this.context = context; | ||
const src = context.src; | ||
let offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM | ||
offset = _comment.parse({ | ||
src: src | ||
}, offset); | ||
this.contents.push(_comment); | ||
} | ||
offset = this.parseDirectives(offset); | ||
offset = this.parseContents(offset); | ||
return offset; | ||
} | ||
switch (src[offset]) { | ||
case '\n': | ||
offset += 1; | ||
break; | ||
setOrigRanges(cr, offset) { | ||
offset = super.setOrigRanges(cr, offset); | ||
this.directives.forEach(node => { | ||
offset = node.setOrigRanges(cr, offset); | ||
}); | ||
this.contents.forEach(node => { | ||
offset = node.setOrigRanges(cr, offset); | ||
}); | ||
return offset; | ||
} | ||
case undefined: | ||
break; | ||
default: | ||
this.error = new _errors.YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix'); | ||
} | ||
} | ||
} | ||
return offset; | ||
} | ||
/** | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this | ||
*/ | ||
}, { | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var src = context.src; | ||
var offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM | ||
offset = this.parseDirectives(offset); | ||
offset = this.parseContents(offset); | ||
return offset; | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
var contents = this.contents, | ||
toString() { | ||
const contents = this.contents, | ||
src = this.context.src, | ||
directives = this.directives, | ||
value = this.value; | ||
if (value != null) return value; | ||
var str = directives.join(''); | ||
if (value != null) return value; | ||
let str = directives.join(''); | ||
if (contents.length > 0) { | ||
if (directives.length > 0 || contents[0].type === _Node2.Type.COMMENT) str += '---\n'; | ||
str += contents.join(''); | ||
} | ||
if (str[str.length - 1] !== '\n') str += '\n'; | ||
return str; | ||
if (contents.length > 0) { | ||
if (directives.length > 0 || contents[0].type === _Node.Type.COMMENT) str += '---\n'; | ||
str += contents.join(''); | ||
} | ||
}]); | ||
return Document; | ||
}(_Node2.default); | ||
if (str[str.length - 1] !== '\n') str += '\n'; | ||
return str; | ||
} | ||
} | ||
exports.default = Document; |
@@ -12,3 +12,3 @@ "use strict"; | ||
var _Node2 = _interopRequireWildcard(require("./Node")); | ||
var _Node = _interopRequireWildcard(require("./Node")); | ||
@@ -21,167 +21,151 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
class FlowCollection extends _Node.default { | ||
constructor(type, props) { | ||
super(type, props); | ||
this.items = null; | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
prevNodeIsJsonLike(idx = this.items.length) { | ||
const node = this.items[idx - 1]; | ||
return !!node && (node.jsonLike || node.type === _Node.Type.COMMENT && this.nodeIsJsonLike(idx - 1)); | ||
} | ||
/** | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this | ||
*/ | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
parse(context, start) { | ||
this.context = context; | ||
const parseNode = context.parseNode, | ||
src = context.src; | ||
let indent = context.indent, | ||
lineStart = context.lineStart; | ||
let char = src[start]; // { or [ | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
this.items = [{ | ||
char, | ||
offset: start | ||
}]; | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
let offset = _Node.default.endOfWhiteSpace(src, start + 1); | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
char = src[offset]; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
while (char && char !== ']' && char !== '}') { | ||
switch (char) { | ||
case '\n': | ||
{ | ||
lineStart = offset + 1; | ||
offset = _Node.default.endOfIndent(src, lineStart); | ||
if (offset - lineStart <= indent) this.error = new _errors.YAMLSemanticError(this, 'Insufficient indentation in flow collection'); | ||
} | ||
break; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
case ',': | ||
{ | ||
this.items.push({ | ||
char, | ||
offset | ||
}); | ||
offset += 1; | ||
} | ||
break; | ||
var FlowCollection = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(FlowCollection, _Node); | ||
case '#': | ||
{ | ||
const comment = new _Comment.default(); | ||
offset = comment.parse({ | ||
src | ||
}, offset); | ||
this.items.push(comment); | ||
} | ||
break; | ||
function FlowCollection(type, props) { | ||
var _this; | ||
case '?': | ||
case ':': | ||
{ | ||
const next = src[offset + 1]; | ||
_classCallCheck(this, FlowCollection); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(FlowCollection).call(this, type, props)); | ||
_this.items = null; | ||
return _this; | ||
} | ||
_createClass(FlowCollection, [{ | ||
key: "prevNodeIsJsonLike", | ||
value: function prevNodeIsJsonLike() { | ||
var idx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.items.length; | ||
var node = this.items[idx - 1]; | ||
return !!node && (node.jsonLike || node.type === _Node2.Type.COMMENT && this.nodeIsJsonLike(idx - 1)); | ||
} | ||
/** | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this | ||
*/ | ||
}, { | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var parseNode = context.parseNode, | ||
src = context.src; | ||
var indent = context.indent, | ||
lineStart = context.lineStart; | ||
var ch = src[start]; // { or [ | ||
this.items = [ch]; | ||
var offset = _Node2.default.endOfWhiteSpace(src, start + 1); | ||
ch = src[offset]; | ||
while (ch && ch !== ']' && ch !== '}') { | ||
switch (ch) { | ||
case '\n': | ||
{ | ||
lineStart = offset + 1; | ||
offset = _Node2.default.endOfIndent(src, lineStart); | ||
if (offset - lineStart <= indent) this.error = new _errors.YAMLSemanticError(this, 'Insufficient indentation in flow collection'); | ||
} | ||
break; | ||
case ',': | ||
{ | ||
this.items.push(ch); | ||
if (next === '\n' || next === '\t' || next === ' ' || next === ',' || // in-flow : after JSON-like key does not need to be followed by whitespace | ||
char === ':' && this.prevNodeIsJsonLike()) { | ||
this.items.push({ | ||
char, | ||
offset | ||
}); | ||
offset += 1; | ||
} | ||
break; | ||
break; | ||
} // fallthrough | ||
case '#': | ||
{ | ||
var comment = new _Comment.default(); | ||
offset = comment.parse({ | ||
src: src | ||
}, offset); | ||
this.items.push(comment); | ||
} | ||
break; | ||
} | ||
case '?': | ||
case ':': | ||
{ | ||
var next = src[offset + 1]; | ||
default: | ||
{ | ||
const node = parseNode({ | ||
atLineStart: false, | ||
inCollection: false, | ||
inFlow: true, | ||
indent: -1, | ||
lineStart, | ||
parent: this | ||
}, offset); | ||
if (next === '\n' || next === '\t' || next === ' ' || next === ',' || // in-flow : after JSON-like key does not need to be followed by whitespace | ||
ch === ':' && this.prevNodeIsJsonLike()) { | ||
this.items.push(ch); | ||
offset += 1; | ||
break; | ||
} // fallthrough | ||
if (!node) { | ||
// at next document start | ||
this.valueRange = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
default: | ||
{ | ||
var node = parseNode({ | ||
atLineStart: false, | ||
inCollection: false, | ||
inFlow: true, | ||
indent: -1, | ||
lineStart: lineStart, | ||
parent: this | ||
}, offset); | ||
this.items.push(node); | ||
offset = _Node.default.normalizeOffset(src, node.range.end); | ||
} | ||
} | ||
if (!node) { | ||
// at next document start | ||
this.valueRange = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
char = src[offset]; | ||
} | ||
this.items.push(node); | ||
offset = _Node2.default.normalizeOffset(src, node.range.end); | ||
} | ||
} | ||
this.valueRange = new _Range.default(start, offset + 1); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
ch = src[offset]; | ||
} | ||
if (char) { | ||
this.items.push({ | ||
char, | ||
offset | ||
}); | ||
offset = _Node.default.endOfWhiteSpace(src, offset + 1); | ||
offset = this.parseComment(offset); | ||
} | ||
this.valueRange = new _Range.default(start, offset + 1); | ||
return offset; | ||
} | ||
if (ch) { | ||
this.items.push(ch); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset + 1); | ||
offset = this.parseComment(offset); | ||
} | ||
setOrigRanges(cr, offset) { | ||
offset = super.setOrigRanges(cr, offset); | ||
this.items.forEach(node => { | ||
offset = node.setOrigRanges(cr, offset); | ||
}); | ||
return offset; | ||
} | ||
return offset; | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
var src = this.context.src, | ||
toString() { | ||
const src = this.context.src, | ||
items = this.items, | ||
range = this.range, | ||
value = this.value; | ||
if (value != null) return value; | ||
var nodes = items.filter(function (item) { | ||
return item instanceof _Node2.default; | ||
}); | ||
var str = ''; | ||
var prevEnd = range.start; | ||
nodes.forEach(function (node) { | ||
var prefix = src.slice(prevEnd, node.range.start); | ||
prevEnd = node.range.end; | ||
str += prefix + String(node); | ||
}); | ||
str += src.slice(prevEnd, range.end); | ||
return _Node2.default.addStringTerminator(src, range.end, str); | ||
} | ||
}]); | ||
if (value != null) return value; | ||
const nodes = items.filter(item => item instanceof _Node.default); | ||
let str = ''; | ||
let prevEnd = range.start; | ||
nodes.forEach(node => { | ||
const prefix = src.slice(prevEnd, node.range.start); | ||
prevEnd = node.range.end; | ||
str += prefix + String(node); | ||
}); | ||
str += src.slice(prevEnd, range.end); | ||
return _Node.default.addStringTerminator(src, range.end, str); | ||
} | ||
return FlowCollection; | ||
}(_Node2.default); | ||
} | ||
exports.default = FlowCollection; |
@@ -20,9 +20,3 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var Type = { | ||
const Type = { | ||
ALIAS: 'ALIAS', | ||
@@ -46,3 +40,3 @@ BLOCK_FOLDED: 'BLOCK_FOLDED', | ||
exports.Type = Type; | ||
var Char = { | ||
const Char = { | ||
ANCHOR: '&', | ||
@@ -58,187 +52,159 @@ COMMENT: '#', | ||
var Node = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(Node, null, [{ | ||
key: "addStringTerminator", | ||
value: function addStringTerminator(src, offset, str) { | ||
if (str[str.length - 1] === '\n') return str; | ||
var next = Node.endOfWhiteSpace(src, offset); | ||
return next >= src.length || src[next] === '\n' ? str + '\n' : str; | ||
} // ^(---|...) | ||
class Node { | ||
static addStringTerminator(src, offset, str) { | ||
if (str[str.length - 1] === '\n') return str; | ||
const next = Node.endOfWhiteSpace(src, offset); | ||
return next >= src.length || src[next] === '\n' ? str + '\n' : str; | ||
} // ^(---|...) | ||
}, { | ||
key: "atDocumentBoundary", | ||
value: function atDocumentBoundary(src, offset, sep) { | ||
var ch0 = src[offset]; | ||
if (!ch0) return true; | ||
var prev = src[offset - 1]; | ||
if (prev && prev !== '\n') return false; | ||
if (sep) { | ||
if (ch0 !== sep) return false; | ||
} else { | ||
if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false; | ||
} | ||
static atDocumentBoundary(src, offset, sep) { | ||
const ch0 = src[offset]; | ||
if (!ch0) return true; | ||
const prev = src[offset - 1]; | ||
if (prev && prev !== '\n') return false; | ||
var ch1 = src[offset + 1]; | ||
var ch2 = src[offset + 2]; | ||
if (ch1 !== ch0 || ch2 !== ch0) return false; | ||
var ch3 = src[offset + 3]; | ||
return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' '; | ||
if (sep) { | ||
if (ch0 !== sep) return false; | ||
} else { | ||
if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false; | ||
} | ||
}, { | ||
key: "endOfIdentifier", | ||
value: function endOfIdentifier(src, offset) { | ||
var ch = src[offset]; | ||
var isVerbatim = ch === '<'; | ||
var notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ',']; | ||
while (ch && notOk.indexOf(ch) === -1) { | ||
ch = src[offset += 1]; | ||
} | ||
const ch1 = src[offset + 1]; | ||
const ch2 = src[offset + 2]; | ||
if (ch1 !== ch0 || ch2 !== ch0) return false; | ||
const ch3 = src[offset + 3]; | ||
return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' '; | ||
} | ||
if (isVerbatim && ch === '>') offset += 1; | ||
return offset; | ||
} | ||
}, { | ||
key: "endOfIndent", | ||
value: function endOfIndent(src, offset) { | ||
var ch = src[offset]; | ||
static endOfIdentifier(src, offset) { | ||
let ch = src[offset]; | ||
const isVerbatim = ch === '<'; | ||
const notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ',']; | ||
while (ch === ' ') { | ||
ch = src[offset += 1]; | ||
} | ||
while (ch && notOk.indexOf(ch) === -1) ch = src[offset += 1]; | ||
return offset; | ||
} | ||
}, { | ||
key: "endOfLine", | ||
value: function endOfLine(src, offset) { | ||
var ch = src[offset]; | ||
if (isVerbatim && ch === '>') offset += 1; | ||
return offset; | ||
} | ||
while (ch && ch !== '\n') { | ||
ch = src[offset += 1]; | ||
} | ||
static endOfIndent(src, offset) { | ||
let ch = src[offset]; | ||
return offset; | ||
} | ||
}, { | ||
key: "endOfWhiteSpace", | ||
value: function endOfWhiteSpace(src, offset) { | ||
var ch = src[offset]; | ||
while (ch === ' ') ch = src[offset += 1]; | ||
while (ch === '\t' || ch === ' ') { | ||
ch = src[offset += 1]; | ||
} | ||
return offset; | ||
} | ||
return offset; | ||
} | ||
}, { | ||
key: "startOfLine", | ||
value: function startOfLine(src, offset) { | ||
var ch = src[offset - 1]; | ||
static endOfLine(src, offset) { | ||
let ch = src[offset]; | ||
while (ch && ch !== '\n') { | ||
ch = src[offset -= 1]; | ||
} | ||
while (ch && ch !== '\n') ch = src[offset += 1]; | ||
return offset + 1; | ||
} | ||
/** | ||
* End of indentation, or null if the line's indent level is not more | ||
* than `indent` | ||
* | ||
* @param {string} src | ||
* @param {number} indent | ||
* @param {number} lineStart | ||
* @returns {?number} | ||
*/ | ||
return offset; | ||
} | ||
}, { | ||
key: "endOfBlockIndent", | ||
value: function endOfBlockIndent(src, indent, lineStart) { | ||
var inEnd = Node.endOfIndent(src, lineStart); | ||
static endOfWhiteSpace(src, offset) { | ||
let ch = src[offset]; | ||
if (inEnd > lineStart + indent) { | ||
return inEnd; | ||
} else { | ||
var wsEnd = Node.endOfWhiteSpace(src, inEnd); | ||
var ch = src[wsEnd]; | ||
if (!ch || ch === '\n') return wsEnd; | ||
} | ||
while (ch === '\t' || ch === ' ') ch = src[offset += 1]; | ||
return null; | ||
return offset; | ||
} | ||
static startOfLine(src, offset) { | ||
let ch = src[offset - 1]; | ||
if (ch === '\n') return offset; | ||
while (ch && ch !== '\n') ch = src[offset -= 1]; | ||
return offset + 1; | ||
} | ||
/** | ||
* End of indentation, or null if the line's indent level is not more | ||
* than `indent` | ||
* | ||
* @param {string} src | ||
* @param {number} indent | ||
* @param {number} lineStart | ||
* @returns {?number} | ||
*/ | ||
static endOfBlockIndent(src, indent, lineStart) { | ||
const inEnd = Node.endOfIndent(src, lineStart); | ||
if (inEnd > lineStart + indent) { | ||
return inEnd; | ||
} else { | ||
const wsEnd = Node.endOfWhiteSpace(src, inEnd); | ||
const ch = src[wsEnd]; | ||
if (!ch || ch === '\n') return wsEnd; | ||
} | ||
}, { | ||
key: "atBlank", | ||
value: function atBlank(src, offset) { | ||
var ch = src[offset]; | ||
return ch === '\n' || ch === '\t' || ch === ' '; | ||
} | ||
}, { | ||
key: "atCollectionItem", | ||
value: function atCollectionItem(src, offset) { | ||
var ch = src[offset]; | ||
return (ch === '?' || ch === ':' || ch === '-') && Node.atBlank(src, offset + 1); | ||
} | ||
}, { | ||
key: "nextNodeIsIndented", | ||
value: function nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) { | ||
if (!ch || indentDiff < 0) return false; | ||
if (indentDiff > 0) return true; | ||
return indicatorAsIndent && ch === '-'; | ||
} // should be at line or string end, or at next non-whitespace char | ||
}, { | ||
key: "normalizeOffset", | ||
value: function normalizeOffset(src, offset) { | ||
var ch = src[offset]; | ||
return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset); | ||
} // fold single newline into space, multiple newlines to N - 1 newlines | ||
// presumes src[offset] === '\n' | ||
return null; | ||
} | ||
}, { | ||
key: "foldNewline", | ||
value: function foldNewline(src, offset, indent) { | ||
var inCount = 0; | ||
var error = false; | ||
var fold = ''; | ||
var ch = src[offset + 1]; | ||
static atBlank(src, offset) { | ||
const ch = src[offset]; | ||
return ch === '\n' || ch === '\t' || ch === ' '; | ||
} | ||
while (ch === ' ' || ch === '\t' || ch === '\n') { | ||
switch (ch) { | ||
case '\n': | ||
inCount = 0; | ||
offset += 1; | ||
fold += '\n'; | ||
break; | ||
static atCollectionItem(src, offset) { | ||
const ch = src[offset]; | ||
return (ch === '?' || ch === ':' || ch === '-') && Node.atBlank(src, offset + 1); | ||
} | ||
case '\t': | ||
if (inCount <= indent) error = true; | ||
offset = Node.endOfWhiteSpace(src, offset + 2) - 1; | ||
break; | ||
static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) { | ||
if (!ch || indentDiff < 0) return false; | ||
if (indentDiff > 0) return true; | ||
return indicatorAsIndent && ch === '-'; | ||
} // should be at line or string end, or at next non-whitespace char | ||
case ' ': | ||
inCount += 1; | ||
offset += 1; | ||
break; | ||
} | ||
ch = src[offset + 1]; | ||
static normalizeOffset(src, offset) { | ||
const ch = src[offset]; | ||
return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset); | ||
} // fold single newline into space, multiple newlines to N - 1 newlines | ||
// presumes src[offset] === '\n' | ||
static foldNewline(src, offset, indent) { | ||
let inCount = 0; | ||
let error = false; | ||
let fold = ''; | ||
let ch = src[offset + 1]; | ||
while (ch === ' ' || ch === '\t' || ch === '\n') { | ||
switch (ch) { | ||
case '\n': | ||
inCount = 0; | ||
offset += 1; | ||
fold += '\n'; | ||
break; | ||
case '\t': | ||
if (inCount <= indent) error = true; | ||
offset = Node.endOfWhiteSpace(src, offset + 2) - 1; | ||
break; | ||
case ' ': | ||
inCount += 1; | ||
offset += 1; | ||
break; | ||
} | ||
if (!fold) fold = ' '; | ||
if (ch && inCount <= indent) error = true; | ||
return { | ||
fold: fold, | ||
offset: offset, | ||
error: error | ||
}; | ||
ch = src[offset + 1]; | ||
} | ||
}]); | ||
function Node(type, props, context) { | ||
_classCallCheck(this, Node); | ||
if (!fold) fold = ' '; | ||
if (ch && inCount <= indent) error = true; | ||
return { | ||
fold, | ||
offset, | ||
error | ||
}; | ||
} | ||
constructor(type, props, context) { | ||
this.context = context || null; | ||
@@ -253,121 +219,87 @@ this.error = null; | ||
_createClass(Node, [{ | ||
key: "getPropValue", | ||
value: function getPropValue(idx, key, skipKey) { | ||
if (!this.context) return null; | ||
var src = this.context.src; | ||
var prop = this.props[idx]; | ||
return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null; | ||
} | ||
}, { | ||
key: "commentHasRequiredWhitespace", | ||
value: function commentHasRequiredWhitespace(start) { | ||
var src = this.context.src; | ||
if (this.header && start === this.header.end) return false; | ||
getPropValue(idx, key, skipKey) { | ||
if (!this.context) return null; | ||
const src = this.context.src; | ||
const prop = this.props[idx]; | ||
return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null; | ||
} | ||
if (this.valueRange) { | ||
var end = this.valueRange.end; | ||
return start !== end || Node.atBlank(src, end - 1); | ||
} | ||
get anchor() { | ||
for (let i = 0; i < this.props.length; ++i) { | ||
const anchor = this.getPropValue(i, Char.ANCHOR, true); | ||
if (anchor != null) return anchor; | ||
} | ||
}, { | ||
key: "parseComment", | ||
value: function parseComment(start) { | ||
var src = this.context.src; | ||
if (src[start] === Char.COMMENT) { | ||
var end = Node.endOfLine(src, start + 1); | ||
var commentRange = new _Range.default(start, end); | ||
this.props.push(commentRange); | ||
return end; | ||
} | ||
return null; | ||
} | ||
return start; | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
var src = this.context.src, | ||
range = this.range, | ||
value = this.value; | ||
if (value != null) return value; | ||
var str = src.slice(range.start, range.end); | ||
return Node.addStringTerminator(src, range.end, str); | ||
} | ||
}, { | ||
key: "anchor", | ||
get: function get() { | ||
for (var i = 0; i < this.props.length; ++i) { | ||
var anchor = this.getPropValue(i, Char.ANCHOR, true); | ||
if (anchor != null) return anchor; | ||
} | ||
get comment() { | ||
const comments = []; | ||
return null; | ||
for (let i = 0; i < this.props.length; ++i) { | ||
const comment = this.getPropValue(i, Char.COMMENT, true); | ||
if (comment != null) comments.push(comment); | ||
} | ||
}, { | ||
key: "comment", | ||
get: function get() { | ||
var comments = []; | ||
for (var i = 0; i < this.props.length; ++i) { | ||
var comment = this.getPropValue(i, Char.COMMENT, true); | ||
if (comment != null) comments.push(comment); | ||
} | ||
return comments.length > 0 ? comments.join('\n') : null; | ||
} | ||
return comments.length > 0 ? comments.join('\n') : null; | ||
commentHasRequiredWhitespace(start) { | ||
const src = this.context.src; | ||
if (this.header && start === this.header.end) return false; | ||
if (this.valueRange) { | ||
const end = this.valueRange.end; | ||
return start !== end || Node.atBlank(src, end - 1); | ||
} | ||
}, { | ||
key: "hasComment", | ||
get: function get() { | ||
if (this.context) { | ||
var src = this.context.src; | ||
} | ||
for (var i = 0; i < this.props.length; ++i) { | ||
if (src[this.props[i].start] === Char.COMMENT) return true; | ||
} | ||
get hasComment() { | ||
if (this.context) { | ||
const src = this.context.src; | ||
for (let i = 0; i < this.props.length; ++i) { | ||
if (src[this.props[i].start] === Char.COMMENT) return true; | ||
} | ||
return false; | ||
} | ||
}, { | ||
key: "hasProps", | ||
get: function get() { | ||
if (this.context) { | ||
var src = this.context.src; | ||
for (var i = 0; i < this.props.length; ++i) { | ||
if (src[this.props[i].start] !== Char.COMMENT) return true; | ||
} | ||
return false; | ||
} | ||
get hasProps() { | ||
if (this.context) { | ||
const src = this.context.src; | ||
for (let i = 0; i < this.props.length; ++i) { | ||
if (src[this.props[i].start] !== Char.COMMENT) return true; | ||
} | ||
} | ||
return false; | ||
} | ||
}, { | ||
key: "jsonLike", | ||
get: function get() { | ||
var jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE]; | ||
return jsonLikeTypes.indexOf(this.type) !== -1; | ||
} | ||
}, { | ||
key: "rawValue", | ||
get: function get() { | ||
if (!this.valueRange || !this.context) return null; | ||
var _this$valueRange = this.valueRange, | ||
return false; | ||
} | ||
get jsonLike() { | ||
const jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE]; | ||
return jsonLikeTypes.indexOf(this.type) !== -1; | ||
} | ||
get rawValue() { | ||
if (!this.valueRange || !this.context) return null; | ||
const _this$valueRange = this.valueRange, | ||
start = _this$valueRange.start, | ||
end = _this$valueRange.end; | ||
return this.context.src.slice(start, end); | ||
} | ||
}, { | ||
key: "tag", | ||
get: function get() { | ||
for (var i = 0; i < this.props.length; ++i) { | ||
var tag = this.getPropValue(i, Char.TAG, false); | ||
return this.context.src.slice(start, end); | ||
} | ||
if (tag != null) { | ||
if (tag[1] === '<') { | ||
return { | ||
verbatim: tag.slice(2, -1) | ||
}; | ||
} else { | ||
var _tag$match = tag.match(/^(.*!)([^!]*)$/), | ||
get tag() { | ||
for (let i = 0; i < this.props.length; ++i) { | ||
const tag = this.getPropValue(i, Char.TAG, false); | ||
if (tag != null) { | ||
if (tag[1] === '<') { | ||
return { | ||
verbatim: tag.slice(2, -1) | ||
}; | ||
} else { | ||
const _tag$match = tag.match(/^(.*!)([^!]*)$/), | ||
_tag$match2 = _slicedToArray(_tag$match, 3), | ||
@@ -378,32 +310,67 @@ _ = _tag$match2[0], | ||
return { | ||
handle: handle, | ||
suffix: suffix | ||
}; | ||
} | ||
return { | ||
handle, | ||
suffix | ||
}; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
}, { | ||
key: "valueRangeContainsNewline", | ||
get: function get() { | ||
if (!this.valueRange || !this.context) return false; | ||
var _this$valueRange2 = this.valueRange, | ||
return null; | ||
} | ||
get valueRangeContainsNewline() { | ||
if (!this.valueRange || !this.context) return false; | ||
const _this$valueRange2 = this.valueRange, | ||
start = _this$valueRange2.start, | ||
end = _this$valueRange2.end; | ||
var src = this.context.src; | ||
const src = this.context.src; | ||
for (var i = start; i < end; ++i) { | ||
if (src[i] === '\n') return true; | ||
} | ||
for (let i = start; i < end; ++i) { | ||
if (src[i] === '\n') return true; | ||
} | ||
return false; | ||
return false; | ||
} | ||
parseComment(start) { | ||
const src = this.context.src; | ||
if (src[start] === Char.COMMENT) { | ||
const end = Node.endOfLine(src, start + 1); | ||
const commentRange = new _Range.default(start, end); | ||
this.props.push(commentRange); | ||
return end; | ||
} | ||
}]); | ||
return Node; | ||
}(); | ||
return start; | ||
} | ||
/** | ||
* Populates the `origStart` and `origEnd` values of all ranges for this | ||
* node. Extended by child classes to handle descendant nodes. | ||
* | ||
* @param {number[]} cr - Positions of dropped CR characters | ||
* @param {number} offset - Starting index of `cr` from the last call | ||
* @returns {number} - The next offset, matching the one found for `origStart` | ||
*/ | ||
setOrigRanges(cr, offset) { | ||
if (this.range) offset = this.range.setOrigRange(cr, offset); | ||
this.valueRange.setOrigRange(cr, offset); | ||
this.props.forEach(prop => prop.setOrigRange(cr, offset)); | ||
return offset; | ||
} | ||
toString() { | ||
const src = this.context.src, | ||
range = this.range, | ||
value = this.value; | ||
if (value != null) return value; | ||
const str = src.slice(range.start, range.end); | ||
return Node.addStringTerminator(src, range.end, str); | ||
} | ||
} | ||
exports.default = Node; |
@@ -16,11 +16,19 @@ "use strict"; | ||
function parse(src) { | ||
if (src.indexOf('\r') !== -1) src = src.replace(/\r\n?/g, '\n'); | ||
var context = new _ParseContext.default({ | ||
src: src | ||
const cr = []; | ||
if (src.indexOf('\r') !== -1) { | ||
src = src.replace(/\r\n?/g, (match, offset) => { | ||
if (match.length > 1) cr.push(offset); | ||
return '\n'; | ||
}); | ||
} | ||
const context = new _ParseContext.default({ | ||
src | ||
}); | ||
var documents = []; | ||
var offset = 0; | ||
const documents = []; | ||
let offset = 0; | ||
while (offset < src.length) { | ||
var doc = new _Document.default(); | ||
const doc = new _Document.default(); | ||
offset = doc.parse(context, offset); | ||
@@ -30,7 +38,20 @@ documents.push(doc); | ||
documents.toString = function () { | ||
return documents.join('...\n'); | ||
documents.setOrigRanges = () => { | ||
if (cr.length === 0) return false; | ||
for (let i = 1; i < cr.length; ++i) cr[i] -= i; | ||
let crOffset = 0; | ||
for (let i = 0; i < documents.length; ++i) { | ||
crOffset = documents[i].setOrigRanges(cr, crOffset); | ||
} | ||
cr.splice(0, cr.length); | ||
return true; | ||
}; | ||
documents.toString = () => documents.join('...\n'); | ||
return documents; | ||
} |
@@ -34,8 +34,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
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; } | ||
@@ -52,71 +46,59 @@ | ||
*/ | ||
var ParseContext = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(ParseContext, null, [{ | ||
key: "parseType", | ||
value: function parseType(src, offset, inFlow) { | ||
switch (src[offset]) { | ||
case '*': | ||
return _Node.Type.ALIAS; | ||
class ParseContext { | ||
static parseType(src, offset, inFlow) { | ||
switch (src[offset]) { | ||
case '*': | ||
return _Node.Type.ALIAS; | ||
case '>': | ||
return _Node.Type.BLOCK_FOLDED; | ||
case '>': | ||
return _Node.Type.BLOCK_FOLDED; | ||
case '|': | ||
return _Node.Type.BLOCK_LITERAL; | ||
case '|': | ||
return _Node.Type.BLOCK_LITERAL; | ||
case '{': | ||
return _Node.Type.FLOW_MAP; | ||
case '{': | ||
return _Node.Type.FLOW_MAP; | ||
case '[': | ||
return _Node.Type.FLOW_SEQ; | ||
case '[': | ||
return _Node.Type.FLOW_SEQ; | ||
case '?': | ||
return !inFlow && _Node.default.atBlank(src, offset + 1) ? _Node.Type.MAP_KEY : _Node.Type.PLAIN; | ||
case '?': | ||
return !inFlow && _Node.default.atBlank(src, offset + 1) ? _Node.Type.MAP_KEY : _Node.Type.PLAIN; | ||
case ':': | ||
return !inFlow && _Node.default.atBlank(src, offset + 1) ? _Node.Type.MAP_VALUE : _Node.Type.PLAIN; | ||
case ':': | ||
return !inFlow && _Node.default.atBlank(src, offset + 1) ? _Node.Type.MAP_VALUE : _Node.Type.PLAIN; | ||
case '-': | ||
return !inFlow && _Node.default.atBlank(src, offset + 1) ? _Node.Type.SEQ_ITEM : _Node.Type.PLAIN; | ||
case '-': | ||
return !inFlow && _Node.default.atBlank(src, offset + 1) ? _Node.Type.SEQ_ITEM : _Node.Type.PLAIN; | ||
case '"': | ||
return _Node.Type.QUOTE_DOUBLE; | ||
case '"': | ||
return _Node.Type.QUOTE_DOUBLE; | ||
case "'": | ||
return _Node.Type.QUOTE_SINGLE; | ||
case "'": | ||
return _Node.Type.QUOTE_SINGLE; | ||
default: | ||
return _Node.Type.PLAIN; | ||
} | ||
default: | ||
return _Node.Type.PLAIN; | ||
} | ||
}]); | ||
} | ||
function ParseContext() { | ||
var _this = this; | ||
constructor(orig = {}, { | ||
atLineStart, | ||
inCollection, | ||
inFlow, | ||
indent, | ||
lineStart, | ||
parent | ||
} = {}) { | ||
_defineProperty(this, "parseNode", (overlay, start) => { | ||
if (_Node.default.atDocumentBoundary(this.src, start)) return null; | ||
const context = new ParseContext(this, overlay); | ||
var orig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const _context$parseProps = context.parseProps(start), | ||
props = _context$parseProps.props, | ||
type = _context$parseProps.type, | ||
valueStart = _context$parseProps.valueStart; | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
atLineStart = _ref.atLineStart, | ||
inCollection = _ref.inCollection, | ||
inFlow = _ref.inFlow, | ||
indent = _ref.indent, | ||
lineStart = _ref.lineStart, | ||
parent = _ref.parent; | ||
let node; | ||
_classCallCheck(this, ParseContext); | ||
_defineProperty(this, "parseNode", function (overlay, start) { | ||
if (_Node.default.atDocumentBoundary(_this.src, start)) return null; | ||
var context = new ParseContext(_this, overlay); | ||
var _context$parseProps = context.parseProps(start), | ||
props = _context$parseProps.props, | ||
type = _context$parseProps.type, | ||
valueStart = _context$parseProps.valueStart; | ||
var node; | ||
switch (type) { | ||
@@ -157,3 +139,3 @@ case _Node.Type.ALIAS: | ||
default: | ||
node.error = new _errors.YAMLSyntaxError(node, "Unknown node type: ".concat(JSON.stringify(type))); | ||
node.error = new _errors.YAMLSyntaxError(node, `Unknown node type: ${JSON.stringify(type)}`); | ||
node.range = new _Range.default(start, start + 1); | ||
@@ -163,7 +145,7 @@ return node; | ||
var offset = node.parse(context, valueStart); | ||
var nodeEnd = _this.src[offset] === '\n' ? offset + 1 : offset; | ||
let offset = node.parse(context, valueStart); | ||
let nodeEnd = this.src[offset] === '\n' ? offset + 1 : offset; | ||
if (nodeEnd <= start) { | ||
node.error = new Error("Node#parse consumed no characters"); | ||
node.error = new Error(`Node#parse consumed no characters`); | ||
node.error.parseEnd = nodeEnd; | ||
@@ -181,3 +163,3 @@ node.error.source = node; | ||
var collection = new _Collection.default(node); | ||
const collection = new _Collection.default(node); | ||
offset = collection.parse(new ParseContext(context), offset); | ||
@@ -201,100 +183,94 @@ collection.range = new _Range.default(start, offset); | ||
_createClass(ParseContext, [{ | ||
key: "nodeStartsCollection", | ||
value: function nodeStartsCollection(node) { | ||
var inCollection = this.inCollection, | ||
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; | ||
} | ||
nodeStartsCollection(node) { | ||
const inCollection = this.inCollection, | ||
inFlow = this.inFlow, | ||
src = this.src; | ||
if (inCollection || inFlow) return false; | ||
if (node instanceof _CollectionItem.default) return true; // check for implicit key | ||
if (inCollection || inFlow) return false; | ||
if (node instanceof _CollectionItem.default) 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); | ||
return src[offset] === ':'; | ||
} // Anchor and tag are before type, which determines the node implementation | ||
// class; hence this intermediate step. | ||
let offset = node.range.end; | ||
if (src[offset] === '\n' || src[offset - 1] === '\n') return false; | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
return src[offset] === ':'; | ||
} // Anchor and tag are before type, which determines the node implementation | ||
// class; hence this intermediate step. | ||
}, { | ||
key: "parseProps", | ||
value: function parseProps(offset) { | ||
var inFlow = this.inFlow, | ||
parseProps(offset) { | ||
const inFlow = this.inFlow, | ||
parent = this.parent, | ||
src = this.src; | ||
var props = []; | ||
var lineHasProps = false; | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
var ch = src[offset]; | ||
const props = []; | ||
let lineHasProps = false; | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
let ch = src[offset]; | ||
while (ch === _Node.Char.ANCHOR || ch === _Node.Char.COMMENT || ch === _Node.Char.TAG || ch === '\n') { | ||
if (ch === '\n') { | ||
var lineStart = offset + 1; | ||
while (ch === _Node.Char.ANCHOR || ch === _Node.Char.COMMENT || ch === _Node.Char.TAG || ch === '\n') { | ||
if (ch === '\n') { | ||
const lineStart = offset + 1; | ||
var inEnd = _Node.default.endOfIndent(src, lineStart); | ||
const inEnd = _Node.default.endOfIndent(src, lineStart); | ||
var indentDiff = inEnd - (lineStart + this.indent); | ||
var noIndicatorAsIndent = parent.type === _Node.Type.SEQ_ITEM && parent.context.atLineStart; | ||
if (!_Node.default.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break; | ||
this.atLineStart = true; | ||
this.lineStart = lineStart; | ||
lineHasProps = false; | ||
offset = inEnd; | ||
} else if (ch === _Node.Char.COMMENT) { | ||
var end = _Node.default.endOfLine(src, offset + 1); | ||
const indentDiff = inEnd - (lineStart + this.indent); | ||
const noIndicatorAsIndent = parent.type === _Node.Type.SEQ_ITEM && parent.context.atLineStart; | ||
if (!_Node.default.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break; | ||
this.atLineStart = true; | ||
this.lineStart = lineStart; | ||
lineHasProps = false; | ||
offset = inEnd; | ||
} else if (ch === _Node.Char.COMMENT) { | ||
const end = _Node.default.endOfLine(src, offset + 1); | ||
props.push(new _Range.default(offset, end)); | ||
offset = end; | ||
} else { | ||
var _end = _Node.default.endOfIdentifier(src, offset + 1); | ||
props.push(new _Range.default(offset, end)); | ||
offset = end; | ||
} else { | ||
let end = _Node.default.endOfIdentifier(src, offset + 1); | ||
if (ch === _Node.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 | ||
// than an empty but 'foo.bar' private-tagged node in a flow collection | ||
// followed without whitespace by a plain string starting with a year | ||
// or date divided by something. | ||
_end = _Node.default.endOfIdentifier(src, _end + 5); | ||
} | ||
props.push(new _Range.default(offset, _end)); | ||
lineHasProps = true; | ||
offset = _Node.default.endOfWhiteSpace(src, _end); | ||
if (ch === _Node.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 | ||
// than an empty but 'foo.bar' private-tagged node in a flow collection | ||
// followed without whitespace by a plain string starting with a year | ||
// or date divided by something. | ||
end = _Node.default.endOfIdentifier(src, end + 5); | ||
} | ||
ch = src[offset]; | ||
} // '- &a : b' has an anchor on an empty node | ||
props.push(new _Range.default(offset, end)); | ||
lineHasProps = true; | ||
offset = _Node.default.endOfWhiteSpace(src, end); | ||
} | ||
ch = src[offset]; | ||
} // '- &a : b' has an anchor on an empty node | ||
if (lineHasProps && ch === ':' && _Node.default.atBlank(src, offset + 1)) offset -= 1; | ||
var type = ParseContext.parseType(src, offset, inFlow); | ||
return { | ||
props: props, | ||
type: type, | ||
valueStart: offset | ||
}; | ||
} | ||
/** | ||
* Parses a node from the source | ||
* @param {ParseContext} overlay | ||
* @param {number} start - Index of first non-whitespace character for the node | ||
* @returns {?Node} - null if at a document boundary | ||
*/ | ||
}, { | ||
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; | ||
} | ||
}]); | ||
if (lineHasProps && ch === ':' && _Node.default.atBlank(src, offset + 1)) offset -= 1; | ||
const type = ParseContext.parseType(src, offset, inFlow); | ||
return { | ||
props, | ||
type, | ||
valueStart: offset | ||
}; | ||
} | ||
/** | ||
* Parses a node from the source | ||
* @param {ParseContext} overlay | ||
* @param {number} start - Index of first non-whitespace character for the node | ||
* @returns {?Node} - null if at a document boundary | ||
*/ | ||
return ParseContext; | ||
}(); | ||
} | ||
exports.default = ParseContext; |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Node = _interopRequireDefault(require("./Node")); | ||
@@ -15,174 +15,135 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
class PlainValue extends _Node.default { | ||
static endOfLine(src, start, inFlow) { | ||
let ch = src[start]; | ||
let offset = start; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
while (ch && ch !== '\n') { | ||
if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break; | ||
const next = src[offset + 1]; | ||
if (ch === ':' && (next === '\n' || next === '\t' || next === ' ' || next === ',')) break; | ||
if ((ch === ' ' || ch === '\t') && next === '#') break; | ||
offset += 1; | ||
ch = next; | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
return offset; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
get strValue() { | ||
if (!this.valueRange || !this.context) return null; | ||
let _this$valueRange = this.valueRange, | ||
start = _this$valueRange.start, | ||
end = _this$valueRange.end; | ||
const src = this.context.src; | ||
let ch = src[end - 1]; | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) ch = src[--end - 1]; | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
ch = src[start]; | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) ch = src[++start]; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
let str = ''; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
for (let i = start; i < end; ++i) { | ||
let ch = src[i]; | ||
var PlainValue = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(PlainValue, _Node); | ||
if (ch === '\n') { | ||
const _Node$foldNewline = _Node.default.foldNewline(src, i, -1), | ||
fold = _Node$foldNewline.fold, | ||
offset = _Node$foldNewline.offset; | ||
function PlainValue() { | ||
_classCallCheck(this, PlainValue); | ||
str += fold; | ||
i = offset; | ||
} else if (ch === ' ' || ch === '\t') { | ||
// trim trailing whitespace | ||
const wsStart = i; | ||
let next = src[i + 1]; | ||
return _possibleConstructorReturn(this, _getPrototypeOf(PlainValue).apply(this, arguments)); | ||
while (i < end && (next === ' ' || next === '\t')) { | ||
i += 1; | ||
next = src[i + 1]; | ||
} | ||
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; | ||
} else { | ||
str += ch; | ||
} | ||
} | ||
return str; | ||
} | ||
_createClass(PlainValue, [{ | ||
key: "parseBlockValue", | ||
value: function parseBlockValue(start) { | ||
var _this$context = this.context, | ||
parseBlockValue(start) { | ||
const _this$context = this.context, | ||
indent = _this$context.indent, | ||
inFlow = _this$context.inFlow, | ||
src = _this$context.src; | ||
var offset = start; | ||
let offset = start; | ||
for (var ch = src[offset]; ch === '\n'; ch = src[offset]) { | ||
if (_Node2.default.atDocumentBoundary(src, offset + 1)) break; | ||
for (let ch = src[offset]; ch === '\n'; ch = src[offset]) { | ||
if (_Node.default.atDocumentBoundary(src, offset + 1)) break; | ||
var end = _Node2.default.endOfBlockIndent(src, indent, offset + 1); | ||
const end = _Node.default.endOfBlockIndent(src, indent, offset + 1); | ||
if (end === null || src[end] === '#') break; | ||
offset = PlainValue.endOfLine(src, end, inFlow); | ||
} | ||
if (this.valueRange.isEmpty) this.valueRange.start = start; | ||
this.valueRange.end = offset; | ||
return offset; | ||
if (end === null || src[end] === '#') break; | ||
offset = PlainValue.endOfLine(src, end, inFlow); | ||
} | ||
/** | ||
* Parses a plain value from the source | ||
* | ||
* Accepted forms are: | ||
* ``` | ||
* #comment | ||
* | ||
* first line | ||
* | ||
* first line #comment | ||
* | ||
* first line | ||
* block | ||
* lines | ||
* | ||
* #comment | ||
* block | ||
* lines | ||
* ``` | ||
* where block lines are empty or have an indent level greater than `indent`. | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this scalar, may be `\n` | ||
*/ | ||
}, { | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var inFlow = context.inFlow, | ||
src = context.src; | ||
var offset = start; | ||
var ch = src[offset]; | ||
if (this.valueRange.isEmpty()) this.valueRange.start = start; | ||
this.valueRange.end = offset; | ||
return offset; | ||
} | ||
/** | ||
* Parses a plain value from the source | ||
* | ||
* Accepted forms are: | ||
* ``` | ||
* #comment | ||
* | ||
* first line | ||
* | ||
* first line #comment | ||
* | ||
* first line | ||
* block | ||
* lines | ||
* | ||
* #comment | ||
* block | ||
* lines | ||
* ``` | ||
* where block lines are empty or have an indent level greater than `indent`. | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this scalar, may be `\n` | ||
*/ | ||
if (ch && ch !== '#' && ch !== '\n') { | ||
offset = PlainValue.endOfLine(src, start, inFlow); | ||
} | ||
this.valueRange = new _Range.default(start, offset); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
parse(context, start) { | ||
this.context = context; | ||
const inFlow = context.inFlow, | ||
src = context.src; | ||
let offset = start; | ||
let ch = src[offset]; | ||
if (!this.hasComment || this.valueRange.isEmpty) { | ||
offset = this.parseBlockValue(offset); | ||
} | ||
return offset; | ||
if (ch && ch !== '#' && ch !== '\n') { | ||
offset = PlainValue.endOfLine(src, start, inFlow); | ||
} | ||
}, { | ||
key: "strValue", | ||
get: function get() { | ||
if (!this.valueRange || !this.context) return null; | ||
var _this$valueRange = this.valueRange, | ||
start = _this$valueRange.start, | ||
end = _this$valueRange.end; | ||
var src = this.context.src; | ||
var ch = src[end - 1]; | ||
while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) { | ||
ch = src[--end - 1]; | ||
} | ||
this.valueRange = new _Range.default(start, offset); | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
ch = src[start]; | ||
while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) { | ||
ch = src[++start]; | ||
} | ||
var str = ''; | ||
for (var i = start; i < end; ++i) { | ||
var _ch = src[i]; | ||
if (_ch === '\n') { | ||
var _Node$foldNewline = _Node2.default.foldNewline(src, i, -1), | ||
fold = _Node$foldNewline.fold, | ||
offset = _Node$foldNewline.offset; | ||
str += fold; | ||
i = offset; | ||
} else if (_ch === ' ' || _ch === '\t') { | ||
// trim trailing whitespace | ||
var wsStart = i; | ||
var next = src[i + 1]; | ||
while (i < end && (next === ' ' || next === '\t')) { | ||
i += 1; | ||
next = src[i + 1]; | ||
} | ||
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : _ch; | ||
} else { | ||
str += _ch; | ||
} | ||
} | ||
return str; | ||
if (!this.hasComment || this.valueRange.isEmpty()) { | ||
offset = this.parseBlockValue(offset); | ||
} | ||
}], [{ | ||
key: "endOfLine", | ||
value: function endOfLine(src, start, inFlow) { | ||
var ch = src[start]; | ||
var offset = start; | ||
while (ch && ch !== '\n') { | ||
if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break; | ||
var next = src[offset + 1]; | ||
if (ch === ':' && (next === '\n' || next === '\t' || next === ' ' || next === ',')) break; | ||
if ((ch === ' ' || ch === '\t') && next === '#') break; | ||
offset += 1; | ||
ch = next; | ||
} | ||
return offset; | ||
} | ||
return offset; | ||
} | ||
}]); | ||
} | ||
return PlainValue; | ||
}(_Node2.default); | ||
exports.default = PlainValue; |
@@ -10,3 +10,3 @@ "use strict"; | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Node = _interopRequireDefault(require("./Node")); | ||
@@ -17,92 +17,39 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
class QuoteDouble extends _Node.default { | ||
static endOfQuote(src, offset) { | ||
let ch = src[offset]; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
while (ch && ch !== '"') { | ||
offset += ch === '\\' ? 2 : 1; | ||
ch = src[offset]; | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var QuoteDouble = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(QuoteDouble, _Node); | ||
function QuoteDouble() { | ||
_classCallCheck(this, QuoteDouble); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(QuoteDouble).apply(this, arguments)); | ||
return offset + 1; | ||
} | ||
/** | ||
* @returns {string | { str: string, errors: YAMLSyntaxError[] }} | ||
*/ | ||
_createClass(QuoteDouble, [{ | ||
key: "parseCharCode", | ||
value: function parseCharCode(offset, length, errors) { | ||
var src = this.context.src; | ||
var cc = src.substr(offset, length); | ||
var ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc); | ||
var code = ok ? parseInt(cc, 16) : NaN; | ||
if (isNaN(code)) { | ||
errors.push(new _errors.YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(offset - 2, length + 2)))); | ||
return src.substr(offset - 2, length + 2); | ||
} | ||
return String.fromCodePoint(code); | ||
} | ||
/** | ||
* Parses a "double quoted" value from the source | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this scalar | ||
*/ | ||
}, { | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var src = context.src; | ||
var offset = QuoteDouble.endOfQuote(src, start + 1); | ||
this.valueRange = new _Range.default(start, offset); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
return offset; | ||
} | ||
}, { | ||
key: "strValue", | ||
/** | ||
* @returns {string | { str: string, errors: YAMLSyntaxError[] }} | ||
*/ | ||
get: function get() { | ||
if (!this.valueRange || !this.context) return null; | ||
var errors = []; | ||
var _this$valueRange = this.valueRange, | ||
get strValue() { | ||
if (!this.valueRange || !this.context) return null; | ||
const errors = []; | ||
const _this$valueRange = this.valueRange, | ||
start = _this$valueRange.start, | ||
end = _this$valueRange.end; | ||
var _this$context = this.context, | ||
const _this$context = this.context, | ||
indent = _this$context.indent, | ||
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 | ||
// escaped backslashes; also, this should be faster. | ||
if (src[end - 1] !== '"') errors.push(new _errors.YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by | ||
// escaped backslashes; also, this should be faster. | ||
var str = ''; | ||
let str = ''; | ||
for (var i = start + 1; i < end - 1; ++i) { | ||
var ch = src[i]; | ||
for (let i = start + 1; i < end - 1; ++i) { | ||
let ch = src[i]; | ||
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 (ch === '\n') { | ||
if (_Node.default.atDocumentBoundary(src, i + 1)) errors.push(new _errors.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); | ||
var _Node$foldNewline = _Node2.default.foldNewline(src, i, indent), | ||
const _Node$foldNewline = _Node.default.foldNewline(src, i, indent), | ||
fold = _Node$foldNewline.fold, | ||
@@ -112,159 +59,175 @@ offset = _Node$foldNewline.offset, | ||
str += fold; | ||
i = offset; | ||
if (error) errors.push(new _errors.YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented')); | ||
} else if (ch === '\\') { | ||
i += 1; | ||
str += fold; | ||
i = offset; | ||
if (error) errors.push(new _errors.YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented')); | ||
} else if (ch === '\\') { | ||
i += 1; | ||
switch (src[i]) { | ||
case '0': | ||
str += '\0'; | ||
break; | ||
// null character | ||
switch (src[i]) { | ||
case '0': | ||
str += '\0'; | ||
break; | ||
// null character | ||
case 'a': | ||
str += '\x07'; | ||
break; | ||
// bell character | ||
case 'a': | ||
str += '\x07'; | ||
break; | ||
// bell character | ||
case 'b': | ||
str += '\b'; | ||
break; | ||
// backspace | ||
case 'b': | ||
str += '\b'; | ||
break; | ||
// backspace | ||
case 'e': | ||
str += '\x1b'; | ||
break; | ||
// escape character | ||
case 'e': | ||
str += '\x1b'; | ||
break; | ||
// escape character | ||
case 'f': | ||
str += '\f'; | ||
break; | ||
// form feed | ||
case 'f': | ||
str += '\f'; | ||
break; | ||
// form feed | ||
case 'n': | ||
str += '\n'; | ||
break; | ||
// line feed | ||
case 'n': | ||
str += '\n'; | ||
break; | ||
// line feed | ||
case 'r': | ||
str += '\r'; | ||
break; | ||
// carriage return | ||
case 'r': | ||
str += '\r'; | ||
break; | ||
// carriage return | ||
case 't': | ||
str += '\t'; | ||
break; | ||
// horizontal tab | ||
case 't': | ||
str += '\t'; | ||
break; | ||
// horizontal tab | ||
case 'v': | ||
str += '\v'; | ||
break; | ||
// vertical tab | ||
case 'v': | ||
str += '\v'; | ||
break; | ||
// vertical tab | ||
case 'N': | ||
str += "\x85"; | ||
break; | ||
// Unicode next line | ||
case 'N': | ||
str += '\u0085'; | ||
break; | ||
// Unicode next line | ||
case '_': | ||
str += "\xA0"; | ||
break; | ||
// Unicode non-breaking space | ||
case '_': | ||
str += '\u00a0'; | ||
break; | ||
// Unicode non-breaking space | ||
case 'L': | ||
str += "\u2028"; | ||
break; | ||
// Unicode line separator | ||
case 'L': | ||
str += '\u2028'; | ||
break; | ||
// Unicode line separator | ||
case 'P': | ||
str += "\u2029"; | ||
break; | ||
// Unicode paragraph separator | ||
case 'P': | ||
str += '\u2029'; | ||
break; | ||
// Unicode paragraph separator | ||
case ' ': | ||
str += ' '; | ||
break; | ||
case ' ': | ||
str += ' '; | ||
break; | ||
case '"': | ||
str += '"'; | ||
break; | ||
case '"': | ||
str += '"'; | ||
break; | ||
case '/': | ||
str += '/'; | ||
break; | ||
case '/': | ||
str += '/'; | ||
break; | ||
case '\\': | ||
str += '\\'; | ||
break; | ||
case '\\': | ||
str += '\\'; | ||
break; | ||
case '\t': | ||
str += '\t'; | ||
break; | ||
case '\t': | ||
str += '\t'; | ||
break; | ||
case 'x': | ||
str += this.parseCharCode(i + 1, 2, errors); | ||
i += 2; | ||
break; | ||
case 'x': | ||
str += this.parseCharCode(i + 1, 2, errors); | ||
i += 2; | ||
break; | ||
case 'u': | ||
str += this.parseCharCode(i + 1, 4, errors); | ||
i += 4; | ||
break; | ||
case 'u': | ||
str += this.parseCharCode(i + 1, 4, errors); | ||
i += 4; | ||
break; | ||
case 'U': | ||
str += this.parseCharCode(i + 1, 8, errors); | ||
i += 8; | ||
break; | ||
case 'U': | ||
str += this.parseCharCode(i + 1, 8, errors); | ||
i += 8; | ||
break; | ||
case '\n': | ||
// skip escaped newlines, but still trim the following line | ||
while (src[i + 1] === ' ' || src[i + 1] === '\t') { | ||
i += 1; | ||
} | ||
case '\n': | ||
// skip escaped newlines, but still trim the following line | ||
while (src[i + 1] === ' ' || src[i + 1] === '\t') i += 1; | ||
break; | ||
break; | ||
default: | ||
errors.push(new _errors.YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(i - 1, 2)))); | ||
str += '\\' + src[i]; | ||
} | ||
} else if (ch === ' ' || ch === '\t') { | ||
// trim trailing whitespace | ||
var wsStart = i; | ||
var next = src[i + 1]; | ||
default: | ||
errors.push(new _errors.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(i - 1, 2)}`)); | ||
str += '\\' + src[i]; | ||
} | ||
} else if (ch === ' ' || ch === '\t') { | ||
// trim trailing whitespace | ||
const wsStart = i; | ||
let next = src[i + 1]; | ||
while (next === ' ' || next === '\t') { | ||
i += 1; | ||
next = src[i + 1]; | ||
} | ||
while (next === ' ' || next === '\t') { | ||
i += 1; | ||
next = src[i + 1]; | ||
} | ||
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; | ||
} else { | ||
str += ch; | ||
} | ||
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; | ||
} else { | ||
str += ch; | ||
} | ||
return errors.length > 0 ? { | ||
errors: errors, | ||
str: str | ||
} : str; | ||
} | ||
}], [{ | ||
key: "endOfQuote", | ||
value: function endOfQuote(src, offset) { | ||
var ch = src[offset]; | ||
while (ch && ch !== '"') { | ||
offset += ch === '\\' ? 2 : 1; | ||
ch = src[offset]; | ||
} | ||
return errors.length > 0 ? { | ||
errors, | ||
str | ||
} : str; | ||
} | ||
return offset + 1; | ||
parseCharCode(offset, length, errors) { | ||
const src = this.context.src; | ||
const cc = src.substr(offset, length); | ||
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc); | ||
const code = ok ? parseInt(cc, 16) : NaN; | ||
if (isNaN(code)) { | ||
errors.push(new _errors.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(offset - 2, length + 2)}`)); | ||
return src.substr(offset - 2, length + 2); | ||
} | ||
}]); | ||
return QuoteDouble; | ||
}(_Node2.default); | ||
return String.fromCodePoint(code); | ||
} | ||
/** | ||
* Parses a "double quoted" value from the source | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this scalar | ||
*/ | ||
parse(context, start) { | ||
this.context = context; | ||
const src = context.src; | ||
let offset = QuoteDouble.endOfQuote(src, start + 1); | ||
this.valueRange = new _Range.default(start, offset); | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
return offset; | ||
} | ||
} | ||
exports.default = QuoteDouble; |
@@ -10,3 +10,3 @@ "use strict"; | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Node = _interopRequireDefault(require("./Node")); | ||
@@ -17,75 +17,41 @@ var _Range = _interopRequireDefault(require("./Range")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
class QuoteSingle extends _Node.default { | ||
static endOfQuote(src, offset) { | ||
let ch = src[offset]; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
while (ch) { | ||
if (ch === "'") { | ||
if (src[offset + 1] !== "'") break; | ||
ch = src[offset += 2]; | ||
} else { | ||
ch = src[offset += 1]; | ||
} | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var QuoteSingle = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(QuoteSingle, _Node); | ||
function QuoteSingle() { | ||
_classCallCheck(this, QuoteSingle); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(QuoteSingle).apply(this, arguments)); | ||
return offset + 1; | ||
} | ||
/** | ||
* @returns {string | { str: string, errors: YAMLSyntaxError[] }} | ||
*/ | ||
_createClass(QuoteSingle, [{ | ||
key: "parse", | ||
/** | ||
* Parses a 'single quoted' value from the source | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this scalar | ||
*/ | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var src = context.src; | ||
var offset = QuoteSingle.endOfQuote(src, start + 1); | ||
this.valueRange = new _Range.default(start, offset); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
return offset; | ||
} | ||
}, { | ||
key: "strValue", | ||
/** | ||
* @returns {string | { str: string, errors: YAMLSyntaxError[] }} | ||
*/ | ||
get: function get() { | ||
if (!this.valueRange || !this.context) return null; | ||
var errors = []; | ||
var _this$valueRange = this.valueRange, | ||
get strValue() { | ||
if (!this.valueRange || !this.context) return null; | ||
const errors = []; | ||
const _this$valueRange = this.valueRange, | ||
start = _this$valueRange.start, | ||
end = _this$valueRange.end; | ||
var _this$context = this.context, | ||
const _this$context = this.context, | ||
indent = _this$context.indent, | ||
src = _this$context.src; | ||
if (src[end - 1] !== "'") errors.push(new _errors.YAMLSyntaxError(this, "Missing closing 'quote")); | ||
var str = ''; | ||
if (src[end - 1] !== "'") errors.push(new _errors.YAMLSyntaxError(this, "Missing closing 'quote")); | ||
let str = ''; | ||
for (var i = start + 1; i < end - 1; ++i) { | ||
var ch = src[i]; | ||
for (let i = start + 1; i < end - 1; ++i) { | ||
let ch = src[i]; | ||
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 (ch === '\n') { | ||
if (_Node.default.atDocumentBoundary(src, i + 1)) errors.push(new _errors.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); | ||
var _Node$foldNewline = _Node2.default.foldNewline(src, i, indent), | ||
const _Node$foldNewline = _Node.default.foldNewline(src, i, indent), | ||
fold = _Node$foldNewline.fold, | ||
@@ -95,51 +61,51 @@ offset = _Node$foldNewline.offset, | ||
str += fold; | ||
i = offset; | ||
if (error) errors.push(new _errors.YAMLSemanticError(this, 'Multi-line single-quoted string needs to be sufficiently indented')); | ||
} else if (ch === "'") { | ||
str += ch; | ||
str += fold; | ||
i = offset; | ||
if (error) errors.push(new _errors.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.')); | ||
} else if (ch === ' ' || ch === '\t') { | ||
// trim trailing whitespace | ||
const wsStart = i; | ||
let next = src[i + 1]; | ||
while (next === ' ' || next === '\t') { | ||
i += 1; | ||
if (src[i] !== "'") errors.push(new _errors.YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.')); | ||
} else if (ch === ' ' || ch === '\t') { | ||
// trim trailing whitespace | ||
var wsStart = i; | ||
var next = src[i + 1]; | ||
next = src[i + 1]; | ||
} | ||
while (next === ' ' || next === '\t') { | ||
i += 1; | ||
next = src[i + 1]; | ||
} | ||
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; | ||
} else { | ||
str += ch; | ||
} | ||
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; | ||
} else { | ||
str += ch; | ||
} | ||
return errors.length > 0 ? { | ||
errors: errors, | ||
str: str | ||
} : str; | ||
} | ||
}], [{ | ||
key: "endOfQuote", | ||
value: function endOfQuote(src, offset) { | ||
var ch = src[offset]; | ||
while (ch) { | ||
if (ch === "'") { | ||
if (src[offset + 1] !== "'") break; | ||
ch = src[offset += 2]; | ||
} else { | ||
ch = src[offset += 1]; | ||
} | ||
} | ||
return errors.length > 0 ? { | ||
errors, | ||
str | ||
} : str; | ||
} | ||
/** | ||
* Parses a 'single quoted' value from the source | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this scalar | ||
*/ | ||
return offset + 1; | ||
} | ||
}]); | ||
return QuoteSingle; | ||
}(_Node2.default); | ||
parse(context, start) { | ||
this.context = context; | ||
const src = context.src; | ||
let offset = QuoteSingle.endOfQuote(src, start + 1); | ||
this.valueRange = new _Range.default(start, offset); | ||
offset = _Node.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
return offset; | ||
} | ||
} | ||
exports.default = QuoteSingle; |
@@ -8,45 +8,55 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class Range { | ||
static copy(orig) { | ||
return new Range(orig.start, orig.end); | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
constructor(start, end) { | ||
this.start = start; | ||
this.end = end || start; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
isEmpty() { | ||
return typeof this.start !== 'number' || !this.end || this.end <= this.start; | ||
} | ||
/** | ||
* Set `origStart` and `origEnd` to point to the original source range for | ||
* this node, which may differ due to dropped CR characters. | ||
* | ||
* @param {number[]} cr - Positions of dropped CR characters | ||
* @param {number} offset - Starting index of `cr` from the last call | ||
* @returns {number} - The next offset, matching the one found for `origStart` | ||
*/ | ||
var Range = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(Range, null, [{ | ||
key: "copy", | ||
value: function copy(orig) { | ||
return new Range(orig.start, orig.end); | ||
setOrigRange(cr, offset) { | ||
const start = this.start, | ||
end = this.end; | ||
if (cr.length === 0 || end <= cr[0]) { | ||
this.origStart = start; | ||
this.origEnd = end; | ||
return offset; | ||
} | ||
}]); | ||
function Range(start, end) { | ||
_classCallCheck(this, Range); | ||
let i = offset; | ||
this.start = start; | ||
this.end = end || start; | ||
} | ||
while (i < cr.length) { | ||
if (cr[i] > start) break;else ++i; | ||
} | ||
_createClass(Range, [{ | ||
key: "apply", | ||
value: function apply(src) { | ||
return this.isEmpty ? '' : src.slice(this.start, this.end); | ||
this.origStart = start + i; | ||
const nextOffset = i; | ||
while (i < cr.length) { | ||
// if end was at \n, it should now be at \r | ||
if (cr[i] >= end) break;else ++i; | ||
} | ||
}, { | ||
key: "isEmpty", | ||
get: function get() { | ||
return typeof this.start !== 'number' || !this.end || this.end <= this.start; | ||
} | ||
}, { | ||
key: "length", | ||
get: function get() { | ||
return this.isEmpty ? 0 : this.end - this.start; | ||
} | ||
}]); | ||
return Range; | ||
}(); | ||
this.origEnd = end + i; | ||
return nextOffset; | ||
} | ||
} | ||
exports.default = Range; |
@@ -24,3 +24,3 @@ "use strict"; | ||
var _toJSON2 = _interopRequireDefault(require("./toJSON")); | ||
var _toJSON = _interopRequireDefault(require("./toJSON")); | ||
@@ -41,20 +41,8 @@ var _Scalar = _interopRequireDefault(require("./schema/Scalar")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
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; } | ||
var isCollectionItem = function isCollectionItem(node) { | ||
return node && [_Node.Type.MAP_KEY, _Node.Type.MAP_VALUE, _Node.Type.SEQ_ITEM].includes(node.type); | ||
}; | ||
const isCollectionItem = node => node && [_Node.Type.MAP_KEY, _Node.Type.MAP_VALUE, _Node.Type.SEQ_ITEM].includes(node.type); | ||
var Document = | ||
/*#__PURE__*/ | ||
function () { | ||
function Document(options) { | ||
_classCallCheck(this, Document); | ||
class Document { | ||
constructor(options) { | ||
this.anchors = new _Anchors.default(); | ||
@@ -72,511 +60,465 @@ this.commentBefore = null; | ||
_createClass(Document, [{ | ||
key: "getDefaults", | ||
value: function getDefaults() { | ||
return Document.defaults[this.version] || Document.defaults[this.options.version] || {}; | ||
} | ||
}, { | ||
key: "setSchema", | ||
value: function setSchema() { | ||
if (!this.schema) this.schema = new _schema.default(Object.assign({}, this.getDefaults(), this.options)); | ||
} | ||
}, { | ||
key: "parse", | ||
value: function parse(_ref) { | ||
var _this = this; | ||
getDefaults() { | ||
return Document.defaults[this.version] || Document.defaults[this.options.version] || {}; | ||
} | ||
var _ref$directives = _ref.directives, | ||
directives = _ref$directives === void 0 ? [] : _ref$directives, | ||
_ref$contents = _ref.contents, | ||
contents = _ref$contents === void 0 ? [] : _ref$contents, | ||
error = _ref.error, | ||
valueRange = _ref.valueRange; | ||
setSchema() { | ||
if (!this.schema) this.schema = new _schema.default(Object.assign({}, this.getDefaults(), this.options)); | ||
} | ||
if (error) { | ||
if (!error.source) error.source = this; | ||
this.errors.push(error); | ||
} | ||
parse(node) { | ||
if (this.options.keepCstNodes) this.cstNode = node; | ||
if (this.options.keepNodeTypes) this.type = "DOCUMENT"; | ||
const _node$directives = node.directives, | ||
directives = _node$directives === void 0 ? [] : _node$directives, | ||
_node$contents = node.contents, | ||
contents = _node$contents === void 0 ? [] : _node$contents, | ||
error = node.error, | ||
valueRange = node.valueRange; | ||
var directiveComments = []; | ||
directives.forEach(function (directive) { | ||
var comment = directive.comment, | ||
if (error) { | ||
if (!error.source) error.source = this; | ||
this.errors.push(error); | ||
} | ||
const directiveComments = []; | ||
directives.forEach(directive => { | ||
const comment = directive.comment, | ||
name = directive.name; | ||
switch (name) { | ||
case 'TAG': | ||
_this.resolveTagDirective(directive); | ||
switch (name) { | ||
case 'TAG': | ||
this.resolveTagDirective(directive); | ||
break; | ||
break; | ||
case 'YAML': | ||
case 'YAML:1.0': | ||
this.resolveYamlDirective(directive); | ||
break; | ||
case 'YAML': | ||
case 'YAML:1.0': | ||
_this.resolveYamlDirective(directive); | ||
default: | ||
if (name) { | ||
const msg = `YAML only supports %TAG and %YAML directives, and not %${name}`; | ||
this.warnings.push(new _errors.YAMLWarning(directive, msg)); | ||
} | ||
break; | ||
} | ||
default: | ||
if (name) { | ||
var msg = "YAML only supports %TAG and %YAML directives, and not %".concat(name); | ||
if (comment) directiveComments.push(comment); | ||
}); | ||
this.range = valueRange ? [valueRange.start, valueRange.end] : null; | ||
this.setSchema(); | ||
this.anchors._cstAliases = []; | ||
this.commentBefore = directiveComments.join('\n') || null; | ||
const comments = { | ||
before: [], | ||
after: [] | ||
}; | ||
const contentNodes = []; | ||
contents.forEach(node => { | ||
if (node.valueRange) { | ||
if (contentNodes.length === 1) { | ||
const msg = 'Document is not valid YAML (bad indentation?)'; | ||
this.errors.push(new _errors.YAMLSyntaxError(node, msg)); | ||
} | ||
_this.warnings.push(new _errors.YAMLWarning(directive, msg)); | ||
} | ||
contentNodes.push(this.resolveNode(node)); | ||
} else if (node.comment) { | ||
const cc = contentNodes.length === 0 ? comments.before : comments.after; | ||
cc.push(node.comment); | ||
} | ||
}); | ||
} | ||
switch (contentNodes.length) { | ||
case 0: | ||
this.contents = null; | ||
comments.after = comments.before; | ||
break; | ||
if (comment) directiveComments.push(comment); | ||
}); | ||
this.range = valueRange ? [valueRange.start, valueRange.end] : null; | ||
this.setSchema(); | ||
this.anchors._cstAliases = []; | ||
this.commentBefore = directiveComments.join('\n') || null; | ||
var comments = { | ||
before: [], | ||
after: [] | ||
}; | ||
var contentNodes = []; | ||
contents.forEach(function (node) { | ||
if (node.valueRange && !node.valueRange.isEmpty) { | ||
if (contentNodes.length === 1) { | ||
var msg = 'Document is not valid YAML (bad indentation?)'; | ||
case 1: | ||
this.contents = contentNodes[0]; | ||
_this.errors.push(new _errors.YAMLSyntaxError(node, msg)); | ||
if (this.contents) { | ||
const cb = comments.before.join('\n') || null; | ||
if (cb) { | ||
const cbNode = this.contents instanceof _Collection.default && this.contents.items[0] ? this.contents.items[0] : this.contents; | ||
cbNode.commentBefore = cbNode.commentBefore ? `${cb}\n${cbNode.commentBefore}` : cb; | ||
} | ||
contentNodes.push(_this.resolveNode(node)); | ||
} else if (node.comment) { | ||
var cc = contentNodes.length === 0 ? comments.before : comments.after; | ||
cc.push(node.comment); | ||
} else { | ||
comments.after = comments.before.concat(comments.after); | ||
} | ||
}); | ||
switch (contentNodes.length) { | ||
case 0: | ||
this.contents = null; | ||
comments.after = comments.before; | ||
break; | ||
break; | ||
case 1: | ||
this.contents = contentNodes[0]; | ||
default: | ||
this.contents = contentNodes; | ||
if (this.contents) { | ||
var cb = comments.before.join('\n') || null; | ||
if (this.contents[0]) { | ||
this.contents[0].commentBefore = comments.before.join('\n') || null; | ||
} else { | ||
comments.after = comments.before.concat(comments.after); | ||
} | ||
if (cb) { | ||
var cbNode = this.contents instanceof _Collection.default && this.contents.items[0] ? this.contents.items[0] : this.contents; | ||
cbNode.commentBefore = cbNode.commentBefore ? "".concat(cb, "\n").concat(cbNode.commentBefore) : cb; | ||
} | ||
} else { | ||
comments.after = comments.before.concat(comments.after); | ||
} | ||
} | ||
break; | ||
this.comment = comments.after.join('\n') || null; | ||
this.anchors.resolveNodes(); | ||
return this; | ||
} | ||
default: | ||
this.contents = contentNodes; | ||
if (this.contents[0]) { | ||
this.contents[0].commentBefore = comments.before.join('\n') || null; | ||
} else { | ||
comments.after = comments.before.concat(comments.after); | ||
} | ||
} | ||
this.comment = comments.after.join('\n') || null; | ||
this.anchors.resolveNodes(); | ||
return this; | ||
} | ||
}, { | ||
key: "resolveTagDirective", | ||
value: function resolveTagDirective(directive) { | ||
var _directive$parameters = _slicedToArray(directive.parameters, 2), | ||
resolveTagDirective(directive) { | ||
const _directive$parameters = _slicedToArray(directive.parameters, 2), | ||
handle = _directive$parameters[0], | ||
prefix = _directive$parameters[1]; | ||
if (handle && prefix) { | ||
if (this.tagPrefixes.every(function (p) { | ||
return p.handle !== handle; | ||
})) { | ||
this.tagPrefixes.push({ | ||
handle: handle, | ||
prefix: prefix | ||
}); | ||
} else { | ||
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)); | ||
} | ||
if (handle && prefix) { | ||
if (this.tagPrefixes.every(p => p.handle !== handle)) { | ||
this.tagPrefixes.push({ | ||
handle, | ||
prefix | ||
}); | ||
} else { | ||
var _msg = 'Insufficient parameters given for %TAG directive'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, _msg)); | ||
const 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)); | ||
} | ||
} else { | ||
const msg = 'Insufficient parameters given for %TAG directive'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, msg)); | ||
} | ||
}, { | ||
key: "resolveYamlDirective", | ||
value: function resolveYamlDirective(directive) { | ||
var _directive$parameters2 = _slicedToArray(directive.parameters, 1), | ||
version = _directive$parameters2[0]; | ||
} | ||
if (directive.name === 'YAML:1.0') version = '1.0'; | ||
resolveYamlDirective(directive) { | ||
let _directive$parameters2 = _slicedToArray(directive.parameters, 1), | ||
version = _directive$parameters2[0]; | ||
if (this.version) { | ||
var msg = 'The %YAML directive must only be given at most once per document.'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, msg)); | ||
} | ||
if (directive.name === 'YAML:1.0') version = '1.0'; | ||
if (!version) { | ||
var _msg2 = 'Insufficient parameters given for %YAML directive'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, _msg2)); | ||
} else { | ||
if (!Document.defaults[version]) { | ||
var v0 = this.version || this.options.version; | ||
if (this.version) { | ||
const msg = 'The %YAML directive must only be given at most once per document.'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, msg)); | ||
} | ||
var _msg3 = "Document will be parsed as YAML ".concat(v0, " rather than YAML ").concat(version); | ||
if (!version) { | ||
const msg = 'Insufficient parameters given for %YAML directive'; | ||
this.errors.push(new _errors.YAMLSemanticError(directive, msg)); | ||
} else { | ||
if (!Document.defaults[version]) { | ||
const v0 = this.version || this.options.version; | ||
const msg = `Document will be parsed as YAML ${v0} rather than YAML ${version}`; | ||
this.warnings.push(new _errors.YAMLWarning(directive, msg)); | ||
} | ||
this.warnings.push(new _errors.YAMLWarning(directive, _msg3)); | ||
} | ||
this.version = version; | ||
} | ||
} | ||
this.version = version; | ||
} | ||
} | ||
}, { | ||
key: "resolveTagName", | ||
value: function resolveTagName(node) { | ||
var tag = node.tag, | ||
resolveTagName(node) { | ||
const tag = node.tag, | ||
type = node.type; | ||
var nonSpecific = false; | ||
let nonSpecific = false; | ||
if (tag) { | ||
var handle = tag.handle, | ||
if (tag) { | ||
const handle = tag.handle, | ||
suffix = tag.suffix, | ||
verbatim = tag.verbatim; | ||
if (verbatim) { | ||
if (verbatim !== '!' && verbatim !== '!!') return verbatim; | ||
var msg = "Verbatim tags aren't resolved, so ".concat(verbatim, " is invalid."); | ||
this.errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
} else if (handle === '!' && !suffix) { | ||
nonSpecific = true; | ||
} else { | ||
var prefix = this.tagPrefixes.find(function (p) { | ||
return p.handle === handle; | ||
}); | ||
if (verbatim) { | ||
if (verbatim !== '!' && verbatim !== '!!') return verbatim; | ||
const msg = `Verbatim tags aren't resolved, so ${verbatim} is invalid.`; | ||
this.errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
} else if (handle === '!' && !suffix) { | ||
nonSpecific = true; | ||
} else { | ||
let prefix = this.tagPrefixes.find(p => p.handle === handle); | ||
if (!prefix) { | ||
var dtp = this.getDefaults().tagPrefixes; | ||
if (dtp) prefix = dtp.find(function (p) { | ||
return p.handle === handle; | ||
}); | ||
} | ||
if (!prefix) { | ||
const dtp = this.getDefaults().tagPrefixes; | ||
if (dtp) prefix = dtp.find(p => p.handle === handle); | ||
} | ||
if (prefix) { | ||
if (suffix) { | ||
if (handle === '!' && (this.version || this.options.version) === '1.0') { | ||
if (suffix[0] === '^') return suffix; | ||
if (prefix) { | ||
if (suffix) { | ||
if (handle === '!' && (this.version || this.options.version) === '1.0') { | ||
if (suffix[0] === '^') return suffix; | ||
if (/[:/]/.test(suffix)) { | ||
// word/foo -> tag:word.yaml.org,2002:foo | ||
var vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i); | ||
return vocab ? "tag:".concat(vocab[1], ".yaml.org,2002:").concat(vocab[2]) : "tag:".concat(suffix); | ||
} | ||
if (/[:/]/.test(suffix)) { | ||
// word/foo -> tag:word.yaml.org,2002:foo | ||
const vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i); | ||
return vocab ? `tag:${vocab[1]}.yaml.org,2002:${vocab[2]}` : `tag:${suffix}`; | ||
} | ||
return prefix.prefix + decodeURIComponent(suffix); | ||
} | ||
this.errors.push(new _errors.YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix."))); | ||
} else { | ||
var _msg4 = "The ".concat(handle, " tag handle is non-default and was not declared."); | ||
return prefix.prefix + decodeURIComponent(suffix); | ||
} | ||
this.errors.push(new _errors.YAMLSemanticError(node, _msg4)); | ||
} | ||
this.errors.push(new _errors.YAMLSemanticError(node, `The ${handle} tag has no suffix.`)); | ||
} else { | ||
const msg = `The ${handle} tag handle is non-default and was not declared.`; | ||
this.errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
} | ||
} | ||
} | ||
switch (type) { | ||
case _Node.Type.BLOCK_FOLDED: | ||
case _Node.Type.BLOCK_LITERAL: | ||
case _Node.Type.QUOTE_DOUBLE: | ||
case _Node.Type.QUOTE_SINGLE: | ||
return _schema.DefaultTags.STR; | ||
switch (type) { | ||
case _Node.Type.BLOCK_FOLDED: | ||
case _Node.Type.BLOCK_LITERAL: | ||
case _Node.Type.QUOTE_DOUBLE: | ||
case _Node.Type.QUOTE_SINGLE: | ||
return _schema.DefaultTags.STR; | ||
case _Node.Type.FLOW_MAP: | ||
case _Node.Type.MAP: | ||
return _schema.DefaultTags.MAP; | ||
case _Node.Type.FLOW_MAP: | ||
case _Node.Type.MAP: | ||
return _schema.DefaultTags.MAP; | ||
case _Node.Type.FLOW_SEQ: | ||
case _Node.Type.SEQ: | ||
return _schema.DefaultTags.SEQ; | ||
case _Node.Type.FLOW_SEQ: | ||
case _Node.Type.SEQ: | ||
return _schema.DefaultTags.SEQ; | ||
case _Node.Type.PLAIN: | ||
return nonSpecific ? _schema.DefaultTags.STR : null; | ||
case _Node.Type.PLAIN: | ||
return nonSpecific ? _schema.DefaultTags.STR : null; | ||
default: | ||
return null; | ||
} | ||
default: | ||
return null; | ||
} | ||
}, { | ||
key: "resolveNode", | ||
value: function resolveNode(node) { | ||
if (!node) return null; | ||
var anchors = this.anchors, | ||
} | ||
resolveNode(node) { | ||
if (!node) return null; | ||
const anchors = this.anchors, | ||
errors = this.errors, | ||
schema = this.schema; | ||
var hasAnchor = false; | ||
var hasTag = false; | ||
var comments = { | ||
before: [], | ||
after: [] | ||
}; | ||
var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props; | ||
props.forEach(function (_ref2, i) { | ||
var start = _ref2.start, | ||
end = _ref2.end; | ||
let hasAnchor = false; | ||
let hasTag = false; | ||
const comments = { | ||
before: [], | ||
after: [] | ||
}; | ||
const props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props; | ||
props.forEach(({ | ||
start, | ||
end | ||
}, i) => { | ||
switch (node.context.src[start]) { | ||
case _Node.Char.COMMENT: | ||
if (!node.commentHasRequiredWhitespace(start)) { | ||
const msg = 'Comments must be separated from other tokens by white space characters'; | ||
errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
} | ||
switch (node.context.src[start]) { | ||
case _Node.Char.COMMENT: | ||
if (!node.commentHasRequiredWhitespace(start)) { | ||
var msg = 'Comments must be separated from other tokens by white space characters'; | ||
errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
} | ||
var c = node.context.src.slice(start + 1, end); | ||
var header = node.header, | ||
const c = node.context.src.slice(start + 1, end); | ||
const header = node.header, | ||
valueRange = node.valueRange; | ||
if (valueRange && (start > valueRange.start || header && start > header.start)) { | ||
comments.after.push(c); | ||
} else { | ||
comments.before.push(c); | ||
} | ||
if (valueRange && (start > valueRange.start || header && start > header.start)) { | ||
comments.after.push(c); | ||
} else { | ||
comments.before.push(c); | ||
} | ||
break; | ||
break; | ||
case _Node.Char.ANCHOR: | ||
if (hasAnchor) { | ||
var _msg5 = 'A node can have at most one anchor'; | ||
errors.push(new _errors.YAMLSemanticError(node, _msg5)); | ||
} | ||
case _Node.Char.ANCHOR: | ||
if (hasAnchor) { | ||
const msg = 'A node can have at most one anchor'; | ||
errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
} | ||
hasAnchor = true; | ||
break; | ||
hasAnchor = true; | ||
break; | ||
case _Node.Char.TAG: | ||
if (hasTag) { | ||
var _msg6 = 'A node can have at most one tag'; | ||
errors.push(new _errors.YAMLSemanticError(node, _msg6)); | ||
} | ||
case _Node.Char.TAG: | ||
if (hasTag) { | ||
const msg = 'A node can have at most one tag'; | ||
errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
} | ||
hasTag = true; | ||
break; | ||
} | ||
}); | ||
hasTag = true; | ||
break; | ||
} | ||
}); | ||
if (hasAnchor) { | ||
var name = node.anchor; | ||
var prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor | ||
// name have already been resolved, so it may safely be renamed. | ||
if (hasAnchor) { | ||
const name = node.anchor; | ||
const prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor | ||
// name have already been resolved, so it may safely be renamed. | ||
if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as | ||
// anchors need to be available during resolution to allow for | ||
// circular references. | ||
if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as | ||
// anchors need to be available during resolution to allow for | ||
// circular references. | ||
anchors.map[name] = node; | ||
} | ||
anchors.map[name] = node; | ||
} | ||
var res; | ||
let res; | ||
if (node.type === _Node.Type.ALIAS) { | ||
if (hasAnchor || hasTag) { | ||
var msg = 'An alias node must not specify any properties'; | ||
errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
} | ||
if (node.type === _Node.Type.ALIAS) { | ||
if (hasAnchor || hasTag) { | ||
const msg = 'An alias node must not specify any properties'; | ||
errors.push(new _errors.YAMLSemanticError(node, msg)); | ||
} | ||
var _name = node.rawValue; | ||
var src = anchors.getNode(_name); | ||
const name = node.rawValue; | ||
const src = anchors.getNode(name); | ||
if (!src) { | ||
var _msg7 = "Aliased anchor not found: ".concat(_name); | ||
if (!src) { | ||
const msg = `Aliased anchor not found: ${name}`; | ||
errors.push(new _errors.YAMLReferenceError(node, msg)); | ||
return null; | ||
} // Lazy resolution for circular references | ||
errors.push(new _errors.YAMLReferenceError(node, _msg7)); | ||
return null; | ||
} // Lazy resolution for circular references | ||
res = new _Alias.default(src); | ||
res = new _Alias.default(src); | ||
anchors._cstAliases.push(res); | ||
anchors._cstAliases.push(res); | ||
if (!src.resolved) { | ||
const msg = 'Alias node contains a circular reference, which cannot be resolved as JSON'; | ||
this.warnings.push(new _errors.YAMLWarning(node, msg)); | ||
} | ||
} else { | ||
const tagName = this.resolveTagName(node); | ||
if (!src.resolved) { | ||
var _msg8 = 'Alias node contains a circular reference, which cannot be resolved as JSON'; | ||
this.warnings.push(new _errors.YAMLWarning(node, _msg8)); | ||
if (tagName) { | ||
res = schema.resolveNodeWithFallback(this, node, tagName); | ||
} else { | ||
if (node.type !== _Node.Type.PLAIN) { | ||
const msg = `Failed to resolve ${node.type} node here`; | ||
errors.push(new _errors.YAMLSyntaxError(node, msg)); | ||
return null; | ||
} | ||
} else { | ||
var tagName = this.resolveTagName(node); | ||
if (tagName) { | ||
res = schema.resolveNodeWithFallback(this, node, tagName); | ||
} else { | ||
if (node.type !== _Node.Type.PLAIN) { | ||
var _msg9 = "Failed to resolve ".concat(node.type, " node here"); | ||
try { | ||
res = schema.resolveScalar(node.strValue || ''); | ||
} catch (error) { | ||
if (!error.source) error.source = node; | ||
errors.push(error); | ||
return null; | ||
} | ||
} | ||
} | ||
errors.push(new _errors.YAMLSyntaxError(node, _msg9)); | ||
return null; | ||
} | ||
if (res) { | ||
res.range = [node.range.start, node.range.end]; | ||
if (this.options.keepCstNodes) res.cstNode = node; | ||
if (this.options.keepNodeTypes) res.type = node.type; | ||
const cb = comments.before.join('\n'); | ||
try { | ||
res = schema.resolveScalar(node.strValue || ''); | ||
} catch (error) { | ||
if (!error.source) error.source = node; | ||
errors.push(error); | ||
return null; | ||
} | ||
} | ||
if (cb) { | ||
res.commentBefore = res.commentBefore ? `${res.commentBefore}\n${cb}` : cb; | ||
} | ||
if (res) { | ||
res.range = [node.range.start, node.range.end]; | ||
if (this.options.keepCstNodes) res.cstNode = node; | ||
if (this.options.keepNodeTypes) res.type = node.type; | ||
var cb = comments.before.join('\n'); | ||
const ca = comments.after.join('\n'); | ||
if (ca) res.comment = res.comment ? `${res.comment}\n${ca}` : ca; | ||
} | ||
if (cb) { | ||
res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb; | ||
} | ||
return node.resolved = res; | ||
} | ||
var ca = comments.after.join('\n'); | ||
if (ca) res.comment = res.comment ? "".concat(res.comment, "\n").concat(ca) : ca; | ||
} | ||
listNonDefaultTags() { | ||
return (0, _listTagNames.default)(this.contents).filter(t => t.indexOf(_schema.defaultPrefix) !== 0); | ||
} | ||
return node.resolved = res; | ||
} | ||
}, { | ||
key: "listNonDefaultTags", | ||
value: function listNonDefaultTags() { | ||
return (0, _listTagNames.default)(this.contents).filter(function (t) { | ||
return t.indexOf(_schema.defaultPrefix) !== 0; | ||
setTagPrefix(handle, prefix) { | ||
if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !'); | ||
if (prefix) { | ||
const prev = this.tagPrefixes.find(p => p.handle === handle); | ||
if (prev) prev.prefix = prefix;else this.tagPrefixes.push({ | ||
handle, | ||
prefix | ||
}); | ||
} else { | ||
this.tagPrefixes = this.tagPrefixes.filter(p => p.handle !== handle); | ||
} | ||
}, { | ||
key: "setTagPrefix", | ||
value: function setTagPrefix(handle, prefix) { | ||
if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !'); | ||
} | ||
if (prefix) { | ||
var prev = this.tagPrefixes.find(function (p) { | ||
return p.handle === handle; | ||
}); | ||
if (prev) prev.prefix = prefix;else this.tagPrefixes.push({ | ||
handle: handle, | ||
prefix: prefix | ||
}); | ||
} else { | ||
this.tagPrefixes = this.tagPrefixes.filter(function (p) { | ||
return p.handle !== handle; | ||
}); | ||
stringifyTag(tag) { | ||
if ((this.version || this.options.version) === '1.0') { | ||
const priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/); | ||
if (priv) return '!' + priv[1]; | ||
const vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/); | ||
return vocab ? `!${vocab[1]}/${vocab[2]}` : `!${tag.replace(/^tag:/, '')}`; | ||
} else { | ||
let p = this.tagPrefixes.find(p => tag.indexOf(p.prefix) === 0); | ||
if (!p) { | ||
const dtp = this.getDefaults().tagPrefixes; | ||
p = dtp && dtp.find(p => tag.indexOf(p.prefix) === 0); | ||
} | ||
if (!p) return tag[0] === '!' ? tag : `!<${tag}>`; | ||
const suffix = tag.substr(p.prefix.length).replace(/[!,\[]{}]/g, ch => ({ | ||
'!': '%21', | ||
',': '%2C', | ||
'[': '%5B', | ||
']': '%5D', | ||
'{': '%7B', | ||
'}': '%7D' | ||
})[ch]); | ||
return p.handle + suffix; | ||
} | ||
}, { | ||
key: "stringifyTag", | ||
value: function stringifyTag(tag) { | ||
if ((this.version || this.options.version) === '1.0') { | ||
var priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/); | ||
if (priv) return '!' + priv[1]; | ||
var vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/); | ||
return vocab ? "!".concat(vocab[1], "/").concat(vocab[2]) : "!".concat(tag.replace(/^tag:/, '')); | ||
} else { | ||
var p = this.tagPrefixes.find(function (p) { | ||
return tag.indexOf(p.prefix) === 0; | ||
}); | ||
} | ||
if (!p) { | ||
var dtp = this.getDefaults().tagPrefixes; | ||
p = dtp && dtp.find(function (p) { | ||
return tag.indexOf(p.prefix) === 0; | ||
}); | ||
} | ||
toJSON(arg) { | ||
const cr = this.warnings.find(w => /circular reference/.test(w.message)); | ||
if (cr) throw new _errors.YAMLSemanticError(cr.source, cr.message); | ||
const keep = this.options.keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default)); | ||
return (0, _toJSON.default)(this.contents, arg, keep); | ||
} | ||
if (!p) return tag[0] === '!' ? tag : "!<".concat(tag, ">"); | ||
var suffix = tag.substr(p.prefix.length).replace(/[!,\[]{}]/g, function (ch) { | ||
return { | ||
'!': '%21', | ||
',': '%2C', | ||
'[': '%5B', | ||
']': '%5D', | ||
'{': '%7B', | ||
'}': '%7D' | ||
}[ch]; | ||
}); | ||
return p.handle + suffix; | ||
toString() { | ||
if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified'); | ||
this.setSchema(); | ||
const lines = []; | ||
if (this.commentBefore) lines.push(this.commentBefore.replace(/^/gm, '#')); | ||
let hasDirectives = false; | ||
if (this.version) { | ||
let vd = '%YAML 1.2'; | ||
if (this.schema.name === 'yaml-1.1') { | ||
if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1'; | ||
} | ||
lines.push(vd); | ||
hasDirectives = true; | ||
} | ||
}, { | ||
key: "toJSON", | ||
value: function toJSON(arg) { | ||
var cr = this.warnings.find(function (w) { | ||
return /circular reference/.test(w.message); | ||
}); | ||
if (cr) throw new _errors.YAMLSemanticError(cr.source, cr.message); | ||
var keep = this.options.keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default)); | ||
return (0, _toJSON2.default)(this.contents, arg, keep); | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified'); | ||
this.setSchema(); | ||
var lines = []; | ||
if (this.commentBefore) lines.push(this.commentBefore.replace(/^/gm, '#')); | ||
var hasDirectives = false; | ||
if (this.version) { | ||
var vd = '%YAML 1.2'; | ||
if (this.schema.name === 'yaml-1.1') { | ||
if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1'; | ||
} | ||
lines.push(vd); | ||
const tagNames = this.listNonDefaultTags(); | ||
this.tagPrefixes.forEach(({ | ||
handle, | ||
prefix | ||
}) => { | ||
if (tagNames.some(t => t.indexOf(prefix) === 0)) { | ||
lines.push(`%TAG ${handle} ${prefix}`); | ||
hasDirectives = true; | ||
} | ||
}); | ||
if (hasDirectives) lines.push('---'); | ||
const ctx = { | ||
anchors: {}, | ||
doc: this, | ||
indent: '' | ||
}; | ||
var tagNames = this.listNonDefaultTags(); | ||
this.tagPrefixes.forEach(function (_ref3) { | ||
var handle = _ref3.handle, | ||
prefix = _ref3.prefix; | ||
if (this.contents) { | ||
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment | ||
if (tagNames.some(function (t) { | ||
return t.indexOf(prefix) === 0; | ||
})) { | ||
lines.push("%TAG ".concat(handle, " ").concat(prefix)); | ||
hasDirectives = true; | ||
} | ||
ctx.forceBlockIndent = !!this.comment; | ||
let comment = this.contents.comment; | ||
const body = this.schema.stringify(this.contents, ctx, () => { | ||
comment = null; | ||
}); | ||
if (hasDirectives) lines.push('---'); | ||
var ctx = { | ||
anchors: {}, | ||
doc: this, | ||
indent: '' | ||
}; | ||
lines.push((0, _addComment.default)(body, '', comment)); | ||
} else if (this.contents !== undefined) { | ||
lines.push(this.schema.stringify(this.contents, ctx)); | ||
} | ||
if (this.contents) { | ||
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment | ||
if (this.comment) lines.push(this.comment.replace(/^/gm, '#')); | ||
return lines.join('\n') + '\n'; | ||
} | ||
ctx.forceBlockIndent = !!this.comment; | ||
var comment = this.contents.comment; | ||
var body = this.schema.stringify(this.contents, ctx, function () { | ||
comment = null; | ||
}); | ||
lines.push((0, _addComment.default)(body, '', comment)); | ||
} else if (this.contents !== undefined) { | ||
lines.push(this.schema.stringify(this.contents, ctx)); | ||
} | ||
} | ||
if (this.comment) lines.push(this.comment.replace(/^/gm, '#')); | ||
return lines.join('\n') + '\n'; | ||
} | ||
}]); | ||
return Document; | ||
}(); | ||
exports.default = Document; | ||
@@ -583,0 +525,0 @@ |
@@ -12,32 +12,4 @@ "use strict"; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null) return null; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } | ||
function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var YAMLReferenceError = | ||
/*#__PURE__*/ | ||
function (_ReferenceError) { | ||
_inherits(YAMLReferenceError, _ReferenceError); | ||
function YAMLReferenceError(source, message) { | ||
var _this; | ||
_classCallCheck(this, YAMLReferenceError); | ||
class YAMLReferenceError extends ReferenceError { | ||
constructor(source, message) { | ||
if (!message || !(source instanceof _Node.default)) { | ||
@@ -47,24 +19,14 @@ throw new Error('Invalid arguments for new YAMLReferenceError'); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(YAMLReferenceError).call(this)); | ||
_this.name = 'YAMLReferenceError'; | ||
_this.message = message; | ||
_this.source = source; | ||
return _this; | ||
super(); | ||
this.name = 'YAMLReferenceError'; | ||
this.message = message; | ||
this.source = source; | ||
} | ||
return YAMLReferenceError; | ||
}(_wrapNativeSuper(ReferenceError)); | ||
} | ||
exports.YAMLReferenceError = YAMLReferenceError; | ||
var YAMLSemanticError = | ||
/*#__PURE__*/ | ||
function (_SyntaxError) { | ||
_inherits(YAMLSemanticError, _SyntaxError); | ||
function YAMLSemanticError(source, message) { | ||
var _this2; | ||
_classCallCheck(this, YAMLSemanticError); | ||
class YAMLSemanticError extends SyntaxError { | ||
constructor(source, message) { | ||
if (!message || !(source instanceof _Node.default)) { | ||
@@ -74,24 +36,14 @@ throw new Error('Invalid arguments for new YAMLSemanticError'); | ||
_this2 = _possibleConstructorReturn(this, _getPrototypeOf(YAMLSemanticError).call(this)); | ||
_this2.name = 'YAMLSemanticError'; | ||
_this2.message = message; | ||
_this2.source = source; | ||
return _this2; | ||
super(); | ||
this.name = 'YAMLSemanticError'; | ||
this.message = message; | ||
this.source = source; | ||
} | ||
return YAMLSemanticError; | ||
}(_wrapNativeSuper(SyntaxError)); | ||
} | ||
exports.YAMLSemanticError = YAMLSemanticError; | ||
var YAMLSyntaxError = | ||
/*#__PURE__*/ | ||
function (_SyntaxError2) { | ||
_inherits(YAMLSyntaxError, _SyntaxError2); | ||
function YAMLSyntaxError(source, message) { | ||
var _this3; | ||
_classCallCheck(this, YAMLSyntaxError); | ||
class YAMLSyntaxError extends SyntaxError { | ||
constructor(source, message) { | ||
if (!message || !(source instanceof _Node.default)) { | ||
@@ -101,24 +53,14 @@ throw new Error('Invalid arguments for new YAMLSyntaxError'); | ||
_this3 = _possibleConstructorReturn(this, _getPrototypeOf(YAMLSyntaxError).call(this)); | ||
_this3.name = 'YAMLSyntaxError'; | ||
_this3.message = message; | ||
_this3.source = source; | ||
return _this3; | ||
super(); | ||
this.name = 'YAMLSyntaxError'; | ||
this.message = message; | ||
this.source = source; | ||
} | ||
return YAMLSyntaxError; | ||
}(_wrapNativeSuper(SyntaxError)); | ||
} | ||
exports.YAMLSyntaxError = YAMLSyntaxError; | ||
var YAMLWarning = | ||
/*#__PURE__*/ | ||
function (_Error) { | ||
_inherits(YAMLWarning, _Error); | ||
function YAMLWarning(source, message) { | ||
var _this4; | ||
_classCallCheck(this, YAMLWarning); | ||
class YAMLWarning extends Error { | ||
constructor(source, message) { | ||
if (!message || !(source instanceof _Node.default)) { | ||
@@ -128,12 +70,10 @@ throw new Error('Invalid arguments for new YAMLWarning'); | ||
_this4 = _possibleConstructorReturn(this, _getPrototypeOf(YAMLWarning).call(this)); | ||
_this4.name = 'YAMLWarning'; | ||
_this4.message = message; | ||
_this4.source = source; | ||
return _this4; | ||
super(); | ||
this.name = 'YAMLWarning'; | ||
this.message = message; | ||
this.source = source; | ||
} | ||
return YAMLWarning; | ||
}(_wrapNativeSuper(Error)); | ||
} | ||
exports.YAMLWarning = YAMLWarning; |
@@ -8,7 +8,7 @@ "use strict"; | ||
exports.FOLD_QUOTED = exports.FOLD_BLOCK = exports.FOLD_FLOW = void 0; | ||
var FOLD_FLOW = 'flow'; | ||
const FOLD_FLOW = 'flow'; | ||
exports.FOLD_FLOW = FOLD_FLOW; | ||
var FOLD_BLOCK = 'block'; | ||
const FOLD_BLOCK = 'block'; | ||
exports.FOLD_BLOCK = FOLD_BLOCK; | ||
var FOLD_QUOTED = 'quoted'; | ||
const FOLD_QUOTED = 'quoted'; | ||
/** | ||
@@ -37,21 +37,20 @@ * Tries to keep input at up to `lineWidth` characters, splitting only on spaces | ||
function foldFlowLines(text, indent, mode, _ref) { | ||
var indentAtStart = _ref.indentAtStart, | ||
_ref$lineWidth = _ref.lineWidth, | ||
lineWidth = _ref$lineWidth === void 0 ? 80 : _ref$lineWidth, | ||
_ref$minContentWidth = _ref.minContentWidth, | ||
minContentWidth = _ref$minContentWidth === void 0 ? 20 : _ref$minContentWidth, | ||
onFold = _ref.onFold, | ||
onOverflow = _ref.onOverflow; | ||
function foldFlowLines(text, indent, mode, { | ||
indentAtStart, | ||
lineWidth = 80, | ||
minContentWidth = 20, | ||
onFold, | ||
onOverflow | ||
}) { | ||
if (!lineWidth || lineWidth < 0) return text; | ||
var endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length); | ||
const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length); | ||
if (text.length <= endStep) return text; | ||
var folds = []; | ||
var escapedFolds = {}; | ||
var end = lineWidth - (typeof indentAtStart === 'number' ? indentAtStart : indent.length); | ||
var split = undefined; | ||
var prev = undefined; | ||
var overflow = false; | ||
const folds = []; | ||
const escapedFolds = {}; | ||
let end = lineWidth - (typeof indentAtStart === 'number' ? indentAtStart : indent.length); | ||
let split = undefined; | ||
let prev = undefined; | ||
let overflow = false; | ||
for (var i = 0, ch = text[0]; ch; ch = text[i += 1]) { | ||
for (let i = 0, ch = text[0]; ch; ch = text[i += 1]) { | ||
if (mode === FOLD_QUOTED && ch === '\\') { | ||
@@ -79,3 +78,3 @@ switch (text[i + 1]) { | ||
// more-indented lines in blocks can't be folded | ||
var next = text[i + 1]; | ||
let next = text[i + 1]; | ||
@@ -96,4 +95,4 @@ while (next === ' ' || next === '\t') { | ||
// space surrounded by non-space can be replaced with newline + indent | ||
var _next = text[i + 1]; | ||
if (_next && _next !== ' ' && _next !== '\n' && _next !== '\t') split = i; | ||
const next = text[i + 1]; | ||
if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i; | ||
} | ||
@@ -131,11 +130,9 @@ | ||
if (onFold) onFold(); | ||
var res = text.slice(0, folds[0]); | ||
let res = text.slice(0, folds[0]); | ||
for (var _i = 0; _i < folds.length; ++_i) { | ||
var fold = folds[_i]; | ||
var _end = folds[_i + 1] || text.length; | ||
if (mode === FOLD_QUOTED && escapedFolds[fold]) res += "".concat(text[fold], "\\"); | ||
res += "\n".concat(indent).concat(text.slice(fold + 1, _end)); | ||
for (let i = 0; i < folds.length; ++i) { | ||
const fold = folds[i]; | ||
const end = folds[i + 1] || text.length; | ||
if (mode === FOLD_QUOTED && escapedFolds[fold]) res += `${text[fold]}\\`; | ||
res += `\n${indent}${text.slice(fold + 1, end)}`; | ||
} | ||
@@ -142,0 +139,0 @@ |
@@ -18,17 +18,3 @@ "use strict"; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var defaultOptions = { | ||
const defaultOptions = { | ||
keepNodeTypes: true, | ||
@@ -40,28 +26,19 @@ keepBlobsInJSON: true, | ||
var Document = | ||
/*#__PURE__*/ | ||
function (_YAMLDocument) { | ||
_inherits(Document, _YAMLDocument); | ||
function Document(options) { | ||
_classCallCheck(this, Document); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(Document).call(this, Object.assign({}, defaultOptions, options))); | ||
class Document extends _Document.default { | ||
constructor(options) { | ||
super(Object.assign({}, defaultOptions, options)); | ||
} | ||
return Document; | ||
}(_Document.default); | ||
} | ||
function parseAllDocuments(src, options) { | ||
return (0, _parse.default)(src).map(function (cstDoc) { | ||
return new Document(options).parse(cstDoc); | ||
}); | ||
return (0, _parse.default)(src).map(cstDoc => new Document(options).parse(cstDoc)); | ||
} | ||
function parseDocument(src, options) { | ||
var cst = (0, _parse.default)(src); | ||
var doc = new Document(options).parse(cst[0]); | ||
const cst = (0, _parse.default)(src); | ||
const doc = new Document(options).parse(cst[0]); | ||
if (cst.length > 1) { | ||
var errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()'; | ||
const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()'; | ||
doc.errors.unshift(new _errors.YAMLSemanticError(cst[1], errMsg)); | ||
@@ -74,6 +51,4 @@ } | ||
function parse(src, options) { | ||
var doc = parseDocument(src, options); | ||
doc.warnings.forEach(function (warning) { | ||
return console.warn(warning); | ||
}); | ||
const doc = parseDocument(src, options); | ||
doc.warnings.forEach(warning => console.warn(warning)); | ||
if (doc.errors.length > 0) throw doc.errors[0]; | ||
@@ -84,3 +59,3 @@ return doc.toJSON(); | ||
function stringify(value, options) { | ||
var doc = new Document(options); | ||
const doc = new Document(options); | ||
doc.contents = value; | ||
@@ -92,10 +67,10 @@ return String(doc); | ||
createNode: _createNode.default, | ||
defaultOptions: defaultOptions, | ||
Document: Document, | ||
parse: parse, | ||
parseAllDocuments: parseAllDocuments, | ||
defaultOptions, | ||
Document, | ||
parse, | ||
parseAllDocuments, | ||
parseCST: _parse.default, | ||
parseDocument: parseDocument, | ||
stringify: stringify | ||
parseDocument, | ||
stringify | ||
}; | ||
exports.default = _default; |
@@ -16,13 +16,9 @@ "use strict"; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
const visit = (node, tags) => { | ||
if (node && typeof node === 'object') { | ||
const tag = node.tag; | ||
var visit = function visit(node, tags) { | ||
if (node && _typeof(node) === 'object') { | ||
var tag = node.tag; | ||
if (node instanceof _Collection.default) { | ||
if (tag) tags[tag] = true; | ||
node.items.forEach(function (n) { | ||
return visit(n, tags); | ||
}); | ||
node.items.forEach(n => visit(n, tags)); | ||
} else if (node instanceof _Pair.default) { | ||
@@ -39,6 +35,4 @@ visit(node.key, tags); | ||
var _default = function _default(node) { | ||
return Object.keys(visit(node, {})); | ||
}; | ||
var _default = node => Object.keys(visit(node, {})); | ||
exports.default = _default; |
@@ -15,3 +15,3 @@ "use strict"; | ||
// Published as 'yaml/types/binary' | ||
var binary = { | ||
const binary = { | ||
class: Uint8Array, | ||
@@ -30,15 +30,12 @@ // Buffer inherits from Uint8Array | ||
*/ | ||
resolve: function resolve(doc, node) { | ||
resolve: (doc, node) => { | ||
if (typeof Buffer === 'function') { | ||
var src = (0, _string.resolve)(doc, node); | ||
const src = (0, _string.resolve)(doc, node); | ||
return Buffer.from(src, 'base64'); | ||
} else if (typeof atob === 'function') { | ||
var _src = atob((0, _string.resolve)(doc, node)); | ||
const src = atob((0, _string.resolve)(doc, node)); | ||
const buffer = new Uint8Array(src.length); | ||
var buffer = new Uint8Array(_src.length); | ||
for (let i = 0; i < src.length; ++i) buffer[i] = src.charCodeAt(i); | ||
for (var i = 0; i < _src.length; ++i) { | ||
buffer[i] = _src.charCodeAt(i); | ||
} | ||
return buffer; | ||
@@ -54,7 +51,8 @@ } else { | ||
}, | ||
stringify: function stringify(_ref, ctx, onComment) { | ||
var comment = _ref.comment, | ||
type = _ref.type, | ||
value = _ref.value; | ||
var src; | ||
stringify: ({ | ||
comment, | ||
type, | ||
value | ||
}, ctx, onComment) => { | ||
let src; | ||
@@ -64,7 +62,5 @@ if (typeof Buffer === 'function') { | ||
} else if (typeof btoa === 'function') { | ||
var s = ''; | ||
let s = ''; | ||
for (var i = 0; i < value.length; ++i) { | ||
s += String.fromCharCode(buf[i]); | ||
} | ||
for (let i = 0; i < value.length; ++i) s += String.fromCharCode(buf[i]); | ||
@@ -81,8 +77,8 @@ src = btoa(s); | ||
} else { | ||
var lineWidth = binary.options.lineWidth; | ||
var n = Math.ceil(src.length / lineWidth); | ||
var lines = new Array(n); | ||
const lineWidth = binary.options.lineWidth; | ||
const n = Math.ceil(src.length / lineWidth); | ||
const lines = new Array(n); | ||
for (var _i = 0, o = 0; _i < n; ++_i, o += lineWidth) { | ||
lines[_i] = src.substr(o, lineWidth); | ||
for (let i = 0, o = 0; i < n; ++i, o += lineWidth) { | ||
lines[i] = src.substr(o, lineWidth); | ||
} | ||
@@ -94,5 +90,5 @@ | ||
return (0, _string.stringify)({ | ||
comment: comment, | ||
type: type, | ||
value: value | ||
comment, | ||
type, | ||
value | ||
}, ctx, onComment); | ||
@@ -99,0 +95,0 @@ } |
@@ -17,5 +17,4 @@ "use strict"; | ||
var strOptions = { | ||
const strOptions = { | ||
defaultType: _Node.Type.PLAIN, | ||
dropCR: false, | ||
doubleQuoted: { | ||
@@ -32,8 +31,23 @@ jsonEncoding: false, | ||
var resolve = function resolve(doc, node) { | ||
const lineLengthOverLimit = (str, limit) => { | ||
const strLen = str.length; | ||
if (strLen <= limit) return false; | ||
for (let i = 0, start = 0; i < strLen; ++i) { | ||
if (str[i] === '\n') { | ||
if (i - start > limit) return true; | ||
start = i + 1; | ||
if (strLen - start <= limit) return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
const resolve = (doc, node) => { | ||
// on error, will return { str: string, errors: Error[] } | ||
var res = node.strValue; | ||
const res = node.strValue; | ||
if (!res) return ''; | ||
if (typeof res === 'string') return res; | ||
res.errors.forEach(function (error) { | ||
res.errors.forEach(error => { | ||
if (!error.source) error.source = node; | ||
@@ -47,12 +61,15 @@ doc.errors.push(error); | ||
function doubleQuotedString(value, indent, oneLine) { | ||
var _strOptions$doubleQuo = strOptions.doubleQuoted, | ||
jsonEncoding = _strOptions$doubleQuo.jsonEncoding, | ||
minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength; | ||
var json = JSON.stringify(value); | ||
function doubleQuotedString(value, { | ||
implicitKey, | ||
indent | ||
}) { | ||
const _strOptions$doubleQuo = strOptions.doubleQuoted, | ||
jsonEncoding = _strOptions$doubleQuo.jsonEncoding, | ||
minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength; | ||
const json = JSON.stringify(value); | ||
if (jsonEncoding) return json; | ||
var str = ''; | ||
var start = 0; | ||
let str = ''; | ||
let start = 0; | ||
for (var i = 0, ch = json[i]; ch; ch = json[++i]) { | ||
for (let i = 0, ch = json[i]; ch; ch = json[++i]) { | ||
if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') { | ||
@@ -69,3 +86,3 @@ // space before newline needs to be escaped to not be folded | ||
str += json.slice(start, i); | ||
var code = json.substr(i + 2, 4); | ||
const code = json.substr(i + 2, 4); | ||
@@ -114,3 +131,3 @@ switch (code) { | ||
case 'n': | ||
if (oneLine || json[i + 2] === '"' || json.length < minMultiLineLength) { | ||
if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) { | ||
i += 1; | ||
@@ -141,33 +158,41 @@ } else { | ||
str = start ? str + json.slice(start) : json; | ||
return oneLine ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, strOptions.fold); | ||
return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, strOptions.fold); | ||
} | ||
function singleQuotedString(value, indent, oneLine) { | ||
if (oneLine) { | ||
if (/\n/.test(value)) return doubleQuotedString(value, indent, true); | ||
function singleQuotedString(value, ctx) { | ||
const indent = ctx.indent, | ||
implicitKey = ctx.implicitKey; | ||
if (implicitKey) { | ||
if (/\n/.test(value)) return doubleQuotedString(value, ctx); | ||
} else { | ||
// single quoted string can't have leading or trailing whitespace around newline | ||
if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, indent, false); | ||
if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx); | ||
} | ||
value = "'" + value.replace(/'/g, "''").replace(/\n+/g, "$&\n".concat(indent)) + "'"; | ||
return oneLine ? value : (0, _foldFlowLines.default)(value, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold); | ||
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'"; | ||
return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold); | ||
} | ||
function blockString(value, indent, literal, forceBlockIndent, comment, onComment) { | ||
// Block can't end in whitespace unless the last line is non-empty | ||
// Strings consisting of only whitespace are best rendered explicitly | ||
function blockString({ | ||
comment, | ||
type, | ||
value | ||
}, ctx, onComment) { | ||
// 1. Block can't end in whitespace unless the last line is non-empty. | ||
// 2. Strings consisting of only whitespace are best rendered explicitly. | ||
if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) { | ||
return doubleQuotedString(value, indent, false); | ||
return doubleQuotedString(value, ctx); | ||
} | ||
if (forceBlockIndent && !indent) indent = ' '; | ||
var indentSize = indent ? '2' : '1'; // root is at -1 | ||
const indent = ctx.indent || (ctx.forceBlockIndent ? ' ' : ''); | ||
const indentSize = indent ? '2' : '1'; // root is at -1 | ||
var header = literal ? '|' : '>'; | ||
const literal = type === _Node.Type.BLOCK_FOLDED ? false : type === _Node.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length); | ||
let header = literal ? '|' : '>'; | ||
if (!value) return header + '\n'; | ||
var wsStart = ''; | ||
var wsEnd = ''; | ||
value = value.replace(/[\n\t ]*$/, function (ws) { | ||
var n = ws.indexOf('\n'); | ||
let wsStart = ''; | ||
let wsEnd = ''; | ||
value = value.replace(/[\n\t ]*$/, ws => { | ||
const n = ws.indexOf('\n'); | ||
@@ -182,5 +207,5 @@ if (n === -1) { | ||
return ''; | ||
}).replace(/^[\n ]*/, function (ws) { | ||
}).replace(/^[\n ]*/, ws => { | ||
if (ws.indexOf(' ') !== -1) header += indentSize; | ||
var m = ws.match(/ +$/); | ||
const m = ws.match(/ +$/); | ||
@@ -195,4 +220,4 @@ if (m) { | ||
}); | ||
if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, "$&".concat(indent)); | ||
if (wsStart) wsStart = wsStart.replace(/\n+/g, "$&".concat(indent)); | ||
if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, `$&${indent}`); | ||
if (wsStart) wsStart = wsStart.replace(/\n+/g, `$&${indent}`); | ||
@@ -204,7 +229,7 @@ if (comment) { | ||
if (!value) return "".concat(header).concat(indentSize, "\n").concat(indent).concat(wsEnd); | ||
if (!value) return `${header}${indentSize}\n${indent}${wsEnd}`; | ||
if (literal) { | ||
value = value.replace(/\n+/g, "$&".concat(indent)); | ||
return "".concat(header, "\n").concat(indent).concat(wsStart).concat(value).concat(wsEnd); | ||
value = value.replace(/\n+/g, `$&${indent}`); | ||
return `${header}\n${indent}${wsStart}${value}${wsEnd}`; | ||
} | ||
@@ -214,10 +239,18 @@ | ||
// ^ ind.line ^ empty ^ capture next empty lines only at end of indent | ||
.replace(/\n+/g, "$&".concat(indent)); | ||
var body = (0, _foldFlowLines.default)("".concat(wsStart).concat(value).concat(wsEnd), indent, _foldFlowLines.FOLD_BLOCK, strOptions.fold); | ||
return "".concat(header, "\n").concat(indent).concat(body); | ||
.replace(/\n+/g, `$&${indent}`); | ||
const body = (0, _foldFlowLines.default)(`${wsStart}${value}${wsEnd}`, indent, _foldFlowLines.FOLD_BLOCK, strOptions.fold); | ||
return `${header}\n${indent}${body}`; | ||
} | ||
function plainString(value, indent, implicitKey, inFlow, forceBlockIndent, tags, comment, onComment) { | ||
function plainString(item, ctx, onComment) { | ||
const comment = item.comment, | ||
type = item.type, | ||
value = item.value; | ||
const implicitKey = ctx.implicitKey, | ||
indent = ctx.indent, | ||
inFlow = ctx.inFlow, | ||
tags = ctx.tags; | ||
if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) { | ||
return doubleQuotedString(value, indent, implicitKey); | ||
return doubleQuotedString(value, ctx); | ||
} | ||
@@ -232,13 +265,18 @@ | ||
// - end with ' ' | ||
return implicitKey || inFlow ? doubleQuotedString(value, indent, implicitKey) : blockString(value, indent, false, forceBlockIndent, comment, onComment); | ||
return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment); | ||
} | ||
if (!implicitKey && !inFlow && type !== _Node.Type.PLAIN && value.indexOf('\n') !== -1) { | ||
// Where allowed & type not set explicitly, prefer block style for multiline strings | ||
return blockString(item, ctx, onComment); | ||
} // Need to verify that output will be parsed as a string | ||
var str = value.replace(/\n+/g, "$&\n".concat(indent)); | ||
const str = value.replace(/\n+/g, `$&\n${indent}`); | ||
if (typeof tags.resolveScalar(str).value !== 'string') { | ||
return doubleQuotedString(value, indent, implicitKey); | ||
return doubleQuotedString(value, ctx); | ||
} | ||
var body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold); | ||
const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, strOptions.fold); | ||
@@ -253,36 +291,31 @@ if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) { | ||
function stringify(_ref) { | ||
var comment = _ref.comment, | ||
type = _ref.type, | ||
value = _ref.value; | ||
function stringify(item, ctx, onComment) { | ||
const defaultType = strOptions.defaultType; | ||
const implicitKey = ctx.implicitKey, | ||
inFlow = ctx.inFlow; | ||
let _item = item, | ||
type = _item.type, | ||
value = _item.value; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
forceBlockIndent = _ref2.forceBlockIndent, | ||
implicitKey = _ref2.implicitKey, | ||
indent = _ref2.indent, | ||
inFlow = _ref2.inFlow, | ||
tags = _ref2.tags; | ||
if (typeof value !== 'string') { | ||
value = String(value); | ||
item = Object.assign({}, item, { | ||
value | ||
}); | ||
} | ||
var onComment = arguments.length > 2 ? arguments[2] : undefined; | ||
var dropCR = strOptions.dropCR, | ||
defaultType = strOptions.defaultType; | ||
if (typeof value !== 'string') value = String(value); | ||
if (dropCR && /\r/.test(value)) value = value.replace(/\r\n?/g, '\n'); | ||
var _stringify = function _stringify(_type) { | ||
const _stringify = _type => { | ||
switch (_type) { | ||
case _Node.Type.BLOCK_FOLDED: | ||
return blockString(value, indent, false, forceBlockIndent, comment, onComment); | ||
case _Node.Type.BLOCK_LITERAL: | ||
return blockString(value, indent, true, forceBlockIndent, comment, onComment); | ||
return blockString(item, ctx, onComment); | ||
case _Node.Type.QUOTE_DOUBLE: | ||
return doubleQuotedString(value, indent, implicitKey, comment); | ||
return doubleQuotedString(value, ctx); | ||
case _Node.Type.QUOTE_SINGLE: | ||
return singleQuotedString(value, indent, implicitKey, comment); | ||
return singleQuotedString(value, ctx); | ||
case _Node.Type.PLAIN: | ||
return plainString(value, indent, implicitKey, inFlow, forceBlockIndent, tags, comment, onComment); | ||
return plainString(item, ctx, onComment); | ||
@@ -302,7 +335,7 @@ default: | ||
var res = _stringify(type); | ||
let res = _stringify(type); | ||
if (res === null) { | ||
res = _stringify(defaultType); | ||
if (res === null) throw new Error("Unsupported default string type ".concat(defaultType)); | ||
if (res === null) throw new Error(`Unsupported default string type ${defaultType}`); | ||
} | ||
@@ -313,10 +346,10 @@ | ||
var str = { | ||
const str = { | ||
class: String, | ||
default: true, | ||
tag: 'tag:yaml.org,2002:str', | ||
resolve: resolve, | ||
stringify: stringify, | ||
resolve, | ||
stringify, | ||
options: strOptions | ||
}; | ||
exports.str = str; |
@@ -11,6 +11,4 @@ "use strict"; | ||
// Published as 'yaml/types/timestamp' | ||
var parseSexagesimal = function parseSexagesimal(sign, parts) { | ||
var n = parts.split(':').reduce(function (n, p) { | ||
return n * 60 + Number(p); | ||
}, 0); | ||
const parseSexagesimal = (sign, parts) => { | ||
const n = parts.split(':').reduce((n, p) => n * 60 + Number(p), 0); | ||
return sign === '-' ? -n : n; | ||
@@ -20,6 +18,7 @@ }; // hhhh:mm:ss.sss | ||
var stringifySexagesimal = function stringifySexagesimal(_ref) { | ||
var value = _ref.value; | ||
const stringifySexagesimal = ({ | ||
value | ||
}) => { | ||
if (isNaN(value) || !isFinite(value)) return (0, _core.stringifyNumber)(value); | ||
var sign = ''; | ||
let sign = ''; | ||
@@ -31,3 +30,3 @@ if (value < 0) { | ||
var parts = [value % 60]; // seconds, including ms | ||
const parts = [value % 60]; // seconds, including ms | ||
@@ -46,9 +45,7 @@ if (value < 60) { | ||
return sign + parts.map(function (n) { | ||
return n < 10 ? '0' + String(n) : String(n); | ||
}).join(':').replace(/000000\d*$/, '') // % 60 may introduce error | ||
return sign + parts.map(n => n < 10 ? '0' + String(n) : String(n)).join(':').replace(/000000\d*$/, '') // % 60 may introduce error | ||
; | ||
}; | ||
var intTime = { | ||
const intTime = { | ||
class: Number, | ||
@@ -59,9 +56,7 @@ default: true, | ||
test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/, | ||
resolve: function resolve(str, sign, parts) { | ||
return parseSexagesimal(sign, parts.replace(/_/g, '')); | ||
}, | ||
resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')), | ||
stringify: stringifySexagesimal | ||
}; | ||
exports.intTime = intTime; | ||
var floatTime = { | ||
const floatTime = { | ||
class: Number, | ||
@@ -72,9 +67,7 @@ default: true, | ||
test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/, | ||
resolve: function resolve(str, sign, parts) { | ||
return parseSexagesimal(sign, parts.replace(/_/g, '')); | ||
}, | ||
resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')), | ||
stringify: stringifySexagesimal | ||
}; | ||
exports.floatTime = floatTime; | ||
var timestamp = { | ||
const timestamp = { | ||
class: Date, | ||
@@ -91,8 +84,8 @@ default: true, | ||
')?' + ')$'), | ||
resolve: function resolve(str, year, month, day, hour, minute, second, millisec, tz) { | ||
resolve: (str, year, month, day, hour, minute, second, millisec, tz) => { | ||
if (millisec) millisec = (millisec + '00').substr(1, 3); | ||
var date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0); | ||
let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0); | ||
if (tz && tz !== 'Z') { | ||
var d = parseSexagesimal(tz[0], tz.slice(1)); | ||
let d = parseSexagesimal(tz[0], tz.slice(1)); | ||
if (Math.abs(d) < 30) d *= 60; | ||
@@ -104,6 +97,5 @@ date -= 60000 * d; | ||
}, | ||
stringify: function stringify(_ref2) { | ||
var value = _ref2.value; | ||
return value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, ''); | ||
} | ||
stringify: ({ | ||
value | ||
}) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '') | ||
}; | ||
@@ -110,0 +102,0 @@ exports.timestamp = timestamp; |
@@ -8,80 +8,45 @@ "use strict"; | ||
var _Node2 = require("../cst/Node"); | ||
var _Node = require("../cst/Node"); | ||
var _toJSON2 = _interopRequireDefault(require("../toJSON")); | ||
var _toJSON = _interopRequireDefault(require("../toJSON")); | ||
var _Node3 = _interopRequireDefault(require("./Node")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
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; } | ||
var Alias = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(Alias, _Node); | ||
class Alias extends _Node2.default { | ||
static stringify({ | ||
range, | ||
source | ||
}, { | ||
anchors, | ||
doc, | ||
implicitKey | ||
}) { | ||
const anchor = Object.keys(anchors).find(a => anchors[a] === source); | ||
if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`; | ||
const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node'; | ||
throw new Error(`${msg} [${range}]`); | ||
} | ||
_createClass(Alias, null, [{ | ||
key: "stringify", | ||
value: function stringify(_ref, _ref2) { | ||
var range = _ref.range, | ||
source = _ref.source; | ||
var anchors = _ref2.anchors, | ||
doc = _ref2.doc, | ||
implicitKey = _ref2.implicitKey; | ||
var anchor = Object.keys(anchors).find(function (a) { | ||
return anchors[a] === source; | ||
}); | ||
if (anchor) return "*".concat(anchor).concat(implicitKey ? ' ' : ''); | ||
var msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node'; | ||
throw new Error("".concat(msg, " [").concat(range, "]")); | ||
} | ||
}]); | ||
constructor(source) { | ||
super(); | ||
this.source = source; | ||
this.type = _Node.Type.ALIAS; | ||
} | ||
function Alias(source) { | ||
var _this; | ||
set tag(t) { | ||
throw new Error('Alias nodes cannot have tags'); | ||
} | ||
_classCallCheck(this, Alias); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Alias).call(this)); | ||
_this.source = source; | ||
_this.type = _Node2.Type.ALIAS; | ||
return _this; | ||
toJSON(arg, keep) { | ||
return (0, _toJSON.default)(this.source, arg, keep); | ||
} | ||
_createClass(Alias, [{ | ||
key: "toJSON", | ||
value: function toJSON(arg, keep) { | ||
return (0, _toJSON2.default)(this.source, arg, keep); | ||
} | ||
}, { | ||
key: "tag", | ||
set: function set(t) { | ||
throw new Error('Alias nodes cannot have tags'); | ||
} | ||
}]); | ||
} | ||
return Alias; | ||
}(_Node3.default); | ||
exports.default = Alias; | ||
_defineProperty(Alias, "default", true); |
@@ -10,139 +10,96 @@ "use strict"; | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Node = _interopRequireDefault(require("./Node")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
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; } | ||
var Collection = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(Collection, _Node); | ||
class Collection extends _Node.default { | ||
constructor(...args) { | ||
super(...args); | ||
function Collection() { | ||
var _getPrototypeOf2; | ||
_defineProperty(this, "items", []); | ||
} | ||
var _this; | ||
_classCallCheck(this, Collection); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Collection)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "items", []); | ||
return _this; | ||
// overridden in implementations | ||
toJSON() { | ||
return null; | ||
} | ||
_createClass(Collection, [{ | ||
key: "toJSON", | ||
// overridden in implementations | ||
value: function toJSON() { | ||
return null; | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString(ctx, _ref, onComment) { | ||
var _this2 = this; | ||
var blockItem = _ref.blockItem, | ||
flowChars = _ref.flowChars, | ||
itemIndent = _ref.itemIndent; | ||
var _ctx = ctx, | ||
toString(ctx, { | ||
blockItem, | ||
flowChars, | ||
itemIndent | ||
}, onComment) { | ||
const _ctx = ctx, | ||
doc = _ctx.doc, | ||
indent = _ctx.indent; | ||
var inFlow = this.type && this.type.substr(0, 4) === 'FLOW' || ctx.inFlow; | ||
if (inFlow) itemIndent += ' '; | ||
ctx = Object.assign({}, ctx, { | ||
indent: itemIndent, | ||
inFlow: inFlow, | ||
type: null | ||
}); | ||
var hasItemWithComment = false; | ||
var hasItemWithNewLine = false; | ||
var nodes = this.items.reduce(function (nodes, item, i) { | ||
var commentBefore = item && item.commentBefore; | ||
const inFlow = this.type && this.type.substr(0, 4) === 'FLOW' || ctx.inFlow; | ||
if (inFlow) itemIndent += ' '; | ||
ctx = Object.assign({}, ctx, { | ||
indent: itemIndent, | ||
inFlow, | ||
type: null | ||
}); | ||
let hasItemWithComment = false; | ||
let hasItemWithNewLine = false; | ||
const nodes = this.items.reduce((nodes, item, i) => { | ||
const commentBefore = item && item.commentBefore; | ||
if (commentBefore) { | ||
hasItemWithComment = true; | ||
commentBefore.match(/^.*$/gm).forEach(function (line) { | ||
nodes.push({ | ||
type: 'comment', | ||
str: "#".concat(line) | ||
}); | ||
if (commentBefore) { | ||
hasItemWithComment = true; | ||
commentBefore.match(/^.*$/gm).forEach(line => { | ||
nodes.push({ | ||
type: 'comment', | ||
str: `#${line}` | ||
}); | ||
} | ||
var comment = item && item.comment; | ||
if (comment) hasItemWithComment = true; | ||
var str = doc.schema.stringify(item, ctx, function () { | ||
comment = null; | ||
}); | ||
if (!hasItemWithNewLine && str.indexOf('\n') !== -1) hasItemWithNewLine = true; | ||
if (inFlow && i < _this2.items.length - 1) str += ','; | ||
str = (0, _addComment.default)(str, itemIndent, comment); | ||
nodes.push({ | ||
type: 'item', | ||
str: str | ||
}); | ||
return nodes; | ||
}, []); | ||
var str; | ||
} | ||
if (nodes.length === 0) { | ||
str = flowChars.start + flowChars.end; | ||
} else if (inFlow) { | ||
var start = flowChars.start, | ||
let comment = item && item.comment; | ||
if (comment) hasItemWithComment = true; | ||
let str = doc.schema.stringify(item, ctx, () => { | ||
comment = null; | ||
}); | ||
if (!hasItemWithNewLine && str.indexOf('\n') !== -1) hasItemWithNewLine = true; | ||
if (inFlow && i < this.items.length - 1) str += ','; | ||
str = (0, _addComment.default)(str, itemIndent, comment); | ||
nodes.push({ | ||
type: 'item', | ||
str | ||
}); | ||
return nodes; | ||
}, []); | ||
let str; | ||
if (nodes.length === 0) { | ||
str = flowChars.start + flowChars.end; | ||
} else if (inFlow) { | ||
const start = flowChars.start, | ||
end = flowChars.end; | ||
var strings = nodes.map(function (_ref2) { | ||
var str = _ref2.str; | ||
return str; | ||
}); | ||
const strings = nodes.map(({ | ||
str | ||
}) => str); | ||
if (hasItemWithComment || hasItemWithNewLine || strings.reduce(function (sum, str) { | ||
return sum + str.length + 2; | ||
}, 2) > Collection.maxFlowStringSingleLineLength) { | ||
str = "".concat(start, "\n ").concat(indent).concat(strings.join("\n ".concat(indent)), "\n").concat(indent).concat(end); | ||
} else { | ||
str = "".concat(start, " ").concat(strings.join(' '), " ").concat(end); | ||
} | ||
if (hasItemWithComment || hasItemWithNewLine || strings.reduce((sum, str) => sum + str.length + 2, 2) > Collection.maxFlowStringSingleLineLength) { | ||
str = `${start}\n ${indent}${strings.join(`\n ${indent}`)}\n${indent}${end}`; | ||
} else { | ||
str = nodes.map(blockItem).join("\n".concat(indent)); | ||
str = `${start} ${strings.join(' ')} ${end}`; | ||
} | ||
} else { | ||
str = nodes.map(blockItem).join(`\n${indent}`); | ||
} | ||
if (this.comment) { | ||
if (!hasItemWithNewLine && str.indexOf('\n') === -1) str = (0, _addComment.default)(str, indent, this.comment);else str += '\n' + this.comment.replace(/^/gm, "".concat(indent, "#")); | ||
if (onComment) onComment(); | ||
} | ||
return str; | ||
if (this.comment) { | ||
if (!hasItemWithNewLine && str.indexOf('\n') === -1) str = (0, _addComment.default)(str, indent, this.comment);else str += '\n' + this.comment.replace(/^/gm, `${indent}#`); | ||
if (onComment) onComment(); | ||
} | ||
}]); | ||
return Collection; | ||
}(_Node2.default); | ||
return str; | ||
} | ||
} | ||
exports.default = Collection; | ||
_defineProperty(Collection, "maxFlowStringSingleLineLength", 60); |
@@ -12,9 +12,8 @@ "use strict"; | ||
var stringifyNumber = function stringifyNumber(_ref) { | ||
var value = _ref.value; | ||
return isFinite(value) ? JSON.stringify(value) : isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf'; | ||
}; | ||
const stringifyNumber = ({ | ||
value | ||
}) => isFinite(value) ? JSON.stringify(value) : isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf'; | ||
exports.stringifyNumber = stringifyNumber; | ||
var nullOptions = { | ||
const nullOptions = { | ||
nullStr: 'null' | ||
@@ -29,9 +28,5 @@ }; | ||
test: /^(?:~|[Nn]ull|NULL)?$/, | ||
resolve: function resolve() { | ||
return null; | ||
}, | ||
resolve: () => null, | ||
options: nullOptions, | ||
stringify: function stringify() { | ||
return nullOptions.nullStr; | ||
} | ||
stringify: () => nullOptions.nullStr | ||
}, { | ||
@@ -42,5 +37,3 @@ class: Boolean, | ||
test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/, | ||
resolve: function resolve(str) { | ||
return str[0] === 't' || str[0] === 'T'; | ||
} | ||
resolve: str => str[0] === 't' || str[0] === 'T' | ||
}, { | ||
@@ -52,9 +45,6 @@ class: Number, | ||
test: /^0o([0-7]+)$/, | ||
resolve: function resolve(str, oct) { | ||
return parseInt(oct, 8); | ||
}, | ||
stringify: function stringify(_ref2) { | ||
var value = _ref2.value; | ||
return '0o' + value.toString(8); | ||
} | ||
resolve: (str, oct) => parseInt(oct, 8), | ||
stringify: ({ | ||
value | ||
}) => '0o' + value.toString(8) | ||
}, { | ||
@@ -65,5 +55,3 @@ class: Number, | ||
test: /^[-+]?[0-9]+$/, | ||
resolve: function resolve(str) { | ||
return parseInt(str, 10); | ||
}, | ||
resolve: str => parseInt(str, 10), | ||
stringify: stringifyNumber | ||
@@ -76,9 +64,6 @@ }, { | ||
test: /^0x([0-9a-fA-F]+)$/, | ||
resolve: function resolve(str, hex) { | ||
return parseInt(hex, 16); | ||
}, | ||
stringify: function stringify(_ref3) { | ||
var value = _ref3.value; | ||
return '0x' + value.toString(16); | ||
} | ||
resolve: (str, hex) => parseInt(hex, 16), | ||
stringify: ({ | ||
value | ||
}) => '0x' + value.toString(16) | ||
}, { | ||
@@ -89,5 +74,3 @@ class: Number, | ||
test: /^(?:[-+]?\.inf|(\.nan))$/i, | ||
resolve: function resolve(str, nan) { | ||
return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY; | ||
}, | ||
resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, | ||
stringify: stringifyNumber | ||
@@ -99,5 +82,3 @@ }, { | ||
test: /^[-+]?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][-+]?[0-9]+)?$/, | ||
resolve: function resolve(str) { | ||
return parseFloat(str); | ||
}, | ||
resolve: str => parseFloat(str), | ||
stringify: stringifyNumber | ||
@@ -104,0 +85,0 @@ }]); |
@@ -20,3 +20,3 @@ "use strict"; | ||
var map = { | ||
const map = { | ||
class: _Map.default, | ||
@@ -26,8 +26,6 @@ default: true, | ||
resolve: _parseMap.default, | ||
stringify: function stringify(value, ctx, onComment) { | ||
return value.toString(ctx, onComment); | ||
} | ||
stringify: (value, ctx, onComment) => value.toString(ctx, onComment) | ||
}; | ||
exports.map = map; | ||
var seq = { | ||
const seq = { | ||
class: _Seq.default, | ||
@@ -37,5 +35,3 @@ default: true, | ||
resolve: _parseSeq.default, | ||
stringify: function stringify(value, ctx, onComment) { | ||
return value.toString(ctx, onComment); | ||
} | ||
stringify: (value, ctx, onComment) => value.toString(ctx, onComment) | ||
}; | ||
@@ -42,0 +38,0 @@ exports.seq = seq; |
@@ -36,11 +36,3 @@ "use strict"; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var availableSchema = { | ||
const availableSchema = { | ||
core: _core.default, | ||
@@ -52,5 +44,5 @@ failsafe: _failsafe.default, | ||
exports.availableSchema = availableSchema; | ||
var defaultPrefix = 'tag:yaml.org,2002:'; | ||
const defaultPrefix = 'tag:yaml.org,2002:'; | ||
exports.defaultPrefix = defaultPrefix; | ||
var DefaultTags = { | ||
const DefaultTags = { | ||
MAP: 'tag:yaml.org,2002:map', | ||
@@ -62,29 +54,20 @@ SEQ: 'tag:yaml.org,2002:seq', | ||
var isMap = function isMap(_ref) { | ||
var type = _ref.type; | ||
return type === _Node.Type.FLOW_MAP || type === _Node.Type.MAP; | ||
}; | ||
const isMap = ({ | ||
type | ||
}) => type === _Node.Type.FLOW_MAP || type === _Node.Type.MAP; | ||
var isSeq = function isSeq(_ref2) { | ||
var type = _ref2.type; | ||
return type === _Node.Type.FLOW_SEQ || type === _Node.Type.SEQ; | ||
}; | ||
const isSeq = ({ | ||
type | ||
}) => type === _Node.Type.FLOW_SEQ || type === _Node.Type.SEQ; | ||
var Schema = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(Schema, null, [{ | ||
key: "defaultStringifier", | ||
value: function defaultStringifier(value) { | ||
return JSON.stringify(value); | ||
} | ||
}]); | ||
class Schema { | ||
static defaultStringifier(value) { | ||
return JSON.stringify(value); | ||
} | ||
function Schema(_ref3) { | ||
var merge = _ref3.merge, | ||
schema = _ref3.schema, | ||
tags = _ref3.tags; | ||
_classCallCheck(this, Schema); | ||
constructor({ | ||
merge, | ||
schema, | ||
tags | ||
}) { | ||
this.merge = !!merge; | ||
@@ -95,6 +78,4 @@ this.name = schema; | ||
if (!this.schema) { | ||
var keys = Object.keys(availableSchema).map(function (key) { | ||
return JSON.stringify(key); | ||
}).join(', '); | ||
throw new Error("Unknown schema; use ".concat(keys, ", or { tag, test, resolve }[]")); | ||
const keys = Object.keys(availableSchema).map(key => JSON.stringify(key)).join(', '); | ||
throw new Error(`Unknown schema; use ${keys}, or { tag, test, resolve }[]`); | ||
} | ||
@@ -110,9 +91,7 @@ | ||
_createClass(Schema, [{ | ||
key: "resolveScalar", | ||
value: function resolveScalar(str, tags) { | ||
if (!tags) tags = this.schema; | ||
resolveScalar(str, tags) { | ||
if (!tags) tags = this.schema; | ||
for (var i = 0; i < tags.length; ++i) { | ||
var _tags$i = tags[i], | ||
for (let i = 0; i < tags.length; ++i) { | ||
const _tags$i = tags[i], | ||
format = _tags$i.format, | ||
@@ -122,176 +101,157 @@ test = _tags$i.test, | ||
if (test) { | ||
var match = str.match(test); | ||
if (test) { | ||
const match = str.match(test); | ||
if (match) { | ||
var res = new _Scalar.default(resolve.apply(null, match)); | ||
if (format) res.format = format; | ||
return res; | ||
} | ||
if (match) { | ||
const res = new _Scalar.default(resolve.apply(null, match)); | ||
if (format) res.format = format; | ||
return res; | ||
} | ||
} | ||
} | ||
if (this.schema.scalarFallback) str = this.schema.scalarFallback(str); | ||
return new _Scalar.default(str); | ||
} // sets node.resolved on success | ||
if (this.schema.scalarFallback) str = this.schema.scalarFallback(str); | ||
return new _Scalar.default(str); | ||
} // sets node.resolved on success | ||
}, { | ||
key: "resolveNode", | ||
value: function resolveNode(doc, node, tagName) { | ||
var tags = this.schema.filter(function (_ref4) { | ||
var tag = _ref4.tag; | ||
return tag === tagName; | ||
}); | ||
var generic = tags.find(function (_ref5) { | ||
var test = _ref5.test; | ||
return !test; | ||
}); | ||
if (node.error) doc.errors.push(node.error); | ||
try { | ||
if (generic) { | ||
var res = generic.resolve(doc, node); | ||
if (!(res instanceof _Collection.default)) res = new _Scalar.default(res); | ||
node.resolved = res; | ||
} else { | ||
var str = (0, _string.resolve)(doc, node); | ||
resolveNode(doc, node, tagName) { | ||
const tags = this.schema.filter(({ | ||
tag | ||
}) => tag === tagName); | ||
const generic = tags.find(({ | ||
test | ||
}) => !test); | ||
if (node.error) doc.errors.push(node.error); | ||
if (typeof str === 'string' && tags.length > 0) { | ||
node.resolved = this.resolveScalar(str, tags); | ||
} | ||
try { | ||
if (generic) { | ||
let res = generic.resolve(doc, node); | ||
if (!(res instanceof _Collection.default)) res = new _Scalar.default(res); | ||
node.resolved = res; | ||
} else { | ||
const str = (0, _string.resolve)(doc, node); | ||
if (typeof str === 'string' && tags.length > 0) { | ||
node.resolved = this.resolveScalar(str, tags); | ||
} | ||
} catch (error) { | ||
if (!error.source) error.source = node; | ||
doc.errors.push(error); | ||
node.resolved = null; | ||
} | ||
if (!node.resolved) return null; | ||
if (tagName) node.resolved.tag = tagName; | ||
return node.resolved; | ||
} catch (error) { | ||
if (!error.source) error.source = node; | ||
doc.errors.push(error); | ||
node.resolved = null; | ||
} | ||
}, { | ||
key: "resolveNodeWithFallback", | ||
value: function resolveNodeWithFallback(doc, node, tagName) { | ||
var res = this.resolveNode(doc, node, tagName); | ||
if (node.hasOwnProperty('resolved')) return res; | ||
var fallback = isMap(node) ? DefaultTags.MAP : isSeq(node) ? DefaultTags.SEQ : DefaultTags.STR; | ||
if (fallback) { | ||
doc.warnings.push(new _errors.YAMLWarning(node, "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback))); | ||
if (!node.resolved) return null; | ||
if (tagName) node.resolved.tag = tagName; | ||
return node.resolved; | ||
} | ||
var _res = this.resolveNode(doc, node, fallback); | ||
resolveNodeWithFallback(doc, node, tagName) { | ||
const res = this.resolveNode(doc, node, tagName); | ||
if (node.hasOwnProperty('resolved')) return res; | ||
const fallback = isMap(node) ? DefaultTags.MAP : isSeq(node) ? DefaultTags.SEQ : DefaultTags.STR; | ||
_res.tag = tagName; | ||
return _res; | ||
} else { | ||
doc.errors.push(new _errors.YAMLReferenceError(node, "The tag ".concat(tagName, " is unavailable"))); | ||
} | ||
return null; | ||
if (fallback) { | ||
doc.warnings.push(new _errors.YAMLWarning(node, `The tag ${tagName} is unavailable, falling back to ${fallback}`)); | ||
const res = this.resolveNode(doc, node, fallback); | ||
res.tag = tagName; | ||
return res; | ||
} else { | ||
doc.errors.push(new _errors.YAMLReferenceError(node, `The tag ${tagName} is unavailable`)); | ||
} | ||
}, { | ||
key: "getTagObject", | ||
value: function getTagObject(item) { | ||
if (item instanceof _Alias.default) return _Alias.default; | ||
if (item.tag) { | ||
var match = this.schema.find(function (_ref6) { | ||
var format = _ref6.format, | ||
tag = _ref6.tag; | ||
return tag === item.tag && format === item.format; | ||
}); | ||
if (!match) match = this.schema.find(function (_ref7) { | ||
var tag = _ref7.tag; | ||
return tag === item.tag; | ||
}); | ||
if (match) return match; | ||
} | ||
return null; | ||
} | ||
if (item.value === null) { | ||
var _match = this.schema.find(function (t) { | ||
return t.class === null && !t.format; | ||
}); | ||
getTagObject(item) { | ||
if (item instanceof _Alias.default) return _Alias.default; | ||
if (!_match) throw new Error('Tag not resolved for null value'); | ||
return _match; | ||
} else { | ||
var obj = item; | ||
if (item.tag) { | ||
let match = this.schema.find(({ | ||
format, | ||
tag | ||
}) => tag === item.tag && format === item.format); | ||
if (!match) match = this.schema.find(({ | ||
tag | ||
}) => tag === item.tag); | ||
if (match) return match; | ||
} | ||
if (item.hasOwnProperty('value')) { | ||
switch (_typeof(item.value)) { | ||
case 'boolean': | ||
obj = new Boolean(); | ||
break; | ||
if (item.value === null) { | ||
const match = this.schema.find(t => t.class === null && !t.format); | ||
if (!match) throw new Error('Tag not resolved for null value'); | ||
return match; | ||
} else { | ||
let obj = item; | ||
case 'number': | ||
obj = new Number(); | ||
break; | ||
if (item.hasOwnProperty('value')) { | ||
switch (typeof item.value) { | ||
case 'boolean': | ||
obj = new Boolean(); | ||
break; | ||
case 'string': | ||
obj = new String(); | ||
break; | ||
case 'number': | ||
obj = new Number(); | ||
break; | ||
default: | ||
obj = item.value; | ||
} | ||
} | ||
case 'string': | ||
obj = new String(); | ||
break; | ||
var _match2 = this.schema.find(function (t) { | ||
return t.class && obj instanceof t.class && t.format === item.format; | ||
}); | ||
if (!_match2) { | ||
_match2 = this.schema.find(function (t) { | ||
return t.class && obj instanceof t.class && !t.format; | ||
}); | ||
default: | ||
obj = item.value; | ||
} | ||
if (!_match2) { | ||
var name = obj && obj.constructor ? obj.constructor.name : _typeof(obj); | ||
throw new Error("Tag not resolved for ".concat(name, " value")); | ||
} | ||
return _match2; | ||
} | ||
} // needs to be called before stringifier to allow for circular anchor refs | ||
}, { | ||
key: "stringifyProps", | ||
value: function stringifyProps(node, tagObj, _ref8) { | ||
var anchors = _ref8.anchors, | ||
doc = _ref8.doc; | ||
var props = []; | ||
var anchor = doc.anchors.getName(node); | ||
let match = this.schema.find(t => t.class && obj instanceof t.class && t.format === item.format); | ||
if (anchor) { | ||
anchors[anchor] = node; | ||
props.push("&".concat(anchor)); | ||
if (!match) { | ||
match = this.schema.find(t => t.class && obj instanceof t.class && !t.format); | ||
} | ||
if (node.tag && node.tag !== tagObj.tag) { | ||
props.push(doc.stringifyTag(node.tag)); | ||
} else if (!tagObj.default) { | ||
props.push(doc.stringifyTag(tagObj.tag)); | ||
if (!match) { | ||
const name = obj && obj.constructor ? obj.constructor.name : typeof obj; | ||
throw new Error(`Tag not resolved for ${name} value`); | ||
} | ||
return props.join(' '); | ||
return match; | ||
} | ||
}, { | ||
key: "stringify", | ||
value: function stringify(item, ctx, onComment) { | ||
if (!(item instanceof _Node2.default)) item = (0, _createNode.default)(item, true); | ||
ctx.tags = this; | ||
if (item instanceof _Pair.default) return item.toString(ctx, onComment); | ||
var tagObj = this.getTagObject(item); | ||
var props = this.stringifyProps(item, tagObj, ctx); | ||
var stringify = tagObj.stringify || Schema.defaultStringifier; | ||
var str = stringify(item, ctx, onComment); | ||
return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? "".concat(props, "\n").concat(ctx.indent).concat(str) : "".concat(props, " ").concat(str) : str; | ||
} // needs to be called before stringifier to allow for circular anchor refs | ||
stringifyProps(node, tagObj, { | ||
anchors, | ||
doc | ||
}) { | ||
const props = []; | ||
const anchor = doc.anchors.getName(node); | ||
if (anchor) { | ||
anchors[anchor] = node; | ||
props.push(`&${anchor}`); | ||
} | ||
}]); | ||
return Schema; | ||
}(); | ||
if (node.tag && node.tag !== tagObj.tag) { | ||
props.push(doc.stringifyTag(node.tag)); | ||
} else if (!tagObj.default) { | ||
props.push(doc.stringifyTag(tagObj.tag)); | ||
} | ||
return props.join(' '); | ||
} | ||
stringify(item, ctx, onComment) { | ||
if (!(item instanceof _Node2.default)) item = (0, _createNode.default)(item, true); | ||
ctx.tags = this; | ||
if (item instanceof _Pair.default) return item.toString(ctx, onComment); | ||
const tagObj = this.getTagObject(item); | ||
const props = this.stringifyProps(item, tagObj, ctx); | ||
const stringify = tagObj.stringify || Schema.defaultStringifier; | ||
const str = stringify(item, ctx, onComment); | ||
return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? `${props}\n${ctx.indent}${str}` : `${props} ${str}` : str; | ||
} | ||
} | ||
exports.default = Schema; |
@@ -12,3 +12,3 @@ "use strict"; | ||
var schema = [_failsafe.map, _failsafe.seq, { | ||
const schema = [_failsafe.map, _failsafe.seq, { | ||
class: String, | ||
@@ -23,5 +23,3 @@ default: true, | ||
test: /^null$/, | ||
resolve: function resolve() { | ||
return null; | ||
} | ||
resolve: () => null | ||
}, { | ||
@@ -32,5 +30,3 @@ class: Boolean, | ||
test: /^true$/, | ||
resolve: function resolve() { | ||
return true; | ||
} | ||
resolve: () => true | ||
}, { | ||
@@ -41,5 +37,3 @@ class: Boolean, | ||
test: /^false$/, | ||
resolve: function resolve() { | ||
return false; | ||
} | ||
resolve: () => false | ||
}, { | ||
@@ -50,5 +44,3 @@ class: Number, | ||
test: /^-?(?:0|[1-9][0-9]*)$/, | ||
resolve: function resolve(str) { | ||
return parseInt(str, 10); | ||
} | ||
resolve: str => parseInt(str, 10) | ||
}, { | ||
@@ -59,9 +51,7 @@ class: Number, | ||
test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/, | ||
resolve: function resolve(str) { | ||
return parseFloat(str); | ||
} | ||
resolve: str => parseFloat(str) | ||
}]; | ||
schema.scalarFallback = function (str) { | ||
throw new SyntaxError("Unresolved plain scalar ".concat(JSON.stringify(str))); | ||
schema.scalarFallback = str => { | ||
throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(str)}`); | ||
}; | ||
@@ -68,0 +58,0 @@ |
@@ -8,5 +8,5 @@ "use strict"; | ||
var _toJSON2 = _interopRequireDefault(require("../toJSON")); | ||
var _toJSON = _interopRequireDefault(require("../toJSON")); | ||
var _Collection2 = _interopRequireDefault(require("./Collection")); | ||
var _Collection = _interopRequireDefault(require("./Collection")); | ||
@@ -19,100 +19,59 @@ var _Merge = _interopRequireDefault(require("./Merge")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
// Published as 'yaml/map' | ||
class YAMLMap extends _Collection.default { | ||
toJSON(_, keep) { | ||
return this.items.reduce((map, item) => { | ||
if (item instanceof _Merge.default) { | ||
// If the value associated with a merge key is a single mapping node, | ||
// each of its key/value pairs is inserted into the current mapping, | ||
// unless the key already exists in it. If the value associated with the | ||
// merge key is a sequence, then this sequence is expected to contain | ||
// mapping nodes and each of these nodes is merged in turn according to | ||
// its order in the sequence. Keys in mapping nodes earlier in the | ||
// sequence override keys specified in later mapping nodes. | ||
// -- http://yaml.org/type/merge.html | ||
const keys = Object.keys(map); | ||
const items = item.value.items; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
for (let i = items.length - 1; i >= 0; --i) { | ||
const source = items[i].source; | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
if (source instanceof YAMLMap) { | ||
const obj = source.toJSON('', keep); | ||
Object.keys(obj).forEach(key => { | ||
if (!keys.includes(key)) map[key] = obj[key]; | ||
}); | ||
} else { | ||
throw new Error('Merge sources must be maps'); | ||
} | ||
} | ||
} else { | ||
const stringKey = item.stringKey, | ||
value = item.value; | ||
map[stringKey] = (0, _toJSON.default)(value, stringKey, keep); | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
return map; | ||
}, {}); | ||
} | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } | ||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var YAMLMap = | ||
/*#__PURE__*/ | ||
function (_Collection) { | ||
_inherits(YAMLMap, _Collection); | ||
function YAMLMap() { | ||
_classCallCheck(this, YAMLMap); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(YAMLMap).apply(this, arguments)); | ||
toString(ctx, onComment) { | ||
if (!ctx) return JSON.stringify(this); | ||
this.items.forEach(item => { | ||
if (!(item instanceof _Pair.default)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`); | ||
}); | ||
return super.toString(ctx, { | ||
blockItem: ({ | ||
str | ||
}) => str, | ||
flowChars: { | ||
start: '{', | ||
end: '}' | ||
}, | ||
itemIndent: ctx.indent || '' | ||
}, onComment); | ||
} | ||
_createClass(YAMLMap, [{ | ||
key: "toJSON", | ||
value: function toJSON(_, keep) { | ||
return this.items.reduce(function (map, item) { | ||
if (item instanceof _Merge.default) { | ||
(function () { | ||
// If the value associated with a merge key is a single mapping node, | ||
// each of its key/value pairs is inserted into the current mapping, | ||
// unless the key already exists in it. If the value associated with the | ||
// merge key is a sequence, then this sequence is expected to contain | ||
// mapping nodes and each of these nodes is merged in turn according to | ||
// its order in the sequence. Keys in mapping nodes earlier in the | ||
// sequence override keys specified in later mapping nodes. | ||
// -- http://yaml.org/type/merge.html | ||
var keys = Object.keys(map); | ||
var items = item.value.items; | ||
} | ||
for (var i = items.length - 1; i >= 0; --i) { | ||
var source = items[i].source; | ||
if (source instanceof YAMLMap) { | ||
(function () { | ||
var obj = source.toJSON('', keep); | ||
Object.keys(obj).forEach(function (key) { | ||
if (!keys.includes(key)) map[key] = obj[key]; | ||
}); | ||
})(); | ||
} else { | ||
throw new Error('Merge sources must be maps'); | ||
} | ||
} | ||
})(); | ||
} else { | ||
var stringKey = item.stringKey, | ||
value = item.value; | ||
map[stringKey] = (0, _toJSON2.default)(value, stringKey, keep); | ||
} | ||
return map; | ||
}, {}); | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString(ctx, onComment) { | ||
if (!ctx) return JSON.stringify(this); | ||
this.items.forEach(function (item) { | ||
if (!(item instanceof _Pair.default)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead")); | ||
}); | ||
return _get(_getPrototypeOf(YAMLMap.prototype), "toString", this).call(this, ctx, { | ||
blockItem: function blockItem(_ref) { | ||
var str = _ref.str; | ||
return str; | ||
}, | ||
flowChars: { | ||
start: '{', | ||
end: '}' | ||
}, | ||
itemIndent: ctx.indent || '' | ||
}, onComment); | ||
} | ||
}]); | ||
return YAMLMap; | ||
}(_Collection2.default); | ||
exports.default = YAMLMap; |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _Pair2 = _interopRequireDefault(require("./Pair")); | ||
var _Pair = _interopRequireDefault(require("./Pair")); | ||
@@ -17,40 +17,10 @@ var _Scalar = _interopRequireDefault(require("./Scalar")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } | ||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var MERGE_KEY = '<<'; | ||
const MERGE_KEY = '<<'; | ||
exports.MERGE_KEY = MERGE_KEY; | ||
var Merge = | ||
/*#__PURE__*/ | ||
function (_Pair) { | ||
_inherits(Merge, _Pair); | ||
class Merge extends _Pair.default { | ||
constructor(pair) { | ||
if (pair instanceof _Pair.default) { | ||
let seq = pair.value; | ||
function Merge(pair) { | ||
var _this; | ||
_classCallCheck(this, Merge); | ||
if (pair instanceof _Pair2.default) { | ||
var seq = pair.value; | ||
if (!(seq instanceof _Seq.default)) { | ||
@@ -62,29 +32,22 @@ seq = new _Seq.default(); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Merge).call(this, pair.key, seq)); | ||
_this.range = pair.range; | ||
super(pair.key, seq); | ||
this.range = pair.range; | ||
} else { | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Merge).call(this, new _Scalar.default(MERGE_KEY), new _Seq.default())); | ||
super(new _Scalar.default(MERGE_KEY), new _Seq.default()); | ||
} | ||
_this.type = 'MERGE_PAIR'; | ||
return _possibleConstructorReturn(_this); | ||
this.type = 'MERGE_PAIR'; | ||
} | ||
_createClass(Merge, [{ | ||
key: "toString", | ||
value: function toString(ctx, onComment) { | ||
var seq = this.value; | ||
if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment); | ||
this.value = seq.items[0]; | ||
toString(ctx, onComment) { | ||
const seq = this.value; | ||
if (seq.items.length > 1) return super.toString(ctx, onComment); | ||
this.value = seq.items[0]; | ||
const str = super.toString(ctx, onComment); | ||
this.value = seq; | ||
return str; | ||
} | ||
var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment); | ||
} | ||
this.value = seq; | ||
return str; | ||
} | ||
}]); | ||
return Merge; | ||
}(_Pair2.default); | ||
exports.default = Merge; |
@@ -8,8 +8,4 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class Node {} | ||
var Node = function Node() { | ||
_classCallCheck(this, Node); | ||
}; | ||
exports.default = Node; |
@@ -10,7 +10,7 @@ "use strict"; | ||
var _toJSON2 = _interopRequireDefault(require("../toJSON")); | ||
var _toJSON = _interopRequireDefault(require("../toJSON")); | ||
var _Collection = _interopRequireDefault(require("./Collection")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Node = _interopRequireDefault(require("./Node")); | ||
@@ -21,113 +21,79 @@ var _Scalar = _interopRequireDefault(require("./Scalar")); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
// Published as 'yaml/pair' | ||
class Pair extends _Node.default { | ||
constructor(key, value = null) { | ||
super(); | ||
this.key = key; | ||
this.value = value; | ||
this.type = 'PAIR'; | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
get commentBefore() { | ||
return this.key && this.key.commentBefore; | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
set commentBefore(cb) { | ||
if (this.key == null) this.key = new _Scalar.default(null); | ||
this.key.commentBefore = cb; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
get comment() { | ||
return this.value && this.value.comment; | ||
} | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
set comment(comment) { | ||
if (this.value == null) this.value = new _Scalar.default(null); | ||
this.value.comment = comment; | ||
} | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
get stringKey() { | ||
const key = (0, _toJSON.default)(this.key); | ||
if (key === null) return ''; | ||
if (typeof key === 'object') try { | ||
return JSON.stringify(key); | ||
} catch (e) { | ||
/* should not happen, but let's ignore in any case */ | ||
} | ||
return String(key); | ||
} | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var Pair = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(Pair, _Node); | ||
function Pair(key) { | ||
var _this; | ||
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
_classCallCheck(this, Pair); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Pair).call(this)); | ||
_this.key = key; | ||
_this.value = value; | ||
_this.type = 'PAIR'; | ||
return _this; | ||
toJSON(_, keep) { | ||
const pair = {}; | ||
const sk = this.stringKey; | ||
pair[sk] = (0, _toJSON.default)(this.value, sk, keep); | ||
return pair; | ||
} | ||
_createClass(Pair, [{ | ||
key: "toJSON", | ||
value: function toJSON(_, keep) { | ||
var pair = {}; | ||
var sk = this.stringKey; | ||
pair[sk] = (0, _toJSON2.default)(this.value, sk, keep); | ||
return pair; | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString(ctx, onComment) { | ||
if (!ctx || !ctx.doc) return JSON.stringify(this); | ||
var key = this.key, | ||
toString(ctx, onComment) { | ||
if (!ctx || !ctx.doc) return JSON.stringify(this); | ||
const key = this.key, | ||
value = this.value; | ||
var keyComment = key instanceof _Node2.default && key.comment; | ||
var explicitKey = !key || keyComment || key instanceof _Collection.default; | ||
var _ctx = ctx, | ||
let keyComment = key instanceof _Node.default && key.comment; | ||
const explicitKey = !key || keyComment || key instanceof _Collection.default; | ||
const _ctx = ctx, | ||
doc = _ctx.doc, | ||
indent = _ctx.indent; | ||
ctx = Object.assign({}, ctx, { | ||
implicitKey: !explicitKey, | ||
indent: indent + ' ' | ||
}); | ||
var keyStr = doc.schema.stringify(key, ctx, function () { | ||
keyComment = null; | ||
}); | ||
if (keyComment) keyStr = (0, _addComment.default)(keyStr, ctx.indent, keyComment); | ||
ctx.implicitKey = false; | ||
var valueStr = doc.schema.stringify(value, ctx, onComment); | ||
var vcb = value && value.commentBefore ? " #".concat(value.commentBefore.replace(/\n+(?!\n|$)/g, "$&".concat(ctx.indent, "#"))) : ''; | ||
ctx = Object.assign({}, ctx, { | ||
implicitKey: !explicitKey, | ||
indent: indent + ' ' | ||
}); | ||
let keyStr = doc.schema.stringify(key, ctx, () => { | ||
keyComment = null; | ||
}); | ||
if (keyComment) keyStr = (0, _addComment.default)(keyStr, ctx.indent, keyComment); | ||
ctx.implicitKey = false; | ||
const valueStr = doc.schema.stringify(value, ctx, onComment); | ||
const vcb = value && value.commentBefore ? ` #${value.commentBefore.replace(/\n+(?!\n|$)/g, `$&${ctx.indent}#`)}` : ''; | ||
if (explicitKey) { | ||
return "? ".concat(keyStr, "\n").concat(indent, ":").concat(vcb ? "".concat(vcb, "\n").concat(ctx.indent) : ' ').concat(valueStr); | ||
} else if (value instanceof _Collection.default) { | ||
return "".concat(keyStr, ":").concat(vcb, "\n").concat(ctx.indent).concat(valueStr); | ||
} else { | ||
return "".concat(keyStr, ":").concat(vcb ? "".concat(vcb, "\n").concat(ctx.indent) : ' ').concat(valueStr); | ||
} | ||
if (explicitKey) { | ||
return `? ${keyStr}\n${indent}:${vcb ? `${vcb}\n${ctx.indent}` : ' '}${valueStr}`; | ||
} else if (value instanceof _Collection.default) { | ||
return `${keyStr}:${vcb}\n${ctx.indent}${valueStr}`; | ||
} else { | ||
return `${keyStr}:${vcb ? `${vcb}\n${ctx.indent}` : ' '}${valueStr}`; | ||
} | ||
}, { | ||
key: "commentBefore", | ||
get: function get() { | ||
return this.key && this.key.commentBefore; | ||
}, | ||
set: function set(cb) { | ||
if (this.key == null) this.key = new _Scalar.default(null); | ||
this.key.commentBefore = cb; | ||
} | ||
}, { | ||
key: "comment", | ||
get: function get() { | ||
return this.value && this.value.comment; | ||
}, | ||
set: function set(comment) { | ||
if (this.value == null) this.value = new _Scalar.default(null); | ||
this.value.comment = comment; | ||
} | ||
}, { | ||
key: "stringKey", | ||
get: function get() { | ||
var key = (0, _toJSON2.default)(this.key); | ||
if (key === null) return ''; | ||
if (_typeof(key) === 'object') try { | ||
return JSON.stringify(key); | ||
} catch (e) { | ||
/* should not happen, but let's ignore in any case */ | ||
} | ||
return String(key); | ||
} | ||
}]); | ||
} | ||
return Pair; | ||
}(_Node2.default); | ||
} | ||
exports.default = Pair; |
@@ -10,2 +10,4 @@ "use strict"; | ||
var _PlainValue = _interopRequireDefault(require("../cst/PlainValue")); | ||
var _errors = require("../errors"); | ||
@@ -29,3 +31,3 @@ | ||
if (cst.type !== _Node.Type.MAP && cst.type !== _Node.Type.FLOW_MAP) { | ||
var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping"); | ||
const msg = `A ${cst.type} node cannot be resolved as a mapping`; | ||
doc.errors.push(new _errors.YAMLSyntaxError(cst, msg)); | ||
@@ -35,33 +37,22 @@ return null; | ||
var _ref = cst.type === _Node.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst), | ||
comments = _ref.comments, | ||
items = _ref.items; | ||
const _ref = cst.type === _Node.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst), | ||
comments = _ref.comments, | ||
items = _ref.items; | ||
var map = new _Map.default(); | ||
const map = new _Map.default(); | ||
map.items = items; | ||
(0, _parseUtils.resolveComments)(map, comments); | ||
for (var i = 0; i < items.length; ++i) { | ||
var iKey = items[i].key; | ||
for (let i = 0; i < items.length; ++i) { | ||
const iKey = items[i].key; | ||
for (var j = i + 1; j < items.length; ++j) { | ||
var jKey = items[j].key; | ||
if (iKey === jKey || iKey && jKey && iKey.hasOwnProperty('value') && iKey.value === jKey.value) { | ||
var _msg = "Map keys must be unique; \"".concat(iKey, "\" is repeated"); | ||
doc.errors.push(new _errors.YAMLSemanticError(cst, _msg)); | ||
break; | ||
} | ||
} | ||
if (doc.schema.merge && iKey.value === _Merge.MERGE_KEY) { | ||
if (doc.schema.merge && iKey && iKey.value === _Merge.MERGE_KEY) { | ||
items[i] = new _Merge.default(items[i]); | ||
var sources = items[i].value.items; | ||
var error = null; | ||
sources.some(function (node) { | ||
const sources = items[i].value.items; | ||
let error = null; | ||
sources.some(node => { | ||
if (node instanceof _Alias.default) { | ||
// 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; | ||
const type = node.source.type; | ||
if (type === _Node.Type.MAP || type === _Node.Type.FLOW_MAP) return false; | ||
@@ -74,2 +65,12 @@ return error = 'Merge nodes aliases can only point to maps'; | ||
if (error) doc.errors.push(new _errors.YAMLSemanticError(cst, error)); | ||
} else { | ||
for (let j = i + 1; j < items.length; ++j) { | ||
const jKey = items[j].key; | ||
if (iKey === jKey || iKey && jKey && iKey.hasOwnProperty('value') && iKey.value === jKey.value) { | ||
const msg = `Map keys must be unique; "${iKey}" is repeated`; | ||
doc.errors.push(new _errors.YAMLSemanticError(cst, msg)); | ||
break; | ||
} | ||
} | ||
} | ||
@@ -83,9 +84,9 @@ } | ||
function resolveBlockMapItems(doc, cst) { | ||
var comments = []; | ||
var items = []; | ||
var key = undefined; | ||
var keyStart = null; | ||
const comments = []; | ||
const items = []; | ||
let key = undefined; | ||
let keyStart = null; | ||
for (var i = 0; i < cst.items.length; ++i) { | ||
var item = cst.items[i]; | ||
for (let i = 0; i < cst.items.length; ++i) { | ||
const item = cst.items[i]; | ||
@@ -112,7 +113,29 @@ switch (item.type) { | ||
if (!item.context.atLineStart && item.node && item.node.type === _Node.Type.MAP && !item.node.context.atLineStart) { | ||
var msg = 'Nested mappings are not allowed in compact mappings'; | ||
const msg = 'Nested mappings are not allowed in compact mappings'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item.node, msg)); | ||
} | ||
items.push(new _Pair.default(key, doc.resolveNode(item.node))); | ||
let valueNode = item.node; | ||
if (!valueNode && item.props.length > 0) { | ||
// Comments on an empty mapping value need to be preserved, so we | ||
// need to construct a minimal empty node here to use instead of the | ||
// missing `item.node`. -- eemeli/yaml#19 | ||
valueNode = new _PlainValue.default(_Node.Type.PLAIN, []); | ||
valueNode.context = { | ||
parent: item, | ||
src: item.context.src | ||
}; | ||
const pos = item.range.start + 1; | ||
valueNode.range = { | ||
start: pos, | ||
end: pos | ||
}; | ||
valueNode.valueRange = { | ||
start: pos, | ||
end: pos | ||
}; | ||
} | ||
items.push(new _Pair.default(key, doc.resolveNode(valueNode))); | ||
(0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart); | ||
@@ -128,12 +151,12 @@ key = undefined; | ||
if (item.error) doc.errors.push(item.error); | ||
var nextItem = cst.items[i + 1]; | ||
const nextItem = cst.items[i + 1]; | ||
if (!nextItem || nextItem.type !== _Node.Type.MAP_VALUE) { | ||
var _msg2 = 'Implicit map keys need to be followed by map values'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item, _msg2)); | ||
const msg = 'Implicit map keys need to be followed by map values'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item, msg)); | ||
} | ||
if (item.valueRangeContainsNewline) { | ||
var _msg3 = 'Implicit map keys need to be on a single line'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item, _msg3)); | ||
const msg = 'Implicit map keys need to be on a single line'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item, msg)); | ||
} | ||
@@ -146,4 +169,4 @@ | ||
return { | ||
comments: comments, | ||
items: items | ||
comments, | ||
items | ||
}; | ||
@@ -153,15 +176,17 @@ } | ||
function resolveFlowMapItems(doc, cst) { | ||
var comments = []; | ||
var items = []; | ||
var key = undefined; | ||
var keyStart = null; | ||
var explicitKey = false; | ||
var next = '{'; | ||
const comments = []; | ||
const items = []; | ||
let key = undefined; | ||
let keyStart = null; | ||
let explicitKey = false; | ||
let next = '{'; | ||
for (var i = 0; i < cst.items.length; ++i) { | ||
for (let i = 0; i < cst.items.length; ++i) { | ||
(0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart); | ||
var item = cst.items[i]; | ||
const item = cst.items[i]; | ||
if (typeof item === 'string') { | ||
if (item === '?' && key === undefined && !explicitKey) { | ||
if (typeof item.char === 'string') { | ||
const char = item.char; | ||
if (char === '?' && key === undefined && !explicitKey) { | ||
explicitKey = true; | ||
@@ -172,3 +197,3 @@ next = ':'; | ||
if (item === ':') { | ||
if (char === ':') { | ||
if (key === undefined) key = null; | ||
@@ -182,3 +207,3 @@ | ||
if (explicitKey) { | ||
if (key === undefined && item !== ',') key = null; | ||
if (key === undefined && char !== ',') key = null; | ||
explicitKey = false; | ||
@@ -192,3 +217,3 @@ } | ||
if (item === ',') { | ||
if (char === ',') { | ||
next = ':'; | ||
@@ -200,5 +225,5 @@ continue; | ||
if (item === '}') { | ||
if (char === '}') { | ||
if (i === cst.items.length - 1) continue; | ||
} else if (item === next) { | ||
} else if (char === next) { | ||
next = ':'; | ||
@@ -208,3 +233,3 @@ continue; | ||
doc.errors.push(new _errors.YAMLSyntaxError(cst, "Flow map contains an unexpected ".concat(item))); | ||
doc.errors.push(new _errors.YAMLSyntaxError(cst, `Flow map contains an unexpected ${char}`)); | ||
} else if (item.type === _Node.Type.COMMENT) { | ||
@@ -227,8 +252,8 @@ comments.push({ | ||
if (cst.items[cst.items.length - 1] !== '}') doc.errors.push(new _errors.YAMLSemanticError(cst, 'Expected flow map to end with }')); | ||
if (cst.items[cst.items.length - 1].char !== '}') doc.errors.push(new _errors.YAMLSemanticError(cst, 'Expected flow map to end with }')); | ||
if (key !== undefined) items.push(new _Pair.default(key)); | ||
return { | ||
comments: comments, | ||
items: items | ||
comments, | ||
items | ||
}; | ||
} |
@@ -22,3 +22,3 @@ "use strict"; | ||
if (cst.type !== _Node.Type.SEQ && cst.type !== _Node.Type.FLOW_SEQ) { | ||
var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence"); | ||
const msg = `A ${cst.type} node cannot be resolved as a sequence`; | ||
doc.errors.push(new _errors.YAMLSyntaxError(cst, msg)); | ||
@@ -28,7 +28,7 @@ return null; | ||
var _ref = cst.type === _Node.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst), | ||
comments = _ref.comments, | ||
items = _ref.items; | ||
const _ref = cst.type === _Node.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst), | ||
comments = _ref.comments, | ||
items = _ref.items; | ||
var seq = new _Seq.default(); | ||
const seq = new _Seq.default(); | ||
seq.items = items; | ||
@@ -41,7 +41,7 @@ (0, _parseUtils.resolveComments)(seq, comments); | ||
function resolveBlockSeqItems(doc, cst) { | ||
var comments = []; | ||
var items = []; | ||
const comments = []; | ||
const items = []; | ||
for (var i = 0; i < cst.items.length; ++i) { | ||
var item = cst.items[i]; | ||
for (let i = 0; i < cst.items.length; ++i) { | ||
const item = cst.items[i]; | ||
@@ -61,3 +61,3 @@ switch (item.type) { | ||
if (item.hasProps) { | ||
var msg = 'Sequence items cannot have tags or anchors before the - indicator'; | ||
const msg = 'Sequence items cannot have tags or anchors before the - indicator'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item, msg)); | ||
@@ -70,3 +70,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 _errors.YAMLSyntaxError(item, `Unexpected ${item.type} node in sequence`)); | ||
} | ||
@@ -76,4 +76,4 @@ } | ||
return { | ||
comments: comments, | ||
items: items | ||
comments, | ||
items | ||
}; | ||
@@ -83,15 +83,17 @@ } | ||
function resolveFlowSeqItems(doc, cst) { | ||
var comments = []; | ||
var items = []; | ||
var explicitKey = false; | ||
var key = undefined; | ||
var keyStart = null; | ||
var next = '['; | ||
const comments = []; | ||
const items = []; | ||
let explicitKey = false; | ||
let key = undefined; | ||
let keyStart = null; | ||
let next = '['; | ||
for (var i = 0; i < cst.items.length; ++i) { | ||
var item = cst.items[i]; | ||
for (let i = 0; i < cst.items.length; ++i) { | ||
const item = cst.items[i]; | ||
if (typeof item === 'string') { | ||
if (item !== ':' && (explicitKey || key !== undefined)) { | ||
if (explicitKey && key === undefined) key = null; | ||
if (typeof item.char === 'string') { | ||
const char = item.char; | ||
if (char !== ':' && (explicitKey || key !== undefined)) { | ||
if (explicitKey && key === undefined) key = next ? items.pop() : null; | ||
items.push(new _Pair.default(key)); | ||
@@ -103,7 +105,7 @@ explicitKey = false; | ||
if (item === next) { | ||
if (char === next) { | ||
next = null; | ||
} else if (!next && item === '?') { | ||
} else if (!next && char === '?') { | ||
explicitKey = true; | ||
} else if (next !== '[' && item === ':' && key === undefined) { | ||
} else if (next !== '[' && char === ':' && key === undefined) { | ||
if (next === ',') { | ||
@@ -113,4 +115,4 @@ key = items.pop(); | ||
if (key instanceof _Pair.default) { | ||
var msg = 'Chaining flow sequence pairs is invalid (e.g. [ a : b : c ])'; | ||
doc.errors.push(new _errors.YAMLSemanticError(item, msg)); | ||
const msg = 'Chaining flow sequence pairs is invalid (e.g. [ a : b : c ])'; | ||
doc.errors.push(new _errors.YAMLSemanticError(char, msg)); | ||
} | ||
@@ -127,6 +129,5 @@ | ||
next = null; | ||
} else if (next === '[' || item !== ']' || i < cst.items.length - 1) { | ||
var _msg = "Flow sequence contains an unexpected ".concat(item); | ||
doc.errors.push(new _errors.YAMLSyntaxError(cst, _msg)); | ||
} else if (next === '[' || char !== ']' || i < cst.items.length - 1) { | ||
const msg = `Flow sequence contains an unexpected ${char}`; | ||
doc.errors.push(new _errors.YAMLSyntaxError(cst, msg)); | ||
} | ||
@@ -140,8 +141,7 @@ } else if (item.type === _Node.Type.COMMENT) { | ||
if (next) { | ||
var _msg2 = "Expected a ".concat(next, " here in flow sequence"); | ||
doc.errors.push(new _errors.YAMLSemanticError(item, _msg2)); | ||
const msg = `Expected a ${next} here in flow sequence`; | ||
doc.errors.push(new _errors.YAMLSemanticError(item, msg)); | ||
} | ||
var value = doc.resolveNode(item); | ||
const value = doc.resolveNode(item); | ||
@@ -160,8 +160,8 @@ if (key === undefined) { | ||
if (cst.items[cst.items.length - 1] !== ']') doc.errors.push(new _errors.YAMLSemanticError(cst, 'Expected flow sequence to end with ]')); | ||
if (cst.items[cst.items.length - 1].char !== ']') doc.errors.push(new _errors.YAMLSemanticError(cst, 'Expected flow sequence to end with ]')); | ||
if (key !== undefined) items.push(new _Pair.default(key)); | ||
return { | ||
comments: comments, | ||
items: items | ||
comments, | ||
items | ||
}; | ||
} |
@@ -12,9 +12,9 @@ "use strict"; | ||
function checkKeyLength(errors, node, itemIdx, key, keyStart) { | ||
if (typeof keyStart !== 'number') return; | ||
var item = node.items[itemIdx]; | ||
var keyEnd = item && item.range && item.range.start; | ||
if (!key || typeof keyStart !== 'number') return; | ||
const item = node.items[itemIdx]; | ||
let keyEnd = item && item.range && item.range.start; | ||
if (!keyEnd) { | ||
for (var i = itemIdx - 1; i >= 0; --i) { | ||
var it = node.items[i]; | ||
for (let i = itemIdx - 1; i >= 0; --i) { | ||
const it = node.items[i]; | ||
@@ -29,4 +29,4 @@ if (it && it.range) { | ||
if (keyEnd > keyStart + 1024) { | ||
var k = String(key).substr(0, 8) + '...' + String(key).substr(-8); | ||
errors.push(new _errors.YAMLSemanticError(node, "The \"".concat(k, "\" key is too long"))); | ||
const k = String(key).substr(0, 8) + '...' + String(key).substr(-8); | ||
errors.push(new _errors.YAMLSemanticError(node, `The "${k}" key is too long`)); | ||
} | ||
@@ -36,6 +36,7 @@ } | ||
function resolveComments(collection, comments) { | ||
comments.forEach(function (_ref) { | ||
var comment = _ref.comment, | ||
before = _ref.before; | ||
var item = collection.items[before]; | ||
comments.forEach(({ | ||
comment, | ||
before | ||
}) => { | ||
const item = collection.items[before]; | ||
@@ -42,0 +43,0 @@ if (!item) { |
@@ -8,56 +8,25 @@ "use strict"; | ||
var _toJSON2 = _interopRequireDefault(require("../toJSON")); | ||
var _toJSON = _interopRequireDefault(require("../toJSON")); | ||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
var _Node = _interopRequireDefault(require("./Node")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
// Published as 'yaml/scalar' | ||
class Scalar extends _Node.default { | ||
constructor(value) { | ||
super(); | ||
this.value = value; | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
toJSON(arg, keep) { | ||
return keep ? this.value : (0, _toJSON.default)(this.value, arg, keep); | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var Scalar = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
_inherits(Scalar, _Node); | ||
function Scalar(value) { | ||
var _this; | ||
_classCallCheck(this, Scalar); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Scalar).call(this)); | ||
_this.value = value; | ||
return _this; | ||
toString() { | ||
return String(this.value); | ||
} | ||
_createClass(Scalar, [{ | ||
key: "toJSON", | ||
value: function toJSON(arg, keep) { | ||
return keep ? this.value : (0, _toJSON2.default)(this.value, arg, keep); | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
return String(this.value); | ||
} | ||
}]); | ||
} | ||
return Scalar; | ||
}(_Node2.default); | ||
exports.default = Scalar; |
@@ -8,70 +8,31 @@ "use strict"; | ||
var _toJSON2 = _interopRequireDefault(require("../toJSON")); | ||
var _toJSON = _interopRequireDefault(require("../toJSON")); | ||
var _Collection2 = _interopRequireDefault(require("./Collection")); | ||
var _Collection = _interopRequireDefault(require("./Collection")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
// Published as 'yaml/seq' | ||
class YAMLSeq extends _Collection.default { | ||
toJSON(_, keep) { | ||
return this.items.map((v, i) => (0, _toJSON.default)(v, String(i), keep)); | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } | ||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var YAMLSeq = | ||
/*#__PURE__*/ | ||
function (_Collection) { | ||
_inherits(YAMLSeq, _Collection); | ||
function YAMLSeq() { | ||
_classCallCheck(this, YAMLSeq); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(YAMLSeq).apply(this, arguments)); | ||
toString(ctx, onComment) { | ||
if (!ctx) return JSON.stringify(this); | ||
return super.toString(ctx, { | ||
blockItem: ({ | ||
type, | ||
str | ||
}) => type === 'comment' ? str : `- ${str}`, | ||
flowChars: { | ||
start: '[', | ||
end: ']' | ||
}, | ||
itemIndent: (ctx.indent || '') + ' ' | ||
}, onComment); | ||
} | ||
_createClass(YAMLSeq, [{ | ||
key: "toJSON", | ||
value: function toJSON(_, keep) { | ||
return this.items.map(function (v, i) { | ||
return (0, _toJSON2.default)(v, String(i), keep); | ||
}); | ||
} | ||
}, { | ||
key: "toString", | ||
value: function toString(ctx, onComment) { | ||
if (!ctx) return JSON.stringify(this); | ||
return _get(_getPrototypeOf(YAMLSeq.prototype), "toString", this).call(this, ctx, { | ||
blockItem: function blockItem(_ref) { | ||
var type = _ref.type, | ||
str = _ref.str; | ||
return type === 'comment' ? str : "- ".concat(str); | ||
}, | ||
flowChars: { | ||
start: '[', | ||
end: ']' | ||
}, | ||
itemIndent: (ctx.indent || '') + ' ' | ||
}, onComment); | ||
} | ||
}]); | ||
} | ||
return YAMLSeq; | ||
}(_Collection2.default); | ||
exports.default = YAMLSeq; |
@@ -20,7 +20,7 @@ "use strict"; | ||
var nullOptions = { | ||
const nullOptions = { | ||
nullStr: 'null' | ||
}; | ||
exports.nullOptions = nullOptions; | ||
var boolOptions = { | ||
const boolOptions = { | ||
trueStr: 'true', | ||
@@ -36,9 +36,5 @@ falseStr: 'false' | ||
test: /^(?:~|[Nn]ull|NULL)?$/, | ||
resolve: function resolve() { | ||
return null; | ||
}, | ||
resolve: () => null, | ||
options: nullOptions, | ||
stringify: function stringify() { | ||
return nullOptions.nullStr; | ||
} | ||
stringify: () => nullOptions.nullStr | ||
}, { | ||
@@ -49,10 +45,7 @@ class: Boolean, | ||
test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/, | ||
resolve: function resolve() { | ||
return true; | ||
}, | ||
resolve: () => true, | ||
options: boolOptions, | ||
stringify: function stringify(_ref) { | ||
var value = _ref.value; | ||
return value ? boolOptions.trueStr : boolOptions.falseStr; | ||
} | ||
stringify: ({ | ||
value | ||
}) => value ? boolOptions.trueStr : boolOptions.falseStr | ||
}, { | ||
@@ -63,10 +56,7 @@ class: Boolean, | ||
test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i, | ||
resolve: function resolve() { | ||
return false; | ||
}, | ||
resolve: () => false, | ||
options: boolOptions, | ||
stringify: function stringify(_ref2) { | ||
var value = _ref2.value; | ||
return value ? boolOptions.trueStr : boolOptions.falseStr; | ||
} | ||
stringify: ({ | ||
value | ||
}) => value ? boolOptions.trueStr : boolOptions.falseStr | ||
}, { | ||
@@ -78,9 +68,6 @@ class: Number, | ||
test: /^0b([0-1_]+)$/, | ||
resolve: function resolve(str, bin) { | ||
return parseInt(bin.replace(/_/g, ''), 2); | ||
}, | ||
stringify: function stringify(_ref3) { | ||
var value = _ref3.value; | ||
return '0b' + value.toString(2); | ||
} | ||
resolve: (str, bin) => parseInt(bin.replace(/_/g, ''), 2), | ||
stringify: ({ | ||
value | ||
}) => '0b' + value.toString(2) | ||
}, { | ||
@@ -92,9 +79,6 @@ class: Number, | ||
test: /^[-+]?0([0-7_]+)$/, | ||
resolve: function resolve(str, oct) { | ||
return parseInt(oct.replace(/_/g, ''), 8); | ||
}, | ||
stringify: function stringify(_ref4) { | ||
var value = _ref4.value; | ||
return (value < 0 ? '-0' : '0') + value.toString(8); | ||
} | ||
resolve: (str, oct) => parseInt(oct.replace(/_/g, ''), 8), | ||
stringify: ({ | ||
value | ||
}) => (value < 0 ? '-0' : '0') + value.toString(8) | ||
}, { | ||
@@ -105,5 +89,3 @@ class: Number, | ||
test: /^[-+]?[0-9][0-9_]*$/, | ||
resolve: function resolve(str) { | ||
return parseInt(str.replace(/_/g, ''), 10); | ||
}, | ||
resolve: str => parseInt(str.replace(/_/g, ''), 10), | ||
stringify: _core.stringifyNumber | ||
@@ -116,9 +98,6 @@ }, { | ||
test: /^0x([0-9a-fA-F_]+)$/, | ||
resolve: function resolve(str, hex) { | ||
return parseInt(hex.replace(/_/g, ''), 16); | ||
}, | ||
stringify: function stringify(_ref5) { | ||
var value = _ref5.value; | ||
return (value < 0 ? '-0x' : '0x') + value.toString(16); | ||
} | ||
resolve: (str, hex) => parseInt(hex.replace(/_/g, ''), 16), | ||
stringify: ({ | ||
value | ||
}) => (value < 0 ? '-0x' : '0x') + value.toString(16) | ||
}, { | ||
@@ -129,5 +108,3 @@ class: Number, | ||
test: /^(?:[-+]?\.inf|(\.nan))$/i, | ||
resolve: function resolve(str, nan) { | ||
return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY; | ||
}, | ||
resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, | ||
stringify: _core.stringifyNumber | ||
@@ -139,5 +116,3 @@ }, { | ||
test: /^[-+]?([0-9][0-9_]*)?\.[0-9_]*([eE][-+]?[0-9]+)?$/, | ||
resolve: function resolve(str) { | ||
return parseFloat(str.replace(/_/g, '')); | ||
}, | ||
resolve: str => parseFloat(str.replace(/_/g, '')), | ||
stringify: _core.stringifyNumber | ||
@@ -144,0 +119,0 @@ }], _timestamp.default, _binary.default); |
@@ -24,3 +24,3 @@ "use strict"; | ||
function testEvents(src, options) { | ||
var opt = Object.assign({ | ||
const opt = Object.assign({ | ||
keepCstNodes: true, | ||
@@ -30,28 +30,24 @@ keepNodeTypes: true, | ||
}, options); | ||
var docs = (0, _parse.default)(src).map(function (cstDoc) { | ||
return new _Document.default(opt).parse(cstDoc); | ||
}); | ||
var errDoc = docs.find(function (doc) { | ||
return doc.errors.length > 0; | ||
}); | ||
var error = errDoc ? errDoc.errors[0].message : null; | ||
var events = ['+STR']; | ||
const docs = (0, _parse.default)(src).map(cstDoc => new _Document.default(opt).parse(cstDoc)); | ||
const errDoc = docs.find(doc => doc.errors.length > 0); | ||
const error = errDoc ? errDoc.errors[0].message : null; | ||
const events = ['+STR']; | ||
try { | ||
for (var i = 0; i < docs.length; ++i) { | ||
var doc = docs[i]; | ||
var root = doc.contents; | ||
for (let i = 0; i < docs.length; ++i) { | ||
const doc = docs[i]; | ||
let root = doc.contents; | ||
if (Array.isArray(root)) root = root[0]; | ||
var _ref = doc.range || [0, 0], | ||
_ref2 = _slicedToArray(_ref, 2), | ||
rootStart = _ref2[0], | ||
rootEnd = _ref2[1]; | ||
const _ref = doc.range || [0, 0], | ||
_ref2 = _slicedToArray(_ref, 2), | ||
rootStart = _ref2[0], | ||
rootEnd = _ref2[1]; | ||
var e = doc.errors[0] && doc.errors[0].source; | ||
let e = doc.errors[0] && doc.errors[0].source; | ||
if (e && e.type === 'SEQ_ITEM') e = e.node; | ||
if (e && (e.type === 'DOCUMENT' || e.range.start < rootStart)) throw new Error(); | ||
var docStart = '+DOC'; | ||
var pre = src.slice(0, rootStart); | ||
var explicitDoc = /---\s*$/.test(pre); | ||
let docStart = '+DOC'; | ||
const pre = src.slice(0, rootStart); | ||
const explicitDoc = /---\s*$/.test(pre); | ||
if (explicitDoc) docStart += ' ---';else if (!doc.contents) continue; | ||
@@ -61,7 +57,7 @@ events.push(docStart); | ||
if (doc.contents && doc.contents.length > 1) throw new Error(); | ||
var docEnd = '-DOC'; | ||
let docEnd = '-DOC'; | ||
if (rootEnd) { | ||
var post = src.slice(rootEnd); | ||
if (/^(\s*(#.*)?\n)*\.\.\./.test(post)) docEnd += ' ...'; | ||
const post = src.slice(rootEnd); | ||
if (/^\.\.\./.test(post)) docEnd += ' ...'; | ||
} | ||
@@ -73,3 +69,3 @@ | ||
return { | ||
events: events, | ||
events, | ||
error: error || e | ||
@@ -81,4 +77,4 @@ }; | ||
return { | ||
events: events, | ||
error: error | ||
events, | ||
error | ||
}; | ||
@@ -90,34 +86,33 @@ } | ||
if (e && node.cstNode === e) throw new Error(); | ||
var props = ''; | ||
var anchor = doc.anchors.getName(node); | ||
let props = ''; | ||
let anchor = doc.anchors.getName(node); | ||
if (anchor) { | ||
if (/\d$/.test(anchor)) { | ||
var alt = anchor.replace(/\d$/, ''); | ||
const alt = anchor.replace(/\d$/, ''); | ||
if (doc.anchors.getNode(alt)) anchor = alt; | ||
} | ||
props = " &".concat(anchor); | ||
props = ` &${anchor}`; | ||
} | ||
if (node.cstNode && node.cstNode.tag) { | ||
var _node$cstNode$tag = node.cstNode.tag, | ||
handle = _node$cstNode$tag.handle, | ||
suffix = _node$cstNode$tag.suffix; | ||
props += handle === '!' && !suffix ? ' <!>' : " <".concat(node.tag, ">"); | ||
const _node$cstNode$tag = node.cstNode.tag, | ||
handle = _node$cstNode$tag.handle, | ||
suffix = _node$cstNode$tag.suffix; | ||
props += handle === '!' && !suffix ? ' <!>' : ` <${node.tag}>`; | ||
} | ||
var scalar = null; | ||
let scalar = null; | ||
switch (node.type) { | ||
case 'ALIAS': | ||
var alias = doc.anchors.getName(node.source); | ||
let alias = doc.anchors.getName(node.source); | ||
if (/\d$/.test(alias)) { | ||
var _alt = alias.replace(/\d$/, ''); | ||
if (doc.anchors.getNode(_alt)) alias = _alt; | ||
const alt = alias.replace(/\d$/, ''); | ||
if (doc.anchors.getNode(alt)) alias = alt; | ||
} | ||
events.push("=ALI".concat(props, " *").concat(alias)); | ||
events.push(`=ALI${props} *${alias}`); | ||
break; | ||
@@ -146,3 +141,3 @@ | ||
case 'PAIR': | ||
events.push("+MAP".concat(props)); | ||
events.push(`+MAP${props}`); | ||
addEvents(events, doc, e, node.key); | ||
@@ -155,4 +150,4 @@ addEvents(events, doc, e, node.value); | ||
case 'SEQ': | ||
events.push("+SEQ".concat(props)); | ||
node.items.forEach(function (item) { | ||
events.push(`+SEQ${props}`); | ||
node.items.forEach(item => { | ||
addEvents(events, doc, e, item); | ||
@@ -165,6 +160,7 @@ }); | ||
case 'MAP': | ||
events.push("+MAP".concat(props)); | ||
node.items.forEach(function (_ref3) { | ||
var key = _ref3.key, | ||
value = _ref3.value; | ||
events.push(`+MAP${props}`); | ||
node.items.forEach(({ | ||
key, | ||
value | ||
}) => { | ||
addEvents(events, doc, e, key); | ||
@@ -177,9 +173,9 @@ addEvents(events, doc, e, value); | ||
default: | ||
throw new Error("Unexpected node type ".concat(node.type)); | ||
throw new Error(`Unexpected node type ${node.type}`); | ||
} | ||
if (scalar) { | ||
var value = node.cstNode.strValue.replace(/\\/g, '\\\\').replace(/\0/g, '\\0').replace(/\x07/g, '\\a').replace(/\x08/g, '\\b').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\v/g, '\\v').replace(/\f/g, '\\f').replace(/\r/g, '\\r').replace(/\x1b/g, '\\e'); | ||
events.push("=VAL".concat(props, " ").concat(scalar).concat(value)); | ||
const value = node.cstNode.strValue.replace(/\\/g, '\\\\').replace(/\0/g, '\\0').replace(/\x07/g, '\\a').replace(/\x08/g, '\\b').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\v/g, '\\v').replace(/\f/g, '\\f').replace(/\r/g, '\\r').replace(/\x1b/g, '\\e'); | ||
events.push(`=VAL${props} ${scalar}${value}`); | ||
} | ||
} |
@@ -9,5 +9,3 @@ "use strict"; | ||
function toJSON(value, arg, keep) { | ||
return Array.isArray(value) ? value.map(function (v, i) { | ||
return toJSON(v, String(i), keep); | ||
}) : value && typeof value.toJSON === 'function' ? value.toJSON(arg, keep) : value; | ||
return Array.isArray(value) ? value.map((v, i) => toJSON(v, String(i), keep)) : value && typeof value.toJSON === 'function' ? value.toJSON(arg, keep) : value; | ||
} |
{ | ||
"name": "yaml", | ||
"version": "1.0.0-rc.7", | ||
"version": "1.0.0-rc.8", | ||
"main": "dist/index.js", | ||
@@ -8,3 +8,3 @@ "license": "ISC", | ||
"repository": "github:eemeli/yaml", | ||
"description": "JavaScript parser and stringifier for YAML 1.2", | ||
"description": "JavaScript parser and stringifier for YAML", | ||
"keywords": [ | ||
@@ -34,8 +34,15 @@ "YAML", | ||
"presets": [ | ||
"@babel/env", | ||
"@babel/stage-3" | ||
[ | ||
"@babel/env", | ||
{ | ||
"targets": { | ||
"node": "6" | ||
} | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties", | ||
[ | ||
"trace", | ||
"babel-plugin-trace", | ||
{ | ||
@@ -58,11 +65,11 @@ "strip": true | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.52", | ||
"@babel/core": "^7.0.0-beta.52", | ||
"@babel/preset-env": "^7.0.0-beta.52", | ||
"@babel/preset-stage-3": "^7.0.0-beta.52", | ||
"@babel/cli": "^7.0.0-rc.2", | ||
"@babel/core": "^7.0.0-rc.2", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0-rc.2", | ||
"@babel/preset-env": "^7.0.0-rc.2", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^23.2.0", | ||
"babel-jest": "^23.4.2", | ||
"babel-plugin-trace": "^1.1.0", | ||
"jest": "^23.3.0", | ||
"prettier": "^1.13.7" | ||
"jest": "^23.5.0", | ||
"prettier": "^1.14.2" | ||
}, | ||
@@ -69,0 +76,0 @@ "dependencies": {}, |
@@ -1,2 +0,2 @@ | ||
# YAML <a href="https://www.npmjs.com/package/yaml"><img align="right" src="https://badge.fury.io/js/yaml.svg" title="npm package" /></a> | ||
# YAML <a href="https://www.npmjs.com/package/yaml"><img align="right" src="https://badge.fury.io/js/yaml.svg" title="npm package" /></a><a href="https://travis-ci.org/eemeli/yaml"><img align="right" src="https://travis-ci.org/eemeli/yaml.svg?branch=master" title="Build status" /></a> | ||
@@ -3,0 +3,0 @@ `yaml` is a JavaScript parser and stringifier for [YAML](http://yaml.org/), a human friendly data serialization standard. It supports both parsing and stringifying data using all versions of YAML, along with all common data schemas. As a particularly distinguishing feature, `yaml` fully supports reading and writing comments in YAML documents. |
163243
4370