diff --git a/.node-version b/.node-version index 728f7de..6fa8dec 100644 --- a/.node-version +++ b/.node-version @@ -1 +1 @@ -22.9.0 +22.13.0 diff --git a/dist/index.js b/dist/index.js index 9aff758..145de4b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -678,7 +678,7 @@ class Alias extends NodeBase { data = anchors.get(source); } /* istanbul ignore if */ - if (!data || data.res === undefined) { + if (data?.res === undefined) { const msg = 'This should not happen: Alias anchor was not resolved?'; throw new ReferenceError(msg); } @@ -1690,7 +1690,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) { ws += `\n${indentComment(cs, ctx.indent)}`; } if (valueStr === '' && !ctx.inFlow) { - if (ws === '\n') + if (ws === '\n' && valueComment) ws = '\n\n'; } else { @@ -2338,7 +2338,7 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) { const num = typeof value === 'number' ? value : Number(value); if (!isFinite(num)) return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf'; - let n = JSON.stringify(value); + let n = Object.is(value, -0) ? '-0' : JSON.stringify(value); if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && @@ -3594,7 +3594,7 @@ const prettifyError = (src, lc) => (error) => { if (/[^ ]/.test(lineStr)) { let count = 1; const end = error.linePos[1]; - if (end && end.line === line && end.col > col) { + if (end?.line === line && end.col > col) { count = Math.max(1, Math.min(end.col - col, 80 - ci)); } const pointer = ' '.repeat(ci) + '^'.repeat(count); @@ -3929,7 +3929,7 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta }); if (!props.found) { if (props.anchor || props.tag || value) { - if (value && value.type === 'block-seq') + if (value?.type === 'block-seq') onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column'); else onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator'); @@ -4115,7 +4115,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr } } else if (value) { - if ('source' in value && value.source && value.source[0] === ':') + if ('source' in value && value.source?.[0] === ':') onError(value, 'MISSING_CHAR', `Missing space after : in ${fcName}`); else onError(valueProps.start, 'MISSING_CHAR', `Missing , or : between ${fcName} items`); @@ -4159,7 +4159,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr const expectedEnd = isMap ? '}' : ']'; const [ce, ...ee] = fc.end; let cePos = offset; - if (ce && ce.source === expectedEnd) + if (ce?.source === expectedEnd) cePos = ce.offset + ce.source.length; else { const name = fcName[0].toUpperCase() + fcName.substring(1); @@ -4239,7 +4239,7 @@ function composeCollection(CN, ctx, token, props, onError) { let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType); if (!tag) { const kt = ctx.schema.knownTags[tagName]; - if (kt && kt.collection === expType) { + if (kt?.collection === expType) { ctx.schema.tags.push(Object.assign({}, kt, { default: false })); tag = kt; } @@ -6575,7 +6575,7 @@ class Parser { } *step() { const top = this.peek(1); - if (this.type === 'doc-end' && (!top || top.type !== 'doc-end')) { + if (this.type === 'doc-end' && top?.type !== 'doc-end') { while (this.stack.length > 0) yield* this.pop(); this.stack.push({ @@ -7107,7 +7107,7 @@ class Parser { do { yield* this.pop(); top = this.peek(1); - } while (top && top.type === 'flow-collection'); + } while (top?.type === 'flow-collection'); } else if (fc.end.length === 0) { switch (this.type) { diff --git a/package-lock.json b/package-lock.json index 3401fe6..8d45ddb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1053,9 +1053,9 @@ } }, "node_modules/@istanbuljs/load-nyc-config/node_modules/js-yaml": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", - "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "version": "3.14.2", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.2.tgz", + "integrity": "sha512-PMSmkqxr106Xa156c2M265Z+FTrPl+oxd/rgOQy2tijQeK5TxQ43psO1ZCwhVOSdnn+RzkzlRz/eY4BgJBYVpg==", "dev": true, "license": "MIT", "dependencies": { @@ -1867,9 +1867,9 @@ } }, "node_modules/@jest/reporters/node_modules/glob": { - "version": "10.4.5", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", - "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz", + "integrity": "sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==", "dev": true, "license": "ISC", "dependencies": { @@ -3073,18 +3073,6 @@ "@babel/types": "^7.28.2" } }, - "node_modules/@types/eslint": { - "version": "8.44.2", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.2.tgz", - "integrity": "sha512-sdPRb9K6iL5XZOmBubg8yiFp5yS/JdUDQsq5e6h95km91MCYMuvp7mh1fjPEYUhvHepKpZOjnEaMBR4PxjWDzg==", - "dev": true, - "optional": true, - "peer": true, - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", @@ -7324,9 +7312,9 @@ } }, "node_modules/jest-config/node_modules/glob": { - "version": "10.4.5", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", - "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz", + "integrity": "sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==", "dev": true, "license": "ISC", "dependencies": { @@ -8646,9 +8634,9 @@ } }, "node_modules/jest-runtime/node_modules/glob": { - "version": "10.4.5", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", - "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz", + "integrity": "sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==", "dev": true, "license": "ISC", "dependencies": { @@ -12107,15 +12095,18 @@ "license": "ISC" }, "node_modules/yaml": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.1.tgz", - "integrity": "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==", + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.2.tgz", + "integrity": "sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A==", "license": "ISC", "bin": { "yaml": "bin.mjs" }, "engines": { "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" } }, "node_modules/yargs": {