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

@@ -1,6 +1,7 @@
import type { YAMLError, YAMLWarning } from '../errors.js';
import { Alias } from '../nodes/Alias.js';
import { Node, NodeType, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
import { NODE_TYPE } from '../nodes/identity.js';
import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node.js';
import { Pair } from '../nodes/Pair.js';
import type { Scalar } from '../nodes/Scalar.js';
import type { YAMLMap } from '../nodes/YAMLMap.js';
@@ -8,22 +9,23 @@ import type { YAMLSeq } from '../nodes/YAMLSeq.js';
import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
import { Schema } from '../schema/Schema.js';
import { Directives } from './directives.js';
export declare type Replacer = any[] | ((key: any, value: any) => unknown);
export type Replacer = any[] | ((key: any, value: any) => unknown);
export declare namespace Document {
interface Parsed<T extends ParsedNode = ParsedNode> extends Document<T> {
/** @ts-ignore The typing of directives fails in TS <= 4.2 */
interface Parsed<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true> extends Document<Contents, Strict> {
directives: Directives;
range: Range;
}
}
export declare class Document<T extends Node = Node> {
export declare class Document<Contents extends Node = Node, Strict extends boolean = true> {
readonly [NODE_TYPE]: symbol;
/** A comment before this Document */
commentBefore: string | null;
/** A comment immediately after this Document */
comment: string | null;
/** The document contents. */
contents: T | null;
directives?: Directives;
contents: Strict extends true ? Contents | null : Contents;
directives: Strict extends true ? Directives | undefined : Directives;
/** Errors encountered during parsing. */
errors: YAMLError[];
options: Required<Omit<ParseOptions & DocumentOptions, '_directives' | 'lineCounter' | 'version'>>;
@@ -49,7 +51,7 @@ export declare class Document<T extends Node = Node> {
*
* Custom Node values that inherit from `Object` still refer to their original instances.
*/
clone(): Document<T>;
clone(): Document<Contents, Strict>;
/** Adds a value to the document. */
add(value: any): void;
/** Adds a value to the document. */
@@ -63,7 +65,7 @@ export declare class Document<T extends Node = Node> {
* `name` will be used as a prefix for a new unique anchor.
* If `name` is undefined, the generated anchor will use 'a' as a prefix.
*/
createAlias(node: Scalar | YAMLMap | YAMLSeq, name?: string): Alias;
createAlias(node: Strict extends true ? Scalar | YAMLMap | YAMLSeq : Node, name?: string): Alias;
/**
* Convert any value into a `Node` using the current schema, recursively
* turning objects into collections.
@@ -90,13 +92,13 @@ export declare class Document<T extends Node = Node> {
* scalar values from their surrounding node; to disable set `keepScalar` to
* `true` (collections are always returned intact).
*/
get(key: unknown, keepScalar?: boolean): unknown;
get(key: unknown, keepScalar?: boolean): Strict extends true ? unknown : any;
/**
* Returns item at `path`, or `undefined` if not found. By default unwraps
* scalar values from their surrounding node; to disable set `keepScalar` to
* `true` (collections are always returned intact).
*/
getIn(path: Iterable<unknown> | null, keepScalar?: boolean): unknown;
getIn(path: Iterable<unknown> | null, keepScalar?: boolean): Strict extends true ? unknown : any;
/**
* Checks if the document includes a value with the key `key`.
*/

View File

@@ -2,11 +2,10 @@
var Alias = require('../nodes/Alias.js');
var Collection = require('../nodes/Collection.js');
var Node = require('../nodes/Node.js');
var identity = require('../nodes/identity.js');
var Pair = require('../nodes/Pair.js');
var toJS = require('../nodes/toJS.js');
var Schema = require('../schema/Schema.js');
var stringify = require('../stringify/stringify.js');
var stringifyDocument = require('../stringify/stringifyDocument.js');
var anchors = require('./anchors.js');
var applyReviver = require('./applyReviver.js');
@@ -23,7 +22,7 @@ class Document {
this.errors = [];
/** Warnings encountered during parsing. */
this.warnings = [];
Object.defineProperty(this, Node.NODE_TYPE, { value: Node.DOC });
Object.defineProperty(this, identity.NODE_TYPE, { value: identity.DOC });
let _replacer = null;
if (typeof replacer === 'function' || Array.isArray(replacer)) {
_replacer = replacer;
@@ -51,11 +50,9 @@ class Document {
else
this.directives = new directives.Directives({ version });
this.setSchema(version, options);
if (value === undefined)
this.contents = null;
else {
this.contents = this.createNode(value, _replacer, options);
}
// @ts-expect-error We can't really know that this matches Contents.
this.contents =
value === undefined ? null : this.createNode(value, _replacer, options);
}
/**
* Create a deep copy of this Document and its contents.
@@ -64,7 +61,7 @@ class Document {
*/
clone() {
const copy = Object.create(Document.prototype, {
[Node.NODE_TYPE]: { value: Node.DOC }
[identity.NODE_TYPE]: { value: identity.DOC }
});
copy.commentBefore = this.commentBefore;
copy.comment = this.comment;
@@ -74,7 +71,8 @@ class Document {
if (this.directives)
copy.directives = this.directives.clone();
copy.schema = this.schema.clone();
copy.contents = Node.isNode(this.contents)
// @ts-expect-error We can't really know that this matches Contents.
copy.contents = identity.isNode(this.contents)
? this.contents.clone(copy.schema)
: this.contents;
if (this.range)
@@ -140,7 +138,7 @@ class Document {
sourceObjects
};
const node = createNode.createNode(value, tag, ctx);
if (flow && Node.isCollection(node))
if (flow && identity.isCollection(node))
node.flow = true;
setAnchors();
return node;
@@ -169,6 +167,7 @@ class Document {
if (Collection.isEmptyPath(path)) {
if (this.contents == null)
return false;
// @ts-expect-error Presumed impossible if Strict extends false
this.contents = null;
return true;
}
@@ -182,7 +181,7 @@ class Document {
* `true` (collections are always returned intact).
*/
get(key, keepScalar) {
return Node.isCollection(this.contents)
return identity.isCollection(this.contents)
? this.contents.get(key, keepScalar)
: undefined;
}
@@ -193,10 +192,10 @@ class Document {
*/
getIn(path, keepScalar) {
if (Collection.isEmptyPath(path))
return !keepScalar && Node.isScalar(this.contents)
return !keepScalar && identity.isScalar(this.contents)
? this.contents.value
: this.contents;
return Node.isCollection(this.contents)
return identity.isCollection(this.contents)
? this.contents.getIn(path, keepScalar)
: undefined;
}
@@ -204,7 +203,7 @@ class Document {
* Checks if the document includes a value with the key `key`.
*/
has(key) {
return Node.isCollection(this.contents) ? this.contents.has(key) : false;
return identity.isCollection(this.contents) ? this.contents.has(key) : false;
}
/**
* Checks if the document includes a value at `path`.
@@ -212,7 +211,7 @@ class Document {
hasIn(path) {
if (Collection.isEmptyPath(path))
return this.contents !== undefined;
return Node.isCollection(this.contents) ? this.contents.hasIn(path) : false;
return identity.isCollection(this.contents) ? this.contents.hasIn(path) : false;
}
/**
* Sets a value in this document. For `!!set`, `value` needs to be a
@@ -220,6 +219,7 @@ class Document {
*/
set(key, value) {
if (this.contents == null) {
// @ts-expect-error We can't really know that this matches Contents.
this.contents = Collection.collectionFromPath(this.schema, [key], value);
}
else if (assertCollection(this.contents)) {
@@ -231,9 +231,12 @@ class Document {
* boolean to add/remove the item from the set.
*/
setIn(path, value) {
if (Collection.isEmptyPath(path))
if (Collection.isEmptyPath(path)) {
// @ts-expect-error We can't really know that this matches Contents.
this.contents = value;
}
else if (this.contents == null) {
// @ts-expect-error We can't really know that this matches Contents.
this.contents = Collection.collectionFromPath(this.schema, Array.from(path), value);
}
else if (assertCollection(this.contents)) {
@@ -293,8 +296,7 @@ class Document {
keep: !json,
mapAsMap: mapAsMap === true,
mapKeyWarned: false,
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100,
stringify: stringify.stringify
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
};
const res = toJS.toJS(this.contents, jsonArg ?? '', ctx);
if (typeof onAnchor === 'function')
@@ -326,7 +328,7 @@ class Document {
}
}
function assertCollection(contents) {
if (Node.isCollection(contents))
if (identity.isCollection(contents))
return true;
throw new Error('Expected a YAML collection as document contents');
}

View File

@@ -1,4 +1,4 @@
import { Node } from '../nodes/Node.js';
import type { Node } from '../nodes/Node.js';
import type { Document } from './Document.js';
/**
* Verify that the input string is a valid anchor.
@@ -6,10 +6,10 @@ import type { Document } from './Document.js';
* Will throw on errors.
*/
export declare function anchorIsValid(anchor: string): true;
export declare function anchorNames(root: Document | Node): Set<string>;
export declare function anchorNames(root: Document<Node, boolean> | Node): Set<string>;
/** Find a new anchor name with the given `prefix` and a one-indexed suffix. */
export declare function findNewAnchor(prefix: string, exclude: Set<string>): string;
export declare function createNodeAnchors(doc: Document, prefix: string): {
export declare function createNodeAnchors(doc: Document<Node, boolean>, prefix: string): {
onAnchor: (source: unknown) => string;
/**
* With circular references, the source node is only resolved after all
@@ -19,6 +19,6 @@ export declare function createNodeAnchors(doc: Document, prefix: string): {
setAnchors: () => void;
sourceObjects: Map<unknown, {
anchor: string | null;
node: Node<unknown> | null;
node: Node | null;
}>;
};

View File

@@ -1,6 +1,6 @@
'use strict';
var Node = require('../nodes/Node.js');
var identity = require('../nodes/identity.js');
var visit = require('../visit.js');
/**
@@ -57,7 +57,7 @@ function createNodeAnchors(doc, prefix) {
const ref = sourceObjects.get(source);
if (typeof ref === 'object' &&
ref.anchor &&
(Node.isScalar(ref.node) || Node.isCollection(ref.node))) {
(identity.isScalar(ref.node) || identity.isCollection(ref.node))) {
ref.node.anchor = ref.anchor;
}
else {

View File

@@ -1,4 +1,4 @@
export declare type Reviver = (key: unknown, value: unknown) => unknown;
export type Reviver = (key: unknown, value: unknown) => unknown;
/**
* Applies the JSON.parse reviver algorithm as defined in the ECMA-262 spec,
* in section 24.5.1.1 "Runtime Semantics: InternalizeJSONProperty" of the

View File

@@ -1,4 +1,4 @@
import { Node } from '../nodes/Node.js';
import type { Node } from '../nodes/Node.js';
import type { Schema } from '../schema/Schema.js';
import type { CollectionTag, ScalarTag } from '../schema/types.js';
import type { Replacer } from './Document.js';

View File

@@ -1,7 +1,7 @@
'use strict';
var Alias = require('../nodes/Alias.js');
var Node = require('../nodes/Node.js');
var identity = require('../nodes/identity.js');
var Scalar = require('../nodes/Scalar.js');
const defaultTagPrefix = 'tag:yaml.org,2002:';
@@ -16,12 +16,12 @@ function findTagObject(value, tagName, tags) {
return tags.find(t => t.identify?.(value) && !t.format);
}
function createNode(value, tagName, ctx) {
if (Node.isDocument(value))
if (identity.isDocument(value))
value = value.contents;
if (Node.isNode(value))
if (identity.isNode(value))
return value;
if (Node.isPair(value)) {
const map = ctx.schema[Node.MAP].createNode?.(ctx.schema, null, ctx);
if (identity.isPair(value)) {
const map = ctx.schema[identity.MAP].createNode?.(ctx.schema, null, ctx);
map.items.push(value);
return map;
}
@@ -65,10 +65,10 @@ function createNode(value, tagName, ctx) {
}
tagObj =
value instanceof Map
? schema[Node.MAP]
? schema[identity.MAP]
: Symbol.iterator in Object(value)
? schema[Node.SEQ]
: schema[Node.MAP];
? schema[identity.SEQ]
: schema[identity.MAP];
}
if (onTagObj) {
onTagObj(tagObj);
@@ -76,9 +76,13 @@ function createNode(value, tagName, ctx) {
}
const node = tagObj?.createNode
? tagObj.createNode(ctx.schema, value, ctx)
: new Scalar.Scalar(value);
: typeof tagObj?.nodeClass?.from === 'function'
? tagObj.nodeClass.from(ctx.schema, value, ctx)
: new Scalar.Scalar(value);
if (tagName)
node.tag = tagName;
else if (!tagObj.default)
node.tag = tagObj.tag;
if (ref)
ref.node = node;
return node;

View File

@@ -1,6 +1,6 @@
'use strict';
var Node = require('../nodes/Node.js');
var identity = require('../nodes/identity.js');
var visit = require('../visit.js');
const escapeChars = {
@@ -118,12 +118,19 @@ class Directives {
onError('Verbatim tags must end with a >');
return verbatim;
}
const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/);
const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/s);
if (!suffix)
onError(`The ${source} tag has no suffix`);
const prefix = this.tags[handle];
if (prefix)
return prefix + decodeURIComponent(suffix);
if (prefix) {
try {
return prefix + decodeURIComponent(suffix);
}
catch (error) {
onError(String(error));
return null;
}
}
if (handle === '!')
return source; // local tag
onError(`Could not resolve tag: ${source}`);
@@ -146,10 +153,10 @@ class Directives {
: [];
const tagEntries = Object.entries(this.tags);
let tagNames;
if (doc && tagEntries.length > 0 && Node.isNode(doc.contents)) {
if (doc && tagEntries.length > 0 && identity.isNode(doc.contents)) {
const tags = {};
visit.visit(doc.contents, (_key, node) => {
if (Node.isNode(node) && node.tag)
if (identity.isNode(node) && node.tag)
tags[node.tag] = true;
});
tagNames = Object.keys(tags);