node_modules: update (#146)

Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
Dawid Dziurla
2026-08-07 08:08:41 +02:00
committed by GitHub
co-authored by dawidd6
parent 6b3dfab4e0
commit 3d5a3a75cc
44 changed files with 660 additions and 284 deletions
+11 -4
View File
@@ -28,19 +28,26 @@ function composeNode(ctx, token, props, onError) {
case 'block-map':
case 'block-seq':
case 'flow-collection':
node = composeCollection(CN, ctx, token, props, onError);
if (anchor)
node.anchor = anchor.source.substring(1);
try {
node = composeCollection(CN, ctx, token, props, onError);
if (anchor)
node.anchor = anchor.source.substring(1);
}
catch (error) {
// Almost certainly here due to a stack overflow
const message = error instanceof Error ? error.message : String(error);
onError(token, 'RESOURCE_EXHAUSTION', message);
}
break;
default: {
const message = token.type === 'error'
? token.message
: `Unsupported token (type: ${token.type})`;
onError(token, 'UNEXPECTED_TOKEN', message);
node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError);
isSrcToken = false;
}
}
node ?? (node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError));
if (anchor && node.anchor === '')
onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
if (atKey &&
+4 -2
View File
@@ -94,8 +94,10 @@ class Composer {
}
}
if (afterDoc) {
Array.prototype.push.apply(doc.errors, this.errors);
Array.prototype.push.apply(doc.warnings, this.warnings);
for (let i = 0; i < this.errors.length; ++i)
doc.errors.push(this.errors[i]);
for (let i = 0; i < this.warnings.length; ++i)
doc.warnings.push(this.warnings[i]);
}
else {
doc.errors = this.errors;
+5 -3
View File
@@ -142,7 +142,7 @@ function doubleQuotedValue(source, onError) {
next = source[++i + 1];
}
else if (next === 'x' || next === 'u' || next === 'U') {
const length = { x: 2, u: 4, U: 8 }[next];
const length = next === 'x' ? 2 : next === 'u' ? 4 : 8;
res += parseCharCode(source, i + 1, length, onError);
i += length;
}
@@ -212,12 +212,14 @@ function parseCharCode(source, offset, length, onError) {
const cc = source.substr(offset, length);
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
const code = ok ? parseInt(cc, 16) : NaN;
if (isNaN(code)) {
try {
return String.fromCodePoint(code);
}
catch {
const raw = source.substr(offset - 2, length + 2);
onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
return raw;
}
return String.fromCodePoint(code);
}
export { resolveFlowScalar };
+2
View File
@@ -19,6 +19,8 @@ class Alias extends NodeBase {
* instance of the `source` anchor before this node.
*/
resolve(doc, ctx) {
if (ctx?.maxAliasCount === 0)
throw new ReferenceError('Alias resolution is disabled');
let nodes;
if (ctx?.aliasResolveCache) {
nodes = ctx.aliasResolveCache;
+28 -24
View File
@@ -310,7 +310,7 @@ class Lexer {
const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
this.indentNext = this.indentValue + 1;
this.indentValue += n;
return yield* this.parseBlockStart();
return 'block-start';
}
return 'doc';
}
@@ -631,32 +631,36 @@ class Lexer {
return 0;
}
*pushIndicators() {
switch (this.charAt(0)) {
case '!':
return ((yield* this.pushTag()) +
(yield* this.pushSpaces(true)) +
(yield* this.pushIndicators()));
case '&':
return ((yield* this.pushUntil(isNotAnchorChar)) +
(yield* this.pushSpaces(true)) +
(yield* this.pushIndicators()));
case '-': // this is an error
case '?': // this is an error outside flow collections
case ':': {
const inFlow = this.flowLevel > 0;
const ch1 = this.charAt(1);
if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) {
if (!inFlow)
this.indentNext = this.indentValue + 1;
else if (this.flowKey)
this.flowKey = false;
return ((yield* this.pushCount(1)) +
(yield* this.pushSpaces(true)) +
(yield* this.pushIndicators()));
let n = 0;
loop: while (true) {
switch (this.charAt(0)) {
case '!':
n += yield* this.pushTag();
n += yield* this.pushSpaces(true);
continue loop;
case '&':
n += yield* this.pushUntil(isNotAnchorChar);
n += yield* this.pushSpaces(true);
continue loop;
case '-': // this is an error
case '?': // this is an error outside flow collections
case ':': {
const inFlow = this.flowLevel > 0;
const ch1 = this.charAt(1);
if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) {
if (!inFlow)
this.indentNext = this.indentValue + 1;
else if (this.flowKey)
this.flowKey = false;
n += yield* this.pushCount(1);
n += yield* this.pushSpaces(true);
continue loop;
}
}
}
break loop;
}
return 0;
return n;
}
*pushTag() {
if (this.charAt(1) === '<') {
+12 -4
View File
@@ -67,6 +67,14 @@ function getFirstKeyStartProps(prev) {
}
return prev.splice(i, prev.length);
}
function arrayPushArray(target, source) {
// May exhaust call stack with large `source` array
if (source.length < 1e5)
Array.prototype.push.apply(target, source);
else
for (let i = 0; i < source.length; ++i)
target.push(source[i]);
}
function fixFlowSeqItems(fc) {
if (fc.start.type === 'flow-seq-start') {
for (const it of fc.items) {
@@ -79,12 +87,12 @@ function fixFlowSeqItems(fc) {
delete it.key;
if (isFlowToken(it.value)) {
if (it.value.end)
Array.prototype.push.apply(it.value.end, it.sep);
arrayPushArray(it.value.end, it.sep);
else
it.value.end = it.sep;
}
else
Array.prototype.push.apply(it.start, it.sep);
arrayPushArray(it.start, it.sep);
delete it.sep;
}
}
@@ -502,7 +510,7 @@ class Parser {
const prev = map.items[map.items.length - 2];
const end = prev?.value?.end;
if (Array.isArray(end)) {
Array.prototype.push.apply(end, it.start);
arrayPushArray(end, it.start);
end.push(this.sourceToken);
map.items.pop();
return;
@@ -717,7 +725,7 @@ class Parser {
const prev = seq.items[seq.items.length - 2];
const end = prev?.value?.end;
if (Array.isArray(end)) {
Array.prototype.push.apply(end, it.start);
arrayPushArray(end, it.start);
end.push(this.sourceToken);
seq.items.pop();
return;
+11 -8
View File
@@ -1,4 +1,4 @@
import { isScalar, isAlias, isSeq, isMap } from '../../nodes/identity.js';
import { isScalar, isSeq, isAlias, isMap } from '../../nodes/identity.js';
import { Scalar } from '../../nodes/Scalar.js';
// If the value associated with a merge key is a single mapping node, each of
@@ -26,18 +26,18 @@ const isMergeKey = (ctx, key) => (merge.identify(key) ||
merge.identify(key.value))) &&
ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
function addMergeToJSMap(ctx, map, value) {
value = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
if (isSeq(value))
for (const it of value.items)
const source = resolveAliasValue(ctx, value);
if (isSeq(source))
for (const it of source.items)
mergeValue(ctx, map, it);
else if (Array.isArray(value))
for (const it of value)
else if (Array.isArray(source))
for (const it of source)
mergeValue(ctx, map, it);
else
mergeValue(ctx, map, value);
mergeValue(ctx, map, source);
}
function mergeValue(ctx, map, value) {
const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
const source = resolveAliasValue(ctx, value);
if (!isMap(source))
throw new Error('Merge sources must be maps or map aliases');
const srcMap = source.toJSON(null, ctx, Map);
@@ -60,5 +60,8 @@ function mergeValue(ctx, map, value) {
}
return map;
}
function resolveAliasValue(ctx, value) {
return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
}
export { addMergeToJSMap, isMergeKey, merge };
+1
View File
@@ -20,6 +20,7 @@ function createStringifyContext(doc, options) {
nullStr: 'null',
simpleKeys: false,
singleQuote: null,
trailingComma: false,
trueStr: 'true',
verifyAliasOrder: true
}, doc.schema.toStringOptions, options);
+13 -3
View File
@@ -102,12 +102,22 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
if (comment)
reqNewline = true;
let str = stringify(item, itemCtx, () => (comment = null));
if (i < items.length - 1)
reqNewline || (reqNewline = lines.length > linesAtValue || str.includes('\n'));
if (i < items.length - 1) {
str += ',';
}
else if (ctx.options.trailingComma) {
if (ctx.options.lineWidth > 0) {
reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) +
(str.length + 2) >
ctx.options.lineWidth);
}
if (reqNewline) {
str += ',';
}
}
if (comment)
str += lineComment(str, itemIndent, commentString(comment));
if (!reqNewline && (lines.length > linesAtValue || str.includes('\n')))
reqNewline = true;
lines.push(str);
linesAtValue = lines.length;
}
+2 -1
View File
@@ -8,7 +8,8 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
if (!format &&
minFractionDigits &&
(!tag || tag === 'tag:yaml.org,2002:float') &&
/^\d/.test(n)) {
/^-?\d/.test(n) &&
!n.includes('e')) {
let i = n.indexOf('.');
if (i < 0) {
i = n.length;