Socket
Socket
Sign inDemoInstall

yaml

Package Overview
Dependencies
Maintainers
3
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml - npm Package Compare versions

Comparing version 1.0.0-rc.2 to 1.0.0-rc.3

dist/createNode.js

5

dist/ast/Collection.js

@@ -79,3 +79,6 @@ "use strict";

var firstItem = this.items[0];
var 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);

@@ -82,0 +85,0 @@ var indent = firstItem.range.start - firstItem.context.lineStart;

4

dist/ast/ParseContext.js

@@ -174,3 +174,3 @@ "use strict";

var collection = new _Collection.default(node);
offset = collection.parse(context, offset);
offset = collection.parse(new ParseContext(context), offset);
collection.range = new _Range.default(start, offset);

@@ -183,3 +183,3 @@ return collection;

this.atLineStart = atLineStart != null ? atLineStart : orig.lineStart || false;
this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false;
this.inCollection = inCollection != null ? inCollection : orig.inCollection || false;

@@ -186,0 +186,0 @@ this.inFlow = inFlow != null ? inFlow : orig.inFlow || false;

@@ -16,4 +16,2 @@ "use strict";

var _resolveValue2 = _interopRequireDefault(require("./resolveValue"));
var _schema = _interopRequireWildcard(require("./schema"));

@@ -143,3 +141,9 @@

this.contents = contentNodes;
if (this.contents[0]) this.contents[0].commentBefore = comments.before.join('\n') || null;else comments.after = comments.before.concat(comments.after);
if (this.contents[0]) {
this.contents[0].commentBefore = comments.before.join('\n') || null;
} else {
comments.after = comments.before.concat(comments.after);
}
}

@@ -317,3 +321,7 @@

var cb = comments.before.join('\n');
if (cb) res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb;
if (cb) {
res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb;
}
var ca = comments.after.join('\n');

