node_modules: upgrade

This commit is contained in:
Dawid Dziurla
2024-01-17 10:08:10 +01:00
parent 9ff0bc8d99
commit 00765f79cf
320 changed files with 31840 additions and 1039 deletions

View File

@@ -3,30 +3,58 @@
var stringifyCollection = require('../stringify/stringifyCollection.js');
var addPairToJSMap = require('./addPairToJSMap.js');
var Collection = require('./Collection.js');
var Node = require('./Node.js');
var identity = require('./identity.js');
var Pair = require('./Pair.js');
var Scalar = require('./Scalar.js');
function findPair(items, key) {
const k = Node.isScalar(key) ? key.value : key;
const k = identity.isScalar(key) ? key.value : key;
for (const it of items) {
if (Node.isPair(it)) {
if (identity.isPair(it)) {
if (it.key === key || it.key === k)
return it;
if (Node.isScalar(it.key) && it.key.value === k)
if (identity.isScalar(it.key) && it.key.value === k)
return it;
}
}
return undefined;
}
class YAMLMap extends Collection.Collection {
constructor(schema) {
super(Node.MAP, schema);
this.items = [];
}
static get tagName() {
return 'tag:yaml.org,2002:map';
}
constructor(schema) {
super(identity.MAP, schema);
this.items = [];
}
/**
* A generic collection parsing method that can be extended
* to other node classes that inherit from YAMLMap
*/
static from(schema, obj, ctx) {
const { keepUndefined, replacer } = ctx;
const map = new this(schema);
const add = (key, value) => {
if (typeof replacer === 'function')
value = replacer.call(obj, key, value);
else if (Array.isArray(replacer) && !replacer.includes(key))
return;
if (value !== undefined || keepUndefined)
map.items.push(Pair.createPair(key, value, ctx));
};
if (obj instanceof Map) {
for (const [key, value] of obj)
add(key, value);
}
else if (obj && typeof obj === 'object') {
for (const key of Object.keys(obj))
add(key, obj[key]);
}
if (typeof schema.sortMapEntries === 'function') {
map.items.sort(schema.sortMapEntries);
}
return map;
}
/**
* Adds a value to the collection.
*
@@ -35,7 +63,7 @@ class YAMLMap extends Collection.Collection {
*/
add(pair, overwrite) {
let _pair;
if (Node.isPair(pair))
if (identity.isPair(pair))
_pair = pair;
else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
// In TypeScript, this never happens.
@@ -49,7 +77,7 @@ class YAMLMap extends Collection.Collection {
if (!overwrite)
throw new Error(`Key ${_pair.key} already set`);
// For scalars, keep the old node & its comments and anchors
if (Node.isScalar(prev.value) && Scalar.isScalarValue(_pair.value))
if (identity.isScalar(prev.value) && Scalar.isScalarValue(_pair.value))
prev.value.value = _pair.value;
else
prev.value = _pair.value;
@@ -75,7 +103,7 @@ class YAMLMap extends Collection.Collection {
get(key, keepScalar) {
const it = findPair(this.items, key);
const node = it?.value;
return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined;
return (!keepScalar && identity.isScalar(node) ? node.value : node) ?? undefined;
}
has(key) {
return !!findPair(this.items, key);
@@ -100,7 +128,7 @@ class YAMLMap extends Collection.Collection {
if (!ctx)
return JSON.stringify(this);
for (const item of this.items) {
if (!Node.isPair(item))
if (!identity.isPair(item))
throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
}
if (!ctx.allNullValues && this.hasAllNullValues(false))