node_modules: upgrade

This commit is contained in:
Dawid Dziurla
2025-06-14 23:18:18 +02:00
parent 948e4a4fb8
commit de40b1f21f
268 changed files with 2150 additions and 3858 deletions

8
node_modules/yaml/dist/cli.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
export declare const help = "yaml: A command-line YAML processor and inspector\n\nReads stdin and writes output to stdout and errors & warnings to stderr.\n\nUsage:\n yaml Process a YAML stream, outputting it as YAML\n yaml cst Parse the CST of a YAML stream\n yaml lex Parse the lexical tokens of a YAML stream\n yaml valid Validate a YAML stream, returning 0 on success\n\nOptions:\n --help, -h Show this message.\n --json, -j Output JSON.\n --indent 2 Output pretty-printed data, indented by the given number of spaces.\n --merge, -m Enable support for \"<<\" merge keys.\n\nAdditional options for bare \"yaml\" command:\n --doc, -d Output pretty-printed JS Document objects.\n --single, -1 Require the input to consist of a single YAML document.\n --strict, -s Stop on errors.\n --visit, -v Apply a visitor to each document (requires a path to import)\n --yaml 1.1 Set the YAML version. (default: 1.2)";
export declare class UserError extends Error {
static ARGS: number;
static SINGLE: number;
code: number;
constructor(code: number, message: string);
}
export declare function cli(stdin: NodeJS.ReadableStream, done: (error?: Error) => void, argv?: string[]): Promise<void>;

201
node_modules/yaml/dist/cli.mjs generated vendored Normal file
View File

@@ -0,0 +1,201 @@
import { resolve } from 'path';
import { parseArgs } from 'util';
import { prettyToken } from './parse/cst.js';
import { Lexer } from './parse/lexer.js';
import { Parser } from './parse/parser.js';
import { Composer } from './compose/composer.js';
import { LineCounter } from './parse/line-counter.js';
import { prettifyError } from './errors.js';
import { visit } from './visit.js';
const help = `\
yaml: A command-line YAML processor and inspector
Reads stdin and writes output to stdout and errors & warnings to stderr.
Usage:
yaml Process a YAML stream, outputting it as YAML
yaml cst Parse the CST of a YAML stream
yaml lex Parse the lexical tokens of a YAML stream
yaml valid Validate a YAML stream, returning 0 on success
Options:
--help, -h Show this message.
--json, -j Output JSON.
--indent 2 Output pretty-printed data, indented by the given number of spaces.
--merge, -m Enable support for "<<" merge keys.
Additional options for bare "yaml" command:
--doc, -d Output pretty-printed JS Document objects.
--single, -1 Require the input to consist of a single YAML document.
--strict, -s Stop on errors.
--visit, -v Apply a visitor to each document (requires a path to import)
--yaml 1.1 Set the YAML version. (default: 1.2)`;
class UserError extends Error {
constructor(code, message) {
super(`Error: ${message}`);
this.code = code;
}
}
UserError.ARGS = 2;
UserError.SINGLE = 3;
async function cli(stdin, done, argv) {
let args;
try {
args = parseArgs({
args: argv,
allowPositionals: true,
options: {
doc: { type: 'boolean', short: 'd' },
help: { type: 'boolean', short: 'h' },
indent: { type: 'string', short: 'i' },
merge: { type: 'boolean', short: 'm' },
json: { type: 'boolean', short: 'j' },
single: { type: 'boolean', short: '1' },
strict: { type: 'boolean', short: 's' },
visit: { type: 'string', short: 'v' },
yaml: { type: 'string', default: '1.2' }
}
});
}
catch (error) {
return done(new UserError(UserError.ARGS, error.message));
}
const { positionals: [mode], values: opt } = args;
let indent = Number(opt.indent);
stdin.setEncoding('utf-8');
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
switch (opt.help || mode) {
/* istanbul ignore next */
case true: // --help
console.log(help);
break;
case 'lex': {
const lexer = new Lexer();
const data = [];
const add = (tok) => {
if (opt.json)
data.push(tok);
else
console.log(prettyToken(tok));
};
stdin.on('data', (chunk) => {
for (const tok of lexer.lex(chunk, true))
add(tok);
});
stdin.on('end', () => {
for (const tok of lexer.lex('', false))
add(tok);
if (opt.json)
console.log(JSON.stringify(data, null, indent));
done();
});
break;
}
case 'cst': {
const parser = new Parser();
const data = [];
const add = (tok) => {
if (opt.json)
data.push(tok);
else
console.dir(tok, { depth: null });
};
stdin.on('data', (chunk) => {
for (const tok of parser.parse(chunk, true))
add(tok);
});
stdin.on('end', () => {
for (const tok of parser.parse('', false))
add(tok);
if (opt.json)
console.log(JSON.stringify(data, null, indent));
done();
});
break;
}
case undefined:
case 'valid': {
const lineCounter = new LineCounter();
const parser = new Parser(lineCounter.addNewLine);
// @ts-expect-error Version is validated at runtime
const composer = new Composer({ version: opt.yaml, merge: opt.merge });
const visitor = opt.visit
? (await import(resolve(opt.visit))).default
: null;
let source = '';
let hasDoc = false;
let reqDocEnd = false;
const data = [];
const add = (doc) => {
if (hasDoc && opt.single) {
return done(new UserError(UserError.SINGLE, 'Input stream contains multiple documents'));
}
for (const error of doc.errors) {
prettifyError(source, lineCounter)(error);
if (opt.strict || mode === 'valid')
return done(error);
console.error(error);
}
for (const warning of doc.warnings) {
prettifyError(source, lineCounter)(warning);
console.error(warning);
}
if (visitor)
visit(doc, visitor);
if (mode === 'valid')
doc.toJS();
else if (opt.json)
data.push(doc);
else if (opt.doc) {
Object.defineProperties(doc, {
options: { enumerable: false },
schema: { enumerable: false }
});
console.dir(doc, { depth: null });
}
else {
if (reqDocEnd)
console.log('...');
try {
indent || (indent = 2);
const str = doc.toString({ indent });
console.log(str.endsWith('\n') ? str.slice(0, -1) : str);
}
catch (error) {
done(error);
}
}
hasDoc = true;
reqDocEnd = !doc.directives?.docEnd;
};
stdin.on('data', (chunk) => {
source += chunk;
for (const tok of parser.parse(chunk, true)) {
for (const doc of composer.next(tok))
add(doc);
}
});
stdin.on('end', () => {
for (const tok of parser.parse('', false)) {
for (const doc of composer.next(tok))
add(doc);
}
for (const doc of composer.end(false))
add(doc);
if (opt.single && !hasDoc) {
return done(new UserError(UserError.SINGLE, 'Input stream contained no documents'));
}
if (mode !== 'valid' && opt.json) {
console.log(JSON.stringify(opt.single ? data[0] : data, null, indent));
}
done();
});
break;
}
default:
done(new UserError(UserError.ARGS, `Unknown command: ${JSON.stringify(mode)}`));
}
}
export { UserError, cli, help };

View File

@@ -1,5 +1,11 @@
import type { ParsedNode } from '../nodes/Node.js';
import type { BlockMap, BlockSequence, FlowCollection, SourceToken } from '../parse/cst.js';
import type { ComposeContext, ComposeNode } from './compose-node.js';
import type { ComposeErrorHandler } from './composer.js';
export declare function composeCollection(CN: ComposeNode, ctx: ComposeContext, token: BlockMap | BlockSequence | FlowCollection, tagToken: SourceToken | null, onError: ComposeErrorHandler): ParsedNode;
import type { ParsedNode } from '../nodes/Node';
import type { BlockMap, BlockSequence, FlowCollection, SourceToken } from '../parse/cst';
import type { ComposeContext, ComposeNode } from './compose-node';
import type { ComposeErrorHandler } from './composer';
interface Props {
anchor: SourceToken | null;
tag: SourceToken | null;
newlineAfterProp: SourceToken | null;
}
export declare function composeCollection(CN: ComposeNode, ctx: ComposeContext, token: BlockMap | BlockSequence | FlowCollection, props: Props, onError: ComposeErrorHandler): ParsedNode;
export {};

View File

@@ -25,10 +25,23 @@ function resolveCollection(CN, ctx, token, onError, tagName, tag) {
coll.tag = tagName;
return coll;
}
function composeCollection(CN, ctx, token, tagToken, onError) {
function composeCollection(CN, ctx, token, props, onError) {
const tagToken = props.tag;
const tagName = !tagToken
? null
: ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg));
if (token.type === 'block-seq') {
const { anchor, newlineAfterProp: nl } = props;
const lastProp = anchor && tagToken
? anchor.offset > tagToken.offset
? anchor
: tagToken
: (anchor ?? tagToken);
if (lastProp && (!nl || nl.offset < lastProp.offset)) {
const message = 'Missing newline after block sequence props';
onError(lastProp, 'MISSING_CHAR', message);
}
}
const expType = token.type === 'block-map'
? 'map'
: token.type === 'block-seq'
@@ -42,8 +55,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
!tagName ||
tagName === '!' ||
(tagName === YAMLMap.YAMLMap.tagName && expType === 'map') ||
(tagName === YAMLSeq.YAMLSeq.tagName && expType === 'seq') ||
!expType) {
(tagName === YAMLSeq.YAMLSeq.tagName && expType === 'seq')) {
return resolveCollection(CN, ctx, token, onError, tagName);
}
let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
@@ -54,8 +66,8 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
tag = kt;
}
else {
if (kt?.collection) {
onError(tagToken, 'BAD_COLLECTION_TYPE', `${kt.tag} used for ${expType} collection, but expects ${kt.collection}`, true);
if (kt) {
onError(tagToken, 'BAD_COLLECTION_TYPE', `${kt.tag} used for ${expType} collection, but expects ${kt.collection ?? 'scalar'}`, true);
}
else {
onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true);

View File

@@ -1,7 +1,7 @@
import type { Directives } from '../doc/directives.js';
import { Document } from '../doc/Document.js';
import type { ParsedNode } from '../nodes/Node.js';
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
import type * as CST from '../parse/cst.js';
import type { ComposeErrorHandler } from './composer.js';
import type { Directives } from '../doc/directives';
import { Document } from '../doc/Document';
import type { ParsedNode } from '../nodes/Node';
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options';
import type * as CST from '../parse/cst';
import type { ComposeErrorHandler } from './composer';
export declare function composeDoc<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true>(options: ParseOptions & DocumentOptions & SchemaOptions, directives: Directives, { offset, start, value, end }: CST.Document, onError: ComposeErrorHandler): Document.Parsed<Contents, Strict>;

View File

@@ -9,6 +9,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
const opts = Object.assign({ _directives: directives }, options);
const doc = new Document.Document(undefined, opts);
const ctx = {
atKey: false,
atRoot: true,
directives: doc.directives,
options: doc.options,
@@ -19,6 +20,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
next: value ?? end?.[0],
offset,
onError,
parentIndent: 0,
startOnNewline: true
});
if (props.found) {

View File

@@ -1,10 +1,11 @@
import type { Directives } from '../doc/directives.js';
import type { ParsedNode } from '../nodes/Node.js';
import type { ParseOptions } from '../options.js';
import type { SourceToken, Token } from '../parse/cst.js';
import type { Schema } from '../schema/Schema.js';
import type { ComposeErrorHandler } from './composer.js';
import type { Directives } from '../doc/directives';
import type { ParsedNode } from '../nodes/Node';
import type { ParseOptions } from '../options';
import type { SourceToken, Token } from '../parse/cst';
import type { Schema } from '../schema/Schema';
import type { ComposeErrorHandler } from './composer';
export interface ComposeContext {
atKey: boolean;
atRoot: boolean;
directives: Directives;
options: Readonly<Required<Omit<ParseOptions, 'lineCounter'>>>;
@@ -15,6 +16,7 @@ interface Props {
comment: string;
anchor: SourceToken | null;
tag: SourceToken | null;
newlineAfterProp: SourceToken | null;
end: number;
}
declare const CN: {
@@ -23,5 +25,5 @@ declare const CN: {
};
export type ComposeNode = typeof CN;
export declare function composeNode(ctx: ComposeContext, token: Token, props: Props, onError: ComposeErrorHandler): ParsedNode;
export declare function composeEmptyNode(ctx: ComposeContext, offset: number, before: Token[] | undefined, pos: number | null, { spaceBefore, comment, anchor, tag, end }: Props, onError: ComposeErrorHandler): import("../index.js").Scalar.Parsed;
export declare function composeEmptyNode(ctx: ComposeContext, offset: number, before: Token[] | undefined, pos: number | null, { spaceBefore, comment, anchor, tag, end }: Props, onError: ComposeErrorHandler): import('../index').Scalar.Parsed;
export {};

View File

@@ -1,6 +1,7 @@
'use strict';
var Alias = require('../nodes/Alias.js');
var identity = require('../nodes/identity.js');
var composeCollection = require('./compose-collection.js');
var composeScalar = require('./compose-scalar.js');
var resolveEnd = require('./resolve-end.js');
@@ -8,6 +9,7 @@ var utilEmptyScalarPosition = require('./util-empty-scalar-position.js');
const CN = { composeNode, composeEmptyNode };
function composeNode(ctx, token, props, onError) {
const atKey = ctx.atKey;
const { spaceBefore, comment, anchor, tag } = props;
let node;
let isSrcToken = true;
@@ -28,7 +30,7 @@ function composeNode(ctx, token, props, onError) {
case 'block-map':
case 'block-seq':
case 'flow-collection':
node = composeCollection.composeCollection(CN, ctx, token, tag, onError);
node = composeCollection.composeCollection(CN, ctx, token, props, onError);
if (anchor)
node.anchor = anchor.source.substring(1);
break;
@@ -43,6 +45,14 @@ function composeNode(ctx, token, props, onError) {
}
if (anchor && node.anchor === '')
onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
if (atKey &&
ctx.options.stringKeys &&
(!identity.isScalar(node) ||
typeof node.value !== 'string' ||
(node.tag && node.tag !== 'tag:yaml.org,2002:str'))) {
const msg = 'With stringKeys, all keys must be strings';
onError(tag ?? token, 'NON_STRING_KEY', msg);
}
if (spaceBefore)
node.spaceBefore = true;
if (comment) {

View File

@@ -1,5 +1,5 @@
import { Scalar } from '../nodes/Scalar.js';
import type { BlockScalar, FlowScalar, SourceToken } from '../parse/cst.js';
import type { ComposeContext } from './compose-node.js';
import type { ComposeErrorHandler } from './composer.js';
import { Scalar } from '../nodes/Scalar';
import type { BlockScalar, FlowScalar, SourceToken } from '../parse/cst';
import type { ComposeContext } from './compose-node';
import type { ComposeErrorHandler } from './composer';
export declare function composeScalar(ctx: ComposeContext, token: FlowScalar | BlockScalar, tagToken: SourceToken | null, onError: ComposeErrorHandler): Scalar.Parsed;

View File

@@ -7,16 +7,21 @@ var resolveFlowScalar = require('./resolve-flow-scalar.js');
function composeScalar(ctx, token, tagToken, onError) {
const { value, type, comment, range } = token.type === 'block-scalar'
? resolveBlockScalar.resolveBlockScalar(token, ctx.options.strict, onError)
? resolveBlockScalar.resolveBlockScalar(ctx, token, onError)
: resolveFlowScalar.resolveFlowScalar(token, ctx.options.strict, onError);
const tagName = tagToken
? ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg))
: null;
const tag = tagToken && tagName
? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError)
: token.type === 'scalar'
? findScalarTagByTest(ctx, value, token, onError)
: ctx.schema[identity.SCALAR];
let tag;
if (ctx.options.stringKeys && ctx.atKey) {
tag = ctx.schema[identity.SCALAR];
}
else if (tagName)
tag = findScalarTagByName(ctx.schema, value, tagName, tagToken, onError);
else if (token.type === 'scalar')
tag = findScalarTagByTest(ctx, value, token, onError);
else
tag = ctx.schema[identity.SCALAR];
let scalar;
try {
const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
@@ -64,8 +69,9 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str');
return schema[identity.SCALAR];
}
function findScalarTagByTest({ directives, schema }, value, token, onError) {
const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[identity.SCALAR];
function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
const tag = schema.tags.find(tag => (tag.default === true || (atKey && tag.default === 'key')) &&
tag.test?.test(value)) || schema[identity.SCALAR];
if (schema.compat) {
const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
schema[identity.SCALAR];

View File

@@ -1,9 +1,10 @@
import { Directives } from '../doc/directives.js';
import { Document } from '../doc/Document.js';
import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js';
import type { ParsedNode, Range } from '../nodes/Node.js';
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
import type { Token } from '../parse/cst.js';
import { Directives } from '../doc/directives';
import { Document } from '../doc/Document';
import type { ErrorCode } from '../errors';
import { YAMLParseError, YAMLWarning } from '../errors';
import type { ParsedNode, Range } from '../nodes/Node';
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options';
import type { Token } from '../parse/cst';
type ErrorSource = number | [number, number] | Range | {
offset: number;
source?: string;

View File

@@ -1,5 +1,6 @@
'use strict';
var node_process = require('process');
var directives = require('../doc/directives.js');
var Document = require('../doc/Document.js');
var errors = require('../errors.js');
@@ -133,7 +134,7 @@ class Composer {
}
/** Advance the composer by one CST token. */
*next(token) {
if (process.env.LOG_STREAM)
if (node_process.env.LOG_STREAM)
console.dir(token, { depth: null });
switch (token.type) {
case 'directive':

View File

@@ -1,7 +1,6 @@
import type { ParsedNode } from '../nodes/Node.js';
import { YAMLMap } from '../nodes/YAMLMap.js';
import type { BlockMap } from '../parse/cst.js';
import { CollectionTag } from '../schema/types.js';
import type { ComposeContext, ComposeNode } from './compose-node.js';
import type { ComposeErrorHandler } from './composer.js';
export declare function resolveBlockMap({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bm: BlockMap, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLMap.Parsed<ParsedNode, ParsedNode | null>;
import { YAMLMap } from '../nodes/YAMLMap';
import type { BlockMap } from '../parse/cst';
import type { CollectionTag } from '../schema/types';
import type { ComposeContext, ComposeNode } from './compose-node';
import type { ComposeErrorHandler } from './composer';
export declare function resolveBlockMap({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bm: BlockMap, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLMap.Parsed;

View File

@@ -23,6 +23,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
next: key ?? sep?.[0],
offset,
onError,
parentIndent: bm.indent,
startOnNewline: true
});
const implicitKey = !keyProps.found;
@@ -43,7 +44,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
}
continue;
}
if (keyProps.hasNewlineAfterProp || utilContainsNewline.containsNewline(key)) {
if (keyProps.newlineAfterProp || utilContainsNewline.containsNewline(key)) {
onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
}
}
@@ -51,12 +52,14 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
onError(offset, 'BAD_INDENT', startColMsg);
}
// key value
ctx.atKey = true;
const keyStart = keyProps.end;
const keyNode = key
? composeNode(ctx, key, keyProps, onError)
: composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
if (ctx.schema.compat)
utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
ctx.atKey = false;
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
// value properties
@@ -65,6 +68,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
next: value,
offset: keyNode.range[2],
onError,
parentIndent: bm.indent,
startOnNewline: !key || key.type === 'block-scalar'
});
offset = valueProps.end;

View File

@@ -1,8 +1,9 @@
import { Range } from '../nodes/Node.js';
import { Scalar } from '../nodes/Scalar.js';
import type { BlockScalar } from '../parse/cst.js';
import type { ComposeErrorHandler } from './composer.js';
export declare function resolveBlockScalar(scalar: BlockScalar, strict: boolean, onError: ComposeErrorHandler): {
import type { Range } from '../nodes/Node';
import { Scalar } from '../nodes/Scalar';
import type { BlockScalar } from '../parse/cst';
import type { ComposeContext } from './compose-node';
import type { ComposeErrorHandler } from './composer';
export declare function resolveBlockScalar(ctx: ComposeContext, scalar: BlockScalar, onError: ComposeErrorHandler): {
value: string;
type: Scalar.BLOCK_FOLDED | Scalar.BLOCK_LITERAL | null;
comment: string;

View File

@@ -2,9 +2,9 @@
var Scalar = require('../nodes/Scalar.js');
function resolveBlockScalar(scalar, strict, onError) {
function resolveBlockScalar(ctx, scalar, onError) {
const start = scalar.offset;
const header = parseBlockScalarHeader(scalar, strict, onError);
const header = parseBlockScalarHeader(scalar, ctx.options.strict, onError);
if (!header)
return { value: '', type: null, comment: '', range: [start, start, start] };
const type = header.mode === '>' ? Scalar.Scalar.BLOCK_FOLDED : Scalar.Scalar.BLOCK_LITERAL;
@@ -46,6 +46,10 @@ function resolveBlockScalar(scalar, strict, onError) {
if (header.indent === 0)
trimIndent = indent.length;
contentStart = i;
if (trimIndent === 0 && !ctx.atRoot) {
const message = 'Block scalar values in collections must be indented';
onError(offset, 'BAD_INDENT', message);
}
break;
}
offset += indent.length + content.length + 1;

View File

@@ -1,6 +1,6 @@
import { YAMLSeq } from '../nodes/YAMLSeq.js';
import type { BlockSequence } from '../parse/cst.js';
import { CollectionTag } from '../schema/types.js';
import type { ComposeContext, ComposeNode } from './compose-node.js';
import type { ComposeErrorHandler } from './composer.js';
export declare function resolveBlockSeq({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bs: BlockSequence, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLSeq.Parsed<import("../index.js").ParsedNode>;
import { YAMLSeq } from '../nodes/YAMLSeq';
import type { BlockSequence } from '../parse/cst';
import type { CollectionTag } from '../schema/types';
import type { ComposeContext, ComposeNode } from './compose-node';
import type { ComposeErrorHandler } from './composer';
export declare function resolveBlockSeq({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bs: BlockSequence, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLSeq.Parsed;

View File

@@ -9,6 +9,8 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta
const seq = new NodeClass(ctx.schema);
if (ctx.atRoot)
ctx.atRoot = false;
if (ctx.atKey)
ctx.atKey = false;
let offset = bs.offset;
let commentEnd = null;
for (const { start, value } of bs.items) {
@@ -17,6 +19,7 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta
next: value,
offset,
onError,
parentIndent: bs.indent,
startOnNewline: true
});
if (!props.found) {

View File

@@ -1,5 +1,5 @@
import type { SourceToken } from '../parse/cst.js';
import type { ComposeErrorHandler } from './composer.js';
import type { SourceToken } from '../parse/cst';
import type { ComposeErrorHandler } from './composer';
export declare function resolveEnd(end: SourceToken[] | undefined, offset: number, reqSpace: boolean, onError: ComposeErrorHandler): {
comment: string;
offset: number;

View File

@@ -1,7 +1,7 @@
import { YAMLMap } from '../nodes/YAMLMap.js';
import { YAMLSeq } from '../nodes/YAMLSeq.js';
import type { FlowCollection } from '../parse/cst.js';
import { CollectionTag } from '../schema/types.js';
import type { ComposeContext, ComposeNode } from './compose-node.js';
import type { ComposeErrorHandler } from './composer.js';
export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLMap.Parsed<import("../index.js").ParsedNode, import("../index.js").ParsedNode | null> | YAMLSeq.Parsed<import("../index.js").ParsedNode>;
import { YAMLMap } from '../nodes/YAMLMap';
import { YAMLSeq } from '../nodes/YAMLSeq';
import type { FlowCollection } from '../parse/cst';
import type { CollectionTag } from '../schema/types';
import type { ComposeContext, ComposeNode } from './compose-node';
import type { ComposeErrorHandler } from './composer';
export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLMap.Parsed<import('../index').ParsedNode, import('../index').ParsedNode | null> | YAMLSeq.Parsed<import('../index').ParsedNode>;

View File

@@ -20,6 +20,8 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
const atRoot = ctx.atRoot;
if (atRoot)
ctx.atRoot = false;
if (ctx.atKey)
ctx.atKey = false;
let offset = fc.offset + fc.start.source.length;
for (let i = 0; i < fc.items.length; ++i) {
const collItem = fc.items[i];
@@ -30,6 +32,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
next: key ?? sep?.[0],
offset,
onError,
parentIndent: fc.indent,
startOnNewline: false
});
if (!props.found) {
@@ -98,12 +101,14 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
else {
// item is a key+value pair
// key value
ctx.atKey = true;
const keyStart = props.end;
const keyNode = key
? composeNode(ctx, key, props, onError)
: composeEmptyNode(ctx, keyStart, start, null, props, onError);
if (isBlock(key))
onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
ctx.atKey = false;
// value properties
const valueProps = resolveProps.resolveProps(sep ?? [], {
flow: fcName,
@@ -111,6 +116,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
next: value,
offset: keyNode.range[2],
onError,
parentIndent: fc.indent,
startOnNewline: false
});
if (valueProps.found) {
@@ -163,6 +169,8 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
const map = new YAMLMap.YAMLMap(ctx.schema);
map.flow = true;
map.items.push(pair);
const endRange = (valueNode ?? keyNode).range;
map.range = [keyNode.range[0], endRange[1], endRange[2]];
coll.items.push(map);
}
offset = valueNode ? valueNode.range[2] : valueProps.end;

View File

@@ -1,7 +1,7 @@
import { Range } from '../nodes/Node.js';
import { Scalar } from '../nodes/Scalar.js';
import type { FlowScalar } from '../parse/cst.js';
import type { ComposeErrorHandler } from './composer.js';
import type { Range } from '../nodes/Node';
import { Scalar } from '../nodes/Scalar';
import type { FlowScalar } from '../parse/cst';
import type { ComposeErrorHandler } from './composer';
export declare function resolveFlowScalar(scalar: FlowScalar, strict: boolean, onError: ComposeErrorHandler): {
value: string;
type: Scalar.PLAIN | Scalar.QUOTE_DOUBLE | Scalar.QUOTE_SINGLE | null;

View File

@@ -86,7 +86,7 @@ function foldLines(source) {
first = new RegExp('(.*?)(?<![ \t])[ \t]*\r?\n', 'sy');
line = new RegExp('[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n', 'sy');
}
catch (_) {
catch {
first = /(.*?)[ \t]*\r?\n/sy;
line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
}
@@ -191,19 +191,19 @@ function foldNewline(source, offset) {
return { fold, offset };
}
const escapeCodes = {
'0': '\0',
a: '\x07',
b: '\b',
e: '\x1b',
f: '\f',
n: '\n',
r: '\r',
t: '\t',
v: '\v',
N: '\u0085',
_: '\u00a0',
L: '\u2028',
P: '\u2029',
'0': '\0', // null character
a: '\x07', // bell character
b: '\b', // backspace
e: '\x1b', // escape character
f: '\f', // form feed
n: '\n', // line feed
r: '\r', // carriage return
t: '\t', // horizontal tab
v: '\v', // vertical tab
N: '\u0085', // Unicode next line
_: '\u00a0', // Unicode non-breaking space
L: '\u2028', // Unicode line separator
P: '\u2029', // Unicode paragraph separator
' ': ' ',
'"': '"',
'/': '/',

View File

@@ -1,22 +1,23 @@
import type { SourceToken, Token } from '../parse/cst.js';
import type { ComposeErrorHandler } from './composer.js';
import type { SourceToken, Token } from '../parse/cst';
import type { ComposeErrorHandler } from './composer';
export interface ResolvePropsArg {
flow?: 'flow map' | 'flow sequence';
indicator: 'doc-start' | 'explicit-key-ind' | 'map-value-ind' | 'seq-item-ind';
next: Token | null | undefined;
offset: number;
onError: ComposeErrorHandler;
parentIndent: number;
startOnNewline: boolean;
}
export declare function resolveProps(tokens: SourceToken[], { flow, indicator, next, offset, onError, startOnNewline }: ResolvePropsArg): {
export declare function resolveProps(tokens: SourceToken[], { flow, indicator, next, offset, onError, parentIndent, startOnNewline }: ResolvePropsArg): {
comma: SourceToken | null;
found: SourceToken | null;
spaceBefore: boolean;
comment: string;
hasNewline: boolean;
hasNewlineAfterProp: boolean;
anchor: SourceToken | null;
tag: SourceToken | null;
newlineAfterProp: SourceToken | null;
end: number;
start: number;
};

View File

@@ -1,16 +1,17 @@
'use strict';
function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnNewline }) {
function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIndent, startOnNewline }) {
let spaceBefore = false;
let atNewline = startOnNewline;
let hasSpace = startOnNewline;
let comment = '';
let commentSep = '';
let hasNewline = false;
let hasNewlineAfterProp = false;
let reqSpace = false;
let tab = null;
let anchor = null;
let tag = null;
let newlineAfterProp = null;
let comma = null;
let found = null;
let start = null;
@@ -22,16 +23,22 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
onError(token.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
reqSpace = false;
}
if (tab) {
if (atNewline && token.type !== 'comment' && token.type !== 'newline') {
onError(tab, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation');
}
tab = null;
}
switch (token.type) {
case 'space':
// At the doc level, tabs at line start may be parsed
// as leading white space rather than indentation.
// In a flow collection, only the parser handles indent.
if (!flow &&
atNewline &&
indicator !== 'doc-start' &&
token.source[0] === '\t')
onError(token, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation');
(indicator !== 'doc-start' || next?.type !== 'flow-collection') &&
token.source.includes('\t')) {
tab = token;
}
hasSpace = true;
break;
case 'comment': {
@@ -50,7 +57,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
if (atNewline) {
if (comment)
comment += token.source;
else
else if (!found || indicator !== 'seq-item-ind')
spaceBefore = true;
}
else
@@ -58,7 +65,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
atNewline = true;
hasNewline = true;
if (anchor || tag)
hasNewlineAfterProp = true;
newlineAfterProp = token;
hasSpace = true;
break;
case 'anchor':
@@ -67,8 +74,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
if (token.source.endsWith(':'))
onError(token.offset + token.source.length - 1, 'BAD_ALIAS', 'Anchor ending in : is ambiguous', true);
anchor = token;
if (start === null)
start = token.offset;
start ?? (start = token.offset);
atNewline = false;
hasSpace = false;
reqSpace = true;
@@ -77,8 +83,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
if (tag)
onError(token, 'MULTIPLE_TAGS', 'A node can have at most one tag');
tag = token;
if (start === null)
start = token.offset;
start ?? (start = token.offset);
atNewline = false;
hasSpace = false;
reqSpace = true;
@@ -91,7 +96,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
if (found)
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`);
found = token;
atNewline = false;
atNewline =
indicator === 'seq-item-ind' || indicator === 'explicit-key-ind';
hasSpace = false;
break;
case 'comma':
@@ -117,17 +123,23 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
next.type !== 'space' &&
next.type !== 'newline' &&
next.type !== 'comma' &&
(next.type !== 'scalar' || next.source !== ''))
(next.type !== 'scalar' || next.source !== '')) {
onError(next.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
}
if (tab &&
((atNewline && tab.indent <= parentIndent) ||
next?.type === 'block-map' ||
next?.type === 'block-seq'))
onError(tab, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation');
return {
comma,
found,
spaceBefore,
comment,
hasNewline,
hasNewlineAfterProp,
anchor,
tag,
newlineAfterProp,
end,
start: start ?? end
};

View File

@@ -1,2 +1,2 @@
import type { Token } from '../parse/cst.js';
import type { Token } from '../parse/cst';
export declare function containsNewline(key: Token | null | undefined): boolean | null;

View File

@@ -1,2 +1,2 @@
import type { Token } from '../parse/cst.js';
import type { Token } from '../parse/cst';
export declare function emptyScalarPosition(offset: number, before: Token[] | undefined, pos: number | null): number;

View File

@@ -2,8 +2,7 @@
function emptyScalarPosition(offset, before, pos) {
if (before) {
if (pos === null)
pos = before.length;
pos ?? (pos = before.length);
for (let i = pos - 1; i >= 0; --i) {
let st = before[i];
switch (st.type) {

View File

@@ -1,3 +1,3 @@
import { Token } from '../parse/cst';
import { ComposeErrorHandler } from './composer';
import type { Token } from '../parse/cst';
import type { ComposeErrorHandler } from './composer';
export declare function flowIndentCheck(indent: number, fc: Token | null | undefined, onError: ComposeErrorHandler): void;

View File

@@ -1,4 +1,4 @@
import type { ParsedNode } from '../nodes/Node.js';
import type { Pair } from '../nodes/Pair.js';
import type { ComposeContext } from './compose-node.js';
import type { ParsedNode } from '../nodes/Node';
import type { Pair } from '../nodes/Pair';
import type { ComposeContext } from './compose-node';
export declare function mapIncludes(ctx: ComposeContext, items: Pair<ParsedNode>[], search: ParsedNode): boolean;

View File

@@ -8,11 +8,7 @@ function mapIncludes(ctx, items, search) {
return false;
const isEqual = typeof uniqueKeys === 'function'
? uniqueKeys
: (a, b) => a === b ||
(identity.isScalar(a) &&
identity.isScalar(b) &&
a.value === b.value &&
!(a.value === '<<' && ctx.schema.merge));
: (a, b) => a === b || (identity.isScalar(a) && identity.isScalar(b) && a.value === b.value);
return items.some(pair => isEqual(pair.key, search));
}

View File

@@ -1,14 +1,14 @@
import type { YAMLError, YAMLWarning } from '../errors.js';
import { Alias } from '../nodes/Alias.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';
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';
import type { YAMLError, YAMLWarning } from '../errors';
import { Alias } from '../nodes/Alias';
import { NODE_TYPE } from '../nodes/identity';
import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node';
import { Pair } from '../nodes/Pair';
import type { Scalar } from '../nodes/Scalar';
import type { YAMLMap } from '../nodes/YAMLMap';
import type { YAMLSeq } from '../nodes/YAMLSeq';
import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options';
import { Schema } from '../schema/Schema';
import { Directives } from './directives';
export type Replacer = any[] | ((key: any, value: any) => unknown);
export declare namespace Document {
/** @ts-ignore The typing of directives fails in TS <= 4.2 */

View File

@@ -37,6 +37,7 @@ class Document {
logLevel: 'warn',
prettyErrors: true,
strict: true,
stringKeys: false,
uniqueKeys: true,
version: '1.2'
}, options);
@@ -260,7 +261,7 @@ class Document {
this.directives.yaml.version = '1.1';
else
this.directives = new directives.Directives({ version: '1.1' });
opt = { merge: true, resolveKnownTags: false, schema: 'yaml-1.1' };
opt = { resolveKnownTags: false, schema: 'yaml-1.1' };
break;
case '1.2':
case 'next':
@@ -268,7 +269,7 @@ class Document {
this.directives.yaml.version = version;
else
this.directives = new directives.Directives({ version });
opt = { merge: false, resolveKnownTags: true, schema: 'core' };
opt = { resolveKnownTags: true, schema: 'core' };
break;
case null:
if (this.directives)

View File

@@ -1,5 +1,5 @@
import type { Node } from '../nodes/Node.js';
import type { Document } from './Document.js';
import type { Node } from '../nodes/Node';
import type { Document } from './Document';
/**
* Verify that the input string is a valid anchor.
*

View File

@@ -41,8 +41,7 @@ function createNodeAnchors(doc, prefix) {
return {
onAnchor: (source) => {
aliasObjects.push(source);
if (!prevAnchors)
prevAnchors = anchorNames(doc);
prevAnchors ?? (prevAnchors = anchorNames(doc));
const anchor = findNewAnchor(prefix, prevAnchors);
prevAnchors.add(anchor);
return anchor;

View File

@@ -13,6 +13,7 @@ function applyReviver(reviver, obj, key, val) {
for (let i = 0, len = val.length; i < len; ++i) {
const v0 = val[i];
const v1 = applyReviver(reviver, val, String(i), v0);
// eslint-disable-next-line @typescript-eslint/no-array-delete
if (v1 === undefined)
delete val[i];
else if (v1 !== v0)

View File

@@ -1,7 +1,7 @@
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';
import type { Node } from '../nodes/Node';
import type { Schema } from '../schema/Schema';
import type { CollectionTag, ScalarTag } from '../schema/types';
import type { Replacer } from './Document';
export interface CreateNodeContext {
aliasDuplicateObjects: boolean;
keepUndefined: boolean;

View File

@@ -40,8 +40,7 @@ function createNode(value, tagName, ctx) {
if (aliasDuplicateObjects && value && typeof value === 'object') {
ref = sourceObjects.get(value);
if (ref) {
if (!ref.anchor)
ref.anchor = onAnchor(value);
ref.anchor ?? (ref.anchor = onAnchor(value));
return new Alias.Alias(ref.anchor);
}
else {

View File

@@ -1,4 +1,4 @@
import type { Document } from './Document.js';
import type { Document } from './Document';
export declare class Directives {
static defaultYaml: Directives['yaml'];
static defaultTags: Directives['tags'];

2
node_modules/yaml/dist/errors.d.ts generated vendored
View File

@@ -1,5 +1,5 @@
import type { LineCounter } from './parse/line-counter';
export type ErrorCode = 'ALIAS_PROPS' | 'BAD_ALIAS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'DUPLICATE_KEY' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE';
export type ErrorCode = 'ALIAS_PROPS' | 'BAD_ALIAS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'DUPLICATE_KEY' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'NON_STRING_KEY' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE';
export type LinePos = {
line: number;
col: number;

39
node_modules/yaml/dist/index.d.ts generated vendored
View File

@@ -1,22 +1,25 @@
export { Composer } from './compose/composer.js';
export { Document } from './doc/Document.js';
export { Schema } from './schema/Schema.js';
export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
export { Alias } from './nodes/Alias.js';
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/identity.js';
export { Node, ParsedNode, Range } from './nodes/Node.js';
export { Pair } from './nodes/Pair.js';
export { Scalar } from './nodes/Scalar.js';
export { YAMLMap } from './nodes/YAMLMap.js';
export { YAMLSeq } from './nodes/YAMLSeq.js';
export type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
export * as CST from './parse/cst.js';
export { Lexer } from './parse/lexer.js';
export { LineCounter } from './parse/line-counter.js';
export { Parser } from './parse/parser.js';
export { EmptyStream, parse, parseAllDocuments, parseDocument, stringify } from './public-api.js';
export { Composer } from './compose/composer';
export { Document } from './doc/Document';
export { Schema } from './schema/Schema';
export type { ErrorCode } from './errors';
export { YAMLError, YAMLParseError, YAMLWarning } from './errors';
export { Alias } from './nodes/Alias';
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/identity';
export type { Node, ParsedNode, Range } from './nodes/Node';
export { Pair } from './nodes/Pair';
export { Scalar } from './nodes/Scalar';
export { YAMLMap } from './nodes/YAMLMap';
export { YAMLSeq } from './nodes/YAMLSeq';
export type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options';
export * as CST from './parse/cst';
export { Lexer } from './parse/lexer';
export { LineCounter } from './parse/line-counter';
export { Parser } from './parse/parser';
export type { EmptyStream } from './public-api';
export { parse, parseAllDocuments, parseDocument, stringify } from './public-api';
export type { TagId, Tags } from './schema/tags';
export type { CollectionTag, ScalarTag } from './schema/types';
export type { YAMLOMap } from './schema/yaml-1.1/omap';
export type { YAMLSet } from './schema/yaml-1.1/set';
export { asyncVisitor, asyncVisitorFn, visit, visitAsync, visitor, visitorFn } from './visit.js';
export type { asyncVisitor, asyncVisitorFn, visitor, visitorFn } from './visit';
export { visit, visitAsync } from './visit';

8
node_modules/yaml/dist/log.js generated vendored
View File

@@ -1,15 +1,15 @@
'use strict';
var node_process = require('process');
function debug(logLevel, ...messages) {
if (logLevel === 'debug')
console.log(...messages);
}
function warn(logLevel, warning) {
if (logLevel === 'debug' || logLevel === 'warn') {
// https://github.com/typescript-eslint/typescript-eslint/issues/7478
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
if (typeof process !== 'undefined' && process.emitWarning)
process.emitWarning(warning);
if (typeof node_process.emitWarning === 'function')
node_process.emitWarning(warning);
else
console.warn(warning);
}

View File

@@ -1,11 +1,12 @@
import type { Document } from '../doc/Document.js';
import type { FlowScalar } from '../parse/cst.js';
import type { StringifyContext } from '../stringify/stringify.js';
import { NodeBase, Range } from './Node.js';
import type { Document } from '../doc/Document';
import type { FlowScalar } from '../parse/cst';
import type { StringifyContext } from '../stringify/stringify';
import type { Range } from './Node';
import { NodeBase } from './Node';
import type { Scalar } from './Scalar';
import { ToJSContext } from './toJS.js';
import type { YAMLMap } from './YAMLMap.js';
import type { YAMLSeq } from './YAMLSeq.js';
import type { ToJSContext } from './toJS';
import type { YAMLMap } from './YAMLMap';
import type { YAMLSeq } from './YAMLSeq';
export declare namespace Alias {
interface Parsed extends Alias {
range: Range;
@@ -22,7 +23,7 @@ export declare class Alias extends NodeBase {
* Resolve the value of this alias within `doc`, finding the last
* instance of the `source` anchor before this node.
*/
resolve(doc: Document): Scalar | YAMLMap | YAMLSeq | undefined;
toJSON(_arg?: unknown, ctx?: ToJSContext): {} | null;
resolve(doc: Document, ctx?: ToJSContext): Scalar | YAMLMap | YAMLSeq | undefined;
toJSON(_arg?: unknown, ctx?: ToJSContext): unknown;
toString(ctx?: StringifyContext, _onComment?: () => void, _onChompKeep?: () => void): string;
}

View File

@@ -20,23 +20,36 @@ class Alias extends Node.NodeBase {
* Resolve the value of this alias within `doc`, finding the last
* instance of the `source` anchor before this node.
*/
resolve(doc) {
resolve(doc, ctx) {
let nodes;
if (ctx?.aliasResolveCache) {
nodes = ctx.aliasResolveCache;
}
else {
nodes = [];
visit.visit(doc, {
Node: (_key, node) => {
if (identity.isAlias(node) || identity.hasAnchor(node))
nodes.push(node);
}
});
if (ctx)
ctx.aliasResolveCache = nodes;
}
let found = undefined;
visit.visit(doc, {
Node: (_key, node) => {
if (node === this)
return visit.visit.BREAK;
if (node.anchor === this.source)
found = node;
}
});
for (const node of nodes) {
if (node === this)
break;
if (node.anchor === this.source)
found = node;
}
return found;
}
toJSON(_arg, ctx) {
if (!ctx)
return { source: this.source };
const { anchors, doc, maxAliasCount } = ctx;
const source = this.resolve(doc);
const source = this.resolve(doc, ctx);
if (!source) {
const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
throw new ReferenceError(msg);

View File

@@ -1,10 +1,9 @@
import type { Schema } from '../schema/Schema.js';
import { NODE_TYPE } from './identity.js';
import { NodeBase } from './Node.js';
export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node;
import type { Schema } from '../schema/Schema';
import { NODE_TYPE } from './identity';
import { NodeBase } from './Node';
export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import('./Node').Node;
export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) => path is null | undefined;
export declare abstract class Collection extends NodeBase {
static maxFlowStringSingleLineLength: number;
schema: Schema | undefined;
[NODE_TYPE]: symbol;
items: unknown[];

View File

@@ -145,7 +145,6 @@ class Collection extends Node.NodeBase {
}
}
}
Collection.maxFlowStringSingleLineLength = 60;
exports.Collection = Collection;
exports.collectionFromPath = collectionFromPath;

View File

@@ -1,12 +1,13 @@
import type { Document } from '../doc/Document.js';
import type { ToJSOptions } from '../options.js';
import { Token } from '../parse/cst.js';
import type { StringifyContext } from '../stringify/stringify.js';
import type { Alias } from './Alias.js';
import { NODE_TYPE } from './identity.js';
import type { Scalar } from './Scalar.js';
import type { YAMLMap } from './YAMLMap.js';
import type { YAMLSeq } from './YAMLSeq.js';
import type { Document } from '../doc/Document';
import type { ToJSOptions } from '../options';
import type { Token } from '../parse/cst';
import type { StringifyContext } from '../stringify/stringify';
import type { Alias } from './Alias';
import { NODE_TYPE } from './identity';
import type { Scalar } from './Scalar';
import type { ToJSContext } from './toJS';
import type { MapLike, YAMLMap } from './YAMLMap';
import type { YAMLSeq } from './YAMLSeq';
export type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
/** Utility type mapper */
export type NodeType<T> = T extends string | number | bigint | boolean | null | undefined ? Scalar<T> : T extends Date ? Scalar<string | Date> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
@@ -15,6 +16,7 @@ export type NodeType<T> = T extends string | number | bigint | boolean | null |
[key: number]: any;
} ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
export type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
/** `[start, value-end, node-end]` */
export type Range = [number, number, number];
export declare abstract class NodeBase {
readonly [NODE_TYPE]: symbol;
@@ -35,6 +37,11 @@ export declare abstract class NodeBase {
srcToken?: Token;
/** A fully qualified tag, if required */
tag?: string;
/**
* Customize the way that a key-value pair is resolved.
* Used for YAML 1.1 !!merge << handling.
*/
addToJSMap?: (ctx: ToJSContext | undefined, map: MapLike, value: unknown) => void;
/** A plain JS representation of this node */
abstract toJSON(): any;
abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;

View File

@@ -1,11 +1,12 @@
import { CreateNodeContext } from '../doc/createNode.js';
import type { CollectionItem } from '../parse/cst.js';
import type { Schema } from '../schema/Schema.js';
import type { StringifyContext } from '../stringify/stringify.js';
import { addPairToJSMap } from './addPairToJSMap.js';
import { NODE_TYPE } from './identity.js';
import type { ToJSContext } from './toJS.js';
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node, import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./Scalar.js").Scalar<unknown> | import("./Alias.js").Alias | import("./YAMLSeq.js").YAMLSeq<unknown>>;
import type { CreateNodeContext } from '../doc/createNode';
import type { CollectionItem } from '../parse/cst';
import type { Schema } from '../schema/Schema';
import type { StringifyContext } from '../stringify/stringify';
import { addPairToJSMap } from './addPairToJSMap';
import { NODE_TYPE } from './identity';
import type { Node } from './Node';
import type { ToJSContext } from './toJS';
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<Node, Node>;
export declare class Pair<K = unknown, V = unknown> {
readonly [NODE_TYPE]: symbol;
/** Always Node or null when parsed, but can be set to anything. */

View File

@@ -1,6 +1,7 @@
import type { BlockScalar, FlowScalar } from '../parse/cst.js';
import { NodeBase, Range } from './Node.js';
import { ToJSContext } from './toJS.js';
import type { BlockScalar, FlowScalar } from '../parse/cst';
import type { Range } from './Node';
import { NodeBase } from './Node';
import type { ToJSContext } from './toJS';
export declare const isScalarValue: (value: unknown) => boolean;
export declare namespace Scalar {
interface Parsed extends Scalar {

View File

@@ -1,12 +1,12 @@
import type { BlockMap, FlowCollection } from '../parse/cst.js';
import type { Schema } from '../schema/Schema.js';
import type { StringifyContext } from '../stringify/stringify.js';
import { CreateNodeContext } from '../util.js';
import { Collection } from './Collection.js';
import type { ParsedNode, Range } from './Node.js';
import { Pair } from './Pair.js';
import { Scalar } from './Scalar.js';
import type { ToJSContext } from './toJS.js';
import type { BlockMap, FlowCollection } from '../parse/cst';
import type { Schema } from '../schema/Schema';
import type { StringifyContext } from '../stringify/stringify';
import type { CreateNodeContext } from '../util';
import { Collection } from './Collection';
import type { ParsedNode, Range } from './Node';
import { Pair } from './Pair';
import type { Scalar } from './Scalar';
import type { ToJSContext } from './toJS';
export type MapLike = Map<unknown, unknown> | Set<unknown> | Record<string | number | symbol, unknown>;
export declare function findPair<K = unknown, V = unknown>(items: Iterable<Pair<K, V>>, key: unknown): Pair<K, V> | undefined;
export declare namespace YAMLMap {
@@ -24,7 +24,7 @@ export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
* A generic collection parsing method that can be extended
* to other node classes that inherit from YAMLMap
*/
static from(schema: Schema, obj: unknown, ctx: CreateNodeContext): YAMLMap<unknown, unknown>;
static from(schema: Schema, obj: unknown, ctx: CreateNodeContext): YAMLMap;
/**
* Adds a value to the collection.
*

View File

@@ -1,12 +1,12 @@
import { CreateNodeContext } from '../doc/createNode.js';
import type { BlockSequence, FlowCollection } from '../parse/cst.js';
import type { Schema } from '../schema/Schema.js';
import type { StringifyContext } from '../stringify/stringify.js';
import { Collection } from './Collection.js';
import type { ParsedNode, Range } from './Node.js';
import type { Pair } from './Pair.js';
import { Scalar } from './Scalar.js';
import { ToJSContext } from './toJS.js';
import type { CreateNodeContext } from '../doc/createNode';
import type { BlockSequence, FlowCollection } from '../parse/cst';
import type { Schema } from '../schema/Schema';
import type { StringifyContext } from '../stringify/stringify';
import { Collection } from './Collection';
import type { ParsedNode, Range } from './Node';
import type { Pair } from './Pair';
import type { Scalar } from './Scalar';
import type { ToJSContext } from './toJS';
export declare namespace YAMLSeq {
interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
items: T[];
@@ -56,5 +56,5 @@ export declare class YAMLSeq<T = unknown> extends Collection {
set(key: unknown, value: T): void;
toJSON(_?: unknown, ctx?: ToJSContext): unknown[];
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
static from(schema: Schema, obj: unknown, ctx: CreateNodeContext): YAMLSeq<unknown>;
static from(schema: Schema, obj: unknown, ctx: CreateNodeContext): YAMLSeq;
}

View File

@@ -1,4 +1,4 @@
import type { Pair } from './Pair.js';
import { ToJSContext } from './toJS.js';
import type { MapLike } from './YAMLMap.js';
import type { Pair } from './Pair';
import type { ToJSContext } from './toJS';
import type { MapLike } from './YAMLMap';
export declare function addPairToJSMap(ctx: ToJSContext | undefined, map: MapLike, { key, value }: Pair): MapLike;

View File

@@ -1,24 +1,17 @@
'use strict';
var log = require('../log.js');
var merge = require('../schema/yaml-1.1/merge.js');
var stringify = require('../stringify/stringify.js');
var identity = require('./identity.js');
var Scalar = require('./Scalar.js');
var toJS = require('./toJS.js');
const MERGE_KEY = '<<';
function addPairToJSMap(ctx, map, { key, value }) {
if (ctx?.doc.schema.merge && isMergeKey(key)) {
value = identity.isAlias(value) ? value.resolve(ctx.doc) : value;
if (identity.isSeq(value))
for (const it of value.items)
mergeToJSMap(ctx, map, it);
else if (Array.isArray(value))
for (const it of value)
mergeToJSMap(ctx, map, it);
else
mergeToJSMap(ctx, map, value);
}
if (identity.isNode(key) && key.addToJSMap)
key.addToJSMap(ctx, map, value);
// TODO: Should drop this special case for bare << handling
else if (merge.isMergeKey(ctx, key))
merge.addMergeToJSMap(ctx, map, value);
else {
const jsKey = toJS.toJS(key, '', ctx);
if (map instanceof Map) {
@@ -43,44 +36,10 @@ function addPairToJSMap(ctx, map, { key, value }) {
}
return map;
}
const isMergeKey = (key) => key === MERGE_KEY ||
(identity.isScalar(key) &&
key.value === MERGE_KEY &&
(!key.type || key.type === Scalar.Scalar.PLAIN));
// 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
function mergeToJSMap(ctx, map, value) {
const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
if (!identity.isMap(source))
throw new Error('Merge sources must be maps or map aliases');
const srcMap = source.toJSON(null, ctx, Map);
for (const [key, value] of srcMap) {
if (map instanceof Map) {
if (!map.has(key))
map.set(key, value);
}
else if (map instanceof Set) {
map.add(key);
}
else if (!Object.prototype.hasOwnProperty.call(map, key)) {
Object.defineProperty(map, key, {
value,
writable: true,
enumerable: true,
configurable: true
});
}
}
return map;
}
function stringifyKey(key, jsKey, ctx) {
if (jsKey === null)
return '';
// eslint-disable-next-line @typescript-eslint/no-base-to-string
if (typeof jsKey !== 'object')
return String(jsKey);
if (identity.isNode(key) && ctx?.doc) {

View File

@@ -1,10 +1,10 @@
import type { Document } from '../doc/Document.js';
import type { Alias } from './Alias.js';
import type { Node } from './Node.js';
import type { Pair } from './Pair.js';
import type { Scalar } from './Scalar.js';
import type { YAMLMap } from './YAMLMap.js';
import type { YAMLSeq } from './YAMLSeq.js';
import type { Document } from '../doc/Document';
import type { Alias } from './Alias';
import type { Node } from './Node';
import type { Pair } from './Pair';
import type { Scalar } from './Scalar';
import type { YAMLMap } from './YAMLMap';
import type { YAMLSeq } from './YAMLSeq';
export declare const ALIAS: unique symbol;
export declare const DOC: unique symbol;
export declare const MAP: unique symbol;
@@ -13,7 +13,7 @@ export declare const SCALAR: unique symbol;
export declare const SEQ: unique symbol;
export declare const NODE_TYPE: unique symbol;
export declare const isAlias: (node: any) => node is Alias;
export declare const isDocument: <T extends Node = Node>(node: any) => node is Document<T, true>;
export declare const isDocument: <T extends Node = Node>(node: any) => node is Document<T>;
export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;

View File

@@ -1,5 +1,5 @@
import type { Document } from '../doc/Document.js';
import type { Node } from './Node.js';
import type { Document } from '../doc/Document';
import type { Node } from './Node';
export interface AnchorData {
aliasCount: number;
count: number;
@@ -7,6 +7,8 @@ export interface AnchorData {
}
export interface ToJSContext {
anchors: Map<Node, AnchorData>;
/** Cached anchor and alias nodes in the order they occur in the document */
aliasResolveCache?: Node[];
doc: Document<Node, boolean>;
keep: boolean;
mapAsMap: boolean;

26
node_modules/yaml/dist/options.d.ts generated vendored
View File

@@ -1,13 +1,13 @@
import type { Reviver } from './doc/applyReviver.js';
import type { Directives } from './doc/directives.js';
import type { LogLevelId } from './log.js';
import type { ParsedNode } from './nodes/Node.js';
import type { Pair } from './nodes/Pair.js';
import type { Scalar } from './nodes/Scalar.js';
import type { LineCounter } from './parse/line-counter.js';
import type { Schema } from './schema/Schema.js';
import type { Tags } from './schema/tags.js';
import type { CollectionTag, ScalarTag } from './schema/types.js';
import type { Reviver } from './doc/applyReviver';
import type { Directives } from './doc/directives';
import type { LogLevelId } from './log';
import type { ParsedNode } from './nodes/Node';
import type { Pair } from './nodes/Pair';
import type { Scalar } from './nodes/Scalar';
import type { LineCounter } from './parse/line-counter';
import type { Schema } from './schema/Schema';
import type { Tags } from './schema/tags';
import type { CollectionTag, ScalarTag } from './schema/types';
export type ParseOptions = {
/**
* Whether integers should be parsed into BigInt rather than number values.
@@ -42,6 +42,12 @@ export type ParseOptions = {
* Default: `true`
*/
strict?: boolean;
/**
* Parse all mapping keys as strings. Treat all non-scalar keys as errors.
*
* Default: `false`
*/
stringKeys?: boolean;
/**
* YAML requires map keys to be unique. By default, this is checked by
* comparing scalar values with `===`; deep equality is not checked for

View File

@@ -1,7 +1,7 @@
import { ErrorCode } from '../errors.js';
import { Range } from '../nodes/Node.js';
import type { Scalar } from '../nodes/Scalar.js';
import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst.js';
import type { ErrorCode } from '../errors';
import type { Range } from '../nodes/Node';
import type { Scalar } from '../nodes/Scalar';
import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst';
/**
* If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
* Otherwise, return `null`.

View File

@@ -20,7 +20,7 @@ function resolveAsScalar(token, strict = true, onError) {
case 'double-quoted-scalar':
return resolveFlowScalar.resolveFlowScalar(token, strict, _onError);
case 'block-scalar':
return resolveBlockScalar.resolveBlockScalar(token, strict, _onError);
return resolveBlockScalar.resolveBlockScalar({ options: { strict } }, token, _onError);
}
}
return null;

View File

@@ -1,4 +1,4 @@
import type { CollectionItem, Token } from './cst.js';
import type { CollectionItem, Token } from './cst';
/**
* Stringify a CST document, token, or collection item
*

View File

@@ -1,4 +1,4 @@
import type { CollectionItem, Document } from './cst.js';
import type { BlockMap, BlockSequence, CollectionItem, Document, FlowCollection } from './cst';
export type VisitPath = readonly ['key' | 'value', number][];
export type Visitor = (item: CollectionItem, path: VisitPath) => number | symbol | Visitor | void;
/**
@@ -35,5 +35,5 @@ export declare namespace visit {
var SKIP: symbol;
var REMOVE: symbol;
var itemAtPath: (cst: Document | CollectionItem, path: VisitPath) => CollectionItem | undefined;
var parentCollection: (cst: Document | CollectionItem, path: VisitPath) => import("./cst.js").BlockMap | import("./cst.js").BlockSequence | import("./cst.js").FlowCollection;
var parentCollection: (cst: Document | CollectionItem, path: VisitPath) => BlockMap | BlockSequence | FlowCollection;
}

View File

@@ -1,6 +1,7 @@
export { createScalarToken, resolveAsScalar, setScalarValue } from './cst-scalar.js';
export { stringify } from './cst-stringify.js';
export { visit, Visitor, VisitPath } from './cst-visit.js';
export { createScalarToken, resolveAsScalar, setScalarValue } from './cst-scalar';
export { stringify } from './cst-stringify';
export type { Visitor, VisitPath } from './cst-visit';
export { visit } from './cst-visit';
export interface SourceToken {
type: 'byte-order-mark' | 'doc-mode' | 'doc-start' | 'space' | 'comment' | 'newline' | 'directive-line' | 'anchor' | 'tag' | 'seq-item-ind' | 'explicit-key-ind' | 'map-value-ind' | 'flow-map-start' | 'flow-map-end' | 'flow-seq-start' | 'flow-seq-end' | 'flow-error-end' | 'comma' | 'block-scalar-header';
offset: number;
@@ -51,11 +52,13 @@ export interface BlockMap {
indent: number;
items: Array<{
start: SourceToken[];
explicitKey?: true;
key?: never;
sep?: never;
value?: never;
} | {
start: SourceToken[];
explicitKey?: true;
key: Token | null;
sep: SourceToken[];
value?: Token;
@@ -99,7 +102,7 @@ export declare const SCALAR = "\u001F";
/** @returns `true` if `token` is a flow or block collection */
export declare const isCollection: (token: Token | null | undefined) => token is BlockMap | BlockSequence | FlowCollection;
/** @returns `true` if `token` is a flow or block scalar; not an alias */
export declare const isScalar: (token: Token | null | undefined) => token is BlockScalar | FlowScalar;
export declare const isScalar: (token: Token | null | undefined) => token is FlowScalar | BlockScalar;
/** Get a printable representation of a lexer token */
export declare function prettyToken(token: string): string;
/** Identify the type of a lexer token. May return `null` for unknown tokens. */

View File

@@ -59,7 +59,7 @@ export declare class Lexer {
*
* @returns A generator of lexical tokens
*/
lex(source: string, incomplete?: boolean): Generator<string, void, unknown>;
lex(source: string, incomplete?: boolean): Generator<string, void>;
private atLineEnd;
private charAt;
private continueScalar;

View File

@@ -81,11 +81,11 @@ function isEmpty(ch) {
return false;
}
}
const hexDigits = '0123456789ABCDEFabcdef'.split('');
const tagChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()".split('');
const invalidFlowScalarChars = ',[]{}'.split('');
const invalidAnchorChars = ' ,[]{}\n\r\t'.split('');
const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.includes(ch);
const hexDigits = new Set('0123456789ABCDEFabcdef');
const tagChars = new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()");
const flowIndicatorChars = new Set(',[]{}');
const invalidAnchorChars = new Set(' ,[]{}\n\r\t');
const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.has(ch);
/**
* Splits an input string into lexical tokens, i.e. smaller strings that are
* easily identifiable by `tokens.tokenType()`.
@@ -151,6 +151,8 @@ class Lexer {
*/
*lex(source, incomplete = false) {
if (source) {
if (typeof source !== 'string')
throw TypeError('source is not a string');
this.buffer = this.buffer ? this.buffer + source : source;
this.lineEndPos = null;
}
@@ -250,11 +252,16 @@ class Lexer {
}
if (line[0] === '%') {
let dirEnd = line.length;
const cs = line.indexOf('#');
if (cs !== -1) {
let cs = line.indexOf('#');
while (cs !== -1) {
const ch = line[cs - 1];
if (ch === ' ' || ch === '\t')
if (ch === ' ' || ch === '\t') {
dirEnd = cs - 1;
break;
}
else {
cs = line.indexOf('#', cs + 1);
}
}
while (true) {
const ch = line[dirEnd - 1];
@@ -285,15 +292,11 @@ class Lexer {
if (!this.atEnd && !this.hasChars(4))
return this.setNext('line-start');
const s = this.peek(3);
if (s === '---' && isEmpty(this.charAt(3))) {
if ((s === '---' || s === '...') && isEmpty(this.charAt(3))) {
yield* this.pushCount(3);
this.indentValue = 0;
this.indentNext = 0;
return 'doc';
}
else if (s === '...' && isEmpty(this.charAt(3))) {
yield* this.pushCount(3);
return 'stream';
return s === '---' ? 'doc' : 'stream';
}
}
this.indentValue = yield* this.pushSpaces(false);
@@ -520,8 +523,10 @@ class Lexer {
if (indent >= this.indentNext) {
if (this.blockScalarIndent === -1)
this.indentNext = indent;
else
this.indentNext += this.blockScalarIndent;
else {
this.indentNext =
this.blockScalarIndent + (this.indentNext === 0 ? 1 : this.indentNext);
}
do {
const cs = this.continueScalar(nl + 1);
if (cs === -1)
@@ -534,14 +539,25 @@ class Lexer {
nl = this.buffer.length;
}
}
if (!this.blockScalarKeep) {
// Trailing insufficiently indented tabs are invalid.
// To catch that during parsing, we include them in the block scalar value.
let i = nl + 1;
ch = this.buffer[i];
while (ch === ' ')
ch = this.buffer[++i];
if (ch === '\t') {
while (ch === '\t' || ch === ' ' || ch === '\r' || ch === '\n')
ch = this.buffer[++i];
nl = i - 1;
}
else if (!this.blockScalarKeep) {
do {
let i = nl - 1;
let ch = this.buffer[i];
if (ch === '\r')
ch = this.buffer[--i];
const lastChar = i; // Drop the line if last char not more indented
while (ch === ' ' || ch === '\t')
while (ch === ' ')
ch = this.buffer[--i];
if (ch === '\n' && i >= this.pos && i + 1 + indent > lastChar)
nl = i;
@@ -561,7 +577,7 @@ class Lexer {
while ((ch = this.buffer[++i])) {
if (ch === ':') {
const next = this.buffer[i + 1];
if (isEmpty(next) || (inFlow && next === ','))
if (isEmpty(next) || (inFlow && flowIndicatorChars.has(next)))
break;
end = i;
}
@@ -576,7 +592,7 @@ class Lexer {
else
end = i;
}
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
if (next === '#' || (inFlow && flowIndicatorChars.has(next)))
break;
if (ch === '\n') {
const cs = this.continueScalar(i + 1);
@@ -586,7 +602,7 @@ class Lexer {
}
}
else {
if (inFlow && invalidFlowScalarChars.includes(ch))
if (inFlow && flowIndicatorChars.has(ch))
break;
end = i;
}
@@ -631,7 +647,7 @@ class Lexer {
case ':': {
const inFlow = this.flowLevel > 0;
const ch1 = this.charAt(1);
if (isEmpty(ch1) || (inFlow && invalidFlowScalarChars.includes(ch1))) {
if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) {
if (!inFlow)
this.indentNext = this.indentValue + 1;
else if (this.flowKey)
@@ -656,11 +672,11 @@ class Lexer {
let i = this.pos + 1;
let ch = this.buffer[i];
while (ch) {
if (tagChars.includes(ch))
if (tagChars.has(ch))
ch = this.buffer[++i];
else if (ch === '%' &&
hexDigits.includes(this.buffer[i + 1]) &&
hexDigits.includes(this.buffer[i + 2])) {
hexDigits.has(this.buffer[i + 1]) &&
hexDigits.has(this.buffer[i + 2])) {
ch = this.buffer[(i += 3)];
}
else

View File

@@ -1,4 +1,4 @@
import { Token } from './cst.js';
import type { Token } from './cst';
/**
* A YAML concrete syntax tree (CST) parser
*
@@ -57,14 +57,14 @@ export declare class Parser {
*
* @returns A generator of tokens representing each directive, document, and other structure.
*/
parse(source: string, incomplete?: boolean): Generator<Token, void, unknown>;
parse(source: string, incomplete?: boolean): Generator<Token, void>;
/**
* Advance the parser by the `source` of one lexical token.
*/
next(source: string): Generator<Token, void, unknown>;
next(source: string): Generator<Token, void>;
private lexer;
/** Call at end of input to push out any remaining constructions */
end(): Generator<Token, void, unknown>;
end(): Generator<Token, void>;
private get sourceToken();
private step;
private peek;

View File

@@ -1,5 +1,6 @@
'use strict';
var node_process = require('process');
var cst = require('./cst.js');
var lexer = require('./lexer.js');
@@ -166,7 +167,7 @@ class Parser {
*/
*next(source) {
this.source = source;
if (process.env.LOG_TOKENS)
if (node_process.env.LOG_TOKENS)
console.log('|', cst.prettyToken(source));
if (this.atScalar) {
this.atScalar = false;
@@ -308,7 +309,7 @@ class Parser {
}
else {
Object.assign(it, { key: token, sep: [] });
this.onKeyLine = !includesToken(it.start, 'explicit-key-ind');
this.onKeyLine = !it.explicitKey;
return;
}
break;
@@ -517,7 +518,10 @@ class Parser {
return;
}
if (this.indent >= map.indent) {
const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep;
const atMapIndent = !this.onKeyLine && this.indent === map.indent;
const atNextItem = atMapIndent &&
(it.sep || it.explicitKey) &&
this.type !== 'seq-item-ind';
// For empty nodes, assign newline-separated not indented empty tokens to following node
let start = [];
if (atNextItem && it.sep && !it.value) {
@@ -557,25 +561,26 @@ class Parser {
}
return;
case 'explicit-key-ind':
if (!it.sep && !includesToken(it.start, 'explicit-key-ind')) {
if (!it.sep && !it.explicitKey) {
it.start.push(this.sourceToken);
it.explicitKey = true;
}
else if (atNextItem || it.value) {
start.push(this.sourceToken);
map.items.push({ start });
map.items.push({ start, explicitKey: true });
}
else {
this.stack.push({
type: 'block-map',
offset: this.offset,
indent: this.indent,
items: [{ start: [this.sourceToken] }]
items: [{ start: [this.sourceToken], explicitKey: true }]
});
}
this.onKeyLine = true;
return;
case 'map-value-ind':
if (includesToken(it.start, 'explicit-key-ind')) {
if (it.explicitKey) {
if (!it.sep) {
if (includesToken(it.start, 'newline')) {
Object.assign(it, { key: null, sep: [this.sourceToken] });
@@ -608,7 +613,9 @@ class Parser {
const sep = it.sep;
sep.push(this.sourceToken);
// @ts-expect-error type guard is wrong here
delete it.key, delete it.sep;
delete it.key;
// @ts-expect-error type guard is wrong here
delete it.sep;
this.stack.push({
type: 'block-map',
offset: this.offset,
@@ -666,9 +673,20 @@ class Parser {
default: {
const bv = this.startBlockValue(map);
if (bv) {
if (atNextItem &&
bv.type !== 'block-seq' &&
includesToken(it.start, 'explicit-key-ind')) {
if (bv.type === 'block-seq') {
if (!it.explicitKey &&
it.sep &&
!includesToken(it.sep, 'newline')) {
yield* this.pop({
type: 'error',
offset: this.offset,
message: 'Unexpected block-seq-ind on same line with key',
source: this.source
});
return;
}
}
else if (atMapIndent) {
map.items.push({ start });
}
this.stack.push(bv);
@@ -889,7 +907,7 @@ class Parser {
type: 'block-map',
offset: this.offset,
indent: this.indent,
items: [{ start }]
items: [{ start, explicitKey: true }]
};
}
case 'map-value-ind': {

View File

@@ -1,8 +1,9 @@
import { Composer } from './compose/composer.js';
import type { Reviver } from './doc/applyReviver.js';
import { Document, Replacer } from './doc/Document.js';
import type { Node, ParsedNode } from './nodes/Node.js';
import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
import { Composer } from './compose/composer';
import type { Reviver } from './doc/applyReviver';
import type { Replacer } from './doc/Document';
import { Document } from './doc/Document';
import type { Node, ParsedNode } from './nodes/Node';
import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options';
export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer['streamInfo']> {
empty: true;
}

View File

@@ -4,6 +4,7 @@ var composer = require('./compose/composer.js');
var Document = require('./doc/Document.js');
var errors = require('./errors.js');
var log = require('./log.js');
var identity = require('./nodes/identity.js');
var lineCounter = require('./parse/line-counter.js');
var parser = require('./parse/parser.js');
@@ -95,6 +96,8 @@ function stringify(value, replacer, options) {
if (!keepUndefined)
return undefined;
}
if (identity.isDocument(value) && !_replacer)
return value.toString(options);
return new Document.Document(value, _replacer, options).toString(options);
}

View File

@@ -1,11 +1,10 @@
import { MAP, SCALAR, SEQ } from '../nodes/identity.js';
import type { Pair } from '../nodes/Pair.js';
import type { SchemaOptions, ToStringOptions } from '../options.js';
import type { CollectionTag, ScalarTag } from './types.js';
import { MAP, SCALAR, SEQ } from '../nodes/identity';
import type { Pair } from '../nodes/Pair';
import type { SchemaOptions, ToStringOptions } from '../options';
import type { CollectionTag, ScalarTag } from './types';
export declare class Schema {
compat: Array<CollectionTag | ScalarTag> | null;
knownTags: Record<string, CollectionTag | ScalarTag>;
merge: boolean;
name: string;
sortMapEntries: ((a: Pair, b: Pair) => number) | null;
tags: Array<CollectionTag | ScalarTag>;

View File

@@ -14,10 +14,9 @@ class Schema {
: compat
? tags.getTags(null, compat)
: null;
this.merge = !!merge;
this.name = (typeof schema === 'string' && schema) || 'core';
this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
this.tags = tags.getTags(customTags, this.name);
this.tags = tags.getTags(customTags, this.name, merge);
this.toStringOptions = toStringDefaults ?? null;
Object.defineProperty(this, identity.MAP, { value: map.map });
Object.defineProperty(this, identity.SCALAR, { value: string.string });

View File

@@ -1,2 +1,2 @@
import type { CollectionTag } from '../types.js';
import type { CollectionTag } from '../types';
export declare const map: CollectionTag;

View File

@@ -1,4 +1,4 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const nullTag: ScalarTag & {
test: RegExp;
};

View File

@@ -1,2 +1,2 @@
import type { CollectionTag } from '../types.js';
import type { CollectionTag } from '../types';
export declare const seq: CollectionTag;

View File

@@ -1,2 +1,2 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const string: ScalarTag;

View File

@@ -1,4 +1,4 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const boolTag: ScalarTag & {
test: RegExp;
};

View File

@@ -1,4 +1,4 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const floatNaN: ScalarTag;
export declare const floatExp: ScalarTag;
export declare const float: ScalarTag;

View File

@@ -7,7 +7,7 @@ const floatNaN = {
identify: value => typeof value === 'number',
default: true,
tag: 'tag:yaml.org,2002:float',
test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,
test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
resolve: str => str.slice(-3).toLowerCase() === 'nan'
? NaN
: str[0] === '-'

View File

@@ -1,4 +1,4 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const intOct: ScalarTag;
export declare const int: ScalarTag;
export declare const intHex: ScalarTag;

View File

@@ -1 +1 @@
export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[];
export declare const schema: (import('../types').CollectionTag | import('../types').ScalarTag)[];

View File

@@ -1,2 +1,2 @@
import { CollectionTag, ScalarTag } from '../types.js';
import type { CollectionTag, ScalarTag } from '../types';
export declare const schema: (CollectionTag | ScalarTag)[];

View File

@@ -29,7 +29,7 @@ const jsonScalars = [
identify: value => typeof value === 'boolean',
default: true,
tag: 'tag:yaml.org,2002:bool',
test: /^true|false$/,
test: /^true$|^false$/,
resolve: str => str === 'true',
stringify: stringifyJSON
},

View File

@@ -1,5 +1,5 @@
import { SchemaOptions } from '../options.js';
import type { CollectionTag, ScalarTag } from './types.js';
import type { SchemaOptions } from '../options';
import type { CollectionTag, ScalarTag } from './types';
declare const tagsByName: {
binary: ScalarTag;
bool: ScalarTag & {
@@ -14,6 +14,10 @@ declare const tagsByName: {
intOct: ScalarTag;
intTime: ScalarTag;
map: CollectionTag;
merge: ScalarTag & {
identify(value: unknown): boolean;
test: RegExp;
};
null: ScalarTag & {
test: RegExp;
};
@@ -29,6 +33,10 @@ export type TagId = keyof typeof tagsByName;
export type Tags = Array<ScalarTag | CollectionTag | TagId>;
export declare const coreKnownTags: {
'tag:yaml.org,2002:binary': ScalarTag;
'tag:yaml.org,2002:merge': ScalarTag & {
identify(value: unknown): boolean;
test: RegExp;
};
'tag:yaml.org,2002:omap': CollectionTag;
'tag:yaml.org,2002:pairs': CollectionTag;
'tag:yaml.org,2002:set': CollectionTag;
@@ -36,5 +44,5 @@ export declare const coreKnownTags: {
test: RegExp;
};
};
export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (CollectionTag | ScalarTag)[];
export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string, addMergeTag?: boolean): (CollectionTag | ScalarTag)[];
export {};

View File

@@ -10,6 +10,7 @@ var int = require('./core/int.js');
var schema = require('./core/schema.js');
var schema$1 = require('./json/schema.js');
var binary = require('./yaml-1.1/binary.js');
var merge = require('./yaml-1.1/merge.js');
var omap = require('./yaml-1.1/omap.js');
var pairs = require('./yaml-1.1/pairs.js');
var schema$2 = require('./yaml-1.1/schema.js');
@@ -35,6 +36,7 @@ const tagsByName = {
intOct: int.intOct,
intTime: timestamp.intTime,
map: map.map,
merge: merge.merge,
null: _null.nullTag,
omap: omap.omap,
pairs: pairs.pairs,
@@ -44,13 +46,20 @@ const tagsByName = {
};
const coreKnownTags = {
'tag:yaml.org,2002:binary': binary.binary,
'tag:yaml.org,2002:merge': merge.merge,
'tag:yaml.org,2002:omap': omap.omap,
'tag:yaml.org,2002:pairs': pairs.pairs,
'tag:yaml.org,2002:set': set.set,
'tag:yaml.org,2002:timestamp': timestamp.timestamp
};
function getTags(customTags, schemaName) {
let tags = schemas.get(schemaName);
function getTags(customTags, schemaName, addMergeTag) {
const schemaTags = schemas.get(schemaName);
if (schemaTags && !customTags) {
return addMergeTag && !schemaTags.includes(merge.merge)
? schemaTags.concat(merge.merge)
: schemaTags.slice();
}
let tags = schemaTags;
if (!tags) {
if (Array.isArray(customTags))
tags = [];
@@ -69,17 +78,21 @@ function getTags(customTags, schemaName) {
else if (typeof customTags === 'function') {
tags = customTags(tags.slice());
}
return tags.map(tag => {
if (typeof tag !== 'string')
return tag;
const tagObj = tagsByName[tag];
if (tagObj)
return tagObj;
const keys = Object.keys(tagsByName)
.map(key => JSON.stringify(key))
.join(', ');
throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
});
if (addMergeTag)
tags = tags.concat(merge.merge);
return tags.reduce((tags, tag) => {
const tagObj = typeof tag === 'string' ? tagsByName[tag] : tag;
if (!tagObj) {
const tagName = JSON.stringify(tag);
const keys = Object.keys(tagsByName)
.map(key => JSON.stringify(key))
.join(', ');
throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);
}
if (!tags.includes(tagObj))
tags.push(tagObj);
return tags;
}, []);
}
exports.coreKnownTags = coreKnownTags;

View File

@@ -1,22 +1,24 @@
import type { CreateNodeContext } from '../doc/createNode.js';
import type { Node } from '../nodes/Node.js';
import type { Scalar } from '../nodes/Scalar.js';
import type { YAMLMap } from '../nodes/YAMLMap.js';
import type { YAMLSeq } from '../nodes/YAMLSeq.js';
import type { ParseOptions } from '../options.js';
import type { StringifyContext } from '../stringify/stringify.js';
import type { Schema } from './Schema.js';
import type { CreateNodeContext } from '../doc/createNode';
import type { Node } from '../nodes/Node';
import type { Scalar } from '../nodes/Scalar';
import type { YAMLMap } from '../nodes/YAMLMap';
import type { YAMLSeq } from '../nodes/YAMLSeq';
import type { ParseOptions } from '../options';
import type { StringifyContext } from '../stringify/stringify';
import type { Schema } from './Schema';
interface TagBase {
/**
* An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes.
*/
createNode?: (schema: Schema, value: unknown, ctx: CreateNodeContext) => Node;
/**
* If `true`, together with `test` allows for values to be stringified without
* an explicit tag. For most cases, it's unlikely that you'll actually want to
* use this, even if you first think you do.
* If `true`, allows for values to be stringified without
* an explicit tag together with `test`.
* If `'key'`, this only applies if the value is used as a mapping key.
* For most cases, it's unlikely that you'll actually want to use this,
* even if you first think you do.
*/
default?: boolean;
default?: boolean | 'key';
/**
* If a tag has multiple forms that should be parsed and/or stringified
* differently, use `format` to identify them.

View File

@@ -1,2 +1,2 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const binary: ScalarTag;

View File

@@ -1,10 +1,11 @@
'use strict';
var node_buffer = require('buffer');
var Scalar = require('../../nodes/Scalar.js');
var stringifyString = require('../../stringify/stringifyString.js');
const binary = {
identify: value => value instanceof Uint8Array,
identify: value => value instanceof Uint8Array, // Buffer inherits from Uint8Array
default: false,
tag: 'tag:yaml.org,2002:binary',
/**
@@ -16,8 +17,8 @@ const binary = {
* document.querySelector('#photo').src = URL.createObjectURL(blob)
*/
resolve(src, onError) {
if (typeof Buffer === 'function') {
return Buffer.from(src, 'base64');
if (typeof node_buffer.Buffer === 'function') {
return node_buffer.Buffer.from(src, 'base64');
}
else if (typeof atob === 'function') {
// On IE 11, atob() can't handle newlines
@@ -33,13 +34,15 @@ const binary = {
}
},
stringify({ comment, type, value }, ctx, onComment, onChompKeep) {
if (!value)
return '';
const buf = value; // checked earlier by binary.identify()
let str;
if (typeof Buffer === 'function') {
if (typeof node_buffer.Buffer === 'function') {
str =
buf instanceof Buffer
buf instanceof node_buffer.Buffer
? buf.toString('base64')
: Buffer.from(buf.buffer).toString('base64');
: node_buffer.Buffer.from(buf.buffer).toString('base64');
}
else if (typeof btoa === 'function') {
let s = '';
@@ -50,8 +53,7 @@ const binary = {
else {
throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
}
if (!type)
type = Scalar.Scalar.BLOCK_LITERAL;
type ?? (type = Scalar.Scalar.BLOCK_LITERAL);
if (type !== Scalar.Scalar.QUOTE_DOUBLE) {
const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);
const n = Math.ceil(str.length / lineWidth);

View File

@@ -1,4 +1,4 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const trueTag: ScalarTag & {
test: RegExp;
};

View File

@@ -20,7 +20,7 @@ const falseTag = {
identify: value => value === false,
default: true,
tag: 'tag:yaml.org,2002:bool',
test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
resolve: () => new Scalar.Scalar(false),
stringify: boolStringify
};

View File

@@ -1,4 +1,4 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const floatNaN: ScalarTag;
export declare const floatExp: ScalarTag;
export declare const float: ScalarTag;

View File

@@ -7,7 +7,7 @@ const floatNaN = {
identify: value => typeof value === 'number',
default: true,
tag: 'tag:yaml.org,2002:float',
test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/,
test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
resolve: (str) => str.slice(-3).toLowerCase() === 'nan'
? NaN
: str[0] === '-'

View File

@@ -1,4 +1,4 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const intBin: ScalarTag;
export declare const intOct: ScalarTag;
export declare const int: ScalarTag;

9
node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
import type { ToJSContext } from '../../nodes/toJS';
import type { MapLike } from '../../nodes/YAMLMap';
import type { ScalarTag } from '../types';
export declare const merge: ScalarTag & {
identify(value: unknown): boolean;
test: RegExp;
};
export declare const isMergeKey: (ctx: ToJSContext | undefined, key: unknown) => boolean | undefined;
export declare function addMergeToJSMap(ctx: ToJSContext | undefined, map: MapLike, value: unknown): void;

68
node_modules/yaml/dist/schema/yaml-1.1/merge.js generated vendored Normal file
View File

@@ -0,0 +1,68 @@
'use strict';
var identity = require('../../nodes/identity.js');
var Scalar = require('../../nodes/Scalar.js');
// 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 MERGE_KEY = '<<';
const merge = {
identify: value => value === MERGE_KEY ||
(typeof value === 'symbol' && value.description === MERGE_KEY),
default: 'key',
tag: 'tag:yaml.org,2002:merge',
test: /^<<$/,
resolve: () => Object.assign(new Scalar.Scalar(Symbol(MERGE_KEY)), {
addToJSMap: addMergeToJSMap
}),
stringify: () => MERGE_KEY
};
const isMergeKey = (ctx, key) => (merge.identify(key) ||
(identity.isScalar(key) &&
(!key.type || key.type === Scalar.Scalar.PLAIN) &&
merge.identify(key.value))) &&
ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
function addMergeToJSMap(ctx, map, value) {
value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
if (identity.isSeq(value))
for (const it of value.items)
mergeValue(ctx, map, it);
else if (Array.isArray(value))
for (const it of value)
mergeValue(ctx, map, it);
else
mergeValue(ctx, map, value);
}
function mergeValue(ctx, map, value) {
const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
if (!identity.isMap(source))
throw new Error('Merge sources must be maps or map aliases');
const srcMap = source.toJSON(null, ctx, Map);
for (const [key, value] of srcMap) {
if (map instanceof Map) {
if (!map.has(key))
map.set(key, value);
}
else if (map instanceof Set) {
map.add(key);
}
else if (!Object.prototype.hasOwnProperty.call(map, key)) {
Object.defineProperty(map, key, {
value,
writable: true,
enumerable: true,
configurable: true
});
}
}
return map;
}
exports.addMergeToJSMap = addMergeToJSMap;
exports.isMergeKey = isMergeKey;
exports.merge = merge;

View File

@@ -1,23 +1,17 @@
import { ToJSContext } from '../../nodes/toJS.js';
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
import { CreateNodeContext } from '../../util.js';
import type { Schema } from '../Schema.js';
import { CollectionTag } from '../types.js';
import type { ToJSContext } from '../../nodes/toJS';
import { YAMLMap } from '../../nodes/YAMLMap';
import { YAMLSeq } from '../../nodes/YAMLSeq';
import type { CreateNodeContext } from '../../util';
import type { Schema } from '../Schema';
import type { CollectionTag } from '../types';
export declare class YAMLOMap extends YAMLSeq {
static tag: string;
constructor();
add: (pair: import("../../index.js").Pair<any, any> | {
key: any;
value: any;
}, overwrite?: boolean | undefined) => void;
delete: (key: unknown) => boolean;
get: {
(key: unknown, keepScalar: true): import("../../index.js").Scalar<any> | undefined;
(key: unknown, keepScalar?: false | undefined): any;
(key: unknown, keepScalar?: boolean | undefined): any;
};
has: (key: unknown) => boolean;
set: (key: any, value: any) => void;
add: typeof YAMLMap.prototype.add;
delete: typeof YAMLMap.prototype.delete;
get: typeof YAMLMap.prototype.get;
has: typeof YAMLMap.prototype.has;
set: typeof YAMLMap.prototype.set;
/**
* If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
* but TypeScript won't allow widening the signature of a child method.

View File

@@ -1,10 +1,10 @@
import type { CreateNodeContext } from '../../doc/createNode.js';
import type { ParsedNode } from '../../nodes/Node.js';
import { Pair } from '../../nodes/Pair.js';
import { YAMLMap } from '../../nodes/YAMLMap.js';
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
import type { Schema } from '../../schema/Schema.js';
import type { CollectionTag } from '../types.js';
import type { CreateNodeContext } from '../../doc/createNode';
import type { ParsedNode } from '../../nodes/Node';
import { Pair } from '../../nodes/Pair';
import type { YAMLMap } from '../../nodes/YAMLMap';
import { YAMLSeq } from '../../nodes/YAMLSeq';
import type { Schema } from '../../schema/Schema';
import type { CollectionTag } from '../types';
export declare function resolvePairs(seq: YAMLSeq.Parsed<ParsedNode | Pair<ParsedNode, ParsedNode | null>> | YAMLMap.Parsed, onError: (message: string) => void): YAMLSeq.Parsed<Pair<ParsedNode, ParsedNode | null>>;
export declare function createPairs(schema: Schema, iterable: unknown, ctx: CreateNodeContext): YAMLSeq<unknown>;
export declare const pairs: CollectionTag;

View File

@@ -1 +1 @@
export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[];
export declare const schema: (import('../types').CollectionTag | import('../types').ScalarTag)[];

View File

@@ -8,6 +8,7 @@ var binary = require('./binary.js');
var bool = require('./bool.js');
var float = require('./float.js');
var int = require('./int.js');
var merge = require('./merge.js');
var omap = require('./omap.js');
var pairs = require('./pairs.js');
var set = require('./set.js');
@@ -28,6 +29,7 @@ const schema = [
float.floatExp,
float.float,
binary.binary,
merge.merge,
omap.omap,
pairs.pairs,
set.set,

View File

@@ -1,11 +1,11 @@
import { Pair } from '../../nodes/Pair.js';
import { Scalar } from '../../nodes/Scalar.js';
import { ToJSContext } from '../../nodes/toJS.js';
import { YAMLMap } from '../../nodes/YAMLMap.js';
import type { Schema } from '../../schema/Schema.js';
import type { StringifyContext } from '../../stringify/stringify.js';
import { CreateNodeContext } from '../../util.js';
import type { CollectionTag } from '../types.js';
import { Pair } from '../../nodes/Pair';
import type { Scalar } from '../../nodes/Scalar';
import type { ToJSContext } from '../../nodes/toJS';
import { YAMLMap } from '../../nodes/YAMLMap';
import type { Schema } from '../../schema/Schema';
import type { StringifyContext } from '../../stringify/stringify';
import type { CreateNodeContext } from '../../util';
import type { CollectionTag } from '../types';
export declare class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null> {
static tag: string;
constructor(schema?: Schema);
@@ -23,6 +23,6 @@ export declare class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null
set(key: T, value: null): void;
toJSON(_?: unknown, ctx?: ToJSContext): any;
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
static from(schema: Schema, iterable: unknown, ctx: CreateNodeContext): YAMLSet<unknown>;
static from(schema: Schema, iterable: unknown, ctx: CreateNodeContext): YAMLSet;
}
export declare const set: CollectionTag;

View File

@@ -1,4 +1,4 @@
import type { ScalarTag } from '../types.js';
import type { ScalarTag } from '../types';
export declare const intTime: ScalarTag;
export declare const floatTime: ScalarTag;
export declare const timestamp: ScalarTag & {

View File

@@ -97,7 +97,7 @@ const timestamp = {
}
return new Date(date);
},
stringify: ({ value }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '')
stringify: ({ value }) => value?.toISOString().replace(/(T00:00:00)?\.000Z$/, '') ?? ''
};
exports.floatTime = floatTime;

View File

@@ -11,6 +11,8 @@ const FOLD_QUOTED = 'quoted';
function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow } = {}) {
if (!lineWidth || lineWidth < 0)
return text;
if (lineWidth < minContentWidth)
minContentWidth = 0;
const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
if (text.length <= endStep)
return text;
@@ -30,7 +32,7 @@ function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth =
let escStart = -1;
let escEnd = -1;
if (mode === FOLD_BLOCK) {
i = consumeMoreIndentedLines(text, i);
i = consumeMoreIndentedLines(text, i, indent.length);
if (i !== -1)
end = i + endStep;
}
@@ -54,8 +56,8 @@ function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth =
}
if (ch === '\n') {
if (mode === FOLD_BLOCK)
i = consumeMoreIndentedLines(text, i);
end = i + endStep;
i = consumeMoreIndentedLines(text, i, indent.length);
end = i + indent.length + endStep;
split = undefined;
}
else {
@@ -123,15 +125,24 @@ function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth =
* Presumes `i + 1` is at the start of a line
* @returns index of last newline in more-indented block
*/
function consumeMoreIndentedLines(text, i) {
let ch = text[i + 1];
function consumeMoreIndentedLines(text, i, indent) {
let end = i;
let start = i + 1;
let ch = text[start];
while (ch === ' ' || ch === '\t') {
do {
ch = text[(i += 1)];
} while (ch && ch !== '\n');
ch = text[i + 1];
if (i < start + indent) {
ch = text[++i];
}
else {
do {
ch = text[++i];
} while (ch && ch !== '\n');
end = i;
start = i + 1;
ch = text[start];
}
}
return i;
return end;
}
exports.FOLD_BLOCK = FOLD_BLOCK;

Some files were not shown because too many files have changed in this diff Show More