@@ -326,7 +334,2 @@ if (ca) res.comment = res.comment ? "".concat(res.comment, "\n").concat(ca) : ca;

}, {
key: "resolveValue",
value: function resolveValue(value) {
return (0, _resolveValue2.default)(this, value, true);
}
}, {
key: "listNonDefaultTags",

@@ -393,12 +396,13 @@ value: function listNonDefaultTags() {

if (hasDirectives) lines.push('---');
var ctx = {
doc: this,
indent: ''
};
if (this.contents) {
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#'));
var options = {
// top-level block scalars need to be indented if followed by a comment
forceBlockIndent: !!this.comment,
indent: ''
};
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
ctx.forceBlockIndent = !!this.comment;
var comment = this.contents.comment;
var body = this.schema.stringify(this, this.contents, options, function () {
var body = this.schema.stringify(this.contents, ctx, function () {
comment = null;

@@ -408,5 +412,3 @@ });

} else if (this.contents !== undefined) {
lines.push(this.schema.stringify(this, this.contents, {
indent: ''
}));
lines.push(this.schema.stringify(this.contents, ctx));
}

@@ -413,0 +415,0 @@

@@ -10,2 +10,4 @@ "use strict";

var _createNode = _interopRequireDefault(require("./createNode"));
var _Document3 = _interopRequireDefault(require("./Document"));

@@ -71,2 +73,3 @@

var _default = {
createNode: _createNode.default,
defaultOptions: defaultOptions,

@@ -73,0 +76,0 @@ Document:

@@ -10,4 +10,2 @@ "use strict";

var _errors = require("../errors");
var _Node2 = _interopRequireDefault(require("./Node"));

@@ -23,12 +21,12 @@

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.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; 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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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; }

@@ -47,70 +45,19 @@

function (_Node) {
_createClass(Collection, null, [{
key: "checkKeyLength",
value: function checkKeyLength(doc, node, itemIdx, key, keyStart) {
if (typeof keyStart !== 'number') return;
var item = node.items[itemIdx];
var keyEnd = item && item.range && item.range.start;
function Collection() {
var _getPrototypeOf2;
if (!keyEnd) {
for (var i = itemIdx - 1; i >= 0; --i) {
var it = node.items[i];
var _temp, _this;
if (it && it.range) {
keyEnd = it.range.end + 2 * (itemIdx - i);
break;
}
}
}
_classCallCheck(this, Collection);
if (keyEnd > keyStart + 1024) {
var k = String(key).substr(0, 8) + '...' + String(key).substr(-8);
doc.errors.push(new _errors.YAMLSemanticError(node, "The \"".concat(k, "\" key is too long")));
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
}]);
function Collection(doc) {
var _this;
_classCallCheck(this, Collection);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Collection).call(this));
if (!doc) throw new Error('Document not defined for new collection');
_this._comments = [];
_this.doc = doc;
_this.items = [];
return _this;
return _possibleConstructorReturn(_this, (_temp = _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Collection)).call.apply(_getPrototypeOf2, [this].concat(args))), _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "items", []), _temp));
}
_createClass(Collection, [{
key: "addComment",
value: function addComment(comment) {
this._comments.push({
comment: comment,
before: this.items.length
});
}
}, {
key: "resolveComments",
value: function resolveComments() {
var _this2 = this;
this._comments.forEach(function (_ref) {
var comment = _ref.comment,
before = _ref.before;
var item = _this2.items[before];
if (!item) {
if (_this2.comment) _this2.comment += '\n' + comment;else _this2.comment = comment;
} else {
if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
}
});
delete this._comments;
} // overridden in implementations
}, {
key: "toJSON",
// overridden in implementations
value: function toJSON() {

@@ -121,12 +68,14 @@ return null;

key: "toString",
value: function toString(options, onComment) {
var _this3 = this;
value: function toString(_ref, onComment) {
var _this2 = this;
var schema = this.doc.schema;
var blockItem = options.blockItem,
flowChars = options.flowChars,
indent = options.indent,
inFlow = options.inFlow,
itemIndent = options.itemIndent;
var opt = {
var blockItem = _ref.blockItem,
doc = _ref.doc,
flowChars = _ref.flowChars,
indent = _ref.indent,
inFlow = _ref.inFlow,
itemIndent = _ref.itemIndent;
if (!doc) return JSON.stringify(this);
var ctx = {
doc: doc,
indent: itemIndent,

@@ -153,8 +102,8 @@ inFlow: inFlow,

if (comment) hasItemWithComment = true;
var str = schema.stringify(_this3.doc, item, opt, function () {
var str = doc.schema.stringify(item, ctx, function () {
comment = null;
});
if (!hasItemWithNewLine && str.indexOf('\n') !== -1) hasItemWithNewLine = true;
if (inFlow && i < _this3.items.length - 1) str += ',';
str = (0, _addComment.default)(str, opt.indent, comment);
if (inFlow && i < _this2.items.length - 1) str += ',';
str = (0, _addComment.default)(str, ctx.indent, comment);
nodes.push({

@@ -161,0 +110,0 @@ type: 'item',

@@ -8,4 +8,2 @@ "use strict";

var _Node = require("../ast/Node");
var _Map = _interopRequireDefault(require("./Map"));

@@ -17,2 +15,6 @@

var _parseMap = _interopRequireDefault(require("./parseMap"));
var _parseSeq = _interopRequireDefault(require("./parseSeq"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -23,9 +25,5 @@

tag: 'tag:yaml.org,2002:map',
resolve: function resolve(doc, node) {
return new _Map.default(doc).parse(node);
},
stringify: function stringify(value, _ref, onComment) {
var indent = _ref.indent,
inFlow = _ref.inFlow;
return value.toString(indent, inFlow, onComment);
resolve: _parseMap.default,
stringify: function stringify(value, ctx, onComment) {
return value.toString(ctx, onComment);
}

@@ -37,9 +35,5 @@ };

tag: 'tag:yaml.org,2002:seq',
resolve: function resolve(doc, node) {
return new _Seq.default(doc).parse(node);
},
stringify: function stringify(value, _ref2, onComment) {
var indent = _ref2.indent,
inFlow = _ref2.inFlow;
return value.toString(indent, inFlow, onComment);
resolve: _parseSeq.default,
stringify: function stringify(value, ctx, onComment) {
return value.toString(ctx, onComment);
}

@@ -46,0 +40,0 @@ };

@@ -10,2 +10,4 @@ "use strict";

var _createNode = _interopRequireDefault(require("../createNode"));
var _errors = require("../errors");

@@ -185,12 +187,12 @@

key: "stringify",
value: function stringify(doc, item, options, onComment) {
value: function stringify(item, ctx, onComment) {
if (!(item instanceof _Scalar.default || item instanceof _Collection.default || item instanceof _Pair.default)) {
item = doc.resolveValue(item, true);
item = (0, _createNode.default)(item, true);
}
options.tags = this;
ctx.tags = this;
var match;
if (item instanceof _Pair.default) {
return item.toString(doc, options, onComment);
return item.toString(ctx, onComment);
} else if (item.tag) {

@@ -237,7 +239,7 @@ match = this.schema.filter(function (_ref6) {

var stringify = match[0].stringify || Schema.defaultStringifier;
var str = stringify(item, options, onComment);
var str = stringify(item, ctx, onComment);
var tag = item.origTag || item.tag;
if (tag && tag.indexOf(defaultPrefix) !== 0) {
var p = doc.tagPrefixes.find(function (p) {
var p = ctx.doc.tagPrefixes.find(function (p) {
return tag.indexOf(p.prefix) === 0;

@@ -247,4 +249,4 @@ });

if (item instanceof _Collection.default && !options.inFlow && item.items.length > 0) {
return "".concat(tagProp, "\n").concat(options.indent).concat(str);
if (item instanceof _Collection.default && !ctx.inFlow && item.items.length > 0) {
return "".concat(tagProp, "\n").concat(ctx.indent).concat(str);
} else {

@@ -251,0 +253,0 @@ return "".concat(tagProp, " ").concat(str);

@@ -8,14 +8,4 @@ "use strict";

var _Node = require("../ast/Node");
var _errors = require("../errors");
var _Collection2 = _interopRequireWildcard(require("./Collection"));
var _Pair = _interopRequireDefault(require("./Pair"));
var _Seq = _interopRequireDefault(require("./Seq"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

@@ -25,10 +15,2 @@

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -64,176 +46,7 @@

_createClass(YAMLMap, [{
key: "parse",
value: function parse(ast) {
var _this = this;
ast.resolved = this;
if (ast.type === _Node.Type.FLOW_MAP) {
this.resolveFlowMapItems(ast);
} else {
this.resolveBlockMapItems(ast);
}
this.resolveComments();
for (var i = 0; i < this.items.length; ++i) {
var iKey = this.items[i].key;
for (var j = i + 1; j < this.items.length; ++j) {
var jKey = this.items[j].key;
if (iKey === jKey || iKey && jKey && iKey.hasOwnProperty('value') && iKey.value === jKey.value) {
this.doc.errors.push(new _errors.YAMLSemanticError(ast, "Map keys must be unique; \"".concat(iKey, "\" is repeated")));
break;
}
}
if (this.doc.schema.merge && iKey.value === '<<') {
var src = this.items[i].value;
var srcItems = src instanceof _Seq.default ? src.items.reduce(function (acc, _ref) {
var items = _ref.items;
return acc.concat(items);
}, []) : src.items;
var toAdd = srcItems.reduce(function (toAdd, pair) {
var exists = _this.items.some(function (_ref2) {
var key = _ref2.key;
return key.value === pair.key.value;
}) || toAdd.some(function (_ref3) {
var key = _ref3.key;
return key.value === pair.key.value;
});
return exists ? toAdd : toAdd.concat(pair);
}, []);
Array.prototype.splice.apply(this.items, [i, 1].concat(_toConsumableArray(toAdd)));
i += toAdd.length - 1;
}
}
return this;
}
}, {
key: "resolveBlockMapItems",
value: function resolveBlockMapItems(map) {
var key = undefined;
var keyStart = null;
for (var i = 0; i < map.items.length; ++i) {
var item = map.items[i];
switch (item.type) {
case _Node.Type.COMMENT:
this.addComment(item.comment);
break;
case _Node.Type.MAP_KEY:
if (key !== undefined) this.items.push(new _Pair.default(key));
if (item.error) this.doc.errors.push(item.error);
key = this.doc.resolveNode(item.node);
keyStart = null;
break;
case _Node.Type.MAP_VALUE:
if (key === undefined) key = null;
if (item.error) this.doc.errors.push(item.error);
if (!item.context.atLineStart && item.node && item.node.type === _Node.Type.MAP && !item.node.context.atLineStart) {
this.doc.errors.push(new _errors.YAMLSemanticError(item.node, 'Nested mappings are not allowed in compact mappings'));
}
this.items.push(new _Pair.default(key, this.doc.resolveNode(item.node)));
_Collection2.default.checkKeyLength(this.doc, map, i, key, keyStart);
key = undefined;
keyStart = null;
break;
default:
if (key !== undefined) this.items.push(new _Pair.default(key));
key = this.doc.resolveNode(item);
keyStart = item.range.start;
var nextItem = map.items[i + 1];
if (!nextItem || nextItem.type !== _Node.Type.MAP_VALUE) this.doc.errors.push(new _errors.YAMLSemanticError(item, 'Implicit map keys need to be followed by map values'));
if (item.valueRangeContainsNewline) this.doc.errors.push(new _errors.YAMLSemanticError(item, 'Implicit map keys need to be on a single line'));
}
}
if (key !== undefined) this.items.push(new _Pair.default(key));
}
}, {
key: "resolveFlowMapItems",
value: function resolveFlowMapItems(map) {
var key = undefined;
var keyStart = null;
var explicitKey = false;
var next = '{';
for (var i = 0; i < map.items.length; ++i) {
_Collection2.default.checkKeyLength(this.doc, map, i, key, keyStart);
var item = map.items[i];
if (typeof item === 'string') {
if (item === '?' && key === undefined && !explicitKey) {
explicitKey = true;
next = ':';
continue;
}
if (item === ':') {
if (key === undefined) key = null;
if (next === ':') {
next = ',';
continue;
}
} else {
if (explicitKey) {
if (key === undefined && item !== ',') key = null;
explicitKey = false;
}
if (key !== undefined) {
this.items.push(new _Pair.default(key));
key = undefined;
keyStart = null;
if (item === ',') {
next = ':';
continue;
}
}
}
if (item === '}') {
if (i === map.items.length - 1) continue;
} else if (item === next) {
next = ':';
continue;
}
this.doc.errors.push(new _errors.YAMLSyntaxError(map, "Flow map contains an unexpected ".concat(item)));
} else if (item.type === _Node.Type.COMMENT) {
this.addComment(item.comment);
} else if (key === undefined) {
if (next === ',') this.doc.errors.push(new _errors.YAMLSemanticError(item, 'Separator , missing in flow map'));
key = this.doc.resolveNode(item);
keyStart = explicitKey ? null : item.range.start; // TODO: add error for non-explicit multiline plain key
} else {
if (next !== ',') this.doc.errors.push(new _errors.YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
this.items.push(new _Pair.default(key, this.doc.resolveNode(item)));
key = undefined;
explicitKey = false;
}
}
if (map.items[map.items.length - 1] !== '}') this.doc.errors.push(new _errors.YAMLSemanticError(map, 'Expected flow map to end with }'));
if (key !== undefined) this.items.push(new _Pair.default(key));
}
}, {
key: "toJSON",
value: function toJSON() {
return this.items.reduce(function (map, _ref4) {
var stringKey = _ref4.stringKey,
value = _ref4.value;
return this.items.reduce(function (map, _ref) {
var stringKey = _ref.stringKey,
value = _ref.value;
map[stringKey] = (0, _Collection2.toJSON)(value);

@@ -246,10 +59,16 @@ return map;

value: function toString() {
var indent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var inFlow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var onComment = arguments.length > 2 ? arguments[2] : undefined;
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
doc = _ref2.doc,
_ref2$indent = _ref2.indent,
indent = _ref2$indent === void 0 ? '' : _ref2$indent,
_ref2$inFlow = _ref2.inFlow,
inFlow = _ref2$inFlow === void 0 ? false : _ref2$inFlow;
var onComment = arguments.length > 1 ? arguments[1] : undefined;
return _get(_getPrototypeOf(YAMLMap.prototype), "toString", this).call(this, {
blockItem: function blockItem(_ref5) {
var str = _ref5.str;
blockItem: function blockItem(_ref3) {
var str = _ref3.str;
return str;
},
doc: doc,
flowChars: {

@@ -256,0 +75,0 @@ start: '{',

@@ -47,27 +47,29 @@ "use strict";

key: "toString",
value: function toString(doc, options, onComment) {
if (!doc) return JSON.stringify(this);
value: function toString(ctx, onComment) {
if (!ctx || !ctx.doc) return JSON.stringify(this);
var key = this.key,
value = this.value;
var indent = options.indent;
var explicitKey = !key || key.comment || key instanceof _Collection.default;
var opt = Object.assign({}, options, {
var _ctx = ctx,
doc = _ctx.doc,
indent = _ctx.indent;
ctx = Object.assign({}, ctx, {
implicitKey: !explicitKey,
indent: options.indent + ' '
indent: indent + ' '
});
var keyComment = key && key.comment;
var keyStr = doc.schema.stringify(doc, key, opt, function () {
var keyStr = doc.schema.stringify(key, ctx, function () {
keyComment = null;
});
if (keyComment) keyStr = (0, _addComment.default)(keyStr, opt.indent, keyComment);
opt.implicitKey = false;
var valueStr = doc.schema.stringify(doc, value, opt, onComment);
var vcb = value && value.commentBefore ? " #".concat(value.commentBefore.replace(/\n+(?!\n|$)/g, "$&".concat(opt.indent, "#"))) : '';
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, "#"))) : '';
if (explicitKey) {
return "? ".concat(keyStr, "\n").concat(indent, ":").concat(vcb ? "".concat(vcb, "\n").concat(opt.indent) : ' ').concat(valueStr);
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(opt.indent).concat(valueStr);
return "".concat(keyStr, ":").concat(vcb, "\n").concat(ctx.indent).concat(valueStr);
} else {
return "".concat(keyStr, ":").concat(vcb ? "".concat(vcb, "\n").concat(opt.indent) : ' ').concat(valueStr);
return "".concat(keyStr, ":").concat(vcb ? "".concat(vcb, "\n").concat(ctx.indent) : ' ').concat(valueStr);
}

@@ -81,3 +83,4 @@ }

set: function set(cb) {
return this.key && this.key.commentBefore;
if (this.key == null) this.key = new _Scalar.default(null);
this.key.commentBefore = cb;
}

@@ -84,0 +87,0 @@ }, {

@@ -8,12 +8,4 @@ "use strict";

var _Node = require("../ast/Node");
var _errors = require("../errors");
var _Collection2 = _interopRequireWildcard(require("./Collection"));
var _Pair = _interopRequireDefault(require("./Pair"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

@@ -53,99 +45,2 @@

_createClass(YAMLSeq, [{
key: "parse",
value: function parse(ast) {
ast.resolved = this;
if (ast.type === _Node.Type.FLOW_SEQ) {
this.resolveFlowSeqItems(ast);
} else {
this.resolveBlockSeqItems(ast);
}
this.resolveComments();
return this;
}
}, {
key: "resolveBlockSeqItems",
value: function resolveBlockSeqItems(seq) {
for (var i = 0; i < seq.items.length; ++i) {
var item = seq.items[i];
switch (item.type) {
case _Node.Type.COMMENT:
this.addComment(item.comment);
break;
case _Node.Type.SEQ_ITEM:
if (item.error) this.doc.errors.push(item.error);
this.items.push(this.doc.resolveNode(item.node));
if (item.hasProps) this.doc.errors.push(new _errors.YAMLSemanticError(item, 'Sequence items cannot have tags or anchors before the - indicator'));
break;
default:
this.doc.errors.push(new _errors.YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence")));
}
}
}
}, {
key: "resolveFlowSeqItems",
value: function resolveFlowSeqItems(seq) {
var explicitKey = false;
var key = undefined;
var keyStart = null;
var next = '[';
for (var i = 0; i < seq.items.length; ++i) {
var item = seq.items[i];
if (typeof item === 'string') {
if (item !== ':' && (explicitKey || key !== undefined)) {
if (explicitKey && key === undefined) key = null;
this.items.push(new _Pair.default(key));
explicitKey = false;
key = undefined;
keyStart = null;
}
if (item === next) {
next = null;
} else if (!next && item === '?') {
explicitKey = true;
} else if (next !== '[' && item === ':' && key === undefined) {
if (next === ',') {
key = this.items.pop();
if (key instanceof _Pair.default) this.doc.errors.push(new _errors.YAMLSemanticError(item, 'Chaining flow sequence pairs is invalid (e.g. [ a : b : c ])'));
if (!explicitKey) _Collection2.default.checkKeyLength(this.doc, seq, i, key, keyStart);
} else {
key = null;
}
keyStart = null;
explicitKey = false; // TODO: add error for non-explicit multiline plain key
next = null;
} else if (next === '[' || item !== ']' || i < seq.items.length - 1) {
this.doc.errors.push(new _errors.YAMLSyntaxError(seq, "Flow sequence contains an unexpected ".concat(item)));
}
} else if (item.type === _Node.Type.COMMENT) {
this.addComment(item.comment);
} else {
if (next) this.doc.errors.push(new _errors.YAMLSemanticError(item, "Expected a ".concat(next, " here in flow sequence")));
var value = this.doc.resolveNode(item);
if (key === undefined) {
this.items.push(value);
} else {
this.items.push(new _Pair.default(key, value));
key = undefined;
}
keyStart = item.range.start;
next = ',';
}
}
if (seq.items[seq.items.length - 1] !== ']') this.doc.errors.push(new _errors.YAMLSemanticError(seq, 'Expected flow sequence to end with ]'));
if (key !== undefined) this.items.push(new _Pair.default(key));
}
}, {
key: "toJSON",

@@ -158,11 +53,17 @@ value: function toJSON() {

value: function toString() {
var indent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var inFlow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var onComment = arguments.length > 2 ? arguments[2] : undefined;
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
doc = _ref.doc,
_ref$indent = _ref.indent,
indent = _ref$indent === void 0 ? '' : _ref$indent,
_ref$inFlow = _ref.inFlow,
inFlow = _ref$inFlow === void 0 ? false : _ref$inFlow;
var onComment = arguments.length > 1 ? arguments[1] : undefined;
return _get(_getPrototypeOf(YAMLSeq.prototype), "toString", this).call(this, {
blockItem: function blockItem(_ref) {
var type = _ref.type,
str = _ref.str;
blockItem: function blockItem(_ref2) {
var type = _ref2.type,
str = _ref2.str;
return type === 'comment' ? str : "- ".concat(str);
},
doc: doc,
flowChars: {

@@ -169,0 +70,0 @@ start: '[',

{
"name": "yaml",
"version": "1.0.0-rc.2",
"version": "1.0.0-rc.3",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "license": "ISC",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc