diff --git a/dist/index.js b/dist/index.js index 1a3da48e..bfc13010 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10701,7 +10701,7 @@ function composeNode(ctx, token, props, onError) { node.srcToken = token; return node; } -function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anchor, tag }, onError) { +function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anchor, tag, end }, onError) { const token = { type: 'scalar', offset: utilEmptyScalarPosition.emptyScalarPosition(offset, before, pos), @@ -10716,8 +10716,10 @@ function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anch } if (spaceBefore) node.spaceBefore = true; - if (comment) + if (comment) { node.comment = comment; + node.range[2] = end; + } return node; } function composeAlias({ options }, { offset, source, end }, onError) { @@ -11078,6 +11080,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) { if (ctx.atRoot) ctx.atRoot = false; let offset = bm.offset; + let commentEnd = null; for (const collItem of bm.items) { const { start, key, sep, value } = collItem; // key properties @@ -11097,7 +11100,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) { onError(offset, 'BAD_INDENT', startColMsg); } if (!keyProps.anchor && !keyProps.tag && !sep) { - // TODO: assert being at last item? + commentEnd = keyProps.end; if (keyProps.comment) { if (map.comment) map.comment += '\n' + keyProps.comment; @@ -11167,7 +11170,9 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) { map.items.push(pair); } } - map.range = [bm.offset, offset, offset]; + if (commentEnd && commentEnd < offset) + onError(commentEnd, 'IMPOSSIBLE', 'Map comment with trailing content'); + map.range = [bm.offset, offset, commentEnd ?? offset]; return map; } @@ -11395,6 +11400,7 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) { if (ctx.atRoot) ctx.atRoot = false; let offset = bs.offset; + let commentEnd = null; for (const { start, value } of bs.items) { const props = resolveProps.resolveProps(start, { indicator: 'seq-item-ind', @@ -11403,16 +11409,15 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) { onError, startOnNewline: true }); - offset = props.end; if (!props.found) { if (props.anchor || props.tag || value) { if (value && value.type === 'block-seq') - onError(offset, 'BAD_INDENT', 'All sequence items must start at the same column'); + onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column'); else onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator'); } else { - // TODO: assert being at last item? + commentEnd = props.end; if (props.comment) seq.comment = props.comment; continue; @@ -11420,13 +11425,13 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) { } const node = value ? composeNode(ctx, value, props, onError) - : composeEmptyNode(ctx, offset, start, null, props, onError); + : composeEmptyNode(ctx, props.end, start, null, props, onError); if (ctx.schema.compat) utilFlowIndentCheck.flowIndentCheck(bs.indent, value, onError); offset = node.range[2]; seq.items.push(node); } - seq.range = [bs.offset, offset, offset]; + seq.range = [bs.offset, offset, commentEnd ?? offset]; return seq; } @@ -12727,7 +12732,7 @@ function createNode(value, tagName, ctx) { if (value instanceof String || value instanceof Number || value instanceof Boolean || - (typeof BigInt === 'function' && value instanceof BigInt) // not supported everywhere + (typeof BigInt !== 'undefined' && value instanceof BigInt) // not supported everywhere ) { // https://tc39.es/ecma262/#sec-serializejsonproperty value = value.valueOf(); @@ -17310,7 +17315,8 @@ class YAMLSet extends YAMLMap.YAMLMap { let pair; if (Node.isPair(key)) pair = key; - else if (typeof key === 'object' && + else if (key && + typeof key === 'object' && 'key' in key && 'value' in key && key.value === null) diff --git a/package-lock.json b/package-lock.json index 315dc192..4d913811 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,7 @@ "ts-jest": "^26.5.6", "ts-node": "^10.9.1", "typescript": "^4.8.3", - "yaml": "^2.1.1", + "yaml": "^2.1.3", "yargs": "^17.6.2" }, "engines": { @@ -8766,9 +8766,9 @@ "dev": true }, "node_modules/yaml": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.1.tgz", - "integrity": "sha512-o96x3OPo8GjWeSLF+wOAbrPfhFOGY0W00GNaxCDv+9hkcDJEnev1yh8S7pgHF0ik6zc8sQLuL8hjHjJULZp8bw==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.3.tgz", + "integrity": "sha512-AacA8nRULjKMX2DvWvOAdBZMOfQlypSFkjcOcu9FalllIDJ1kvlREzcdIZmidQUqqeMv7jorHjq2HlLv/+c2lg==", "dev": true, "engines": { "node": ">= 14" @@ -15573,9 +15573,9 @@ "dev": true }, "yaml": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.1.tgz", - "integrity": "sha512-o96x3OPo8GjWeSLF+wOAbrPfhFOGY0W00GNaxCDv+9hkcDJEnev1yh8S7pgHF0ik6zc8sQLuL8hjHjJULZp8bw==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.1.3.tgz", + "integrity": "sha512-AacA8nRULjKMX2DvWvOAdBZMOfQlypSFkjcOcu9FalllIDJ1kvlREzcdIZmidQUqqeMv7jorHjq2HlLv/+c2lg==", "dev": true }, "yargs": { diff --git a/package.json b/package.json index ee840ce0..4e049118 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "ts-jest": "^26.5.6", "ts-node": "^10.9.1", "typescript": "^4.8.3", - "yaml": "^2.1.1", + "yaml": "^2.1.3", "yargs": "^17.6.2" } }